source: dev/trunk/abdev/BasicCompiler_Common/src/Compiler.cpp@ 193

Last change on this file since 193 was 193, checked in by dai_9181, 17 years ago
File size: 2.8 KB
Line 
1#include <jenga/include/smoothie/Type.h>
2#include <jenga/include/smoothie/SmoothieException.h>
3
4#include <Compiler.h>
5
6
7bool Compiler::StringToType( const string &typeName, Type &type ){
8 type.SetIndex( -1 );
9
10 if( typeName[0] == '*' ){
11 if( typeName.size() >= 3
12 && typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){
13 //関数ポインタ(*Function)
14 type.SetBasicType( DEF_PTR_PROC );
15 type.SetIndex( compiler.GetMeta().GetProcPointers().Add( typeName ) );
16 return true;
17 }
18
19 const string &nextTypeName = typeName.substr( 1 );
20
21 if( !StringToType( nextTypeName, type ) ){
22 return false;
23 }
24
25 type.PtrLevelUp();
26
27 return true;
28 }
29
30 {
31 int basicType;
32 if( Type::StringToBasicType( typeName, basicType ) ){
33 // 基本型だったとき
34 type.SetBasicType( basicType );
35 return true;
36 }
37 }
38
39 // Object型だったとき
40 if( typeName == "Object" ){
41 type.SetType( DEF_OBJECT, compiler.GetMeta().GetClasses().GetObjectClassPtr() );
42 return true;
43 }
44
45 // String型だったとき
46 if( typeName == "String" ){
47 type.SetType( DEF_OBJECT, compiler.GetMeta().GetClasses().GetStringClassPtr() );
48 return true;
49 }
50
51
52 ////////////////////
53 // TypeDefされた型
54 ////////////////////
55 int i=compiler.GetMeta().GetTypeDefs().GetIndex( typeName );
56 if(i!=-1){
57 type = compiler.GetMeta().GetTypeDefs()[i].GetBaseType();
58 return true;
59 }
60
61 //クラス
62 const CClass *pobj_c = compiler.GetMeta().GetClasses().Find( typeName );
63 if(pobj_c){
64 type.SetClassPtr( pobj_c );
65
66 if( pobj_c->IsStructure() ){
67 type.SetBasicType( DEF_STRUCT );
68 }
69 else{
70 type.SetBasicType( DEF_OBJECT );
71 }
72 return true;
73 }
74
75 return false;
76}
77
78const string Compiler::TypeToString( const Type &type )
79{
80 if( PTR_LEVEL( type.GetBasicType() ) ){
81 //ポインタレベルが1以上の場合
82 Type tempType( type );
83 tempType.PtrLevelDown();
84
85 return (string)"*" + TypeToString( type );
86 }
87 else if( type.IsObject() || type.IsStruct() ){
88 //オブジェクトまたは構造体
89
90 if( !( type.GetIndex() == 0 || type.GetIndex() == -1 ) ){
91 if( type.GetClass().GetNamespaceScopes().size() >= 1 )
92 {
93 return type.GetClass().GetNamespaceScopes().ToString() + "." + type.GetClass().GetName();
94 }
95 return type.GetClass().GetName();
96 }
97 }
98 else if( type.IsProcPtr() ){
99 if( type.GetIndex() == 0 || type.GetIndex() == -1 ){
100 return "VoidPtr";
101 }
102 else{
103 if( compiler.GetMeta().GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){
104 return "*Sub";
105 }
106 return "*Function";
107 }
108 }
109 else{
110 // 基本型
111 const char *lpszTypeName = Type::BasicTypeToCharPtr( type );
112 if( lpszTypeName )
113 {
114 return (const string)lpszTypeName;
115 }
116 }
117
118 SmoothieException::Throw( 1 );
119
120 return (string)"(null)";
121}
Note: See TracBrowser for help on using the repository browser.