From d473c1650b5c5716180e5f418cbc028816b69161 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 17 Jan 2015 04:41:50 -0800 Subject: [PATCH] Add options conditional on whether code is being pasted --- modules/compiler_vm/languages/_c_base.pm | 2 ++ modules/compiler_vm/languages/_default.pm | 43 ++++++++++++++++++----- modules/compiler_vm/languages/c11.pm | 4 ++- modules/compiler_vm/languages/c89.pm | 6 ++++ modules/compiler_vm/languages/c99.pm | 2 ++ modules/compiler_vm/languages/clang11.pm | 4 ++- modules/compiler_vm/languages/clang89.pm | 7 +++- modules/compiler_vm/languages/clang99.pm | 4 ++- 8 files changed, 60 insertions(+), 12 deletions(-) diff --git a/modules/compiler_vm/languages/_c_base.pm b/modules/compiler_vm/languages/_c_base.pm index 130ec4e3..c59f4d7b 100755 --- a/modules/compiler_vm/languages/_c_base.pm +++ b/modules/compiler_vm/languages/_c_base.pm @@ -17,6 +17,8 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors'; + $self->{options_paste} = '-fdiagnostics-show-caret'; + $self->{options_nopaste} = '-fno-diagnostics-show-caret'; $self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile'; $self->{prelude} = <<'END'; diff --git a/modules/compiler_vm/languages/_default.pm b/modules/compiler_vm/languages/_default.pm index fa37d550..9b5824c5 100755 --- a/modules/compiler_vm/languages/_default.pm +++ b/modules/compiler_vm/languages/_default.pm @@ -91,14 +91,22 @@ sub show_output { $cmdline =~ s/\$sourcefile/$self->{sourcefile}/g; $cmdline =~ s/\$execfile/$self->{execfile}/g; + my $options; if (length $self->{cmdline_options}) { - $cmdline =~ s/\$options/$self->{cmdline_options}/g; + $options = $self->{cmdline_options}; } else { - if (length $self->{default_options}) { - $cmdline =~ s/\$options/$self->{default_options}/g; - } else { - $cmdline =~ s/\$options\s+//g; - } + $options = $self->{default_options}; + } + + if (exists $self->{options_paste}) { + $options .= ' ' if length $options; + $options .= $self->{options_paste}; + } + + if (length $options) { + $cmdline =~ s/\$options/$options/; + } else { + $cmdline =~ s/\$options\s+//; } my $pretty_code = $self->pretty_format($self->{code}); @@ -218,10 +226,29 @@ sub execute { $cmdline =~ s/\$sourcefile/$self->{sourcefile}/g; $cmdline =~ s/\$execfile/$self->{execfile}/g; + my $options; if (length $self->{cmdline_options}) { - $cmdline =~ s/\$options/$self->{cmdline_options}/g; + $options = $self->{cmdline_options}; } else { - $cmdline =~ s/\$options/$self->{default_options}/g; + $options = $self->{default_options}; + } + + if ((not exists $self->{options}->{'-paste'}) and (not defined $self->{got_run} or $self->{got_run} ne 'paste')) { + if (exists $self->{options_nopaste}) { + $options .= ' ' if length $options; + $options .= $self->{options_nopaste}; + } + } else { + if (exists $self->{options_paste}) { + $options .= ' ' if length $options; + $options .= $self->{options_paste}; + } + } + + if (length $options) { + $cmdline =~ s/\$options/$options/; + } else { + $cmdline =~ s/\$options\s+//; } open FILE, ">> log.txt"; diff --git a/modules/compiler_vm/languages/c11.pm b/modules/compiler_vm/languages/c11.pm index 2711d870..566796bc 100755 --- a/modules/compiler_vm/languages/c11.pm +++ b/modules/compiler_vm/languages/c11.pm @@ -11,7 +11,9 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; - $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors -fsanitize=bounds -fsanitize=alignment -fno-diagnostics-show-caret'; + $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors -fsanitize=bounds -fsanitize=alignment'; + $self->{options_paste} = '-fdiagnostics-show-caret'; + $self->{options_nopaste} = '-fno-diagnostics-show-caret'; $self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile'; $self->{prelude} = <<'END'; diff --git a/modules/compiler_vm/languages/c89.pm b/modules/compiler_vm/languages/c89.pm index ef3eb528..8bbb309b 100755 --- a/modules/compiler_vm/languages/c89.pm +++ b/modules/compiler_vm/languages/c89.pm @@ -12,6 +12,8 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c89 -lm -Wfatal-errors -fsanitize=bounds -fsanitize=alignment'; + $self->{options_paste} = '-fdiagnostics-show-caret'; + $self->{options_nopaste} = '-fno-diagnostics-show-caret'; $self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile'; $self->{prelude} = <<'END'; @@ -21,6 +23,7 @@ sub initialize { #include #include #include +#include #include #include #include @@ -31,6 +34,9 @@ sub initialize { #include #include #include +#include +#include +#include #include END diff --git a/modules/compiler_vm/languages/c99.pm b/modules/compiler_vm/languages/c99.pm index 7a23ef25..7f276f41 100755 --- a/modules/compiler_vm/languages/c99.pm +++ b/modules/compiler_vm/languages/c99.pm @@ -12,6 +12,8 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c99 -lm -Wfatal-errors -fsanitize=bounds -fsanitize=alignment'; + $self->{options_paste} = '-fdiagnostics-show-caret'; + $self->{options_nopaste} = '-fno-diagnostics-show-caret'; $self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile'; $self->{prelude} = <<'END'; diff --git a/modules/compiler_vm/languages/clang11.pm b/modules/compiler_vm/languages/clang11.pm index 7181b593..da6036e3 100755 --- a/modules/compiler_vm/languages/clang11.pm +++ b/modules/compiler_vm/languages/clang11.pm @@ -11,7 +11,9 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; - $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors -fsanitize=integer -fsanitize=bounds -fsanitize=undefined -fno-caret-diagnostics'; + $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors -fsanitize=integer -fsanitize=bounds -fsanitize=undefined'; + $self->{options_paste} = '-fcaret-diagnostics'; + $self->{options_nopaste} = '-fno-caret-diagnostics'; $self->{cmdline} = 'clang -g $sourcefile $options -o $execfile'; $self->{prelude} = <<'END'; diff --git a/modules/compiler_vm/languages/clang89.pm b/modules/compiler_vm/languages/clang89.pm index 4faaf8b7..d7bedd7d 100755 --- a/modules/compiler_vm/languages/clang89.pm +++ b/modules/compiler_vm/languages/clang89.pm @@ -11,7 +11,9 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; - $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c89 -lm -Wfatal-errors -fsanitize=integer -fsanitize=bounds -fsanitize=undefined -fno-caret-diagnostics'; + $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c89 -lm -Wfatal-errors -fsanitize=integer -fsanitize=bounds -fsanitize=undefined'; + $self->{options_paste} = '-fcaret-diagnostics'; + $self->{options_nopaste} = '-fno-caret-diagnostics'; $self->{cmdline} = 'clang -ggdb -g3 $sourcefile $options -o $execfile'; $self->{prelude} = <<'END'; @@ -30,6 +32,9 @@ sub initialize { #include #include #include +#include +#include +#include #include END diff --git a/modules/compiler_vm/languages/clang99.pm b/modules/compiler_vm/languages/clang99.pm index d1704cb7..1a7a9dcb 100755 --- a/modules/compiler_vm/languages/clang99.pm +++ b/modules/compiler_vm/languages/clang99.pm @@ -11,7 +11,9 @@ sub initialize { $self->{sourcefile} = 'prog.c'; $self->{execfile} = 'prog'; - $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c99 -lm -Wfatal-errors -fsanitize=integer -fsanitize=bounds -fsanitize=undefined -fno-caret-diagnostics'; + $self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c99 -lm -Wfatal-errors -fsanitize=integer -fsanitize=bounds -fsanitize=undefined'; + $self->{options_paste} = '-fcaret-diagnostics'; + $self->{options_nopaste} = '-fno-caret-diagnostics'; $self->{cmdline} = 'clang -ggdb -g3 $sourcefile $options -o $execfile'; $self->{prelude} = <<'END';