source: dev/trunk/jenga/src/smoothie/Type.cpp@ 192

Last change on this file since 192 was 192, checked in by dai_9181, 17 years ago
File size: 7.6 KB
Line 
1#include <jenga/include/smoothie/Smoothie.h>
2#include <jenga/include/smoothie/Class.h>
3#include <jenga/include/smoothie/SmoothieException.h>
4
5using namespace std;
6
7const int Type::basicTypeList[] = {
8 DEF_BYTE,
9 DEF_SBYTE,
10 DEF_WORD,
11 DEF_INTEGER,
12 DEF_DWORD,
13 DEF_LONG,
14 DEF_QWORD,
15 DEF_INT64,
16
17 DEF_SINGLE,
18 DEF_DOUBLE,
19
20 DEF_BOOLEAN,
21
22 DEF_PTR_VOID,
23
24 DEF_ANY,
25
26 DEF_NON
27};
28
29const string Type::basicTypeNameList[] = {
30 "Byte",
31 "SByte",
32 "Word",
33 "Integer",
34 "DWord",
35 "Long",
36 "QWord",
37 "Int64",
38
39 "Single",
40 "Double",
41
42 "Boolean",
43
44 "VoidPtr",
45
46 "Any",
47
48 ""
49};
50
51bool Type::StringToBasicType( const string &typeName, int &basicType ){
52 for( int i=0; ; i++ ){
53 if( basicTypeList[i] == DEF_NON ){
54 break;
55 }
56 if( basicTypeNameList[i] == typeName ){
57 basicType = basicTypeList[i];
58 return true;
59 }
60 }
61 return false;
62}
63const char *Type::BasicTypeToCharPtr( const Type &type )
64{
65 for( int i=0; ; i++ ){
66 if( basicTypeList[i] == DEF_NON ){
67 break;
68 }
69 if( basicTypeList[i] == type.GetBasicType() ){
70 return basicTypeNameList[i].c_str();
71 }
72 }
73 return NULL;
74}
75
76int Type::GetBasicSize( int basicType )
77{
78
79 // 基本型
80 switch( basicType ){
81 case DEF_SBYTE:
82 case DEF_BYTE:
83 case DEF_BOOLEAN:
84 return sizeof(BYTE);
85
86 case DEF_INTEGER:
87 case DEF_WORD:
88 return sizeof(WORD);
89
90 case DEF_LONG:
91 case DEF_DWORD:
92 return sizeof(DWORD);
93
94 case DEF_INT64:
95 case DEF_QWORD:
96 return sizeof(_int64);
97
98 case DEF_DOUBLE:
99 return sizeof(double);
100 case DEF_SINGLE:
101 return sizeof(float);
102 }
103
104 // ポインタ
105 if(IsPointer( basicType )){
106 return PTR_SIZE;
107 }
108
109 // オブジェクト
110 if(basicType==DEF_OBJECT){
111 return PTR_SIZE;
112 }
113
114 SmoothieException::Throw();
115
116 return 0;
117}
118
119
120bool Type::Equals( const Type &type ) const
121{
122 if( basicType == type.basicType ){
123 if( NATURAL_TYPE( basicType ) == DEF_OBJECT
124 || NATURAL_TYPE( basicType ) == DEF_STRUCT ){
125
126 if( index == type.index ){
127 return true;
128 }
129
130 }
131 else{
132 return true;
133 }
134 }
135 return false;
136}
137
138int Type::GetBasicSize() const
139{
140 return GetBasicSize( basicType );
141}
142int Type::GetSize() const
143{
144
145 // 基本型
146 switch( basicType ){
147 case DEF_LONG:
148 if(index==LITERAL_NULL||index==LITERAL_M128_0||index==LITERAL_0_255){
149 return sizeof(BYTE);
150 }
151 else if(index==LITERAL_M32768_0||index==LITERAL_0_65535){
152 return sizeof(WORD);
153 }
154 return sizeof(DWORD);
155
156 case DEF_SBYTE:
157 case DEF_BYTE:
158 case DEF_BOOLEAN:
159 return sizeof(BYTE);
160
161 case DEF_INTEGER:
162 case DEF_WORD:
163 return sizeof(WORD);
164
165 case DEF_DWORD:
166 return sizeof(DWORD);
167
168 case DEF_INT64:
169 case DEF_QWORD:
170 return sizeof(_int64);
171
172 case DEF_DOUBLE:
173 return sizeof(double);
174 case DEF_SINGLE:
175 return sizeof(float);
176 }
177
178 // ポインタ
179 if(IsPointer()){
180 return PTR_SIZE;
181 }
182
183 // 構造体
184 if( basicType == DEF_STRUCT ){
185 if( !pClass ){
186 SmoothieException::Throw();
187 return 0;
188 }
189
190 return pClass->GetSize();
191 }
192
193 // オブジェクト
194 if(basicType==DEF_OBJECT){
195 if( GetClass().IsInterface() ){
196 // vtblOffsetのサイズを含める
197 return PTR_SIZE*2;
198 }
199 return PTR_SIZE;
200 }
201
202 SmoothieException::Throw();
203 return 0;
204}
205
206bool Type::IsNull() const{
207 if( basicType == DEF_NON ){
208 return true;
209 }
210 return false;
211}
212
213bool Type::IsByte() const{
214 if( basicType == DEF_BYTE ){
215 return true;
216 }
217 return false;
218}
219bool Type::IsSByte() const{
220 if( basicType == DEF_SBYTE ){
221 return true;
222 }
223 return false;
224}
225bool Type::IsWord() const{
226 if( basicType == DEF_WORD ){
227 return true;
228 }
229 return false;
230}
231bool Type::IsInteger() const{
232 if( basicType == DEF_INTEGER ){
233 return true;
234 }
235 return false;
236}
237bool Type::IsDWord() const{
238 if( basicType == DEF_DWORD ){
239 return true;
240 }
241 return false;
242}
243bool Type::IsLong() const{
244 if( basicType == DEF_LONG ){
245 return true;
246 }
247 return false;
248}
249bool Type::IsQWord() const{
250 if( basicType == DEF_QWORD ){
251 return true;
252 }
253 return false;
254}
255bool Type::IsInt64() const{
256 if( basicType == DEF_INT64 ){
257 return true;
258 }
259 return false;
260}
261bool Type::IsSingle() const{
262 if( basicType == DEF_SINGLE ){
263 return true;
264 }
265 return false;
266}
267bool Type::IsDouble() const{
268 if( basicType == DEF_DOUBLE ){
269 return true;
270 }
271 return false;
272}
273bool Type::IsBoolean() const{
274 if( basicType == DEF_BOOLEAN ){
275 return true;
276 }
277 return false;
278}
279
280bool Type::IsPointer( int basicType )
281{
282 if(PTR_LEVEL( basicType )|| basicType == DEF_PTR_VOID || basicType == DEF_PTR_PROC
283 || ( basicType & FLAG_PTR ) ){
284 return true;
285 }
286
287 return false;
288}
289bool Type::IsPointer() const
290{
291 return IsPointer( basicType );
292}
293bool Type::IsSigned() const
294{
295 switch( basicType ){
296 case DEF_SBYTE:
297 case DEF_INTEGER:
298 case DEF_LONG:
299 case DEF_INT64:
300 case DEF_SINGLE:
301 case DEF_DOUBLE:
302 return true;
303 default:
304 break;
305 }
306 return false;
307}
308bool Type::IsNaturalWhole() const
309{
310 switch( basicType ){
311 case DEF_SBYTE:
312 case DEF_BYTE:
313 case DEF_INTEGER:
314 case DEF_WORD:
315 case DEF_LONG:
316 case DEF_DWORD:
317 case DEF_INT64:
318 case DEF_QWORD:
319 return true;
320 default:
321 break;
322 }
323 return false;
324}
325bool Type::IsWhole() const
326{
327 return (
328 IsNaturalWhole()
329 || IsPointer( basicType )
330 || basicType == DEF_BOOLEAN
331 );
332}
333bool Type::IsReal() const
334{
335 switch( basicType ){
336 case DEF_SINGLE:
337 case DEF_DOUBLE:
338 return true;
339 default:
340 break;
341 }
342 return false;
343}
344bool Type::Is64() const
345{
346 switch( basicType ){
347 case DEF_QWORD:
348 case DEF_INT64:
349 return true;
350 default:
351 break;
352 }
353 return false;
354}
355bool Type::IsProcPtr() const
356{
357 if( basicType == DEF_PTR_PROC ){
358 return true;
359 }
360 return false;
361}
362bool Type::IsStruct() const
363{
364 if( basicType == DEF_STRUCT ){
365 return true;
366 }
367 return false;
368}
369bool Type::IsStructPtr() const
370{
371 if( basicType == DEF_PTR_STRUCT ){
372 return true;
373 }
374 return false;
375}
376bool Type::IsObject() const
377{
378 if( basicType == DEF_OBJECT ){
379 return true;
380 }
381 return false;
382}
383bool Type::IsObjectPtr() const
384{
385 if( basicType == DEF_PTR_OBJECT ){
386 return true;
387 }
388 return false;
389}
390bool Type::IsObjectClass() const
391{
392 if( basicType == DEF_OBJECT ){
393 if( pClass->GetName() == "Object" ){
394 return true;
395 }
396 }
397 return false;
398}
399bool Type::IsStringClass() const
400{
401 if( basicType == DEF_OBJECT ){
402 if( pClass->GetName() == "String" ){
403 return true;
404 }
405 }
406 return false;
407}
408bool Type::IsVoidPtr() const
409{
410 if( basicType == DEF_PTR_VOID ){
411 return true;
412 }
413 return false;
414}
415
416bool Type::IsAny() const
417{
418 if( basicType == DEF_ANY ){
419 return true;
420 }
421 return false;
422}
423
424bool Type::HasMember() const
425{
426 if( NATURAL_TYPE( basicType ) == DEF_OBJECT
427 || NATURAL_TYPE( basicType ) == DEF_STRUCT ){
428 return true;
429 }
430 return false;
431}
432
433int Type::GetBasicTypeFromSimpleName( const char *variable ){
434 extern char DefIntVari[26],DefSngVari[26],DefStrVari[26],divNum,dsvNum,dStrvNum;
435 int i;
436 char name[VN_SIZE];
437
438 //構造体メンバの場合を考慮
439 for(i=lstrlen(variable);i>0;i--){
440 if(variable[i]=='.'){
441 i++;
442 break;
443 }
444 }
445
446 for(;;i++){
447 if(variable[i]=='('||variable[i]=='\0'){
448 name[i]=0;
449 break;
450 }
451 name[i]=variable[i];
452 }
453 //変数名から選択
454 i--;
455 if(name[i]=='#') return DEF_DOUBLE;
456 if(name[i]=='!') return DEF_SINGLE;
457 if(name[i]=='%') return DEF_INTEGER;
458 return DEF_DOUBLE;
459}
460
461
462const string BlittableType::GetCreateStaticMethodFullName() const
463{
464 return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName() + "._Create";
465}
Note: See TracBrowser for help on using the repository browser.