clang: include/clang/Parse/RAIIObjectsForParser.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_PARSE_RAIIOBJECTSFORPARSER_H

15#define LLVM_CLANG_PARSE_RAIIOBJECTSFORPARSER_H

16

22

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

48 bool Active;

49

50 public:

51

53 : S(P.getActions()), DiagnosticPool(nullptr) {

54 if (activate) {

55 State = S.PushParsingDeclaration(DiagnosticPool);

56 Active = true;

57 } else {

58 Active = false;

59 }

60 }

62 : S(Other.S), DiagnosticPool(std::move(Other.DiagnosticPool)),

63 State(Other.State), Active(Other.Active) {

64 Other.Active = false;

65 }

67

69 assert(Active && "trying to end an inactive suppression");

70 S.PopParsingDeclaration(State, nullptr);

71 Active = false;

72 }

73

75 assert(!Active && "redelaying without having ended first");

77 S.redelayDiagnostics(DiagnosticPool);

79 }

80

82 if (Active) done();

83 }

84 };

85

86

87

88

89

91 Sema &Actions;

94 bool Popped;

95

98

99 public:

102 : Actions(P.getActions()), DiagnosticPool(nullptr) {

103 push();

104 }

105

106

109 : Actions(P.getActions()), DiagnosticPool(parentPool) {

110 push();

111 }

112

113

114

115

117 : Actions(P.getActions()),

118 DiagnosticPool(other ? other->DiagnosticPool.getParent() : nullptr) {

119 if (other) {

120 DiagnosticPool.steal(other->DiagnosticPool);

122 }

123 push();

124 }

125

128 }

129

131 return DiagnosticPool;

132 }

134 return DiagnosticPool;

135 }

136

137

140 push();

141 }

142

143

144

146 pop(nullptr);

147 }

148

150 assert(!Popped && "ParsingDeclaration has already been popped!");

151 pop(D);

152 }

153

154

155

157 pop(nullptr);

158 }

159

160 private:

161 void push() {

163 Popped = false;

164 }

165

166 void pop(Decl *D) {

167 if (!Popped) {

169 Popped = true;

170 }

171 }

172 };

173

174

177

178 public:

184 ParsingRAII(P, RAII) {}

185

188 }

189

192 }

193

195 ParsingRAII.abort();

196 }

197 };

198

199

202

203 public:

208 ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {}

209

212 }

213

216 }

217

220 ParsingRAII.reset();

221 }

222

225 }

226 };

227

228

231

232 public:

236 ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {}

237

240 }

241

244 }

245

248 }

249 };

250

251

252

253

254

258

260 public:

263 }

264

267 }

268 };

269

270

271

272

275 bool OldVal;

276 public:

278 : P(p), OldVal(P.ColonIsSacred) {

279 P.ColonIsSacred = Value;

280 }

281

282

283

285 P.ColonIsSacred = OldVal;

286 }

287

290 }

291 };

292

293

294

297 bool OldVal;

298

299 public:

301 : P(P), OldVal(P.OpenMPDirectiveParsing) {

302 P.OpenMPDirectiveParsing = Value;

303 }

304

305

306

307 void restore() { P.OpenMPDirectiveParsing = OldVal; }

308

310 };

311

312

313

316 bool OldVal;

317

318 public:

320 : P(P), OldVal(P.OpenACCDirectiveParsing) {

321 P.OpenACCDirectiveParsing = Value;

322 }

323

324

325

326 void restore() { P.OpenACCDirectiveParsing = OldVal; }

327

329 };

330

331

332

334 bool &GreaterThanIsOperator;

335 bool OldGreaterThanIsOperator;

336 public:

338 : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {

339 GreaterThanIsOperator = Val;

340 }

341

343 GreaterThanIsOperator = OldGreaterThanIsOperator;

344 }

345 };

346

348 bool &InMessageExpression;

349 bool OldValue;

350

351 public:

