author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 10 Jul 2008 07:31:14 +0000 | |
changeset 5 | c110eef5b9ef |
parent 2 | cfd2c393abfe |
child 14 | 1f730d82496e |
permissions | -rw-r--r-- |
1 | 1 |
"{ Package: 'cvut:fel/cface' }" |
2 |
||
3 |
"{ NameSpace: Cface }" |
|
4 |
||
5 |
CTypeNode subclass:#CUserDefinedTypeNode |
|
6 |
instanceVariableNames:'type' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'Cface-C AST' |
|
10 |
! |
|
11 |
||
12 |
!CUserDefinedTypeNode class methodsFor:'documentation'! |
|
13 |
||
14 |
history |
|
15 |
||
16 |
"Created: / 25-10-2007 / 17:44:38 / haja" |
|
17 |
"Created: #name / 25-10-2007 / 17:44:44 / haja" |
|
18 |
"Created: #name: / 25-10-2007 / 17:44:44 / haja" |
|
19 |
"Created: #id / 25-10-2007 / 17:44:44 / haja" |
|
20 |
"Created: #id: / 25-10-2007 / 17:44:44 / haja" |
|
21 |
"Created: #acceptVisitor: / 02-11-2007 / 10:45:15 / haja" |
|
22 |
"Created: #name:id: / 02-11-2007 / 13:50:44 / haja" |
|
23 |
"Deleted: #id / 02-11-2007 / 13:50:50 / haja" |
|
24 |
"Deleted: #id: / 02-11-2007 / 13:50:50 / haja" |
|
25 |
"Deleted: #name / 02-11-2007 / 13:50:50 / haja" |
|
26 |
"Deleted: #name: / 02-11-2007 / 13:50:50 / haja" |
|
27 |
"Created: #names / 02-11-2007 / 13:51:15 / haja" |
|
28 |
"Created: #reference / 02-11-2007 / 13:51:15 / haja" |
|
29 |
"Created: #reference: / 02-11-2007 / 13:51:15 / haja" |
|
30 |
"Created: #names: / 02-11-2007 / 13:52:13 / haja" |
|
31 |
"Deleted: #name:id: / 02-11-2007 / 13:52:15 / haja" |
|
32 |
"Created: #acceptNameVisitor: / 05-11-2007 / 17:34:09 / haja" |
|
33 |
"Deleted: #acceptNameVisitor: / 12-11-2007 / 09:46:54 / haja" |
|
34 |
"Created: #buildTypeCheckFor:on: / 19-12-2007 / 15:24:03 / haja" |
|
35 |
"Created: #checkFundamentalType: / 19-12-2007 / 15:26:44 / haja" |
|
36 |
"Created: #checkDefinedType: / 19-12-2007 / 15:27:03 / haja" |
|
37 |
"Created: #fundamentalTypes / 19-12-2007 / 15:28:32 / haja" |
|
38 |
"Created: #buildTypeCheckForFundamentalType:on: / 19-12-2007 / 15:31:42 / haja" |
|
39 |
"Created: #buildTypeCheckForDefinedType:on: / 19-12-2007 / 15:31:52 / haja" |
|
40 |
"Deleted: #checkDefinedType: / 19-12-2007 / 15:34:33 / haja" |
|
41 |
"Deleted: #checkFundamentalType: / 19-12-2007 / 15:34:35 / haja" |
|
42 |
"Created: #buildObjectCreationOn: / 19-12-2007 / 16:34:44 / haja" |
|
43 |
"Created: #buildObjectCreationFundamentalTypeOn: / 19-12-2007 / 16:35:39 / haja" |
|
44 |
"Created: #buildObjectCreationOnDefinedTypeOn: / 19-12-2007 / 16:36:11 / haja" |
|
45 |
"Created: #buildValueExtractionFor:on: / 19-12-2007 / 17:26:12 / haja" |
|
46 |
"Created: #buildValueExtractionForDefinedType:on: / 19-12-2007 / 17:26:43 / haja" |
|
47 |
"Created: #buildValueExtractionForFundamentalType:on: / 19-12-2007 / 17:26:57 / haja" |
|
48 |
"Created: #buildObjectCreationFor:on: / 19-12-2007 / 17:40:07 / haja" |
|
49 |
"Created: #buildObjectCreationFundamentalTypeFor:on: / 19-12-2007 / 17:40:14 / haja" |
|
50 |
"Created: #buildObjectCreationOnDefinedTypeFor:on: / 19-12-2007 / 17:40:23 / haja" |
|
51 |
"Deleted: #buildObjectCreationOnDefinedTypeFor:on: / 19-12-2007 / 17:40:46 / haja" |
|
52 |
"Created: #buildObjectCreationDefinedTypeFor:on: / 19-12-2007 / 17:42:08 / haja" |
|
53 |
"Deleted: #buildObjectCreationFundamentalTypeOn: / 19-12-2007 / 17:42:14 / haja" |
|
54 |
"Deleted: #buildObjectCreationOn: / 19-12-2007 / 17:42:15 / haja" |
|
55 |
"Deleted: #buildObjectCreationOnDefinedTypeOn: / 19-12-2007 / 17:42:16 / haja" |
|
56 |
"Created: #buildCTypeOn: / 19-12-2007 / 18:13:30 / haja" |
|
57 |
"Created: #buildTypeDescriptionOn: / 20-12-2007 / 12:11:52 / haja" |
|
58 |
! ! |
|
59 |
||
60 |
!CUserDefinedTypeNode class methodsFor:'instance creation'! |
|
61 |
||
62 |
names:aNames |
|
63 |
||
64 |
| anIdNode | |
|
65 |
||
66 |
anIdNode := self new. |
|
67 |
anIdNode names:aNames. |
|
68 |
||
69 |
^anIdNode |
|
70 |
||
71 |
"Created: / 02-11-2007 / 13:52:13 / haja" |
|
72 |
! ! |
|
73 |
||
74 |
!CUserDefinedTypeNode methodsFor:'accessing'! |
|
75 |
||
5
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
76 |
cByteSize |
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
77 |
|
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
78 |
^type cByteSize |
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
79 |
|
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
80 |
"Created: / 09-07-2008 / 19:39:45 / Jan Vrany <vranyj1@fel.cvut.cz>" |
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
81 |
! |
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
82 |
|
2
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
83 |
ffiTypeSymbol |
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
84 |
"Superclass Cface::CTypeNode says that I am responsible to implement this method" |
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
85 |
|
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
86 |
^type ffiTypeSymbol |
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
87 |
|
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
88 |
"Created: / 03-07-2008 / 22:55:48 / Jan Vrany <vranyj1@fel.cvut.cz>" |
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
89 |
! |
cfd2c393abfe
Smalltalk/X generator improvements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
90 |
|
1 | 91 |
type |
92 |
^ type |
|
93 |
||
94 |
"Created: / 12-02-2008 / 23:21:13 / janfrog" |
|
95 |
! |
|
96 |
||
97 |
type:something |
|
98 |
type := something. |
|
99 |
||
100 |
"Created: / 12-02-2008 / 23:21:13 / janfrog" |
|
101 |
! ! |
|
102 |
||
103 |
!CUserDefinedTypeNode methodsFor:'builder'! |
|
104 |
||
105 |
buildCTypeOn:aBuilder |
|
106 |
||
107 |
((reference references:EnumNode) | (reference references:StructNode) | (reference references:UnionNode)) ifTrue:[ |
|
108 |
(reference typedef) ifFalse:[ |
|
109 |
(reference references:EnumNode) ifTrue:[ aBuilder nextPutString:'enum ' ]. |
|
110 |
(reference references:StructNode) ifTrue:[ aBuilder nextPutString:'struct ' ]. |
|
111 |
(reference references:UnionNode) ifTrue:[ aBuilder nextPutString:'union ' ]. |
|
112 |
]. |
|
113 |
]. |
|
114 |
||
115 |
aBuilder idNamesWith:names. |
|
116 |
||
117 |
"Created: / 19-12-2007 / 18:13:30 / haja" |
|
118 |
! |
|
119 |
||
120 |
buildObjectCreationDefinedTypeFor:aVariable on:aBuilder |
|
121 |
||
122 |
(reference references:EnumNode) ifTrue:[ |
|
123 |
^aBuilder buildIntegerCreationFor:aVariable. |
|
124 |
]. |
|
125 |
||
126 |
^aBuilder buildPointerCreationFor:aVariable. |
|
127 |
||
128 |
"Created: / 19-12-2007 / 17:42:08 / haja" |
|
129 |
! |
|
130 |
||
131 |
buildObjectCreationFor:aVariable on:aBuilder |
|
132 |
||
133 |
self fundamentalTypes do:[:aType| (aType = names last) ifTrue:[ ^self buildObjectCreationFundamentalTypeFor:aVariable on:aBuilder. ] ]. |
|
134 |
||
135 |
^self buildObjectCreationDefinedTypeFor:aVariable on:aBuilder. |
|
136 |
||
137 |
"Created: / 19-12-2007 / 16:34:44 / haja" |
|
138 |
"Modified: / 19-12-2007 / 17:44:19 / haja" |
|
139 |
! |
|
140 |
||
141 |
buildObjectCreationFundamentalTypeFor:aVariable on:aBuilder |
|
142 |
||
143 |
(((names last = 'int') | (names last = 'short') | (names last = 'long')) & ((names includes:'unsigned')not)) ifTrue:[ |
|
144 |
^aBuilder buildIntegerCreationFor:aVariable. |
|
145 |
]. |
|
146 |
||
147 |
(((names last = 'int') | (names last = 'short') | (names last = 'long') | (names last = 'unsigned')) & ((names includes:'signed')not)) ifTrue:[ |
|
148 |
^aBuilder buildUnsignedIntegerCreationFor:aVariable. |
|
149 |
]. |
|
150 |
||
151 |
(names last = 'char') ifTrue:[ |
|
152 |
^aBuilder buildCharacterCreationFor:aVariable. |
|
153 |
]. |
|
154 |
||
155 |
(names last = 'float') ifTrue:[ |
|
156 |
^aBuilder buildFloatCreationFor:aVariable. |
|
157 |
]. |
|
158 |
(names last = 'double') ifTrue:[ |
|
159 |
^aBuilder buildDoubleCreationFor:aVariable. |
|
160 |
]. |
|
161 |
||
162 |
^aBuilder buildPointerCreationFor:aVariable. |
|
163 |
||
164 |
"Created: / 19-12-2007 / 17:40:14 / haja" |
|
165 |
! |
|
166 |
||
167 |
buildTypeCheckFor:aVariable on:aBuilder |
|
168 |
||
169 |
self fundamentalTypes do:[:aType| (aType = names last) ifTrue:[ ^self buildTypeCheckForFundamentalType:aVariable on:aBuilder. ] ]. |
|
170 |
||
171 |
^self buildTypeCheckForDefinedType:aVariable on:aBuilder. |
|
172 |
||
173 |
"Created: / 19-12-2007 / 15:24:02 / haja" |
|
174 |
! |
|
175 |
||
176 |
buildTypeCheckForDefinedType:aVariable on:aBuilder |
|
177 |
||
178 |
(reference references:EnumNode) ifTrue:[ |
|
179 |
^aBuilder buildIntegerCheckFor:aVariable. |
|
180 |
]. |
|
181 |
||
182 |
^aBuilder buildPointerCheckFor:aVariable. |
|
183 |
||
184 |
"Created: / 19-12-2007 / 15:31:52 / haja" |
|
185 |
! |
|
186 |
||
187 |
buildTypeCheckForFundamentalType:aVariable on:aBuilder |
|
188 |
||
189 |
((names last = 'int') | (names last = 'short') | (names last = 'long') | (names last = 'unsigned')) ifTrue:[ |
|
190 |
^aBuilder buildIntegerCheckFor:aVariable. |
|
191 |
]. |
|
192 |
||
193 |
(names last = 'char') ifTrue:[ |
|
194 |
^aBuilder buildCharacterCheckFor:aVariable. |
|
195 |
]. |
|
196 |
||
197 |
(names last = 'float') ifTrue:[ |
|
198 |
^aBuilder buildFloatCheckFor:aVariable. |
|
199 |
]. |
|
200 |
(names last = 'double') ifTrue:[ |
|
201 |
^aBuilder buildDoubleCheckFor:aVariable. |
|
202 |
]. |
|
203 |
||
204 |
^aBuilder buildPointerCheckFor:aVariable. |
|
205 |
||
206 |
"Created: / 19-12-2007 / 15:31:42 / haja" |
|
207 |
! |
|
208 |
||
209 |
buildTypeDescriptionOn:aBuilder |
|
210 |
||
211 |
(reference references:Cface::EnumNode) ifTrue:[ |
|
212 |
aBuilder nextPutString:'enumeration '. |
|
213 |
]. |
|
214 |
(reference references:Cface::StructNode) ifTrue:[ |
|
215 |
aBuilder nextPutString:'structure '. |
|
216 |
]. |
|
217 |
(reference references:Cface::UnionNode) ifTrue:[ |
|
218 |
aBuilder nextPutString:'union '. |
|
219 |
]. |
|
220 |
||
221 |
names do:[:aName| aBuilder nextPutString:aName asString,' ' ]. |
|
222 |
||
223 |
"Created: / 20-12-2007 / 12:11:52 / haja" |
|
224 |
! |
|
225 |
||
226 |
buildValueExtractionFor:aVariable on:aBuilder |
|
227 |
||
228 |
self fundamentalTypes do:[:aType| (aType = names last) ifTrue:[ ^self buildValueExtractionForFundamentalType:aVariable on:aBuilder. ] ]. |
|
229 |
||
230 |
^self buildValueExtractionForDefinedType:aVariable on:aBuilder. |
|
231 |
||
232 |
"Created: / 19-12-2007 / 17:26:12 / haja" |
|
233 |
! |
|
234 |
||
235 |
buildValueExtractionForDefinedType:aVariable on:aBuilder |
|
236 |
||
237 |
(reference references:EnumNode) ifTrue:[ |
|
238 |
^aBuilder buildIntegerValueExtractionFor:aVariable. |
|
239 |
]. |
|
240 |
||
241 |
^aBuilder buildPointerValueExtractionFor:aVariable. |
|
242 |
||
243 |
"Created: / 19-12-2007 / 17:26:43 / haja" |
|
244 |
! |
|
245 |
||
246 |
buildValueExtractionForFundamentalType:aVariable on:aBuilder |
|
247 |
||
248 |
(((names last = 'int') | (names last = 'short') | (names last = 'long')) & ((names includes:'unsigned')not)) ifTrue:[ |
|
249 |
^aBuilder buildIntegerValueExtractionFor:aVariable. |
|
250 |
]. |
|
251 |
||
252 |
(((names last = 'int') | (names last = 'short') | (names last = 'long') | (names last = 'unsigned')) & ((names includes:'signed')not)) ifTrue:[ |
|
253 |
^aBuilder buildUnsignedIntegerValueExtractionFor:aVariable. |
|
254 |
]. |
|
255 |
||
256 |
(names last = 'char') ifTrue:[ |
|
257 |
^aBuilder buildCharacterValueExtractionFor:aVariable. |
|
258 |
]. |
|
259 |
||
260 |
(names last = 'float') ifTrue:[ |
|
261 |
^aBuilder buildFloatValueExtractionFor:aVariable. |
|
262 |
]. |
|
263 |
(names last = 'double') ifTrue:[ |
|
264 |
^aBuilder buildDoubleValueExtractionFor:aVariable. |
|
265 |
]. |
|
266 |
||
267 |
^aBuilder buildPointerValueExtractionFor:aVariable. |
|
268 |
||
269 |
"Created: / 19-12-2007 / 17:26:57 / haja" |
|
270 |
! ! |
|
271 |
||
272 |
!CUserDefinedTypeNode methodsFor:'converting'! |
|
273 |
||
274 |
resolved |
|
275 |
type |
|
5
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
276 |
ifNil:[ self error:'User defined type ' , cName , ' not yet resolved' ]. |
1 | 277 |
^ type |
278 |
||
279 |
"Created: / 17-02-2008 / 17:56:03 / janfrog" |
|
5
c110eef5b9ef
- externalization of libraryName (now supports unix & win32 simultaneously)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
280 |
"Modified: / 09-07-2008 / 19:51:28 / Jan Vrany <vranyj1@fel.cvut.cz>" |
1 | 281 |
! ! |
282 |
||
283 |
!CUserDefinedTypeNode methodsFor:'printing'! |
|
284 |
||
285 |
printOn: stream indent: level |
|
286 |
||
287 |
stream nextPutAll: cName |
|
288 |
||
289 |
"Created: / 17-02-2008 / 18:18:11 / janfrog" |
|
290 |
! ! |
|
291 |
||
292 |
!CUserDefinedTypeNode methodsFor:'private'! |
|
293 |
||
294 |
fundamentalTypes |
|
295 |
||
296 |
" |
|
297 |
Possible combinations: |
|
298 |
||
299 |
char |
|
300 |
signed char |
|
301 |
unsigned char |
|
302 |
||
303 |
int, signed int |
|
304 |
short int, short, signed short int, signed short |
|
305 |
long int, long, signed long int,signed long |
|
306 |
||
307 |
unsigned int, unsigned |
|
308 |
unsigned short int, unsigned short |
|
309 |
unsigned long int, unsigned long |
|
310 |
||
311 |
float |
|
312 |
double |
|
313 |
long double |
|
314 |
" |
|
315 |
||
316 |
^#('char' 'short' 'int' 'long' 'float' 'double' 'void' 'signed' 'unsigned'). |
|
317 |
||
318 |
"Created: / 19-12-2007 / 15:28:32 / haja" |
|
319 |
! ! |
|
320 |
||
321 |
!CUserDefinedTypeNode methodsFor:'visiting'! |
|
322 |
||
323 |
acceptVisitor:aVisitor |
|
324 |
"Double dispatch back to the visitor, passing my type encoded in |
|
325 |
the selector (visitor pattern)" |
|
326 |
||
327 |
"stub code automatically generated - please change if required" |
|
328 |
||
329 |
^ aVisitor visitCUserDefinedTypeNode:self |
|
330 |
||
331 |
"Created: / 02-11-2007 / 13:50:44 / haja" |
|
332 |
"Modified: / 12-02-2008 / 22:59:33 / janfrog" |
|
333 |
! ! |
|
334 |
||
335 |
!CUserDefinedTypeNode class methodsFor:'documentation'! |
|
336 |
||
337 |
version |
|
338 |
^ '$Header: /opt/data/cvs/cvut-fel/cface/Cface__CUserDefinedTypeNode.st,v 1.1 2008/02/26 15:57:04 vranyj1 Exp $' |
|
339 |
! ! |