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)),
63 State(Other.State), Active(Other.Active) {
69 assert(Active &&
"trying to end an inactive suppression");
70 S.PopParsingDeclaration(State,
nullptr);
75 assert(!Active &&
"redelaying without having ended first");
77 S.redelayDiagnostics(DiagnosticPool);
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!");
184 ParsingRAII(
P, RAII) {}
208 ParsingRAII(
P, &DS.getDelayedDiagnosticPool()) {}
236 ParsingRAII(
P, &DS.getDelayedDiagnosticPool()) {}
278 :
P(p), OldVal(
P.ColonIsSacred) {
285 P.ColonIsSacred = OldVal;
301 :
P(
P), OldVal(
P.OpenMPDirectiveParsing) {
302 P.OpenMPDirectiveParsing =
Value;
307 void restore() {
P.OpenMPDirectiveParsing = OldVal; }
315 bool &GreaterThanIsOperator;
316 bool OldGreaterThanIsOperator;
319 : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
320 GreaterThanIsOperator = Val;
324 GreaterThanIsOperator = OldGreaterThanIsOperator;
329 bool &InMessageExpression;
334 : InMessageExpression(
P.InMessageExpression),
335 OldValue(
P.InMessageExpression) {
336 InMessageExpression =
Value;
340 InMessageExpression = OldValue;
350 : OffsetOfState(
P.OffsetOfState), OldValue(
P.OffsetOfState) {
351 OffsetOfState =
Value;
361 unsigned short ParenCount, BracketCount, BraceCount;
364 :
P(p), ParenCount(p.ParenCount), BracketCount(p.BracketCount),
365 BraceCount(p.BraceCount) { }
368 P.AngleBrackets.clear(
P);
369 P.ParenCount = ParenCount;
370 P.BracketCount = BracketCount;
371 P.BraceCount = BraceCount;
387 : Ident_AbnormalTermination(Self.Ident_AbnormalTermination, NewValue),
388 Ident_GetExceptionCode(Self.Ident_GetExceptionCode, NewValue),
389 Ident_GetExceptionInfo(Self.Ident_GetExceptionInfo, NewValue),
390 Ident__abnormal_termination(Self.Ident__abnormal_termination, NewValue),
391 Ident__exception_code(Self.Ident__exception_code, NewValue),
392 Ident__exception_info(Self.Ident__exception_info, NewValue),
393 Ident___abnormal_termination(Self.Ident___abnormal_termination, NewValue),
394 Ident___exception_code(Self.Ident___exception_code, NewValue),
395 Ident___exception_info(Self.Ident___exception_info, NewValue) {
407 unsigned short &getDepth() {
409 case tok::l_brace:
return P.BraceCount;
410 case tok::l_square:
return P.BracketCount;
411 case tok::l_paren:
return P.ParenCount;
412 default: llvm_unreachable(
"Wrong token kind");
416 bool diagnoseOverflow();
417 bool diagnoseMissingClose();
423 P(p), Kind(k), FinalToken(FinalToken)
426 default: llvm_unreachable(
"Unexpected balanced token");
428 Close = tok::r_brace;
429 Consumer = &Parser::ConsumeBrace;
432 Close = tok::r_paren;
433 Consumer = &Parser::ConsumeParen;
437 Close = tok::r_square;
438 Consumer = &Parser::ConsumeBracket;
451 if (getDepth() <
P.getLangOpts().BracketDepth) {
452 LOpen = (
P.*Consumer)();
456 return diagnoseOverflow();
460 const char *Msg =
"",
463 if (
P.Tok.is(Close)) {
464 LClose = (
P.*Consumer)();
466 }
else if (
P.Tok.is(tok::semi) &&
P.NextToken().is(Close)) {
468 P.Diag(SemiLoc, diag::err_unexpected_semi)
470 LClose = (
P.*Consumer)();
474 return diagnoseMissingClose();
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
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
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
ColonProtectionRAIIObject(Parser &p, bool Value=true)
~ColonProtectionRAIIObject()
Captures information about "declaration specifiers".
Decl - This represents one declaration (or definition), e.g.
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void clear()
Reset the contents of this Declarator.
Concrete class used by the front-end to report problems and issues.
void DecrementAllExtensionsSilenced()
void IncrementAllExtensionsSilenced()
Counter bumped when an extension block is/ encountered.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them.
ExtensionRAIIObject(DiagnosticsEngine &diags)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
RAII object that makes '>' behave either as an operator or as the closing angle bracket for a templat...
~GreaterThanIsOperatorScope()
GreaterThanIsOperatorScope(bool >IO, bool Val)
InMessageExpressionRAIIObject(Parser &P, bool Value)
~InMessageExpressionRAIIObject()
OffsetOfStateRAIIObject(Parser &P, Sema::OffsetOfKind Value)
~OffsetOfStateRAIIObject()
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
~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
A class for parsing a declarator.
ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, const ParsedAttributes &DeclarationAttrs, DeclaratorContext C)
const ParsingDeclSpec & getDeclSpec() const
ParsingDeclSpec & getMutableDeclSpec() const
A class for parsing a field declarator.
const ParsingDeclSpec & getDeclSpec() const
ParsingDeclSpec & getMutableDeclSpec() const
ParsingFieldDeclarator(Parser &P, const ParsingDeclSpec &DS, const ParsedAttributes &DeclarationAttrs)
Activates OpenMP parsing mode to preseve OpenMP specific annotation tokens.
~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.
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.
A RAII object used to temporarily suppress access-like checking.
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.
void steal(DelayedDiagnosticPool &pool)
Steal the diagnostics from the given pool.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
@ C
Languages that the frontend can parse and compile.
This little struct is used to capture information about structure field declarators,...