14#ifndef LLVM_CLANG_PARSE_RAIIOBJECTSFORPARSER_H
15#define LLVM_CLANG_PARSE_RAIIOBJECTSFORPARSER_H
53 : S(P.getActions()), DiagnosticPool(
nullptr) {
55 State = S.PushParsingDeclaration(DiagnosticPool);
62 : S(
Other.S), DiagnosticPool(
std::move(
Other.DiagnosticPool)),
69 assert(Active &&
"trying to end an inactive suppression");
70 S.PopParsingDeclaration(State,
nullptr);
75 assert(!Active &&
"redelaying without having ended first");
76 if (!DiagnosticPool.pool_empty())
77 S.redelayDiagnostics(DiagnosticPool);
78 assert(DiagnosticPool.pool_empty());
90 class ParsingDeclRAIIObject {
96 ParsingDeclRAIIObject(
const ParsingDeclRAIIObject &) =
delete;
97 void operator=(
const ParsingDeclRAIIObject &) =
delete;
102 : Actions(P.getActions()), DiagnosticPool(
nullptr) {
109 : Actions(P.getActions()), DiagnosticPool(parentPool) {
117 : Actions(P.getActions()),
118 DiagnosticPool(other ? other->DiagnosticPool.getParent() :
nullptr) {
120 DiagnosticPool.steal(other->DiagnosticPool);
131 return DiagnosticPool;
134 return DiagnosticPool;
150 assert(!Popped &&
"ParsingDeclaration has already been popped!");
180 : DeclSpec(P.getAttrFactory()),
183 : DeclSpec(P.getAttrFactory()),
184 ParsingRAII(P, RAII) {}
187 return ParsingRAII.getDelayedDiagnosticPool();
191 ParsingRAII.complete(D);
208 ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {}
224 ParsingRAII.complete(D);
236 ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {}
247 ParsingRAII.complete(
D);
255 class ExtensionRAIIObject {
256 ExtensionRAIIObject(
const ExtensionRAIIObject &) =
delete;
257 void operator=(
const ExtensionRAIIObject &) =
delete;
262 Diags.IncrementAllExtensionsSilenced();
266 Diags.DecrementAllExtensionsSilenced();
278 : P(p), OldVal(P.ColonIsSacred) {
279 P.ColonIsSacred =
Value;
285 P.ColonIsSacred = OldVal;
299 : P(P), OldVal(P.ParsingGenericAssociationType) {
300 P.ParsingGenericAssociationType =
Value;
308 void restore() { P.ParsingGenericAssociationType = OldVal; }
321 : P(P), OldVal(P.OpenMPDirectiveParsing) {
322 P.OpenMPDirectiveParsing =
Value;
327 void restore() { P.OpenMPDirectiveParsing = OldVal; }
340 : P(P), OldVal(P.OpenACCDirectiveParsing) {
341 P.OpenACCDirectiveParsing =
Value;
346 void restore() { P.OpenACCDirectiveParsing = OldVal; }
354 bool &GreaterThanIsOperator;
355 bool OldGreaterThanIsOperator;
358 : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
359 GreaterThanIsOperator = Val;
363 GreaterThanIsOperator = OldGreaterThanIsOperator;
368 bool &InMessageExpression;
373 : InMessageExpression(P.InMessageExpression),
374 OldValue(P.InMessageExpression) {
375 InMessageExpression =
Value;
379 InMessageExpression = OldValue;
389 : OffsetOfState(P.OffsetOfState), OldValue(P.OffsetOfState) {
390 OffsetOfState =
Value;
400 unsigned short ParenCount, BracketCount, BraceCount;
403 : P(p), ParenCount(p.ParenCount), BracketCount(p.BracketCount),
404 BraceCount(p.BraceCount) { }
407 P.AngleBrackets.clear(P);
408 P.ParenCount = ParenCount;
409 P.BracketCount = BracketCount;
410 P.BraceCount = BraceCount;
426 : Ident_AbnormalTermination(
Self.Ident_AbnormalTermination, NewValue),
427 Ident_GetExceptionCode(
Self.Ident_GetExceptionCode, NewValue),
428 Ident_GetExceptionInfo(
Self.Ident_GetExceptionInfo, NewValue),
429 Ident__abnormal_termination(
Self.Ident__abnormal_termination, NewValue),
430 Ident__exception_code(
Self.Ident__exception_code, NewValue),
431 Ident__exception_info(
Self.Ident__exception_info, NewValue),
432 Ident___abnormal_termination(
Self.Ident___abnormal_termination, NewValue),
433 Ident___exception_code(
Self.Ident___exception_code, NewValue),
434 Ident___exception_info(
Self.Ident___exception_info, NewValue) {
446 unsigned short &getDepth() {
448 case tok::l_brace:
return P.BraceCount;
449 case tok::l_square:
return P.BracketCount;
450 case tok::l_paren:
return P.ParenCount;
451 default: llvm_unreachable(
"Wrong token kind");
455 bool diagnoseOverflow();
456 bool diagnoseMissingClose();
462 P(p), Kind(k), FinalToken(FinalToken)
465 default: llvm_unreachable(
"Unexpected balanced token");
467 Close = tok::r_brace;
468 Consumer = &Parser::ConsumeBrace;
471 Close = tok::r_paren;
472 Consumer = &Parser::ConsumeParen;
476 Close = tok::r_square;
477 Consumer = &Parser::ConsumeBracket;
490 if (getDepth() < P.getLangOpts().BracketDepth) {
491 LOpen = (P.*Consumer)();
495 return diagnoseOverflow();
499 const char *Msg =
"",
502 if (P.Tok.is(Close)) {
503 LClose = (P.*Consumer)();
505 }
else if (P.Tok.is(tok::semi) && P.NextToken().is(Close)) {
507 P.Diag(SemiLoc, diag::err_unexpected_semi)
509 LClose = (P.*Consumer)();
513 return diagnoseMissingClose();
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
SourceLocation getOpenLocation() const
SourceRange getRange() const
BalancedDelimiterTracker(Parser &p, tok::TokenKind k, tok::TokenKind FinalToken=tok::semi)
SourceLocation getCloseLocation() const
void restore()
restore - This can be used to restore the state early, before the dtor is run.
ColonProtectionRAIIObject(Parser &p, bool Value=true)
~ColonProtectionRAIIObject()
Decl - This represents one declaration (or definition), e.g.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Declarator(const DeclSpec &DS, const ParsedAttributesView &DeclarationAttrs, DeclaratorContext C)
DS and DeclarationAttrs must outlive the Declarator.
void clear()
Reset the contents of this Declarator.
Concrete class used by the front-end to report problems and issues.
ExtensionRAIIObject(DiagnosticsEngine &diags)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
GenericAssociationTypeRAIIObject(const GenericAssociationTypeRAIIObject &)=delete
GenericAssociationTypeRAIIObject & operator=(const GenericAssociationTypeRAIIObject &)=delete
GenericAssociationTypeRAIIObject(Parser &P, bool Value=true)
~GenericAssociationTypeRAIIObject()
~GreaterThanIsOperatorScope()
GreaterThanIsOperatorScope(bool >IO, bool Val)
InMessageExpressionRAIIObject(Parser &P, bool Value)
~InMessageExpressionRAIIObject()
~OffsetOfStateRAIIObject()
OffsetOfStateRAIIObject(Parser &P, OffsetOfKind Value)
~ParenBraceBracketBalancer()
ParenBraceBracketBalancer(Parser &p)
ParsedAttributes - A collection of parsed attributes.
Parser - This implements a parser for the C family of languages.
RAII object used to inform the actions that we're currently parsing a declaration.
ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *other)
Creates a RAII object and, optionally, initialize its diagnostics pool by stealing the diagnostics fr...
ParsingDeclRAIIObject(Parser &P, const sema::DelayedDiagnosticPool *parentPool)
Creates a RAII object whose pool is optionally parented by another.
void abort()
Signals that the context was completed without an appropriate declaration being parsed.
void abortAndRemember()
Unregister this object from Sema, but remember all the diagnostics that were emitted into it.
const sema::DelayedDiagnosticPool & getDelayedDiagnosticPool() const
sema::DelayedDiagnosticPool & getDelayedDiagnosticPool()
ParsingDeclRAIIObject(Parser &P, NoParent_t _)
void reset()
Resets the RAII object for a new declaration.
A class for parsing a DeclSpec.
ParsingDeclSpec(Parser &P)
ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
const sema::DelayedDiagnosticPool & getDelayedDiagnosticPool() const
ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, const ParsedAttributes &DeclarationAttrs, DeclaratorContext C)
const ParsingDeclSpec & getDeclSpec() const
ParsingDeclSpec & getMutableDeclSpec() const
const ParsingDeclSpec & getDeclSpec() const
ParsingDeclSpec & getMutableDeclSpec() const
ParsingFieldDeclarator(Parser &P, const ParsingDeclSpec &DS, const ParsedAttributes &DeclarationAttrs)
void restore()
This can be used to restore the state early, before the dtor is run.
~ParsingOpenACCDirectiveRAII()
ParsingOpenACCDirectiveRAII(Parser &P, bool Value=true)
~ParsingOpenMPDirectiveRAII()
void restore()
This can be used to restore the state early, before the dtor is run.
ParsingOpenMPDirectiveRAII(Parser &P, bool Value=true)
An RAII object for [un]poisoning an identifier within a scope.
PoisonSEHIdentifiersRAIIObject(Parser &Self, bool NewValue)
Sema - This implements semantic analysis and AST building for C.
DelayedDiagnosticsState ParsingDeclState
void PopParsingDeclaration(ParsingDeclState state, Decl *decl)
ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool)
Encodes a location in the source.
A trivial tuple used to represent a source range.
void operator=(SuppressAccessChecks &&Other)=delete
SuppressAccessChecks(Parser &P, bool activate=true)
Begin suppressing access-like checks.
SuppressAccessChecks(SuppressAccessChecks &&Other)
A collection of diagnostics which were delayed.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Top level wrappers for InstallAPI frontend operations.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Other
Other implicit parameter.
FieldDeclarator(const DeclSpec &DS, const ParsedAttributes &DeclarationAttrs)