annotate dmd/TypeEnum.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents 0c8cc2a10f99
children cd48cb899aee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeEnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 93
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.EnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.CppMangleState;
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
19 import dmd.StringExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TypeInfoEnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TY;
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
24 import dmd.MOD;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 class TypeEnum : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 EnumDeclaration sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 this(EnumDeclaration sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 156
diff changeset
35 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 super(TY.Tenum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this.sym = sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
40 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
45 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 if (!sym.memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 error(loc, "enum %s is forward referenced", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 return 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 return sym.memtype.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
55 override uint alignsize()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
57 if (!sym.memtype)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
58 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
59 debug writef("1: ");
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
60
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
61 error(Loc(0), "enum %s is forward referenced", sym.toChars());
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
62 return 4;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
63 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
64 return sym.memtype.alignsize();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
66
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
67 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
69 if (mod)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
70 return super.toChars();
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
71 return sym.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
74 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 //printf("TypeEnum::semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 //sym.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
81 override Dsymbol toDsymbol(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
86 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 string name = sym.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 buf.printf("%s", name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
93 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
95 if (mod != this.mod)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
96 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
97 toCBuffer3(buf, hgs, mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
98 return;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
99 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 0
diff changeset
100 buf.writestring(sym.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
103 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Dsymbol s = sym.search(e.loc, ident, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (ident is Id.max ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 ident is Id.min ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 ident is Id.init_ ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 ident is Id.stringof_ ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 !sym.memtype
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 return getProperty(e.loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 return sym.memtype.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 EnumMember m = s.isEnumMember();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 Expression em = m.value.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 em.loc = e.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 return em;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
130 override Expression getProperty(Loc loc, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
156
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
132 Expression e;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
133
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
134 if (ident is Id.max)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
135 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
136 if (!sym.maxval)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
137 goto Lfwd;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
138 e = sym.maxval;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
139 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
140 else if (ident is Id.min)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
141 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
142 if (!sym.minval)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
143 goto Lfwd;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
144 e = sym.minval;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
145 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
146 else if (ident is Id.init_)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
147 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
148 e = defaultInitLiteral(loc);
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
149 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
150 else if (ident is Id.stringof_)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
151 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
152 string s = toChars();
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
153 e = new StringExp(loc, s, 'c');
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
154 Scope sc;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
155 e = e.semantic(sc);
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
156 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
157 else if (ident is Id.mangleof_)
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
158 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
159 e = Type.getProperty(loc, ident);
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
160 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
161 else
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
162 {
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
163 e = toBasetype().getProperty(loc, ident);
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
164 }
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
165 return e;
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
166
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
167 Lfwd:
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
168 error(loc, "forward reference of %s.%s", toChars(), ident.toChars());
0c8cc2a10f99 + ArrayInitializer.toAssocArrayLiteral()
trass3r
parents: 135
diff changeset
169 return new ErrorExp();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
172 override bool isintegral()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
174 return sym.memtype.isintegral();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
177 override bool isfloating()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
179 return sym.memtype.isfloating();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
180 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
181
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
182 override bool isreal()
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
183 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
184 return sym.memtype.isreal();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
185 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
186
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
187 override bool isimaginary()
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
188 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
189 return sym.memtype.isimaginary();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
190 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
191
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
192 override bool iscomplex()
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
193 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
194 return sym.memtype.iscomplex();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
195 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
196
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
197 override bool checkBoolean()
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
198 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
199 return sym.memtype.checkBoolean();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
200 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
201
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
202 override bool isAssignable()
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
203 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
204 return sym.memtype.isAssignable();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
207 override bool isscalar()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
209 return sym.memtype.isscalar();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
212 override bool isunsigned()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 return sym.memtype.isunsigned();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
217 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 //printf("TypeEnum::implicitConvTo()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 if (ty == to.ty && sym == (cast(TypeEnum)to).sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 m = (mod == to.mod) ? MATCHexact : MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 else if (sym.memtype.implicitConvTo(to))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 m = MATCHconvert; // match with conversions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 m = MATCHnomatch; // no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
231 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
233 if (equals(to))
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
234 return MATCHexact;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
235 if (ty == to.ty && sym == (cast(TypeEnum)to).sym &&
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
236 MODimplicitConv(mod, to.mod))
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
237 return MATCHconst;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
238 return MATCHnomatch;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
241 override Type toBasetype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
243 if (sym.scope_)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
244 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
245 sym.semantic(null); // attempt to resolve forward reference
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
246 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 if (!sym.memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 debug writef("2: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 error(sym.loc, "enum %s is forward referenced", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 return tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 return sym.memtype.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
257 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 printf("TypeEnum::defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 // Initialize to first member of enum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 //printf("%s\n", sym.defaultval.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (!sym.defaultval)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 error(loc, "forward reference of %s.init", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 return sym.defaultval;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
272 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (!sym.defaultval)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 debug writef("3: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 error(loc, "enum %s is forward referenced", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 return sym.defaultval.isBool(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
283 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
285 // Extra check
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
286 if (tparam && tparam.ty == Tenum)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
287 {
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
288 TypeEnum tp = cast(TypeEnum)tparam;
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
289
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
290 if (sym != tp.sym)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
291 return MATCHnomatch;
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
292 }
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
293 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
296 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 return new TypeInfoEnumDeclaration(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
301 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 return toBasetype().hasPointers();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
313 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 return sym.memtype.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
317 }