clang 20.0.0git
|
Parser - This implements a parser for the C family of languages. More...
#include "clang/Parse/Parser.h"
Classes | |
struct | ConditionDeclarationOrInitStatementState |
class | MultiParseScope |
Introduces zero or more scopes for parsing. More... | |
class | ObjCTypeParamListScope |
Class to handle popping type parameters when leaving the scope. More... | |
class | ParseScope |
ParseScope - Introduces a new scope for parsing. More... | |
struct | ReenterClassScopeRAII |
Utility to re-enter a class scope while parsing its late-parsed components. More... | |
struct | ReenterTemplateScopeRAII |
Utility to re-enter a possibly-templated scope while parsing its late-parsed components. More... | |
Public Types | |
enum | SkipUntilFlags { StopAtSemi = 1 << 0 , StopBeforeMatch = 1 << 1 , StopAtCodeCompletion = 1 << 2 } |
Control flags for SkipUntil functions. More... | |
enum | TypeCastState { NotTypeCast = 0 , MaybeTypeCast , IsTypeCast } |
TypeCastState - State whether an expression is or may be a type cast. More... | |
typedef OpaquePtr< DeclGroupRef > | DeclGroupPtrTy |
typedef OpaquePtr< TemplateName > | TemplateTy |
typedef SmallVector< TemplateParameterList *, 4 > | TemplateParameterLists |
typedef Sema::FullExprArg | FullExprArg |
typedef SmallVector< Stmt *, 32 > | StmtVector |
A SmallVector of statements. | |
Public Member Functions | |
Parser (Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies) | |
~Parser () override | |
const LangOptions & | getLangOpts () const |
const TargetInfo & | getTargetInfo () const |
Preprocessor & | getPreprocessor () const |
Sema & | getActions () const |
AttributeFactory & | getAttrFactory () |
const Token & | getCurToken () const |
Scope * | getCurScope () const |
void | incrementMSManglingNumber () const |
ObjCContainerDecl * | getObjCDeclContext () const |
void | Initialize () |
Initialize - Warm up the parser. | |
bool | ParseFirstTopLevelDecl (DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState) |
Parse the first top-level declaration in a translation unit. | |
bool | ParseTopLevelDecl (DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState) |
ParseTopLevelDecl - Parse one top-level declaration. | |
bool | ParseTopLevelDecl () |
SourceLocation | ConsumeToken () |
ConsumeToken - Consume the current 'peek token' and lex the next one. | |
bool | TryConsumeToken (tok::TokenKind Expected) |
bool | TryConsumeToken (tok::TokenKind Expected, SourceLocation &Loc) |
SourceLocation | ConsumeAnyToken (bool ConsumeCodeCompletionTok=false) |
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type. | |
SourceLocation | getEndOfPreviousToken () |
IdentifierInfo * | getNullabilityKeyword (NullabilityKind nullability) |
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind. | |
const Token & | NextToken () |
NextToken - This peeks ahead one token and returns it without consuming it. | |
bool | TryAnnotateTypeOrScopeToken (ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No) |
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C++) or a C++ scope specifier not followed by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens with a single annotation token representing the typename or C++ scope respectively. | |
bool | TryAnnotateTypeOrScopeTokenAfterScopeSpec (CXXScopeSpec &SS, bool IsNewScope, ImplicitTypenameContext AllowImplicitTypename) |
Try to annotate a type or scope token, having already parsed an optional scope specifier. | |
bool | TryAnnotateCXXScopeToken (bool EnteringContext=false) |
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and template-ids. | |
bool | MightBeCXXScopeToken () |
bool | TryAnnotateOptionalCXXScopeToken (bool EnteringContext=false) |
void | EnterScope (unsigned ScopeFlags) |
EnterScope - Start a new scope. | |
void | ExitScope () |
ExitScope - Pop a scope off the scope stack. | |
unsigned | ReenterTemplateScopes (MultiParseScope &S, Decl *D) |
Re-enter the template scopes for a declaration that might be a template. | |
DiagnosticBuilder | Diag (SourceLocation Loc, unsigned DiagID) |
DiagnosticBuilder | Diag (const Token &Tok, unsigned DiagID) |
DiagnosticBuilder | Diag (unsigned DiagID) |
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 is specified). | |
bool | SkipUntil (tok::TokenKind T1, tok::TokenKind T2, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0)) |
bool | SkipUntil (tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0)) |
bool | SkipUntil (ArrayRef< tok::TokenKind > Toks, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0)) |
SkipUntil - Read tokens until we get to the specified token, then consume it (unless no flag StopBeforeMatch). | |
void | SkipMalformedDecl () |
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a simple-declaration. | |
ExprResult | ParseExpression (TypeCastState isTypeCast=NotTypeCast) |
Simple precedence-based parser for binary/ternary operators. | |
ExprResult | ParseConstantExpressionInExprEvalContext (TypeCastState isTypeCast=NotTypeCast) |
ExprResult | ParseConstantExpression () |
ExprResult | ParseArrayBoundExpression () |
ExprResult | ParseCaseExpression (SourceLocation CaseLoc) |
ExprResult | ParseConstraintExpression () |
Parse a constraint-expression. | |
ExprResult | ParseConstraintLogicalAndExpression (bool IsTrailingRequiresClause) |
Parse a constraint-logical-and-expression. | |
ExprResult | ParseConstraintLogicalOrExpression (bool IsTrailingRequiresClause) |
Parse a constraint-logical-or-expression. | |
ExprResult | ParseAssignmentExpression (TypeCastState isTypeCast=NotTypeCast) |
Parse an expr that doesn't include (top-level) commas. | |
ExprResult | ParseConditionalExpression () |
ExprResult | ParseMSAsmIdentifier (llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, bool IsUnevaluated) |
Parse an identifier in an MS-style inline assembly block. | |
ExprResult | ParseStringLiteralExpression (bool AllowUserDefinedLiteral=false) |
ExprResult | ParseUnevaluatedStringLiteralExpression () |
TypeResult | ParseTypeName (SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr) |
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt]. | |
ExprResult | ParseOpenMPParensExpr (StringRef ClauseName, SourceLocation &RLoc, bool IsAddressOfOperand=false) |
Parses simple expression in parens for single-expression clauses of OpenMP constructs. | |
bool | ParseOpenMPReservedLocator (OpenMPClauseKind Kind, SemaOpenMP::OpenMPVarListDataTy &Data, const LangOptions &LangOpts) |
Parses a reserved locator like 'omp_all_memory'. | |
bool | ParseOpenMPVarList (OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr * > &Vars, SemaOpenMP::OpenMPVarListDataTy &Data) |
Parses clauses with list. | |
bool | ParseUnqualifiedId (CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result) |
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity. | |
bool | parseMapperModifier (SemaOpenMP::OpenMPVarListDataTy &Data) |
Parses the mapper modifier in map, to, and from clauses. | |
bool | parseMapTypeModifiers (SemaOpenMP::OpenMPVarListDataTy &Data) |
Parses map-type-modifiers in map clause. | |
DeclGroupPtrTy | ParseOpenACCDirectiveDecl () |
Placeholder for now, should just ignore the directives after emitting a diagnostic. | |
StmtResult | ParseOpenACCDirectiveStmt () |
Public Member Functions inherited from clang::CodeCompletionHandler | |
virtual | ~CodeCompletionHandler () |
virtual void | CodeCompleteDirective (bool InConditional) |
Callback invoked when performing code completion for a preprocessor directive. | |
virtual void | CodeCompleteInConditionalExclusion () |
Callback invoked when performing code completion within a block of code that was excluded due to preprocessor conditionals. | |
virtual void | CodeCompleteMacroName (bool IsDefinition) |
Callback invoked when performing code completion in a context where the name of a macro is expected. | |
virtual void | CodeCompletePreprocessorExpression () |
Callback invoked when performing code completion in a preprocessor expression, such as the condition of an #if or #elif directive. | |
virtual void | CodeCompleteMacroArgument (IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned ArgumentIndex) |
Callback invoked when performing code completion inside a function-like macro argument. | |
virtual void | CodeCompleteIncludedFile (llvm::StringRef Dir, bool IsAngled) |
Callback invoked when performing code completion inside the filename part of an #include directive. | |
virtual void | CodeCompleteNaturalLanguage () |
Callback invoked when performing code completion in a part of the file where we expect natural language, e.g., a comment, string, or #error directive. | |
Static Public Member Functions | |
static TypeResult | getTypeAnnotation (const Token &Tok) |
getTypeAnnotation - Read a parsed type out of an annotation token. | |
Public Attributes | |
SourceLocation | MisleadingIndentationElseLoc |
The location of the first statement inside an else that might have a missleading indentation. | |
Friends | |
class | ColonProtectionRAIIObject |
class | ParsingOpenMPDirectiveRAII |
class | ParsingOpenACCDirectiveRAII |
class | InMessageExpressionRAIIObject |
class | OffsetOfStateRAIIObject |
class | PoisonSEHIdentifiersRAIIObject |
class | ObjCDeclContextSwitch |
class | ParenBraceBracketBalancer |
class | BalancedDelimiterTracker |
constexpr SkipUntilFlags | operator| (SkipUntilFlags L, SkipUntilFlags R) |
Parser - This implements a parser for the C family of languages.
After parsing units of the grammar, productions are invoked to handle whatever has been read.
typedef SmallVector<Stmt *, 32> clang::Parser::StmtVector |
Parser::Parser | ( | Preprocessor & | PP, |
Sema & | Actions, | ||
bool | SkipFunctionBodies | ||
) |
|
override |
Definition at line 470 of file Parser.cpp.
References clang::Preprocessor::clearCodeCompletionHandler(), getCurScope(), and clang::Preprocessor::removeCommentHandler().
|
inline |
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
This should only be used in cases where the type of the token really isn't known, e.g. in error recovery.
Definition at line 576 of file Parser.h.
References ConsumeToken(), clang::Token::is(), and clang::Token::isAnnotation().
Referenced by ParseMSAsmIdentifier(), SkipMalformedDecl(), and SkipUntil().
|
inline |
ConsumeToken - Consume the current 'peek token' and lex the next one.
This does not work with special tokens: string literals, code completion, annotation tokens and balanced tokens must be handled using the specific consume methods. Returns the location of the consumed token.
Definition at line 548 of file Parser.h.
References clang::Token::getLocation(), and clang::Preprocessor::Lex().
Referenced by ConsumeAnyToken(), Initialize(), clang::Parser::ConditionDeclarationOrInitStatementState::markNotExpression(), ParseConstraintLogicalAndExpression(), ParseConstraintLogicalOrExpression(), parseMapperModifier(), parseMapTypeModifiers(), ParseMSAsmIdentifier(), ParseOpenMPReservedLocator(), ParseOpenMPVarList(), ParseUnqualifiedId(), SkipMalformedDecl(), SkipUntil(), TryAnnotateTypeOrScopeToken(), and TryAnnotateTypeOrScopeTokenAfterScopeSpec().
DiagnosticBuilder Parser::Diag | ( | const Token & | Tok, |
unsigned | DiagID | ||
) |
Definition at line 85 of file Parser.cpp.
References Diag(), and clang::Token::getLocation().
DiagnosticBuilder Parser::Diag | ( | SourceLocation | Loc, |
unsigned | DiagID | ||
) |
Definition at line 81 of file Parser.cpp.
References Loc, and clang::DiagnosticsEngine::Report().
Referenced by Diag(), diagnoseExpectedAttributeSubjectSubRule(), diagnoseUnknownAttributeSubjectSubRule(), ParseConstraintLogicalAndExpression(), ParseFirstTopLevelDecl(), parseMapperModifier(), parseMapTypeModifiers(), ParseOpenMPReservedLocator(), ParseOpenMPVarList(), ParseUnqualifiedId(), and TryAnnotateTypeOrScopeToken().
|
inline |
void Parser::EnterScope | ( | unsigned | ScopeFlags | ) |
EnterScope - Start a new scope.
Definition at line 420 of file Parser.cpp.
References getCurScope(), and clang::Scope::Init().
Referenced by Initialize(), and ParseOpenMPVarList().
void Parser::ExitScope | ( | ) |
ExitScope - Pop a scope off the scope stack.
Definition at line 431 of file Parser.cpp.
References clang::Sema::ActOnPopScope(), getCurScope(), clang::Token::getLocation(), and clang::Scope::getParent().
Referenced by ParseOpenMPVarList().
|
inline |
Definition at line 498 of file Parser.h.
Referenced by ParseOpenACCDirectiveDecl(), and ParseOpenACCDirectiveStmt().
|
inline |
|
inline |
Definition at line 502 of file Parser.h.
References clang::Sema::getCurScope().
Referenced by EnterScope(), ExitScope(), Initialize(), ParseAssignmentExpression(), ParseConditionalExpression(), ParseConstraintLogicalAndExpression(), ParseConstraintLogicalOrExpression(), ParseUnqualifiedId(), clang::Parser::ReenterClassScopeRAII::ReenterClassScopeRAII(), TryAnnotateTypeOrScopeToken(), TryAnnotateTypeOrScopeTokenAfterScopeSpec(), ~Parser(), and clang::Parser::ReenterClassScopeRAII::~ReenterClassScopeRAII().
|
inline |
Definition at line 501 of file Parser.h.
Referenced by parseMapTypeModifiers(), and ParseOpenMPVarList().
|
inline |
Definition at line 594 of file Parser.h.
References clang::Preprocessor::getLocForEndOfToken().
|
inline |
Definition at line 495 of file Parser.h.
References clang::Preprocessor::getLangOpts().
Referenced by clang::BalancedDelimiterTracker::expectAndConsume(), Initialize(), MightBeCXXScopeToken(), ParseFirstTopLevelDecl(), parseMapperModifier(), parseMapTypeModifiers(), ParseMSAsmIdentifier(), ParseOpenMPVarList(), ParseTopLevelDecl(), ParseUnqualifiedId(), TryAnnotateCXXScopeToken(), TryAnnotateTypeOrScopeToken(), and TryAnnotateTypeOrScopeTokenAfterScopeSpec().
|
inline |
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind.
Definition at line 600 of file Parser.h.
References clang::Sema::getNullabilityKeyword().
|
inline |
Definition at line 507 of file Parser.h.
References clang::SemaObjC::getObjCDeclContext(), and clang::Sema::ObjC().
|
inline |
|
inline |
Definition at line 496 of file Parser.h.
References clang::Preprocessor::getTargetInfo().
|
inlinestatic |
getTypeAnnotation - Read a parsed type out of an annotation token.
Definition at line 877 of file Parser.h.
References clang::Token::getAnnotationValue(), clang::OpaquePtr< QualType >::getFromOpaquePtr(), and clang::TypeError().
|
inline |
Definition at line 503 of file Parser.h.
References clang::Sema::incrementMSManglingNumber().
void Parser::Initialize | ( | ) |
Initialize - Warm up the parser.
Definition at line 490 of file Parser.cpp.
References clang::Sema::ActOnTranslationUnitScope(), ConsumeToken(), clang::Scope::DeclScope, EnterScope(), clang::IdentifierTable::get(), getCurScope(), clang::Preprocessor::getIdentifierInfo(), clang::Preprocessor::getIdentifierTable(), getLangOpts(), clang::Sema::Initialize(), clang::ObjC, and clang::Preprocessor::SetPoisonReason().
|
inline |
Definition at line 929 of file Parser.h.
References getLangOpts(), clang::Token::is(), and NextToken().
Referenced by TryAnnotateCXXScopeToken(), and TryAnnotateOptionalCXXScopeToken().
|
inline |
NextToken - This peeks ahead one token and returns it without consuming it.
Definition at line 872 of file Parser.h.
References clang::Preprocessor::LookAhead().
Referenced by MightBeCXXScopeToken(), ParseConstraintLogicalAndExpression(), ParseOpenMPVarList(), ParseTopLevelDecl(), ParseUnqualifiedId(), SkipMalformedDecl(), TryAnnotateTypeOrScopeToken(), and TryAnnotateTypeOrScopeTokenAfterScopeSpec().
ExprResult Parser::ParseArrayBoundExpression | ( | ) |
Definition at line 245 of file ParseExpr.cpp.
References clang::Sema::ConstantEvaluated, clang::Sema::ExprEvalContexts, NotTypeCast, and ParseConstantExpressionInExprEvalContext().
ExprResult Parser::ParseAssignmentExpression | ( | TypeCastState | isTypeCast = NotTypeCast | ) |
Parse an expr that doesn't include (top-level) commas.
Definition at line 171 of file ParseExpr.cpp.
References clang::prec::Assignment, clang::SemaCodeCompletion::CodeCompleteExpression(), clang::Sema::CodeCompletion(), clang::ExprError(), clang::PreferredTypeBuilder::get(), getCurScope(), clang::Token::getLocation(), and clang::Token::is().
Referenced by ParseExpression(), and ParseOpenMPVarList().
ExprResult Parser::ParseCaseExpression | ( | SourceLocation | CaseLoc | ) |
Definition at line 254 of file ParseExpr.cpp.
References clang::Sema::ActOnCaseExpr(), clang::prec::Conditional, clang::Sema::ConstantEvaluated, and NotTypeCast.
ExprResult Parser::ParseConditionalExpression | ( | ) |
Definition at line 190 of file ParseExpr.cpp.
References clang::SemaCodeCompletion::CodeCompleteExpression(), clang::Sema::CodeCompletion(), clang::prec::Conditional, clang::ExprError(), clang::PreferredTypeBuilder::get(), getCurScope(), clang::Token::getLocation(), clang::Token::is(), and NotTypeCast.
ExprResult Parser::ParseConstantExpression | ( | ) |
Definition at line 235 of file ParseExpr.cpp.
References clang::Sema::ConstantEvaluated, NotTypeCast, and ParseConstantExpressionInExprEvalContext().
ExprResult Parser::ParseConstantExpressionInExprEvalContext | ( | TypeCastState | isTypeCast = NotTypeCast | ) |
Definition at line 225 of file ParseExpr.cpp.
References clang::Sema::ActOnConstantExpression(), clang::prec::Conditional, clang::Sema::ConstantEvaluated, and clang::Sema::ExprEvalContexts.
Referenced by ParseArrayBoundExpression(), and ParseConstantExpression().
ExprResult Parser::ParseConstraintExpression | ( | ) |
Parse a constraint-expression.
/// constraint-expression: C++2a[temp.constr.decl]p1 /// logical-or-expression ///
Definition at line 268 of file ParseExpr.cpp.
References clang::Sema::CheckConstraintExpression(), clang::Sema::CorrectDelayedTyposInExpr(), clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), clang::ActionResult< PtrTy, Compress >::isUsable(), clang::prec::LogicalOr, and clang::Sema::Unevaluated.
ExprResult Parser::ParseConstraintLogicalAndExpression | ( | bool | IsTrailingRequiresClause | ) |
Parse a constraint-logical-and-expression.
/// C++2a[temp.constr.decl]p1 /// constraint-logical-and-expression: /// primary-expression /// constraint-logical-and-expression '&&' primary-expression /// ///
Definition at line 290 of file ParseExpr.cpp.
References clang::Sema::ActOnBinOp(), clang::Sema::CheckConstraintExpression(), ConsumeToken(), clang::Sema::CorrectDelayedTyposInExpr(), clang::FixItHint::CreateInsertion(), Diag(), E, clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), clang::Stmt::getBeginLoc(), clang::getBinOpPrecedence(), getCurScope(), clang::Stmt::getEndLoc(), clang::Expr::getExprLoc(), clang::Token::getKind(), clang::Preprocessor::getLocForEndOfToken(), clang::Stmt::getSourceRange(), clang::prec::InclusiveOr, clang::Token::is(), clang::ActionResult< PtrTy, Compress >::isInvalid(), clang::Token::isOneOf(), clang::ActionResult< PtrTy, Compress >::isUsable(), clang::prec::LogicalAnd, NextToken(), clang::Note, NotTypeCast, and clang::Sema::Unevaluated.
Referenced by ParseConstraintLogicalOrExpression().
ExprResult Parser::ParseConstraintLogicalOrExpression | ( | bool | IsTrailingRequiresClause | ) |
Parse a constraint-logical-or-expression.
/// C++2a[temp.constr.decl]p1 /// constraint-logical-or-expression: /// constraint-logical-and-expression /// constraint-logical-or-expression '||' /// constraint-logical-and-expression /// ///
Definition at line 382 of file ParseExpr.cpp.
References clang::Sema::ActOnBinOp(), ConsumeToken(), clang::Sema::CorrectDelayedTyposInExpr(), clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), getCurScope(), clang::Token::is(), clang::ActionResult< PtrTy, Compress >::isUsable(), and ParseConstraintLogicalAndExpression().
ExprResult Parser::ParseExpression | ( | TypeCastState | isTypeCast = NotTypeCast | ) |
Simple precedence-based parser for binary/ternary operators.
Note: we diverge from the C99 grammar when parsing the assignment-expression production. C99 specifies that the LHS of an assignment operator should be parsed as a unary-expression, but consistency dictates that it be a conditional-expession. In practice, the important thing here is that the LHS of an assignment has to be an l-value, which productions between unary-expression and conditional-expression don't produce. Because we want consistency, we parse the LHS as a conditional-expression, then check for l-value-ness in semantic analysis stages.
/// pm-expression: [C++ 5.5] /// cast-expression /// pm-expression '.*' cast-expression /// pm-expression '->*' cast-expression /// /// multiplicative-expression: [C99 6.5.5] /// Note: in C++, apply pm-expression instead of cast-expression /// cast-expression /// multiplicative-expression '*' cast-expression /// multiplicative-expression '/' cast-expression /// multiplicative-expression '%' cast-expression /// /// additive-expression: [C99 6.5.6] /// multiplicative-expression /// additive-expression '+' multiplicative-expression /// additive-expression '-' multiplicative-expression /// /// shift-expression: [C99 6.5.7] /// additive-expression /// shift-expression '<<' additive-expression /// shift-expression '>>' additive-expression /// /// compare-expression: [C++20 expr.spaceship] /// shift-expression /// compare-expression '<=>' shift-expression /// /// relational-expression: [C99 6.5.8] /// compare-expression /// relational-expression '<' compare-expression /// relational-expression '>' compare-expression /// relational-expression '<=' compare-expression /// relational-expression '>=' compare-expression /// /// equality-expression: [C99 6.5.9] /// relational-expression /// equality-expression '==' relational-expression /// equality-expression '!=' relational-expression /// /// AND-expression: [C99 6.5.10] /// equality-expression /// AND-expression '&' equality-expression /// /// exclusive-OR-expression: [C99 6.5.11] /// AND-expression /// exclusive-OR-expression '^' AND-expression /// /// inclusive-OR-expression: [C99 6.5.12] /// exclusive-OR-expression /// inclusive-OR-expression '|' exclusive-OR-expression /// /// logical-AND-expression: [C99 6.5.13] /// inclusive-OR-expression /// logical-AND-expression '&&' inclusive-OR-expression /// /// logical-OR-expression: [C99 6.5.14] /// logical-AND-expression /// logical-OR-expression '||' logical-AND-expression /// /// conditional-expression: [C99 6.5.15] /// logical-OR-expression /// logical-OR-expression '?' expression ':' conditional-expression /// [GNU] logical-OR-expression '?' ':' conditional-expression /// [C++] the third operand is an assignment-expression /// /// assignment-expression: [C99 6.5.16] /// conditional-expression /// unary-expression assignment-operator assignment-expression /// [C++] throw-expression [C++ 15] /// /// assignment-operator: one of /// = *= /= %= += -= <<= >>= &= ^= |= /// /// expression: [C99 6.5.17] /// assignment-expression ...[opt] /// expression ',' assignment-expression ...[opt] ///
Definition at line 134 of file ParseExpr.cpp.
References clang::prec::Comma, and ParseAssignmentExpression().
bool Parser::ParseFirstTopLevelDecl | ( | DeclGroupPtrTy & | Result, |
Sema::ModuleImportState & | ImportState | ||
) |
Parse the first top-level declaration in a translation unit.
translation-unit: [C] external-declaration [C] translation-unit external-declaration [C++] top-level-declaration-seq[opt] [C++20] global-module-fragment[opt] module-declaration top-level-declaration-seq[opt] private-module-fragment[opt]
Note that in C, it is an error if there is no first declaration.
Definition at line 601 of file Parser.cpp.
References clang::Sema::ActOnStartOfTranslationUnit(), clang::CPlusPlus, Diag(), clang::Sema::FirstDecl, clang::Sema::getASTContext(), clang::ASTContext::getExternalSource(), getLangOpts(), ParseTopLevelDecl(), and clang::Result.
bool Parser::parseMapperModifier | ( | SemaOpenMP::OpenMPVarListDataTy & | Data | ) |
Parses the mapper modifier in map, to, and from clauses.
Parse the mapper modifier in map, to, and from clauses.
Definition at line 4204 of file ParseOpenMP.cpp.
References ConsumeToken(), clang::CPlusPlus, clang::Data, clang::ASTContext::DeclarationNames, Diag(), clang::Sema::getASTContext(), clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLocation(), clang::Token::isNot(), SkipUntil(), StopBeforeMatch, and clang::T.
Referenced by parseMapTypeModifiers(), and ParseOpenMPVarList().
bool Parser::parseMapTypeModifiers | ( | SemaOpenMP::OpenMPVarListDataTy & | Data | ) |
Parses map-type-modifiers in map clause.
Parse map-type-modifiers in map clause.
map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) where, map-type-modifier ::= always | close | mapper(mapper-identifier)
map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list) where, map-type-modifier ::= always | close | mapper(mapper-identifier) | present where, map-type ::= alloc | delete | from | release | to | tofrom
Definition at line 4239 of file ParseOpenMP.cpp.
References ConsumeToken(), clang::Data, Diag(), getCurToken(), clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLocation(), clang::IdentifierInfo::getName(), clang::Token::is(), isMapModifier(), isMapType(), clang::Token::isNot(), clang::Preprocessor::LookAhead(), clang::OMPC_MAP_unknown, and parseMapperModifier().
Referenced by ParseOpenMPVarList().
ExprResult Parser::ParseMSAsmIdentifier | ( | llvm::SmallVectorImpl< Token > & | LineToks, |
unsigned & | NumLineToksConsumed, | ||
bool | IsUnevaluated | ||
) |
Parse an identifier in an MS-style inline assembly block.
Definition at line 200 of file ParseStmtAsm.cpp.
References ConsumeAnyToken(), ConsumeToken(), clang::CPlusPlus, clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLocation(), Id, clang::Token::is(), clang::Token::isNot(), clang::Preprocessor::LookAhead(), clang::Sema::LookupInlineAsmIdentifier(), clang::Sema::LookupInlineAsmVarDeclField(), ParseUnqualifiedId(), clang::Result, clang::Token::setKind(), and clang::Token::startToken().
Parser::DeclGroupPtrTy Parser::ParseOpenACCDirectiveDecl | ( | ) |
Placeholder for now, should just ignore the directives after emitting a diagnostic.
Eventually will be split into a few functions to parse different situations.
Definition at line 1426 of file ParseOpenACC.cpp.
References getActions(), clang::Token::is(), and clang::OpaquePtr< PtrTy >::make().
StmtResult Parser::ParseOpenACCDirectiveStmt | ( | ) |
Definition at line 1442 of file ParseOpenACC.cpp.
References clang::SemaOpenACC::ActOnAssociatedStmt(), clang::SemaOpenACC::ActOnEndStmtDirective(), getActions(), clang::Token::is(), clang::Sema::OpenACC(), and clang::StmtError().
ExprResult Parser::ParseOpenMPParensExpr | ( | StringRef | ClauseName, |
SourceLocation & | RLoc, | ||
bool | IsAddressOfOperand = false |
||
) |
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
RLoc | Returned location of right paren. |
Definition at line 3478 of file ParseOpenMP.cpp.
References clang::Sema::ActOnFinishFullExpr(), clang::prec::Conditional, clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), clang::Token::getLocation(), NotTypeCast, and clang::T.
bool Parser::ParseOpenMPReservedLocator | ( | OpenMPClauseKind | Kind, |
SemaOpenMP::OpenMPVarListDataTy & | Data, | ||
const LangOptions & | LangOpts | ||
) |
Parses a reserved locator like 'omp_all_memory'.
Definition at line 4458 of file ParseOpenMP.cpp.
References ConsumeToken(), clang::Data, Diag(), clang::Token::getIdentifierInfo(), clang::Token::is(), and clang::IdentifierInfo::isStr().
Referenced by ParseOpenMPVarList().
bool Parser::ParseOpenMPVarList | ( | OpenMPDirectiveKind | DKind, |
OpenMPClauseKind | Kind, | ||
SmallVectorImpl< Expr * > & | Vars, | ||
SemaOpenMP::OpenMPVarListDataTy & | Data | ||
) |
Parses clauses with list.
Definition at line 4505 of file ParseOpenMP.cpp.
References clang::Sema::ActOnFinishFullExpr(), clang::BalancedDelimiterTracker::consumeClose(), clang::BalancedDelimiterTracker::consumeOpen(), ConsumeToken(), clang::Sema::CorrectDelayedTyposInExpr(), clang::CPlusPlus, clang::Data, clang::Scope::DeclScope, Diag(), EnterScope(), ExitScope(), clang::ActionResult< PtrTy, Compress >::get(), getCurToken(), clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLocation(), clang::Sema::GetNameFromUnqualifiedId(), clang::getOpenMPSimpleClauseType(), clang::Preprocessor::getSpelling(), clang::Token::is(), clang::Token::isAnnotation(), clang::Token::isNot(), clang::isOpenMPDistributeDirective(), clang::isOpenMPTaskLoopDirective(), clang::IdentifierInfo::isStr(), clang::ActionResult< PtrTy, Compress >::isUsable(), Loc, clang::Preprocessor::LookAhead(), NextToken(), clang::OMPC_ADJUST_ARGS_unknown, clang::OMPC_DEPEND_unknown, clang::OMPC_DOACROSS_unknown, clang::OMPC_LASTPRIVATE_unknown, clang::OMPC_MAP_unknown, clang::OMPC_MOTION_MODIFIER_unknown, clang::OMPC_REDUCTION_unknown, clang::Scope::OpenMPDirectiveScope, ParseAssignmentExpression(), parseMapperModifier(), parseMapType(), parseMapTypeModifiers(), ParseOpenMPReservedLocator(), ParseReductionId(), clang::Preprocessor::parseSimpleIntegerLiteral(), parseStepSize(), SkipUntil(), StopBeforeMatch, and clang::T.
ExprResult clang::Parser::ParseStringLiteralExpression | ( | bool | AllowUserDefinedLiteral = false | ) |
|
inline |
Definition at line 537 of file Parser.h.
References clang::Sema::NotACXX20Module, ParseTopLevelDecl(), and clang::Result.
Referenced by ParseFirstTopLevelDecl(), and ParseTopLevelDecl().
bool Parser::ParseTopLevelDecl | ( | DeclGroupPtrTy & | Result, |
Sema::ModuleImportState & | ImportState | ||
) |
ParseTopLevelDecl - Parse one top-level declaration.
ParseTopLevelDecl - Parse one top-level declaration, return whatever the action tells us to.
Returns true if the EOF was encountered.
This returns true if the EOF was encountered.
top-level-declaration: declaration [C++20] module-import-declaration
Definition at line 628 of file Parser.cpp.
References clang::Sema::ActOnAnnotModuleBegin(), clang::Sema::ActOnAnnotModuleEnd(), clang::Sema::ActOnAnnotModuleInclude(), clang::Sema::ActOnEndOfTranslationUnit(), clang::Sema::ActOnModuleImport(), clang::Sema::ConvertDeclToDeclGroup(), clang::Preprocessor::Diag(), clang::Sema::FirstDecl, clang::Token::getAnnotationValue(), clang::Token::getIdentifierInfo(), clang::Token::getKind(), getKind(), getLangOpts(), clang::Token::getLocation(), clang::Preprocessor::getMaxTokens(), clang::Preprocessor::getMaxTokensOverrideLoc(), clang::Preprocessor::getTokenCount(), clang::Sema::ImportAllowed, clang::Sema::ImportFinished, clang::Module::isHeaderUnit(), clang::SourceLocation::isValid(), Loc, NextToken(), clang::Sema::NotACXX20Module, clang::Sema::PrivateFragmentImportAllowed, clang::Sema::PrivateFragmentImportFinished, clang::Result, and clang::Sema::SetLateTemplateParser().
TypeResult Parser::ParseTypeName | ( | SourceRange * | Range = nullptr , |
DeclaratorContext | Context = DeclaratorContext::TypeName , |
||
AccessSpecifier | AS = AS_none , |
||
Decl ** | OwnedType = nullptr , |
||
ParsedAttributes * | Attrs = nullptr |
||
) |
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Called type-id in C++.
Definition at line 50 of file ParseDecl.cpp.
References clang::Sema::ActOnTypeName(), clang::DeclSpec::addAttributes(), clang::DeclSpec::getAttributes(), clang::DeclSpec::getRepAsDecl(), clang::Declarator::getSourceRange(), clang::Declarator::isInvalidType(), clang::DeclSpec::isTypeSpecOwned(), clang::ParsedAttributesView::none(), Range, and clang::ParsedAttributes::takeOneFrom().
ExprResult clang::Parser::ParseUnevaluatedStringLiteralExpression | ( | ) |
bool Parser::ParseUnqualifiedId | ( | CXXScopeSpec & | SS, |
ParsedType | ObjectType, | ||
bool | ObjectHadErrors, | ||
bool | EnteringContext, | ||
bool | AllowDestructorName, | ||
bool | AllowConstructorName, | ||
bool | AllowDeductionGuide, | ||
SourceLocation * | TemplateKWLoc, | ||
UnqualifiedId & | Result | ||
) |
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
SS | The nested-name-specifier that preceded this unqualified-id. If non-empty, then we are parsing the unqualified-id of a qualified-id. |
ObjectType | if this unqualified-id occurs within a member access expression, the type of the base object whose member is being accessed. |
ObjectHadErrors | if this unqualified-id occurs within a member access expression, indicates whether the original subexpressions had any errors. When true, diagnostics for missing 'template' keyword will be supressed. |
EnteringContext | whether we are entering the scope of the nested-name-specifier. |
AllowDestructorName | whether we allow parsing of a destructor name. |
AllowConstructorName | whether we allow parsing a constructor name. |
AllowDeductionGuide | whether we allow parsing a deduction guide name. |
Result | on a successful parse, contains the parsed unqualified-id. |
Definition at line 2970 of file ParseExprCXX.cpp.
References clang::Sema::ActOnTemplateName(), clang::CXXScopeSpec::clear(), ConsumeToken(), clang::CPlusPlus, clang::CPlusPlus17, clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateRemoval(), Diag(), clang::Sema::getConstructorName(), getCurScope(), clang::Sema::getDestructorName(), clang::Sema::getDestructorTypeForDecltype(), clang::Token::getIdentifierInfo(), clang::Token::getKind(), getLangOpts(), clang::Token::getLocation(), clang::IdentifierInfo::getName(), Id, clang::IK_LiteralOperatorId, clang::IK_OperatorFunctionId, clang::Token::is(), clang::Sema::isCurrentClassName(), clang::Sema::isDeductionGuideName(), clang::CXXScopeSpec::isEmpty(), clang::TemplateIdAnnotation::isInvalid(), clang::Token::isNot(), clang::CXXScopeSpec::isNotEmpty(), clang::CXXScopeSpec::isSet(), clang::SourceLocation::isValid(), clang::TemplateIdAnnotation::LAngleLoc, clang::TemplateIdAnnotation::Name, NextToken(), clang::TemplateIdAnnotation::RAngleLoc, clang::Result, clang::Token::setKind(), clang::Sema::ShouldEnterDeclaratorScope(), clang::TemplateIdAnnotation::TemplateKWLoc, clang::TemplateIdAnnotation::TemplateNameLoc, clang::TNK_Dependent_template_name, clang::TNK_Function_template, clang::TNK_Non_template, and clang::TNK_Var_template.
Referenced by ParseMSAsmIdentifier().
unsigned Parser::ReenterTemplateScopes | ( | MultiParseScope & | S, |
Decl * | D | ||
) |
Re-enter the template scopes for a declaration that might be a template.
Re-enter a possible template scope, creating as many template parameter scopes as necessary.
Definition at line 30 of file ParseTemplate.cpp.
References clang::Sema::ActOnReenterTemplateScope(), D, clang::Sema::getCurScope(), and clang::Scope::TemplateParamScope.
Referenced by clang::Parser::ReenterTemplateScopeRAII::ReenterTemplateScopeRAII().
void Parser::SkipMalformedDecl | ( | ) |
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a simple-declaration.
Skip until we reach something which seems like a sensible place to pick up parsing after a malformed declaration.
This will sometimes stop sooner than SkipUntil(tok::r_brace) would, but will never stop later.
Definition at line 2214 of file ParseDecl.cpp.
References ConsumeAnyToken(), ConsumeToken(), clang::Token::getKind(), clang::Token::isAtStartOfLine(), clang::Token::isOneOf(), NextToken(), SkipUntil(), and TryConsumeToken().
bool Parser::SkipUntil | ( | ArrayRef< tok::TokenKind > | Toks, |
SkipUntilFlags | Flags = static_cast<SkipUntilFlags>(0) |
||
) |
SkipUntil - Read tokens until we get to the specified token, then consume it (unless no flag StopBeforeMatch).
Because we cannot guarantee that the token will ever occur, this skips to the next token, or to some likely good stopping point. If StopAtSemi is true, skipping will stop at a ';' character.
If SkipUntil finds the specified token, it returns true, otherwise it returns false.
Definition at line 286 of file Parser.cpp.
References ConsumeAnyToken(), ConsumeToken(), clang::Token::getKind(), HasFlagsSet(), clang::Token::is(), clang::Token::isNot(), SkipUntil(), StopAtCodeCompletion, StopAtSemi, and StopBeforeMatch.
|
inline |
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch is specified).
Because we cannot guarantee that the token will ever occur, this skips to the next token, or to some likely good stopping point. If Flags has StopAtSemi flag, skipping will stop at a ';' character. Balances (), [], and {} delimiter tokens while skipping.
If SkipUntil finds the specified token, it returns true, otherwise it returns false.
Definition at line 1294 of file Parser.h.
References SkipUntil(), and clang::T.
Referenced by clang::BalancedDelimiterTracker::expectAndConsume(), clang::Parser::ConditionDeclarationOrInitStatementState::markNotExpression(), parseMapperModifier(), ParseOpenMPVarList(), SkipMalformedDecl(), clang::BalancedDelimiterTracker::skipToEnd(), and SkipUntil().
|
inline |
Definition at line 1298 of file Parser.h.
References SkipUntil().
|
inline |
Definition at line 1303 of file Parser.h.
References SkipUntil().
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and template-ids.
This returns true if there was an error that could not be recovered from.
Note that this routine emits an error if you call it with ::new or ::delete as the current tokens, so only call it in contexts where these are invalid.
Definition at line 2239 of file Parser.cpp.
References clang::CPlusPlus, getLangOpts(), clang::CXXScopeSpec::isEmpty(), and MightBeCXXScopeToken().
Referenced by TryAnnotateOptionalCXXScopeToken().
Definition at line 936 of file Parser.h.
References MightBeCXXScopeToken(), and TryAnnotateCXXScopeToken().
bool Parser::TryAnnotateTypeOrScopeToken | ( | ImplicitTypenameContext | AllowImplicitTypename = ImplicitTypenameContext::No | ) |
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C++) or a C++ scope specifier not followed by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens with a single annotation token representing the typename or C++ scope respectively.
This simplifies handling of C++ scope specifiers and allows efficient backtracking without the need to re-parse and resolve nested-names and typenames. It will mainly be called when we expect to treat identifiers as typenames (if they are typenames). For example, in C we do not expect identifiers inside expressions to be treated as typenames so it will not be called for expressions in C. The benefit for C/ObjC is that a typename will be annotated and Actions.getTypeName will not be needed to be called again (e.g. getTypeName will not be called twice, once to check whether we have a declaration specifier, and another one to get the actual type inside ParseDeclarationSpecifiers).
This returns true if an error occurred.
Note that this routine emits an error if you call it with ::new or ::delete as the current tokens, so only call it in contexts where these are invalid.
Definition at line 1995 of file Parser.cpp.
References clang::Sema::ActOnTypenameType(), clang::Preprocessor::AnnotateCachedTokens(), ConsumeToken(), clang::CPlusPlus, Diag(), clang::Preprocessor::EnterToken(), clang::Token::getAnnotationRange(), getCurScope(), clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLastLoc(), clang::Token::getLocation(), clang::CXXScopeSpec::getRange(), clang::TemplateIdAnnotation::getTemplateArgs(), clang::Token::is(), clang::Token::isAnnotation(), clang::Token::isEditorPlaceholder(), clang::CXXScopeSpec::isEmpty(), clang::TemplateIdAnnotation::isInvalid(), clang::TemplateIdAnnotation::LAngleLoc, clang::Preprocessor::Lex(), clang::TemplateIdAnnotation::mightBeType(), clang::TemplateIdAnnotation::Name, NextToken(), clang::TemplateIdAnnotation::NumArgs, clang::TemplateIdAnnotation::RAngleLoc, clang::Result, clang::Token::setAnnotationEndLoc(), clang::Token::setKind(), clang::Token::setLocation(), clang::TemplateIdAnnotation::Template, clang::TemplateIdAnnotation::TemplateKWLoc, clang::TemplateIdAnnotation::TemplateNameLoc, TryAnnotateTypeOrScopeToken(), TryAnnotateTypeOrScopeTokenAfterScopeSpec(), and clang::TypeError().
Referenced by TryAnnotateTypeOrScopeToken().
bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec | ( | CXXScopeSpec & | SS, |
bool | IsNewScope, | ||
ImplicitTypenameContext | AllowImplicitTypename | ||
) |
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.
An Objective-C object type followed by '<' is a specialization of a parameterized class type or a protocol-qualified type.
Definition at line 2124 of file Parser.cpp.
References clang::Preprocessor::AnnotateCachedTokens(), ConsumeToken(), clang::CPlusPlus, clang::OpaquePtr< PtrTy >::get(), clang::ActionResult< PtrTy, Compress >::get(), clang::CXXScopeSpec::getBeginLoc(), getCurScope(), clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLocation(), clang::Sema::getTypeName(), clang::Token::is(), clang::CXXScopeSpec::isEmpty(), clang::CXXScopeSpec::isNotEmpty(), clang::Type::isObjCObjectPointerType(), clang::Type::isObjCObjectType(), clang::Sema::isTemplateName(), clang::ActionResult< PtrTy, Compress >::isUsable(), clang::TemplateIdAnnotation::Kind, NextToken(), clang::ObjC, clang::Token::setAnnotationEndLoc(), clang::Token::setKind(), clang::Token::setLocation(), clang::TNK_Type_template, and clang::TNK_Undeclared_template.
Referenced by TryAnnotateTypeOrScopeToken().
|
inline |
Definition at line 556 of file Parser.h.
References clang::Token::getLocation(), clang::Token::isNot(), and clang::Preprocessor::Lex().
Referenced by SkipMalformedDecl(), and TryConsumeToken().
|
inline |
Definition at line 566 of file Parser.h.
References Loc, and TryConsumeToken().
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
SourceLocation clang::Parser::MisleadingIndentationElseLoc |