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> OptimizeHandler;
167 std::unique_ptr<PragmaHandler> LoopHintHandler;
168 std::unique_ptr<PragmaHandler> UnrollHintHandler;
169 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
171 std::unique_ptr<CommentHandler> CommentSemaHandler;
177 bool GreaterThanIsOperator;
190 bool InMessageExpression;
193 unsigned TemplateParameterDepth;
196 class TemplateParameterDepthRAII {
198 unsigned AddedLevels;
200 explicit TemplateParameterDepthRAII(
unsigned &
Depth)
201 : Depth(Depth), AddedLevels(0) {}
203 ~TemplateParameterDepthRAII() {
204 Depth -= AddedLevels;
211 void addDepth(
unsigned D) {
215 unsigned getDepth()
const {
return Depth; }
219 AttributeFactory AttrFactory;
223 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
226 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
228 IdentifierInfo *getSEHExceptKeyword();
235 bool ParsingInObjCContainer;
237 bool SkipFunctionBodies;
240 Parser(Preprocessor &PP, Sema &Actions,
bool SkipFunctionBodies);
285 assert(!isTokenSpecial() &&
286 "Should consume special tokens with Consume*Token");
289 return PrevTokLocation;
293 if (Tok.
isNot(Expected))
295 assert(!isTokenSpecial() &&
296 "Should consume special tokens with Consume*Token");
305 Loc = PrevTokLocation;
321 bool isTokenParen()
const {
322 return Tok.
getKind() == tok::l_paren || Tok.
getKind() == tok::r_paren;
325 bool isTokenBracket()
const {
326 return Tok.
getKind() == tok::l_square || Tok.
getKind() == tok::r_square;
329 bool isTokenBrace()
const {
330 return Tok.
getKind() == tok::l_brace || Tok.
getKind() == tok::r_brace;
333 bool isTokenStringLiteral()
const {
337 bool isTokenSpecial()
const {
338 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
339 isTokenBrace() || Tok.
is(tok::code_completion);
344 bool isTokenEqualOrEqualTypo();
348 void UnconsumeToken(
Token &Consumed) {
358 SourceLocation ConsumeAnyToken(
bool ConsumeCodeCompletionTok =
false) {
360 return ConsumeParen();
361 if (isTokenBracket())
362 return ConsumeBracket();
364 return ConsumeBrace();
365 if (isTokenStringLiteral())
366 return ConsumeStringToken();
367 if (Tok.
is(tok::code_completion))
368 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
369 : handleUnexpectedCodeCompletionToken();
375 SourceLocation ConsumeParen() {
376 assert(isTokenParen() &&
"wrong consume method");
377 if (Tok.
getKind() == tok::l_paren)
383 return PrevTokLocation;
388 SourceLocation ConsumeBracket() {
389 assert(isTokenBracket() &&
"wrong consume method");
390 if (Tok.
getKind() == tok::l_square)
392 else if (BracketCount)
397 return PrevTokLocation;
402 SourceLocation ConsumeBrace() {
403 assert(isTokenBrace() &&
"wrong consume method");
404 if (Tok.
getKind() == tok::l_brace)
411 return PrevTokLocation;
418 SourceLocation ConsumeStringToken() {
419 assert(isTokenStringLiteral() &&
420 "Should only consume string literals with this method");
423 return PrevTokLocation;
431 SourceLocation ConsumeCodeCompletionToken() {
432 assert(Tok.
is(tok::code_completion));
435 return PrevTokLocation;
443 SourceLocation handleUnexpectedCodeCompletionToken();
447 void cutOffParsing() {
458 return Kind ==
tok::eof || Kind == tok::annot_module_begin ||
459 Kind == tok::annot_module_end || Kind == tok::annot_module_include;
463 void initializePragmaHandlers();
466 void resetPragmaHandlers();
469 void HandlePragmaUnused();
473 void HandlePragmaVisibility();
477 void HandlePragmaPack();
481 void HandlePragmaMSStruct();
485 void HandlePragmaMSComment();
487 void HandlePragmaMSPointersToMembers();
489 void HandlePragmaMSVtorDisp();
491 void HandlePragmaMSPragma();
492 bool HandlePragmaMSSection(StringRef PragmaName,
493 SourceLocation PragmaLocation);
494 bool HandlePragmaMSSegment(StringRef PragmaName,
495 SourceLocation PragmaLocation);
496 bool HandlePragmaMSInitSeg(StringRef PragmaName,
497 SourceLocation PragmaLocation);
501 void HandlePragmaAlign();
505 void HandlePragmaWeak();
509 void HandlePragmaWeakAlias();
513 void HandlePragmaRedefineExtname();
517 void HandlePragmaFPContract();
521 void HandlePragmaOpenCLExtension();
529 bool HandlePragmaLoopHint(LoopHint &Hint);
538 const Token &GetLookAheadToken(
unsigned N) {
563 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
569 Tok.setAnnotationValue(ER.getAsOpaquePointer());
576 bool NeedType =
false);
584 enum AnnotatedNameKind {
597 TryAnnotateName(
bool IsAddressOfOperand,
598 std::unique_ptr<CorrectionCandidateCallback> CCC =
nullptr);
601 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
606 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
607 const char *&PrevSpec,
unsigned &DiagID,
612 if (Tok.getIdentifierInfo() != Ident_vector &&
613 Tok.getIdentifierInfo() != Ident_bool &&
614 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
617 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
623 bool TryAltiVecVectorToken() {
625 Tok.getIdentifierInfo() != Ident_vector)
return false;
626 return TryAltiVecVectorTokenOutOfLine();
629 bool TryAltiVecVectorTokenOutOfLine();
630 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
631 const char *&PrevSpec,
unsigned &DiagID,
637 bool isObjCInstancetype() {
639 if (!Ident_instancetype)
641 return Tok.getIdentifierInfo() == Ident_instancetype;
649 bool TryKeywordIdentFallback(
bool DisableKeyword);
652 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
665 class TentativeParsingAction {
668 size_t PrevTentativelyDeclaredIdentifierCount;
669 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
673 explicit TentativeParsingAction(
Parser&
p) :
P(p) {
675 PrevTentativelyDeclaredIdentifierCount =
676 P.TentativelyDeclaredIdentifiers.size();
677 PrevParenCount =
P.ParenCount;
678 PrevBracketCount =
P.BracketCount;
679 PrevBraceCount =
P.BraceCount;
680 P.PP.EnableBacktrackAtThisPos();
684 assert(isActive &&
"Parsing action was finished!");
685 P.TentativelyDeclaredIdentifiers.resize(
686 PrevTentativelyDeclaredIdentifierCount);
687 P.PP.CommitBacktrackedTokens();
691 assert(isActive &&
"Parsing action was finished!");
694 P.TentativelyDeclaredIdentifiers.resize(
695 PrevTentativelyDeclaredIdentifierCount);
696 P.ParenCount = PrevParenCount;
697 P.BracketCount = PrevBracketCount;
698 P.BraceCount = PrevBraceCount;
701 ~TentativeParsingAction() {
702 assert(!isActive &&
"Forgot to call Commit or Revert!");
705 class UnannotatedTentativeParsingAction;
713 SaveAndRestore<bool> WithinObjCContainer;
717 WithinObjCContainer(
P.ParsingInObjCContainer, DC != nullptr) {
719 P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
723 P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
736 unsigned Diag = diag::err_expected,
737 StringRef DiagMsg =
"");
744 bool ExpectAndConsumeSemi(
unsigned DiagID);
750 InstanceVariableList = 2,
751 AfterMemberFunctionDefinition = 3
755 void ConsumeExtraSemi(ExtraSemiKind Kind,
unsigned TST =
TST_unspecified);
777 bool BeforeCompoundStmt =
false)
779 if (EnteredScope && !BeforeCompoundStmt)
782 if (BeforeCompoundStmt)
785 this->Self =
nullptr;
811 class ParseScopeFlags {
814 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
815 void operator=(
const ParseScopeFlags &) =
delete;
818 ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
826 DiagnosticBuilder
Diag(SourceLocation Loc,
unsigned DiagID);
827 DiagnosticBuilder
Diag(
const Token &Tok,
unsigned DiagID);
829 return Diag(Tok, DiagID);
850 static_cast<unsigned>(R));
863 return SkipUntil(llvm::makeArrayRef(T), Flags);
896 class LateParsedDeclaration {
898 virtual ~LateParsedDeclaration();
900 virtual void ParseLexedMethodDeclarations();
901 virtual void ParseLexedMemberInitializers();
902 virtual void ParseLexedMethodDefs();
903 virtual void ParseLexedAttributes();
908 class LateParsedClass :
public LateParsedDeclaration {
910 LateParsedClass(
Parser *
P, ParsingClass *
C);
911 ~LateParsedClass()
override;
913 void ParseLexedMethodDeclarations()
override;
914 void ParseLexedMemberInitializers()
override;
915 void ParseLexedMethodDefs()
override;
916 void ParseLexedAttributes()
override;
929 struct LateParsedAttribute :
public LateParsedDeclaration {
932 IdentifierInfo &AttrName;
933 SourceLocation AttrNameLoc;
934 SmallVector<Decl*, 2> Decls;
936 explicit LateParsedAttribute(
Parser *
P, IdentifierInfo &Name,
938 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
940 void ParseLexedAttributes()
override;
942 void addDecl(Decl *D) { Decls.push_back(D); }
946 class LateParsedAttrList:
public SmallVector<LateParsedAttribute *, 2> {
948 LateParsedAttrList(
bool PSoon =
false) : ParseSoon(PSoon) { }
950 bool parseSoon() {
return ParseSoon; }
959 struct LexedMethod :
public LateParsedDeclaration {
969 explicit LexedMethod(
Parser*
P, Decl *MD)
970 : Self(P), D(MD), TemplateScope(
false) {}
972 void ParseLexedMethodDefs()
override;
979 struct LateParsedDefaultArgument {
980 explicit LateParsedDefaultArgument(Decl *
P,
982 : Param(P), Toks(Toks) { }
998 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
999 explicit LateParsedMethodDeclaration(
Parser *
P, Decl *M)
1000 : Self(P), Method(M), TemplateScope(
false),
1001 ExceptionSpecTokens(nullptr) {}
1003 void ParseLexedMethodDeclarations()
override;
1020 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1030 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1031 LateParsedMemberInitializer(
Parser *
P, Decl *FD)
1032 : Self(P), Field(FD) { }
1034 void ParseLexedMemberInitializers()
override;
1052 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
1057 struct ParsingClass {
1058 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
1059 : TopLevelClass(TopLevelClass), TemplateScope(
false),
1060 IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { }
1064 bool TopLevelClass : 1;
1069 bool TemplateScope : 1;
1072 bool IsInterface : 1;
1075 Decl *TagOrTemplate;
1080 LateParsedDeclarationsContainer LateParsedDeclarations;
1086 std::stack<ParsingClass *> ClassStack;
1088 ParsingClass &getCurrentClass() {
1089 assert(!ClassStack.empty() &&
"No lexed method stacks!");
1090 return *ClassStack.top();
1094 class ParsingClassDefinition {
1100 ParsingClassDefinition(
Parser &
P, Decl *TagOrTemplate,
bool TopLevelClass,
1102 : P(P), Popped(
false),
1103 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1108 assert(!Popped &&
"Nested class has already been popped");
1110 P.PopParsingClass(
State);
1113 ~ParsingClassDefinition() {
1115 P.PopParsingClass(
State);
1122 struct ParsedTemplateInfo {
1123 ParsedTemplateInfo()
1124 : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
1127 bool isSpecialization,
1128 bool lastParameterListWasEmpty =
false)
1129 : Kind(isSpecialization? ExplicitSpecialization : Template),
1130 TemplateParams(TemplateParams),
1131 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1133 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1134 SourceLocation TemplateLoc)
1135 : Kind(ExplicitInstantiation), TemplateParams(nullptr),
1136 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1137 LastParameterListWasEmpty(
false){ }
1146 ExplicitSpecialization,
1148 ExplicitInstantiation
1157 SourceLocation ExternLoc;
1161 SourceLocation TemplateLoc;
1164 bool LastParameterListWasEmpty;
1166 SourceRange getSourceRange() const LLVM_READONLY;
1169 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
1170 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1172 static
void LateTemplateParserCallback(
void *
P, LateParsedTemplate &LPT);
1173 static
void LateTemplateParserCleanupCallback(
void *P);
1175 Sema::ParsingClassState
1176 PushParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
1177 void DeallocateParsedClasses(ParsingClass *Class);
1178 void PopParsingClass(Sema::ParsingClassState);
1180 enum CachedInitKind {
1181 CIK_DefaultArgument,
1182 CIK_DefaultInitializer
1186 AttributeList *AccessAttrs,
1187 ParsingDeclarator &D,
1188 const ParsedTemplateInfo &TemplateInfo,
1189 const VirtSpecifiers& VS,
1190 SourceLocation PureSpecLoc);
1191 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1192 void ParseLexedAttributes(ParsingClass &Class);
1193 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1195 void ParseLexedAttribute(LateParsedAttribute &LA,
1197 void ParseLexedMethodDeclarations(ParsingClass &Class);
1198 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1199 void ParseLexedMethodDefs(ParsingClass &Class);
1200 void ParseLexedMethodDef(LexedMethod &LM);
1201 void ParseLexedMemberInitializers(ParsingClass &Class);
1202 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1203 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
1204 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1205 bool ConsumeAndStoreInitializer(
CachedTokens &Toks, CachedInitKind CIK);
1210 bool ConsumeFinalToken =
true) {
1211 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1216 bool ConsumeFinalToken =
true);
1220 struct ParsedAttributesWithRange : ParsedAttributes {
1221 ParsedAttributesWithRange(AttributeFactory &factory)
1222 : ParsedAttributes(factory) {}
1227 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
1228 ParsingDeclSpec *DS =
nullptr);
1229 bool isDeclarationAfterDeclarator();
1230 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1232 ParsedAttributesWithRange &attrs,
1233 ParsingDeclSpec *DS =
nullptr,
1235 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
1236 ParsingDeclSpec &DS,
1239 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1240 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1241 LateParsedAttrList *LateParsedAttrs =
nullptr);
1242 void ParseKNRParamDeclarations(Declarator &D);
1245 ExprResult ParseSimpleAsm(SourceLocation *EndLoc =
nullptr);
1251 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1252 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1253 ParsedAttributes &prefixAttrs);
1254 ObjCTypeParamList *parseObjCTypeParamList();
1255 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1256 SourceLocation &lAngleLoc,
1257 SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1258 SourceLocation &rAngleLoc,
1259 bool mayBeProtocolList =
true);
1261 void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1263 SmallVectorImpl<Decl *> &AllIvarDecls,
1264 bool RBraceMissing);
1265 void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
1267 SourceLocation atLoc);
1268 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &
P,
1269 SmallVectorImpl<SourceLocation> &PLocs,
1270 bool WarnOnDeclarations,
1271 bool ForObjCContainer,
1272 SourceLocation &LAngleLoc,
1273 SourceLocation &EndProtoLoc,
1274 bool consumeLastToken);
1279 void parseObjCTypeArgsOrProtocolQualifiers(
1281 SourceLocation &typeArgsLAngleLoc,
1282 SmallVectorImpl<ParsedType> &typeArgs,
1283 SourceLocation &typeArgsRAngleLoc,
1284 SourceLocation &protocolLAngleLoc,
1285 SmallVectorImpl<Decl *> &protocols,
1286 SmallVectorImpl<SourceLocation> &protocolLocs,
1287 SourceLocation &protocolRAngleLoc,
1288 bool consumeLastToken,
1289 bool warnOnIncompleteProtocols);
1293 void parseObjCTypeArgsAndProtocolQualifiers(
1295 SourceLocation &typeArgsLAngleLoc,
1296 SmallVectorImpl<ParsedType> &typeArgs,
1297 SourceLocation &typeArgsRAngleLoc,
1298 SourceLocation &protocolLAngleLoc,
1299 SmallVectorImpl<Decl *> &protocols,
1300 SmallVectorImpl<SourceLocation> &protocolLocs,
1301 SourceLocation &protocolRAngleLoc,
1302 bool consumeLastToken);
1306 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1310 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1312 bool consumeLastToken,
1313 SourceLocation &endLoc);
1317 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1318 ParsedAttributes &prefixAttrs);
1320 struct ObjCImplParsingDataRAII {
1324 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1325 LateParsedObjCMethodContainer LateParsedObjCMethods;
1327 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
1328 :
P(parser), Dcl(D), HasCFunction(
false) {
1329 P.CurParsedObjCImpl =
this;
1332 ~ObjCImplParsingDataRAII();
1334 void finish(SourceRange AtEnd);
1335 bool isFinished()
const {
return Finished; }
1340 ObjCImplParsingDataRAII *CurParsedObjCImpl;
1341 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
1343 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1345 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1346 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1347 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1349 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1352 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1353 objc_nonnull, objc_nullable, objc_null_unspecified,
1356 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1358 bool isTokIdentifier_in()
const;
1361 ParsedAttributes *ParamAttrs);
1362 void ParseObjCMethodRequirement();
1363 Decl *ParseObjCMethodPrototype(
1365 bool MethodDefinition =
true);
1366 Decl *ParseObjCMethodDecl(SourceLocation mLoc,
tok::TokenKind mType,
1368 bool MethodDefinition=
true);
1369 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1371 Decl *ParseObjCMethodDefinition();
1391 unsigned &NumLineToksConsumed,
1393 bool IsUnevaluated);
1402 ExprResult ParseCastExpression(
bool isUnaryExpression,
1403 bool isAddressOfOperand,
1406 ExprResult ParseCastExpression(
bool isUnaryExpression,
1407 bool isAddressOfOperand =
false,
1411 bool isNotExpressionStart();
1415 bool isPostfixExpressionSuffixStart() {
1417 return (K == tok::l_square || K == tok::l_paren ||
1418 K == tok::period || K == tok::arrow ||
1419 K == tok::plusplus || K == tok::minusminus);
1423 ExprResult ParseUnaryExprOrTypeTraitExpression();
1429 SourceRange &CastRange);
1431 typedef SmallVector<Expr*, 20> ExprListTy;
1432 typedef SmallVector<SourceLocation, 20> CommaLocsTy;
1435 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1436 SmallVectorImpl<SourceLocation> &CommaLocs,
1437 std::function<
void()> Completer =
nullptr);
1441 bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
1442 SmallVectorImpl<SourceLocation> &CommaLocs);
1446 enum ParenParseOption {
1452 ExprResult ParseParenExpression(ParenParseOption &ExprType,
1453 bool stopIfCastExpr,
1456 SourceLocation &RParenLoc);
1459 ParenParseOption &ExprType,
ParsedType &CastTy,
1462 SourceLocation LParenLoc,
1463 SourceLocation RParenLoc);
1465 ExprResult ParseStringLiteralExpression(
bool AllowUserDefinedLiteral =
false);
1467 ExprResult ParseGenericSelectionExpression();
1475 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
1476 Token &Replacement);
1477 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
1479 bool areTokensAdjacent(
const Token &A,
const Token &B);
1481 void CheckForTemplateAndDigraph(
Token &Next,
ParsedType ObjectTypePtr,
1482 bool EnteringContext, IdentifierInfo &II,
1485 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1487 bool EnteringContext,
1488 bool *MayBePseudoDestructor =
nullptr,
1489 bool IsTypename =
false,
1490 IdentifierInfo **LastII =
nullptr);
1492 void CheckForLParenAfterColonColon();
1500 Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro,
1501 bool *SkippedInits =
nullptr);
1502 bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1503 ExprResult ParseLambdaExpressionAfterIntroducer(
1504 LambdaIntroducer &Intro);
1520 ExprResult ParseCXXPseudoDestructor(Expr *
Base, SourceLocation OpLoc,
1535 SourceRange &SpecificationRange,
1536 SmallVectorImpl<ParsedType> &DynamicExceptions,
1537 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
1543 SourceRange &SpecificationRange,
1544 SmallVectorImpl<ParsedType> &Exceptions,
1545 SmallVectorImpl<SourceRange> &
Ranges);
1549 TypeResult ParseTrailingReturnType(SourceRange &Range);
1557 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
1562 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1564 bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
1568 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1570 void ParseDirectNewDeclarator(Declarator &D);
1571 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
1572 ExprResult ParseCXXDeleteExpression(
bool UseGlobal,
1573 SourceLocation Start);
1578 SourceLocation Loc,
bool ConvertToBoolean);
1591 if (Tok.isNot(tok::l_brace))
1593 return ParseBraceInitializer();
1595 bool MayBeDesignationStart();
1597 ExprResult ParseInitializerWithPotentialDesignator();
1606 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
1607 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
1608 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1609 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1610 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
1611 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1612 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
1613 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
1614 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
1615 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
1616 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
1617 bool isSimpleObjCMessageExpression();
1619 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
1620 SourceLocation SuperLoc,
1622 Expr *ReceiverExpr);
1623 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
1624 SourceLocation LBracloc, SourceLocation SuperLoc,
1625 ParsedType ReceiverType, Expr *ReceiverExpr);
1626 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
1633 typedef SmallVector<Stmt*, 32> StmtVector;
1635 typedef SmallVector<Expr*, 12> ExprVector;
1637 typedef SmallVector<ParsedType, 12> TypeVector;
1639 StmtResult ParseStatement(SourceLocation *TrailingElseLoc =
nullptr);
1641 ParseStatementOrDeclaration(StmtVector &Stmts,
bool OnlyStatement,
1642 SourceLocation *TrailingElseLoc =
nullptr);
1643 StmtResult ParseStatementOrDeclarationAfterAttributes(
1646 SourceLocation *TrailingElseLoc,
1647 ParsedAttributesWithRange &Attrs);
1649 StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
1650 StmtResult ParseCaseStatement(
bool MissingCase =
false,
1653 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
1654 StmtResult ParseCompoundStatement(
bool isStmtExpr,
1655 unsigned ScopeFlags);
1656 void ParseCompoundStatementLeadingPragmas();
1657 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
1661 bool ConvertToBoolean);
1662 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
1663 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
1664 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
1666 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
1672 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1673 StmtResult ParsePragmaLoopHint(StmtVector &Stmts,
bool OnlyStatement,
1674 SourceLocation *TrailingElseLoc,
1675 ParsedAttributesWithRange &Attrs);
1679 enum IfExistsBehavior {
1691 struct IfExistsCondition {
1693 SourceLocation KeywordLoc;
1706 IfExistsBehavior Behavior;
1709 bool ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result);
1710 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1711 void ParseMicrosoftIfExistsExternalDeclaration();
1712 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
1714 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
1716 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
1717 SmallVectorImpl<Expr *> &Constraints,
1718 SmallVectorImpl<Expr *> &Exprs);
1724 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc,
bool FnTry =
false);
1725 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
1731 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
1732 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
1738 StmtResult ParseObjCAtStatement(SourceLocation atLoc);
1739 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
1740 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1741 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1742 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1751 enum DeclSpecContext {
1756 DSC_alias_declaration,
1758 DSC_template_type_arg,
1759 DSC_objc_method_result,
1765 static bool isTypeSpecifier(DeclSpecContext DSC) {
1770 case DSC_objc_method_result:
1774 case DSC_template_type_arg:
1775 case DSC_type_specifier:
1777 case DSC_alias_declaration:
1780 llvm_unreachable(
"Missing DeclSpecContext case");
1785 struct ForRangeInit {
1789 bool ParsedForRangeDecl() {
return !
ColonLoc.isInvalid(); }
1793 ParsedAttributesWithRange &attrs);
1795 SourceLocation &DeclEnd,
1796 ParsedAttributesWithRange &attrs,
1798 ForRangeInit *FRI =
nullptr);
1799 bool MightBeDeclarator(
unsigned Context);
1801 SourceLocation *DeclEnd =
nullptr,
1802 ForRangeInit *FRI =
nullptr);
1803 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1804 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1805 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1806 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1808 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1809 ForRangeInit *FRI =
nullptr);
1810 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1811 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
1817 bool trySkippingFunctionBody();
1819 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1820 const ParsedTemplateInfo &TemplateInfo,
1822 ParsedAttributesWithRange &Attrs);
1823 DeclSpecContext getDeclSpecContextFromDeclaratorContext(
unsigned Context);
1824 void ParseDeclarationSpecifiers(DeclSpec &DS,
1825 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1827 DeclSpecContext DSC = DSC_normal,
1828 LateParsedAttrList *LateAttrs =
nullptr);
1829 bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS,
AccessSpecifier AS,
1830 DeclSpecContext DSContext,
1831 LateParsedAttrList *LateAttrs =
nullptr);
1834 DeclSpecContext DSC = DSC_normal);
1836 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1839 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1840 const ParsedTemplateInfo &TemplateInfo,
1842 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
1843 void ParseStructUnionBody(SourceLocation StartLoc,
unsigned TagType,
1846 void ParseStructDeclaration(
1847 ParsingDeclSpec &DS,
1848 llvm::function_ref<
void(ParsingFieldDeclarator &)> FieldsCallback);
1850 bool isDeclarationSpecifier(
bool DisambiguatingWithExpression =
false);
1851 bool isTypeSpecifierQualifier();
1852 bool isTypeQualifier()
const;
1857 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
1862 bool isKnownToBeDeclarationSpecifier() {
1865 return isDeclarationSpecifier(
true);
1871 bool isDeclarationStatement() {
1873 return isCXXDeclarationStatement();
1874 return isDeclarationSpecifier(
true);
1881 bool isForInitDeclaration() {
1883 return isCXXSimpleDeclaration(
true);
1884 return isDeclarationSpecifier(
true);
1888 bool isForRangeIdentifier();
1892 bool isStartOfObjCClassMessageMissingOpenBracket();
1897 bool isConstructorDeclarator(
bool Unqualified);
1901 enum TentativeCXXTypeIdContext {
1904 TypeIdAsTemplateArgument
1911 bool isTypeIdInParens(
bool &isAmbiguous) {
1913 return isCXXTypeId(TypeIdInParens, isAmbiguous);
1914 isAmbiguous =
false;
1915 return isTypeSpecifierQualifier();
1917 bool isTypeIdInParens() {
1919 return isTypeIdInParens(isAmbiguous);
1925 bool isTypeIdUnambiguously() {
1928 return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
1929 return isTypeSpecifierQualifier();
1935 bool isCXXDeclarationStatement();
1942 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
1951 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr);
1957 bool isCXXConditionDeclaration();
1959 bool isCXXTypeId(TentativeCXXTypeIdContext
Context,
bool &isAmbiguous);
1960 bool isCXXTypeId(TentativeCXXTypeIdContext
Context) {
1962 return isCXXTypeId(Context, isAmbiguous);
1967 enum class TPResult {
1968 True, False, Ambiguous,
Error
1991 isCXXDeclarationSpecifier(TPResult BracedCastResult =
TPResult::False,
1992 bool *HasMissingTypename =
nullptr);
1997 bool isCXXDeclarationSpecifierAType();
2002 bool isTentativelyDeclared(IdentifierInfo *II);
2011 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
2012 TPResult TryParseTypeofSpecifier();
2013 TPResult TryParseProtocolQualifiers();
2014 TPResult TryParsePtrOperatorSeq();
2015 TPResult TryParseOperatorId();
2016 TPResult TryParseInitDeclaratorList();
2017 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier=
true);
2019 TryParseParameterDeclarationClause(
bool *InvalidAsDeclaration =
nullptr,
2020 bool VersusTemplateArg =
false);
2021 TPResult TryParseFunctionDeclarator();
2022 TPResult TryParseBracketDeclarator();
2023 TPResult TryConsumeDeclarationSpecifier();
2030 Decl **OwnedType =
nullptr,
2031 ParsedAttributes *Attrs =
nullptr);
2034 void ParseBlockId(SourceLocation CaretLoc);
2038 bool CheckProhibitedCXX11Attribute() {
2039 assert(Tok.is(tok::l_square));
2042 return DiagnoseProhibitedCXX11Attribute();
2044 bool DiagnoseProhibitedCXX11Attribute();
2045 void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2046 SourceLocation CorrectLocation) {
2049 if ((Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2050 Tok.isNot(tok::kw_alignas))
2052 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2054 void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2055 SourceLocation CorrectLocation);
2057 void handleDeclspecAlignBeforeClassKey(ParsedAttributesWithRange &Attrs,
2060 void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
2061 if (!attrs.Range.isValid())
return;
2062 DiagnoseProhibitedAttributes(attrs);
2065 void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
2070 void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs);
2074 SourceLocation SkipCXX11Attributes();
2078 void DiagnoseAndSkipCXX11Attributes();
2085 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2086 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2087 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2090 void MaybeParseGNUAttributes(Declarator &D,
2091 LateParsedAttrList *LateAttrs =
nullptr) {
2092 if (Tok.is(tok::kw___attribute)) {
2093 ParsedAttributes attrs(AttrFactory);
2094 SourceLocation endLoc;
2095 ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D);
2096 D.takeAttributes(attrs, endLoc);
2099 void MaybeParseGNUAttributes(ParsedAttributes &attrs,
2100 SourceLocation *endLoc =
nullptr,
2101 LateParsedAttrList *LateAttrs =
nullptr) {
2102 if (Tok.is(tok::kw___attribute))
2103 ParseGNUAttributes(attrs, endLoc, LateAttrs);
2105 void ParseGNUAttributes(ParsedAttributes &attrs,
2106 SourceLocation *endLoc =
nullptr,
2107 LateParsedAttrList *LateAttrs =
nullptr,
2108 Declarator *D =
nullptr);
2109 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2110 SourceLocation AttrNameLoc,
2111 ParsedAttributes &Attrs,
2112 SourceLocation *EndLoc,
2113 IdentifierInfo *ScopeName,
2114 SourceLocation ScopeLoc,
2117 IdentifierLoc *ParseIdentifierLoc();
2119 void MaybeParseCXX11Attributes(Declarator &D) {
2121 ParsedAttributesWithRange attrs(AttrFactory);
2122 SourceLocation endLoc;
2123 ParseCXX11Attributes(attrs, &endLoc);
2124 D.takeAttributes(attrs, endLoc);
2127 void MaybeParseCXX11Attributes(ParsedAttributes &attrs,
2128 SourceLocation *endLoc =
nullptr) {
2130 ParsedAttributesWithRange attrsWithRange(AttrFactory);
2131 ParseCXX11Attributes(attrsWithRange, endLoc);
2132 attrs.takeAllFrom(attrsWithRange);
2135 void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2136 SourceLocation *endLoc =
nullptr,
2137 bool OuterMightBeMessageSend =
false) {
2139 isCXX11AttributeSpecifier(
false, OuterMightBeMessageSend))
2140 ParseCXX11Attributes(attrs, endLoc);
2143 void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
2144 SourceLocation *EndLoc =
nullptr);
2145 void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2146 SourceLocation *EndLoc =
nullptr);
2149 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2150 SourceLocation AttrNameLoc,
2151 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2152 IdentifierInfo *ScopeName,
2153 SourceLocation ScopeLoc);
2155 IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
2157 void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
2158 SourceLocation *endLoc =
nullptr) {
2159 if (
getLangOpts().MicrosoftExt && Tok.is(tok::l_square))
2160 ParseMicrosoftAttributes(attrs, endLoc);
2162 void ParseMicrosoftAttributes(ParsedAttributes &attrs,
2163 SourceLocation *endLoc =
nullptr);
2164 void MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2165 SourceLocation *
End =
nullptr) {
2167 if ((LO.MicrosoftExt || LO.Borland || LO.CUDA) &&
2168 Tok.is(tok::kw___declspec))
2169 ParseMicrosoftDeclSpecs(Attrs,
End);
2171 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2172 SourceLocation *
End =
nullptr);
2173 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2174 SourceLocation AttrNameLoc,
2175 ParsedAttributes &Attrs);
2176 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2177 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2178 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2179 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
2180 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2181 void ParseOpenCLAttributes(ParsedAttributes &attrs);
2182 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2183 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2185 VersionTuple ParseVersionTuple(SourceRange &Range);
2186 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2187 SourceLocation AvailabilityLoc,
2188 ParsedAttributes &attrs,
2189 SourceLocation *endLoc,
2190 IdentifierInfo *ScopeName,
2191 SourceLocation ScopeLoc,
2194 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2195 SourceLocation ObjCBridgeRelatedLoc,
2196 ParsedAttributes &attrs,
2197 SourceLocation *endLoc,
2198 IdentifierInfo *ScopeName,
2199 SourceLocation ScopeLoc,
2202 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2203 SourceLocation AttrNameLoc,
2204 ParsedAttributes &Attrs,
2205 SourceLocation *EndLoc,
2206 IdentifierInfo *ScopeName,
2207 SourceLocation ScopeLoc,
2210 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2211 SourceLocation AttrNameLoc,
2212 ParsedAttributes &Attrs,
2213 SourceLocation *EndLoc,
2214 IdentifierInfo *ScopeName,
2215 SourceLocation ScopeLoc,
2218 void ParseTypeofSpecifier(DeclSpec &DS);
2219 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
2220 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
2221 SourceLocation StartLoc,
2222 SourceLocation EndLoc);
2223 void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
2224 void ParseAtomicSpecifier(DeclSpec &DS);
2226 ExprResult ParseAlignArgument(SourceLocation Start,
2227 SourceLocation &EllipsisLoc);
2228 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2229 SourceLocation *endLoc =
nullptr);
2233 return isCXX11VirtSpecifier(Tok);
2235 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
2236 SourceLocation FriendLoc);
2238 bool isCXX11FinalKeyword()
const;
2243 class DeclaratorScopeObj {
2249 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2250 :
P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2252 void EnterDeclaratorScope() {
2253 assert(!EnteredScope &&
"Already entered the scope!");
2254 assert(SS.isSet() &&
"C++ scope was not set!");
2256 CreatedScope =
true;
2259 if (!
P.Actions.ActOnCXXEnterDeclaratorScope(
P.getCurScope(), SS))
2260 EnteredScope =
true;
2263 ~DeclaratorScopeObj() {
2265 assert(SS.isSet() &&
"C++ scope was cleared ?");
2266 P.Actions.ActOnCXXExitDeclaratorScope(
P.getCurScope(), SS);
2274 void ParseDeclarator(Declarator &D);
2276 typedef void (
Parser::*DirectDeclParseFunction)(Declarator&);
2277 void ParseDeclaratorInternal(Declarator &D,
2278 DirectDeclParseFunction DirectDeclParser);
2280 enum AttrRequirements {
2281 AR_NoAttributesParsed = 0,
2282 AR_GNUAttributesParsedAndRejected = 1 << 0,
2283 AR_GNUAttributesParsed = 1 << 1,
2284 AR_CXX11AttributesParsed = 1 << 2,
2285 AR_DeclspecAttributesParsed = 1 << 3,
2286 AR_AllAttributesParsed = AR_GNUAttributesParsed |
2287 AR_CXX11AttributesParsed |
2288 AR_DeclspecAttributesParsed,
2289 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
2290 AR_DeclspecAttributesParsed
2293 void ParseTypeQualifierListOpt(DeclSpec &DS,
2294 unsigned AttrReqs = AR_AllAttributesParsed,
2295 bool AtomicAllowed =
true,
2296 bool IdentifierRequired =
false);
2297 void ParseDirectDeclarator(Declarator &D);
2298 void ParseParenDeclarator(Declarator &D);
2299 void ParseFunctionDeclarator(Declarator &D,
2300 ParsedAttributes &attrs,
2303 bool RequiresArg =
false);
2304 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2305 SourceLocation &RefQualifierLoc);
2306 bool isFunctionDeclaratorIdentifierList();
2307 void ParseFunctionDeclaratorIdentifierList(
2309 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2310 void ParseParameterDeclarationClause(
2312 ParsedAttributes &attrs,
2313 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2314 SourceLocation &EllipsisLoc);
2315 void ParseBracketDeclarator(Declarator &D);
2316 void ParseMisplacedBracketDeclarator(Declarator &D);
2322 enum CXX11AttributeKind {
2324 CAK_NotAttributeSpecifier,
2326 CAK_AttributeSpecifier,
2329 CAK_InvalidAttributeSpecifier
2332 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
2333 bool OuterMightBeMessageSend =
false);
2335 void DiagnoseUnexpectedNamespace(NamedDecl *
Context);
2337 Decl *ParseNamespace(
unsigned Context, SourceLocation &DeclEnd,
2338 SourceLocation InlineLoc = SourceLocation());
2339 void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
2340 std::vector<IdentifierInfo*>& Ident,
2341 std::vector<SourceLocation>& NamespaceLoc,
2342 unsigned int index, SourceLocation& InlineLoc,
2343 ParsedAttributes& attrs,
2345 Decl *ParseLinkage(ParsingDeclSpec &DS,
unsigned Context);
2346 Decl *ParseUsingDirectiveOrDeclaration(
unsigned Context,
2347 const ParsedTemplateInfo &TemplateInfo,
2348 SourceLocation &DeclEnd,
2349 ParsedAttributesWithRange &attrs,
2350 Decl **OwnedType =
nullptr);
2351 Decl *ParseUsingDirective(
unsigned Context,
2352 SourceLocation UsingLoc,
2353 SourceLocation &DeclEnd,
2354 ParsedAttributes &attrs);
2355 Decl *ParseUsingDeclaration(
unsigned Context,
2356 const ParsedTemplateInfo &TemplateInfo,
2357 SourceLocation UsingLoc,
2358 SourceLocation &DeclEnd,
2360 Decl **OwnedType =
nullptr);
2361 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2362 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2363 SourceLocation AliasLoc, IdentifierInfo *Alias,
2364 SourceLocation &DeclEnd);
2368 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
2369 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
2370 DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo,
2372 DeclSpecContext DSC,
2373 ParsedAttributesWithRange &Attributes);
2374 void SkipCXXMemberSpecification(SourceLocation StartLoc,
2375 SourceLocation AttrFixitLoc,
2378 void ParseCXXMemberSpecification(SourceLocation StartLoc,
2379 SourceLocation AttrFixitLoc,
2380 ParsedAttributesWithRange &Attrs,
2383 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
2384 SourceLocation &EqualLoc);
2385 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
2388 LateParsedAttrList &LateAttrs);
2389 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
2390 VirtSpecifiers &VS);
2391 void ParseCXXClassMemberDeclaration(
AccessSpecifier AS, AttributeList *Attr,
2392 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2393 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
2394 void ParseConstructorInitializer(Decl *ConstructorDecl);
2396 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
2401 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
2402 SourceLocation &EndLocation);
2403 void ParseBaseClause(Decl *ClassDecl);
2404 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
2407 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
2408 SourceLocation TemplateKWLoc,
2409 IdentifierInfo *Name,
2410 SourceLocation NameLoc,
2411 bool EnteringContext,
2414 bool AssumeTemplateId);
2415 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2431 SmallVectorImpl<Expr *> &VarList,
2432 bool AllowScopeSpecifier);
2439 ParseOpenMPDeclarativeOrExecutableDirective(
bool StandAloneAllowed);
2477 bool AllowDestructorName,
2478 bool AllowConstructorName,
2480 SourceLocation& TemplateKWLoc,
2488 Decl *ParseDeclarationStartingWithTemplate(
unsigned Context,
2489 SourceLocation &DeclEnd,
2491 AttributeList *AccessAttrs =
nullptr);
2492 Decl *ParseTemplateDeclarationOrSpecialization(
unsigned Context,
2493 SourceLocation &DeclEnd,
2495 AttributeList *AccessAttrs);
2496 Decl *ParseSingleDeclarationAfterTemplate(
2498 const ParsedTemplateInfo &TemplateInfo,
2499 ParsingDeclRAIIObject &DiagsFromParams,
2500 SourceLocation &DeclEnd,
2502 AttributeList *AccessAttrs =
nullptr);
2503 bool ParseTemplateParameters(
unsigned Depth,
2504 SmallVectorImpl<Decl*> &TemplateParams,
2505 SourceLocation &LAngleLoc,
2506 SourceLocation &RAngleLoc);
2507 bool ParseTemplateParameterList(
unsigned Depth,
2508 SmallVectorImpl<Decl*> &TemplateParams);
2509 bool isStartOfTemplateTypeParameter();
2510 Decl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
2511 Decl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
2512 Decl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
2513 Decl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
2514 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
2515 SourceLocation CorrectLoc,
2516 bool AlreadyHasEllipsis,
2517 bool IdentifierHasName);
2518 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
2521 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
2523 bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc,
2524 bool ConsumeLastToken,
2525 bool ObjCGenericList);
2526 bool ParseTemplateIdAfterTemplateName(
TemplateTy Template,
2527 SourceLocation TemplateNameLoc,
2528 const CXXScopeSpec &SS,
2529 bool ConsumeLastToken,
2530 SourceLocation &LAngleLoc,
2531 TemplateArgList &TemplateArgs,
2532 SourceLocation &RAngleLoc);
2536 SourceLocation TemplateKWLoc,
2537 UnqualifiedId &TemplateName,
2538 bool AllowTypeAnnotation =
true);
2539 void AnnotateTemplateIdTokenAsType();
2540 bool IsTemplateArgumentList(
unsigned Skip = 0);
2541 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
2542 ParsedTemplateArgument ParseTemplateTemplateArgument();
2543 ParsedTemplateArgument ParseTemplateArgument();
2544 Decl *ParseExplicitInstantiation(
unsigned Context,
2545 SourceLocation ExternLoc,
2546 SourceLocation TemplateLoc,
2547 SourceLocation &DeclEnd,
2565 void CodeCompleteDirective(
bool InConditional)
override;
2566 void CodeCompleteInConditionalExclusion()
override;
2567 void CodeCompleteMacroName(
bool IsDefinition)
override;
2568 void CodeCompletePreprocessorExpression()
override;
2569 void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
2570 unsigned ArgumentIndex)
override;
2571 void CodeCompleteNaturalLanguage()
override;
Sema::FullExprArg FullExprArg
Scope * getCurScope() const
Retrieve the parser's current scope.
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
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
ActionResult< Expr * > ExprResult
void incrementMSManglingNumber() const
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Wrapper for void* pointer.
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
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
const Token & NextToken()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< QualType > ParsedType
friend class BalancedDelimiterTracker
const LangOptions & getLangOpts() const
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
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))
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)
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...
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. Be careful when changing this: this...
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
ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, void *Info, bool IsUnevaluated)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
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. IsNewScope should be true unless the scope specifier was extracted from an existing tok::annot_cxxscope annotation.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Preprocessor & getPreprocessor() const
ActionResult< CXXBaseSpecifier * > BaseResult
bool is(tok::TokenKind K) const
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)
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
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()
bool TryAnnotateTypeOrScopeToken(bool EnteringContext=false, bool NeedType=false)
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.