[Parse] Improve macro expansion parsing

* Unify macro expansion parsing logic between MacroExpansionExpr and
  MacroExpansionDecl
* Diagnose whitespace between '#' and the macro name
* Diagnose keyword as a macro name
This commit is contained in:
Rintaro Ishizaki
2023-05-15 13:30:55 -07:00
parent 23c19333df
commit e3a0f24cfe
9 changed files with 198 additions and 86 deletions

View File

@@ -1751,6 +1751,16 @@ public:
DeclNameRef parseDeclNameRef(DeclNameLoc &loc, const Diagnostic &diag,
DeclNameOptions flags);
/// Parse macro expansion.
///
/// macro-expansion:
/// '#' identifier generic-arguments? expr-paren? trailing-closure?
ParserStatus parseFreestandingMacroExpansion(
SourceLoc &poundLoc, DeclNameLoc &macroNameLoc, DeclNameRef &macroNameRef,
SourceLoc &leftAngleLoc, SmallVectorImpl<TypeRepr *> &genericArgs,
SourceLoc &rightAngleLoc, ArgumentList *&argList, bool isExprBasic,
const Diagnostic &diag);
ParserResult<Expr> parseExprIdentifier();
Expr *parseExprEditorPlaceholder(Token PlaceholderTok,
Identifier PlaceholderId);