clang 22.0.0git
clang::Parser Class Reference

Parser - This implements a parser for the C family of languages. More...

#include "clang/Parse/Parser.h"

Inheritance diagram for clang::Parser:
[legend]

Classes

struct  ConditionDeclarationOrInitStatementState
class  MultiParseScope
 Introduces zero or more scopes for parsing. More...
class  ObjCTypeParamListScope
class  ParseScope
 ParseScope - Introduces a new scope for parsing. More...
struct  ReenterClassScopeRAII
struct  ReenterTemplateScopeRAII

Parsing

Implementations are in Parser.cpp

enum  SkipUntilFlags { StopAtSemi = 1 << 0 , StopBeforeMatch = 1 << 1 , StopAtCodeCompletion = 1 << 2 }
 Control flags for SkipUntil functions. More...
typedef OpaquePtr< DeclGroupRefDeclGroupPtrTy
typedef OpaquePtr< TemplateNameTemplateTy
class ColonProtectionRAIIObject
class PoisonSEHIdentifiersRAIIObject
class ParenBraceBracketBalancer
class BalancedDelimiterTracker
constexpr SkipUntilFlags operator| (SkipUntilFlags L, SkipUntilFlags R)
 Parser (Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies)
 ~Parser () override
const LangOptionsgetLangOpts () const
const TargetInfogetTargetInfo () const
PreprocessorgetPreprocessor () const
SemagetActions () const
AttributeFactorygetAttrFactory ()
const TokengetCurToken () const
ScopegetCurScope () const
void incrementMSManglingNumber () 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, return whatever the action tells us to.
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 () const
const TokenGetLookAheadToken (unsigned N)
 GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
const TokenNextToken ()
 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.
DiagnosticBuilder Diag (SourceLocation Loc, unsigned DiagID)
DiagnosticBuilder Diag (const Token &Tok, unsigned DiagID)
DiagnosticBuilder Diag (unsigned DiagID)
DiagnosticBuilder DiagCompat (SourceLocation Loc, unsigned CompatDiagId)
DiagnosticBuilder DiagCompat (const Token &Tok, unsigned CompatDiagId)
DiagnosticBuilder DiagCompat (unsigned CompatDiagId)
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).
static TypeResult getTypeAnnotation (const Token &Tok)
 getTypeAnnotation - Read a parsed type out of an annotation token.

Expressions

Implementations are in ParseExpr.cpp

