Mercurial > projects > ddmd
annotate dmd/TypeInfoStructDeclaration.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 |
rev | line source |
---|---|
72 | 1 module dmd.TypeInfoStructDeclaration; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Type; |
5 import dmd.TY; | |
6 import dmd.MOD; | |
7 import dmd.Loc; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
8 import dmd.Parameter; |
72 | 9 import dmd.STC; |
10 import dmd.TypeStruct; | |
11 import dmd.TypeFunction; | |
12 import dmd.StructDeclaration; | |
13 import dmd.FuncDeclaration; | |
14 import dmd.Dsymbol; | |
15 import dmd.ArrayTypes; | |
16 import dmd.Scope; | |
17 import dmd.LINK; | |
18 import dmd.Id; | |
174 | 19 import dmd.Global; |
72 | 20 import dmd.TypeInfoDeclaration; |
21 import dmd.backend.dt_t; | |
22 import dmd.backend.TYM; | |
23 import dmd.backend.Util; | |
24 import dmd.expression.Util; | |
25 | |
26 import std.string : toStringz; | |
27 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 |
0 | 30 class TypeInfoStructDeclaration : TypeInfoDeclaration |
31 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
32 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
33 |
0 | 34 this(Type tinfo) |
35 { | |
178 | 36 register(); |
0 | 37 super(tinfo, 0); |
174 | 38 type = global.typeinfostruct.type; |
0 | 39 } |
40 | |
72 | 41 override void toDt(dt_t** pdt) |
0 | 42 { |
72 | 43 //printf("TypeInfoStructDeclaration.toDt() '%s'\n", toChars()); |
44 | |
174 | 45 uint offset = global.typeinfostruct.structsize; |
72 | 46 |
174 | 47 dtxoff(pdt, global.typeinfostruct.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for TypeInfo_Struct |
72 | 48 dtdword(pdt, 0); // monitor |
49 | |
50 assert(tinfo.ty == TY.Tstruct); | |
51 | |
52 TypeStruct tc = cast(TypeStruct)tinfo; | |
53 StructDeclaration sd = tc.sym; | |
54 | |
55 /* Put out: | |
56 * char[] name; | |
57 * void[] init; | |
58 * hash_t function(in void*) xtoHash; | |
59 * bool function(in void*, in void*) xopEquals; | |
60 * int function(in void*, in void*) xopCmp; | |
61 * string function(const(void)*) xtoString; | |
62 * uint m_flags; | |
63 * xgetMembers; | |
64 * xdtor; | |
65 * xpostblit; | |
66 * | |
67 * name[] | |
68 */ | |
69 | |
70 string name = sd.toPrettyChars(); | |
71 size_t namelen = name.length; | |
72 dtdword(pdt, namelen); | |
73 | |
74 //dtabytes(pdt, TYnptr, 0, namelen + 1, name); | |
75 dtxoff(pdt, toSymbol(), offset, TYM.TYnptr); | |
76 offset += namelen + 1; | |
77 | |
78 // void[] init; | |
79 dtdword(pdt, sd.structsize); // init.length | |
80 if (sd.zeroInit) | |
81 dtdword(pdt, 0); // null for 0 initialization | |
82 else | |
83 dtxoff(pdt, sd.toInitializer(), 0, TYM.TYnptr); // init.ptr | |
84 FuncDeclaration fd; | |
85 FuncDeclaration fdx; | |
86 TypeFunction tf; | |
87 Type ta; | |
88 Dsymbol s; | |
89 | |
90 TypeFunction tfeqptr; | |
174 | 91 { |
72 | 92 // bool opEqual(const T*) const; |
133
e8a741997ccf
Fix update bugs
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
131
diff
changeset
|
93 scope sc = new Scope(); |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
94 auto arguments = new Parameters; |
72 | 95 version (STRUCTTHISREF) { |
96 // arg type is ref const T | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
97 auto arg = new Parameter(STC.STCref, tc.constOf(), null, null); |
72 | 98 } else { |
99 // arg type is const T* | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
100 auto arg = new Parameter(STC.STCin, tc.pointerTo(), null, null); |
72 | 101 } |
102 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
103 arguments.push(arg); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
104 tfeqptr = new TypeFunction(arguments, Type.tbool, 0, LINK.LINKd); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
105 tfeqptr.mod = MODconst; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
106 tfeqptr = cast(TypeFunction)tfeqptr.semantic(Loc(0), sc); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
107 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
108 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
109 { |
133
e8a741997ccf
Fix update bugs
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
131
diff
changeset
|
110 scope sc = new Scope; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
111 auto arguments = new Parameters; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
112 version(STRUCTTHISREF) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
113 // arg type is ref const T |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
114 auto arg = new Parameter(STC.STCref, tc.constOf(), null, null); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
115 } else { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
116 // arg type is const T* |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
117 auto arg = new Parameter(STC.STCin, tc.pointerTo(), null, null); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
118 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
119 |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
120 arguments.push(arg); |
72 | 121 tfeqptr = new TypeFunction(arguments, Type.tbool, 0, LINK.LINKd); |
122 tfeqptr.mod = MOD.MODconst; | |
123 tfeqptr = cast(TypeFunction)tfeqptr.semantic(Loc(0), sc); | |
124 } | |
125 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
126 TypeFunction tfcmpptr; |
72 | 127 { |
128 scope Scope sc = new Scope(); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
129 auto arguments = new Parameters; |
72 | 130 version (STRUCTTHISREF) { |
131 // arg type is ref const T | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
132 auto arg = new Parameter(STC.STCref, tc.constOf(), null, null); |
72 | 133 } else { |
134 // arg type is const T* | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
135 auto arg = new Parameter(STC.STCin, tc.pointerTo(), null, null); |
72 | 136 } |
137 | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
138 arguments.push(arg); |
72 | 139 tfcmpptr = new TypeFunction(arguments, Type.tint32, 0, LINK.LINKd); |
140 tfcmpptr.mod = MOD.MODconst; | |
141 tfcmpptr = cast(TypeFunction)tfcmpptr.semantic(Loc(0), sc); | |
142 } | |
143 | |
144 s = search_function(sd, Id.tohash); | |
145 fdx = s ? s.isFuncDeclaration() : null; | |
146 if (fdx) | |
174 | 147 { |
176 | 148 fd = fdx.overloadExactMatch(global.tftohash); |
72 | 149 if (fd) |
150 dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr); | |
151 else | |
152 //fdx.error("must be declared as extern (D) uint toHash()"); | |
153 dtdword(pdt, 0); | |
154 } | |
155 else | |
156 dtdword(pdt, 0); | |
157 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
158 if (sd.eq) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
159 dtxoff(pdt, sd.eq.toSymbol(), 0, TYnptr); |
72 | 160 else |
161 dtdword(pdt, 0); | |
162 | |
163 s = search_function(sd, Id.cmp); | |
164 fdx = s ? s.isFuncDeclaration() : null; | |
165 if (fdx) | |
166 { | |
167 //printf("test1 %s, %s, %s\n", fdx.toChars(), fdx.type.toChars(), tfeqptr.toChars()); | |
168 fd = fdx.overloadExactMatch(tfcmpptr); | |
169 if (fd) | |
170 { | |
171 dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr); | |
172 //printf("test2\n"); | |
173 } | |
174 else | |
175 //fdx.error("must be declared as extern (D) int %s(%s*)", fdx.toChars(), sd.toChars()); | |
176 dtdword(pdt, 0); | |
177 } | |
178 else | |
179 dtdword(pdt, 0); | |
174 | 180 |
72 | 181 s = search_function(sd, Id.tostring); |
182 fdx = s ? s.isFuncDeclaration() : null; | |
183 if (fdx) | |
174 | 184 { |
176 | 185 fd = fdx.overloadExactMatch(global.tftostring); |
72 | 186 if (fd) |
187 dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr); | |
188 else | |
189 //fdx.error("must be declared as extern (D) char[] toString()"); | |
190 dtdword(pdt, 0); | |
191 } | |
192 else | |
193 dtdword(pdt, 0); | |
194 | |
195 // uint m_flags; | |
196 dtdword(pdt, tc.hasPointers()); | |
197 | |
198 version (DMDV2) { | |
199 // xgetMembers | |
200 FuncDeclaration sgetmembers = sd.findGetMembers(); | |
201 if (sgetmembers) | |
202 dtxoff(pdt, sgetmembers.toSymbol(), 0, TYM.TYnptr); | |
203 else | |
204 dtdword(pdt, 0); // xgetMembers | |
205 | |
206 // xdtor | |
207 FuncDeclaration sdtor = sd.dtor; | |
208 if (sdtor) | |
209 dtxoff(pdt, sdtor.toSymbol(), 0, TYM.TYnptr); | |
210 else | |
211 dtdword(pdt, 0); // xdtor | |
212 | |
213 // xpostblit | |
214 FuncDeclaration spostblit = sd.postblit; | |
215 if (spostblit) | |
216 dtxoff(pdt, spostblit.toSymbol(), 0, TYM.TYnptr); | |
217 else | |
218 dtdword(pdt, 0); // xpostblit | |
219 } | |
220 // name[] | |
221 dtnbytes(pdt, namelen + 1, toStringz(name)); | |
0 | 222 } |
223 } | |
224 |