0
|
1 module dmd.TypeEnum;
|
|
2
|
|
3 import dmd.Type;
|
|
4 import dmd.EnumDeclaration;
|
|
5 import dmd.Scope;
|
|
6 import dmd.Loc;
|
|
7 import dmd.Id;
|
|
8 import dmd.ErrorExp;
|
|
9 import dmd.Dsymbol;
|
|
10 import dmd.EnumMember;
|
|
11 import dmd.OutBuffer;
|
|
12 import dmd.HdrGenState;
|
|
13 import dmd.Expression;
|
|
14 import dmd.Identifier;
|
|
15 import dmd.MATCH;
|
|
16 import dmd.OutBuffer;
|
|
17 import dmd.CppMangleState;
|
|
18 import dmd.TypeInfoDeclaration;
|
|
19 import dmd.TypeInfoEnumDeclaration;
|
|
20 import dmd.ArrayTypes;
|
|
21 import dmd.TY;
|
|
22 import dmd.Util;
|
|
23
|
|
24 import dmd.backend.TYPE;
|
|
25
|
|
26 class TypeEnum : Type
|
|
27 {
|
|
28 EnumDeclaration sym;
|
|
29
|
|
30 this(EnumDeclaration sym)
|
|
31 {
|
|
32 super(TY.Tenum);
|
|
33 this.sym = sym;
|
|
34 }
|
|
35
|
|
36 version (DumbClone) {
|
|
37 } else {
|
|
38 Type clone()
|
|
39 {
|
|
40 assert(false);
|
|
41 }
|
|
42 }
|
|
43 Type syntaxCopy()
|
|
44 {
|
|
45 assert(false);
|
|
46 }
|
|
47
|
|
48 ulong size(Loc loc)
|
|
49 {
|
|
50 if (!sym.memtype)
|
|
51 {
|
|
52 error(loc, "enum %s is forward referenced", sym.toChars());
|
|
53 return 4;
|
|
54 }
|
|
55 return sym.memtype.size(loc);
|
|
56 }
|
|
57
|
|
58 uint alignsize()
|
|
59 {
|
|
60 assert(false);
|
|
61 }
|
|
62
|
|
63 string toChars()
|
|
64 {
|
|
65 assert(false);
|
|
66 }
|
|
67
|
|
68 Type semantic(Loc loc, Scope sc)
|
|
69 {
|
|
70 //printf("TypeEnum::semantic() %s\n", toChars());
|
|
71 //sym.semantic(sc);
|
|
72 return merge();
|
|
73 }
|
|
74
|
|
75 Dsymbol toDsymbol(Scope sc)
|
|
76 {
|
|
77 return sym;
|
|
78 }
|
|
79
|
|
80 void toDecoBuffer(OutBuffer buf, int flag)
|
|
81 {
|
|
82 string name = sym.mangle();
|
|
83 Type.toDecoBuffer(buf, flag);
|
|
84 buf.printf("%s", name);
|
|
85 }
|
|
86
|
|
87 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, int mod)
|
|
88 {
|
|
89 assert(false);
|
|
90 }
|
|
91
|
|
92 Expression dotExp(Scope sc, Expression e, Identifier ident)
|
|
93 {
|
|
94 version (LOGDOTEXP) {
|
|
95 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars());
|
|
96 }
|
|
97 Dsymbol s = sym.search(e.loc, ident, 0);
|
|
98 if (!s)
|
|
99 {
|
|
100 if (ident is Id.max ||
|
|
101 ident is Id.min ||
|
|
102 ident is Id.init_ ||
|
|
103 ident is Id.stringof_ ||
|
|
104 !sym.memtype
|
|
105 )
|
|
106 {
|
|
107 return getProperty(e.loc, ident);
|
|
108 }
|
|
109
|
|
110 return sym.memtype.dotExp(sc, e, ident);
|
|
111 }
|
|
112
|
|
113 EnumMember m = s.isEnumMember();
|
|
114 Expression em = m.value.copy();
|
|
115 em.loc = e.loc;
|
|
116 return em;
|
|
117 }
|
|
118
|
|
119 Expression getProperty(Loc loc, Identifier ident)
|
|
120 {
|
|
121 assert(false);
|
|
122 }
|
|
123
|
|
124 bool isintegral()
|
|
125 {
|
|
126 return true;
|
|
127 }
|
|
128
|
|
129 bool isfloating()
|
|
130 {
|
|
131 return false;
|
|
132 }
|
|
133
|
|
134 bool isscalar()
|
|
135 {
|
|
136 return true;
|
|
137 //return sym.memtype.isscalar();
|
|
138 }
|
|
139
|
|
140 bool isunsigned()
|
|
141 {
|
|
142 return sym.memtype.isunsigned();
|
|
143 }
|
|
144
|
|
145 MATCH implicitConvTo(Type to)
|
|
146 {
|
|
147 MATCH m;
|
|
148
|
|
149 //printf("TypeEnum::implicitConvTo()\n");
|
|
150 if (ty == to.ty && sym == (cast(TypeEnum)to).sym)
|
|
151 m = (mod == to.mod) ? MATCHexact : MATCHconst;
|
|
152 else if (sym.memtype.implicitConvTo(to))
|
|
153 m = MATCHconvert; // match with conversions
|
|
154 else
|
|
155 m = MATCHnomatch; // no match
|
|
156 return m;
|
|
157 }
|
|
158
|
|
159 MATCH constConv(Type to)
|
|
160 {
|
|
161 assert(false);
|
|
162 }
|
|
163
|
|
164 Type toBasetype()
|
|
165 {
|
|
166 if (!sym.memtype)
|
|
167 {
|
|
168 debug writef("2: ");
|
|
169 error(sym.loc, "enum %s is forward referenced", sym.toChars());
|
|
170 return tint32;
|
|
171 }
|
|
172
|
|
173 return sym.memtype.toBasetype();
|
|
174 }
|
|
175
|
|
176 Expression defaultInit(Loc loc)
|
|
177 {
|
|
178 version (LOGDEFAULTINIT) {
|
|
179 printf("TypeEnum::defaultInit() '%s'\n", toChars());
|
|
180 }
|
|
181 // Initialize to first member of enum
|
|
182 //printf("%s\n", sym.defaultval.type.toChars());
|
|
183 if (!sym.defaultval)
|
|
184 {
|
|
185 error(loc, "forward reference of %s.init", toChars());
|
|
186 return new ErrorExp();
|
|
187 }
|
|
188 return sym.defaultval;
|
|
189 }
|
|
190
|
|
191 bool isZeroInit(Loc loc)
|
|
192 {
|
|
193 if (!sym.defaultval)
|
|
194 {
|
|
195 debug writef("3: ");
|
|
196 error(loc, "enum %s is forward referenced", sym.toChars());
|
|
197 return 0;
|
|
198 }
|
|
199 return sym.defaultval.isBool(false);
|
|
200 }
|
|
201
|
|
202 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
|
|
203 {
|
|
204 assert(false);
|
|
205 }
|
|
206
|
|
207 TypeInfoDeclaration getTypeInfoDeclaration()
|
|
208 {
|
|
209 return new TypeInfoEnumDeclaration(this);
|
|
210 }
|
|
211
|
|
212 bool hasPointers()
|
|
213 {
|
|
214 return toBasetype().hasPointers();
|
|
215 }
|
|
216
|
|
217 version (CPP_MANGLE) {
|
|
218 void toCppMangle(OutBuffer buf, CppMangleState* cms)
|
|
219 {
|
|
220 assert(false);
|
|
221 }
|
|
222 }
|
|
223
|
|
224 type* toCtype()
|
|
225 {
|
|
226 return sym.memtype.toCtype();
|
|
227 }
|
|
228 } |