diff options
author | Alex Lorenz <arphaman@gmail.com> | 2023-02-23 14:14:14 -0800 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2023-02-23 14:59:26 -0800 |
commit | c8b37e48f6f00bb2aa3882ca3cc26082f85ca999 (patch) | |
tree | 5e75ac7a02846bddc0e9addf2bf87595eedea841 /clang/lib/Parse/ParseDecl.cpp | |
parent | 5a4f193afa0d73f7ec459648d8f02535577dd604 (diff) | |
download | llvm-c8b37e48f6f00bb2aa3882ca3cc26082f85ca999.zip llvm-c8b37e48f6f00bb2aa3882ca3cc26082f85ca999.tar.gz llvm-c8b37e48f6f00bb2aa3882ca3cc26082f85ca999.tar.bz2 |
[clang] extend external_source_symbol attribute with USR clause
Allow the user to specify a concrete USR in the external_source_symbol attribute.
That will let Clang's indexer to use Swift USRs for Swift declarations that are
represented with C++ declarations.
This new clause is used by Swift when generating a C++ header representation
of a Swift module:
https://github.com/apple/swift/pull/63002
Differential Revision: https://reviews.llvm.org/D141324
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 6465d859..d654cdf 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1340,6 +1340,7 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability, /// keyword-arg: /// 'language' '=' <string> /// 'defined_in' '=' <string> +/// 'USR' '=' <string> /// 'generated_declaration' void Parser::ParseExternalSourceSymbolAttribute( IdentifierInfo &ExternalSourceSymbol, SourceLocation Loc, @@ -1355,6 +1356,7 @@ void Parser::ParseExternalSourceSymbolAttribute( Ident_language = PP.getIdentifierInfo("language"); Ident_defined_in = PP.getIdentifierInfo("defined_in"); Ident_generated_declaration = PP.getIdentifierInfo("generated_declaration"); + Ident_USR = PP.getIdentifierInfo("USR"); } ExprResult Language; @@ -1362,6 +1364,8 @@ void Parser::ParseExternalSourceSymbolAttribute( ExprResult DefinedInExpr; bool HasDefinedIn = false; IdentifierLoc *GeneratedDeclaration = nullptr; + ExprResult USR; + bool HasUSR = false; // Parse the language/defined_in/generated_declaration keywords do { @@ -1383,7 +1387,8 @@ void Parser::ParseExternalSourceSymbolAttribute( continue; } - if (Keyword != Ident_language && Keyword != Ident_defined_in) { + if (Keyword != Ident_language && Keyword != Ident_defined_in && + Keyword != Ident_USR) { Diag(Tok, diag::err_external_source_symbol_expected_keyword); SkipUntil(tok::r_paren, StopAtSemi); return; @@ -1396,16 +1401,22 @@ void Parser::ParseExternalSourceSymbolAttribute( return; } - bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn; + bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn, + HadUSR = HasUSR; if (Keyword == Ident_language) HasLanguage = true; + else if (Keyword == Ident_USR) + HasUSR = true; else HasDefinedIn = true; if (Tok.isNot(tok::string_literal)) { Diag(Tok, diag::err_expected_string_literal) << /*Source='external_source_symbol attribute'*/ 3 - << /*language | source container*/ (Keyword != Ident_language); + << /*language | source container | USR*/ ( + Keyword == Ident_language + ? 0 + : (Keyword == Ident_defined_in ? 1 : 2)); SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch); continue; } @@ -1417,6 +1428,14 @@ void Parser::ParseExternalSourceSymbolAttribute( continue; } Language = ParseStringLiteralExpression(); + } else if (Keyword == Ident_USR) { + if (HadUSR) { + Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause) + << Keyword; + ParseStringLiteralExpression(); + continue; + } + USR = ParseStringLiteralExpression(); } else { assert(Keyword == Ident_defined_in && "Invalid clause keyword!"); if (HadDefinedIn) { @@ -1435,8 +1454,8 @@ void Parser::ParseExternalSourceSymbolAttribute( if (EndLoc) *EndLoc = T.getCloseLocation(); - ArgsUnion Args[] = {Language.get(), DefinedInExpr.get(), - GeneratedDeclaration}; + ArgsUnion Args[] = {Language.get(), DefinedInExpr.get(), GeneratedDeclaration, + USR.get()}; Attrs.addNew(&ExternalSourceSymbol, SourceRange(Loc, T.getCloseLocation()), ScopeName, ScopeLoc, Args, std::size(Args), Syntax); } |