scope.h revision 1.1.1.1
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 13class Dsymbol; 14class ScopeDsymbol; 15class Identifier; 16class Module; 17class Statement; 18class SwitchStatement; 19class TryFinallyStatement; 20class LabelStatement; 21class ForeachStatement; 22class ClassDeclaration; 23class AggregateDeclaration; 24class FuncDeclaration; 25class UserAttributeDeclaration; 26struct DocComment; 27struct AA; 28class TemplateInstance; 29 30#include "dsymbol.h" 31 32#if __GNUC__ 33// Requires a full definition for LINK 34#include "globals.h" 35#else 36enum LINK; 37enum 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#define SCOPEfullinst 0x1000 // fully instantiate templates 65 66#define SCOPEfree 0x8000 // is on free list 67 68struct Scope 69{ 70 Scope *enclosing; // enclosing Scope 71 72 Module *_module; // Root module 73 ScopeDsymbol *scopesym; // current symbol 74 ScopeDsymbol *sds; // if in static if, and declaring new symbols, 75 // sds gets the addMember() 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 TryFinallyStatement *tf; // enclosing try finally statement 81 OnScopeStatement *os; // enclosing scope(xxx) statement 82 Statement *sbreak; // enclosing statement that supports "break" 83 Statement *scontinue; // enclosing statement that supports "continue" 84 ForeachStatement *fes; // if nested function for ForeachStatement, this is it 85 Scope *callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__ 86 int inunion; // we're processing members of a union 87 int nofree; // set if shouldn't free it 88 int noctor; // set if constructor calls aren't allowed 89 int intypeof; // in typeof(exp) 90 VarDeclaration *lastVar; // Previous symbol used to prevent goto-skips-init 91 92 /* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope). 93 * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint). 94 * If minst && tinst, it's in instantiated code scope without speculation. 95 * If !minst && tinst, it's in instantiated code scope with speculation. 96 */ 97 Module *minst; // root module where the instantiated templates should belong to 98 TemplateInstance *tinst; // enclosing template instance 99 100 unsigned callSuper; // primitive flow analysis for constructors 101 unsigned *fieldinit; 102 size_t fieldinit_dim; 103 104 AlignDeclaration *aligndecl; // alignment for struct members 105 106 LINK linkage; // linkage for external functions 107 CPPMANGLE cppmangle; // C++ mangle type 108 PINLINE inlining; // inlining strategy for functions 109 110 Prot protection; // protection for class members 111 int explicitProtection; // set if in an explicit protection attribute 112 113 StorageClass stc; // storage class 114 115 DeprecatedDeclaration *depdecl; // customized deprecation message 116 117 unsigned flags; 118 119 UserAttributeDeclaration *userAttribDecl; // user defined attributes 120 121 DocComment *lastdc; // documentation comment for last symbol at this scope 122 AA *anchorCounts; // lookup duplicate anchor name count 123 Identifier *prevAnchor; // qualified symbol name of last doc anchor 124 125 static Scope *freelist; 126 static Scope *alloc(); 127 static Scope *createGlobal(Module *module); 128 129 Scope(); 130 131 Scope *copy(); 132 133 Scope *push(); 134 Scope *push(ScopeDsymbol *ss); 135 Scope *pop(); 136 137 Scope *startCTFE(); 138 Scope *endCTFE(); 139 140 void mergeCallSuper(Loc loc, unsigned cs); 141 142 unsigned *saveFieldInit(); 143 void mergeFieldInit(Loc loc, unsigned *cses); 144 145 Module *instantiatingModule(); 146 147 Dsymbol *search(Loc loc, Identifier *ident, Dsymbol **pscopesym, int flags = IgnoreNone); 148 static void deprecation10378(Loc loc, Dsymbol *sold, Dsymbol *snew); 149 Dsymbol *search_correct(Identifier *ident); 150 static const char *search_correct_C(Identifier *ident); 151 Dsymbol *insert(Dsymbol *s); 152 153 ClassDeclaration *getClassScope(); 154 AggregateDeclaration *getStructClassScope(); 155 void setNoFree(); 156 157 structalign_t alignment(); 158}; 159