14 #ifndef LLVM_CLANG_PARSE_PARSER_H
15 #define LLVM_CLANG_PARSE_PARSER_H
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/Support/Compiler.h"
28 #include "llvm/Support/PrettyStackTrace.h"
29 #include "llvm/Support/SaveAndRestore.h"
36 class BalancedDelimiterTracker;
37 class CorrectionCandidateCallback;
39 class DiagnosticBuilder;
41 class ParsingDeclRAIIObject;
42 class ParsingDeclSpec;
43 class ParsingDeclarator;
44 class ParsingFieldDeclarator;
45 class ColonProtectionRAIIObject;
46 class InMessageExpressionRAIIObject;
47 class PoisonSEHIdentifiersRAIIObject;
50 class ObjCTypeParamList;
51 class ObjCTypeParameter;
77 unsigned short ParenCount = 0, BracketCount = 0, BraceCount = 0;
78 unsigned short MisplacedModuleBeginCount = 0;
87 enum { ScopeCacheSize = 16 };
88 unsigned NumCachedScopes;
89 Scope *ScopeCache[ScopeCacheSize];
95 *Ident___exception_code,
96 *Ident_GetExceptionCode;
99 *Ident___exception_info,
100 *Ident_GetExceptionInfo;
103 *Ident___abnormal_termination,
104 *Ident_AbnormalTermination;
147 *Ident_generated_declaration;
156 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
158 std::unique_ptr<PragmaHandler> AlignHandler;
159 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
160 std::unique_ptr<PragmaHandler> OptionsHandler;
161 std::unique_ptr<PragmaHandler> PackHandler;
162 std::unique_ptr<PragmaHandler> MSStructHandler;
163 std::unique_ptr<PragmaHandler> UnusedHandler;
164 std::unique_ptr<PragmaHandler> WeakHandler;
165 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
166 std::unique_ptr<PragmaHandler> FPContractHandler;
167 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
168 std::unique_ptr<PragmaHandler> OpenMPHandler;
169 std::unique_ptr<PragmaHandler> PCSectionHandler;
170 std::unique_ptr<PragmaHandler> MSCommentHandler;
171 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
172 std::unique_ptr<PragmaHandler> MSPointersToMembers;
173 std::unique_ptr<PragmaHandler> MSVtorDisp;
174 std::unique_ptr<PragmaHandler> MSInitSeg;
175 std::unique_ptr<PragmaHandler> MSDataSeg;
176 std::unique_ptr<PragmaHandler> MSBSSSeg;
177 std::unique_ptr<PragmaHandler> MSConstSeg;
178 std::unique_ptr<PragmaHandler> MSCodeSeg;
179 std::unique_ptr<PragmaHandler> MSSection;
180 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
181 std::unique_ptr<PragmaHandler> MSIntrinsic;
182 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
183 std::unique_ptr<PragmaHandler> OptimizeHandler;
184 std::unique_ptr<PragmaHandler> LoopHintHandler;
185 std::unique_ptr<PragmaHandler> UnrollHintHandler;
186 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
187 std::unique_ptr<PragmaHandler> FPHandler;
188 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
190 std::unique_ptr<CommentHandler> CommentSemaHandler;
196 bool GreaterThanIsOperator;
209 bool InMessageExpression;
212 unsigned TemplateParameterDepth;
215 class TemplateParameterDepthRAII {
217 unsigned AddedLevels;
219 explicit TemplateParameterDepthRAII(
unsigned &
Depth)
220 : Depth(Depth), AddedLevels(0) {}
222 ~TemplateParameterDepthRAII() {
223 Depth -= AddedLevels;
230 void addDepth(
unsigned D) {
234 unsigned getDepth()
const {
return Depth; }
238 AttributeFactory AttrFactory;
242 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
245 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
247 IdentifierInfo *getSEHExceptKeyword();
254 bool ParsingInObjCContainer;
256 bool SkipFunctionBodies;
261 SourceLocation ExprStatementTokLoc;
264 Parser(Preprocessor &PP, Sema &Actions,
bool SkipFunctionBodies);
313 assert(!isTokenSpecial() &&
314 "Should consume special tokens with Consume*Token");
317 return PrevTokLocation;
321 if (Tok.
isNot(Expected))
323 assert(!isTokenSpecial() &&
324 "Should consume special tokens with Consume*Token");
333 Loc = PrevTokLocation;
353 bool isTokenParen()
const {
354 return Tok.
getKind() == tok::l_paren || Tok.
getKind() == tok::r_paren;
357 bool isTokenBracket()
const {
358 return Tok.
getKind() == tok::l_square || Tok.
getKind() == tok::r_square;
361 bool isTokenBrace()
const {
362 return Tok.
getKind() == tok::l_brace || Tok.
getKind() == tok::r_brace;
365 bool isTokenStringLiteral()
const {
369 bool isTokenSpecial()
const {
370 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
371 isTokenBrace() || Tok.
is(tok::code_completion) || Tok.
isAnnotation();
376 bool isTokenEqualOrEqualTypo();
380 void UnconsumeToken(
Token &Consumed) {
390 SourceLocation ConsumeAnyToken(
bool ConsumeCodeCompletionTok =
false) {
392 return ConsumeParen();
393 if (isTokenBracket())
394 return ConsumeBracket();
396 return ConsumeBrace();
397 if (isTokenStringLiteral())
398 return ConsumeStringToken();
399 if (Tok.
is(tok::code_completion))
400 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
401 : handleUnexpectedCodeCompletionToken();
403 return ConsumeAnnotationToken();
407 SourceLocation ConsumeAnnotationToken() {
417 SourceLocation ConsumeParen() {
418 assert(isTokenParen() &&
"wrong consume method");
419 if (Tok.
getKind() == tok::l_paren)
425 return PrevTokLocation;
430 SourceLocation ConsumeBracket() {
431 assert(isTokenBracket() &&
"wrong consume method");
432 if (Tok.
getKind() == tok::l_square)
434 else if (BracketCount)
439 return PrevTokLocation;
444 SourceLocation ConsumeBrace() {
445 assert(isTokenBrace() &&
"wrong consume method");
446 if (Tok.
getKind() == tok::l_brace)
453 return PrevTokLocation;
460 SourceLocation ConsumeStringToken() {
461 assert(isTokenStringLiteral() &&
462 "Should only consume string literals with this method");
465 return PrevTokLocation;
473 SourceLocation ConsumeCodeCompletionToken() {
474 assert(Tok.
is(tok::code_completion));
477 return PrevTokLocation;
485 SourceLocation handleUnexpectedCodeCompletionToken();
489 void cutOffParsing() {
500 return Kind ==
tok::eof || Kind == tok::annot_module_begin ||
501 Kind == tok::annot_module_end || Kind == tok::annot_module_include;
505 void initializePragmaHandlers();
508 void resetPragmaHandlers();
511 void HandlePragmaUnused();
515 void HandlePragmaVisibility();
519 void HandlePragmaPack();
523 void HandlePragmaMSStruct();
527 void HandlePragmaMSComment();
529 void HandlePragmaMSPointersToMembers();
531 void HandlePragmaMSVtorDisp();
533 void HandlePragmaMSPragma();
534 bool HandlePragmaMSSection(StringRef PragmaName,
535 SourceLocation PragmaLocation);
536 bool HandlePragmaMSSegment(StringRef PragmaName,
537 SourceLocation PragmaLocation);
538 bool HandlePragmaMSInitSeg(StringRef PragmaName,
539 SourceLocation PragmaLocation);
543 void HandlePragmaAlign();
547 void HandlePragmaDump();
551 void HandlePragmaWeak();
555 void HandlePragmaWeakAlias();
559 void HandlePragmaRedefineExtname();
563 void HandlePragmaFPContract();
567 void HandlePragmaFP();
571 void HandlePragmaOpenCLExtension();
579 bool HandlePragmaLoopHint(LoopHint &Hint);
581 bool ParsePragmaAttributeSubjectMatchRuleSet(
583 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
585 void HandlePragmaAttribute();
594 const Token &GetLookAheadToken(
unsigned N) {
619 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
625 Tok.setAnnotationValue(ER.getAsOpaquePointer());
637 enum AnnotatedNameKind {
650 TryAnnotateName(
bool IsAddressOfOperand,
651 std::unique_ptr<CorrectionCandidateCallback> CCC =
nullptr);
654 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
659 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
660 const char *&PrevSpec,
unsigned &DiagID,
665 if (Tok.getIdentifierInfo() != Ident_vector &&
666 Tok.getIdentifierInfo() != Ident_bool &&
667 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
670 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
676 bool TryAltiVecVectorToken() {
678 Tok.getIdentifierInfo() != Ident_vector)
return false;
679 return TryAltiVecVectorTokenOutOfLine();
682 bool TryAltiVecVectorTokenOutOfLine();
683 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
684 const char *&PrevSpec,
unsigned &DiagID,
690 bool isObjCInstancetype() {
692 if (Tok.isAnnotation())
694 if (!Ident_instancetype)
696 return Tok.getIdentifierInfo() == Ident_instancetype;
704 bool TryKeywordIdentFallback(
bool DisableKeyword);
707 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
720 class TentativeParsingAction {
723 size_t PrevTentativelyDeclaredIdentifierCount;
724 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
728 explicit TentativeParsingAction(
Parser& p) :
P(p) {
730 PrevTentativelyDeclaredIdentifierCount =
731 P.TentativelyDeclaredIdentifiers.size();
732 PrevParenCount =
P.ParenCount;
733 PrevBracketCount =
P.BracketCount;
734 PrevBraceCount =
P.BraceCount;
735 P.PP.EnableBacktrackAtThisPos();
739 assert(isActive &&
"Parsing action was finished!");
740 P.TentativelyDeclaredIdentifiers.resize(
741 PrevTentativelyDeclaredIdentifierCount);
742 P.PP.CommitBacktrackedTokens();
746 assert(isActive &&
"Parsing action was finished!");
749 P.TentativelyDeclaredIdentifiers.resize(
750 PrevTentativelyDeclaredIdentifierCount);
751 P.ParenCount = PrevParenCount;
752 P.BracketCount = PrevBracketCount;
753 P.BraceCount = PrevBraceCount;
756 ~TentativeParsingAction() {
757 assert(!isActive &&
"Forgot to call Commit or Revert!");
762 class RevertingTentativeParsingAction
763 :
private Parser::TentativeParsingAction {
765 RevertingTentativeParsingAction(
Parser &
P)
766 :
Parser::TentativeParsingAction(P) {}
767 ~RevertingTentativeParsingAction() { Revert(); }
770 class UnannotatedTentativeParsingAction;
778 SaveAndRestore<bool> WithinObjCContainer;
782 WithinObjCContainer(
P.ParsingInObjCContainer, DC != nullptr) {
784 P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
788 P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
801 unsigned Diag = diag::err_expected,
802 StringRef DiagMsg =
"");
809 bool ExpectAndConsumeSemi(
unsigned DiagID);
815 InstanceVariableList = 2,
816 AfterMemberFunctionDefinition = 3
820 void ConsumeExtraSemi(ExtraSemiKind Kind,
unsigned TST =
TST_unspecified);
828 bool expectIdentifier();
850 bool BeforeCompoundStmt =
false)
852 if (EnteredScope && !BeforeCompoundStmt)
855 if (BeforeCompoundStmt)
858 this->Self =
nullptr;
884 class ParseScopeFlags {
887 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
888 void operator=(
const ParseScopeFlags &) =
delete;
891 ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
899 DiagnosticBuilder
Diag(SourceLocation Loc,
unsigned DiagID);
900 DiagnosticBuilder
Diag(
const Token &Tok,
unsigned DiagID);
902 return Diag(Tok, DiagID);
923 static_cast<unsigned>(R));
936 return SkipUntil(llvm::makeArrayRef(T), Flags);
969 class LateParsedDeclaration {
971 virtual ~LateParsedDeclaration();
973 virtual void ParseLexedMethodDeclarations();
974 virtual void ParseLexedMemberInitializers();
975 virtual void ParseLexedMethodDefs();
976 virtual void ParseLexedAttributes();
981 class LateParsedClass :
public LateParsedDeclaration {
983 LateParsedClass(
Parser *
P, ParsingClass *C);
984 ~LateParsedClass()
override;
986 void ParseLexedMethodDeclarations()
override;
987 void ParseLexedMemberInitializers()
override;
988 void ParseLexedMethodDefs()
override;
989 void ParseLexedAttributes()
override;
1002 struct LateParsedAttribute :
public LateParsedDeclaration {
1005 IdentifierInfo &AttrName;
1006 SourceLocation AttrNameLoc;
1007 SmallVector<Decl*, 2> Decls;
1009 explicit LateParsedAttribute(
Parser *
P, IdentifierInfo &
Name,
1011 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
1013 void ParseLexedAttributes()
override;
1015 void addDecl(Decl *D) { Decls.push_back(D); }
1019 class LateParsedAttrList:
public SmallVector<LateParsedAttribute *, 2> {
1021 LateParsedAttrList(
bool PSoon =
false) : ParseSoon(PSoon) { }
1023 bool parseSoon() {
return ParseSoon; }
1032 struct LexedMethod :
public LateParsedDeclaration {
1042 explicit LexedMethod(
Parser*
P, Decl *MD)
1043 : Self(P), D(MD), TemplateScope(
false) {}
1045 void ParseLexedMethodDefs()
override;
1052 struct LateParsedDefaultArgument {
1053 explicit LateParsedDefaultArgument(Decl *
P,
1054 std::unique_ptr<CachedTokens> Toks =
nullptr)
1055 : Param(P), Toks(std::move(Toks)) { }
1064 std::unique_ptr<CachedTokens> Toks;
1071 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1072 explicit LateParsedMethodDeclaration(
Parser *
P, Decl *M)
1073 : Self(P), Method(M), TemplateScope(
false),
1074 ExceptionSpecTokens(nullptr) {}
1076 void ParseLexedMethodDeclarations()
override;
1093 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1103 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1104 LateParsedMemberInitializer(
Parser *
P, Decl *FD)
1105 : Self(P),
Field(FD) { }
1107 void ParseLexedMemberInitializers()
override;
1125 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
1130 struct ParsingClass {
1131 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
1132 : TopLevelClass(TopLevelClass), TemplateScope(
false),
1133 IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { }
1137 bool TopLevelClass : 1;
1142 bool TemplateScope : 1;
1145 bool IsInterface : 1;
1148 Decl *TagOrTemplate;
1153 LateParsedDeclarationsContainer LateParsedDeclarations;
1159 std::stack<ParsingClass *> ClassStack;
1161 ParsingClass &getCurrentClass() {
1162 assert(!ClassStack.empty() &&
"No lexed method stacks!");
1163 return *ClassStack.top();
1167 class ParsingClassDefinition {
1173 ParsingClassDefinition(
Parser &
P, Decl *TagOrTemplate,
bool TopLevelClass,
1175 : P(P), Popped(
false),
1176 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1181 assert(!Popped &&
"Nested class has already been popped");
1183 P.PopParsingClass(
State);
1186 ~ParsingClassDefinition() {
1188 P.PopParsingClass(
State);
1195 struct ParsedTemplateInfo {
1196 ParsedTemplateInfo()
1197 : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
1200 bool isSpecialization,
1201 bool lastParameterListWasEmpty =
false)
1202 : Kind(isSpecialization? ExplicitSpecialization : Template),
1203 TemplateParams(TemplateParams),
1204 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1206 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1207 SourceLocation TemplateLoc)
1208 : Kind(ExplicitInstantiation), TemplateParams(nullptr),
1209 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1210 LastParameterListWasEmpty(
false){ }
1219 ExplicitSpecialization,
1221 ExplicitInstantiation
1230 SourceLocation ExternLoc;
1234 SourceLocation TemplateLoc;
1237 bool LastParameterListWasEmpty;
1242 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
1243 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1245 static
void LateTemplateParserCallback(
void *
P, LateParsedTemplate &LPT);
1246 static
void LateTemplateParserCleanupCallback(
void *P);
1248 Sema::ParsingClassState
1249 PushParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
1250 void DeallocateParsedClasses(ParsingClass *Class);
1251 void PopParsingClass(Sema::ParsingClassState);
1253 enum CachedInitKind {
1254 CIK_DefaultArgument,
1255 CIK_DefaultInitializer
1259 AttributeList *AccessAttrs,
1260 ParsingDeclarator &D,
1261 const ParsedTemplateInfo &TemplateInfo,
1262 const VirtSpecifiers& VS,
1263 SourceLocation PureSpecLoc);
1264 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1265 void ParseLexedAttributes(ParsingClass &Class);
1266 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1268 void ParseLexedAttribute(LateParsedAttribute &LA,
1270 void ParseLexedMethodDeclarations(ParsingClass &Class);
1271 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1272 void ParseLexedMethodDefs(ParsingClass &Class);
1273 void ParseLexedMethodDef(LexedMethod &LM);
1274 void ParseLexedMemberInitializers(ParsingClass &Class);
1275 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1276 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
1277 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1278 bool ConsumeAndStoreInitializer(
CachedTokens &Toks, CachedInitKind CIK);
1283 bool ConsumeFinalToken =
true) {
1284 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1289 bool ConsumeFinalToken =
true);
1293 struct ParsedAttributesWithRange : ParsedAttributes {
1294 ParsedAttributesWithRange(AttributeFactory &factory)
1295 : ParsedAttributes(factory) {}
1299 Range = SourceRange();
1305 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
1306 ParsingDeclSpec *DS =
nullptr);
1307 bool isDeclarationAfterDeclarator();
1308 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1310 ParsedAttributesWithRange &attrs,
1311 ParsingDeclSpec *DS =
nullptr,
1313 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
1314 ParsingDeclSpec &DS,
1317 void SkipFunctionBody();
1318 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1319 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1320 LateParsedAttrList *LateParsedAttrs =
nullptr);
1321 void ParseKNRParamDeclarations(Declarator &D);
1324 ExprResult ParseSimpleAsm(SourceLocation *EndLoc =
nullptr);
1330 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1331 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1332 ParsedAttributes &prefixAttrs);
1333 class ObjCTypeParamListScope;
1334 ObjCTypeParamList *parseObjCTypeParamList();
1335 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1336 ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1337 SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1338 SourceLocation &rAngleLoc,
bool mayBeProtocolList =
true);
1340 void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1342 SmallVectorImpl<Decl *> &AllIvarDecls,
1343 bool RBraceMissing);
1344 void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
1346 SourceLocation atLoc);
1347 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &
P,
1348 SmallVectorImpl<SourceLocation> &PLocs,
1349 bool WarnOnDeclarations,
1350 bool ForObjCContainer,
1351 SourceLocation &LAngleLoc,
1352 SourceLocation &EndProtoLoc,
1353 bool consumeLastToken);
1358 void parseObjCTypeArgsOrProtocolQualifiers(
1360 SourceLocation &typeArgsLAngleLoc,
1361 SmallVectorImpl<ParsedType> &typeArgs,
1362 SourceLocation &typeArgsRAngleLoc,
1363 SourceLocation &protocolLAngleLoc,
1364 SmallVectorImpl<Decl *> &protocols,
1365 SmallVectorImpl<SourceLocation> &protocolLocs,
1366 SourceLocation &protocolRAngleLoc,
1367 bool consumeLastToken,
1368 bool warnOnIncompleteProtocols);
1372 void parseObjCTypeArgsAndProtocolQualifiers(
1374 SourceLocation &typeArgsLAngleLoc,
1375 SmallVectorImpl<ParsedType> &typeArgs,
1376 SourceLocation &typeArgsRAngleLoc,
1377 SourceLocation &protocolLAngleLoc,
1378 SmallVectorImpl<Decl *> &protocols,
1379 SmallVectorImpl<SourceLocation> &protocolLocs,
1380 SourceLocation &protocolRAngleLoc,
1381 bool consumeLastToken);
1385 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1389 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1391 bool consumeLastToken,
1392 SourceLocation &endLoc);
1396 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1397 ParsedAttributes &prefixAttrs);
1399 struct ObjCImplParsingDataRAII {
1403 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1404 LateParsedObjCMethodContainer LateParsedObjCMethods;
1406 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
1407 :
P(parser), Dcl(D), HasCFunction(
false) {
1408 P.CurParsedObjCImpl =
this;
1411 ~ObjCImplParsingDataRAII();
1413 void finish(SourceRange AtEnd);
1414 bool isFinished()
const {
return Finished; }
1419 ObjCImplParsingDataRAII *CurParsedObjCImpl;
1420 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
1422 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1424 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1425 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1426 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1428 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1431 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1432 objc_nonnull, objc_nullable, objc_null_unspecified,
1435 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1437 bool isTokIdentifier_in()
const;
1440 ParsedAttributes *ParamAttrs);
1441 void ParseObjCMethodRequirement();
1442 Decl *ParseObjCMethodPrototype(
1444 bool MethodDefinition =
true);
1447 bool MethodDefinition=
true);
1448 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1450 Decl *ParseObjCMethodDefinition();
1472 unsigned &NumLineToksConsumed,
1474 bool IsUnevaluated);
1483 ExprResult ParseCastExpression(
bool isUnaryExpression,
1484 bool isAddressOfOperand,
1487 bool isVectorLiteral =
false);
1488 ExprResult ParseCastExpression(
bool isUnaryExpression,
1489 bool isAddressOfOperand =
false,
1491 bool isVectorLiteral =
false);
1494 bool isNotExpressionStart();
1498 bool isPostfixExpressionSuffixStart() {
1500 return (K == tok::l_square || K == tok::l_paren ||
1501 K == tok::period || K == tok::arrow ||
1502 K == tok::plusplus || K == tok::minusminus);
1505 bool diagnoseUnknownTemplateId(
ExprResult TemplateName, SourceLocation Less);
1508 ExprResult ParseUnaryExprOrTypeTraitExpression();
1514 SourceRange &CastRange);
1516 typedef SmallVector<Expr*, 20> ExprListTy;
1517 typedef SmallVector<SourceLocation, 20> CommaLocsTy;
1520 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1521 SmallVectorImpl<SourceLocation> &CommaLocs,
1522 std::function<
void()> Completer =
nullptr);
1526 bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
1527 SmallVectorImpl<SourceLocation> &CommaLocs);
1531 enum ParenParseOption {
1537 ExprResult ParseParenExpression(ParenParseOption &ExprType,
1538 bool stopIfCastExpr,
1541 SourceLocation &RParenLoc);
1544 ParenParseOption &ExprType,
ParsedType &CastTy,
1547 SourceLocation LParenLoc,
1548 SourceLocation RParenLoc);
1550 ExprResult ParseStringLiteralExpression(
bool AllowUserDefinedLiteral =
false);
1552 ExprResult ParseGenericSelectionExpression();
1560 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
1562 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
1564 bool areTokensAdjacent(
const Token &A,
const Token &B);
1566 void CheckForTemplateAndDigraph(
Token &Next,
ParsedType ObjectTypePtr,
1567 bool EnteringContext, IdentifierInfo &II,
1570 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1572 bool EnteringContext,
1573 bool *MayBePseudoDestructor =
nullptr,
1574 bool IsTypename =
false,
1575 IdentifierInfo **LastII =
nullptr,
1576 bool OnlyNamespace =
false);
1584 Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro,
1585 bool *SkippedInits =
nullptr);
1586 bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1587 ExprResult ParseLambdaExpressionAfterIntroducer(
1588 LambdaIntroducer &Intro);
1604 ExprResult ParseCXXPseudoDestructor(Expr *
Base, SourceLocation OpLoc,
1619 SourceRange &SpecificationRange,
1620 SmallVectorImpl<ParsedType> &DynamicExceptions,
1621 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
1627 SourceRange &SpecificationRange,
1628 SmallVectorImpl<ParsedType> &Exceptions,
1629 SmallVectorImpl<SourceRange> &Ranges);
1633 TypeResult ParseTrailingReturnType(SourceRange &Range);
1641 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
1646 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1648 bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
1652 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1654 void ParseDirectNewDeclarator(Declarator &D);
1655 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
1656 ExprResult ParseCXXDeleteExpression(
bool UseGlobal,
1657 SourceLocation Start);
1661 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
1678 if (Tok.isNot(tok::l_brace))
1680 return ParseBraceInitializer();
1682 bool MayBeDesignationStart();
1684 ExprResult ParseInitializerWithPotentialDesignator();
1693 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
1694 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
1695 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1696 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1697 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
1698 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1699 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
1700 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
1701 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
1702 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
1703 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
1704 bool isSimpleObjCMessageExpression();
1706 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
1707 SourceLocation SuperLoc,
1709 Expr *ReceiverExpr);
1710 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
1711 SourceLocation LBracloc, SourceLocation SuperLoc,
1712 ParsedType ReceiverType, Expr *ReceiverExpr);
1713 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
1720 typedef SmallVector<Stmt*, 32> StmtVector;
1722 typedef SmallVector<Expr*, 12> ExprVector;
1724 typedef SmallVector<ParsedType, 12> TypeVector;
1726 StmtResult ParseStatement(SourceLocation *TrailingElseLoc =
nullptr,
1727 bool AllowOpenMPStandalone =
false);
1728 enum AllowedConstructsKind {
1732 ACK_StatementsOpenMPNonStandalone,
1734 ACK_StatementsOpenMPAnyExecutable
1737 ParseStatementOrDeclaration(StmtVector &Stmts, AllowedConstructsKind Allowed,
1738 SourceLocation *TrailingElseLoc =
nullptr);
1739 StmtResult ParseStatementOrDeclarationAfterAttributes(
1741 AllowedConstructsKind Allowed,
1742 SourceLocation *TrailingElseLoc,
1743 ParsedAttributesWithRange &Attrs);
1745 StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
1746 StmtResult ParseCaseStatement(
bool MissingCase =
false,
1749 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
1750 StmtResult ParseCompoundStatement(
bool isStmtExpr,
1751 unsigned ScopeFlags);
1752 void ParseCompoundStatementLeadingPragmas();
1753 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
1754 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
1755 Sema::ConditionResult &CondResult,
1758 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
1759 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
1760 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
1762 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
1768 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1769 StmtResult ParsePragmaLoopHint(StmtVector &Stmts,
1770 AllowedConstructsKind Allowed,
1771 SourceLocation *TrailingElseLoc,
1772 ParsedAttributesWithRange &Attrs);
1776 enum IfExistsBehavior {
1788 struct IfExistsCondition {
1790 SourceLocation KeywordLoc;
1803 IfExistsBehavior Behavior;
1806 bool ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result);
1807 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1808 void ParseMicrosoftIfExistsExternalDeclaration();
1809 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
1811 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
1813 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &
Names,
1814 SmallVectorImpl<Expr *> &Constraints,
1815 SmallVectorImpl<Expr *> &Exprs);
1821 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc,
bool FnTry =
false);
1822 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
1828 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
1829 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
1835 StmtResult ParseObjCAtStatement(SourceLocation atLoc);
1836 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
1837 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1838 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1839 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1848 enum DeclSpecContext {
1853 DSC_alias_declaration,
1856 DSC_template_type_arg,
1857 DSC_objc_method_result,
1863 static bool isTypeSpecifier(DeclSpecContext DSC) {
1866 case DSC_template_param:
1869 case DSC_objc_method_result:
1873 case DSC_template_type_arg:
1874 case DSC_type_specifier:
1876 case DSC_alias_declaration:
1879 llvm_unreachable(
"Missing DeclSpecContext case");
1884 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1887 case DSC_template_param:
1891 case DSC_type_specifier:
1894 case DSC_objc_method_result:
1895 case DSC_template_type_arg:
1897 case DSC_alias_declaration:
1900 llvm_unreachable(
"Missing DeclSpecContext case");
1905 struct ForRangeInit {
1909 bool ParsedForRangeDecl() {
return !
ColonLoc.isInvalid(); }
1913 ParsedAttributesWithRange &attrs);
1915 SourceLocation &DeclEnd,
1916 ParsedAttributesWithRange &attrs,
1918 ForRangeInit *FRI =
nullptr);
1919 bool MightBeDeclarator(
unsigned Context);
1921 SourceLocation *DeclEnd =
nullptr,
1922 ForRangeInit *FRI =
nullptr);
1923 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1924 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1925 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1926 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1928 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1929 ForRangeInit *FRI =
nullptr);
1930 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1931 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
1937 bool trySkippingFunctionBody();
1939 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1940 const ParsedTemplateInfo &TemplateInfo,
1942 ParsedAttributesWithRange &Attrs);
1943 DeclSpecContext getDeclSpecContextFromDeclaratorContext(
unsigned Context);
1944 void ParseDeclarationSpecifiers(DeclSpec &DS,
1945 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1947 DeclSpecContext DSC = DSC_normal,
1948 LateParsedAttrList *LateAttrs =
nullptr);
1949 bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS,
AccessSpecifier AS,
1950 DeclSpecContext DSContext,
1951 LateParsedAttrList *LateAttrs =
nullptr);
1954 DeclSpecContext DSC = DSC_normal);
1956 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1959 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1960 const ParsedTemplateInfo &TemplateInfo,
1962 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
1963 void ParseStructUnionBody(SourceLocation StartLoc,
unsigned TagType,
1966 void ParseStructDeclaration(
1967 ParsingDeclSpec &DS,
1968 llvm::function_ref<
void(ParsingFieldDeclarator &)> FieldsCallback);
1970 bool isDeclarationSpecifier(
bool DisambiguatingWithExpression =
false);
1971 bool isTypeSpecifierQualifier();
1976 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
1981 bool isKnownToBeDeclarationSpecifier() {
1984 return isDeclarationSpecifier(
true);
1990 bool isDeclarationStatement() {
1992 return isCXXDeclarationStatement();
1993 return isDeclarationSpecifier(
true);
2000 bool isForInitDeclaration() {
2002 return isCXXSimpleDeclaration(
true);
2003 return isDeclarationSpecifier(
true);
2007 bool isForRangeIdentifier();
2011 bool isStartOfObjCClassMessageMissingOpenBracket();
2016 bool isConstructorDeclarator(
bool Unqualified,
bool DeductionGuide =
false);
2020 enum TentativeCXXTypeIdContext {
2023 TypeIdAsTemplateArgument
2030 bool isTypeIdInParens(
bool &isAmbiguous) {
2032 return isCXXTypeId(TypeIdInParens, isAmbiguous);
2033 isAmbiguous =
false;
2034 return isTypeSpecifierQualifier();
2036 bool isTypeIdInParens() {
2038 return isTypeIdInParens(isAmbiguous);
2044 bool isTypeIdUnambiguously() {
2047 return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
2048 return isTypeSpecifierQualifier();
2054 bool isCXXDeclarationStatement();
2061 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
2070 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr);
2072 struct ConditionDeclarationOrInitStatementState;
2073 enum class ConditionOrInitStatement {
2082 ConditionOrInitStatement
2083 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt);
2085 bool isCXXTypeId(TentativeCXXTypeIdContext
Context,
bool &isAmbiguous);
2086 bool isCXXTypeId(TentativeCXXTypeIdContext
Context) {
2088 return isCXXTypeId(Context, isAmbiguous);
2093 enum class TPResult {
2094 True, False, Ambiguous,
Error
2117 isCXXDeclarationSpecifier(TPResult BracedCastResult =
TPResult::False,
2118 bool *HasMissingTypename =
nullptr);
2123 bool isCXXDeclarationSpecifierAType();
2128 bool isTentativelyDeclared(IdentifierInfo *II);
2137 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
2138 TPResult TryParseTypeofSpecifier();
2139 TPResult TryParseProtocolQualifiers();
2140 TPResult TryParsePtrOperatorSeq();
2141 TPResult TryParseOperatorId();
2142 TPResult TryParseInitDeclaratorList();
2143 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier=
true);
2145 TryParseParameterDeclarationClause(
bool *InvalidAsDeclaration =
nullptr,
2146 bool VersusTemplateArg =
false);
2147 TPResult TryParseFunctionDeclarator();
2148 TPResult TryParseBracketDeclarator();
2149 TPResult TryConsumeDeclarationSpecifier();
2156 Decl **OwnedType =
nullptr,
2157 ParsedAttributes *Attrs =
nullptr);
2160 void ParseBlockId(SourceLocation CaretLoc);
2164 bool CheckProhibitedCXX11Attribute() {
2165 assert(Tok.is(tok::l_square));
2168 return DiagnoseProhibitedCXX11Attribute();
2170 bool DiagnoseProhibitedCXX11Attribute();
2171 void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2172 SourceLocation CorrectLocation) {
2175 if ((Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2176 Tok.isNot(tok::kw_alignas))
2178 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2180 void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2181 SourceLocation CorrectLocation);
2183 void stripTypeAttributesOffDeclSpec(ParsedAttributesWithRange &Attrs,
2186 void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
2187 if (!attrs.Range.isValid())
return;
2188 DiagnoseProhibitedAttributes(attrs);
2191 void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
2196 void ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
2201 SourceLocation SkipCXX11Attributes();
2205 void DiagnoseAndSkipCXX11Attributes();
2212 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2213 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2214 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2217 void MaybeParseGNUAttributes(Declarator &D,
2218 LateParsedAttrList *LateAttrs =
nullptr) {
2219 if (Tok.is(tok::kw___attribute)) {
2220 ParsedAttributes attrs(AttrFactory);
2221 SourceLocation endLoc;
2222 ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D);
2223 D.takeAttributes(attrs, endLoc);
2226 void MaybeParseGNUAttributes(ParsedAttributes &attrs,
2227 SourceLocation *endLoc =
nullptr,
2228 LateParsedAttrList *LateAttrs =
nullptr) {
2229 if (Tok.is(tok::kw___attribute))
2230 ParseGNUAttributes(attrs, endLoc, LateAttrs);
2232 void ParseGNUAttributes(ParsedAttributes &attrs,
2233 SourceLocation *endLoc =
nullptr,
2234 LateParsedAttrList *LateAttrs =
nullptr,
2235 Declarator *D =
nullptr);
2236 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2237 SourceLocation AttrNameLoc,
2238 ParsedAttributes &Attrs,
2239 SourceLocation *EndLoc,
2240 IdentifierInfo *ScopeName,
2241 SourceLocation ScopeLoc,
2244 IdentifierLoc *ParseIdentifierLoc();
2247 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2248 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2249 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2252 void MaybeParseCXX11Attributes(Declarator &D) {
2254 ParsedAttributesWithRange attrs(AttrFactory);
2255 SourceLocation endLoc;
2256 ParseCXX11Attributes(attrs, &endLoc);
2257 D.takeAttributes(attrs, endLoc);
2260 void MaybeParseCXX11Attributes(ParsedAttributes &attrs,
2261 SourceLocation *endLoc =
nullptr) {
2263 ParsedAttributesWithRange attrsWithRange(AttrFactory);
2264 ParseCXX11Attributes(attrsWithRange, endLoc);
2265 attrs.takeAllFrom(attrsWithRange);
2268 void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2269 SourceLocation *endLoc =
nullptr,
2270 bool OuterMightBeMessageSend =
false) {
2272 isCXX11AttributeSpecifier(
false, OuterMightBeMessageSend))
2273 ParseCXX11Attributes(attrs, endLoc);
2276 void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
2277 SourceLocation *EndLoc =
nullptr);
2278 void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2279 SourceLocation *EndLoc =
nullptr);
2282 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2283 SourceLocation AttrNameLoc,
2284 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2285 IdentifierInfo *ScopeName,
2286 SourceLocation ScopeLoc);
2288 IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
2290 void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
2291 SourceLocation *endLoc =
nullptr) {
2292 if (
getLangOpts().MicrosoftExt && Tok.is(tok::l_square))
2293 ParseMicrosoftAttributes(attrs, endLoc);
2295 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
2296 void ParseMicrosoftAttributes(ParsedAttributes &attrs,
2297 SourceLocation *endLoc =
nullptr);
2298 void MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2299 SourceLocation *
End =
nullptr) {
2301 if (LO.DeclSpecKeyword && Tok.is(tok::kw___declspec))
2302 ParseMicrosoftDeclSpecs(Attrs,
End);
2304 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2305 SourceLocation *
End =
nullptr);
2306 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2307 SourceLocation AttrNameLoc,
2308 ParsedAttributes &Attrs);
2309 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2310 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2311 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2312 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
2313 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2314 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2315 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2319 bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) {
2321 return ParseOpenCLUnrollHintAttribute(Attrs);
2326 bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs);
2327 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2329 VersionTuple ParseVersionTuple(SourceRange &Range);
2330 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2331 SourceLocation AvailabilityLoc,
2332 ParsedAttributes &attrs,
2333 SourceLocation *endLoc,
2334 IdentifierInfo *ScopeName,
2335 SourceLocation ScopeLoc,
2338 Optional<AvailabilitySpec> ParseAvailabilitySpec();
2339 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
2341 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2343 ParsedAttributes &Attrs,
2344 SourceLocation *EndLoc,
2345 IdentifierInfo *ScopeName,
2346 SourceLocation ScopeLoc,
2349 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2350 SourceLocation ObjCBridgeRelatedLoc,
2351 ParsedAttributes &attrs,
2352 SourceLocation *endLoc,
2353 IdentifierInfo *ScopeName,
2354 SourceLocation ScopeLoc,
2357 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2358 SourceLocation AttrNameLoc,
2359 ParsedAttributes &Attrs,
2360 SourceLocation *EndLoc,
2361 IdentifierInfo *ScopeName,
2362 SourceLocation ScopeLoc,
2365 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2366 SourceLocation AttrNameLoc,
2367 ParsedAttributes &Attrs,
2368 SourceLocation *EndLoc,
2369 IdentifierInfo *ScopeName,
2370 SourceLocation ScopeLoc,
2373 void ParseTypeofSpecifier(DeclSpec &DS);
2374 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
2375 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
2376 SourceLocation StartLoc,
2377 SourceLocation EndLoc);
2378 void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
2379 void ParseAtomicSpecifier(DeclSpec &DS);
2381 ExprResult ParseAlignArgument(SourceLocation Start,
2382 SourceLocation &EllipsisLoc);
2383 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2384 SourceLocation *endLoc =
nullptr);
2388 return isCXX11VirtSpecifier(Tok);
2390 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
2391 SourceLocation FriendLoc);
2393 bool isCXX11FinalKeyword()
const;
2398 class DeclaratorScopeObj {
2404 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2405 :
P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2407 void EnterDeclaratorScope() {
2408 assert(!EnteredScope &&
"Already entered the scope!");
2409 assert(SS.isSet() &&
"C++ scope was not set!");
2411 CreatedScope =
true;
2414 if (!
P.Actions.ActOnCXXEnterDeclaratorScope(
P.getCurScope(), SS))
2415 EnteredScope =
true;
2418 ~DeclaratorScopeObj() {
2420 assert(SS.isSet() &&
"C++ scope was cleared ?");
2421 P.Actions.ActOnCXXExitDeclaratorScope(
P.getCurScope(), SS);
2429 void ParseDeclarator(Declarator &D);
2431 typedef void (
Parser::*DirectDeclParseFunction)(Declarator&);
2432 void ParseDeclaratorInternal(Declarator &D,
2433 DirectDeclParseFunction DirectDeclParser);
2435 enum AttrRequirements {
2436 AR_NoAttributesParsed = 0,
2437 AR_GNUAttributesParsedAndRejected = 1 << 0,
2438 AR_GNUAttributesParsed = 1 << 1,
2439 AR_CXX11AttributesParsed = 1 << 2,
2440 AR_DeclspecAttributesParsed = 1 << 3,
2441 AR_AllAttributesParsed = AR_GNUAttributesParsed |
2442 AR_CXX11AttributesParsed |
2443 AR_DeclspecAttributesParsed,
2444 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
2445 AR_DeclspecAttributesParsed
2448 void ParseTypeQualifierListOpt(
2449 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2450 bool AtomicAllowed =
true,
bool IdentifierRequired =
false,
2451 Optional<llvm::function_ref<
void()>> CodeCompletionHandler =
None);
2452 void ParseDirectDeclarator(Declarator &D);
2453 void ParseDecompositionDeclarator(Declarator &D);
2454 void ParseParenDeclarator(Declarator &D);
2455 void ParseFunctionDeclarator(Declarator &D,
2456 ParsedAttributes &attrs,
2459 bool RequiresArg =
false);
2460 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2461 SourceLocation &RefQualifierLoc);
2462 bool isFunctionDeclaratorIdentifierList();
2463 void ParseFunctionDeclaratorIdentifierList(
2465 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2466 void ParseParameterDeclarationClause(
2468 ParsedAttributes &attrs,
2469 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2470 SourceLocation &EllipsisLoc);
2471 void ParseBracketDeclarator(Declarator &D);
2472 void ParseMisplacedBracketDeclarator(Declarator &D);
2478 enum CXX11AttributeKind {
2480 CAK_NotAttributeSpecifier,
2482 CAK_AttributeSpecifier,
2485 CAK_InvalidAttributeSpecifier
2488 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
2489 bool OuterMightBeMessageSend =
false);
2491 void DiagnoseUnexpectedNamespace(NamedDecl *
Context);
2494 SourceLocation InlineLoc = SourceLocation());
2495 void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
2496 std::vector<IdentifierInfo*>& Ident,
2497 std::vector<SourceLocation>& NamespaceLoc,
2498 unsigned int index, SourceLocation& InlineLoc,
2499 ParsedAttributes& attrs,
2501 Decl *ParseLinkage(ParsingDeclSpec &DS,
unsigned Context);
2502 Decl *ParseExportDeclaration();
2504 unsigned Context,
const ParsedTemplateInfo &TemplateInfo,
2505 SourceLocation &DeclEnd, ParsedAttributesWithRange &attrs);
2506 Decl *ParseUsingDirective(
unsigned Context,
2507 SourceLocation UsingLoc,
2508 SourceLocation &DeclEnd,
2509 ParsedAttributes &attrs);
2511 struct UsingDeclarator {
2512 SourceLocation TypenameLoc;
2514 SourceLocation TemplateKWLoc;
2516 SourceLocation EllipsisLoc;
2519 TypenameLoc = TemplateKWLoc = EllipsisLoc = SourceLocation();
2525 bool ParseUsingDeclarator(
unsigned Context, UsingDeclarator &D);
2527 const ParsedTemplateInfo &TemplateInfo,
2528 SourceLocation UsingLoc,
2529 SourceLocation &DeclEnd,
2531 Decl *ParseAliasDeclarationAfterDeclarator(
2532 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
2534 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
2536 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2537 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2538 SourceLocation AliasLoc, IdentifierInfo *Alias,
2539 SourceLocation &DeclEnd);
2543 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
2544 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
2545 DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo,
2547 DeclSpecContext DSC,
2548 ParsedAttributesWithRange &Attributes);
2549 void SkipCXXMemberSpecification(SourceLocation StartLoc,
2550 SourceLocation AttrFixitLoc,
2553 void ParseCXXMemberSpecification(SourceLocation StartLoc,
2554 SourceLocation AttrFixitLoc,
2555 ParsedAttributesWithRange &Attrs,
2558 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
2559 SourceLocation &EqualLoc);
2560 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
2563 LateParsedAttrList &LateAttrs);
2564 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
2565 VirtSpecifiers &VS);
2568 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2569 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
2573 void ParseConstructorInitializer(Decl *ConstructorDecl);
2575 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
2580 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
2581 SourceLocation &EndLocation);
2582 void ParseBaseClause(Decl *ClassDecl);
2583 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
2586 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
2587 SourceLocation TemplateKWLoc,
2588 IdentifierInfo *
Name,
2589 SourceLocation NameLoc,
2590 bool EnteringContext,
2593 bool AssumeTemplateId);
2594 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2603 SourceLocation Loc);
2608 Decl *TagDecl =
nullptr);
2619 bool ParseOpenMPSimpleVarList(
2621 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)> &
2623 bool AllowScopeSpecifier);
2632 ParseOpenMPDeclarativeOrExecutableDirective(AllowedConstructsKind Allowed);
2686 bool IsMapTypeImplicit =
false;
2695 bool AllowDestructorName,
2696 bool AllowConstructorName,
2697 bool AllowDeductionGuide,
2707 Decl *ParseDeclarationStartingWithTemplate(
unsigned Context,
2711 Decl *ParseTemplateDeclarationOrSpecialization(
unsigned Context,
2715 Decl *ParseSingleDeclarationAfterTemplate(
2717 const ParsedTemplateInfo &TemplateInfo,
2722 bool ParseTemplateParameters(
unsigned Depth,
2726 bool ParseTemplateParameterList(
unsigned Depth,
2728 bool isStartOfTemplateTypeParameter();
2735 bool AlreadyHasEllipsis,
2736 bool IdentifierHasName);
2737 void DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
2743 bool ConsumeLastToken,
2744 bool ObjCGenericList);
2745 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
2754 bool AllowTypeAnnotation =
true);
2755 void AnnotateTemplateIdTokenAsType(
bool IsClassName =
false);
2756 bool IsTemplateArgumentList(
unsigned Skip = 0);
2760 Decl *ParseExplicitInstantiation(
unsigned Context,
2770 bool parseMisplacedModuleImport();
2771 bool tryParseMisplacedModuleImport() {
2773 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
2774 Kind == tok::annot_module_include)
2775 return parseMisplacedModuleImport();
2779 bool ParseModuleName(
2795 void CodeCompleteDirective(
bool InConditional)
override;
2796 void CodeCompleteInConditionalExclusion()
override;
2797 void CodeCompleteMacroName(
bool IsDefinition)
override;
2798 void CodeCompletePreprocessorExpression()
override;
2800 unsigned ArgumentIndex)
override;
2801 void CodeCompleteNaturalLanguage()
override;
Sema::FullExprArg FullExprArg
Scope * getCurScope() const
Retrieve the parser's current scope.
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind...
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
ParseScope - Introduces a new scope for parsing.
DeclarationNameInfo ReductionId
SourceLocation getEndOfPreviousToken()
void Initialize()
Initialize - Warm up the parser.
const Token & getCurToken() const
const LangOptions & getLangOpts() const
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
NullabilityKind
Describes the nullability of a particular type.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
ActionResult< Expr * > ExprResult
Decl - This represents one declaration (or definition), e.g.
void incrementMSManglingNumber() const
RAII object used to inform the actions that we're currently parsing a declaration.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
SourceLocation DepLinMapLoc
Decl * getObjCDeclContext() const
void setCodeCompletionReached()
Note that we hit the code-completion point.
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
Information about one declarator, including the parsed type information and the identifier.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
friend class ObjCDeclContextSwitch
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
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 ...
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
friend class BalancedDelimiterTracker
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
const LangOptions & getLangOpts() const
Token - This structure provides full information about a lexed token.
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation &TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
void setKind(tok::TokenKind K)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
Defines some OpenMP-specific enums and functions.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const TargetInfo & getTargetInfo() const
Represents a C++ unqualified-id that has been parsed.
friend constexpr SkipUntilFlags operator|(SkipUntilFlags L, SkipUntilFlags R)
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc)
Concrete class used by the front-end to report problems and issues.
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
Scope - A scope is a transient data structure that is used while parsing the program.
Represents a C++ nested-name-specifier or a global scope specifier.
tok::TokenKind getKind() const
const TargetInfo & getTargetInfo() const
AttributeFactory & getAttrFactory()
void * getAnnotationValue() const
Sema - This implements semantic analysis and AST building for C.
A little helper class used to produce diagnostics.
TypeResult ParseTypeName(SourceRange *Range=nullptr, Declarator::TheContext Context=Declarator::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Exposes information about the current target.
void setAnnotationValue(void *val)
Expr - This represents one expression.
MatchFinder::MatchCallback * Callback
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
OpaquePtr< TemplateName > TemplateTy
CXXScopeSpec ReductionIdScopeSpec
Defines the clang::Preprocessor interface.
OpenMPClauseKind
OpenMP clauses.
Represents a C++ template name within the type system.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
bool isNot(tok::TokenKind K) const
Defines and computes precedence levels for binary/ternary operators.
ActionResult< CXXCtorInitializer * > MemInitResult
The result type of a method or function.
SourceLocation getAnnotationEndLoc() const
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Stop skipping at semicolon.
Represents the parsed form of a C++ template argument.
ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, void *Info, bool IsUnevaluated)
Parse an identifier in an MS-style inline assembly block.
Encodes a location in the source.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
bool TryAnnotateTypeOrScopeToken()
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
DiagnosticBuilder Diag(unsigned DiagID)
void ExitScope()
ExitScope - Pop a scope off the scope stack.
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies)
OpenMPDirectiveKind
OpenMP directives.
Scope * getCurScope() const
void Lex(Token &Result)
Lex the next token for this preprocessor.
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Preprocessor & getPreprocessor() const
ActionResult< CXXBaseSpecifier * > BaseResult
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)) {...
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc)
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
Defines various enumerations that describe declaration and type specifiers.
ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope=true, bool BeforeCompoundStmt=false)
static bool isInvalid(LocType Loc, bool *Invalid)
Sema & getActions() const
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
SkipUntilFlags
Control flags for SkipUntil functions.
Data used for parsing list of variables in OpenMP clauses.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
static const TST TST_unspecified
friend class ColonProtectionRAIIObject
Encapsulates the data about a macro definition (e.g.
Syntax
The style used to specify an attribute.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
ActionResult< Stmt * > StmtResult
void * getAsOpaquePtr() const
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
ActionResult< ParsedType > TypeResult
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
ProcessingContextState ParsingClassState
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
void incrementMSManglingNumber() const
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the keyword associated.
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS, bool IsNewScope)
Try to annotate a type or scope token, having already parsed an optional scope specifier.
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr * > &Vars, OpenMPVarListDataTy &Data)
Parses clauses with list.
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
A trivial tuple used to represent a source range.
Callback handler that receives notifications when performing code completion within the preprocessor...
Decl * getObjCDeclContext() const
static OpaquePtr getFromOpaquePtr(void *P)
SourceLocation ColonLoc
Location of ':'.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result)
Parse the first top-level declaration in a translation unit.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
AttributeList - Represents a syntactic attribute.
Stop skipping at specified token, but don't skip the token itself.