| 723 | |
| 724 | |
| 725 | void Preprocessor::ParseDef(TokenSequence ls) { |
| 726 | ls.Next(); |
| 727 | auto ident = ls.Expect(Token::IDENTIFIER); |
| 728 | if (ident->str_ == "defined") { |
| 729 | Error(ident, "'defined' cannot be used as a macro name"); |
| 730 | } |
| 731 | auto tok = ls.Peek(); |
| 732 | if (tok->tag_ == '(' && !tok->ws_) { |
| 733 | // There is no white space between ident and '(' |
| 734 | // Hence, we are defining function-like macro |
| 735 | |
| 736 | // Parse Identifier list |
| 737 | ls.Next(); // Skip '(' |
| 738 | ParamList params; |
| 739 | auto variadic = ParseIdentList(params, ls); |
| 740 | const auto& macro = Macro(variadic, params, ls); |
| 741 | AddMacro(ident->str_, macro); |
| 742 | } |
| 743 | else { |
| 744 | AddMacro(ident->str_, Macro(ls)); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | |
| 749 | bool Preprocessor::ParseIdentList(ParamList& params, TokenSequence& is) { |