From b10fcc79baf79b8b7f485cc61b5060356bb6732a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 11 Apr 2020 12:41:48 +0300 Subject: [PATCH] comptime: fix #ifdef/#endif generation --- cmd/tools/vtest-fixed.v | 15 +++++++++------ vlib/v/gen/cgen.v | 41 ++++++++++++++++++++++++++--------------- vlib/v/gen/cheaders.v | 2 +- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/cmd/tools/vtest-fixed.v b/cmd/tools/vtest-fixed.v index 5c8cba7ca6..b807a28686 100644 --- a/cmd/tools/vtest-fixed.v +++ b/cmd/tools/vtest-fixed.v @@ -9,7 +9,6 @@ const ( 'vlib/arrays/arrays_test.v', 'vlib/cli/command_test.v', 'vlib/cli/flag_test.v', - 'vlib/clipboard/clipboard_test.v', // Linux only 'vlib/crypto/aes/aes_test.v', 'vlib/crypto/rand/rand_test.v', 'vlib/crypto/rc4/rc4_test.v', @@ -22,16 +21,12 @@ const ( 'vlib/net/http/http_httpbin_test.v', 'vlib/net/http/http_test.v', 'vlib/regex/regex_test.v', - 'vlib/sqlite/sqlite_test.v', // Linux only 'vlib/strconv/ftoa/f32_f64_to_string_test.v', 'vlib/v/tests/array_to_string_test.v', - 'vlib/v/tests/asm_test.v', // Linux only - 'vlib/v/tests/backtrace_test.v', // TCC only 'vlib/v/tests/enum_bitfield_test.v', 'vlib/v/tests/fixed_array_test.v', 'vlib/v/tests/fn_test.v', 'vlib/v/tests/fn_variadic_test.v', - 'vlib/v/tests/live_test.v', // Linux only 'vlib/v/tests/match_test.v', 'vlib/v/tests/msvc_test.v', 'vlib/v/tests/mut_test.v', @@ -47,6 +42,12 @@ const ( 'vlib/v/tests/valgrind/valgrind_test.v', // ubuntu-musl only 'vlib/v/tests/pointers_str_test.v', ] + skip_on_non_linux = [ + 'vlib/clipboard/clipboard_test.v', // Linux only + 'vlib/sqlite/sqlite_test.v', // Linux only + 'vlib/v/tests/asm_test.v', // Linux only + 'vlib/v/tests/live_test.v', // Linux only + ] ) fn main() { @@ -57,12 +58,14 @@ fn main() { args_string := args[1..].join(' ') cmd_prefix := args_string.all_before('test-fixed') title := 'testing all fixed tests' - all_test_files := os.walk_ext( os.join_path(vroot,'vlib'), '_test.v') testing.eheader(title) mut tsession := testing.new_test_session(cmd_prefix) tsession.files << all_test_files tsession.skip_files << skip_test_files + $if !linux { + tsession.skip_files << skip_on_non_linux + } tsession.test() eprintln(tsession.benchmark.total_message(title)) if tsession.benchmark.nfail > 0 { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 83d87bef97..e01e6fe854 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -508,6 +508,7 @@ fn (g mut Gen) write_defer_stmts() { if defer_stmt.ifdef.len > 0 { g.writeln(defer_stmt.ifdef) g.stmts(defer_stmt.stmts) + g.writeln('') g.writeln('#endif') } else { g.stmts(defer_stmt.stmts) @@ -2755,6 +2756,7 @@ fn op_to_fn_name(name string) string { fn comp_if_to_ifdef(name string) string { match name { + // platforms/os-es: 'windows' { return '_WIN32' } @@ -2785,27 +2787,36 @@ fn comp_if_to_ifdef(name string) string { 'android' { return '__ANDROID__' } - 'js' { - return '_VJS' - } 'solaris' { return '__sun' } 'haiku' { return '__haiku__' } - 'tinyc' { - return 'tinyc' - } - 'debug' { - return '_VDEBUG' - } 'linux_or_macos' { return '' } + // + 'js' { + return '_VJS' + } + // compilers: + 'tinyc' { + return '__TINYC__' + } + 'clang' { + return '__clang__' + } 'mingw' { return '__MINGW32__' } + 'msvc' { + return '_MSC_VER' + } + // other: + 'debug' { + return '_VDEBUG' + } 'glibc' { return '__GLIBC__' } @@ -3015,24 +3026,24 @@ fn (g mut Gen) comp_if(it ast.CompIf) { // NOTE: g.defer_ifdef is needed for defers called witin an ifdef // in v1 this code would be completely excluded g.defer_ifdef = if it.is_not { - '#ifndef ' + ifdef + '\n#ifndef ' + ifdef } else { - '#ifdef ' + ifdef + '\n#ifdef ' + ifdef } // println('comp if stmts $g.file.path:$it.pos.line_nr') g.stmts(it.stmts) g.defer_ifdef = '' if it.has_else { - g.writeln('#else') + g.writeln('\n#else') g.defer_ifdef = if it.is_not { - '#ifdef ' + ifdef + '\n#ifdef ' + ifdef } else { - '#ifndef ' + ifdef + '\n#ifndef ' + ifdef } g.stmts(it.else_stmts) g.defer_ifdef = '' } - g.writeln('#endif') + g.writeln('\n#endif') } fn (g mut Gen) go_stmt(node ast.GoStmt) { diff --git a/vlib/v/gen/cheaders.v b/vlib/v/gen/cheaders.v index 8a565dcdb1..0f01601352 100644 --- a/vlib/v/gen/cheaders.v +++ b/vlib/v/gen/cheaders.v @@ -54,7 +54,7 @@ const ( #define V64_PRINTFORMAT "0x%"PRIx64 #elif defined(__WIN32__) #define V64_PRINTFORMAT "0x%I64x" -#elif defined(__LINUX__) && defined(__LP64__) +#elif defined(__linux__) && defined(__LP64__) #define V64_PRINTFORMAT "0x%lx" #else #define V64_PRINTFORMAT "0x%llx"