typedef Sema::FullExprArg FullExprArg
class OffsetOfStateRAIIObject
ExprResult ParseExpression (TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
 Simple precedence-based parser for binary/ternary operators.
ExprResult ParseConstantExpressionInExprEvalContext (TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
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 (TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
 Parse an expr that doesn't include (top-level) commas.
ExprResult ParseConditionalExpression ()
ExprResult ParseStringLiteralExpression (bool AllowUserDefinedLiteral=false)
 ParseStringLiteralExpression - This handles the various token types that form string literals, and also handles string concatenation [C99 5.1.1.2, translation phase #6].
ExprResult ParseUnevaluatedStringLiteralExpression ()

Statements

Implementations are in ParseStmt.cpp

typedef SmallVector< Stmt *, 24 > StmtVector
 A SmallVector of statements.
SourceLocation MisleadingIndentationElseLoc
 The location of the first statement inside an else that might have a missleading indentation.

C++ Templates

Implementations are in ParseTemplate.cpp

typedef SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
unsigned ReenterTemplateScopes (MultiParseScope &S, Decl *D)
 Re-enter a possible template scope, creating as many template parameter scopes as necessary.

Declarations

Implementations are in ParseDecl.cpp

void SkipMalformedDecl ()
 SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a simple-declaration.
TypeResult ParseTypeName (SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
 ParseTypeName.

C++ Expressions

Implementations are in ParseExprCXX.cpp

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.

OpenACC Constructs

Implementations are in ParseOpenACC.cpp

class ParsingOpenACCDirectiveRAII
DeclGroupPtrTy ParseOpenACCDirectiveDecl (AccessSpecifier &AS, ParsedAttributes &Attrs, DeclSpec::TST TagType, Decl *TagDecl)
 Parse OpenACC directive on a declaration.
StmtResult ParseOpenACCDirectiveStmt ()

Objective-C Constructs

Implementations are in ParseObjc.cpp

class InMessageExpressionRAIIObject
class ObjCDeclContextSwitch
ObjCContainerDeclgetObjCDeclContext () const
IdentifierInfogetNullabilityKeyword (NullabilityKind nullability)
 Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind.

OpenMP Constructs

Implementations are in ParseOpenMP.cpp

class ParsingOpenMPDirectiveRAII
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 parseMapperModifier (SemaOpenMP::OpenMPVarListDataTy &Data)
 Parses the mapper modifier in map, to, and from clauses.
bool parseMapTypeModifiers (SemaOpenMP::OpenMPVarListDataTy &Data)
 Parse map-type-modifiers in map clause.
bool ParseOpenMPDeclareBeginVariantDirective (SourceLocation Loc)
 Parses 'omp begin declare variant' directive.

<tt>inline asm</tt> Statement

Implementations are in ParseStmtAsm.cpp

ExprResult ParseMSAsmIdentifier (llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, bool IsUnevaluated)
 Parse an identifier in an MS-style inline assembly block.

Additional Inherited Members

Public Member Functions inherited from clang::CodeCompletionHandler
virtual ~CodeCompletionHandler ()

Detailed Description

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.

Definition at line 171 of file Parser.h.

Member Typedef Documentation

◆ DeclGroupPtrTy

Definition at line 219 of file Parser.h.

◆ FullExprArg

Definition at line 3632 of file Parser.h.

◆ StmtVector

A SmallVector of statements.

Definition at line 7185 of file Parser.h.

◆ TemplateParameterLists

◆ TemplateTy

Definition at line 220 of file Parser.h.

Member Enumeration Documentation

◆ SkipUntilFlags

Control flags for SkipUntil functions.

Enumerator
StopAtSemi 

Stop skipping at semicolon.

StopBeforeMatch 

Stop skipping at specified token, but don't skip the token itself.

StopAtCodeCompletion 

Stop at code completion.

Definition at line 473 of file Parser.h.

Constructor & Destructor Documentation

◆ Parser()

◆ ~Parser()

Parser::~Parser ( )
override

Definition at line 465 of file Parser.cpp.

References getCurScope().

Member Function Documentation

◆ ConsumeAnyToken()

SourceLocation clang::Parser::ConsumeAnyToken ( bool ConsumeCodeCompletionTok = false)
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 290 of file Parser.h.

References ConsumeToken().

Referenced by parseContextScore(), ParseMSAsmIdentifier(), ParseOpenMPDeclareBeginVariantDirective(), parseOpenMPSimpleClause(), SkipMalformedDecl(), and SkipUntil().

◆ ConsumeToken()

SourceLocation clang::Parser::ConsumeToken ( )
inline

◆ Diag() [1/3]

DiagnosticBuilder Parser::Diag ( const Token & Tok,
unsigned DiagID )

Definition at line 89 of file Parser.cpp.

References Diag().

◆ Diag() [2/3]

◆ Diag() [3/3]

DiagnosticBuilder clang::Parser::Diag ( unsigned DiagID)
inline

Definition at line 464 of file Parser.h.

References Diag().

Referenced by Diag().

◆ DiagCompat() [1/3]

DiagnosticBuilder Parser::DiagCompat ( const Token & Tok,
unsigned CompatDiagId )

Definition at line 99 of file Parser.cpp.

References DiagCompat().

◆ DiagCompat() [2/3]

DiagnosticBuilder Parser::DiagCompat ( SourceLocation Loc,
unsigned CompatDiagId )

Definition at line 93 of file Parser.cpp.

References Diag(), clang::DiagnosticIDs::getCXXCompatDiagId(), and getLangOpts().

Referenced by DiagCompat(), and DiagCompat().

◆ DiagCompat() [3/3]

DiagnosticBuilder clang::Parser::DiagCompat ( unsigned CompatDiagId)
inline

Definition at line 468 of file Parser.h.

References DiagCompat().

◆ EnterScope()

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().

◆ ExitScope()

void Parser::ExitScope ( )

ExitScope - Pop a scope off the scope stack.

Definition at line 430 of file Parser.cpp.

References getCurScope(), and clang::Scope::getParent().

Referenced by ParseOpenMPVarList().

◆ getActions()

◆ getAttrFactory()

AttributeFactory & clang::Parser::getAttrFactory ( )
inline

Definition at line 208 of file Parser.h.

◆ getCurScope()

◆ getCurToken()

◆ getEndOfPreviousToken()

SourceLocation Parser::getEndOfPreviousToken ( ) const

Definition at line 1878 of file Parser.cpp.

References clang::SourceLocation::isValid().

◆ getLangOpts()

◆ GetLookAheadToken()

const Token & clang::Parser::GetLookAheadToken ( unsigned N)
inline

GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.

LookAhead(0) returns 'Tok', LookAhead(1) returns the token after Tok, etc.

Note that this differs from the Preprocessor's LookAhead method, because the Parser always has one token lexed that the preprocessor doesn't.

Definition at line 316 of file Parser.h.

Referenced by ParseTopLevelDecl().

◆ getNullabilityKeyword()

IdentifierInfo * clang::Parser::getNullabilityKeyword ( NullabilityKind nullability)
inline

Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind.

Definition at line 5338 of file Parser.h.

Referenced by addContextSensitiveTypeNullability().

◆ getObjCDeclContext()

ObjCContainerDecl * clang::Parser::getObjCDeclContext ( ) const
inline

Definition at line 5332 of file Parser.h.

◆ getPreprocessor()

Preprocessor & clang::Parser::getPreprocessor ( ) const
inline

◆ getTargetInfo()

const TargetInfo & clang::Parser::getTargetInfo ( ) const
inline

Definition at line 205 of file Parser.h.

◆ getTypeAnnotation()

TypeResult clang::Parser::getTypeAnnotation ( const Token & Tok)
inlinestatic

getTypeAnnotation - Read a parsed type out of an annotation token.

Definition at line 327 of file Parser.h.

References clang::OpaquePtr< QualType >::getFromOpaquePtr(), and clang::TypeError().

◆ incrementMSManglingNumber()

void clang::Parser::incrementMSManglingNumber ( ) const
inline

Definition at line 213 of file Parser.h.

◆ Initialize()

◆ MightBeCXXScopeToken()

bool clang::Parser::MightBeCXXScopeToken ( )
inline

Definition at line 376 of file Parser.h.

References getLangOpts(), is(), and NextToken().

Referenced by TryAnnotateCXXScopeToken(), and TryAnnotateOptionalCXXScopeToken().

◆ NextToken()

const Token & clang::Parser::NextToken ( )
inline

◆ ParseArrayBoundExpression()

ExprResult Parser::ParseArrayBoundExpression ( )

◆ ParseAssignmentExpression()

ExprResult Parser::ParseAssignmentExpression ( TypoCorrectionTypeBehavior CorrectionBehavior = TypoCorrectionTypeBehavior::AllowNonTypes)

Parse an expr that doesn't include (top-level) commas.

Definition at line 75 of file ParseExpr.cpp.

References clang::AnyCastExpr, clang::prec::Assignment, clang::ExprError(), and getCurScope().

Referenced by ParseExpression(), parseOpenMPAllocateClauseModifiers(), ParseOpenMPVarList(), and parseStepSize().

◆ ParseCaseExpression()

ExprResult Parser::ParseCaseExpression ( SourceLocation CaseLoc)

◆ ParseConditionalExpression()

ExprResult Parser::ParseConditionalExpression ( )

◆ ParseConstantExpression()

ExprResult Parser::ParseConstantExpression ( )

◆ ParseConstantExpressionInExprEvalContext()

ExprResult Parser::ParseConstantExpressionInExprEvalContext ( TypoCorrectionTypeBehavior CorrectionBehavior = TypoCorrectionTypeBehavior::AllowNonTypes)

◆ ParseConstraintExpression()

ExprResult Parser::ParseConstraintExpression ( )

Parse a constraint-expression.

///       constraint-expression: C++2a[temp.constr.decl]p1
///         logical-or-expression
/// 

Definition at line 185 of file ParseExpr.cpp.

References clang::AnyCastExpr, clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), clang::ActionResult< PtrTy, Compress >::isUsable(), clang::prec::LogicalOr, and clang::Sema::Unevaluated.

◆ ParseConstraintLogicalAndExpression()

ExprResult Parser::ParseConstraintLogicalAndExpression ( bool IsTrailingRequiresClause)

◆ 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 274 of file ParseExpr.cpp.

References ConsumeToken(), clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), getCurScope(), clang::ActionResult< PtrTy, Compress >::isUsable(), and ParseConstraintLogicalAndExpression().

◆ ParseExpression()

ExprResult Parser::ParseExpression ( TypoCorrectionTypeBehavior CorrectionBehavior = TypoCorrectionTypeBehavior::AllowNonTypes)

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 47 of file ParseExpr.cpp.

References clang::prec::Comma, and ParseAssignmentExpression().

◆ ParseFirstTopLevelDecl()

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 594 of file Parser.cpp.

References clang::CPlusPlus, Diag(), clang::Sema::FirstDecl, getLangOpts(), ParseTopLevelDecl(), and clang::Result.

Referenced by clang::ParseAST().

◆ parseMapperModifier()

bool Parser::parseMapperModifier ( SemaOpenMP::OpenMPVarListDataTy & Data)

Parses the mapper modifier in map, to, and from clauses.

Definition at line 4040 of file ParseOpenMP.cpp.

References BalancedDelimiterTracker, ConsumeToken(), clang::CPlusPlus, clang::Data, Diag(), getLangOpts(), SkipUntil(), StopBeforeMatch, and clang::T.

Referenced by parseMapTypeModifiers(), and ParseOpenMPVarList().

◆ parseMapTypeModifiers()

bool Parser::parseMapTypeModifiers ( SemaOpenMP::OpenMPVarListDataTy & Data)

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) | present where, map-type ::= alloc | delete | from | release | to | tofrom

Definition at line 4070 of file ParseOpenMP.cpp.

References ConsumeToken(), clang::Data, Diag(), getCurToken(), getLangOpts(), is(), isMapModifier(), isMapType(), isNot(), clang::OMPC_MAP_unknown, and parseMapperModifier().

Referenced by ParseOpenMPVarList().

◆ ParseMSAsmIdentifier()

ExprResult Parser::ParseMSAsmIdentifier ( llvm::SmallVectorImpl< Token > & LineToks,
unsigned & NumLineToksConsumed,
bool IsUnevaluated )

◆ ParseOpenACCDirectiveDecl()

Parser::DeclGroupPtrTy Parser::ParseOpenACCDirectiveDecl ( AccessSpecifier & AS,
ParsedAttributes & Attrs,
DeclSpec::TST TagType,
Decl * TagDecl )

Parse OpenACC directive on a declaration.

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 1646 of file ParseOpenACC.cpp.

References getActions(), clang::OpaquePtr< DeclGroupRef >::make(), ParsingOpenACCDirectiveRAII, and clang::Routine.

◆ ParseOpenACCDirectiveStmt()

◆ ParseOpenMPDeclareBeginVariantDirective()

bool Parser::ParseOpenMPDeclareBeginVariantDirective ( SourceLocation Loc)

Parses 'omp begin declare variant' directive.

The syntax is:

/// { #pragma omp begin declare variant clause }
/// <function-declaration-or-definition-sequence>
/// { #pragma omp end declare variant }
/// 

Definition at line 545 of file ParseOpenMP.cpp.

References ConsumeAnyToken(), Diag(), std::function, clang::OMPTraitInfo::getAsVariantMatchInfo(), clang::ASTContext::getNewOMPTraitInfo(), parseOpenMPDirectiveKind(), ParsingOpenMPDirectiveRAII, SkipUntil(), and StopBeforeMatch.

◆ ParseOpenMPParensExpr()

ExprResult Parser::ParseOpenMPParensExpr ( StringRef ClauseName,
SourceLocation & RLoc,
bool IsAddressOfOperand = false )

Parses simple expression in parens for single-expression clauses of OpenMP constructs.

Parameters
RLocReturned location of right paren.

Definition at line 3378 of file ParseOpenMP.cpp.

References clang::AllowNonTypes, clang::AnyCastExpr, BalancedDelimiterTracker, clang::prec::Conditional, clang::ExprError(), clang::ActionResult< PtrTy, Compress >::get(), and clang::T.

Referenced by parseContextScore(), parseDeclareSimdClauses(), and parseOpenMPAllocateClauseModifiers().

◆ ParseOpenMPReservedLocator()

bool Parser::ParseOpenMPReservedLocator ( OpenMPClauseKind Kind,
SemaOpenMP::OpenMPVarListDataTy & Data,
const LangOptions & LangOpts )

Parses a reserved locator like 'omp_all_memory'.

Definition at line 4299 of file ParseOpenMP.cpp.

References ConsumeToken(), clang::Data, and Diag().

Referenced by ParseOpenMPVarList().

◆ ParseOpenMPVarList()

◆ ParseStringLiteralExpression()

ExprResult Parser::ParseStringLiteralExpression ( bool AllowUserDefinedLiteral = false)

ParseStringLiteralExpression - This handles the various token types that form string literals, and also handles string concatenation [C99 5.1.1.2, translation phase #6].

///       primary-expression: [C99 6.5.1]
///         string-literal
/// 

Definition at line 2964 of file ParseExpr.cpp.

References ParseStringLiteralExpression().

Referenced by ParseStringLiteralExpression(), and ParseUnevaluatedStringLiteralExpression().

◆ ParseTopLevelDecl() [1/2]

bool clang::Parser::ParseTopLevelDecl ( )
inline

◆ ParseTopLevelDecl() [2/2]

bool Parser::ParseTopLevelDecl ( DeclGroupPtrTy & Result,
Sema::ModuleImportState & ImportState )

ParseTopLevelDecl - Parse one top-level declaration, return whatever the action tells us to.

This returns true if the EOF was encountered.

///   top-level-declaration:
///           declaration
/// [C++20]   module-import-declaration
/// 

Definition at line 615 of file Parser.cpp.

References clang::Sema::FirstDecl, clang::Token::getIdentifierInfo(), getKind(), getLangOpts(), GetLookAheadToken(), clang::Sema::ImportAllowed, clang::Sema::ImportFinished, clang::Module::isHeaderUnit(), isNot(), clang::SourceLocation::isValid(), NextToken(), clang::Sema::NotACXX20Module, clang::nullptr, clang::Sema::PrivateFragmentImportAllowed, clang::Sema::PrivateFragmentImportFinished, and clang::Result.

Referenced by clang::ParseAST().

◆ ParseTypeName()

TypeResult Parser::ParseTypeName ( SourceRange * Range = nullptr,
DeclaratorContext Context = DeclaratorContext::TypeName,
AccessSpecifier AS = AS_none,
Decl ** OwnedType = nullptr,
ParsedAttributes * Attrs = nullptr )

◆ ParseUnevaluatedStringLiteralExpression()

ExprResult Parser::ParseUnevaluatedStringLiteralExpression ( )

Definition at line 2969 of file ParseExpr.cpp.

References ParseStringLiteralExpression().

◆ ParseUnqualifiedId()

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.

///       unqualified-id: [C++ expr.prim.general]
///         identifier
///         operator-function-id
///         conversion-function-id
/// [C++0x] literal-operator-id [TODO]
///         ~ class-name
///         template-id
/// 
Parameters
SSThe nested-name-specifier that preceded this unqualified-id. If non-empty, then we are parsing the unqualified-id of a qualified-id.
ObjectTypeif this unqualified-id occurs within a member access expression, the type of the base object whose member is being accessed.
ObjectHadErrorsif 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.
EnteringContextwhether we are entering the scope of the nested-name-specifier.
AllowDestructorNamewhether we allow parsing of a destructor name.
AllowConstructorNamewhether we allow parsing a constructor name.
AllowDeductionGuidewhether we allow parsing a deduction guide name.
Resulton a successful parse, contains the parsed unqualified-id.
Returns
true if parsing fails, false otherwise.

Definition at line 2576 of file ParseExprCXX.cpp.

References clang::CXXScopeSpec::clear(), ColonProtectionRAIIObject, ConsumeToken(), clang::CPlusPlus, clang::CPlusPlus17, clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateRemoval(), Diag(), getCurScope(), getLangOpts(), clang::IK_LiteralOperatorId, clang::IK_OperatorFunctionId, is(), clang::CXXScopeSpec::isEmpty(), clang::TemplateIdAnnotation::isInvalid(), clang::CXXScopeSpec::isNotEmpty(), clang::CXXScopeSpec::isSet(), clang::SourceLocation::isValid(), clang::TemplateIdAnnotation::LAngleLoc, clang::TemplateIdAnnotation::Name, NextToken(), clang::TemplateIdAnnotation::RAngleLoc, clang::Result, clang::Template, 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(), and ParseReductionId().

◆ ReenterTemplateScopes()

unsigned Parser::ReenterTemplateScopes ( MultiParseScope & S,
Decl * D )

Re-enter a possible template scope, creating as many template parameter scopes as necessary.

Returns
The number of template parameter scopes entered.

Definition at line 25 of file ParseTemplate.cpp.

References clang::Parser::MultiParseScope::Enter(), and clang::Scope::TemplateParamScope.

◆ SkipMalformedDecl()

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 2045 of file ParseDecl.cpp.

References ConsumeAnyToken(), ConsumeToken(), is(), NextToken(), SkipUntil(), and TryConsumeToken().

◆ SkipUntil() [1/4]

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 287 of file Parser.cpp.

References ConsumeAnyToken(), ConsumeToken(), HasFlagsSet(), SkipUntil(), StopAtCodeCompletion, StopAtSemi, and StopBeforeMatch.

◆ SkipUntil() [2/4]

bool clang::Parser::SkipUntil ( tok::TokenKind T,
SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0) )
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 495 of file Parser.h.

References SkipUntil(), and clang::T.

Referenced by parseMapperModifier(), ParseOpenMPDeclareBeginVariantDirective(), parseOpenMPReductionId(), ParseOpenMPVarList(), SkipMalformedDecl(), SkipUntil(), SkipUntil(), SkipUntil(), and SkipUntil().

◆ SkipUntil() [3/4]

bool clang::Parser::SkipUntil ( tok::TokenKind T1,
tok::TokenKind T2,
SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0) )
inline

Definition at line 499 of file Parser.h.

References SkipUntil().

◆ SkipUntil() [4/4]

bool clang::Parser::SkipUntil ( tok::TokenKind T1,
tok::TokenKind T2,
tok::TokenKind T3,
SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0) )
inline

