Merge dmd upstream 6243fa6d2
[official-gcc.git] / gcc / d / dmd / enum.h
blobce500579e17382ad3de8553ff92b1493ee85d4a9
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2018 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 */
11 #pragma once
13 #include "root/root.h"
14 #include "dsymbol.h"
15 #include "declaration.h"
16 #include "tokens.h"
18 class Identifier;
19 class Type;
20 class Expression;
21 class VarDeclaration;
23 class EnumDeclaration : public ScopeDsymbol
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;
34 Type *type; // the TypeEnum
35 Type *memtype; // type of the members
36 Prot protection;
38 Expression *maxval;
39 Expression *minval;
40 Expression *defaultval; // default initializer
42 bool isdeprecated;
43 bool added;
44 int inuse;
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);
62 EnumDeclaration *isEnumDeclaration() { return this; }
64 Symbol *sinit;
65 void accept(Visitor *v) { v->visit(this); }
69 class EnumMember : public VarDeclaration
71 public:
72 /* Can take the following forms:
73 * 1. id
74 * 2. id = value
75 * 3. type id = value
77 Expression *&value();
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;
85 EnumDeclaration *ed;
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);
93 EnumMember *isEnumMember() { return this; }
94 void accept(Visitor *v) { v->visit(this); }