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