Definition at line 504 of file Parser.h.

References SkipUntil().

◆ TryAnnotateCXXScopeToken()

bool Parser::TryAnnotateCXXScopeToken ( bool EnteringContext = false)

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 2137 of file Parser.cpp.

References clang::CPlusPlus, getLangOpts(), clang::CXXScopeSpec::isEmpty(), and MightBeCXXScopeToken().

Referenced by TryAnnotateOptionalCXXScopeToken().

◆ TryAnnotateOptionalCXXScopeToken()

bool clang::Parser::TryAnnotateOptionalCXXScopeToken ( bool EnteringContext = false)
inline

Definition at line 383 of file Parser.h.

References MightBeCXXScopeToken(), and TryAnnotateCXXScopeToken().

◆ TryAnnotateTypeOrScopeToken()

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 1894 of file Parser.cpp.

References ConsumeToken(), clang::CPlusPlus, Diag(), getCurScope(), getLangOpts(), clang::CXXScopeSpec::getRange(), clang::TemplateIdAnnotation::getTemplateArgs(), is(), clang::CXXScopeSpec::isEmpty(), clang::TemplateIdAnnotation::isInvalid(), isNot(), clang::TemplateIdAnnotation::LAngleLoc, clang::TemplateIdAnnotation::mightBeType(), clang::TemplateIdAnnotation::Name, NextToken(), clang::TemplateIdAnnotation::NumArgs, clang::TemplateIdAnnotation::RAngleLoc, clang::Result, clang::TemplateIdAnnotation::Template, clang::TemplateIdAnnotation::TemplateKWLoc, clang::TemplateIdAnnotation::TemplateNameLoc, TryAnnotateTypeOrScopeToken(), TryAnnotateTypeOrScopeTokenAfterScopeSpec(), and clang::TypeError().

