14 #ifndef LLVM_CLANG_LIB_PARSE_RAIIOBJECTSFORPARSER_H 15 #define LLVM_CLANG_LIB_PARSE_RAIIOBJECTSFORPARSER_H 53 : S(P.getActions()), DiagnosticPool(nullptr) {
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");
75 assert(!Active &&
"redelaying without having ended first");
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()) {
232 :
FieldDeclarator(DS), ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {
275 : P(p), OldVal(P.ColonIsSacred) {
276 P.ColonIsSacred =
Value;
282 P.ColonIsSacred = OldVal;
293 bool &GreaterThanIsOperator;
294 bool OldGreaterThanIsOperator;
297 : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
298 GreaterThanIsOperator = Val;
302 GreaterThanIsOperator = OldGreaterThanIsOperator;
307 bool &InMessageExpression;
312 : InMessageExpression(P.InMessageExpression),
313 OldValue(P.InMessageExpression) {
314 InMessageExpression =
Value;
318 InMessageExpression = OldValue;
326 unsigned short ParenCount, BracketCount, BraceCount;
329 : P(p), ParenCount(p.ParenCount), BracketCount(p.BracketCount),
330 BraceCount(p.BraceCount) { }
333 P.AngleBrackets.clear(P);
334 P.ParenCount = ParenCount;
335 P.BracketCount = BracketCount;
336 P.BraceCount = BraceCount;
352 : Ident_AbnormalTermination(Self.Ident_AbnormalTermination, NewValue),
353 Ident_GetExceptionCode(Self.Ident_GetExceptionCode, NewValue),
354 Ident_GetExceptionInfo(Self.Ident_GetExceptionInfo, NewValue),
355 Ident__abnormal_termination(Self.Ident__abnormal_termination, NewValue),
356 Ident__exception_code(Self.Ident__exception_code, NewValue),
357 Ident__exception_info(Self.Ident__exception_info, NewValue),
358 Ident___abnormal_termination(Self.Ident___abnormal_termination, NewValue),
359 Ident___exception_code(Self.Ident___exception_code, NewValue),
360 Ident___exception_info(Self.Ident___exception_info, NewValue) {
372 unsigned short &getDepth() {
374 case tok::l_brace:
return P.BraceCount;
375 case tok::l_square:
return P.BracketCount;
376 case tok::l_paren:
return P.ParenCount;
377 default: llvm_unreachable(
"Wrong token kind");
381 bool diagnoseOverflow();
382 bool diagnoseMissingClose();
388 P(p), Kind(k), FinalToken(FinalToken)
391 default: llvm_unreachable(
"Unexpected balanced token");
393 Close = tok::r_brace;
394 Consumer = &Parser::ConsumeBrace;
397 Close = tok::r_paren;
398 Consumer = &Parser::ConsumeParen;
402 Close = tok::r_square;
403 Consumer = &Parser::ConsumeBracket;
417 LOpen = (P.*Consumer)();
421 return diagnoseOverflow();
424 bool expectAndConsume(
unsigned DiagID = diag::err_expected,
425 const char *Msg =
"",
428 if (P.Tok.
is(Close)) {
429 LClose = (P.*Consumer)();
433 P.
Diag(SemiLoc, diag::err_unexpected_semi)
435 LClose = (P.*Consumer)();
439 return diagnoseMissingClose();
452 : Container(Container) {}
DestroyTemplateIdAnnotationsRAIIObj(SmallVectorImpl< TemplateIdAnnotation *> &Container)
void restore()
restore - This can be used to restore the state early, before the dtor is run.
void clear()
Reset the contents of this Declarator.
ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, DeclaratorContext C)
SuppressAccessChecks(SuppressAccessChecks &&Other)
ColonProtectionRAIIObject(Parser &p, bool Value=true)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
Decl - This represents one declaration (or definition), e.g.
RAII object used to inform the actions that we're currently parsing a declaration.
A RAII object used to temporarily suppress access-like checking.
void PopParsingDeclaration(ParsingDeclState state, Decl *decl)
SourceLocation getCloseLocation() const
Parser - This implements a parser for the C family of languages.
Information about one declarator, including the parsed type information and the identifier.
RAIIObject to destroy the contents of a SmallVector of TemplateIdAnnotation pointers and clear the ve...
ExtensionRAIIObject(DiagnosticsEngine &diags)
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
void operator=(SuppressAccessChecks &&Other)=delete
ParenBraceBracketBalancer(Parser &p)
~GreaterThanIsOperatorScope()
void IncrementAllExtensionsSilenced()
Counter bumped when an extension block is/ encountered.
const sema::DelayedDiagnosticPool & getDelayedDiagnosticPool() const
ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
ParsingFieldDeclarator(Parser &P, const ParsingDeclSpec &DS)
This little struct is used to capture information about structure field declarators, which is basically just a bitfield size.
void reset()
Resets the RAII object for a new declaration.
void abortAndRemember()
Unregister this object from Sema, but remember all the diagnostics that were emitted into it...
SourceRange getRange() const
Concrete class used by the front-end to report problems and issues.
ParsingDeclSpec & getMutableDeclSpec() const
void steal(DelayedDiagnosticPool &pool)
Steal the diagnostics from the given pool.
const ParsingDeclSpec & getDeclSpec() const
GreaterThanIsOperatorScope(bool >IO, bool Val)
Sema - This implements semantic analysis and AST building for C.
A class for parsing a declarator.
ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
ParsingDeclRAIIObject(Parser &P, const sema::DelayedDiagnosticPool *parentPool)
Creates a RAII object whose pool is optionally parented by another.
ParsingDeclRAIIObject(Parser &P, NoParent_t _)
~ColonProtectionRAIIObject()
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *other)
Creates a RAII object and, optionally, initialize its diagnostics pool by stealing the diagnostics fr...
SuppressAccessChecks(Parser &P, bool activate=true)
Begin suppressing access-like checks.
A class for parsing a field declarator.
SourceLocation getOpenLocation() const
RAII object that makes '>' behave either as an operator or as the closing angle bracket for a templat...
const LangOptions & getLangOpts() const
A class for parsing a DeclSpec.
Encodes a location in the source.
const ParsingDeclSpec & getDeclSpec() const
ParsingDeclSpec(Parser &P)
~ParenBraceBracketBalancer()
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
InMessageExpressionRAIIObject(Parser &P, bool Value)
Dataflow Directional Tag Classes.
void redelayDiagnostics(sema::DelayedDiagnosticPool &pool)
BalancedDelimiterTracker(Parser &p, tok::TokenKind k, tok::TokenKind FinalToken=tok::semi)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const sema::DelayedDiagnosticPool & getDelayedDiagnosticPool() const
~DestroyTemplateIdAnnotationsRAIIObj()
sema::DelayedDiagnosticPool & getDelayedDiagnosticPool()
void abort()
Signals that the context was completed without an appropriate declaration being parsed.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
ParsingDeclSpec & getMutableDeclSpec() const
~InMessageExpressionRAIIObject()
void DecrementAllExtensionsSilenced()
Captures information about "declaration specifiers".
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
PoisonSEHIdentifiersRAIIObject(Parser &Self, bool NewValue)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
A collection of diagnostics which were delayed.
A trivial tuple used to represent a source range.
An RAII object for [un]poisoning an identifier within a scope.