d: Merge upstream dmd ff57fec515, druntime ff57fec515, phobos 17bafda79.
[official-gcc.git] / gcc / d / dmd / enum.h
blobe17e8cf5b0afdb598569beb922de8fae1f858dc0
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 */
11 #pragma once
13 #include "dsymbol.h"
14 #include "declaration.h"
16 class Identifier;
17 class Type;
18 class Expression;
20 class EnumDeclaration final : public ScopeDsymbol
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;
31 Type *type; // the TypeEnum
32 Type *memtype; // type of the members
33 Visibility visibility;
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);
48 EnumDeclaration *syntaxCopy(Dsymbol *s) override;
49 void setScope(Scope *sc) override;
50 bool oneMember(Dsymbol **ps, Identifier *ident) override;
51 Type *getType() override;
52 const char *kind() const override;
53 bool isDeprecated() const override; // is Dsymbol deprecated?
54 Visibility visible() override;
55 bool isSpecial() const;
56 Expression *getDefaultValue(const Loc &loc);
57 Type *getMemtype(const Loc &loc);
59 EnumDeclaration *isEnumDeclaration() override { return this; }
61 Symbol *sinit;
62 void accept(Visitor *v) override { v->visit(this); }
66 class EnumMember final : public VarDeclaration
68 public:
69 /* Can take the following forms:
70 * 1. id
71 * 2. id = value
72 * 3. type id = value
74 Expression *&value();
76 // A cast() is injected to 'value' after semantic(),
77 // but 'origValue' will preserve the original value,
78 // or previous value + 1 if none was specified.
79 Expression *origValue;
80 Type *origType;
82 EnumDeclaration *ed;
84 EnumMember *syntaxCopy(Dsymbol *s) override;
85 const char *kind() const override;
87 EnumMember *isEnumMember() override { return this; }
88 void accept(Visitor *v) override { v->visit(this); }