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