| ... | ... | @@ -13,8 +13,8 @@ const TokenIterator = ast.Tree.TokenList.Iterator; |
| 13 | 13 | pub const Error = error{ParseError} || Allocator.Error; |
| 14 | 14 | |
| 15 | 15 | pub const Options = struct { |
| 16 | | /// Keep simple macros unexpanded and add the definitions to the ast |
| 17 | | retain_macros: bool = false, |
| 16 | // /// Keep simple macros unexpanded and add the definitions to the ast |
| 17 | // retain_macros: bool = false, |
| 18 | 18 | |
| 19 | 19 | /// Warning or error |
| 20 | 20 | warn_as_err: union(enum) { |
| ... | ... | @@ -204,12 +204,16 @@ const Parser = struct { |
| 204 | 204 | } |
| 205 | 205 | var first_dr = try parser.declarator(.Must); |
| 206 | 206 | if (first_dr != null and declaratorIsFunction(first_dr.?)) { |
| 207 | // TODO typedeffed fn proto-only |
| 207 | 208 | const dr = @fieldParentPtr(Node.Declarator, "base", first_dr.?); |
| 208 | 209 | try parser.declareSymbol(ds.type_spec, dr); |
| 209 | 210 | var old_decls = Node.FnDecl.OldDeclList.init(parser.arena); |
| 210 | 211 | const body = if (parser.eatToken(.Semicolon)) |_| |
| 211 | 212 | null |
| 212 | 213 | else blk: { |
| 214 | if (local) { |
| 215 | // TODO nested function warning |
| 216 | } |
| 213 | 217 | // TODO first_dr.is_old |
| 214 | 218 | // while (true) { |
| 215 | 219 | // var old_ds = Node.DeclSpec{}; |
| ... | ... | @@ -387,13 +391,11 @@ const Parser = struct { |
| 387 | 391 | /// / IDENTIFIER // typedef name |
| 388 | 392 | /// / TypeQual |
| 389 | 393 | fn typeSpec(parser: *Parser, type_spec: *Node.TypeSpec) !bool { |
| 390 | | while (try parser.typeQual(&type_spec.qual)) {} |
| 391 | 394 | blk: { |
| 392 | 395 | if (parser.eatToken(.Keyword_void)) |tok| { |
| 393 | 396 | if (type_spec.spec != .None) |
| 394 | 397 | break :blk; |
| 395 | 398 | type_spec.spec = .{ .Void = tok }; |
| 396 | | return true; |
| 397 | 399 | } else if (parser.eatToken(.Keyword_char)) |tok| { |
| 398 | 400 | switch (type_spec.spec) { |
| 399 | 401 | .None => { |
| ... | ... | @@ -415,7 +417,6 @@ const Parser = struct { |
| 415 | 417 | }, |
| 416 | 418 | else => break :blk, |
| 417 | 419 | } |
| 418 | | return true; |
| 419 | 420 | } else if (parser.eatToken(.Keyword_short)) |tok| { |
| 420 | 421 | switch (type_spec.spec) { |
| 421 | 422 | .None => { |
| ... | ... | @@ -437,7 +438,6 @@ const Parser = struct { |
| 437 | 438 | }, |
| 438 | 439 | else => break :blk, |
| 439 | 440 | } |
| 440 | | return true; |
| 441 | 441 | } else if (parser.eatToken(.Keyword_long)) |tok| { |
| 442 | 442 | switch (type_spec.spec) { |
| 443 | 443 | .None => { |
| ... | ... | @@ -468,7 +468,6 @@ const Parser = struct { |
| 468 | 468 | }, |
| 469 | 469 | else => break :blk, |
| 470 | 470 | } |
| 471 | | return true; |
| 472 | 471 | } else if (parser.eatToken(.Keyword_int)) |tok| { |
| 473 | 472 | switch (type_spec.spec) { |
| 474 | 473 | .None => { |
| ... | ... | @@ -495,7 +494,6 @@ const Parser = struct { |
| 495 | 494 | }, |
| 496 | 495 | else => break :blk, |
| 497 | 496 | } |
| 498 | | return true; |
| 499 | 497 | } else if (parser.eatToken(.Keyword_signed) orelse parser.eatToken(.Keyword_unsigned)) |tok| { |
| 500 | 498 | switch (type_spec.spec) { |
| 501 | 499 | .None => { |
| ... | ... | @@ -527,7 +525,6 @@ const Parser = struct { |
| 527 | 525 | }, |
| 528 | 526 | else => break :blk, |
| 529 | 527 | } |
| 530 | | return true; |
| 531 | 528 | } else if (parser.eatToken(.Keyword_float)) |tok| { |
| 532 | 529 | if (type_spec.spec != .None) |
| 533 | 530 | break :blk; |
| ... | ... | @@ -536,7 +533,6 @@ const Parser = struct { |
| 536 | 533 | .float = tok, |
| 537 | 534 | }, |
| 538 | 535 | }; |
| 539 | | return true; |
| 540 | 536 | } else if (parser.eatToken(.Keyword_double)) |tok| { |
| 541 | 537 | if (type_spec.spec != .None) |
| 542 | 538 | break :blk; |
| ... | ... | @@ -545,7 +541,6 @@ const Parser = struct { |
| 545 | 541 | .double = tok, |
| 546 | 542 | }, |
| 547 | 543 | }; |
| 548 | | return true; |
| 549 | 544 | } else if (parser.eatToken(.Keyword_complex)) |tok| { |
| 550 | 545 | switch (type_spec.spec) { |
| 551 | 546 | .None => { |
| ... | ... | @@ -568,36 +563,34 @@ const Parser = struct { |
| 568 | 563 | }, |
| 569 | 564 | else => break :blk, |
| 570 | 565 | } |
| 571 | | return true; |
| 572 | | } |
| 573 | | if (parser.eatToken(.Keyword_bool)) |tok| { |
| 566 | } else if (parser.eatToken(.Keyword_bool)) |tok| { |
| 574 | 567 | if (type_spec.spec != .None) |
| 575 | 568 | break :blk; |
| 576 | 569 | type_spec.spec = .{ .Bool = tok }; |
| 577 | | return true; |
| 578 | 570 | } else if (parser.eatToken(.Keyword_atomic)) |tok| { |
| 579 | | if (type_spec.spec != .None) |
| 580 | | break :blk; |
| 581 | | _ = try parser.expectToken(.LParen); |
| 582 | | const name = (try parser.typeName()) orelse return parser.err(.{ |
| 583 | | .ExpectedTypeName = .{ .token = parser.it.index }, |
| 584 | | }); |
| 585 | | type_spec.spec.Atomic = .{ |
| 586 | | .atomic = tok, |
| 587 | | .typename = name, |
| 588 | | .rparen = try parser.expectToken(.RParen), |
| 589 | | }; |
| 590 | | return true; |
| 571 | // might be _Atomic qualifier |
| 572 | if (parser.eatToken(.LParen)) |_| { |
| 573 | if (type_spec.spec != .None) |
| 574 | break :blk; |
| 575 | const name = (try parser.typeName()) orelse return parser.err(.{ |
| 576 | .ExpectedTypeName = .{ .token = parser.it.index }, |
| 577 | }); |
| 578 | type_spec.spec.Atomic = .{ |
| 579 | .atomic = tok, |
| 580 | .typename = name, |
| 581 | .rparen = try parser.expectToken(.RParen), |
| 582 | }; |
| 583 | } else { |
| 584 | parser.putBackToken(tok); |
| 585 | } |
| 591 | 586 | } else if (parser.eatToken(.Keyword_enum)) |tok| { |
| 592 | 587 | if (type_spec.spec != .None) |
| 593 | 588 | break :blk; |
| 594 | 589 | type_spec.spec.Enum = try parser.enumSpec(tok); |
| 595 | | return true; |
| 596 | 590 | } else if (parser.eatToken(.Keyword_union) orelse parser.eatToken(.Keyword_struct)) |tok| { |
| 597 | 591 | if (type_spec.spec != .None) |
| 598 | 592 | break :blk; |
| 599 | 593 | type_spec.spec.Record = try parser.recordSpec(tok); |
| 600 | | return true; |
| 601 | 594 | } else if (parser.eatToken(.Identifier)) |tok| { |
| 602 | 595 | const ty = parser.getSymbol(tok) orelse { |
| 603 | 596 | parser.putBackToken(tok); |
| ... | ... | @@ -637,6 +630,7 @@ const Parser = struct { |
| 637 | 630 | parser.putBackToken(tok); |
| 638 | 631 | return false; |
| 639 | 632 | } |
| 633 | return parser.typeQual(&type_spec.qual); |
| 640 | 634 | } |
| 641 | 635 | return parser.err(.{ |
| 642 | 636 | .InvalidTypeSpecifier = .{ |
| ... | ... | @@ -874,6 +868,7 @@ const Parser = struct { |
| 874 | 868 | var node: *Node.Declarator = undefined; |
| 875 | 869 | var inner_fn = false; |
| 876 | 870 | |
| 871 | // TODO sizof(int (int)) |
| 877 | 872 | // prefix |
| 878 | 873 | if (parser.eatToken(.LParen)) |lparen| { |
| 879 | 874 | const inner = (try parser.declarator(named)) orelse return parser.err(.{ |
| ... | ... | @@ -981,6 +976,7 @@ const Parser = struct { |
| 981 | 976 | var ds = Node.DeclSpec{}; |
| 982 | 977 | if (try parser.declSpec(&ds)) { |
| 983 | 978 | //TODO |
| 979 | // TODO try parser.declareSymbol(ds.type_spec, dr); |
| 984 | 980 | } else if (parser.eatToken(.Identifier)) |tok| { |
| 985 | 981 | old_style = true; |
| 986 | 982 | } else if (parser.eatToken(.Ellipsis)) |tok| { |