Go to the documentation of this file.
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) {}
205 :
Declarator(DS, C), ParsingRAII(
P, &DS.getDelayedDiagnosticPool()) {
275 :
P(p), OldVal(
P.ColonIsSacred) {
282 P.ColonIsSacred = OldVal;
298 :
P(
P), OldVal(
P.OpenMPDirectiveParsing) {
299 P.OpenMPDirectiveParsing =
Value;
304 void restore() {
P.OpenMPDirectiveParsing = OldVal; }
312 bool &GreaterThanIsOperator;
313 bool OldGreaterThanIsOperator;
316 : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
317 GreaterThanIsOperator = Val;
321 GreaterThanIsOperator = OldGreaterThanIsOperator;
326 bool &InMessageExpression;
331 : InMessageExpression(
P.InMessageExpression),
332 OldValue(
P.InMessageExpression) {
333 InMessageExpression =
Value;
337 InMessageExpression = OldValue;
345 unsigned short ParenCount, BracketCount, BraceCount;
348 :
P(p), ParenCount(p.ParenCount), BracketCount(p.BracketCount),
349 BraceCount(p.BraceCount) { }
352 P.AngleBrackets.clear(
P);
353 P.ParenCount = ParenCount;
354 P.BracketCount = BracketCount;
355 P.BraceCount = BraceCount;
371 : Ident_AbnormalTermination(Self.Ident_AbnormalTermination, NewValue),
372 Ident_GetExceptionCode(Self.Ident_GetExceptionCode, NewValue),
373 Ident_GetExceptionInfo(Self.Ident_GetExceptionInfo, NewValue),
374 Ident__abnormal_termination(Self.Ident__abnormal_termination, NewValue),
375 Ident__exception_code(Self.Ident__exception_code, NewValue),
376 Ident__exception_info(Self.Ident__exception_info, NewValue),
377 Ident___abnormal_termination(Self.Ident___abnormal_termination, NewValue),
378 Ident___exception_code(Self.Ident___exception_code, NewValue),
379 Ident___exception_info(Self.Ident___exception_info, NewValue) {
391 unsigned short &getDepth() {
393 case tok::l_brace:
return P.BraceCount;
394 case tok::l_square:
return P.BracketCount;
395 case tok::l_paren:
return P.ParenCount;
396 default: llvm_unreachable(
"Wrong token kind");
400 bool diagnoseOverflow();
401 bool diagnoseMissingClose();
407 P(p), Kind(k), FinalToken(FinalToken)
410 default: llvm_unreachable(
"Unexpected balanced token");
412 Close = tok::r_brace;
413 Consumer = &Parser::ConsumeBrace;
416 Close = tok::r_paren;
417 Consumer = &Parser::ConsumeParen;
421 Close = tok::r_square;
422 Consumer = &Parser::ConsumeBracket;
435 if (getDepth() <
P.getLangOpts().BracketDepth) {
436 LOpen = (
P.*Consumer)();
440 return diagnoseOverflow();
444 const char *Msg =
"",
447 if (
P.Tok.is(Close)) {
448 LClose = (
P.*Consumer)();
450 }
else if (
P.Tok.is(tok::semi) &&
P.NextToken().is(Close)) {
452 P.Diag(SemiLoc, diag::err_unexpected_semi)
454 LClose = (
P.*Consumer)();
458 return diagnoseMissingClose();
ParsingDeclSpec(Parser &P)
A class for parsing a DeclSpec.
void IncrementAllExtensionsSilenced()
Counter bumped when an extension block is/ encountered.
~GreaterThanIsOperatorScope()
void operator=(SuppressAccessChecks &&Other)=delete
A trivial tuple used to represent a source range.
InMessageExpressionRAIIObject(Parser &P, bool Value)
const sema::DelayedDiagnosticPool & getDelayedDiagnosticPool() const
Encodes a location in the source.
ColonProtectionRAIIObject(Parser &p, bool Value=true)
void restore()
restore - This can be used to restore the state early, before the dtor is run.
ParsingDeclRAIIObject(Parser &P, NoParent_t _)
ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *other)
Creates a RAII object and, optionally, initialize its diagnostics pool by stealing the diagnostics fr...
Concrete class used by the front-end to report problems and issues.
Parser - This implements a parser for the C family of languages.
~InMessageExpressionRAIIObject()
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
void abortAndRemember()
Unregister this object from Sema, but remember all the diagnostics that were emitted into it.
A RAII object used to temporarily suppress access-like checking.
ParenBraceBracketBalancer(Parser &p)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
ParsingDeclSpec & getMutableDeclSpec() const
A collection of diagnostics which were delayed.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
void steal(DelayedDiagnosticPool &pool)
Steal the diagnostics from the given pool.
ParsingDeclRAIIObject(Parser &P, const sema::DelayedDiagnosticPool *parentPool)
Creates a RAII object whose pool is optionally parented by another.
SourceLocation getCloseLocation() const
Activates OpenMP parsing mode to preseve OpenMP specific annotation tokens.
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
~ParsingOpenMPDirectiveRAII()
PoisonSEHIdentifiersRAIIObject(Parser &Self, bool NewValue)
const ParsingDeclSpec & getDeclSpec() const
GreaterThanIsOperatorScope(bool >IO, bool Val)
ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, DeclaratorContext C)
void clear()
Reset the contents of this Declarator.
void abort()
Signals that the context was completed without an appropriate declaration being parsed.
~ParenBraceBracketBalancer()
void restore()
This can be used to restore the state early, before the dtor is run.
sema::DelayedDiagnosticPool & getDelayedDiagnosticPool()
ExtensionRAIIObject(DiagnosticsEngine &diags)
const sema::DelayedDiagnosticPool & getDelayedDiagnosticPool() const
ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
SuppressAccessChecks(Parser &P, bool activate=true)
Begin suppressing access-like checks.
void reset()
Resets the RAII object for a new declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
RAII object used to inform the actions that we're currently parsing a declaration.
A class for parsing a field declarator.
Decl - This represents one declaration (or definition), e.g.
const ParsingDeclSpec & getDeclSpec() const
Sema - This implements semantic analysis and AST building for C.
BalancedDelimiterTracker(Parser &p, tok::TokenKind k, tok::TokenKind FinalToken=tok::semi)
SourceLocation getOpenLocation() const
void PopParsingDeclaration(ParsingDeclState state, Decl *decl)
An RAII object for [un]poisoning an identifier within a scope.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them.
ParsingOpenMPDirectiveRAII(Parser &P, bool Value=true)
Information about one declarator, including the parsed type information and the identifier.
This little struct is used to capture information about structure field declarators,...
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
ParsingDeclSpec & getMutableDeclSpec() const
A class for parsing a declarator.
RAII object that makes '>' behave either as an operator or as the closing angle bracket for a templat...
~ColonProtectionRAIIObject()
SourceRange getRange() const
ParsingFieldDeclarator(Parser &P, const ParsingDeclSpec &DS)
Captures information about "declaration specifiers".
ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool)
void DecrementAllExtensionsSilenced()
SuppressAccessChecks(SuppressAccessChecks &&Other)