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