source: dev/trunk/abdev/BasicCompiler_Common/src/Type.cpp@ 206

Last change on this file since 206 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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