clang: include/clang/Sema/Scope.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_CLANG_SEMA_SCOPE_H
14#define LLVM_CLANG_SEMA_SCOPE_H
15
18#include "llvm/ADT/PointerIntPair.h"
19#include "llvm/ADT/SmallPtrSet.h"
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/iterator_range.h"
22#include
23#include
24
25namespace llvm {
26
27class raw_ostream;
28
29}
30
32
34class DeclContext;
35class UsingDirectiveDecl;
36class VarDecl;
37
38
39
40
42public:
43
44
46
48
49
50
52
53
54
56
57
58
60
61
62
64
65
67
68
70
71
72
73
74
76
77
78
79
80
82
83
84
86
87
88
89
90
92
93
94
96
97
98
100
101
103
104
106
107
109
110
112
113
115
116
117
118
120
121
123
124
126
127
129
130
132
133
135
136
137
139
140
142
143
144
145
147
148
149
151
152
153
154
156
157
158
160
161
163
164
166 };
167
168private:
169
170
171 Scope *AnyParent;
172
173
174
175 unsigned Flags;
176
177
178
179 unsigned short Depth;
180
181
182
183 unsigned short MSLastManglingNumber;
184
185 unsigned short MSCurManglingNumber;
186
187
188
189 unsigned short PrototypeDepth;
190
191
192
193 unsigned short PrototypeIndex;
194
195
196
198 Scope *MSLastManglingParent;
199
200
201
202
203
204 Scope *BreakParent, *ContinueParent;
205
206
207
208 Scope *BlockParent;
209
210
211
212
213
214 Scope *TemplateParamParent;
215
216
217
218 Scope *DeclParent;
219
220
221
222
223
224
225
227 DeclSetTy DeclsInScope;
228
229
230
231
233
235 UsingDirectivesTy UsingDirectives;
236
237
239
240
241
242
243
244
245
246
247 std::optional<VarDecl *> NRVO;
248
249
250
251
253
254 void setFlags(Scope *Parent, unsigned F);
255
256public:
258 : ErrorTrap(Diag) {
260 }
261
262
263 unsigned getFlags() const { return Flags; }
264
266
267
269
270
273
274
277
279 return MSLastManglingParent;
280 }
282
283
284
286 return ContinueParent;
287 }
288
291 }
292
293
294
296 Flags = (Flags & ~ConditionVarScope) |
298 }
299
302 }
303
304
305
307 return BreakParent;
308 }
311 }
312
315
318
321
322
323 unsigned getDepth() const { return Depth; }
324
325
326
328 return PrototypeDepth;
329 }
330
331
332
335 return PrototypeIndex++;
336 }
337
338 using decl_range = llvm::iterator_rangeDeclSetTy::iterator;
339
341 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
342 }
343
344 bool decl_empty() const { return DeclsInScope.empty(); }
345
347 if (auto *VD = dyn_cast(D))
348 if (!isa(VD))
349 ReturnSlots.insert(VD);
350
351 DeclsInScope.insert(D);
352 }
353
355
358 MSLMP->MSLastManglingNumber += 1;
359 MSCurManglingNumber += 1;
360 }
361 }
362
365 MSLMP->MSLastManglingNumber -= 1;
366 MSCurManglingNumber -= 1;
367 }
368 }
369
372 return MSLMP->MSLastManglingNumber;
373 return 1;
374 }
375
377 return MSCurManglingNumber;
378 }
379
380
381
383
384
387 }
388
389
390
392
395 "entity associated with template param scope");
396 Entity = E;
397 }
399
400
401
402
403
406 }
407
408
410
411
413
414
415
418 }
419
420
421
424 assert(FnS->getParent() && "TUScope not created?");
425 return FnS->getParent()->isClassScope();
426 }
427 return false;
428 }
429
430
431
433 for (const Scope *S = this; S; S = S->getParent()) {
434
436 return true;
437 }
438 return false;
439 }
440
441
442
444 if (const Scope *S = this) {
445
447 return true;
448 }
449 return false;
450 }
451
452
453
456 }
457
458
459
462 }
463
464
465
468 }
469
470
473 }
474
475
477
478
480 for (const Scope *S = this; S; S = S->getParent()) {
482 return true;
487 return false;
488 }
489 return false;
490 }
491
492
494
495
498 }
499
500
503 }
504
505
506
510 "OpenMP loop directive scope is not a directive scope");
511 return true;
512 }
513 return false;
514 }
515
516
517
520 }
521
522
523
526 return P && P->isOpenMPLoopDirectiveScope();
527 }
528
529
530
533 }
534
535
536
539 }
540
541
542
543
545 for (const Scope *S = this; S; S = S->getParent()) {
546 if (S->isOpenACCComputeConstructScope())
547 return true;
548
549 if (S->getFlags() & Flags)
550 return false;
551
552 else if (S->getFlags() &
556 return false;
557 }
558 return false;
559 }
560
561
562
565 }
566
567
569
570
573 }
574
575
577
578
580
581
584 }
585
586
587
589
590
592
593
595
596
597
598
599
600 bool Contains(const Scope& rhs) const { return Depth < rhs.Depth; }
601
602
603
605
607 UsingDirectives.push_back(UDir);
608 }
609
611 llvm::iterator_rangeUsingDirectivesTy::iterator;
612
615 UsingDirectives.end());
616 }
617
619
621
622
623 void Init(Scope *parent, unsigned flags);
624
625
626
627 void AddFlags(unsigned Flags);
628
629 void dumpImpl(raw_ostream &OS) const;
630 void dump() const;
631};
632
633}
634
635#endif
Defines the Diagnostic-related interfaces.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
RAII class that determines when any errors have occurred between the time the instance was created an...
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created.
Concrete class used by the front-end to report problems and issues.
Scope - A scope is a transient data structure that is used while parsing the program.
bool isFriendScope() const
Determine whether this scope is a friend scope.
Scope * getMSLastManglingParent()
void setEntity(DeclContext *E)
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
bool isBlockScope() const
isBlockScope - Return true if this scope correspond to a closure.
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
unsigned getNextFunctionPrototypeIndex()
Return the number of parameters declared in this function prototype, increasing it by one for the nex...
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isSEHExceptScope() const
Determine whether this scope is a SEH '__except' block.
llvm::iterator_range< DeclSetTy::iterator > decl_range
bool isInObjcMethodOuterScope() const
isInObjcMethodOuterScope - Return true if this scope is an Objective-C method outer most body.
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
bool isCatchScope() const
isCatchScope - Return true if this scope is a C++ catch statement.
void setFlags(unsigned F)
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body.
void incrementMSManglingNumber()
const Scope * getBreakParent() const
bool isInCXXInlineMethodScope() const
isInCXXInlineMethodScope - Return true if this scope is a C++ inline method scope or is inside one.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
const Scope * getMSLastManglingParent() const
bool isOpenMPLoopDirectiveScope() const
Determine whether this scope is some OpenMP loop directive scope (for example, 'omp for',...
unsigned getFlags() const
getFlags - Return the flags for this scope.
DeclContext * getLookupEntity() const
Get the DeclContext in which to continue unqualified lookup after a lookup in this scope.
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
bool isTypeAliasScope() const
Determine whether this scope is a type alias scope.
bool isOpenMPDirectiveScope() const
Determines whether this scope is the OpenMP directive scope.
using_directives_range using_directives()
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by.
llvm::iterator_range< UsingDirectivesTy::iterator > using_directives_range
Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
void setIsConditionVarScope(bool InConditionVarScope)
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
bool isFnTryCatchScope() const
Determine whether this scope is a function-level C++ try or catch scope.
void decrementMSManglingNumber()
bool isControlScope() const
Determine whether this scope is a controlling scope in a if/switch/while/for statement.
const Scope * getTemplateParamParent() const
void setLookupEntity(DeclContext *E)
unsigned getMSLastManglingNumber() const
DeclContext * getEntity() const
Get the entity corresponding to this scope.
unsigned getMSCurManglingNumber() const
bool isLoopScope() const
Return true if this scope is a loop.
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
bool isOpenMPSimdDirectiveScope() const
Determine whether this scope is (or is nested into) some OpenMP loop simd directive scope (for exampl...
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
unsigned getFunctionPrototypeDepth() const
Returns the number of function prototype scopes in this scope chain.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by.
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
bool isInOpenACCComputeConstructScope(ScopeFlags Flags=NoScope) const
Determine if this scope (or its parents) are a compute construct.
bool isFunctionDeclarationScope() const
isFunctionDeclarationScope - Return true if this scope is a function prototype scope.
bool containedInPrototypeScope() const
containedInPrototypeScope - Return true if this or a parent scope is a FunctionPrototypeScope.
bool isOpenMPOrderClauseScope() const
Determine whether this scope is some OpenMP directive with order clause which specifies concurrent sc...
const Scope * getParent() const
getParent - Return the scope that this is nested in.
bool isContinueScope() const
Determine whether this scope is a while/do/for statement, which can have continue statements embedded...
bool isClassInheritanceScope() const
Determines whether this scope is between inheritance colon and the real class/struct definition.
bool isConditionVarScope() const
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
bool isTryScope() const
Determine whether this scope is a C++ 'try' block.
void updateNRVOCandidate(VarDecl *VD)
const Scope * getBlockParent() const
bool isFunctionScope() const
isFunctionScope() - Return true if this scope is a function scope.
const Scope * getContinueParent() const
bool isOpenACCComputeConstructScope() const
Determine whether this scope is the statement associated with an OpenACC Compute construct directive.
void dumpImpl(raw_ostream &OS) const
const Scope * getDeclParent() const
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred within this scope.
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
Scope * getTemplateParamParent()
ScopeFlags
ScopeFlags - These are bitfields that are or'd together when creating a scope, which defines the sort...
@ OpenMPDirectiveScope
This is the scope of OpenMP executable directive.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ OpenMPOrderClauseScope
This is a scope of some OpenMP directive with order clause which specifies concurrent.
@ LambdaScope
This is the scope for a lambda, after the lambda introducer.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ SEHTryScope
This scope corresponds to an SEH try.
@ FriendScope
This is a scope of friend declaration.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ OpenACCComputeConstructScope
This is the scope of an OpenACC Compute Construct, which restricts jumping into/out of it.
@ TypeAliasScope
This is a scope of type alias declaration.
@ ControlScope
The controlling scope in a if/switch/while/for statement.
@ ClassInheritanceScope
We are between inheritance colon and the real class/struct definition scope.
@ AtCatchScope
This is a scope that corresponds to the Objective-C @catch statement.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ SEHFilterScope
We are currently in the filter expression of an SEH except block.
@ SwitchScope
This is a scope that corresponds to a switch statement.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ CatchScope
This is the scope of a C++ catch statement.
@ CompoundStmtScope
This is a compound statement scope.
@ FnTryCatchScope
This is the scope for a function-level C++ try or catch scope.
@ SEHExceptScope
This scope corresponds to an SEH except.
@ ClassScope
The scope of a struct/union/class definition.
@ TryScope
This is the scope of a C++ try statement.
@ OpenMPSimdDirectiveScope
This is the scope of some OpenMP simd directive.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ ConditionVarScope
This is a scope in which a condition variable is currently being parsed.
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ ObjCMethodScope
This scope corresponds to an Objective-C method body.
@ EnumScope
This scope corresponds to an enum.
@ OpenMPLoopDirectiveScope
This is the scope of some OpenMP loop directive.
@ DeclScope
This is a scope that can contain a declaration.
void PushUsingDirective(UsingDirectiveDecl *UDir)
Represents C++ using-directive.
Represents a variable declaration or definition.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.