1 2 /* Compiler implementation of the D programming language 3 * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved 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) 64 65 #define SCOPEfree 0x8000 // is on free list 66 #define SCOPEfullinst 0x10000 // fully instantiate templates 67 #define SCOPEalias 0x20000 // inside alias declaration 68 69 struct Scope 70 { 71 Scope *enclosing; // enclosing Scope 72 73 Module *_module; // Root module 74 ScopeDsymbol *scopesym; // current symbol 75 ScopeDsymbol *sds; // if in static if, and declaring new symbols, 76 // sds gets the addMember() 77 FuncDeclaration *func; // function we are in 78 Dsymbol *parent; // parent to use 79 LabelStatement *slabel; // enclosing labelled statement 80 SwitchStatement *sw; // enclosing switch statement 81 TryFinallyStatement *tf; // enclosing try finally statement 82 OnScopeStatement *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 int inunion; // we're processing members of a union 88 int nofree; // set if shouldn't free it 89 int noctor; // set if 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 callSuper; // primitive flow analysis for constructors 102 unsigned *fieldinit; 103 size_t fieldinit_dim; 104 105 AlignDeclaration *aligndecl; // alignment for struct members 106 107 LINK linkage; // linkage for external functions 108 CPPMANGLE cppmangle; // C++ mangle type 109 PINLINE inlining; // inlining strategy for functions 110 111 Prot protection; // protection for class members 112 int explicitProtection; // set if in an explicit protection attribute 113 114 StorageClass stc; // storage class 115 116 DeprecatedDeclaration *depdecl; // customized deprecation message 117 118 unsigned flags; 119 120 UserAttributeDeclaration *userAttribDecl; // user defined attributes 121 122 DocComment *lastdc; // documentation comment for last symbol at this scope 123 AA *anchorCounts; // lookup duplicate anchor name count 124 Identifier *prevAnchor; // qualified symbol name of last doc anchor 125 126 static Scope *freelist; 127 static Scope *alloc(); 128 static Scope *createGlobal(Module *module); 129 130 Scope(); 131 132 Scope *copy(); 133 134 Scope *push(); 135 Scope *push(ScopeDsymbol *ss); 136 Scope *pop(); 137 138 Scope *startCTFE(); 139 Scope *endCTFE(); 140 141 void mergeCallSuper(Loc loc, unsigned cs); 142 143 unsigned *saveFieldInit(); 144 void mergeFieldInit(Loc loc, unsigned *cses); 145 146 Module *instantiatingModule(); 147 148 Dsymbol *search(Loc loc, Identifier *ident, Dsymbol **pscopesym, int flags = IgnoreNone); 149 static void deprecation10378(Loc loc, Dsymbol *sold, Dsymbol *snew); 150 Dsymbol *search_correct(Identifier *ident); 151 static const char *search_correct_C(Identifier *ident); 152 Dsymbol *insert(Dsymbol *s); 153 154 ClassDeclaration *getClassScope(); 155 AggregateDeclaration *getStructClassScope(); 156 void setNoFree(); 157 158 structalign_t alignment(); 159 }; 160