1 2/* Compiler implementation of the D programming language 3 * Copyright (C) 1999-2022 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 16class Identifier; 17class Type; 18class Expression; 19 20class EnumDeclaration : public ScopeDsymbol 21{ 22public: 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 39 bool isdeprecated; 40 bool added; 41 int inuse; 42 43 EnumDeclaration *syntaxCopy(Dsymbol *s); 44 void addMember(Scope *sc, ScopeDsymbol *sds); 45 void setScope(Scope *sc); 46 bool oneMember(Dsymbol **ps, Identifier *ident); 47 Type *getType(); 48 const char *kind() const; 49 Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); 50 bool isDeprecated() const; // is Dsymbol deprecated? 51 Visibility visible(); 52 bool isSpecial() const; 53 Expression *getDefaultValue(const Loc &loc); 54 Type *getMemtype(const Loc &loc); 55 56 EnumDeclaration *isEnumDeclaration() { return this; } 57 58 Symbol *sinit; 59 void accept(Visitor *v) { v->visit(this); } 60}; 61 62 63class EnumMember : public VarDeclaration 64{ 65public: 66 /* Can take the following forms: 67 * 1. id 68 * 2. id = value 69 * 3. type id = value 70 */ 71 Expression *&value(); 72 73 // A cast() is injected to 'value' after semantic(), 74 // but 'origValue' will preserve the original value, 75 // or previous value + 1 if none was specified. 76 Expression *origValue; 77 Type *origType; 78 79 EnumDeclaration *ed; 80 81 EnumMember *syntaxCopy(Dsymbol *s); 82 const char *kind() const; 83 84 EnumMember *isEnumMember() { return this; } 85 void accept(Visitor *v) { v->visit(this); } 86}; 87