annotate dmd/EnumDeclaration.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents b0d41ff5e0df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.EnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.AddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.CmpExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.EqualExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Loc;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
23 import dmd.Module;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TypeEnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.DYNCAST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Id;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
29 import dmd.Json;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import std.stdio : writef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
43 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
44
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 class EnumDeclaration : ScopeDsymbol
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
46 {
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
47 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
48
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
49 /* enum ident : memtype { ... }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 Type type; // the TypeEnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 Type memtype; // type of the members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
54 version (DMDV1)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
55 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 ulong maxval;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 ulong minval;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 ulong defaultval; // default initializer
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
59 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
60 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
61 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 Expression maxval;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Expression minval;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 Expression defaultval; // default initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
138
Trass3r
parents: 114
diff changeset
66 bool isdeprecated = false;
Trass3r
parents: 114
diff changeset
67 bool isdone = false; // 0: not done
Trass3r
parents: 114
diff changeset
68 // 1: semantic() successfully completed
Trass3r
parents: 114
diff changeset
69
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 this(Loc loc, Identifier id, Type memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 138
diff changeset
72 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 type = new TypeEnum(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 this.memtype = memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
79 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
81 Type t = null;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
82 if (memtype)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
83 t = memtype.syntaxCopy();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
84
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
85 EnumDeclaration ed;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
86 if (s)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
87 { ed = cast(EnumDeclaration)s;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
88 ed.memtype = t;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
89 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
90 else
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
91 ed = new EnumDeclaration(loc, ident, t);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
92 ScopeDsymbol.syntaxCopy(ed);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
93 return ed;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
96 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 Scope sce;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 //writef("EnumDeclaration.semantic(sd = %p, '%s') %s\n", sc.scopesym, sc.scopesym.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 //writef("EnumDeclaration.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (!members) // enum ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (!memtype && !isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 // Set memtype if we can to reduce fwd reference errors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 memtype = Type.tint32; // case 1) enum ident { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (symtab) // if already done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
138
Trass3r
parents: 114
diff changeset
114 if (isdone || !scope_)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 return; // semantic() already completed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 symtab = new DsymbolTable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 Scope scx = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 { sc = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 scx = scope_; // save so we don't make redundant copies
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 scope_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
126
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
127 uint dprogress_save = global.dprogress;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 if (sc.stc & STC.STCdeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 isdeprecated = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 /* The separate, and distinct, cases are:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 * 1. enum { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 * 2. enum : memtype { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 * 3. enum ident { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 * 4. enum ident : memtype { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 memtype = memtype.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 /* Check to see if memtype is forward referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (memtype.ty == TY.Tenum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 { EnumDeclaration sym = cast(EnumDeclaration)memtype.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 if (!sym.memtype || !sym.members || !sym.symtab || sym.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 // memtype is forward referenced, so try again later
87
b17640f0e4e8 Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents: 79
diff changeset
152 scope_ = scx ? scx : sc.clone();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 scope_.module_.addDeferredSemantic(this);
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
155 global.dprogress = dprogress_save;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
156 //writef("\tdeferring %s\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
138
Trass3r
parents: 114
diff changeset
160 static if (false)
Trass3r
parents: 114
diff changeset
161 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 // Decided to abandon this restriction for D 2.0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (!memtype.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 { error("base type must be of integral type, not %s", memtype.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 memtype = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
138
Trass3r
parents: 114
diff changeset
170 isdone = true;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
171 global.dprogress++;
138
Trass3r
parents: 114
diff changeset
172
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 if (isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 sce = sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 { sce = sc.push(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 sce.parent = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 if (members.dim == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 error("enum %s must have at least one member", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 int first = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 Expression elast = null;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
184 foreach (Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
186 EnumMember em = s.isEnumMember();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (!em)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 /* The e.semantic(sce) can insert other symbols, such as
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 * template instances and function literals.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 //printf(" Enum member '%s'\n",em.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 if (em.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 em.type = em.type.semantic(em.loc, sce);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 e = em.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 assert(e.dyncast() == DYNCAST.DYNCAST_EXPRESSION);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 e = e.semantic(sce);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 e = e.implicitCastTo(sce, memtype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 if (!isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 e = e.castTo(sce, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 t = memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 else if (em.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 e = e.implicitCastTo(sce, em.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 assert(isAnonymous());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 t = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 t = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 else if (first)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 t = memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 else if (em.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 t = em.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 t = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 e = new IntegerExp(em.loc, 0, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 e = e.implicitCastTo(sce, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 if (!isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 e = e.castTo(sce, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 // Set value to (elast + 1).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 // But first check that (elast != t.max)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 assert(elast);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 e = new EqualExp(TOK.TOKequal, em.loc, elast, t.getProperty(Loc(0), Id.max));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 e = e.semantic(sce);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if (e.toInteger())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 error("overflow of enum value %s", elast.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 // Now set e to (elast + 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 e = new AddExp(em.loc, elast, new IntegerExp(em.loc, 1, Type.tint32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 e = e.semantic(sce);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 e = e.castTo(sce, elast.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 elast = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 em.value = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 // Add to symbol table only after evaluating 'value'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 if (isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 /* Anonymous enum members get added to enclosing scope.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 for (Scope scxx = sce; scxx; scxx = scxx.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (scxx.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 if (!scxx.scopesym.symtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 scxx.scopesym.symtab = new DsymbolTable();
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
267 em.addMember(sce, scxx.scopesym, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 else
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
273 em.addMember(sc, this, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 /* Compute .min, .max and .default values.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 * If enum doesn't have a name, we can never identify the enum type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 * so there is no purpose for a .min, .max or .default
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 if (!isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 if (first)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 { defaultval = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 minval = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 maxval = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 { Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 /* In order to work successfully with UDTs,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 * build expressions to do the comparisons,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 * and let the semantic analyzer and constant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 * folder give us the result.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 // Compute if(e < minval)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 ec = new CmpExp(TOK.TOKlt, em.loc, e, minval);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 ec = ec.semantic(sce);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 ec = ec.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 if (ec.toInteger())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 minval = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 ec = new CmpExp(TOK.TOKgt, em.loc, e, maxval);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 ec = ec.semantic(sce);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 ec = ec.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (ec.toInteger())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 maxval = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 first = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 //printf("defaultval = %lld\n", defaultval);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 //if (defaultval) printf("defaultval: %s %s\n", defaultval.toChars(), defaultval.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 if (sc != sce)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 sce.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 //members.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
319 override bool oneMember(Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
321 if (isAnonymous())
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
322 return Dsymbol.oneMembers(members, ps);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
323 return Dsymbol.oneMember(ps);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
326 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
328 buf.writestring("enum ");
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
329 if (ident)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
330 { buf.writestring(ident.toChars());
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
331 buf.writeByte(' ');
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
332 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
333 if (memtype)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
334 {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
335 buf.writestring(": ");
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
336 memtype.toCBuffer(buf, null, hgs);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
337 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
338 if (!members)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
339 {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
340 buf.writeByte(';');
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
341 buf.writenl();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
342 return;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
343 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
344 buf.writenl();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
345 buf.writeByte('{');
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
346 buf.writenl();
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
347 foreach(Dsymbol s; members)
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
348 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
349 EnumMember em = s.isEnumMember();
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
350 if (!em)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
351 continue;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
352 //buf.writestring(" ");
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
353 em.toCBuffer(buf, hgs);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
354 buf.writeByte(',');
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
355 buf.writenl();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
356 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
357 buf.writeByte('}');
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
358 buf.writenl();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
361 override Type getType()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 return type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
366 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 return "enum";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
372 override Dsymbol search(Loc, Identifier ident, int flags)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
374 //printf("%s.EnumDeclaration.search('%s')\n", toChars(), ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 // Try one last time to resolve this enum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 semantic(scope_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 if (!members || !symtab || scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 error("is forward referenced when looking for '%s'", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 //*(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 return ScopeDsymbol.search(loc, ident, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
389 override bool isDeprecated() // is Dsymbol deprecated?
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 return isdeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
394 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
398
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
399 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
400 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
401 //writef("EnumDeclaration.toJsonBuffer()\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
402 if (isAnonymous())
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
403 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
404 if (members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
405 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
406 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
407 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
408 s.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
409 buf.writestring(",\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
410 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
411 JsonRemoveComma(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
412 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
413 return;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
414 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
416 buf.writestring("{\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
417
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
418 JsonProperty(buf, Pname, toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
419 JsonProperty(buf, Pkind, kind());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
420 if (comment)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
421 JsonProperty(buf, Pcomment, comment);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
422
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
423 if (loc.linnum)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
424 JsonProperty(buf, Pline, loc.linnum);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
425
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
426 if (memtype)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
427 JsonProperty(buf, "base", memtype.toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
428
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
429 JsonString(buf, Pmembers);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
430 buf.writestring(" : [\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
431 size_t offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
432 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
433 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
434 if (offset != buf.offset)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
435 {
96
acd69f84627e further work
Trass3r
parents: 89
diff changeset
436 buf.writestring(",\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
437 offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
438 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
439 s.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
440 }
96
acd69f84627e further work
Trass3r
parents: 89
diff changeset
441 JsonRemoveComma(buf);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
442 buf.writestring("]\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
443
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
444 buf.writestring("}\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
445 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
446
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
447 override void toDocBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
452 override EnumDeclaration isEnumDeclaration() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
454 override void toObjFile(int multiobj) // compile to .obj file
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
456 //printf("EnumDeclaration.toObjFile('%s')\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 if (isAnonymous())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 toDebug();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 type.getTypeInfo(null); // generate TypeInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 TypeEnum tc = cast(TypeEnum)type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 if (!tc.sym.defaultval || type.isZeroInit(Loc(0))) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 SC scclass = SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 if (inTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 scclass = SCcomdat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 // Generate static initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 sinit.Sclass = scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 sinit.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 version (ELFOBJ) { // Burton
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 sinit.Sseg = Segment.CDATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 version (MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 sinit.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 dtnbytes(&sinit.Sdt, tc.size(0), cast(char*)&tc.sym.defaultval);
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
487 //sinit.Sdt = tc.sym.init.toDt();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 tc.sym.defaultval.toDt(&sinit.Sdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 outdata(sinit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 void toDebug()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
501 override int cvMember(ubyte* p)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 Symbol* sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 Symbol* toInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 Classsym* stag;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 if (!sinit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 stag = fake_classsym(Id.ClassInfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 Identifier ident_save = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 if (!ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 ident = Lexer.uniqueId("__enum");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 s = toSymbolX("__init", SCextern, stag.Stype, "Z");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 ident = ident_save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 s.Sfl = FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 s.Sflags |= SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 sinit = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 return sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
529 };