]>
Commit | Line | Data |
---|---|---|
b4c522fa IB |
1 | |
2 | /* Compiler implementation of the D programming language | |
a3b38b77 | 3 | * Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved |
b4c522fa IB |
4 | * written by Walter Bright |
5 | * http://www.digitalmars.com | |
6 | * Distributed under the Boost Software License, Version 1.0. | |
7 | * http://www.boost.org/LICENSE_1_0.txt | |
8 | * https://github.com/dlang/dmd/blob/master/src/dmd/scope.h | |
9 | */ | |
10 | ||
11 | #pragma once | |
12 | ||
13 | class Dsymbol; | |
14 | class ScopeDsymbol; | |
15 | class Identifier; | |
16 | class Module; | |
17 | class Statement; | |
18 | class SwitchStatement; | |
19 | class TryFinallyStatement; | |
20 | class LabelStatement; | |
21 | class ForeachStatement; | |
22 | class ClassDeclaration; | |
23 | class AggregateDeclaration; | |
24 | class FuncDeclaration; | |
25 | class UserAttributeDeclaration; | |
26 | struct DocComment; | |
27 | struct AA; | |
28 | class TemplateInstance; | |
29 | ||
30 | #include "dsymbol.h" | |
31 | ||
32 | #if __GNUC__ | |
33 | // Requires a full definition for LINK | |
34 | #include "globals.h" | |
35 | #else | |
36 | enum LINK; | |
37 | enum PINLINE; | |
38 | #endif | |
39 | ||
40 | #define CSXthis_ctor 1 // called this() | |
41 | #define CSXsuper_ctor 2 // called super() | |
42 | #define CSXthis 4 // referenced this | |
43 | #define CSXsuper 8 // referenced super | |
44 | #define CSXlabel 0x10 // seen a label | |
45 | #define CSXreturn 0x20 // seen a return statement | |
46 | #define CSXany_ctor 0x40 // either this() or super() was called | |
47 | #define CSXhalt 0x80 // assert(0) | |
48 | ||
49 | // Flags that would not be inherited beyond scope nesting | |
50 | #define SCOPEctor 0x0001 // constructor type | |
51 | #define SCOPEcondition 0x0004 // inside static if/assert condition | |
52 | #define SCOPEdebug 0x0008 // inside debug conditional | |
53 | ||
54 | // Flags that would be inherited beyond scope nesting | |
55 | #define SCOPEnoaccesscheck 0x0002 // don't do access checks | |
56 | #define SCOPEconstraint 0x0010 // inside template constraint | |
57 | #define SCOPEinvariant 0x0020 // inside invariant code | |
58 | #define SCOPErequire 0x0040 // inside in contract code | |
59 | #define SCOPEensure 0x0060 // inside out contract code | |
60 | #define SCOPEcontract 0x0060 // [mask] we're inside contract code | |
61 | #define SCOPEctfe 0x0080 // inside a ctfe-only expression | |
62 | #define SCOPEcompile 0x0100 // inside __traits(compile) | |
63 | #define SCOPEignoresymbolvisibility 0x0200 // ignore symbol visibility (Bugzilla 15907) | |
b4c522fa IB |
64 | |
65 | #define SCOPEfree 0x8000 // is on free list | |
5b74dd0a IB |
66 | #define SCOPEfullinst 0x10000 // fully instantiate templates |
67 | #define SCOPEalias 0x20000 // inside alias declaration | |
b4c522fa IB |
68 | |
69 | struct Scope | |
70 | { | |
71 | Scope *enclosing; // enclosing Scope | |
72 | ||
73 | Module *_module; // Root module | |
74 | ScopeDsymbol *scopesym; // current symbol | |
b4c522fa IB |
75 | FuncDeclaration *func; // function we are in |
76 | Dsymbol *parent; // parent to use | |
77 | LabelStatement *slabel; // enclosing labelled statement | |
78 | SwitchStatement *sw; // enclosing switch statement | |
79 | TryFinallyStatement *tf; // enclosing try finally statement | |
72acf751 | 80 | ScopeGuardStatement *os; // enclosing scope(xxx) statement |
b4c522fa IB |
81 | Statement *sbreak; // enclosing statement that supports "break" |
82 | Statement *scontinue; // enclosing statement that supports "continue" | |
83 | ForeachStatement *fes; // if nested function for ForeachStatement, this is it | |
84 | Scope *callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__ | |
85 | int inunion; // we're processing members of a union | |
86 | int nofree; // set if shouldn't free it | |
87 | int noctor; // set if constructor calls aren't allowed | |
88 | int intypeof; // in typeof(exp) | |
89 | VarDeclaration *lastVar; // Previous symbol used to prevent goto-skips-init | |
90 | ||
91 | /* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope). | |
92 | * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint). | |
93 | * If minst && tinst, it's in instantiated code scope without speculation. | |
94 | * If !minst && tinst, it's in instantiated code scope with speculation. | |
95 | */ | |
96 | Module *minst; // root module where the instantiated templates should belong to | |
97 | TemplateInstance *tinst; // enclosing template instance | |
98 | ||
99 | unsigned callSuper; // primitive flow analysis for constructors | |
100 | unsigned *fieldinit; | |
101 | size_t fieldinit_dim; | |
102 | ||
103 | AlignDeclaration *aligndecl; // alignment for struct members | |
104 | ||
105 | LINK linkage; // linkage for external functions | |
106 | CPPMANGLE cppmangle; // C++ mangle type | |
107 | PINLINE inlining; // inlining strategy for functions | |
108 | ||
109 | Prot protection; // protection for class members | |
110 | int explicitProtection; // set if in an explicit protection attribute | |
111 | ||
112 | StorageClass stc; // storage class | |
113 | ||
114 | DeprecatedDeclaration *depdecl; // customized deprecation message | |
115 | ||
116 | unsigned flags; | |
117 | ||
118 | UserAttributeDeclaration *userAttribDecl; // user defined attributes | |
119 | ||
120 | DocComment *lastdc; // documentation comment for last symbol at this scope | |
121 | AA *anchorCounts; // lookup duplicate anchor name count | |
122 | Identifier *prevAnchor; // qualified symbol name of last doc anchor | |
123 | ||
124 | static Scope *freelist; | |
125 | static Scope *alloc(); | |
126 | static Scope *createGlobal(Module *module); | |
127 | ||
128 | Scope(); | |
129 | ||
130 | Scope *copy(); | |
131 | ||
132 | Scope *push(); | |
133 | Scope *push(ScopeDsymbol *ss); | |
134 | Scope *pop(); | |
135 | ||
136 | Scope *startCTFE(); | |
137 | Scope *endCTFE(); | |
138 | ||
139 | void mergeCallSuper(Loc loc, unsigned cs); | |
140 | ||
141 | unsigned *saveFieldInit(); | |
142 | void mergeFieldInit(Loc loc, unsigned *cses); | |
143 | ||
144 | Module *instantiatingModule(); | |
145 | ||
146 | Dsymbol *search(Loc loc, Identifier *ident, Dsymbol **pscopesym, int flags = IgnoreNone); | |
b4c522fa IB |
147 | Dsymbol *search_correct(Identifier *ident); |
148 | static const char *search_correct_C(Identifier *ident); | |
149 | Dsymbol *insert(Dsymbol *s); | |
150 | ||
151 | ClassDeclaration *getClassScope(); | |
152 | AggregateDeclaration *getStructClassScope(); | |
153 | void setNoFree(); | |
154 | ||
155 | structalign_t alignment(); | |
156 | }; |