(root)/
gcc-13.2.0/
gcc/
d/
dmd/
scope.h
       1  
       2  /* Compiler implementation of the D programming language
       3   * Copyright (C) 1999-2023 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 class CSX : uint16_t
      32  {
      33      none       = 0,
      34      this_ctor  = 1,      // called this()
      35      super_ctor = 2,      // called super()
      36      label      = 4,      // seen a label
      37      return_    = 8,      // seen a return statement
      38      any_ctor   = 0x10,   // either this() or super() was called
      39      halt       = 0x20,   // assert(0)
      40  };
      41  
      42  enum class SCOPE
      43  {
      44      // Flags that would not be inherited beyond scope nesting
      45      ctor          = 0x0001,  // constructor type
      46      noaccesscheck = 0x0002,  // don't do access checks
      47      condition     = 0x0004,  // inside static if/assert condition
      48      debug_        = 0x0008,  // inside debug conditional
      49  
      50      // Flags that would be inherited beyond scope nesting
      51      constraint    = 0x0010,  // inside template constraint
      52      invariant_    = 0x0020,  // inside invariant code
      53      require       = 0x0040,  // inside in contract code
      54      ensure        = 0x0060,  // inside out contract code
      55      contract      = 0x0060,  // [mask] we're inside contract code
      56      ctfe          = 0x0080,  // inside a ctfe-only expression
      57      compile       = 0x0100,  // inside __traits(compile)
      58      ignoresymbolvisibility = 0x0200,  // ignore symbol visibility (Bugzilla 15907)
      59  
      60      Cfile         = 0x0800,  // C semantics apply
      61      free          = 0x8000,  // is on free list
      62      fullinst      = 0x10000, // fully instantiate templates
      63  };
      64  
      65  struct Scope
      66  {
      67      Scope *enclosing;           // enclosing Scope
      68  
      69      Module *_module;            // Root module
      70      ScopeDsymbol *scopesym;     // current symbol
      71      FuncDeclaration *func;      // function we are in
      72      VarDeclaration  *varDecl;   // variable we are in during semantic2
      73      Dsymbol *parent;            // parent to use
      74      LabelStatement *slabel;     // enclosing labelled statement
      75      SwitchStatement *sw;        // enclosing switch statement
      76      Statement *tryBody;         // enclosing _body of TryCatchStatement or TryFinallyStatement
      77      TryFinallyStatement *tf;    // enclosing try finally statement
      78      ScopeGuardStatement *os;       // enclosing scope(xxx) statement
      79      Statement *sbreak;          // enclosing statement that supports "break"
      80      Statement *scontinue;       // enclosing statement that supports "continue"
      81      ForeachStatement *fes;      // if nested function for ForeachStatement, this is it
      82      Scope *callsc;              // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__
      83      Dsymbol *inunion;           // !=null if processing members of a union
      84      d_bool nofree;                // true if shouldn't free it
      85      d_bool inLoop;                // true if inside a loop (where constructor calls aren't allowed)
      86      int intypeof;               // in typeof(exp)
      87      VarDeclaration *lastVar;    // Previous symbol used to prevent goto-skips-init
      88  
      89      /* If  minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
      90       * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
      91       * If  minst &&  tinst, it's in instantiated code scope without speculation.
      92       * If !minst &&  tinst, it's in instantiated code scope with speculation.
      93       */
      94      Module *minst;              // root module where the instantiated templates should belong to
      95      TemplateInstance *tinst;    // enclosing template instance
      96  
      97      CSX callSuper;              // primitive flow analysis for constructors
      98      CSX *fieldinit;
      99      size_t fieldinit_dim;
     100  
     101      AlignDeclaration *aligndecl;    // alignment for struct members
     102  
     103      /// C++ namespace this symbol belongs to
     104      CPPNamespaceDeclaration *namespace_;
     105  
     106      LINK linkage;               // linkage for external functions
     107      CPPMANGLE cppmangle;        // C++ mangle type
     108      PragmaDeclaration *inlining; // inlining strategy for functions
     109  
     110      Visibility visibility;            // visibility for class members
     111      int explicitVisibility;     // set if in an explicit visibility 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      AliasDeclaration *aliasAsg; // if set, then aliasAsg is being assigned a new value,
     126                                  // do not set wasRead for it
     127  
     128      Dsymbol *search(const Loc &loc, Identifier *ident, Dsymbol **pscopesym, int flags = IgnoreNone);
     129  };