(root)/
gcc-13.2.0/
gcc/
d/
dmd/
enum.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/enum.h
       9   */
      10  
      11  #pragma once
      12  
      13  #include "dsymbol.h"
      14  #include "declaration.h"
      15  
      16  class Identifier;
      17  class Type;
      18  class Expression;
      19  
      20  class EnumDeclaration final : public ScopeDsymbol
      21  {
      22  public:
      23      /* The separate, and distinct, cases are:
      24       *  1. enum { ... }
      25       *  2. enum : memtype { ... }
      26       *  3. enum id { ... }
      27       *  4. enum id : memtype { ... }
      28       *  5. enum id : memtype;
      29       *  6. enum id;
      30       */
      31      Type *type;                 // the TypeEnum
      32      Type *memtype;              // type of the members
      33      Visibility visibility;
      34  
      35      Expression *maxval;
      36      Expression *minval;
      37      Expression *defaultval;     // default initializer
      38  private:
      39      uint8_t bitFields;
      40  public:
      41      bool isdeprecated() const;
      42      bool isdeprecated(bool v);
      43      bool added() const;
      44      bool added(bool v);
      45      bool inuse() const;
      46      bool inuse(bool v);
      47  
      48      EnumDeclaration *syntaxCopy(Dsymbol *s) override;
      49      void addMember(Scope *sc, ScopeDsymbol *sds) override;
      50      void setScope(Scope *sc) override;
      51      bool oneMember(Dsymbol **ps, Identifier *ident) override;
      52      Type *getType() override;
      53      const char *kind() const override;
      54      Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly) override;
      55      bool isDeprecated() const override;       // is Dsymbol deprecated?
      56      Visibility visible() override;
      57      bool isSpecial() const;
      58      Expression *getDefaultValue(const Loc &loc);
      59      Type *getMemtype(const Loc &loc);
      60  
      61      EnumDeclaration *isEnumDeclaration() override { return this; }
      62  
      63      Symbol *sinit;
      64      void accept(Visitor *v) override { v->visit(this); }
      65  };
      66  
      67  
      68  class EnumMember final : public VarDeclaration
      69  {
      70  public:
      71      /* Can take the following forms:
      72       *  1. id
      73       *  2. id = value
      74       *  3. type id = value
      75       */
      76      Expression *&value();
      77  
      78      // A cast() is injected to 'value' after semantic(),
      79      // but 'origValue' will preserve the original value,
      80      // or previous value + 1 if none was specified.
      81      Expression *origValue;
      82      Type *origType;
      83  
      84      EnumDeclaration *ed;
      85  
      86      EnumMember *syntaxCopy(Dsymbol *s) override;
      87      const char *kind() const override;
      88  
      89      EnumMember *isEnumMember() override { return this; }
      90      void accept(Visitor *v) override { v->visit(this); }
      91  };