Debian Codegraph @

gcc/d/dmd/scope.h

raw
1
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2025 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 ErrorSink;
14 class Identifier;
15 class Module;
16 class Statement;
17 class SwitchStatement;
18 class TryFinallyStatement;
19 class LabelStatement;
20 class ForeachStatement;
21 class ClassDeclaration;
22 class AggregateDeclaration;
23 class FuncDeclaration;
24 class UserAttributeDeclaration;
25 struct DocComment;
26 struct AA;
27 class TemplateInstance;
28 class CPPNamespaceDeclaration;
29
30 #include "dsymbol.h"
31
32 enum class CSX : uint16_t
33 {
34 none = 0,
35 this_ctor = 1, // called this()
36 super_ctor = 2, // called super()
37 label = 4, // seen a label
38 return_ = 8, // seen a return statement
39 any_ctor = 0x10, // either this() or super() was called
40 halt = 0x20, // assert(0)
41 };
42
43 enum class Contract : uint8_t
44 {
45 none = 0u,
46 invariant_ = 1u,
47 require = 2u,
48 ensure = 3u,
49 };
50
51 struct Scope final
52 {
53 Scope *enclosing; // enclosing Scope
54
55 Module *_module; // Root module
56 ScopeDsymbol *scopesym; // current symbol
57 FuncDeclaration *func; // function we are in
58 VarDeclaration *varDecl; // variable we are in during semantic2
59 Dsymbol *parent; // parent to use
60 LabelStatement *slabel; // enclosing labelled statement
61 SwitchStatement *switchStatement; // enclosing switch statement
62 Statement *tryBody; // enclosing _body of TryCatchStatement or TryFinallyStatement
63 TryFinallyStatement *tryFinally; // enclosing try finally statement
64 ScopeGuardStatement *scopeGuard; // enclosing scope(xxx) statement
65 Statement *sbreak; // enclosing statement that supports "break"
66 Statement *scontinue; // enclosing statement that supports "continue"
67 ForeachStatement *fes; // if nested function for ForeachStatement, this is it
68 Scope *callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__
69 Dsymbol *inunion; // !=null if processing members of a union
70 d_bool nofree; // true if shouldn't free it
71 d_bool inLoop; // true if inside a loop (where constructor calls aren't allowed)
72 d_bool inDefaultArg; // true if inside a default argument (where __FILE__, etc are evaluated at the call site)
73 int intypeof; // in typeof(exp)
74 VarDeclaration *lastVar; // Previous symbol used to prevent goto-skips-init
75 ErrorSink *eSink; // sink for error messages
76
77 /* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
78 * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
79 * If minst && tinst, it's in instantiated code scope without speculation.
80 * If !minst && tinst, it's in instantiated code scope with speculation.
81 */
82 Module *minst; // root module where the instantiated templates should belong to
83 TemplateInstance *tinst; // enclosing template instance
84
85 CSX callSuper; // primitive flow analysis for constructors
86 CSX *fieldinit;
87 size_t fieldinit_dim;
88
89 AlignDeclaration *aligndecl; // alignment for struct members
90
91 /// C++ namespace this symbol belongs to
92 CPPNamespaceDeclaration *namespace_;
93
94 LINK linkage; // linkage for external functions
95 CPPMANGLE cppmangle; // C++ mangle type
96 PragmaDeclaration *inlining; // inlining strategy for functions
97
98 Visibility visibility; // visibility for class members
99 int explicitVisibility; // set if in an explicit visibility attribute
100
101 StorageClass stc; // storage class
102
103 DeprecatedDeclaration *depdecl; // customized deprecation message
104
105 uint16_t flags;
106 uint16_t previews; // state of preview switches
107
108 bool ctor() const;
109 bool ctor(bool v);
110 bool noAccessCheck() const;
111 bool noAccessCheck(bool v);
112 bool condition() const;
113 bool condition(bool v);
114 bool debug_() const;
115 bool debug_(bool v);
116 bool inTemplateConstraint() const;
117 bool inTemplateConstraint(bool v);
118 Contract contract() const;
119 Contract contract(Contract v);
120 bool ctfe() const;
121 bool ctfe(bool v);
122 bool traitsCompiles() const;
123 bool traitsCompiles(bool v);
124 bool ignoresymbolvisibility() const;
125 bool ignoresymbolvisibility(bool v);
126 bool inCfile() const;
127 bool inCfile(bool v);
128 bool canFree() const;
129 bool canFree(bool v);
130 bool fullinst() const;
131 bool fullinst(bool v);
132 bool ctfeBlock() const;
133 bool ctfeBlock(bool v);
134
135 UserAttributeDeclaration *userAttribDecl; // user defined attributes
136
137 DocComment *lastdc; // documentation comment for last symbol at this scope
138 AA *anchorCounts; // lookup duplicate anchor name count
139 Identifier *prevAnchor; // qualified symbol name of last doc anchor
140
141 AliasDeclaration *aliasAsg; // if set, then aliasAsg is being assigned a new value,
142 // do not set wasRead for it
143 StructDeclaration *argStruct; // elimiate recursion when looking for rvalue construction
144
145 Dsymbol *search(Loc loc, Identifier *ident, Dsymbol *&pscopesym, SearchOptFlags flags = (SearchOptFlags)SearchOpt::all);
146 };