Referenced by TryAnnotateTypeOrScopeToken().

◆ TryAnnotateTypeOrScopeTokenAfterScopeSpec()

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 2020 of file Parser.cpp.

References ConsumeToken(), clang::CPlusPlus, Diag(), clang::ActionResult< PtrTy, Compress >::get(), clang::CXXScopeSpec::getBeginLoc(), getCurScope(), getLangOpts(), is(), clang::CXXScopeSpec::isEmpty(), clang::CXXScopeSpec::isNotEmpty(), clang::ActionResult< PtrTy, Compress >::isUsable(), clang::TemplateIdAnnotation::Kind, NextToken(), clang::ObjC, clang::T, clang::Template, clang::TNK_Type_template, and clang::TNK_Undeclared_template.

Referenced by TryAnnotateTypeOrScopeToken().

◆ TryConsumeToken() [1/2]

bool clang::Parser::TryConsumeToken ( tok::TokenKind Expected)
inline

Definition at line 270 of file Parser.h.

Referenced by SkipMalformedDecl(), and TryConsumeToken().

◆ TryConsumeToken() [2/2]

bool clang::Parser::TryConsumeToken ( tok::TokenKind Expected,
SourceLocation & Loc )
inline

Definition at line 280 of file Parser.h.

References TryConsumeToken().

