authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-01 21:42:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-01 21:42:33-04:00
log8156e4f78f1433a22077571c902b81db44b75d61
tree8591856e25b6cc6dbd0754db127b1046e8e1e2fc
parente3ea0b652c7bec25d7303d98e08cdfe1d288a9ec

fix parse-c tests


3 files changed, 34 insertions(+), 24 deletions(-)

src/parsec.cpp+7-2
...@@ -3174,8 +3174,13 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch...@@ -3174,8 +3174,13 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
3174 c->warnings_on = codegen->verbose;3174 c->warnings_on = codegen->verbose;
3175 c->import = import;3175 c->import = import;
3176 c->errors = errors;3176 c->errors = errors;
3177 c->visib_mod = (source_node == nullptr) ? VisibModPrivate : VisibModPub;3177 if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) {
3178 c->export_visib_mod = (source_node == nullptr) ? VisibModExport : VisibModPub;3178 c->visib_mod = VisibModPub;
3179 c->export_visib_mod = VisibModPub;
3180 } else {
3181 c->visib_mod = VisibModPub;
3182 c->export_visib_mod = VisibModExport;
3183 }
3179 c->decl_table.init(8);3184 c->decl_table.init(8);
3180 c->macro_table.init(8);3185 c->macro_table.init(8);
3181 c->ptr_params.init(8);3186 c->ptr_params.init(8);
test/parsec.zig+18-18
...@@ -21,7 +21,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -21,7 +21,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
21 \\pub extern fn foo() -> noreturn;21 \\pub extern fn foo() -> noreturn;
22 );22 );
2323
24 cases.add("simple function",24 cases.addC("simple function",
25 \\int abs(int a) {25 \\int abs(int a) {
26 \\ return a < 0 ? -a : a;26 \\ return a < 0 ? -a : a;
27 \\}27 \\}
...@@ -315,7 +315,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -315,7 +315,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
315 \\pub const LUA_GLOBALSINDEX = -10002;315 \\pub const LUA_GLOBALSINDEX = -10002;
316 );316 );
317317
318 cases.add("post increment",318 cases.addC("post increment",
319 \\unsigned foo1(unsigned a) {319 \\unsigned foo1(unsigned a) {
320 \\ a++;320 \\ a++;
321 \\ return a;321 \\ return a;
...@@ -337,7 +337,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -337,7 +337,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
337 \\}337 \\}
338 );338 );
339339
340 cases.add("shift right assign",340 cases.addC("shift right assign",
341 \\int log2(unsigned a) {341 \\int log2(unsigned a) {
342 \\ int i = 0;342 \\ int i = 0;
343 \\ while (a > 0) {343 \\ while (a > 0) {
...@@ -356,7 +356,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -356,7 +356,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
356 \\}356 \\}
357 );357 );
358358
359 cases.add("if statement",359 cases.addC("if statement",
360 \\int max(int a, int b) {360 \\int max(int a, int b) {
361 \\ if (a < b)361 \\ if (a < b)
362 \\ return b;362 \\ return b;
...@@ -373,7 +373,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -373,7 +373,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
373 \\}373 \\}
374 );374 );
375375
376 cases.add("==, !=",376 cases.addC("==, !=",
377 \\int max(int a, int b) {377 \\int max(int a, int b) {
378 \\ if (a == b)378 \\ if (a == b)
379 \\ return a;379 \\ return a;
...@@ -389,7 +389,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -389,7 +389,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
389 \\}389 \\}
390 );390 );
391391
392 cases.add("add, sub, mul, div, rem",392 cases.addC("add, sub, mul, div, rem",
393 \\int s(int a, int b) {393 \\int s(int a, int b) {
394 \\ int c;394 \\ int c;
395 \\ c = a + b;395 \\ c = a + b;
...@@ -425,7 +425,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -425,7 +425,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
425 \\}425 \\}
426 );426 );
427427
428 cases.add("bitwise binary operators",428 cases.addC("bitwise binary operators",
429 \\int max(int a, int b) {429 \\int max(int a, int b) {
430 \\ return (a & b) ^ (a | b);430 \\ return (a & b) ^ (a | b);
431 \\}431 \\}
...@@ -435,7 +435,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -435,7 +435,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
435 \\}435 \\}
436 );436 );
437437
438 cases.add("logical and, logical or",438 cases.addC("logical and, logical or",
439 \\int max(int a, int b) {439 \\int max(int a, int b) {
440 \\ if (a < b || a == b)440 \\ if (a < b || a == b)
441 \\ return b;441 \\ return b;
...@@ -451,7 +451,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -451,7 +451,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
451 \\}451 \\}
452 );452 );
453453
454 cases.add("assign",454 cases.addC("assign",
455 \\int max(int a) {455 \\int max(int a) {
456 \\ int tmp;456 \\ int tmp;
457 \\ tmp = a;457 \\ tmp = a;
...@@ -466,7 +466,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -466,7 +466,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
466 \\}466 \\}
467 );467 );
468468
469 cases.add("chaining assign",469 cases.addC("chaining assign",
470 \\void max(int a) {470 \\void max(int a) {
471 \\ int b, c;471 \\ int b, c;
472 \\ c = b = a;472 \\ c = b = a;
...@@ -483,7 +483,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -483,7 +483,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
483 \\}483 \\}
484 );484 );
485485
486 cases.add("shift right assign with a fixed size type",486 cases.addC("shift right assign with a fixed size type",
487 \\#include <stdint.h>487 \\#include <stdint.h>
488 \\int log2(uint32_t a) {488 \\int log2(uint32_t a) {
489 \\ int i = 0;489 \\ int i = 0;
...@@ -513,7 +513,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -513,7 +513,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
513 \\pub const Two = 1;513 \\pub const Two = 1;
514 );514 );
515515
516 cases.add("function call",516 cases.addC("function call",
517 \\static void bar(void) { }517 \\static void bar(void) { }
518 \\void foo(void) { bar(); }518 \\void foo(void) { bar(); }
519 ,519 ,
...@@ -523,7 +523,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -523,7 +523,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
523 \\}523 \\}
524 );524 );
525525
526 cases.add("field access expression",526 cases.addC("field access expression",
527 \\struct Foo {527 \\struct Foo {
528 \\ int field;528 \\ int field;
529 \\};529 \\};
...@@ -539,7 +539,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -539,7 +539,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
539 \\}539 \\}
540 );540 );
541541
542 cases.add("null statements",542 cases.addC("null statements",
543 \\void foo(void) {543 \\void foo(void) {
544 \\ ;;;;;544 \\ ;;;;;
545 \\}545 \\}
...@@ -553,7 +553,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -553,7 +553,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
553 \\pub var array: [100]c_int = undefined;553 \\pub var array: [100]c_int = undefined;
554 );554 );
555555
556 cases.add("array access",556 cases.addC("array access",
557 \\int array[100];557 \\int array[100];
558 \\int foo(int index) {558 \\int foo(int index) {
559 \\ return array[index];559 \\ return array[index];
...@@ -566,7 +566,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -566,7 +566,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
566 );566 );
567567
568568
569 cases.add("c style cast",569 cases.addC("c style cast",
570 \\int float_to_int(float a) {570 \\int float_to_int(float a) {
571 \\ return (int)a;571 \\ return (int)a;
572 \\}572 \\}
...@@ -576,7 +576,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -576,7 +576,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
576 \\}576 \\}
577 );577 );
578578
579 cases.add("implicit cast to void *",579 cases.addC("implicit cast to void *",
580 \\void *foo(unsigned short *x) {580 \\void *foo(unsigned short *x) {
581 \\ return x;581 \\ return x;
582 \\}582 \\}
...@@ -586,7 +586,7 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -586,7 +586,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
586 \\}586 \\}
587 );587 );
588588
589 cases.add("sizeof",589 cases.addC("sizeof",
590 \\#include <stddef.h>590 \\#include <stddef.h>
591 \\size_t size_of(void) {591 \\size_t size_of(void) {
592 \\ return sizeof(int);592 \\ return sizeof(int);
test/tests.zig+9-4
...@@ -916,7 +916,7 @@ pub const ParseCContext = struct {...@@ -916,7 +916,7 @@ pub const ParseCContext = struct {
916 %%io.stderr.printf("\n");916 %%io.stderr.printf("\n");
917 }917 }
918918
919 pub fn create(self: &ParseCContext, allow_warnings: bool, name: []const u8,919 pub fn create(self: &ParseCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
920 source: []const u8, expected_lines: ...) -> &TestCase920 source: []const u8, expected_lines: ...) -> &TestCase
921 {921 {
922 const tc = %%self.b.allocator.create(TestCase);922 const tc = %%self.b.allocator.create(TestCase);
...@@ -926,7 +926,7 @@ pub const ParseCContext = struct {...@@ -926,7 +926,7 @@ pub const ParseCContext = struct {
926 .expected_lines = ArrayList([]const u8).init(self.b.allocator),926 .expected_lines = ArrayList([]const u8).init(self.b.allocator),
927 .allow_warnings = allow_warnings,927 .allow_warnings = allow_warnings,
928 };928 };
929 tc.addSourceFile("source.h", source);929 tc.addSourceFile(filename, source);
930 comptime var arg_i = 0;930 comptime var arg_i = 0;
931 inline while (arg_i < expected_lines.len) : (arg_i += 1) {931 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
932 tc.addExpectedLine(expected_lines[arg_i]);932 tc.addExpectedLine(expected_lines[arg_i]);
...@@ -935,12 +935,17 @@ pub const ParseCContext = struct {...@@ -935,12 +935,17 @@ pub const ParseCContext = struct {
935 }935 }
936936
937 pub fn add(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {937 pub fn add(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
938 const tc = self.create(false, name, source, expected_lines);938 const tc = self.create(false, "source.h", name, source, expected_lines);
939 self.addCase(tc);
940 }
941
942 pub fn addC(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
943 const tc = self.create(false, "source.c", name, source, expected_lines);
939 self.addCase(tc);944 self.addCase(tc);
940 }945 }
941946
942 pub fn addAllowWarnings(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {947 pub fn addAllowWarnings(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
943 const tc = self.create(true, name, source, expected_lines);948 const tc = self.create(true, "source.h", name, source, expected_lines);
944 self.addCase(tc);949 self.addCase(tc);
945 }950 }
946951