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
31743174 c->warnings_on = codegen->verbose;
31753175 c->import = import;
31763176 c->errors = errors;
3177 c->visib_mod = (source_node == nullptr) ? VisibModPrivate : VisibModPub;
3178 c->export_visib_mod = (source_node == nullptr) ? VisibModExport : VisibModPub;
3177 if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) {
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 }
31793184 c->decl_table.init(8);
31803185 c->macro_table.init(8);
31813186 c->ptr_params.init(8);
test/parsec.zig+18-18
......@@ -21,7 +21,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
2121 \\pub extern fn foo() -> noreturn;
2222 );
2323
24 cases.add("simple function",
24 cases.addC("simple function",
2525 \\int abs(int a) {
2626 \\ return a < 0 ? -a : a;
2727 \\}
......@@ -315,7 +315,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
315315 \\pub const LUA_GLOBALSINDEX = -10002;
316316 );
317317
318 cases.add("post increment",
318 cases.addC("post increment",
319319 \\unsigned foo1(unsigned a) {
320320 \\ a++;
321321 \\ return a;
......@@ -337,7 +337,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
337337 \\}
338338 );
339339
340 cases.add("shift right assign",
340 cases.addC("shift right assign",
341341 \\int log2(unsigned a) {
342342 \\ int i = 0;
343343 \\ while (a > 0) {
......@@ -356,7 +356,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
356356 \\}
357357 );
358358
359 cases.add("if statement",
359 cases.addC("if statement",
360360 \\int max(int a, int b) {
361361 \\ if (a < b)
362362 \\ return b;
......@@ -373,7 +373,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
373373 \\}
374374 );
375375
376 cases.add("==, !=",
376 cases.addC("==, !=",
377377 \\int max(int a, int b) {
378378 \\ if (a == b)
379379 \\ return a;
......@@ -389,7 +389,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
389389 \\}
390390 );
391391
392 cases.add("add, sub, mul, div, rem",
392 cases.addC("add, sub, mul, div, rem",
393393 \\int s(int a, int b) {
394394 \\ int c;
395395 \\ c = a + b;
......@@ -425,7 +425,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
425425 \\}
426426 );
427427
428 cases.add("bitwise binary operators",
428 cases.addC("bitwise binary operators",
429429 \\int max(int a, int b) {
430430 \\ return (a & b) ^ (a | b);
431431 \\}
......@@ -435,7 +435,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
435435 \\}
436436 );
437437
438 cases.add("logical and, logical or",
438 cases.addC("logical and, logical or",
439439 \\int max(int a, int b) {
440440 \\ if (a < b || a == b)
441441 \\ return b;
......@@ -451,7 +451,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
451451 \\}
452452 );
453453
454 cases.add("assign",
454 cases.addC("assign",
455455 \\int max(int a) {
456456 \\ int tmp;
457457 \\ tmp = a;
......@@ -466,7 +466,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
466466 \\}
467467 );
468468
469 cases.add("chaining assign",
469 cases.addC("chaining assign",
470470 \\void max(int a) {
471471 \\ int b, c;
472472 \\ c = b = a;
......@@ -483,7 +483,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
483483 \\}
484484 );
485485
486 cases.add("shift right assign with a fixed size type",
486 cases.addC("shift right assign with a fixed size type",
487487 \\#include <stdint.h>
488488 \\int log2(uint32_t a) {
489489 \\ int i = 0;
......@@ -513,7 +513,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
513513 \\pub const Two = 1;
514514 );
515515
516 cases.add("function call",
516 cases.addC("function call",
517517 \\static void bar(void) { }
518518 \\void foo(void) { bar(); }
519519 ,
......@@ -523,7 +523,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
523523 \\}
524524 );
525525
526 cases.add("field access expression",
526 cases.addC("field access expression",
527527 \\struct Foo {
528528 \\ int field;
529529 \\};
......@@ -539,7 +539,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
539539 \\}
540540 );
541541
542 cases.add("null statements",
542 cases.addC("null statements",
543543 \\void foo(void) {
544544 \\ ;;;;;
545545 \\}
......@@ -553,7 +553,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
553553 \\pub var array: [100]c_int = undefined;
554554 );
555555
556 cases.add("array access",
556 cases.addC("array access",
557557 \\int array[100];
558558 \\int foo(int index) {
559559 \\ return array[index];
......@@ -566,7 +566,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
566566 );
567567
568568
569 cases.add("c style cast",
569 cases.addC("c style cast",
570570 \\int float_to_int(float a) {
571571 \\ return (int)a;
572572 \\}
......@@ -576,7 +576,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
576576 \\}
577577 );
578578
579 cases.add("implicit cast to void *",
579 cases.addC("implicit cast to void *",
580580 \\void *foo(unsigned short *x) {
581581 \\ return x;
582582 \\}
......@@ -586,7 +586,7 @@ pub fn addCases(cases: &tests.ParseCContext) {
586586 \\}
587587 );
588588
589 cases.add("sizeof",
589 cases.addC("sizeof",
590590 \\#include <stddef.h>
591591 \\size_t size_of(void) {
592592 \\ return sizeof(int);
test/tests.zig+9-4
......@@ -916,7 +916,7 @@ pub const ParseCContext = struct {
916916 %%io.stderr.printf("\n");
917917 }
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,
920920 source: []const u8, expected_lines: ...) -> &TestCase
921921 {
922922 const tc = %%self.b.allocator.create(TestCase);
......@@ -926,7 +926,7 @@ pub const ParseCContext = struct {
926926 .expected_lines = ArrayList([]const u8).init(self.b.allocator),
927927 .allow_warnings = allow_warnings,
928928 };
929 tc.addSourceFile("source.h", source);
929 tc.addSourceFile(filename, source);
930930 comptime var arg_i = 0;
931931 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
932932 tc.addExpectedLine(expected_lines[arg_i]);
......@@ -935,12 +935,17 @@ pub const ParseCContext = struct {
935935 }
936936
937937 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);
939944 self.addCase(tc);
940945 }
941946
942947 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);
944949 self.addCase(tc);
945950 }
946951