◆ BalancedDelimiterTracker

◆ ColonProtectionRAIIObject

friend class ColonProtectionRAIIObject
friend

Definition at line 196 of file Parser.h.

References ColonProtectionRAIIObject.

Referenced by ColonProtectionRAIIObject, ParseOpenMPVarList(), and ParseUnqualifiedId().

◆ InMessageExpressionRAIIObject

friend class InMessageExpressionRAIIObject
friend

Definition at line 5329 of file Parser.h.

References InMessageExpressionRAIIObject.

Referenced by InMessageExpressionRAIIObject.

◆ ObjCDeclContextSwitch

friend class ObjCDeclContextSwitch
friend

Definition at line 5330 of file Parser.h.

◆ OffsetOfStateRAIIObject

friend class OffsetOfStateRAIIObject
friend

Definition at line 3630 of file Parser.h.

References OffsetOfStateRAIIObject.

Referenced by OffsetOfStateRAIIObject.

◆ operator|

SkipUntilFlags operator| ( SkipUntilFlags L,
SkipUntilFlags R )
friend

Definition at line 480 of file Parser.h.

◆ ParenBraceBracketBalancer

friend class ParenBraceBracketBalancer
friend

Definition at line 198 of file Parser.h.

References ParenBraceBracketBalancer.

Referenced by ParenBraceBracketBalancer.

◆ ParsingOpenACCDirectiveRAII

◆ ParsingOpenMPDirectiveRAII

◆ PoisonSEHIdentifiersRAIIObject

friend class PoisonSEHIdentifiersRAIIObject
friend

Definition at line 197 of file Parser.h.

References PoisonSEHIdentifiersRAIIObject.

Referenced by PoisonSEHIdentifiersRAIIObject.

Member Data Documentation

◆ MisleadingIndentationElseLoc

SourceLocation clang::Parser::MisleadingIndentationElseLoc

The location of the first statement inside an else that might have a missleading indentation.

If there is no MisleadingIndentationChecker on an else active, this location is invalid.

Definition at line 7190 of file Parser.h.


The documentation for this class was generated from the following files: