14 #ifndef LLVM_CLANG_PARSE_PARSER_H
15 #define LLVM_CLANG_PARSE_PARSER_H
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/Support/Compiler.h"
27 #include "llvm/Support/PrettyStackTrace.h"
28 #include "llvm/Support/SaveAndRestore.h"
35 class BalancedDelimiterTracker;
36 class CorrectionCandidateCallback;
38 class DiagnosticBuilder;
40 class ParsingDeclRAIIObject;
41 class ParsingDeclSpec;
42 class ParsingDeclarator;
43 class ParsingFieldDeclarator;
44 class ColonProtectionRAIIObject;
45 class InMessageExpressionRAIIObject;
46 class PoisonSEHIdentifiersRAIIObject;
49 class ObjCTypeParamList;
50 class ObjCTypeParameter;
76 unsigned short ParenCount, BracketCount, BraceCount;
85 enum { ScopeCacheSize = 16 };
86 unsigned NumCachedScopes;
87 Scope *ScopeCache[ScopeCacheSize];
93 *Ident___exception_code,
94 *Ident_GetExceptionCode;
97 *Ident___exception_info,
98 *Ident_GetExceptionInfo;
101 *Ident___abnormal_termination,
102 *Ident_AbnormalTermination;
143 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
145 std::unique_ptr<PragmaHandler> AlignHandler;
146 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
147 std::unique_ptr<PragmaHandler> OptionsHandler;
148 std::unique_ptr<PragmaHandler> PackHandler;
149 std::unique_ptr<PragmaHandler> MSStructHandler;
150 std::unique_ptr<PragmaHandler> UnusedHandler;
151 std::unique_ptr<PragmaHandler> WeakHandler;
152 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
153 std::unique_ptr<PragmaHandler> FPContractHandler;
154 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
155 std::unique_ptr<PragmaHandler> OpenMPHandler;
156 std::unique_ptr<PragmaHandler> MSCommentHandler;
157 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
158 std::unique_ptr<PragmaHandler> MSPointersToMembers;
159 std::unique_ptr<PragmaHandler> MSVtorDisp;
160 std::unique_ptr<PragmaHandler> MSInitSeg;
161 std::unique_ptr<PragmaHandler> MSDataSeg;
162 std::unique_ptr<PragmaHandler> MSBSSSeg;
163 std::unique_ptr<PragmaHandler> MSConstSeg;
164 std::unique_ptr<PragmaHandler> MSCodeSeg;
165 std::unique_ptr<PragmaHandler> MSSection;
166 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
167 std::unique_ptr<PragmaHandler> OptimizeHandler;
168 std::unique_ptr<PragmaHandler> LoopHintHandler;
169 std::unique_ptr<PragmaHandler> UnrollHintHandler;
170 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
172 std::unique_ptr<CommentHandler> CommentSemaHandler;
178 bool GreaterThanIsOperator;
191 bool InMessageExpression;
194 unsigned TemplateParameterDepth;
197 class TemplateParameterDepthRAII {
199 unsigned AddedLevels;
201 explicit TemplateParameterDepthRAII(
unsigned &
Depth)
202 : Depth(Depth), AddedLevels(0) {}
204 ~TemplateParameterDepthRAII() {
205 Depth -= AddedLevels;
212 void addDepth(
unsigned D) {
216 unsigned getDepth()
const {
return Depth; }
220 AttributeFactory AttrFactory;
224 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
227 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
229 IdentifierInfo *getSEHExceptKeyword();
236 bool ParsingInObjCContainer;
238 bool SkipFunctionBodies;
241 Parser(Preprocessor &PP, Sema &Actions,
bool SkipFunctionBodies);
286 assert(!isTokenSpecial() &&
287 "Should consume special tokens with Consume*Token");
290 return PrevTokLocation;
294 if (Tok.
isNot(Expected))
296 assert(!isTokenSpecial() &&
297 "Should consume special tokens with Consume*Token");
306 Loc = PrevTokLocation;
322 bool isTokenParen()
const {
323 return Tok.
getKind() == tok::l_paren || Tok.
getKind() == tok::r_paren;
326 bool isTokenBracket()
const {
327 return Tok.
getKind() == tok::l_square || Tok.
getKind() == tok::r_square;
330 bool isTokenBrace()
const {
331 return Tok.
getKind() == tok::l_brace || Tok.
getKind() == tok::r_brace;
334 bool isTokenStringLiteral()
const {
338 bool isTokenSpecial()
const {
339 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
340 isTokenBrace() || Tok.
is(tok::code_completion);
345 bool isTokenEqualOrEqualTypo();
349 void UnconsumeToken(
Token &Consumed) {
359 SourceLocation ConsumeAnyToken(
bool ConsumeCodeCompletionTok =
false) {
361 return ConsumeParen();
362 if (isTokenBracket())
363 return ConsumeBracket();
365 return ConsumeBrace();
366 if (isTokenStringLiteral())
367 return ConsumeStringToken();
368 if (Tok.
is(tok::code_completion))
369 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
370 : handleUnexpectedCodeCompletionToken();
376 SourceLocation ConsumeParen() {
377 assert(isTokenParen() &&
"wrong consume method");
378 if (Tok.
getKind() == tok::l_paren)
384 return PrevTokLocation;
389 SourceLocation ConsumeBracket() {
390 assert(isTokenBracket() &&
"wrong consume method");
391 if (Tok.
getKind() == tok::l_square)
393 else if (BracketCount)
398 return PrevTokLocation;
403 SourceLocation ConsumeBrace() {
404 assert(isTokenBrace() &&
"wrong consume method");
405 if (Tok.
getKind() == tok::l_brace)
412 return PrevTokLocation;
419 SourceLocation ConsumeStringToken() {
420 assert(isTokenStringLiteral() &&
421 "Should only consume string literals with this method");
424 return PrevTokLocation;
432 SourceLocation ConsumeCodeCompletionToken() {
433 assert(Tok.
is(tok::code_completion));
436 return PrevTokLocation;
444 SourceLocation handleUnexpectedCodeCompletionToken();
448 void cutOffParsing() {
459 return Kind ==
tok::eof || Kind == tok::annot_module_begin ||
460 Kind == tok::annot_module_end || Kind == tok::annot_module_include;
464 void initializePragmaHandlers();
467 void resetPragmaHandlers();
470 void HandlePragmaUnused();
474 void HandlePragmaVisibility();
478 void HandlePragmaPack();
482 void HandlePragmaMSStruct();
486 void HandlePragmaMSComment();
488 void HandlePragmaMSPointersToMembers();
490 void HandlePragmaMSVtorDisp();
492 void HandlePragmaMSPragma();
493 bool HandlePragmaMSSection(StringRef PragmaName,
494 SourceLocation PragmaLocation);
495 bool HandlePragmaMSSegment(StringRef PragmaName,
496 SourceLocation PragmaLocation);
497 bool HandlePragmaMSInitSeg(StringRef PragmaName,
498 SourceLocation PragmaLocation);
502 void HandlePragmaAlign();
506 void HandlePragmaDump();
510 void HandlePragmaWeak();
514 void HandlePragmaWeakAlias();
518 void HandlePragmaRedefineExtname();
522 void HandlePragmaFPContract();
526 void HandlePragmaOpenCLExtension();
534 bool HandlePragmaLoopHint(LoopHint &Hint);
543 const Token &GetLookAheadToken(
unsigned N) {
568 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
574 Tok.setAnnotationValue(ER.getAsOpaquePointer());
581 bool NeedType =
false);
589 enum AnnotatedNameKind {
602 TryAnnotateName(
bool IsAddressOfOperand,
603 std::unique_ptr<CorrectionCandidateCallback> CCC =
nullptr);
606 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
611 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
612 const char *&PrevSpec,
unsigned &DiagID,
617 if (Tok.getIdentifierInfo() != Ident_vector &&
618 Tok.getIdentifierInfo() != Ident_bool &&
619 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
622 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
628 bool TryAltiVecVectorToken() {
630 Tok.getIdentifierInfo() != Ident_vector)
return false;
631 return TryAltiVecVectorTokenOutOfLine();
634 bool TryAltiVecVectorTokenOutOfLine();
635 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
636 const char *&PrevSpec,
unsigned &DiagID,
642 bool isObjCInstancetype() {
644 if (!Ident_instancetype)
646 return Tok.getIdentifierInfo() == Ident_instancetype;
654 bool TryKeywordIdentFallback(
bool DisableKeyword);
657 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
670 class TentativeParsingAction {
673 size_t PrevTentativelyDeclaredIdentifierCount;
674 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
678 explicit TentativeParsingAction(
Parser&
p) :
P(p) {
680 PrevTentativelyDeclaredIdentifierCount =
681 P.TentativelyDeclaredIdentifiers.size();
682 PrevParenCount =
P.ParenCount;
683 PrevBracketCount =
P.BracketCount;
684 PrevBraceCount =
P.BraceCount;
685 P.PP.EnableBacktrackAtThisPos();
689 assert(
isActive &&
"Parsing action was finished!");
690 P.TentativelyDeclaredIdentifiers.resize(
691 PrevTentativelyDeclaredIdentifierCount);
692 P.PP.CommitBacktrackedTokens();
696 assert(
isActive &&
"Parsing action was finished!");
699 P.TentativelyDeclaredIdentifiers.resize(
700 PrevTentativelyDeclaredIdentifierCount);
701 P.ParenCount = PrevParenCount;
702 P.BracketCount = PrevBracketCount;
703 P.BraceCount = PrevBraceCount;
706 ~TentativeParsingAction() {
707 assert(!
isActive &&
"Forgot to call Commit or Revert!");
710 class UnannotatedTentativeParsingAction;
718 SaveAndRestore<bool> WithinObjCContainer;
722 WithinObjCContainer(
P.ParsingInObjCContainer, DC != nullptr) {
724 P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
728 P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
741 unsigned Diag = diag::err_expected,
742 StringRef DiagMsg =
"");
749 bool ExpectAndConsumeSemi(
unsigned DiagID);
755 InstanceVariableList = 2,
756 AfterMemberFunctionDefinition = 3
760 void ConsumeExtraSemi(ExtraSemiKind Kind,
unsigned TST =
TST_unspecified);
782 bool BeforeCompoundStmt =
false)
784 if (EnteredScope && !BeforeCompoundStmt)
787 if (BeforeCompoundStmt)
790 this->Self =
nullptr;
816 class ParseScopeFlags {
819 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
820 void operator=(
const ParseScopeFlags &) =
delete;
823 ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
831 DiagnosticBuilder
Diag(SourceLocation Loc,
unsigned DiagID);
832 DiagnosticBuilder
Diag(
const Token &Tok,
unsigned DiagID);
834 return Diag(Tok, DiagID);
855 static_cast<unsigned>(R));
868 return SkipUntil(llvm::makeArrayRef(T), Flags);
901 class LateParsedDeclaration {
903 virtual ~LateParsedDeclaration();
905 virtual void ParseLexedMethodDeclarations();
906 virtual void ParseLexedMemberInitializers();
907 virtual void ParseLexedMethodDefs();
908 virtual void ParseLexedAttributes();
913 class LateParsedClass :
public LateParsedDeclaration {
915 LateParsedClass(
Parser *
P, ParsingClass *
C);
916 ~LateParsedClass()
override;
918 void ParseLexedMethodDeclarations()
override;
919 void ParseLexedMemberInitializers()
override;
920 void ParseLexedMethodDefs()
override;
921 void ParseLexedAttributes()
override;
934 struct LateParsedAttribute :
public LateParsedDeclaration {
937 IdentifierInfo &AttrName;
938 SourceLocation AttrNameLoc;
939 SmallVector<Decl*, 2> Decls;
941 explicit LateParsedAttribute(
Parser *
P, IdentifierInfo &
Name,
943 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
945 void ParseLexedAttributes()
override;
947 void addDecl(Decl *D) { Decls.push_back(D); }
951 class LateParsedAttrList:
public SmallVector<LateParsedAttribute *, 2> {
953 LateParsedAttrList(
bool PSoon =
false) : ParseSoon(PSoon) { }
955 bool parseSoon() {
return ParseSoon; }
964 struct LexedMethod :
public LateParsedDeclaration {
974 explicit LexedMethod(
Parser*
P, Decl *MD)
975 : Self(P), D(MD), TemplateScope(
false) {}
977 void ParseLexedMethodDefs()
override;
984 struct LateParsedDefaultArgument {
985 explicit LateParsedDefaultArgument(Decl *
P,
987 : Param(P), Toks(Toks) { }
1003 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1004 explicit LateParsedMethodDeclaration(
Parser *
P, Decl *M)
1005 : Self(P), Method(M), TemplateScope(
false),
1006 ExceptionSpecTokens(nullptr) {}
1008 void ParseLexedMethodDeclarations()
override;
1025 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1035 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1036 LateParsedMemberInitializer(
Parser *
P, Decl *FD)
1037 : Self(P), Field(FD) { }
1039 void ParseLexedMemberInitializers()
override;
1057 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
1062 struct ParsingClass {
1063 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
1064 : TopLevelClass(TopLevelClass), TemplateScope(
false),
1065 IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { }
1069 bool TopLevelClass : 1;
1074 bool TemplateScope : 1;
1077 bool IsInterface : 1;
1080 Decl *TagOrTemplate;
1085 LateParsedDeclarationsContainer LateParsedDeclarations;
1091 std::stack<ParsingClass *> ClassStack;
1093 ParsingClass &getCurrentClass() {
1094 assert(!ClassStack.empty() &&
"No lexed method stacks!");
1095 return *ClassStack.top();
1099 class ParsingClassDefinition {
1105 ParsingClassDefinition(
Parser &
P, Decl *TagOrTemplate,
bool TopLevelClass,
1107 : P(P), Popped(
false),
1108 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1113 assert(!Popped &&
"Nested class has already been popped");
1115 P.PopParsingClass(
State);
1118 ~ParsingClassDefinition() {
1120 P.PopParsingClass(
State);
1127 struct ParsedTemplateInfo {
1128 ParsedTemplateInfo()
1129 : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
1132 bool isSpecialization,
1133 bool lastParameterListWasEmpty =
false)
1134 : Kind(isSpecialization? ExplicitSpecialization : Template),
1135 TemplateParams(TemplateParams),
1136 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1138 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1139 SourceLocation TemplateLoc)
1140 : Kind(ExplicitInstantiation), TemplateParams(nullptr),
1141 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1142 LastParameterListWasEmpty(
false){ }
1151 ExplicitSpecialization,
1153 ExplicitInstantiation
1162 SourceLocation ExternLoc;
1166 SourceLocation TemplateLoc;
1169 bool LastParameterListWasEmpty;
1171 SourceRange getSourceRange() const LLVM_READONLY;
1174 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
1175 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1177 static
void LateTemplateParserCallback(
void *
P, LateParsedTemplate &LPT);
1178 static
void LateTemplateParserCleanupCallback(
void *P);
1180 Sema::ParsingClassState
1181 PushParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
1182 void DeallocateParsedClasses(ParsingClass *Class);
1183 void PopParsingClass(Sema::ParsingClassState);
1185 enum CachedInitKind {
1186 CIK_DefaultArgument,
1187 CIK_DefaultInitializer
1191 AttributeList *AccessAttrs,
1192 ParsingDeclarator &D,
1193 const ParsedTemplateInfo &TemplateInfo,
1194 const VirtSpecifiers& VS,
1195 SourceLocation PureSpecLoc);
1196 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1197 void ParseLexedAttributes(ParsingClass &Class);
1198 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1200 void ParseLexedAttribute(LateParsedAttribute &LA,
1202 void ParseLexedMethodDeclarations(ParsingClass &Class);
1203 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1204 void ParseLexedMethodDefs(ParsingClass &Class);
1205 void ParseLexedMethodDef(LexedMethod &LM);
1206 void ParseLexedMemberInitializers(ParsingClass &Class);
1207 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1208 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
1209 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1210 bool ConsumeAndStoreInitializer(
CachedTokens &Toks, CachedInitKind CIK);
1215 bool ConsumeFinalToken =
true) {
1216 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1221 bool ConsumeFinalToken =
true);
1225 struct ParsedAttributesWithRange : ParsedAttributes {
1226 ParsedAttributesWithRange(AttributeFactory &factory)
1227 : ParsedAttributes(factory) {}
1232 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
1233 ParsingDeclSpec *DS =
nullptr);
1234 bool isDeclarationAfterDeclarator();
1235 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1237 ParsedAttributesWithRange &attrs,
1238 ParsingDeclSpec *DS =
nullptr,
1240 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
1241 ParsingDeclSpec &DS,
1244 void SkipFunctionBody();
1245 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1246 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1247 LateParsedAttrList *LateParsedAttrs =
nullptr);
1248 void ParseKNRParamDeclarations(Declarator &D);
1251 ExprResult ParseSimpleAsm(SourceLocation *EndLoc =
nullptr);
1257 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1258 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1259 ParsedAttributes &prefixAttrs);
1260 class ObjCTypeParamListScope;
1261 ObjCTypeParamList *parseObjCTypeParamList();
1262 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1263 ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1264 SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1265 SourceLocation &rAngleLoc,
bool mayBeProtocolList =
true);
1267 void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1269 SmallVectorImpl<Decl *> &AllIvarDecls,
1270 bool RBraceMissing);
1271 void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
1273 SourceLocation atLoc);
1274 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &
P,
1275 SmallVectorImpl<SourceLocation> &PLocs,
1276 bool WarnOnDeclarations,
1277 bool ForObjCContainer,
1278 SourceLocation &LAngleLoc,
1279 SourceLocation &EndProtoLoc,
1280 bool consumeLastToken);
1285 void parseObjCTypeArgsOrProtocolQualifiers(
1287 SourceLocation &typeArgsLAngleLoc,
1288 SmallVectorImpl<ParsedType> &typeArgs,
1289 SourceLocation &typeArgsRAngleLoc,
1290 SourceLocation &protocolLAngleLoc,
1291 SmallVectorImpl<Decl *> &protocols,
1292 SmallVectorImpl<SourceLocation> &protocolLocs,
1293 SourceLocation &protocolRAngleLoc,
1294 bool consumeLastToken,
1295 bool warnOnIncompleteProtocols);
1299 void parseObjCTypeArgsAndProtocolQualifiers(
1301 SourceLocation &typeArgsLAngleLoc,
1302 SmallVectorImpl<ParsedType> &typeArgs,
1303 SourceLocation &typeArgsRAngleLoc,
1304 SourceLocation &protocolLAngleLoc,
1305 SmallVectorImpl<Decl *> &protocols,
1306 SmallVectorImpl<SourceLocation> &protocolLocs,
1307 SourceLocation &protocolRAngleLoc,
1308 bool consumeLastToken);
1312 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1316 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1318 bool consumeLastToken,
1319 SourceLocation &endLoc);
1323 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1324 ParsedAttributes &prefixAttrs);
1326 struct ObjCImplParsingDataRAII {
1330 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1331 LateParsedObjCMethodContainer LateParsedObjCMethods;
1333 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
1334 :
P(parser), Dcl(D), HasCFunction(
false) {
1335 P.CurParsedObjCImpl =
this;
1338 ~ObjCImplParsingDataRAII();
1340 void finish(SourceRange AtEnd);
1341 bool isFinished()
const {
return Finished; }
1346 ObjCImplParsingDataRAII *CurParsedObjCImpl;
1347 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
1349 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1351 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1352 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1353 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1355 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1358 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1359 objc_nonnull, objc_nullable, objc_null_unspecified,
1362 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1364 bool isTokIdentifier_in()
const;
1367 ParsedAttributes *ParamAttrs);
1368 void ParseObjCMethodRequirement();
1369 Decl *ParseObjCMethodPrototype(
1371 bool MethodDefinition =
true);
1374 bool MethodDefinition=
true);
1375 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1377 Decl *ParseObjCMethodDefinition();
1397 unsigned &NumLineToksConsumed,
1399 bool IsUnevaluated);
1408 ExprResult ParseCastExpression(
bool isUnaryExpression,
1409 bool isAddressOfOperand,
1412 ExprResult ParseCastExpression(
bool isUnaryExpression,
1413 bool isAddressOfOperand =
false,
1417 bool isNotExpressionStart();
1421 bool isPostfixExpressionSuffixStart() {
1423 return (K == tok::l_square || K == tok::l_paren ||
1424 K == tok::period || K == tok::arrow ||
1425 K == tok::plusplus || K == tok::minusminus);
1429 ExprResult ParseUnaryExprOrTypeTraitExpression();
1435 SourceRange &CastRange);
1437 typedef SmallVector<Expr*, 20> ExprListTy;
1438 typedef SmallVector<SourceLocation, 20> CommaLocsTy;
1441 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1442 SmallVectorImpl<SourceLocation> &CommaLocs,
1443 std::function<
void()> Completer =
nullptr);
1447 bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
1448 SmallVectorImpl<SourceLocation> &CommaLocs);
1452 enum ParenParseOption {
1458 ExprResult ParseParenExpression(ParenParseOption &ExprType,
1459 bool stopIfCastExpr,
1462 SourceLocation &RParenLoc);
1465 ParenParseOption &ExprType,
ParsedType &CastTy,
1468 SourceLocation LParenLoc,
1469 SourceLocation RParenLoc);
1471 ExprResult ParseStringLiteralExpression(
bool AllowUserDefinedLiteral =
false);
1473 ExprResult ParseGenericSelectionExpression();
1481 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
1482 Token &Replacement);
1483 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
1485 bool areTokensAdjacent(
const Token &A,
const Token &B);
1487 void CheckForTemplateAndDigraph(
Token &Next,
ParsedType ObjectTypePtr,
1488 bool EnteringContext, IdentifierInfo &II,
1491 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1493 bool EnteringContext,
1494 bool *MayBePseudoDestructor =
nullptr,
1495 bool IsTypename =
false,
1496 IdentifierInfo **LastII =
nullptr);
1498 void CheckForLParenAfterColonColon();
1506 Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro,
1507 bool *SkippedInits =
nullptr);
1508 bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1509 ExprResult ParseLambdaExpressionAfterIntroducer(
1510 LambdaIntroducer &Intro);
1526 ExprResult ParseCXXPseudoDestructor(Expr *
Base, SourceLocation OpLoc,
1541 SourceRange &SpecificationRange,
1542 SmallVectorImpl<ParsedType> &DynamicExceptions,
1543 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
1549 SourceRange &SpecificationRange,
1550 SmallVectorImpl<ParsedType> &Exceptions,
1551 SmallVectorImpl<SourceRange> &
Ranges);
1555 TypeResult ParseTrailingReturnType(SourceRange &Range);
1563 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
1568 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1570 bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
1574 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1576 void ParseDirectNewDeclarator(Declarator &D);
1577 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
1578 ExprResult ParseCXXDeleteExpression(
bool UseGlobal,
1579 SourceLocation Start);
1584 SourceLocation Loc,
bool ConvertToBoolean);
1599 if (Tok.isNot(tok::l_brace))
1601 return ParseBraceInitializer();
1603 bool MayBeDesignationStart();
1605 ExprResult ParseInitializerWithPotentialDesignator();
1614 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
1615 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
1616 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1617 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1618 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
1619 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1620 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
1621 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
1622 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
1623 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
1624 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
1625 bool isSimpleObjCMessageExpression();
1627 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
1628 SourceLocation SuperLoc,
1630 Expr *ReceiverExpr);
1631 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
1632 SourceLocation LBracloc, SourceLocation SuperLoc,
1633 ParsedType ReceiverType, Expr *ReceiverExpr);
1634 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
1641 typedef SmallVector<Stmt*, 32> StmtVector;
1643 typedef SmallVector<Expr*, 12> ExprVector;
1645 typedef SmallVector<ParsedType, 12> TypeVector;
1647 StmtResult ParseStatement(SourceLocation *TrailingElseLoc =
nullptr,
1648 bool AllowOpenMPStandalone =
false);
1649 enum AllowedContsructsKind {
1653 ACK_StatementsOpenMPNonStandalone,
1655 ACK_StatementsOpenMPAnyExecutable
1658 ParseStatementOrDeclaration(StmtVector &Stmts, AllowedContsructsKind Allowed,
1659 SourceLocation *TrailingElseLoc =
nullptr);
1660 StmtResult ParseStatementOrDeclarationAfterAttributes(
1662 AllowedContsructsKind Allowed,
1663 SourceLocation *TrailingElseLoc,
1664 ParsedAttributesWithRange &Attrs);
1666 StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
1667 StmtResult ParseCaseStatement(
bool MissingCase =
false,
1670 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
1671 StmtResult ParseCompoundStatement(
bool isStmtExpr,
1672 unsigned ScopeFlags);
1673 void ParseCompoundStatementLeadingPragmas();
1674 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
1678 bool ConvertToBoolean);
1679 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
1680 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
1681 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
1683 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
1689 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1690 StmtResult ParsePragmaLoopHint(StmtVector &Stmts,
1691 AllowedContsructsKind Allowed,
1692 SourceLocation *TrailingElseLoc,
1693 ParsedAttributesWithRange &Attrs);
1697 enum IfExistsBehavior {
1709 struct IfExistsCondition {
1711 SourceLocation KeywordLoc;
1724 IfExistsBehavior Behavior;
1727 bool ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result);
1728 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1729 void ParseMicrosoftIfExistsExternalDeclaration();
1730 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
1732 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
1734 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
1735 SmallVectorImpl<Expr *> &Constraints,
1736 SmallVectorImpl<Expr *> &Exprs);
1742 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc,
bool FnTry =
false);
1743 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
1749 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
1750 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
1756 StmtResult ParseObjCAtStatement(SourceLocation atLoc);
1757 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
1758 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1759 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1760 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1769 enum DeclSpecContext {
1774 DSC_alias_declaration,
1776 DSC_template_type_arg,
1777 DSC_objc_method_result,
1783 static bool isTypeSpecifier(DeclSpecContext DSC) {
1788 case DSC_objc_method_result:
1792 case DSC_template_type_arg:
1793 case DSC_type_specifier:
1795 case DSC_alias_declaration:
1798 llvm_unreachable(
"Missing DeclSpecContext case");
1803 struct ForRangeInit {
1807 bool ParsedForRangeDecl() {
return !
ColonLoc.isInvalid(); }
1811 ParsedAttributesWithRange &attrs);
1813 SourceLocation &DeclEnd,
1814 ParsedAttributesWithRange &attrs,
1816 ForRangeInit *FRI =
nullptr);
1817 bool MightBeDeclarator(
unsigned Context);
1819 SourceLocation *DeclEnd =
nullptr,
1820 ForRangeInit *FRI =
nullptr);
1821 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1822 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1823 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1824 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1826 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1827 ForRangeInit *FRI =
nullptr);
1828 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1829 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
1835 bool trySkippingFunctionBody();
1837 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1838 const ParsedTemplateInfo &TemplateInfo,
1840 ParsedAttributesWithRange &Attrs);
1841 DeclSpecContext getDeclSpecContextFromDeclaratorContext(
unsigned Context);
1842 void ParseDeclarationSpecifiers(DeclSpec &DS,
1843 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1845 DeclSpecContext DSC = DSC_normal,
1846 LateParsedAttrList *LateAttrs =
nullptr);
1847 bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS,
AccessSpecifier AS,
1848 DeclSpecContext DSContext,
1849 LateParsedAttrList *LateAttrs =
nullptr);
1852 DeclSpecContext DSC = DSC_normal);
1854 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1857 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1858 const ParsedTemplateInfo &TemplateInfo,
1860 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
1861 void ParseStructUnionBody(SourceLocation StartLoc,
unsigned TagType,
1864 void ParseStructDeclaration(
1865 ParsingDeclSpec &DS,
1866 llvm::function_ref<
void(ParsingFieldDeclarator &)> FieldsCallback);
1868 bool isDeclarationSpecifier(
bool DisambiguatingWithExpression =
false);
1869 bool isTypeSpecifierQualifier();
1870 bool isTypeQualifier()
const;
1875 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
1880 bool isKnownToBeDeclarationSpecifier() {
1883 return isDeclarationSpecifier(
true);
1889 bool isDeclarationStatement() {
1891 return isCXXDeclarationStatement();
1892 return isDeclarationSpecifier(
true);
1899 bool isForInitDeclaration() {
1901 return isCXXSimpleDeclaration(
true);
1902 return isDeclarationSpecifier(
true);
1906 bool isForRangeIdentifier();
1910 bool isStartOfObjCClassMessageMissingOpenBracket();
1915 bool isConstructorDeclarator(
bool Unqualified);
1919 enum TentativeCXXTypeIdContext {
1922 TypeIdAsTemplateArgument
1929 bool isTypeIdInParens(
bool &isAmbiguous) {
1931 return isCXXTypeId(TypeIdInParens, isAmbiguous);
1932 isAmbiguous =
false;
1933 return isTypeSpecifierQualifier();
1935 bool isTypeIdInParens() {
1937 return isTypeIdInParens(isAmbiguous);
1943 bool isTypeIdUnambiguously() {
1946 return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
1947 return isTypeSpecifierQualifier();
1953 bool isCXXDeclarationStatement();
1960 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
1969 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr);
1975 bool isCXXConditionDeclaration();
1977 bool isCXXTypeId(TentativeCXXTypeIdContext
Context,
bool &isAmbiguous);
1978 bool isCXXTypeId(TentativeCXXTypeIdContext
Context) {
1980 return isCXXTypeId(Context, isAmbiguous);
1985 enum class TPResult {
1986 True, False, Ambiguous,
Error
2009 isCXXDeclarationSpecifier(TPResult BracedCastResult =
TPResult::False,
2010 bool *HasMissingTypename =
nullptr);
2015 bool isCXXDeclarationSpecifierAType();
2020 bool isTentativelyDeclared(IdentifierInfo *II);
2029 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
2030 TPResult TryParseTypeofSpecifier();
2031 TPResult TryParseProtocolQualifiers();
2032 TPResult TryParsePtrOperatorSeq();
2033 TPResult TryParseOperatorId();
2034 TPResult TryParseInitDeclaratorList();
2035 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier=
true);
2037 TryParseParameterDeclarationClause(
bool *InvalidAsDeclaration =
nullptr,
2038 bool VersusTemplateArg =
false);
2039 TPResult TryParseFunctionDeclarator();
2040 TPResult TryParseBracketDeclarator();
2041 TPResult TryConsumeDeclarationSpecifier();
2048 Decl **OwnedType =
nullptr,
2049 ParsedAttributes *Attrs =
nullptr);
2052 void ParseBlockId(SourceLocation CaretLoc);
2056 bool CheckProhibitedCXX11Attribute() {
2057 assert(Tok.is(tok::l_square));
2060 return DiagnoseProhibitedCXX11Attribute();
2062 bool DiagnoseProhibitedCXX11Attribute();
2063 void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2064 SourceLocation CorrectLocation) {
2067 if ((Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2068 Tok.isNot(tok::kw_alignas))
2070 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2072 void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2073 SourceLocation CorrectLocation);
2075 void handleDeclspecAlignBeforeClassKey(ParsedAttributesWithRange &Attrs,
2078 void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
2079 if (!attrs.Range.isValid())
return;
2080 DiagnoseProhibitedAttributes(attrs);
2083 void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
2088 void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs);
2092 SourceLocation SkipCXX11Attributes();
2096 void DiagnoseAndSkipCXX11Attributes();
2103 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2104 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2105 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2108 void MaybeParseGNUAttributes(Declarator &D,
2109 LateParsedAttrList *LateAttrs =
nullptr) {
2110 if (Tok.is(tok::kw___attribute)) {
2111 ParsedAttributes attrs(AttrFactory);
2112 SourceLocation endLoc;
2113 ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D);
2114 D.takeAttributes(attrs, endLoc);
2117 void MaybeParseGNUAttributes(ParsedAttributes &attrs,
2118 SourceLocation *endLoc =
nullptr,
2119 LateParsedAttrList *LateAttrs =
nullptr) {
2120 if (Tok.is(tok::kw___attribute))
2121 ParseGNUAttributes(attrs, endLoc, LateAttrs);
2123 void ParseGNUAttributes(ParsedAttributes &attrs,
2124 SourceLocation *endLoc =
nullptr,
2125 LateParsedAttrList *LateAttrs =
nullptr,
2126 Declarator *D =
nullptr);
2127 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2128 SourceLocation AttrNameLoc,
2129 ParsedAttributes &Attrs,
2130 SourceLocation *EndLoc,
2131 IdentifierInfo *ScopeName,
2132 SourceLocation ScopeLoc,
2135 IdentifierLoc *ParseIdentifierLoc();
2137 void MaybeParseCXX11Attributes(Declarator &D) {
2139 ParsedAttributesWithRange attrs(AttrFactory);
2140 SourceLocation endLoc;
2141 ParseCXX11Attributes(attrs, &endLoc);
2142 D.takeAttributes(attrs, endLoc);
2145 void MaybeParseCXX11Attributes(ParsedAttributes &attrs,
2146 SourceLocation *endLoc =
nullptr) {
2148 ParsedAttributesWithRange attrsWithRange(AttrFactory);
2149 ParseCXX11Attributes(attrsWithRange, endLoc);
2150 attrs.takeAllFrom(attrsWithRange);
2153 void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2154 SourceLocation *endLoc =
nullptr,
2155 bool OuterMightBeMessageSend =
false) {
2157 isCXX11AttributeSpecifier(
false, OuterMightBeMessageSend))
2158 ParseCXX11Attributes(attrs, endLoc);
2161 void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
2162 SourceLocation *EndLoc =
nullptr);
2163 void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2164 SourceLocation *EndLoc =
nullptr);
2167 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2168 SourceLocation AttrNameLoc,
2169 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2170 IdentifierInfo *ScopeName,
2171 SourceLocation ScopeLoc);
2173 IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
2175 void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
2176 SourceLocation *endLoc =
nullptr) {
2177 if (
getLangOpts().MicrosoftExt && Tok.is(tok::l_square))
2178 ParseMicrosoftAttributes(attrs, endLoc);
2180 void ParseMicrosoftAttributes(ParsedAttributes &attrs,
2181 SourceLocation *endLoc =
nullptr);
2182 void MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2183 SourceLocation *
End =
nullptr) {
2185 if (LO.DeclSpecKeyword && Tok.is(tok::kw___declspec))
2186 ParseMicrosoftDeclSpecs(Attrs,
End);
2188 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2189 SourceLocation *
End =
nullptr);
2190 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2191 SourceLocation AttrNameLoc,
2192 ParsedAttributes &Attrs);
2193 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2194 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2195 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2196 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
2197 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2198 void ParseOpenCLAttributes(ParsedAttributes &attrs);
2199 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2200 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2202 VersionTuple ParseVersionTuple(SourceRange &Range);
2203 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2204 SourceLocation AvailabilityLoc,
2205 ParsedAttributes &attrs,
2206 SourceLocation *endLoc,
2207 IdentifierInfo *ScopeName,
2208 SourceLocation ScopeLoc,
2211 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2212 SourceLocation ObjCBridgeRelatedLoc,
2213 ParsedAttributes &attrs,
2214 SourceLocation *endLoc,
2215 IdentifierInfo *ScopeName,
2216 SourceLocation ScopeLoc,
2219 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2220 SourceLocation AttrNameLoc,
2221 ParsedAttributes &Attrs,
2222 SourceLocation *EndLoc,
2223 IdentifierInfo *ScopeName,
2224 SourceLocation ScopeLoc,
2227 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2228 SourceLocation AttrNameLoc,
2229 ParsedAttributes &Attrs,
2230 SourceLocation *EndLoc,
2231 IdentifierInfo *ScopeName,
2232 SourceLocation ScopeLoc,
2235 void ParseTypeofSpecifier(DeclSpec &DS);
2236 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
2237 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
2238 SourceLocation StartLoc,
2239 SourceLocation EndLoc);
2240 void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
2241 void ParseAtomicSpecifier(DeclSpec &DS);
2243 ExprResult ParseAlignArgument(SourceLocation Start,
2244 SourceLocation &EllipsisLoc);
2245 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2246 SourceLocation *endLoc =
nullptr);
2250 return isCXX11VirtSpecifier(Tok);
2252 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
2253 SourceLocation FriendLoc);
2255 bool isCXX11FinalKeyword()
const;
2260 class DeclaratorScopeObj {
2266 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2267 :
P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2269 void EnterDeclaratorScope() {
2270 assert(!EnteredScope &&
"Already entered the scope!");
2271 assert(SS.isSet() &&
"C++ scope was not set!");
2273 CreatedScope =
true;
2276 if (!
P.Actions.ActOnCXXEnterDeclaratorScope(
P.getCurScope(), SS))
2277 EnteredScope =
true;
2280 ~DeclaratorScopeObj() {
2282 assert(SS.isSet() &&
"C++ scope was cleared ?");
2283 P.Actions.ActOnCXXExitDeclaratorScope(
P.getCurScope(), SS);
2291 void ParseDeclarator(Declarator &D);
2293 typedef void (
Parser::*DirectDeclParseFunction)(Declarator&);
2294 void ParseDeclaratorInternal(Declarator &D,
2295 DirectDeclParseFunction DirectDeclParser);
2297 enum AttrRequirements {
2298 AR_NoAttributesParsed = 0,
2299 AR_GNUAttributesParsedAndRejected = 1 << 0,
2300 AR_GNUAttributesParsed = 1 << 1,
2301 AR_CXX11AttributesParsed = 1 << 2,
2302 AR_DeclspecAttributesParsed = 1 << 3,
2303 AR_AllAttributesParsed = AR_GNUAttributesParsed |
2304 AR_CXX11AttributesParsed |
2305 AR_DeclspecAttributesParsed,
2306 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
2307 AR_DeclspecAttributesParsed
2310 void ParseTypeQualifierListOpt(DeclSpec &DS,
2311 unsigned AttrReqs = AR_AllAttributesParsed,
2312 bool AtomicAllowed =
true,
2313 bool IdentifierRequired =
false);
2314 void ParseDirectDeclarator(Declarator &D);
2315 void ParseParenDeclarator(Declarator &D);
2316 void ParseFunctionDeclarator(Declarator &D,
2317 ParsedAttributes &attrs,
2320 bool RequiresArg =
false);
2321 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2322 SourceLocation &RefQualifierLoc);
2323 bool isFunctionDeclaratorIdentifierList();
2324 void ParseFunctionDeclaratorIdentifierList(
2326 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2327 void ParseParameterDeclarationClause(
2329 ParsedAttributes &attrs,
2330 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2331 SourceLocation &EllipsisLoc);
2332 void ParseBracketDeclarator(Declarator &D);
2333 void ParseMisplacedBracketDeclarator(Declarator &D);
2339 enum CXX11AttributeKind {
2341 CAK_NotAttributeSpecifier,
2343 CAK_AttributeSpecifier,
2346 CAK_InvalidAttributeSpecifier
2349 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
2350 bool OuterMightBeMessageSend =
false);
2352 void DiagnoseUnexpectedNamespace(NamedDecl *
Context);
2355 SourceLocation InlineLoc = SourceLocation());
2356 void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
2357 std::vector<IdentifierInfo*>& Ident,
2358 std::vector<SourceLocation>& NamespaceLoc,
2359 unsigned int index, SourceLocation& InlineLoc,
2360 ParsedAttributes& attrs,
2362 Decl *ParseLinkage(ParsingDeclSpec &DS,
unsigned Context);
2363 Decl *ParseUsingDirectiveOrDeclaration(
unsigned Context,
2364 const ParsedTemplateInfo &TemplateInfo,
2365 SourceLocation &DeclEnd,
2366 ParsedAttributesWithRange &attrs,
2367 Decl **OwnedType =
nullptr);
2368 Decl *ParseUsingDirective(
unsigned Context,
2369 SourceLocation UsingLoc,
2370 SourceLocation &DeclEnd,
2371 ParsedAttributes &attrs);
2372 Decl *ParseUsingDeclaration(
unsigned Context,
2373 const ParsedTemplateInfo &TemplateInfo,
2374 SourceLocation UsingLoc,
2375 SourceLocation &DeclEnd,
2377 Decl **OwnedType =
nullptr);
2378 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2379 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2380 SourceLocation AliasLoc, IdentifierInfo *Alias,
2381 SourceLocation &DeclEnd);
2385 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
2386 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
2387 DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo,
2389 DeclSpecContext DSC,
2390 ParsedAttributesWithRange &Attributes);
2391 void SkipCXXMemberSpecification(SourceLocation StartLoc,
2392 SourceLocation AttrFixitLoc,
2395 void ParseCXXMemberSpecification(SourceLocation StartLoc,
2396 SourceLocation AttrFixitLoc,
2397 ParsedAttributesWithRange &Attrs,
2400 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
2401 SourceLocation &EqualLoc);
2402 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
2405 LateParsedAttrList &LateAttrs);
2406 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
2407 VirtSpecifiers &VS);
2410 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2411 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
2415 void ParseConstructorInitializer(Decl *ConstructorDecl);
2417 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
2422 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
2423 SourceLocation &EndLocation);
2424 void ParseBaseClause(Decl *ClassDecl);
2425 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
2428 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
2429 SourceLocation TemplateKWLoc,
2430 IdentifierInfo *
Name,
2431 SourceLocation NameLoc,
2432 bool EnteringContext,
2435 bool AssumeTemplateId);
2436 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2452 SmallVectorImpl<Expr *> &VarList,
2453 bool AllowScopeSpecifier);
2462 ParseOpenMPDeclarativeOrExecutableDirective(AllowedContsructsKind Allowed);
2502 bool AllowDestructorName,
2503 bool AllowConstructorName,
2505 SourceLocation& TemplateKWLoc,
2513 Decl *ParseDeclarationStartingWithTemplate(
unsigned Context,
2514 SourceLocation &DeclEnd,
2516 AttributeList *AccessAttrs =
nullptr);
2517 Decl *ParseTemplateDeclarationOrSpecialization(
unsigned Context,
2518 SourceLocation &DeclEnd,
2520 AttributeList *AccessAttrs);
2521 Decl *ParseSingleDeclarationAfterTemplate(
2523 const ParsedTemplateInfo &TemplateInfo,
2524 ParsingDeclRAIIObject &DiagsFromParams,
2525 SourceLocation &DeclEnd,
2527 AttributeList *AccessAttrs =
nullptr);
2528 bool ParseTemplateParameters(
unsigned Depth,
2529 SmallVectorImpl<Decl*> &TemplateParams,
2530 SourceLocation &LAngleLoc,
2531 SourceLocation &RAngleLoc);
2532 bool ParseTemplateParameterList(
unsigned Depth,
2533 SmallVectorImpl<Decl*> &TemplateParams);
2534 bool isStartOfTemplateTypeParameter();
2539 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
2540 SourceLocation CorrectLoc,
2541 bool AlreadyHasEllipsis,
2542 bool IdentifierHasName);
2543 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
2546 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
2548 bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc,
2549 bool ConsumeLastToken,
2550 bool ObjCGenericList);
2551 bool ParseTemplateIdAfterTemplateName(
TemplateTy Template,
2552 SourceLocation TemplateNameLoc,
2553 const CXXScopeSpec &SS,
2554 bool ConsumeLastToken,
2555 SourceLocation &LAngleLoc,
2556 TemplateArgList &TemplateArgs,
2557 SourceLocation &RAngleLoc);
2561 SourceLocation TemplateKWLoc,
2562 UnqualifiedId &TemplateName,
2563 bool AllowTypeAnnotation =
true);
2564 void AnnotateTemplateIdTokenAsType();
2565 bool IsTemplateArgumentList(
unsigned Skip = 0);
2566 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
2567 ParsedTemplateArgument ParseTemplateTemplateArgument();
2568 ParsedTemplateArgument ParseTemplateArgument();
2569 Decl *ParseExplicitInstantiation(
unsigned Context,
2570 SourceLocation ExternLoc,
2571 SourceLocation TemplateLoc,
2572 SourceLocation &DeclEnd,
2578 bool parseMisplacedModuleImport();
2579 bool tryParseMisplacedModuleImport() {
2581 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
2582 Kind == tok::annot_module_include)
2583 return parseMisplacedModuleImport();
2598 void CodeCompleteDirective(
bool InConditional)
override;
2599 void CodeCompleteInConditionalExclusion()
override;
2600 void CodeCompleteMacroName(
bool IsDefinition)
override;
2601 void CodeCompletePreprocessorExpression()
override;
2602 void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
2603 unsigned ArgumentIndex)
override;
2604 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.
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
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.
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.
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.
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
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
const LangOptions & getLangOpts() const
Token - This structure provides full information about a lexed token.
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
A location where the result (returned value) of evaluating a statement should be stored.
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.
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.
ActionResult< Decl * > DeclResult
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)
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
Defines the clang::Preprocessor interface.
OpenMPClauseKind
OpenMP clauses.
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.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
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.
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.
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, bool NeedType, CXXScopeSpec &SS, bool IsNewScope)
Try to annotate a type or scope token, having already parsed an optional scope specifier.
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)) {...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, ParsedType ObjectType, SourceLocation &TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
Defines various enumerations that describe declaration and type specifiers.
ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope=true, bool BeforeCompoundStmt=false)
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.
static __inline__ uint32_t volatile uint32_t * p
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
SkipUntilFlags
Control flags for SkipUntil functions.
friend LLVM_CONSTEXPR SkipUntilFlags operator|(SkipUntilFlags L, SkipUntilFlags R)
friend class ColonProtectionRAIIObject
Syntax
The style used to specify an attribute.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
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
static bool isInvalid(SourceLocation Loc, bool *Invalid)
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
ProcessingContextState ParsingClassState
static ParsedType getTypeAnnotation(Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
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...
bool TryAnnotateTypeOrScopeToken(bool EnteringContext=false, bool NeedType=false)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the keyword associated.
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 ':'.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Stop skipping at specified token, but don't skip the token itself.