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