353 : InMessageExpression(P.InMessageExpression),

354 OldValue(P.InMessageExpression) {

355 InMessageExpression = Value;

356 }

357

359 InMessageExpression = OldValue;

360 }

361 };

362

366

367 public:

369 : OffsetOfState(P.OffsetOfState), OldValue(P.OffsetOfState) {

370 OffsetOfState = Value;

371 }

372

374 };

375

376

377

380 unsigned short ParenCount, BracketCount, BraceCount;

381 public:

383 : P(p), ParenCount(p.ParenCount), BracketCount(p.BracketCount),

384 BraceCount(p.BraceCount) { }

385

387 P.AngleBrackets.clear(P);

388 P.ParenCount = ParenCount;

389 P.BracketCount = BracketCount;

390 P.BraceCount = BraceCount;

391 }

392 };

393

404 public:

406 : Ident_AbnormalTermination(Self.Ident_AbnormalTermination, NewValue),

407 Ident_GetExceptionCode(Self.Ident_GetExceptionCode, NewValue),

408 Ident_GetExceptionInfo(Self.Ident_GetExceptionInfo, NewValue),

409 Ident__abnormal_termination(Self.Ident__abnormal_termination, NewValue),

410 Ident__exception_code(Self.Ident__exception_code, NewValue),

411 Ident__exception_info(Self.Ident__exception_info, NewValue),

412 Ident___abnormal_termination(Self.Ident___abnormal_termination, NewValue),

413 Ident___exception_code(Self.Ident___exception_code, NewValue),

414 Ident___exception_info(Self.Ident___exception_info, NewValue) {

415 }

416 };

417

418

419

425

426 unsigned short &getDepth() {

427 switch (Kind) {

428 case tok::l_brace: return P.BraceCount;

429 case tok::l_square: return P.BracketCount;

430 case tok::l_paren: return P.ParenCount;

431 default: llvm_unreachable("Wrong token kind");

432 }

433 }

434

435 bool diagnoseOverflow();

436 bool diagnoseMissingClose();

437

438 public:

442 P(p), Kind(k), FinalToken(FinalToken)

443 {

444 switch (Kind) {

445 default: llvm_unreachable("Unexpected balanced token");

446 case tok::l_brace:

447 Close = tok::r_brace;

448 Consumer = &Parser::ConsumeBrace;

449 break;

450 case tok::l_paren:

451 Close = tok::r_paren;

452 Consumer = &Parser::ConsumeParen;

453 break;

454

455 case tok::l_square:

456 Close = tok::r_square;

457 Consumer = &Parser::ConsumeBracket;

458 break;

459 }

460 }

461

465

467 if (P.Tok.is(Kind))

468 return true;

469

470 if (getDepth() < P.getLangOpts().BracketDepth) {

471 LOpen = (P.*Consumer)();

472 return false;

473 }

474

475 return diagnoseOverflow();

476 }

477

479 const char *Msg = "",

482 if (P.Tok.is(Close)) {

483 LClose = (P.*Consumer)();

484 return false;

485 } else if (P.Tok.is(tok::semi) && P.NextToken().is(Close)) {

487 P.Diag(SemiLoc, diag::err_unexpected_semi)

489 LClose = (P.*Consumer)();

490 return false;

491 }

492

493 return diagnoseMissingClose();

494 }

496 };

497}

498

499#endif

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 &GTIO, 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 OpenACC parsing mode to preseve OpenACC specific annotation tokens.

void restore()

This can be used to restore the state early, before the dtor is run.

~ParsingOpenACCDirectiveRAII()

ParsingOpenACCDirectiveRAII(Parser &P, bool Value=true)

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.

The JSON file list parser is used to communicate input to InstallAPI.

@ Self

'self' clause, allowed on Compute and Combined Constructs, plus 'update'.

@ Other

Other implicit parameter.

This little struct is used to capture information about structure field declarators,...