14 #ifndef LLVM_CLANG_PARSE_PARSER_H
15 #define LLVM_CLANG_PARSE_PARSER_H
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/Support/Compiler.h"
28 #include "llvm/Support/PrettyStackTrace.h"
29 #include "llvm/Support/SaveAndRestore.h"
36 class BalancedDelimiterTracker;
37 class CorrectionCandidateCallback;
39 class DiagnosticBuilder;
41 class ParsingDeclRAIIObject;
42 class ParsingDeclSpec;
43 class ParsingDeclarator;
44 class ParsingFieldDeclarator;
45 class ColonProtectionRAIIObject;
46 class InMessageExpressionRAIIObject;
47 class PoisonSEHIdentifiersRAIIObject;
50 class ObjCTypeParamList;
51 class ObjCTypeParameter;
77 unsigned short ParenCount, BracketCount, BraceCount;
86 enum { ScopeCacheSize = 16 };
87 unsigned NumCachedScopes;
88 Scope *ScopeCache[ScopeCacheSize];
94 *Ident___exception_code,
95 *Ident_GetExceptionCode;
98 *Ident___exception_info,
99 *Ident_GetExceptionInfo;
102 *Ident___abnormal_termination,
103 *Ident_AbnormalTermination;
150 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
152 std::unique_ptr<PragmaHandler> AlignHandler;
153 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
154 std::unique_ptr<PragmaHandler> OptionsHandler;
155 std::unique_ptr<PragmaHandler> PackHandler;
156 std::unique_ptr<PragmaHandler> MSStructHandler;
157 std::unique_ptr<PragmaHandler> UnusedHandler;
158 std::unique_ptr<PragmaHandler> WeakHandler;
159 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
160 std::unique_ptr<PragmaHandler> FPContractHandler;
161 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
162 std::unique_ptr<PragmaHandler> OpenMPHandler;
163 std::unique_ptr<PragmaHandler> MSCommentHandler;
164 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
165 std::unique_ptr<PragmaHandler> MSPointersToMembers;
166 std::unique_ptr<PragmaHandler> MSVtorDisp;
167 std::unique_ptr<PragmaHandler> MSInitSeg;
168 std::unique_ptr<PragmaHandler> MSDataSeg;
169 std::unique_ptr<PragmaHandler> MSBSSSeg;
170 std::unique_ptr<PragmaHandler> MSConstSeg;
171 std::unique_ptr<PragmaHandler> MSCodeSeg;
172 std::unique_ptr<PragmaHandler> MSSection;
173 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
174 std::unique_ptr<PragmaHandler> OptimizeHandler;
175 std::unique_ptr<PragmaHandler> LoopHintHandler;
176 std::unique_ptr<PragmaHandler> UnrollHintHandler;
177 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
179 std::unique_ptr<CommentHandler> CommentSemaHandler;
185 bool GreaterThanIsOperator;
198 bool InMessageExpression;
201 unsigned TemplateParameterDepth;
204 class TemplateParameterDepthRAII {
206 unsigned AddedLevels;
208 explicit TemplateParameterDepthRAII(
unsigned &
Depth)
209 : Depth(Depth), AddedLevels(0) {}
211 ~TemplateParameterDepthRAII() {
212 Depth -= AddedLevels;
219 void addDepth(
unsigned D) {
223 unsigned getDepth()
const {
return Depth; }
227 AttributeFactory AttrFactory;
231 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
234 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
236 IdentifierInfo *getSEHExceptKeyword();
243 bool ParsingInObjCContainer;
245 bool SkipFunctionBodies;
248 Parser(Preprocessor &PP, Sema &Actions,
bool SkipFunctionBodies);
293 assert(!isTokenSpecial() &&
294 "Should consume special tokens with Consume*Token");
297 return PrevTokLocation;
301 if (Tok.
isNot(Expected))
303 assert(!isTokenSpecial() &&
304 "Should consume special tokens with Consume*Token");
313 Loc = PrevTokLocation;
329 bool isTokenParen()
const {
330 return Tok.
getKind() == tok::l_paren || Tok.
getKind() == tok::r_paren;
333 bool isTokenBracket()
const {
334 return Tok.
getKind() == tok::l_square || Tok.
getKind() == tok::r_square;
337 bool isTokenBrace()
const {
338 return Tok.
getKind() == tok::l_brace || Tok.
getKind() == tok::r_brace;
341 bool isTokenStringLiteral()
const {
345 bool isTokenSpecial()
const {
346 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
347 isTokenBrace() || Tok.
is(tok::code_completion);
352 bool isTokenEqualOrEqualTypo();
356 void UnconsumeToken(
Token &Consumed) {
366 SourceLocation ConsumeAnyToken(
bool ConsumeCodeCompletionTok =
false) {
368 return ConsumeParen();
369 if (isTokenBracket())
370 return ConsumeBracket();
372 return ConsumeBrace();
373 if (isTokenStringLiteral())
374 return ConsumeStringToken();
375 if (Tok.
is(tok::code_completion))
376 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
377 : handleUnexpectedCodeCompletionToken();
383 SourceLocation ConsumeParen() {
384 assert(isTokenParen() &&
"wrong consume method");
385 if (Tok.
getKind() == tok::l_paren)
391 return PrevTokLocation;
396 SourceLocation ConsumeBracket() {
397 assert(isTokenBracket() &&
"wrong consume method");
398 if (Tok.
getKind() == tok::l_square)
400 else if (BracketCount)
405 return PrevTokLocation;
410 SourceLocation ConsumeBrace() {
411 assert(isTokenBrace() &&
"wrong consume method");
412 if (Tok.
getKind() == tok::l_brace)
419 return PrevTokLocation;
426 SourceLocation ConsumeStringToken() {
427 assert(isTokenStringLiteral() &&
428 "Should only consume string literals with this method");
431 return PrevTokLocation;
439 SourceLocation ConsumeCodeCompletionToken() {
440 assert(Tok.
is(tok::code_completion));
443 return PrevTokLocation;
451 SourceLocation handleUnexpectedCodeCompletionToken();
455 void cutOffParsing() {
466 return Kind ==
tok::eof || Kind == tok::annot_module_begin ||
467 Kind == tok::annot_module_end || Kind == tok::annot_module_include;
471 void initializePragmaHandlers();
474 void resetPragmaHandlers();
477 void HandlePragmaUnused();
481 void HandlePragmaVisibility();
485 void HandlePragmaPack();
489 void HandlePragmaMSStruct();
493 void HandlePragmaMSComment();
495 void HandlePragmaMSPointersToMembers();
497 void HandlePragmaMSVtorDisp();
499 void HandlePragmaMSPragma();
500 bool HandlePragmaMSSection(StringRef PragmaName,
501 SourceLocation PragmaLocation);
502 bool HandlePragmaMSSegment(StringRef PragmaName,
503 SourceLocation PragmaLocation);
504 bool HandlePragmaMSInitSeg(StringRef PragmaName,
505 SourceLocation PragmaLocation);
509 void HandlePragmaAlign();
513 void HandlePragmaDump();
517 void HandlePragmaWeak();
521 void HandlePragmaWeakAlias();
525 void HandlePragmaRedefineExtname();
529 void HandlePragmaFPContract();
533 void HandlePragmaOpenCLExtension();
541 bool HandlePragmaLoopHint(LoopHint &Hint);
550 const Token &GetLookAheadToken(
unsigned N) {
575 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
581 Tok.setAnnotationValue(ER.getAsOpaquePointer());
588 bool NeedType =
false);
596 enum AnnotatedNameKind {
609 TryAnnotateName(
bool IsAddressOfOperand,
610 std::unique_ptr<CorrectionCandidateCallback> CCC =
nullptr);
613 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
618 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
619 const char *&PrevSpec,
unsigned &DiagID,
624 if (Tok.getIdentifierInfo() != Ident_vector &&
625 Tok.getIdentifierInfo() != Ident_bool &&
626 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
629 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
635 bool TryAltiVecVectorToken() {
637 Tok.getIdentifierInfo() != Ident_vector)
return false;
638 return TryAltiVecVectorTokenOutOfLine();
641 bool TryAltiVecVectorTokenOutOfLine();
642 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
643 const char *&PrevSpec,
unsigned &DiagID,
649 bool isObjCInstancetype() {
651 if (Tok.isAnnotation())
653 if (!Ident_instancetype)
655 return Tok.getIdentifierInfo() == Ident_instancetype;
663 bool TryKeywordIdentFallback(
bool DisableKeyword);
666 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
679 class TentativeParsingAction {
682 size_t PrevTentativelyDeclaredIdentifierCount;
683 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
687 explicit TentativeParsingAction(
Parser& p) :
P(p) {
689 PrevTentativelyDeclaredIdentifierCount =
690 P.TentativelyDeclaredIdentifiers.size();
691 PrevParenCount =
P.ParenCount;
692 PrevBracketCount =
P.BracketCount;
693 PrevBraceCount =
P.BraceCount;
694 P.PP.EnableBacktrackAtThisPos();
698 assert(
isActive &&
"Parsing action was finished!");
699 P.TentativelyDeclaredIdentifiers.resize(
700 PrevTentativelyDeclaredIdentifierCount);
701 P.PP.CommitBacktrackedTokens();
705 assert(
isActive &&
"Parsing action was finished!");
708 P.TentativelyDeclaredIdentifiers.resize(
709 PrevTentativelyDeclaredIdentifierCount);
710 P.ParenCount = PrevParenCount;
711 P.BracketCount = PrevBracketCount;
712 P.BraceCount = PrevBraceCount;
715 ~TentativeParsingAction() {
716 assert(!
isActive &&
"Forgot to call Commit or Revert!");
721 class RevertingTentativeParsingAction
722 :
private Parser::TentativeParsingAction {
724 RevertingTentativeParsingAction(
Parser &
P)
725 :
Parser::TentativeParsingAction(P) {}
726 ~RevertingTentativeParsingAction() { Revert(); }
729 class UnannotatedTentativeParsingAction;
737 SaveAndRestore<bool> WithinObjCContainer;
741 WithinObjCContainer(
P.ParsingInObjCContainer, DC != nullptr) {
743 P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
747 P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
760 unsigned Diag = diag::err_expected,
761 StringRef DiagMsg =
"");
768 bool ExpectAndConsumeSemi(
unsigned DiagID);
774 InstanceVariableList = 2,
775 AfterMemberFunctionDefinition = 3
779 void ConsumeExtraSemi(ExtraSemiKind Kind,
unsigned TST =
TST_unspecified);
801 bool BeforeCompoundStmt =
false)
803 if (EnteredScope && !BeforeCompoundStmt)
806 if (BeforeCompoundStmt)
809 this->Self =
nullptr;
835 class ParseScopeFlags {
838 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
839 void operator=(
const ParseScopeFlags &) =
delete;
842 ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
850 DiagnosticBuilder
Diag(SourceLocation Loc,
unsigned DiagID);
851 DiagnosticBuilder
Diag(
const Token &Tok,
unsigned DiagID);
853 return Diag(Tok, DiagID);
874 static_cast<unsigned>(R));
887 return SkipUntil(llvm::makeArrayRef(T), Flags);
920 class LateParsedDeclaration {
922 virtual ~LateParsedDeclaration();
924 virtual void ParseLexedMethodDeclarations();
925 virtual void ParseLexedMemberInitializers();
926 virtual void ParseLexedMethodDefs();
927 virtual void ParseLexedAttributes();
932 class LateParsedClass :
public LateParsedDeclaration {
934 LateParsedClass(
Parser *
P, ParsingClass *C);
935 ~LateParsedClass()
override;
937 void ParseLexedMethodDeclarations()
override;
938 void ParseLexedMemberInitializers()
override;
939 void ParseLexedMethodDefs()
override;
940 void ParseLexedAttributes()
override;
953 struct LateParsedAttribute :
public LateParsedDeclaration {
956 IdentifierInfo &AttrName;
957 SourceLocation AttrNameLoc;
958 SmallVector<Decl*, 2> Decls;
960 explicit LateParsedAttribute(
Parser *
P, IdentifierInfo &
Name,
962 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
964 void ParseLexedAttributes()
override;
966 void addDecl(
Decl *D) { Decls.push_back(D); }
970 class LateParsedAttrList:
public SmallVector<LateParsedAttribute *, 2> {
972 LateParsedAttrList(
bool PSoon =
false) : ParseSoon(PSoon) { }
974 bool parseSoon() {
return ParseSoon; }
983 struct LexedMethod :
public LateParsedDeclaration {
994 : Self(P), D(MD), TemplateScope(
false) {}
996 void ParseLexedMethodDefs()
override;
1003 struct LateParsedDefaultArgument {
1004 explicit LateParsedDefaultArgument(
Decl *
P,
1006 : Param(P), Toks(Toks) { }
1022 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1023 explicit LateParsedMethodDeclaration(
Parser *
P,
Decl *M)
1024 : Self(P), Method(M), TemplateScope(
false),
1025 ExceptionSpecTokens(nullptr) {}
1027 void ParseLexedMethodDeclarations()
override;
1044 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1054 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1056 : Self(P),
Field(FD) { }
1058 void ParseLexedMemberInitializers()
override;
1076 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
1081 struct ParsingClass {
1082 ParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
1083 : TopLevelClass(TopLevelClass), TemplateScope(
false),
1084 IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { }
1088 bool TopLevelClass : 1;
1093 bool TemplateScope : 1;
1096 bool IsInterface : 1;
1099 Decl *TagOrTemplate;
1104 LateParsedDeclarationsContainer LateParsedDeclarations;
1110 std::stack<ParsingClass *> ClassStack;
1112 ParsingClass &getCurrentClass() {
1113 assert(!ClassStack.empty() &&
"No lexed method stacks!");
1114 return *ClassStack.top();
1118 class ParsingClassDefinition {
1124 ParsingClassDefinition(
Parser &
P,
Decl *TagOrTemplate,
bool TopLevelClass,
1126 : P(P), Popped(
false),
1127 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1132 assert(!Popped &&
"Nested class has already been popped");
1134 P.PopParsingClass(
State);
1137 ~ParsingClassDefinition() {
1139 P.PopParsingClass(
State);
1146 struct ParsedTemplateInfo {
1147 ParsedTemplateInfo()
1148 : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
1151 bool isSpecialization,
1152 bool lastParameterListWasEmpty =
false)
1153 : Kind(isSpecialization? ExplicitSpecialization : Template),
1154 TemplateParams(TemplateParams),
1155 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1157 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1158 SourceLocation TemplateLoc)
1159 : Kind(ExplicitInstantiation), TemplateParams(nullptr),
1160 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1161 LastParameterListWasEmpty(
false){ }
1170 ExplicitSpecialization,
1172 ExplicitInstantiation
1181 SourceLocation ExternLoc;
1185 SourceLocation TemplateLoc;
1188 bool LastParameterListWasEmpty;
1193 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
1194 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1196 static
void LateTemplateParserCallback(
void *
P, LateParsedTemplate &LPT);
1197 static
void LateTemplateParserCleanupCallback(
void *P);
1199 Sema::ParsingClassState
1200 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
1201 void DeallocateParsedClasses(ParsingClass *Class);
1202 void PopParsingClass(Sema::ParsingClassState);
1204 enum CachedInitKind {
1205 CIK_DefaultArgument,
1206 CIK_DefaultInitializer
1210 AttributeList *AccessAttrs,
1211 ParsingDeclarator &D,
1212 const ParsedTemplateInfo &TemplateInfo,
1213 const VirtSpecifiers& VS,
1214 SourceLocation PureSpecLoc);
1215 void ParseCXXNonStaticMemberInitializer(
Decl *VarD);
1216 void ParseLexedAttributes(ParsingClass &Class);
1217 void ParseLexedAttributeList(LateParsedAttrList &LAs,
Decl *D,
1219 void ParseLexedAttribute(LateParsedAttribute &LA,
1221 void ParseLexedMethodDeclarations(ParsingClass &Class);
1222 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1223 void ParseLexedMethodDefs(ParsingClass &Class);
1224 void ParseLexedMethodDef(LexedMethod &LM);
1225 void ParseLexedMemberInitializers(ParsingClass &Class);
1226 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1227 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
1228 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1229 bool ConsumeAndStoreInitializer(
CachedTokens &Toks, CachedInitKind CIK);
1234 bool ConsumeFinalToken =
true) {
1235 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1240 bool ConsumeFinalToken =
true);
1244 struct ParsedAttributesWithRange : ParsedAttributes {
1245 ParsedAttributesWithRange(AttributeFactory &factory)
1246 : ParsedAttributes(factory) {}
1251 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
1252 ParsingDeclSpec *DS =
nullptr);
1253 bool isDeclarationAfterDeclarator();
1254 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1256 ParsedAttributesWithRange &attrs,
1257 ParsingDeclSpec *DS =
nullptr,
1259 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
1260 ParsingDeclSpec &DS,
1263 void SkipFunctionBody();
1264 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1265 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1266 LateParsedAttrList *LateParsedAttrs =
nullptr);
1267 void ParseKNRParamDeclarations(Declarator &D);
1270 ExprResult ParseSimpleAsm(SourceLocation *EndLoc =
nullptr);
1276 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1277 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1278 ParsedAttributes &prefixAttrs);
1279 class ObjCTypeParamListScope;
1280 ObjCTypeParamList *parseObjCTypeParamList();
1281 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1282 ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1283 SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1284 SourceLocation &rAngleLoc,
bool mayBeProtocolList =
true);
1286 void HelperActionsForIvarDeclarations(
Decl *interfaceDecl, SourceLocation atLoc,
1288 SmallVectorImpl<Decl *> &AllIvarDecls,
1289 bool RBraceMissing);
1290 void ParseObjCClassInstanceVariables(
Decl *interfaceDecl,
1292 SourceLocation atLoc);
1293 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &
P,
1294 SmallVectorImpl<SourceLocation> &PLocs,
1295 bool WarnOnDeclarations,
1296 bool ForObjCContainer,
1297 SourceLocation &LAngleLoc,
1298 SourceLocation &EndProtoLoc,
1299 bool consumeLastToken);
1304 void parseObjCTypeArgsOrProtocolQualifiers(
1306 SourceLocation &typeArgsLAngleLoc,
1307 SmallVectorImpl<ParsedType> &typeArgs,
1308 SourceLocation &typeArgsRAngleLoc,
1309 SourceLocation &protocolLAngleLoc,
1310 SmallVectorImpl<Decl *> &protocols,
1311 SmallVectorImpl<SourceLocation> &protocolLocs,
1312 SourceLocation &protocolRAngleLoc,
1313 bool consumeLastToken,
1314 bool warnOnIncompleteProtocols);
1318 void parseObjCTypeArgsAndProtocolQualifiers(
1320 SourceLocation &typeArgsLAngleLoc,
1321 SmallVectorImpl<ParsedType> &typeArgs,
1322 SourceLocation &typeArgsRAngleLoc,
1323 SourceLocation &protocolLAngleLoc,
1324 SmallVectorImpl<Decl *> &protocols,
1325 SmallVectorImpl<SourceLocation> &protocolLocs,
1326 SourceLocation &protocolRAngleLoc,
1327 bool consumeLastToken);
1331 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1335 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1337 bool consumeLastToken,
1338 SourceLocation &endLoc);
1342 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1343 ParsedAttributes &prefixAttrs);
1345 struct ObjCImplParsingDataRAII {
1349 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1350 LateParsedObjCMethodContainer LateParsedObjCMethods;
1352 ObjCImplParsingDataRAII(
Parser &parser,
Decl *D)
1353 :
P(parser), Dcl(D), HasCFunction(
false) {
1354 P.CurParsedObjCImpl =
this;
1357 ~ObjCImplParsingDataRAII();
1359 void finish(SourceRange AtEnd);
1360 bool isFinished()
const {
return Finished; }
1365 ObjCImplParsingDataRAII *CurParsedObjCImpl;
1366 void StashAwayMethodOrFunctionBodyTokens(
Decl *MDecl);
1368 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1370 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1371 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1372 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1374 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1377 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1378 objc_nonnull, objc_nullable, objc_null_unspecified,
1381 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1383 bool isTokIdentifier_in()
const;
1386 ParsedAttributes *ParamAttrs);
1387 void ParseObjCMethodRequirement();
1388 Decl *ParseObjCMethodPrototype(
1390 bool MethodDefinition =
true);
1393 bool MethodDefinition=
true);
1394 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1396 Decl *ParseObjCMethodDefinition();
1416 unsigned &NumLineToksConsumed,
1418 bool IsUnevaluated);
1427 ExprResult ParseCastExpression(
bool isUnaryExpression,
1428 bool isAddressOfOperand,
1431 ExprResult ParseCastExpression(
bool isUnaryExpression,
1432 bool isAddressOfOperand =
false,
1436 bool isNotExpressionStart();
1440 bool isPostfixExpressionSuffixStart() {
1442 return (K == tok::l_square || K == tok::l_paren ||
1443 K == tok::period || K == tok::arrow ||
1444 K == tok::plusplus || K == tok::minusminus);
1448 ExprResult ParseUnaryExprOrTypeTraitExpression();
1454 SourceRange &CastRange);
1456 typedef SmallVector<Expr*, 20> ExprListTy;
1457 typedef SmallVector<SourceLocation, 20> CommaLocsTy;
1460 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1461 SmallVectorImpl<SourceLocation> &CommaLocs,
1462 std::function<
void()> Completer =
nullptr);
1466 bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
1467 SmallVectorImpl<SourceLocation> &CommaLocs);
1471 enum ParenParseOption {
1477 ExprResult ParseParenExpression(ParenParseOption &ExprType,
1478 bool stopIfCastExpr,
1481 SourceLocation &RParenLoc);
1484 ParenParseOption &ExprType,
ParsedType &CastTy,
1487 SourceLocation LParenLoc,
1488 SourceLocation RParenLoc);
1490 ExprResult ParseStringLiteralExpression(
bool AllowUserDefinedLiteral =
false);
1492 ExprResult ParseGenericSelectionExpression();
1500 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
1502 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
1504 bool areTokensAdjacent(
const Token &A,
const Token &B);
1506 void CheckForTemplateAndDigraph(
Token &Next,
ParsedType ObjectTypePtr,
1507 bool EnteringContext, IdentifierInfo &II,
1510 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1512 bool EnteringContext,
1513 bool *MayBePseudoDestructor =
nullptr,
1514 bool IsTypename =
false,
1515 IdentifierInfo **LastII =
nullptr);
1517 void CheckForLParenAfterColonColon();
1525 Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro,
1526 bool *SkippedInits =
nullptr);
1527 bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1528 ExprResult ParseLambdaExpressionAfterIntroducer(
1529 LambdaIntroducer &Intro);
1545 ExprResult ParseCXXPseudoDestructor(Expr *
Base, SourceLocation OpLoc,
1560 SourceRange &SpecificationRange,
1561 SmallVectorImpl<ParsedType> &DynamicExceptions,
1562 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
1568 SourceRange &SpecificationRange,
1569 SmallVectorImpl<ParsedType> &Exceptions,
1570 SmallVectorImpl<SourceRange> &Ranges);
1574 TypeResult ParseTrailingReturnType(SourceRange &Range);
1582 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
1587 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1589 bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
1593 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1595 void ParseDirectNewDeclarator(Declarator &D);
1596 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
1597 ExprResult ParseCXXDeleteExpression(
bool UseGlobal,
1598 SourceLocation Start);
1602 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
1619 if (Tok.isNot(tok::l_brace))
1621 return ParseBraceInitializer();
1623 bool MayBeDesignationStart();
1625 ExprResult ParseInitializerWithPotentialDesignator();
1634 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
1635 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
1636 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1637 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1638 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
1639 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1640 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
1641 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
1642 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
1643 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
1644 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
1645 bool isSimpleObjCMessageExpression();
1647 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
1648 SourceLocation SuperLoc,
1650 Expr *ReceiverExpr);
1651 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
1652 SourceLocation LBracloc, SourceLocation SuperLoc,
1653 ParsedType ReceiverType, Expr *ReceiverExpr);
1654 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
1661 typedef SmallVector<Stmt*, 32> StmtVector;
1663 typedef SmallVector<Expr*, 12> ExprVector;
1665 typedef SmallVector<ParsedType, 12> TypeVector;
1667 StmtResult ParseStatement(SourceLocation *TrailingElseLoc =
nullptr,
1668 bool AllowOpenMPStandalone =
false);
1669 enum AllowedContsructsKind {
1673 ACK_StatementsOpenMPNonStandalone,
1675 ACK_StatementsOpenMPAnyExecutable
1678 ParseStatementOrDeclaration(StmtVector &Stmts, AllowedContsructsKind Allowed,
1679 SourceLocation *TrailingElseLoc =
nullptr);
1680 StmtResult ParseStatementOrDeclarationAfterAttributes(
1682 AllowedContsructsKind Allowed,
1683 SourceLocation *TrailingElseLoc,
1684 ParsedAttributesWithRange &Attrs);
1686 StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
1687 StmtResult ParseCaseStatement(
bool MissingCase =
false,
1690 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
1691 StmtResult ParseCompoundStatement(
bool isStmtExpr,
1692 unsigned ScopeFlags);
1693 void ParseCompoundStatementLeadingPragmas();
1694 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
1695 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
1696 Sema::ConditionResult &CondResult,
1699 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
1700 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
1701 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
1703 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
1709 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1710 StmtResult ParsePragmaLoopHint(StmtVector &Stmts,
1711 AllowedContsructsKind Allowed,
1712 SourceLocation *TrailingElseLoc,
1713 ParsedAttributesWithRange &Attrs);
1717 enum IfExistsBehavior {
1729 struct IfExistsCondition {
1731 SourceLocation KeywordLoc;
1744 IfExistsBehavior Behavior;
1747 bool ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result);
1748 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1749 void ParseMicrosoftIfExistsExternalDeclaration();
1750 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
1752 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
1754 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &
Names,
1755 SmallVectorImpl<Expr *> &Constraints,
1756 SmallVectorImpl<Expr *> &Exprs);
1762 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc,
bool FnTry =
false);
1763 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
1769 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
1770 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
1776 StmtResult ParseObjCAtStatement(SourceLocation atLoc);
1777 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
1778 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1779 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1780 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1789 enum DeclSpecContext {
1794 DSC_alias_declaration,
1796 DSC_template_type_arg,
1797 DSC_objc_method_result,
1803 static bool isTypeSpecifier(DeclSpecContext DSC) {
1808 case DSC_objc_method_result:
1812 case DSC_template_type_arg:
1813 case DSC_type_specifier:
1815 case DSC_alias_declaration:
1818 llvm_unreachable(
"Missing DeclSpecContext case");
1823 struct ForRangeInit {
1827 bool ParsedForRangeDecl() {
return !
ColonLoc.isInvalid(); }
1831 ParsedAttributesWithRange &attrs);
1833 SourceLocation &DeclEnd,
1834 ParsedAttributesWithRange &attrs,
1836 ForRangeInit *FRI =
nullptr);
1837 bool MightBeDeclarator(
unsigned Context);
1839 SourceLocation *DeclEnd =
nullptr,
1840 ForRangeInit *FRI =
nullptr);
1841 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1842 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1843 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1844 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1846 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1847 ForRangeInit *FRI =
nullptr);
1848 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
1849 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
1855 bool trySkippingFunctionBody();
1857 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1858 const ParsedTemplateInfo &TemplateInfo,
1860 ParsedAttributesWithRange &Attrs);
1861 DeclSpecContext getDeclSpecContextFromDeclaratorContext(
unsigned Context);
1862 void ParseDeclarationSpecifiers(DeclSpec &DS,
1863 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1865 DeclSpecContext DSC = DSC_normal,
1866 LateParsedAttrList *LateAttrs =
nullptr);
1867 bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS,
AccessSpecifier AS,
1868 DeclSpecContext DSContext,
1869 LateParsedAttrList *LateAttrs =
nullptr);
1872 DeclSpecContext DSC = DSC_normal);
1874 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1877 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1878 const ParsedTemplateInfo &TemplateInfo,
1880 void ParseEnumBody(SourceLocation StartLoc,
Decl *TagDecl);
1881 void ParseStructUnionBody(SourceLocation StartLoc,
unsigned TagType,
1884 void ParseStructDeclaration(
1885 ParsingDeclSpec &DS,
1886 llvm::function_ref<
void(ParsingFieldDeclarator &)> FieldsCallback);
1888 bool isDeclarationSpecifier(
bool DisambiguatingWithExpression =
false);
1889 bool isTypeSpecifierQualifier();
1894 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
1899 bool isKnownToBeDeclarationSpecifier() {
1902 return isDeclarationSpecifier(
true);
1908 bool isDeclarationStatement() {
1910 return isCXXDeclarationStatement();
1911 return isDeclarationSpecifier(
true);
1918 bool isForInitDeclaration() {
1920 return isCXXSimpleDeclaration(
true);
1921 return isDeclarationSpecifier(
true);
1925 bool isForRangeIdentifier();
1929 bool isStartOfObjCClassMessageMissingOpenBracket();
1934 bool isConstructorDeclarator(
bool Unqualified);
1938 enum TentativeCXXTypeIdContext {
1941 TypeIdAsTemplateArgument
1948 bool isTypeIdInParens(
bool &isAmbiguous) {
1950 return isCXXTypeId(TypeIdInParens, isAmbiguous);
1951 isAmbiguous =
false;
1952 return isTypeSpecifierQualifier();
1954 bool isTypeIdInParens() {
1956 return isTypeIdInParens(isAmbiguous);
1962 bool isTypeIdUnambiguously() {
1965 return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
1966 return isTypeSpecifierQualifier();
1972 bool isCXXDeclarationStatement();
1979 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
1988 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr);
1990 struct ConditionDeclarationOrInitStatementState;
1991 enum class ConditionOrInitStatement {
2000 ConditionOrInitStatement
2001 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt);
2003 bool isCXXTypeId(TentativeCXXTypeIdContext
Context,
bool &isAmbiguous);
2004 bool isCXXTypeId(TentativeCXXTypeIdContext
Context) {
2006 return isCXXTypeId(Context, isAmbiguous);
2011 enum class TPResult {
2012 True, False, Ambiguous,
Error
2035 isCXXDeclarationSpecifier(TPResult BracedCastResult =
TPResult::False,
2036 bool *HasMissingTypename =
nullptr);
2041 bool isCXXDeclarationSpecifierAType();
2046 bool isTentativelyDeclared(IdentifierInfo *II);
2055 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
2056 TPResult TryParseTypeofSpecifier();
2057 TPResult TryParseProtocolQualifiers();
2058 TPResult TryParsePtrOperatorSeq();
2059 TPResult TryParseOperatorId();
2060 TPResult TryParseInitDeclaratorList();
2061 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier=
true);
2063 TryParseParameterDeclarationClause(
bool *InvalidAsDeclaration =
nullptr,
2064 bool VersusTemplateArg =
false);
2065 TPResult TryParseFunctionDeclarator();
2066 TPResult TryParseBracketDeclarator();
2067 TPResult TryConsumeDeclarationSpecifier();
2074 Decl **OwnedType =
nullptr,
2075 ParsedAttributes *Attrs =
nullptr);
2078 void ParseBlockId(SourceLocation CaretLoc);
2082 bool CheckProhibitedCXX11Attribute() {
2083 assert(Tok.is(tok::l_square));
2086 return DiagnoseProhibitedCXX11Attribute();
2088 bool DiagnoseProhibitedCXX11Attribute();
2089 void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2090 SourceLocation CorrectLocation) {
2093 if ((Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2094 Tok.isNot(tok::kw_alignas))
2096 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2098 void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2099 SourceLocation CorrectLocation);
2101 void handleDeclspecAlignBeforeClassKey(ParsedAttributesWithRange &Attrs,
2104 void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
2105 if (!attrs.Range.isValid())
return;
2106 DiagnoseProhibitedAttributes(attrs);
2109 void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
2114 void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs);
2118 SourceLocation SkipCXX11Attributes();
2122 void DiagnoseAndSkipCXX11Attributes();
2129 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2130 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2131 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2134 void MaybeParseGNUAttributes(Declarator &D,
2135 LateParsedAttrList *LateAttrs =
nullptr) {
2136 if (Tok.is(tok::kw___attribute)) {
2137 ParsedAttributes attrs(AttrFactory);
2138 SourceLocation endLoc;
2139 ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D);
2140 D.takeAttributes(attrs, endLoc);
2143 void MaybeParseGNUAttributes(ParsedAttributes &attrs,
2144 SourceLocation *endLoc =
nullptr,
2145 LateParsedAttrList *LateAttrs =
nullptr) {
2146 if (Tok.is(tok::kw___attribute))
2147 ParseGNUAttributes(attrs, endLoc, LateAttrs);
2149 void ParseGNUAttributes(ParsedAttributes &attrs,
2150 SourceLocation *endLoc =
nullptr,
2151 LateParsedAttrList *LateAttrs =
nullptr,
2152 Declarator *D =
nullptr);
2153 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2154 SourceLocation AttrNameLoc,
2155 ParsedAttributes &Attrs,
2156 SourceLocation *EndLoc,
2157 IdentifierInfo *ScopeName,
2158 SourceLocation ScopeLoc,
2161 IdentifierLoc *ParseIdentifierLoc();
2163 void MaybeParseCXX11Attributes(Declarator &D) {
2165 ParsedAttributesWithRange attrs(AttrFactory);
2166 SourceLocation endLoc;
2167 ParseCXX11Attributes(attrs, &endLoc);
2168 D.takeAttributes(attrs, endLoc);
2171 void MaybeParseCXX11Attributes(ParsedAttributes &attrs,
2172 SourceLocation *endLoc =
nullptr) {
2174 ParsedAttributesWithRange attrsWithRange(AttrFactory);
2175 ParseCXX11Attributes(attrsWithRange, endLoc);
2176 attrs.takeAllFrom(attrsWithRange);
2179 void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2180 SourceLocation *endLoc =
nullptr,
2181 bool OuterMightBeMessageSend =
false) {
2183 isCXX11AttributeSpecifier(
false, OuterMightBeMessageSend))
2184 ParseCXX11Attributes(attrs, endLoc);
2187 void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
2188 SourceLocation *EndLoc =
nullptr);
2189 void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2190 SourceLocation *EndLoc =
nullptr);
2193 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2194 SourceLocation AttrNameLoc,
2195 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2196 IdentifierInfo *ScopeName,
2197 SourceLocation ScopeLoc);
2199 IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
2201 void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
2202 SourceLocation *endLoc =
nullptr) {
2203 if (
getLangOpts().MicrosoftExt && Tok.is(tok::l_square))
2204 ParseMicrosoftAttributes(attrs, endLoc);
2206 void ParseMicrosoftAttributes(ParsedAttributes &attrs,
2207 SourceLocation *endLoc =
nullptr);
2208 void MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2209 SourceLocation *
End =
nullptr) {
2211 if (LO.DeclSpecKeyword && Tok.is(tok::kw___declspec))
2212 ParseMicrosoftDeclSpecs(Attrs,
End);
2214 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2215 SourceLocation *
End =
nullptr);
2216 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2217 SourceLocation AttrNameLoc,
2218 ParsedAttributes &Attrs);
2219 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2220 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2221 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2222 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
2223 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2224 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2225 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2229 bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) {
2231 return ParseOpenCLUnrollHintAttribute(Attrs);
2236 bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs);
2237 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2239 VersionTuple ParseVersionTuple(SourceRange &Range);
2240 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2241 SourceLocation AvailabilityLoc,
2242 ParsedAttributes &attrs,
2243 SourceLocation *endLoc,
2244 IdentifierInfo *ScopeName,
2245 SourceLocation ScopeLoc,
2248 Optional<AvailabilitySpec> ParseAvailabilitySpec();
2249 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
2251 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2252 SourceLocation ObjCBridgeRelatedLoc,
2253 ParsedAttributes &attrs,
2254 SourceLocation *endLoc,
2255 IdentifierInfo *ScopeName,
2256 SourceLocation ScopeLoc,
2259 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2260 SourceLocation AttrNameLoc,
2261 ParsedAttributes &Attrs,
2262 SourceLocation *EndLoc,
2263 IdentifierInfo *ScopeName,
2264 SourceLocation ScopeLoc,
2267 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2268 SourceLocation AttrNameLoc,
2269 ParsedAttributes &Attrs,
2270 SourceLocation *EndLoc,
2271 IdentifierInfo *ScopeName,
2272 SourceLocation ScopeLoc,
2275 void ParseTypeofSpecifier(DeclSpec &DS);
2276 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
2277 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
2278 SourceLocation StartLoc,
2279 SourceLocation EndLoc);
2280 void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
2281 void ParseAtomicSpecifier(DeclSpec &DS);
2283 ExprResult ParseAlignArgument(SourceLocation Start,
2284 SourceLocation &EllipsisLoc);
2285 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2286 SourceLocation *endLoc =
nullptr);
2290 return isCXX11VirtSpecifier(Tok);
2292 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
2293 SourceLocation FriendLoc);
2295 bool isCXX11FinalKeyword()
const;
2300 class DeclaratorScopeObj {
2306 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2307 :
P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2309 void EnterDeclaratorScope() {
2310 assert(!EnteredScope &&
"Already entered the scope!");
2311 assert(SS.isSet() &&
"C++ scope was not set!");
2313 CreatedScope =
true;
2316 if (!
P.Actions.ActOnCXXEnterDeclaratorScope(
P.getCurScope(), SS))
2317 EnteredScope =
true;
2320 ~DeclaratorScopeObj() {
2322 assert(SS.isSet() &&
"C++ scope was cleared ?");
2323 P.Actions.ActOnCXXExitDeclaratorScope(
P.getCurScope(), SS);
2331 void ParseDeclarator(Declarator &D);
2333 typedef void (
Parser::*DirectDeclParseFunction)(Declarator&);
2334 void ParseDeclaratorInternal(Declarator &D,
2335 DirectDeclParseFunction DirectDeclParser);
2337 enum AttrRequirements {
2338 AR_NoAttributesParsed = 0,
2339 AR_GNUAttributesParsedAndRejected = 1 << 0,
2340 AR_GNUAttributesParsed = 1 << 1,
2341 AR_CXX11AttributesParsed = 1 << 2,
2342 AR_DeclspecAttributesParsed = 1 << 3,
2343 AR_AllAttributesParsed = AR_GNUAttributesParsed |
2344 AR_CXX11AttributesParsed |
2345 AR_DeclspecAttributesParsed,
2346 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
2347 AR_DeclspecAttributesParsed
2350 void ParseTypeQualifierListOpt(DeclSpec &DS,
2351 unsigned AttrReqs = AR_AllAttributesParsed,
2352 bool AtomicAllowed =
true,
2353 bool IdentifierRequired =
false);
2354 void ParseDirectDeclarator(Declarator &D);
2355 void ParseParenDeclarator(Declarator &D);
2356 void ParseFunctionDeclarator(Declarator &D,
2357 ParsedAttributes &attrs,
2360 bool RequiresArg =
false);
2361 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2362 SourceLocation &RefQualifierLoc);
2363 bool isFunctionDeclaratorIdentifierList();
2364 void ParseFunctionDeclaratorIdentifierList(
2366 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2367 void ParseParameterDeclarationClause(
2369 ParsedAttributes &attrs,
2370 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2371 SourceLocation &EllipsisLoc);
2372 void ParseBracketDeclarator(Declarator &D);
2373 void ParseMisplacedBracketDeclarator(Declarator &D);
2379 enum CXX11AttributeKind {
2381 CAK_NotAttributeSpecifier,
2383 CAK_AttributeSpecifier,
2386 CAK_InvalidAttributeSpecifier
2389 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
2390 bool OuterMightBeMessageSend =
false);
2392 void DiagnoseUnexpectedNamespace(NamedDecl *
Context);
2395 SourceLocation InlineLoc = SourceLocation());
2396 void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
2397 std::vector<IdentifierInfo*>& Ident,
2398 std::vector<SourceLocation>& NamespaceLoc,
2399 unsigned int index, SourceLocation& InlineLoc,
2400 ParsedAttributes& attrs,
2402 Decl *ParseLinkage(ParsingDeclSpec &DS,
unsigned Context);
2403 Decl *ParseUsingDirectiveOrDeclaration(
unsigned Context,
2404 const ParsedTemplateInfo &TemplateInfo,
2405 SourceLocation &DeclEnd,
2406 ParsedAttributesWithRange &attrs,
2407 Decl **OwnedType =
nullptr);
2408 Decl *ParseUsingDirective(
unsigned Context,
2409 SourceLocation UsingLoc,
2410 SourceLocation &DeclEnd,
2411 ParsedAttributes &attrs);
2412 Decl *ParseUsingDeclaration(
unsigned Context,
2413 const ParsedTemplateInfo &TemplateInfo,
2414 SourceLocation UsingLoc,
2415 SourceLocation &DeclEnd,
2417 Decl **OwnedType =
nullptr);
2418 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2419 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2420 SourceLocation AliasLoc, IdentifierInfo *Alias,
2421 SourceLocation &DeclEnd);
2425 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
2426 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
2427 DeclSpec &DS,
const ParsedTemplateInfo &TemplateInfo,
2429 DeclSpecContext DSC,
2430 ParsedAttributesWithRange &Attributes);
2431 void SkipCXXMemberSpecification(SourceLocation StartLoc,
2432 SourceLocation AttrFixitLoc,
2435 void ParseCXXMemberSpecification(SourceLocation StartLoc,
2436 SourceLocation AttrFixitLoc,
2437 ParsedAttributesWithRange &Attrs,
2441 SourceLocation &EqualLoc);
2442 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
2445 LateParsedAttrList &LateAttrs);
2446 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
2447 VirtSpecifiers &VS);
2450 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2451 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
2455 void ParseConstructorInitializer(
Decl *ConstructorDecl);
2457 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
2462 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
2463 SourceLocation &EndLocation);
2464 void ParseBaseClause(
Decl *ClassDecl);
2468 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
2469 SourceLocation TemplateKWLoc,
2470 IdentifierInfo *
Name,
2471 SourceLocation NameLoc,
2472 bool EnteringContext,
2475 bool AssumeTemplateId);
2476 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2485 SourceLocation Loc);
2490 Decl *TagDecl =
nullptr);
2501 bool ParseOpenMPSimpleVarList(
2503 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)> &
2505 bool AllowScopeSpecifier);
2514 ParseOpenMPDeclarativeOrExecutableDirective(AllowedContsructsKind Allowed);
2568 bool IsMapTypeImplicit =
false;
2577 bool AllowDestructorName,
2578 bool AllowConstructorName,
2588 Decl *ParseDeclarationStartingWithTemplate(
unsigned Context,
2592 Decl *ParseTemplateDeclarationOrSpecialization(
unsigned Context,
2596 Decl *ParseSingleDeclarationAfterTemplate(
2598 const ParsedTemplateInfo &TemplateInfo,
2603 bool ParseTemplateParameters(
unsigned Depth,
2607 bool ParseTemplateParameterList(
unsigned Depth,
2609 bool isStartOfTemplateTypeParameter();
2616 bool AlreadyHasEllipsis,
2617 bool IdentifierHasName);
2618 void DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
2624 bool ConsumeLastToken,
2625 bool ObjCGenericList);
2626 bool ParseTemplateIdAfterTemplateName(
TemplateTy Template,
2629 bool ConsumeLastToken,
2638 bool AllowTypeAnnotation =
true);
2639 void AnnotateTemplateIdTokenAsType();
2640 bool IsTemplateArgumentList(
unsigned Skip = 0);
2644 Decl *ParseExplicitInstantiation(
unsigned Context,
2653 bool parseMisplacedModuleImport();
2654 bool tryParseMisplacedModuleImport() {
2656 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
2657 Kind == tok::annot_module_include)
2658 return parseMisplacedModuleImport();
2673 void CodeCompleteDirective(
bool InConditional)
override;
2674 void CodeCompleteInConditionalExclusion()
override;
2675 void CodeCompleteMacroName(
bool IsDefinition)
override;
2676 void CodeCompletePreprocessorExpression()
override;
2678 unsigned ArgumentIndex)
override;
2679 void CodeCompleteNaturalLanguage()
override;
Sema::FullExprArg FullExprArg
Scope * getCurScope() const
Retrieve the parser's current scope.
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind...
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
ParseScope - Introduces a new scope for parsing.
DeclarationNameInfo ReductionId
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
void incrementMSManglingNumber() const
RAII object used to inform the actions that we're currently parsing a declaration.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
SourceLocation DepLinMapLoc
Decl * getObjCDeclContext() const
void setCodeCompletionReached()
Note that we hit the code-completion point.
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
Information about one declarator, including the parsed type information and the identifier.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
friend class ObjCDeclContextSwitch
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
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. ...
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
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
Represents a C++ unqualified-id that has been parsed.
bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc)
Concrete class used by the front-end to report problems and issues.
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
Scope - A scope is a transient data structure that is used while parsing the program.
Represents a C++ nested-name-specifier or a global scope specifier.
tok::TokenKind getKind() const
const TargetInfo & getTargetInfo() const
AttributeFactory & getAttrFactory()
void * getAnnotationValue() const
Sema - This implements semantic analysis and AST building for C.
A little helper class used to produce diagnostics.
TypeResult ParseTypeName(SourceRange *Range=nullptr, Declarator::TheContext Context=Declarator::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Exposes information about the current target.
void setAnnotationValue(void *val)
Expr - This represents one expression.
MatchFinder::MatchCallback * Callback
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
OpaquePtr< TemplateName > TemplateTy
CXXScopeSpec ReductionIdScopeSpec
Defines the clang::Preprocessor interface.
OpenMPClauseKind
OpenMP clauses.
Represents a C++ template name within the type system.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
bool isNot(tok::TokenKind K) const
Defines and computes precedence levels for binary/ternary operators.
ActionResult< CXXCtorInitializer * > MemInitResult
The result type of a method or function.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Stop skipping at semicolon.
Represents the parsed form of a C++ template argument.
ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, void *Info, bool IsUnevaluated)
Parse an identifier in an MS-style inline assembly block.
Encodes a location in the source.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
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)) {...
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc)
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
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)
static bool isInvalid(LocType Loc, bool *Invalid)
Sema & getActions() const
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
SkipUntilFlags
Control flags for SkipUntil functions.
Data used for parsing list of variables in OpenMP clauses.
friend LLVM_CONSTEXPR SkipUntilFlags operator|(SkipUntilFlags L, SkipUntilFlags R)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
static const TST TST_unspecified
friend class ColonProtectionRAIIObject
Encapsulates the data about a macro definition (e.g.
Syntax
The style used to specify an attribute.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
ActionResult< Stmt * > StmtResult
void * getAsOpaquePtr() const
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
ActionResult< ParsedType > TypeResult
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
ProcessingContextState ParsingClassState
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...
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
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 ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr * > &Vars, OpenMPVarListDataTy &Data)
Parses clauses with list.
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
A trivial tuple used to represent a source range.
Callback handler that receives notifications when performing code completion within the preprocessor...
Decl * getObjCDeclContext() const
static OpaquePtr getFromOpaquePtr(void *P)
SourceLocation ColonLoc
Location of ':'.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
AttributeList - Represents a syntactic attribute.
Stop skipping at specified token, but don't skip the token itself.