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