13#ifndef LLVM_CLANG_PARSE_PARSER_H
14#define LLVM_CLANG_PARSE_PARSER_H
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/Frontend/OpenMP/OMPContext.h"
27#include "llvm/Support/Compiler.h"
28#include "llvm/Support/PrettyStackTrace.h"
29#include "llvm/Support/SaveAndRestore.h"
37 class BalancedDelimiterTracker;
38 class CorrectionCandidateCallback;
40 class DiagnosticBuilder;
43 class ParsingDeclRAIIObject;
44 class ParsingDeclSpec;
45 class ParsingDeclarator;
46 class ParsingFieldDeclarator;
47 class ColonProtectionRAIIObject;
48 class InMessageExpressionRAIIObject;
49 class PoisonSEHIdentifiersRAIIObject;
51 class ObjCTypeParamList;
52 struct OMPTraitProperty;
53 struct OMPTraitSelector;
87 unsigned short ParenCount = 0, BracketCount = 0, BraceCount = 0;
88 unsigned short MisplacedModuleBeginCount = 0;
97 enum { ScopeCacheSize = 16 };
98 unsigned NumCachedScopes;
99 Scope *ScopeCache[ScopeCacheSize];
105 *Ident___exception_code,
106 *Ident_GetExceptionCode;
109 *Ident___exception_info,
110 *Ident_GetExceptionInfo;
113 *Ident___abnormal_termination,
114 *Ident_AbnormalTermination;
160 *Ident_generated_declaration, *Ident_USR;
173 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
175 std::unique_ptr<PragmaHandler> AlignHandler;
176 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
177 std::unique_ptr<PragmaHandler> OptionsHandler;
178 std::unique_ptr<PragmaHandler> PackHandler;
179 std::unique_ptr<PragmaHandler> MSStructHandler;
180 std::unique_ptr<PragmaHandler> UnusedHandler;
181 std::unique_ptr<PragmaHandler> WeakHandler;
182 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
183 std::unique_ptr<PragmaHandler> FPContractHandler;
184 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
185 std::unique_ptr<PragmaHandler> OpenMPHandler;
186 std::unique_ptr<PragmaHandler> PCSectionHandler;
187 std::unique_ptr<PragmaHandler> MSCommentHandler;
188 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
189 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
190 std::unique_ptr<PragmaHandler> FloatControlHandler;
191 std::unique_ptr<PragmaHandler> MSPointersToMembers;
192 std::unique_ptr<PragmaHandler> MSVtorDisp;
193 std::unique_ptr<PragmaHandler> MSInitSeg;
194 std::unique_ptr<PragmaHandler> MSDataSeg;
195 std::unique_ptr<PragmaHandler> MSBSSSeg;
196 std::unique_ptr<PragmaHandler> MSConstSeg;
197 std::unique_ptr<PragmaHandler> MSCodeSeg;
198 std::unique_ptr<PragmaHandler> MSSection;
199 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
200 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
201 std::unique_ptr<PragmaHandler> MSIntrinsic;
202 std::unique_ptr<PragmaHandler> MSFunction;
203 std::unique_ptr<PragmaHandler> MSOptimize;
204 std::unique_ptr<PragmaHandler> MSFenvAccess;
205 std::unique_ptr<PragmaHandler> MSAllocText;
206 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
207 std::unique_ptr<PragmaHandler> OptimizeHandler;
208 std::unique_ptr<PragmaHandler> LoopHintHandler;
209 std::unique_ptr<PragmaHandler> UnrollHintHandler;
210 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
211 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
212 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
213 std::unique_ptr<PragmaHandler> FPHandler;
214 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
215 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
216 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
217 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
218 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
219 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
220 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
221 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
223 std::unique_ptr<CommentHandler> CommentSemaHandler;
229 bool GreaterThanIsOperator;
238 bool OpenMPDirectiveParsing =
false;
245 bool InMessageExpression;
250 bool CalledSignatureHelp =
false;
255 unsigned TemplateParameterDepth;
261 class TemplateParameterDepthRAII {
263 unsigned AddedLevels;
265 explicit TemplateParameterDepthRAII(
unsigned &Depth)
266 : Depth(Depth), AddedLevels(0) {}
268 ~TemplateParameterDepthRAII() {
269 Depth -= AddedLevels;
276 void addDepth(
unsigned D) {
280 void setAddedDepth(
unsigned D) {
281 Depth = Depth - AddedLevels + D;
285 unsigned getDepth()
const {
return Depth; }
286 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
290 AttributeFactory AttrFactory;
294 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
296 void MaybeDestroyTemplateIds() {
297 if (!TemplateIds.empty() &&
299 DestroyTemplateIds();
301 void DestroyTemplateIds();
305 struct DestroyTemplateIdAnnotationsRAIIObj {
308 DestroyTemplateIdAnnotationsRAIIObj(Parser &Self) : Self(Self) {}
309 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
313 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
325 struct AngleBracketTracker {
335 SpaceBeforeLess = 0x0,
337 NoSpaceBeforeLess = 0x1,
368 if (!Locs.empty() && Locs.back().isActive(
P)) {
369 if (Locs.back().Priority <= Prio) {
371 Locs.back().LessLoc = LessLoc;
372 Locs.back().Priority = Prio;
375 Locs.push_back({TemplateName, LessLoc, Prio,
376 P.ParenCount,
P.BracketCount,
P.BraceCount});
383 void clear(Parser &
P) {
384 while (!Locs.empty() && Locs.back().isActiveOrNested(
P))
390 Loc *getCurrent(Parser &
P) {
391 if (!Locs.empty() && Locs.back().isActive(
P))
397 AngleBracketTracker AngleBrackets;
399 IdentifierInfo *getSEHExceptKeyword();
406 bool ParsingInObjCContainer;
412 bool SkipFunctionBodies;
417 SourceLocation ExprStatementTokLoc;
420 enum class ParsedStmtContext {
423 AllowDeclarationsInC = 0x1,
425 AllowStandaloneOpenMPDirectives = 0x2,
432 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
443 Parser(Preprocessor &PP, Sema &Actions,
bool SkipFunctionBodies);
500 assert(!isTokenSpecial() &&
501 "Should consume special tokens with Consume*Token");
504 return PrevTokLocation;
510 assert(!isTokenSpecial() &&
511 "Should consume special tokens with Consume*Token");
520 Loc = PrevTokLocation;
529 return ConsumeParen();
530 if (isTokenBracket())
531 return ConsumeBracket();
533 return ConsumeBrace();
534 if (isTokenStringLiteral())
535 return ConsumeStringToken();
536 if (Tok.
is(tok::code_completion))
537 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
538 : handleUnexpectedCodeCompletionToken();
540 return ConsumeAnnotationToken();
561 bool isTokenParen()
const {
562 return Tok.
isOneOf(tok::l_paren, tok::r_paren);
565 bool isTokenBracket()
const {
566 return Tok.
isOneOf(tok::l_square, tok::r_square);
569 bool isTokenBrace()
const {
570 return Tok.
isOneOf(tok::l_brace, tok::r_brace);
573 bool isTokenStringLiteral()
const {
577 bool isTokenSpecial()
const {
578 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
579 isTokenBrace() || Tok.
is(tok::code_completion) || Tok.
isAnnotation();
584 bool isTokenEqualOrEqualTypo();
588 void UnconsumeToken(Token &Consumed) {
595 SourceLocation ConsumeAnnotationToken() {
605 SourceLocation ConsumeParen() {
606 assert(isTokenParen() &&
"wrong consume method");
607 if (Tok.
getKind() == tok::l_paren)
609 else if (ParenCount) {
610 AngleBrackets.clear(*
this);
615 return PrevTokLocation;
620 SourceLocation ConsumeBracket() {
621 assert(isTokenBracket() &&
"wrong consume method");
622 if (Tok.
getKind() == tok::l_square)
624 else if (BracketCount) {
625 AngleBrackets.clear(*
this);
631 return PrevTokLocation;
636 SourceLocation ConsumeBrace() {
637 assert(isTokenBrace() &&
"wrong consume method");
638 if (Tok.
getKind() == tok::l_brace)
640 else if (BraceCount) {
641 AngleBrackets.clear(*
this);
647 return PrevTokLocation;
654 SourceLocation ConsumeStringToken() {
655 assert(isTokenStringLiteral() &&
656 "Should only consume string literals with this method");
659 return PrevTokLocation;
667 SourceLocation ConsumeCodeCompletionToken() {
668 assert(Tok.
is(tok::code_completion));
671 return PrevTokLocation;
679 SourceLocation handleUnexpectedCodeCompletionToken();
683 void cutOffParsing() {
694 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
695 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include;
705 void initializePragmaHandlers();
708 void resetPragmaHandlers();
711 void HandlePragmaUnused();
715 void HandlePragmaVisibility();
719 void HandlePragmaPack();
723 void HandlePragmaMSStruct();
725 void HandlePragmaMSPointersToMembers();
727 void HandlePragmaMSVtorDisp();
729 void HandlePragmaMSPragma();
730 bool HandlePragmaMSSection(StringRef PragmaName,
731 SourceLocation PragmaLocation);
732 bool HandlePragmaMSSegment(StringRef PragmaName,
733 SourceLocation PragmaLocation);
734 bool HandlePragmaMSInitSeg(StringRef PragmaName,
735 SourceLocation PragmaLocation);
736 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
737 SourceLocation PragmaLocation);
738 bool HandlePragmaMSFunction(StringRef PragmaName,
739 SourceLocation PragmaLocation);
740 bool HandlePragmaMSAllocText(StringRef PragmaName,
741 SourceLocation PragmaLocation);
742 bool HandlePragmaMSOptimize(StringRef PragmaName,
743 SourceLocation PragmaLocation);
747 void HandlePragmaAlign();
751 void HandlePragmaDump();
755 void HandlePragmaWeak();
759 void HandlePragmaWeakAlias();
763 void HandlePragmaRedefineExtname();
767 void HandlePragmaFPContract();
771 void HandlePragmaFEnvAccess();
775 void HandlePragmaFEnvRound();
779 void HandlePragmaFloatControl();
783 void HandlePragmaFP();
787 void HandlePragmaOpenCLExtension();
795 bool HandlePragmaLoopHint(LoopHint &Hint);
797 bool ParsePragmaAttributeSubjectMatchRuleSet(
799 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
801 void HandlePragmaAttribute();
810 const Token &GetLookAheadToken(
unsigned N) {
811 if (N == 0 || Tok.
is(tok::eof))
return Tok;
832 "produced a valid-but-null type annotation?");
836 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
837 return static_cast<NamedDecl*
>(Tok.getAnnotationValue());
840 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
841 Tok.setAnnotationValue(ND);
844 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
845 return static_cast<IdentifierInfo*
>(Tok.getAnnotationValue());
848 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
849 Tok.setAnnotationValue(ND);
854 static ExprResult getExprAnnotation(
const Token &Tok) {
855 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
860 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
861 Tok.setAnnotationValue(ER.getAsOpaquePointer());
871 CXXScopeSpec &SS,
bool IsNewScope,
877 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
878 (Tok.is(tok::annot_template_id) &&
880 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
887 enum AnnotatedNameKind {
901 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
906 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
911 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
912 const char *&PrevSpec,
unsigned &DiagID,
917 if (Tok.getIdentifierInfo() != Ident_vector &&
918 Tok.getIdentifierInfo() != Ident_bool &&
919 Tok.getIdentifierInfo() != Ident_Bool &&
920 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
923 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
929 bool TryAltiVecVectorToken() {
931 Tok.getIdentifierInfo() != Ident_vector)
return false;
932 return TryAltiVecVectorTokenOutOfLine();
935 bool TryAltiVecVectorTokenOutOfLine();
936 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
937 const char *&PrevSpec,
unsigned &DiagID,
943 bool isObjCInstancetype() {
945 if (Tok.isAnnotation())
947 if (!Ident_instancetype)
949 return Tok.getIdentifierInfo() == Ident_instancetype;
957 bool TryKeywordIdentFallback(
bool DisableKeyword);
960 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
973 class TentativeParsingAction {
975 PreferredTypeBuilder PrevPreferredType;
977 size_t PrevTentativelyDeclaredIdentifierCount;
978 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
982 explicit TentativeParsingAction(Parser &p)
983 :
P(p), PrevPreferredType(
P.PreferredType) {
985 PrevTentativelyDeclaredIdentifierCount =
986 P.TentativelyDeclaredIdentifiers.size();
987 PrevParenCount =
P.ParenCount;
988 PrevBracketCount =
P.BracketCount;
989 PrevBraceCount =
P.BraceCount;
990 P.PP.EnableBacktrackAtThisPos();
994 assert(isActive &&
"Parsing action was finished!");
995 P.TentativelyDeclaredIdentifiers.resize(
996 PrevTentativelyDeclaredIdentifierCount);
997 P.PP.CommitBacktrackedTokens();
1001 assert(isActive &&
"Parsing action was finished!");
1003 P.PreferredType = PrevPreferredType;
1005 P.TentativelyDeclaredIdentifiers.resize(
1006 PrevTentativelyDeclaredIdentifierCount);
1007 P.ParenCount = PrevParenCount;
1008 P.BracketCount = PrevBracketCount;
1009 P.BraceCount = PrevBraceCount;
1012 ~TentativeParsingAction() {
1013 assert(!isActive &&
"Forgot to call Commit or Revert!");
1018 class RevertingTentativeParsingAction
1019 :
private Parser::TentativeParsingAction {
1021 RevertingTentativeParsingAction(Parser &P)
1022 : Parser::TentativeParsingAction(
P) {}
1023 ~RevertingTentativeParsingAction() { Revert(); }
1026 class UnannotatedTentativeParsingAction;
1033 ObjCContainerDecl *DC;
1034 SaveAndRestore<bool> WithinObjCContainer;
1036 explicit ObjCDeclContextSwitch(Parser &p)
1038 WithinObjCContainer(
P.ParsingInObjCContainer, DC != nullptr) {
1040 P.Actions.ActOnObjCTemporaryExitContainerContext(DC);
1042 ~ObjCDeclContextSwitch() {
1044 P.Actions.ActOnObjCReenterContainerContext(DC);
1057 unsigned Diag = diag::err_expected,
1058 StringRef DiagMsg =
"");
1065 bool ExpectAndConsumeSemi(
unsigned DiagID , StringRef TokenUsed =
"");
1068 enum ExtraSemiKind {
1069 OutsideFunction = 0,
1071 InstanceVariableList = 2,
1072 AfterMemberFunctionDefinition = 3
1084 bool expectIdentifier();
1087 enum class CompoundToken {
1102 void checkCompoundToken(SourceLocation FirstTokLoc,
1125 bool BeforeCompoundStmt =
false)
1127 if (EnteredScope && !BeforeCompoundStmt)
1130 if (BeforeCompoundStmt)
1133 this->Self =
nullptr;
1155 unsigned NumScopes = 0;
1187 class ParseScopeFlags {
1190 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
1191 void operator=(
const ParseScopeFlags &) =
delete;
1194 ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
1202 DiagnosticBuilder
Diag(SourceLocation Loc,
unsigned DiagID);
1203 DiagnosticBuilder
Diag(
const Token &Tok,
unsigned DiagID);
1205 return Diag(Tok, DiagID);
1226 static_cast<unsigned>(R));
1268 struct ParsingClass;
1278 class LateParsedDeclaration {
1280 virtual ~LateParsedDeclaration();
1282 virtual void ParseLexedMethodDeclarations();
1283 virtual void ParseLexedMemberInitializers();
1284 virtual void ParseLexedMethodDefs();
1285 virtual void ParseLexedAttributes();
1286 virtual void ParseLexedPragmas();
1291 class LateParsedClass :
public LateParsedDeclaration {
1293 LateParsedClass(
Parser *
P, ParsingClass *
C);
1294 ~LateParsedClass()
override;
1296 void ParseLexedMethodDeclarations()
override;
1297 void ParseLexedMemberInitializers()
override;
1298 void ParseLexedMethodDefs()
override;
1299 void ParseLexedAttributes()
override;
1300 void ParseLexedPragmas()
override;
1304 ParsingClass *Class;
1313 struct LateParsedAttribute :
public LateParsedDeclaration {
1316 IdentifierInfo &AttrName;
1317 IdentifierInfo *MacroII =
nullptr;
1318 SourceLocation AttrNameLoc;
1319 SmallVector<Decl*, 2> Decls;
1321 explicit LateParsedAttribute(Parser *
P, IdentifierInfo &Name,
1323 : Self(
P), AttrName(Name), AttrNameLoc(Loc) {}
1325 void ParseLexedAttributes()
override;
1327 void addDecl(Decl *D) { Decls.push_back(D); }
1334 class LateParsedPragma :
public LateParsedDeclaration {
1335 Parser *Self =
nullptr;
1341 : Self(
P), AS(AS) {}
1343 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1347 void ParseLexedPragmas()
override;
1351 class LateParsedAttrList:
public SmallVector<LateParsedAttribute *, 2> {
1353 LateParsedAttrList(
bool PSoon =
false) : ParseSoon(PSoon) { }
1355 bool parseSoon() {
return ParseSoon; }
1364 struct LexedMethod :
public LateParsedDeclaration {
1369 explicit LexedMethod(Parser *
P, Decl *MD) : Self(
P), D(MD) {}
1371 void ParseLexedMethodDefs()
override;
1378 struct LateParsedDefaultArgument {
1379 explicit LateParsedDefaultArgument(Decl *
P,
1380 std::unique_ptr<CachedTokens> Toks =
nullptr)
1381 : Param(
P), Toks(
std::move(Toks)) { }
1390 std::unique_ptr<CachedTokens> Toks;
1397 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1398 explicit LateParsedMethodDeclaration(Parser *
P, Decl *M)
1399 : Self(
P), Method(M), ExceptionSpecTokens(nullptr) {}
1401 void ParseLexedMethodDeclarations()
override;
1413 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1423 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1424 LateParsedMemberInitializer(Parser *
P, Decl *FD)
1427 void ParseLexedMemberInitializers()
override;
1445 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
1450 struct ParsingClass {
1451 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
1452 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
1453 TagOrTemplate(TagOrTemplate) {}
1457 bool TopLevelClass : 1;
1460 bool IsInterface : 1;
1463 Decl *TagOrTemplate;
1468 LateParsedDeclarationsContainer LateParsedDeclarations;
1474 std::stack<ParsingClass *> ClassStack;
1476 ParsingClass &getCurrentClass() {
1477 assert(!ClassStack.empty() &&
"No lexed method stacks!");
1478 return *ClassStack.top();
1482 class ParsingClassDefinition {
1488 ParsingClassDefinition(Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
1491 State(
P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1496 assert(!Popped &&
"Nested class has already been popped");
1498 P.PopParsingClass(State);
1501 ~ParsingClassDefinition() {
1503 P.PopParsingClass(State);
1510 struct ParsedTemplateInfo {
1511 ParsedTemplateInfo() :
Kind(NonTemplate), TemplateParams(nullptr) {}
1514 bool isSpecialization,
1515 bool lastParameterListWasEmpty =
false)
1516 :
Kind(isSpecialization? ExplicitSpecialization : Template),
1517 TemplateParams(TemplateParams),
1518 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1520 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1521 SourceLocation TemplateLoc)
1522 :
Kind(ExplicitInstantiation), TemplateParams(nullptr),
1523 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1524 LastParameterListWasEmpty(
false){ }
1533 ExplicitSpecialization,
1535 ExplicitInstantiation
1544 SourceLocation ExternLoc;
1548 SourceLocation TemplateLoc;
1551 bool LastParameterListWasEmpty;
1557 struct ReenterTemplateScopeRAII;
1558 struct ReenterClassScopeRAII;
1560 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
1561 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1563 static
void LateTemplateParserCallback(
void *
P, LateParsedTemplate &LPT);
1565 Sema::ParsingClassState
1566 PushParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
1567 void DeallocateParsedClasses(ParsingClass *Class);
1568 void PopParsingClass(Sema::ParsingClassState);
1570 enum CachedInitKind {
1571 CIK_DefaultArgument,
1572 CIK_DefaultInitializer
1576 const ParsedAttributesView &AccessAttrs,
1577 ParsingDeclarator &D,
1578 const ParsedTemplateInfo &TemplateInfo,
1579 const VirtSpecifiers &VS,
1580 SourceLocation PureSpecLoc);
1581 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1582 void ParseLexedAttributes(ParsingClass &Class);
1583 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1585 void ParseLexedAttribute(LateParsedAttribute &LA,
1587 void ParseLexedMethodDeclarations(ParsingClass &Class);
1588 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1589 void ParseLexedMethodDefs(ParsingClass &Class);
1590 void ParseLexedMethodDef(LexedMethod &LM);
1591 void ParseLexedMemberInitializers(ParsingClass &Class);
1592 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1593 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
1594 void ParseLexedPragmas(ParsingClass &Class);
1595 void ParseLexedPragma(LateParsedPragma &LP);
1596 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1597 bool ConsumeAndStoreInitializer(
CachedTokens &Toks, CachedInitKind CIK);
1602 bool ConsumeFinalToken =
true) {
1603 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1608 bool ConsumeFinalToken =
true);
1612 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
1613 ParsedAttributes &DeclSpecAttrs,
1614 ParsingDeclSpec *DS =
nullptr);
1615 bool isDeclarationAfterDeclarator();
1616 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1618 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
1620 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
1621 ParsedAttributes &DeclSpecAttrs,
1622 ParsingDeclSpec &DS,
1625 void SkipFunctionBody();
1626 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1627 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1628 LateParsedAttrList *LateParsedAttrs =
nullptr);
1629 void ParseKNRParamDeclarations(Declarator &D);
1631 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1632 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1636 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
1637 ParsedAttributes &DeclSpecAttrs);
1638 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1639 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1640 ParsedAttributes &prefixAttrs);
1641 class ObjCTypeParamListScope;
1642 ObjCTypeParamList *parseObjCTypeParamList();
1643 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1644 ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1645 SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1646 SourceLocation &rAngleLoc,
bool mayBeProtocolList =
true);
1648 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
1649 SourceLocation atLoc,
1651 SmallVectorImpl<Decl *> &AllIvarDecls,
1652 bool RBraceMissing);
1653 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
1655 SourceLocation atLoc);
1656 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &
P,
1657 SmallVectorImpl<SourceLocation> &PLocs,
1658 bool WarnOnDeclarations,
1659 bool ForObjCContainer,
1660 SourceLocation &LAngleLoc,
1661 SourceLocation &EndProtoLoc,
1662 bool consumeLastToken);
1667 void parseObjCTypeArgsOrProtocolQualifiers(
1669 SourceLocation &typeArgsLAngleLoc,
1670 SmallVectorImpl<ParsedType> &typeArgs,
1671 SourceLocation &typeArgsRAngleLoc,
1672 SourceLocation &protocolLAngleLoc,
1673 SmallVectorImpl<Decl *> &protocols,
1674 SmallVectorImpl<SourceLocation> &protocolLocs,
1675 SourceLocation &protocolRAngleLoc,
1676 bool consumeLastToken,
1677 bool warnOnIncompleteProtocols);
1681 void parseObjCTypeArgsAndProtocolQualifiers(
1683 SourceLocation &typeArgsLAngleLoc,
1684 SmallVectorImpl<ParsedType> &typeArgs,
1685 SourceLocation &typeArgsRAngleLoc,
1686 SourceLocation &protocolLAngleLoc,
1687 SmallVectorImpl<Decl *> &protocols,
1688 SmallVectorImpl<SourceLocation> &protocolLocs,
1689 SourceLocation &protocolRAngleLoc,
1690 bool consumeLastToken);
1694 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1698 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1700 bool consumeLastToken,
1701 SourceLocation &endLoc);
1705 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1706 ParsedAttributes &prefixAttrs);
1708 struct ObjCImplParsingDataRAII {
1712 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1713 LateParsedObjCMethodContainer LateParsedObjCMethods;
1715 ObjCImplParsingDataRAII(Parser &parser, Decl *D)
1716 :
P(parser), Dcl(D), HasCFunction(
false) {
1717 P.CurParsedObjCImpl =
this;
1720 ~ObjCImplParsingDataRAII();
1722 void finish(SourceRange AtEnd);
1723 bool isFinished()
const {
return Finished; }
1728 ObjCImplParsingDataRAII *CurParsedObjCImpl;
1729 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
1731 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
1732 ParsedAttributes &Attrs);
1734 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1735 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1736 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1738 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1741 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1742 objc_nonnull, objc_nullable, objc_null_unspecified,
1745 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1747 bool isTokIdentifier_in()
const;
1750 ParsedAttributes *ParamAttrs);
1751 Decl *ParseObjCMethodPrototype(
1753 bool MethodDefinition =
true);
1756 bool MethodDefinition=
true);
1757 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1759 Decl *ParseObjCMethodDefinition();
1785 unsigned &NumLineToksConsumed,
1786 bool IsUnevaluated);
1798 enum CastParseKind {
1803 ExprResult ParseCastExpression(CastParseKind ParseKind,
1804 bool isAddressOfOperand,
1807 bool isVectorLiteral =
false,
1808 bool *NotPrimaryExpression =
nullptr);
1809 ExprResult ParseCastExpression(CastParseKind ParseKind,
1810 bool isAddressOfOperand =
false,
1812 bool isVectorLiteral =
false,
1813 bool *NotPrimaryExpression =
nullptr);
1816 bool isNotExpressionStart();
1820 bool isPostfixExpressionSuffixStart() {
1822 return (K == tok::l_square || K == tok::l_paren ||
1823 K == tok::period || K == tok::arrow ||
1824 K == tok::plusplus || K == tok::minusminus);
1827 bool diagnoseUnknownTemplateId(
ExprResult TemplateName, SourceLocation
Less);
1828 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
1829 bool checkPotentialAngleBracketDelimiter(
const AngleBracketTracker::Loc &,
1830 const Token &OpToken);
1831 bool checkPotentialAngleBracketDelimiter(
const Token &OpToken) {
1832 if (
auto *Info = AngleBrackets.getCurrent(*
this))
1833 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
1838 ExprResult ParseUnaryExprOrTypeTraitExpression();
1840 ExprResult ParseSYCLUniqueStableNameExpression();
1842 ExprResult ParseExprAfterUnaryExprOrTypeTrait(
const Token &OpTok,
1845 SourceRange &CastRange);
1848 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1849 llvm::function_ref<
void()> ExpressionStarts =
1850 llvm::function_ref<
void()>(),
1851 bool FailImmediatelyOnInvalidExpr =
false,
1852 bool EarlyTypoCorrection =
false);
1856 bool ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs);
1859 enum ParenParseOption {
1866 ExprResult ParseParenExpression(ParenParseOption &ExprType,
1867 bool stopIfCastExpr,
1870 SourceLocation &RParenLoc);
1873 ParenParseOption &ExprType,
ParsedType &CastTy,
1876 SourceLocation LParenLoc,
1877 SourceLocation RParenLoc);
1879 ExprResult ParseGenericSelectionExpression();
1887 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
1888 Token &Replacement);
1889 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
1891 bool areTokensAdjacent(
const Token &A,
const Token &B);
1893 void CheckForTemplateAndDigraph(Token &Next,
ParsedType ObjectTypePtr,
1894 bool EnteringContext, IdentifierInfo &II,
1897 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1899 bool ObjectHasErrors,
1900 bool EnteringContext,
1901 bool *MayBePseudoDestructor =
nullptr,
1902 bool IsTypename =
false,
1903 IdentifierInfo **LastII =
nullptr,
1904 bool OnlyNamespace =
false,
1905 bool InUsingDeclaration =
false);
1911 enum class LambdaIntroducerTentativeParse {
1928 ParseLambdaIntroducer(LambdaIntroducer &Intro,
1929 LambdaIntroducerTentativeParse *Tentative =
nullptr);
1930 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
1949 ExprResult ParseCXXPseudoDestructor(Expr *
Base, SourceLocation OpLoc,
1964 SourceRange &SpecificationRange,
1965 SmallVectorImpl<ParsedType> &DynamicExceptions,
1966 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
1972 SourceRange &SpecificationRange,
1973 SmallVectorImpl<ParsedType> &Exceptions,
1974 SmallVectorImpl<SourceRange> &Ranges);
1978 TypeResult ParseTrailingReturnType(SourceRange &Range,
1979 bool MayBeFollowedByDirectInit);
1987 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
1992 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1994 bool ParseCXXTypeSpecifierSeq(
1999 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
2001 void ParseDirectNewDeclarator(Declarator &D);
2002 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
2003 ExprResult ParseCXXDeleteExpression(
bool UseGlobal,
2004 SourceLocation Start);
2008 struct ForRangeInfo;
2009 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
2013 ForRangeInfo *FRI =
nullptr,
2014 bool EnterForConditionScope =
false);
2016 ParsedAttributes &Attrs);
2027 void ParseTrailingRequiresClause(Declarator &D);
2037 if (Tok.isNot(tok::l_brace))
2039 return ParseBraceInitializer();
2041 bool MayBeDesignationStart();
2043 struct DesignatorCompletionInfo {
2044 SmallVectorImpl<Expr *> &InitExprs;
2045 QualType PreferredBaseType;
2047 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
2056 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
2057 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
2058 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
2059 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
2060 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
2061 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
2062 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
2063 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
2064 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
2065 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
2066 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
2067 bool isSimpleObjCMessageExpression();
2069 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
2070 SourceLocation SuperLoc,
2072 Expr *ReceiverExpr);
2073 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
2074 SourceLocation LBracloc, SourceLocation SuperLoc,
2075 ParsedType ReceiverType, Expr *ReceiverExpr);
2076 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
2082 typedef SmallVector<Expr*, 12> ExprVector;
2085 ParseStatement(SourceLocation *TrailingElseLoc =
nullptr,
2086 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt);
2088 StmtVector &Stmts, ParsedStmtContext StmtCtx,
2089 SourceLocation *TrailingElseLoc =
nullptr);
2090 StmtResult ParseStatementOrDeclarationAfterAttributes(
2091 StmtVector &Stmts, ParsedStmtContext StmtCtx,
2092 SourceLocation *TrailingElseLoc, ParsedAttributes &DeclAttrs,
2093 ParsedAttributes &DeclSpecAttrs);
2094 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
2095 StmtResult ParseLabeledStatement(ParsedAttributes &Attrs,
2096 ParsedStmtContext StmtCtx);
2097 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
2098 bool MissingCase =
false,
2100 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
2101 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
2102 StmtResult ParseCompoundStatement(
bool isStmtExpr,
2103 unsigned ScopeFlags);
2104 void ParseCompoundStatementLeadingPragmas();
2105 void DiagnoseLabelAtEndOfCompoundStatement();
2107 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
2108 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
2109 Sema::ConditionResult &CondResult,
2111 SourceLocation &LParenLoc,
2112 SourceLocation &RParenLoc);
2113 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
2114 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
2115 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
2117 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
2123 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
2125 SourceLocation *TrailingElseLoc,
2126 ParsedAttributes &Attrs);
2130 enum IfExistsBehavior {
2142 struct IfExistsCondition {
2144 SourceLocation KeywordLoc;
2157 IfExistsBehavior Behavior;
2160 bool ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result);
2161 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
2162 void ParseMicrosoftIfExistsExternalDeclaration();
2163 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2164 ParsedAttributes &AccessAttrs,
2166 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
2168 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
2169 SmallVectorImpl<Expr *> &Constraints,
2170 SmallVectorImpl<Expr *> &Exprs);
2176 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc,
bool FnTry =
false);
2177 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
2183 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
2184 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
2190 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
2191 ParsedStmtContext StmtCtx);
2192 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
2193 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
2194 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
2195 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
2204 enum class DeclSpecContext {
2209 DSC_alias_declaration,
2214 DSC_template_type_arg,
2215 DSC_objc_method_result,
2223 static bool isTypeSpecifier(DeclSpecContext DSC) {
2225 case DeclSpecContext::DSC_normal:
2226 case DeclSpecContext::DSC_template_param:
2227 case DeclSpecContext::DSC_template_arg:
2228 case DeclSpecContext::DSC_class:
2229 case DeclSpecContext::DSC_top_level:
2230 case DeclSpecContext::DSC_objc_method_result:
2231 case DeclSpecContext::DSC_condition:
2234 case DeclSpecContext::DSC_template_type_arg:
2235 case DeclSpecContext::DSC_type_specifier:
2236 case DeclSpecContext::DSC_conv_operator:
2237 case DeclSpecContext::DSC_trailing:
2238 case DeclSpecContext::DSC_alias_declaration:
2239 case DeclSpecContext::DSC_association:
2242 llvm_unreachable(
"Missing DeclSpecContext case");
2246 enum class AllowDefiningTypeSpec {
2263 static AllowDefiningTypeSpec
2264 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
2266 case DeclSpecContext::DSC_normal:
2267 case DeclSpecContext::DSC_class:
2268 case DeclSpecContext::DSC_top_level:
2269 case DeclSpecContext::DSC_alias_declaration:
2270 case DeclSpecContext::DSC_objc_method_result:
2271 return AllowDefiningTypeSpec::Yes;
2273 case DeclSpecContext::DSC_condition:
2274 case DeclSpecContext::DSC_template_param:
2275 return AllowDefiningTypeSpec::YesButInvalid;
2277 case DeclSpecContext::DSC_template_type_arg:
2278 case DeclSpecContext::DSC_type_specifier:
2279 return AllowDefiningTypeSpec::NoButErrorRecovery;
2281 case DeclSpecContext::DSC_association:
2282 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
2283 : AllowDefiningTypeSpec::Yes;
2285 case DeclSpecContext::DSC_trailing:
2286 case DeclSpecContext::DSC_conv_operator:
2287 case DeclSpecContext::DSC_template_arg:
2288 return AllowDefiningTypeSpec::No;
2290 llvm_unreachable(
"Missing DeclSpecContext case");
2294 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
2296 case DeclSpecContext::DSC_normal:
2297 case DeclSpecContext::DSC_class:
2298 case DeclSpecContext::DSC_top_level:
2301 case DeclSpecContext::DSC_alias_declaration:
2302 case DeclSpecContext::DSC_objc_method_result:
2303 case DeclSpecContext::DSC_condition:
2304 case DeclSpecContext::DSC_template_param:
2305 case DeclSpecContext::DSC_template_type_arg:
2306 case DeclSpecContext::DSC_type_specifier:
2307 case DeclSpecContext::DSC_trailing:
2308 case DeclSpecContext::DSC_association:
2309 case DeclSpecContext::DSC_conv_operator:
2310 case DeclSpecContext::DSC_template_arg:
2314 llvm_unreachable(
"Missing DeclSpecContext case");
2319 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
2321 case DeclSpecContext::DSC_normal:
2322 case DeclSpecContext::DSC_template_param:
2323 case DeclSpecContext::DSC_template_arg:
2324 case DeclSpecContext::DSC_class:
2325 case DeclSpecContext::DSC_top_level:
2326 case DeclSpecContext::DSC_condition:
2327 case DeclSpecContext::DSC_type_specifier:
2328 case DeclSpecContext::DSC_association:
2329 case DeclSpecContext::DSC_conv_operator:
2332 case DeclSpecContext::DSC_objc_method_result:
2333 case DeclSpecContext::DSC_template_type_arg:
2334 case DeclSpecContext::DSC_trailing:
2335 case DeclSpecContext::DSC_alias_declaration:
2338 llvm_unreachable(
"Missing DeclSpecContext case");
2343 getImplicitTypenameContext(DeclSpecContext DSC) {
2345 case DeclSpecContext::DSC_class:
2346 case DeclSpecContext::DSC_top_level:
2347 case DeclSpecContext::DSC_type_specifier:
2348 case DeclSpecContext::DSC_template_type_arg:
2349 case DeclSpecContext::DSC_trailing:
2350 case DeclSpecContext::DSC_alias_declaration:
2351 case DeclSpecContext::DSC_template_param:
2354 case DeclSpecContext::DSC_normal:
2355 case DeclSpecContext::DSC_objc_method_result:
2356 case DeclSpecContext::DSC_condition:
2357 case DeclSpecContext::DSC_template_arg:
2358 case DeclSpecContext::DSC_conv_operator:
2359 case DeclSpecContext::DSC_association:
2362 llvm_unreachable(
"Missing DeclSpecContext case");
2367 struct ForRangeInit {
2368 SourceLocation ColonLoc;
2371 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
2373 struct ForRangeInfo : ForRangeInit {
2378 SourceLocation &DeclEnd,
2379 ParsedAttributes &DeclAttrs,
2380 ParsedAttributes &DeclSpecAttrs,
2381 SourceLocation *DeclSpecStart =
nullptr);
2384 ParsedAttributes &DeclAttrs,
2385 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
2386 ForRangeInit *FRI =
nullptr,
2387 SourceLocation *DeclSpecStart =
nullptr);
2390 ParsedAttributes &Attrs,
2391 SourceLocation *DeclEnd =
nullptr,
2392 ForRangeInit *FRI =
nullptr);
2393 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
2394 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
2395 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
2396 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
2398 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2399 ForRangeInit *FRI =
nullptr);
2400 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
2401 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
2407 bool trySkippingFunctionBody();
2409 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
2410 const ParsedTemplateInfo &TemplateInfo,
2412 ParsedAttributes &Attrs);
2415 void ParseDeclarationSpecifiers(
2417 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2419 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
2420 LateParsedAttrList *LateAttrs =
nullptr) {
2421 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
2422 getImplicitTypenameContext(DSC));
2424 void ParseDeclarationSpecifiers(
2425 DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS,
2426 DeclSpecContext DSC, LateParsedAttrList *LateAttrs,
2429 bool DiagnoseMissingSemiAfterTagDefinition(
2431 LateParsedAttrList *LateAttrs =
nullptr);
2433 void ParseSpecifierQualifierList(
2435 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
2436 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
2439 void ParseSpecifierQualifierList(
2442 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
2444 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
2447 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2448 const ParsedTemplateInfo &TemplateInfo,
2450 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
2451 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2452 RecordDecl *TagDecl);
2454 void ParseStructDeclaration(
2455 ParsingDeclSpec &DS,
2456 llvm::function_ref<
void(ParsingFieldDeclarator &)> FieldsCallback);
2461 bool DisambiguatingWithExpression =
false);
2462 bool isTypeSpecifierQualifier();
2467 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2472 bool isKnownToBeDeclarationSpecifier() {
2485 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
2487 return isCXXDeclarationStatement(DisambiguatingWithExpression);
2495 bool isForInitDeclaration() {
2499 return Tok.is(tok::kw_using) ||
2500 isCXXSimpleDeclaration(
true);
2505 bool isForRangeIdentifier();
2509 bool isStartOfObjCClassMessageMissingOpenBracket();
2514 bool isConstructorDeclarator(
2517 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2521 enum TentativeCXXTypeIdContext {
2524 TypeIdAsTemplateArgument
2531 bool isTypeIdInParens(
bool &isAmbiguous) {
2533 return isCXXTypeId(TypeIdInParens, isAmbiguous);
2534 isAmbiguous =
false;
2535 return isTypeSpecifierQualifier();
2537 bool isTypeIdInParens() {
2539 return isTypeIdInParens(isAmbiguous);
2545 bool isTypeIdUnambiguously() {
2548 return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
2549 return isTypeSpecifierQualifier();
2555 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
2562 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
2571 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
2575 struct ConditionDeclarationOrInitStatementState;
2576 enum class ConditionOrInitStatement {
2586 ConditionOrInitStatement
2587 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
2588 bool CanBeForRangeDecl);
2590 bool isCXXTypeId(TentativeCXXTypeIdContext Context,
bool &isAmbiguous);
2591 bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
2593 return isCXXTypeId(Context, isAmbiguous);
2598 enum class TPResult {
2599 True, False, Ambiguous,
Error
2609 bool isEnumBase(
bool AllowSemi);
2620 TPResult BracedCastResult = TPResult::False,
2621 bool *InvalidAsDeclSpec =
nullptr);
2626 bool isCXXDeclarationSpecifierAType();
2631 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
2636 TPResult isExplicitBool();
2641 bool isTentativelyDeclared(IdentifierInfo *II);
2650 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
2651 TPResult TryParseTypeofSpecifier();
2652 TPResult TryParseProtocolQualifiers();
2653 TPResult TryParsePtrOperatorSeq();
2654 TPResult TryParseOperatorId();
2655 TPResult TryParseInitDeclaratorList();
2656 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
2657 bool mayHaveDirectInit =
false);
2658 TPResult TryParseParameterDeclarationClause(
2659 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
2662 TPResult TryParseFunctionDeclarator();
2663 TPResult TryParseBracketDeclarator();
2664 TPResult TryConsumeDeclarationSpecifier();
2668 bool TrySkipAttributes();
2672 void DiagnoseBitIntUse(
const Token &Tok);
2679 ParsedAttributes *Attrs =
nullptr);
2682 void ParseBlockId(SourceLocation CaretLoc);
2685 bool standardAttributesAllowed()
const {
2687 return LO.DoubleSquareBracketAttributes;
2692 bool CheckProhibitedCXX11Attribute() {
2693 assert(Tok.is(tok::l_square));
2694 if (!standardAttributesAllowed() ||
NextToken().isNot(tok::l_square))
2696 return DiagnoseProhibitedCXX11Attribute();
2699 bool DiagnoseProhibitedCXX11Attribute();
2700 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2701 SourceLocation CorrectLocation) {
2702 if (!standardAttributesAllowed())
2704 if ((Tok.isNot(tok::l_square) ||
NextToken().isNot(tok::l_square)) &&
2705 Tok.isNot(tok::kw_alignas))
2707 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2709 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2710 SourceLocation CorrectLocation);
2712 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2716 void ProhibitAttributes(ParsedAttributes &Attrs,
2717 SourceLocation FixItLoc = SourceLocation()) {
2718 if (Attrs.Range.isInvalid())
2720 DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc);
2724 void ProhibitAttributes(ParsedAttributesView &Attrs,
2725 SourceLocation FixItLoc = SourceLocation()) {
2726 if (Attrs.Range.isInvalid())
2728 DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc);
2729 Attrs.clearListOnly();
2731 void DiagnoseProhibitedAttributes(
const SourceRange &Range,
2732 SourceLocation FixItLoc);
2740 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned DiagID,
2741 bool DiagnoseEmptyAttrs =
false,
2742 bool WarnOnUnknownAttrs =
false);
2747 SourceLocation SkipCXX11Attributes();
2751 void DiagnoseAndSkipCXX11Attributes();
2755 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2762 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2763 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2764 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2767 enum ParseAttrKindMask {
2769 PAKM_Declspec = 1 << 1,
2770 PAKM_CXX11 = 1 << 2,
2787 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2788 LateParsedAttrList *LateAttrs =
nullptr);
2791 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2792 LateParsedAttrList *LateAttrs =
nullptr) {
2793 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2794 (standardAttributesAllowed() && isCXX11AttributeSpecifier())) {
2795 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2801 void MaybeParseGNUAttributes(Declarator &D,
2802 LateParsedAttrList *LateAttrs =
nullptr) {
2803 if (Tok.is(tok::kw___attribute)) {
2804 ParsedAttributes Attrs(AttrFactory);
2805 ParseGNUAttributes(Attrs, LateAttrs, &D);
2806 D.takeAttributes(Attrs);
2810 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2811 LateParsedAttrList *LateAttrs =
nullptr) {
2812 if (Tok.is(tok::kw___attribute)) {
2813 ParseGNUAttributes(Attrs, LateAttrs);
2819 void ParseGNUAttributes(ParsedAttributes &Attrs,
2820 LateParsedAttrList *LateAttrs =
nullptr,
2821 Declarator *D =
nullptr);
2822 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2823 SourceLocation AttrNameLoc,
2824 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2825 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2827 IdentifierLoc *ParseIdentifierLoc();
2830 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2831 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2832 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2835 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
2838 if (!OpenMPTokens.empty()) {
2840 PP.EnterTokenStream(OpenMPTokens,
true,
2845 void MaybeParseCXX11Attributes(Declarator &D) {
2846 if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
2847 ParsedAttributes Attrs(AttrFactory);
2848 ParseCXX11Attributes(Attrs);
2849 D.takeAttributes(Attrs);
2853 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2854 bool OuterMightBeMessageSend =
false) {
2855 if (standardAttributesAllowed() &&
2856 isCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2857 ParseCXX11Attributes(Attrs);
2863 void ParseOpenMPAttributeArgs(IdentifierInfo *AttrName,
2866 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
2868 SourceLocation *EndLoc =
nullptr);
2869 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
2870 SourceLocation *EndLoc =
nullptr) {
2872 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
2873 ReplayOpenMPAttributeTokens(OpenMPTokens);
2875 void ParseCXX11Attributes(ParsedAttributes &attrs);
2878 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2879 SourceLocation AttrNameLoc,
2880 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2881 IdentifierInfo *ScopeName,
2882 SourceLocation ScopeLoc,
2885 IdentifierInfo *TryParseCXX11AttributeIdentifier(
2886 SourceLocation &Loc,
2888 const IdentifierInfo *EnclosingScope =
nullptr);
2890 void MaybeParseHLSLSemantics(Declarator &D,
2891 SourceLocation *EndLoc =
nullptr) {
2892 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLSemantics is for HLSL only");
2893 if (Tok.is(tok::colon)) {
2894 ParsedAttributes Attrs(AttrFactory);
2895 ParseHLSLSemantics(Attrs, EndLoc);
2896 D.takeAttributes(Attrs);
2900 void MaybeParseHLSLSemantics(ParsedAttributes &Attrs,
2901 SourceLocation *EndLoc =
nullptr) {
2902 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLSemantics is for HLSL only");
2904 ParseHLSLSemantics(Attrs, EndLoc);
2907 void ParseHLSLSemantics(ParsedAttributes &Attrs,
2908 SourceLocation *EndLoc =
nullptr);
2909 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd);
2911 void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2913 Tok.is(tok::l_square)) {
2914 ParsedAttributes AttrsWithRange(AttrFactory);
2915 ParseMicrosoftAttributes(AttrsWithRange);
2916 Attrs.takeAllFrom(AttrsWithRange);
2919 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
2920 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
2921 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2922 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2923 ParseMicrosoftDeclSpecs(Attrs);
2928 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2929 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2930 SourceLocation AttrNameLoc,
2931 ParsedAttributes &Attrs);
2932 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2933 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2934 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2935 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2936 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
2937 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2938 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2939 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2940 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2941 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2942 bool isHLSLQualifier(
const Token &Tok)
const;
2943 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2945 VersionTuple ParseVersionTuple(SourceRange &Range);
2946 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2947 SourceLocation AvailabilityLoc,
2948 ParsedAttributes &attrs,
2949 SourceLocation *endLoc,
2950 IdentifierInfo *ScopeName,
2951 SourceLocation ScopeLoc,
2954 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
2955 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
2957 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2959 ParsedAttributes &Attrs,
2960 SourceLocation *EndLoc,
2961 IdentifierInfo *ScopeName,
2962 SourceLocation ScopeLoc,
2965 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2966 SourceLocation ObjCBridgeRelatedLoc,
2967 ParsedAttributes &Attrs,
2968 SourceLocation *EndLoc,
2969 IdentifierInfo *ScopeName,
2970 SourceLocation ScopeLoc,
2973 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2974 SourceLocation AttrNameLoc,
2975 ParsedAttributes &Attrs,
2976 SourceLocation *EndLoc,
2977 IdentifierInfo *ScopeName,
2978 SourceLocation ScopeLoc,
2981 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2982 SourceLocation AttrNameLoc,
2983 ParsedAttributes &Attrs,
2984 SourceLocation *EndLoc,
2985 IdentifierInfo *ScopeName,
2986 SourceLocation ScopeLoc,
2989 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2990 SourceLocation AttrNameLoc,
2991 ParsedAttributes &Attrs,
2992 IdentifierInfo *ScopeName,
2993 SourceLocation ScopeLoc,
2996 void ParseTypeofSpecifier(DeclSpec &DS);
2997 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
2998 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
2999 SourceLocation StartLoc,
3000 SourceLocation EndLoc);
3001 void ParseAtomicSpecifier(DeclSpec &DS);
3003 ExprResult ParseAlignArgument(SourceLocation Start,
3004 SourceLocation &EllipsisLoc);
3005 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
3006 SourceLocation *endLoc =
nullptr);
3011 return isCXX11VirtSpecifier(Tok);
3013 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3014 SourceLocation FriendLoc);
3016 bool isCXX11FinalKeyword()
const;
3017 bool isClassCompatibleKeyword()
const;
3022 class DeclaratorScopeObj {
3028 DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
3029 :
P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
3031 void EnterDeclaratorScope() {
3032 assert(!EnteredScope &&
"Already entered the scope!");
3033 assert(SS.isSet() &&
"C++ scope was not set!");
3035 CreatedScope =
true;
3038 if (!
P.Actions.ActOnCXXEnterDeclaratorScope(
P.getCurScope(), SS))
3039 EnteredScope =
true;
3042 ~DeclaratorScopeObj() {
3044 assert(SS.isSet() &&
"C++ scope was cleared ?");
3045 P.Actions.ActOnCXXExitDeclaratorScope(
P.getCurScope(), SS);
3053 void ParseDeclarator(Declarator &D);
3055 typedef void (Parser::*DirectDeclParseFunction)(
Declarator&);
3056 void ParseDeclaratorInternal(Declarator &D,
3057 DirectDeclParseFunction DirectDeclParser);
3059 enum AttrRequirements {
3060 AR_NoAttributesParsed = 0,
3061 AR_GNUAttributesParsedAndRejected = 1 << 0,
3062 AR_GNUAttributesParsed = 1 << 1,
3063 AR_CXX11AttributesParsed = 1 << 2,
3064 AR_DeclspecAttributesParsed = 1 << 3,
3065 AR_AllAttributesParsed = AR_GNUAttributesParsed |
3066 AR_CXX11AttributesParsed |
3067 AR_DeclspecAttributesParsed,
3068 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
3069 AR_DeclspecAttributesParsed
3072 void ParseTypeQualifierListOpt(
3073 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
3074 bool AtomicAllowed =
true,
bool IdentifierRequired =
false,
3075 std::optional<llvm::function_ref<
void()>> CodeCompletionHandler =
3077 void ParseDirectDeclarator(Declarator &D);
3078 void ParseDecompositionDeclarator(Declarator &D);
3079 void ParseParenDeclarator(Declarator &D);
3080 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
3082 bool IsAmbiguous,
bool RequiresArg =
false);
3083 void InitCXXThisScopeForDeclaratorIfRelevant(
3084 const Declarator &D,
const DeclSpec &DS,
3085 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
3086 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
3087 SourceLocation &RefQualifierLoc);
3088 bool isFunctionDeclaratorIdentifierList();
3089 void ParseFunctionDeclaratorIdentifierList(
3091 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
3092 void ParseParameterDeclarationClause(
3093 Declarator &D, ParsedAttributes &attrs,
3094 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
3095 SourceLocation &EllipsisLoc) {
3096 return ParseParameterDeclarationClause(
3097 D.getContext(), attrs, ParamInfo, EllipsisLoc,
3098 D.getCXXScopeSpec().isSet() &&
3099 D.isFunctionDeclaratorAFunctionDeclaration());
3101 void ParseParameterDeclarationClause(
3103 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
3104 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
3106 void ParseBracketDeclarator(Declarator &D);
3107 void ParseMisplacedBracketDeclarator(Declarator &D);
3108 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3115 enum CXX11AttributeKind {
3117 CAK_NotAttributeSpecifier,
3119 CAK_AttributeSpecifier,
3122 CAK_InvalidAttributeSpecifier
3125 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
3126 bool OuterMightBeMessageSend =
false);
3128 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3131 SourceLocation &DeclEnd,
3132 SourceLocation InlineLoc = SourceLocation());
3134 struct InnerNamespaceInfo {
3135 SourceLocation NamespaceLoc;
3136 SourceLocation InlineLoc;
3137 SourceLocation IdentLoc;
3138 IdentifierInfo *Ident;
3142 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3143 unsigned int index, SourceLocation &InlineLoc,
3144 ParsedAttributes &attrs,
3147 Decl *ParseExportDeclaration();
3150 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3152 SourceLocation UsingLoc,
3153 SourceLocation &DeclEnd,
3154 ParsedAttributes &attrs);
3156 struct UsingDeclarator {
3157 SourceLocation TypenameLoc;
3160 SourceLocation EllipsisLoc;
3163 TypenameLoc = EllipsisLoc = SourceLocation();
3171 const ParsedTemplateInfo &TemplateInfo,
3172 SourceLocation UsingLoc,
3173 SourceLocation &DeclEnd,
3174 ParsedAttributes &Attrs,
3176 Decl *ParseAliasDeclarationAfterDeclarator(
3177 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3179 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3181 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3182 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3183 SourceLocation AliasLoc, IdentifierInfo *Alias,
3184 SourceLocation &DeclEnd);
3188 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3189 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3190 DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo,
3192 DeclSpecContext DSC, ParsedAttributes &Attributes);
3193 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3194 SourceLocation AttrFixitLoc,
3197 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3198 SourceLocation AttrFixitLoc,
3199 ParsedAttributes &Attrs,
unsigned TagType,
3201 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3202 SourceLocation &EqualLoc);
3204 ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3207 LateParsedAttrList &LateAttrs);
3208 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3209 VirtSpecifiers &VS);
3212 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
3213 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3216 ParsedAttributes &AccessAttrs,
3218 void ParseConstructorInitializer(Decl *ConstructorDecl);
3220 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
3225 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3226 SourceLocation &EndLocation);
3227 void ParseBaseClause(Decl *ClassDecl);
3228 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3231 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
3233 bool ObjectHadErrors,
3234 SourceLocation TemplateKWLoc,
3235 IdentifierInfo *Name,
3236 SourceLocation NameLoc,
3237 bool EnteringContext,
3239 bool AssumeTemplateId);
3240 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
3249 SourceLocation Loc);
3253 void parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
3254 llvm::omp::TraitSet Set,
3255 llvm::omp::TraitSelector Selector,
3256 llvm::StringMap<SourceLocation> &Seen);
3259 void parseOMPTraitSelectorKind(OMPTraitSelector &TISelector,
3260 llvm::omp::TraitSet Set,
3261 llvm::StringMap<SourceLocation> &Seen);
3264 void parseOMPTraitSetKind(OMPTraitSet &TISet,
3265 llvm::StringMap<SourceLocation> &Seen);
3268 void parseOMPContextProperty(OMPTraitSelector &TISelector,
3269 llvm::omp::TraitSet Set,
3270 llvm::StringMap<SourceLocation> &Seen);
3273 void parseOMPContextSelector(OMPTraitSelector &TISelector,
3274 llvm::omp::TraitSet Set,
3275 llvm::StringMap<SourceLocation> &SeenSelectors);
3278 void parseOMPContextSelectorSet(OMPTraitSet &TISet,
3279 llvm::StringMap<SourceLocation> &SeenSets);
3282 bool parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI);
3285 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
3289 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc, OMPTraitInfo &TI,
3290 OMPTraitInfo *ParentTI);
3294 SourceLocation Loc);
3298 SourceLocation Loc);
3301 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
3309 SmallVectorImpl<clang::OMPClause *> &Clauses,
3310 SourceLocation Loc);
3313 void ParseOMPDeclareTargetClauses(Sema::DeclareTargetContextInfo &DTCI);
3318 SourceLocation Loc);
3331 SourceLocation MatchingLoc,
3332 SourceLocation FoundLoc,
3333 bool SkipUntilOpenMPEnd);
3339 Decl *TagDecl =
nullptr);
3344 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
3349 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
3350 DeclarationName &Name,
3355 bool tryParseOpenMPArrayShapingCastPart();
3364 bool ParseOpenMPSimpleVarList(
3366 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)> &
3368 bool AllowScopeSpecifier);
3374 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
3375 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
3403 bool ParseOpenMPIndirectClause(Sema::DeclareTargetContextInfo &DTCI,
3418 OMPClause *ParseOpenMPSizesClause();
3426 OMPClause *ParseOpenMPClause(
OpenMPClauseKind Kind,
bool ParseOnly =
false);
3447 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
3455 OMPClause *ParseOpenMPInteropClause(
OpenMPClauseKind Kind,
bool ParseOnly);
3462 bool IsAddressOfOperand =
false);
3466 Sema::OpenMPVarListDataTy &
Data,
3467 const LangOptions &LangOpts);
3470 SmallVectorImpl<Expr *> &Vars,
3471 Sema::OpenMPVarListDataTy &
Data);
3473 bool ObjectHadErrors,
bool EnteringContext,
3474 bool AllowDestructorName,
bool AllowConstructorName,
3475 bool AllowDeductionGuide,
3476 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
3491 SourceLocation &DeclEnd,
3492 ParsedAttributes &AccessAttrs,
3495 SourceLocation &DeclEnd,
3496 ParsedAttributes &AccessAttrs,
3498 Decl *ParseSingleDeclarationAfterTemplate(
3500 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
3502 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
3503 SmallVectorImpl<NamedDecl *> &TemplateParams,
3504 SourceLocation &LAngleLoc,
3505 SourceLocation &RAngleLoc);
3506 bool ParseTemplateParameterList(
unsigned Depth,
3507 SmallVectorImpl<NamedDecl*> &TemplateParams);
3508 TPResult isStartOfTemplateTypeParameter();
3509 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
3510 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
3511 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
3512 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
3513 bool isTypeConstraintAnnotation();
3514 bool TryAnnotateTypeConstraint();
3515 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
3516 SourceLocation CorrectLoc,
3517 bool AlreadyHasEllipsis,
3518 bool IdentifierHasName);
3519 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
3522 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
3524 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
3525 SourceLocation &RAngleLoc,
3526 bool ConsumeLastToken,
3527 bool ObjCGenericList);
3528 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
3529 SourceLocation &LAngleLoc,
3530 TemplateArgList &TemplateArgs,
3531 SourceLocation &RAngleLoc,
3536 SourceLocation TemplateKWLoc,
3537 UnqualifiedId &TemplateName,
3538 bool AllowTypeAnnotation =
true,
3539 bool TypeConstraint =
false);
3541 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
3543 bool IsClassName =
false);
3544 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
3545 TemplateTy Template, SourceLocation OpenLoc);
3546 ParsedTemplateArgument ParseTemplateTemplateArgument();
3547 ParsedTemplateArgument ParseTemplateArgument();
3549 SourceLocation ExternLoc,
3550 SourceLocation TemplateLoc,
3551 SourceLocation &DeclEnd,
3552 ParsedAttributes &AccessAttrs,
3556 ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
3557 SourceLocation &DeclEnd);
3562 Decl *ParseModuleImport(SourceLocation AtLoc,
3564 bool parseMisplacedModuleImport();
3565 bool tryParseMisplacedModuleImport() {
3567 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
3568 Kind == tok::annot_module_include)
3569 return parseMisplacedModuleImport();
3573 bool ParseModuleName(
3574 SourceLocation UseLoc,
3575 SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
3589 void CodeCompleteDirective(
bool InConditional)
override;
3590 void CodeCompleteInConditionalExclusion()
override;
3591 void CodeCompleteMacroName(
bool IsDefinition)
override;
3592 void CodeCompletePreprocessorExpression()
override;
3593 void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
3594 unsigned ArgumentIndex)
override;
3595 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
3596 void CodeCompleteNaturalLanguage()
override;
3598 class GNUAsmQualifiers {
3599 unsigned Qualifiers = AQ_unspecified;
3608 static const char *getQualifierName(AQ Qualifier);
3609 bool setAsmQualifier(AQ Qualifier);
3610 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
3611 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
3612 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
3614 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
3615 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
3616 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
3617 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
Provides LLVM's BitmaskEnum facility to enumeration types declared in namespace clang.
Defines some OpenMP-specific enums and functions.
Defines and computes precedence levels for binary/ternary operators.
Defines the clang::Preprocessor interface.
static bool isInvalid(LocType Loc, bool *Invalid)
Defines various enumerations that describe declaration and type specifiers.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc.
Syntax
The style used to specify an attribute.
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
Callback handler that receives notifications when performing code completion within the preprocessor.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
static const TST TST_unspecified
Decl - This represents one declaration (or definition), e.g.
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
This represents one expression.
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
ObjCContainerDecl - Represents a container for method declarations.
Wrapper for void* pointer.
static OpaquePtr getFromOpaquePtr(void *P)
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
Introduces zero or more scopes for parsing.
MultiParseScope(Parser &Self)
void Enter(unsigned ScopeFlags)
ParseScope - Introduces a new scope for parsing.
ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope=true, bool BeforeCompoundStmt=false)
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS, bool IsNewScope, ImplicitTypenameContext AllowImplicitTypename)
Try to annotate a type or scope token, having already parsed an optional scope specifier.
Preprocessor & getPreprocessor() const
Sema::FullExprArg FullExprArg
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies)
AttributeFactory & getAttrFactory()
void incrementMSManglingNumber() const
Sema & getActions() const
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, bool IsUnevaluated)
Parse an identifier in an MS-style inline assembly block.
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext=false)
friend class ColonProtectionRAIIObject
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr * > &Vars, Sema::OpenMPVarListDataTy &Data)
Parses clauses with list.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
friend constexpr SkipUntilFlags operator|(SkipUntilFlags L, SkipUntilFlags R)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
SourceLocation getEndOfPreviousToken()
ExprResult ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-and-expression.
const TargetInfo & getTargetInfo() const
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
const Token & getCurToken() const
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind...
friend class ObjCDeclContextSwitch
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
void ExitScope()
ExitScope - Pop a scope off the scope stack.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc, bool IsAddressOfOperand=false)
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
SourceLocation MisleadingIndentationElseLoc
The location of the first statement inside an else that might have a missleading indentation.
const LangOptions & getLangOpts() const
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState)
Parse the first top-level declaration in a translation unit.
bool ParseOpenMPReservedLocator(OpenMPClauseKind Kind, Sema::OpenMPVarListDataTy &Data, const LangOptions &LangOpts)
Parses a reserved locator like 'omp_all_memory'.
DiagnosticBuilder Diag(unsigned DiagID)
SmallVector< Stmt *, 32 > StmtVector
A SmallVector of statements.
bool parseMapperModifier(Sema::OpenMPVarListDataTy &Data)
Parses the mapper modifier in map, to, and from clauses.
bool parseMapTypeModifiers(Sema::OpenMPVarListDataTy &Data)
Parses map-type-modifiers in map clause.
SkipUntilFlags
Control flags for SkipUntil functions.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtCodeCompletion
Stop at code completion.
@ StopAtSemi
Stop skipping at semicolon.
bool TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
bool MightBeCXXScopeToken()
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
ObjCContainerDecl * getObjCDeclContext() const
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
friend class BalancedDelimiterTracker
bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc)
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
void Initialize()
Initialize - Warm up the parser.
unsigned ReenterTemplateScopes(MultiParseScope &S, Decl *D)
Re-enter the template scopes for a declaration that might be a template.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
Activates OpenMP parsing mode to preseve OpenMP specific annotation tokens.
Tracks expected type during expression parsing, for use in code completion.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void setCodeCompletionReached()
Note that we hit the code-completion point.
bool mightHavePendingAnnotationTokens()
Determine whether it's possible for a future call to Lex to produce an annotation token created by a ...
void Lex(Token &Result)
Lex the next token for this preprocessor.
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
const TargetInfo & getTargetInfo() const
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
const LangOptions & getLangOpts() const
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
Scope - A scope is a transient data structure that is used while parsing the program.
Sema - This implements semantic analysis and AST building for C.
Scope * getCurScope() const
Retrieve the parser's current scope.
void startOpenMPLoop()
If the current region is a loop-based region, mark the start of the loop construct.
ProcessingContextState ParsingClassState
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the keyword associated.
ObjCContainerDecl * getObjCDeclContext() const
ModuleImportState
An enumeration to represent the transition of states in parsing module fragments and imports.
@ NotACXX20Module
Not a C++20 TU, or an invalid state was found.
void incrementMSManglingNumber() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
Exposes information about the current target.
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
void setKind(tok::TokenKind K)
SourceLocation getAnnotationEndLoc() const
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
void * getAnnotationValue() const
tok::TokenKind getKind() const
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isNot(tok::TokenKind K) const
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
void setAnnotationValue(void *val)
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
@ LLVM_MARK_AS_BITMASK_ENUM
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
bool Pop(InterpState &S, CodePtr OpPC)
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
NullabilityKind
Describes the nullability of a particular type.
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
ActionResult< CXXCtorInitializer * > MemInitResult
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
ActionResult< Expr * > ExprResult
ActionResult< Stmt * > StmtResult
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
ActionResult< ParsedType > TypeResult
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
ActionResult< CXXBaseSpecifier * > BaseResult
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
unsigned short BracketCount
unsigned short BraceCount
AngleBracketTracker::Priority Priority
bool isActive(Parser &P) const
unsigned short ParenCount
bool isActiveOrNested(Parser &P) const