1 | #include "stdafx.h" |
---|
2 | |
---|
3 | #include <jenga/include/smoothie/SmoothieException.h> |
---|
4 | |
---|
5 | #include <Compiler.h> |
---|
6 | #include <Type.h> |
---|
7 | |
---|
8 | Compiler compiler; |
---|
9 | |
---|
10 | void Compiler::StaticLink( ObjectModules &staticLibraries ) |
---|
11 | { |
---|
12 | BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries ) |
---|
13 | { |
---|
14 | // メタ情報 |
---|
15 | pNowObjectModule->StaticLink( *pStaticLibrary ); |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | bool Compiler::StringToType( const string &typeName, Type &type ){ |
---|
20 | type.SetIndex( -1 ); |
---|
21 | |
---|
22 | |
---|
23 | ///////////////////////////////////////////////////////// |
---|
24 | // ☆★☆ ジェネリクスサポート ☆★☆ |
---|
25 | |
---|
26 | if( strstr( typeName.c_str(), "<" ) ) |
---|
27 | { |
---|
28 | // ジェネリッククラスをインスタンス化した型の場合 |
---|
29 | int i = 0; |
---|
30 | char className[VN_SIZE]; |
---|
31 | GetIdentifierToken( className, typeName.c_str(), i ); |
---|
32 | |
---|
33 | // ジェネリクスクラスを取得 |
---|
34 | const CClass *pGenericClass = this->GetObjectModule().meta.GetClasses().Find( className ); |
---|
35 | |
---|
36 | if( !pGenericClass ) |
---|
37 | { |
---|
38 | extern int cp; |
---|
39 | SetError(106, className, cp ); |
---|
40 | return false; |
---|
41 | } |
---|
42 | |
---|
43 | if( typeName[i] != '<' ) |
---|
44 | { |
---|
45 | Jenga::Throw( "StringToType内でジェネリクス構文の解析に失敗" ); |
---|
46 | } |
---|
47 | |
---|
48 | GenericTypes genericTypes; |
---|
49 | while( true ) |
---|
50 | { |
---|
51 | i++; |
---|
52 | |
---|
53 | char typeParameter[VN_SIZE]; |
---|
54 | GetIdentifierToken( typeParameter, typeName.c_str(), i ); |
---|
55 | |
---|
56 | // 型パラメータの型情報を取得 |
---|
57 | Type baseType; |
---|
58 | StringToType( typeParameter, baseType ); |
---|
59 | |
---|
60 | genericTypes.push_back( GenericType( "(non support)", baseType ) ); |
---|
61 | |
---|
62 | if( typeName[i] != ',' ) |
---|
63 | { |
---|
64 | break; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | // 基本型をセット |
---|
69 | type.SetBasicType( DEF_OBJECT ); |
---|
70 | |
---|
71 | // 拡張情報をセット |
---|
72 | type.SetClassPtr( pGenericClass ); |
---|
73 | type.SetActualGenericTypes( genericTypes ); |
---|
74 | |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
78 | // |
---|
79 | ///////////////////////////////////////////////////////// |
---|
80 | |
---|
81 | |
---|
82 | if( typeName[0] == '*' ){ |
---|
83 | if( typeName.size() >= 3 |
---|
84 | && typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){ |
---|
85 | //関数ポインタ(*Function) |
---|
86 | type.SetBasicType( DEF_PTR_PROC ); |
---|
87 | type.SetIndex( this->GetObjectModule().meta.GetProcPointers().Add( typeName ) ); |
---|
88 | return true; |
---|
89 | } |
---|
90 | |
---|
91 | const string &nextTypeName = typeName.substr( 1 ); |
---|
92 | |
---|
93 | if( !StringToType( nextTypeName, type ) ){ |
---|
94 | return false; |
---|
95 | } |
---|
96 | |
---|
97 | type.PtrLevelUp(); |
---|
98 | |
---|
99 | return true; |
---|
100 | } |
---|
101 | |
---|
102 | { |
---|
103 | int basicType; |
---|
104 | if( Type::StringToBasicType( typeName, basicType ) ){ |
---|
105 | // 基本型だったとき |
---|
106 | type.SetBasicType( basicType ); |
---|
107 | return true; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | // Object型だったとき |
---|
112 | if( typeName == "Object" ){ |
---|
113 | type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() ); |
---|
114 | return true; |
---|
115 | } |
---|
116 | |
---|
117 | // String型だったとき |
---|
118 | if( typeName == "String" ){ |
---|
119 | type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetStringClassPtr() ); |
---|
120 | return true; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | //////////////////// |
---|
125 | // TypeDefされた型 |
---|
126 | //////////////////// |
---|
127 | int i=this->GetObjectModule().meta.GetTypeDefs().GetIndex( typeName ); |
---|
128 | if(i!=-1){ |
---|
129 | type = this->GetObjectModule().meta.GetTypeDefs()[i].GetBaseType(); |
---|
130 | return true; |
---|
131 | } |
---|
132 | |
---|
133 | //クラス |
---|
134 | const CClass *pobj_c = this->GetObjectModule().meta.GetClasses().Find( typeName ); |
---|
135 | if(pobj_c){ |
---|
136 | if( pobj_c->IsStructure() ){ |
---|
137 | type.SetBasicType( DEF_STRUCT ); |
---|
138 | } |
---|
139 | else{ |
---|
140 | type.SetBasicType( DEF_OBJECT ); |
---|
141 | } |
---|
142 | type.SetClassPtr( pobj_c ); |
---|
143 | return true; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | ///////////////////////////////////////////////////////// |
---|
148 | // ☆★☆ ジェネリクスサポート ☆★☆ |
---|
149 | |
---|
150 | // 型パラメータ |
---|
151 | if( this->pCompilingClass ) |
---|
152 | { |
---|
153 | // クラスに属するメソッドをコンパイルしているとき |
---|
154 | int formalTypeIndex = this->pCompilingClass->GetFormalGenericTypeParameterIndex( typeName ); |
---|
155 | if( formalTypeIndex != -1 ) |
---|
156 | { |
---|
157 | // コンパイル中クラスにおけるジェネリクス用の型パラメータのとき |
---|
158 | type.SetBasicType( DEF_TYPE_PARAMETER ); |
---|
159 | type.SetClassPtr( this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() ); |
---|
160 | type.SetFormalTypeName( typeName ); |
---|
161 | type.SetFormalTypeIndex( formalTypeIndex ); |
---|
162 | return true; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | // |
---|
167 | ///////////////////////////////////////////////////////// |
---|
168 | |
---|
169 | return false; |
---|
170 | } |
---|
171 | |
---|
172 | const string Compiler::TypeToString( const Type &type ) |
---|
173 | { |
---|
174 | if( PTR_LEVEL( type.GetBasicType() ) ){ |
---|
175 | //ポインタレベルが1以上の場合 |
---|
176 | Type tempType( type ); |
---|
177 | tempType.PtrLevelDown(); |
---|
178 | |
---|
179 | return (string)"*" + TypeToString( tempType ); |
---|
180 | } |
---|
181 | else if( type.IsObject() || type.IsStruct() ){ |
---|
182 | //オブジェクトまたは構造体 |
---|
183 | |
---|
184 | if( !( type.GetIndex() == 0 || type.GetIndex() == -1 ) ){ |
---|
185 | if( type.GetClass().GetNamespaceScopes().size() >= 1 ) |
---|
186 | { |
---|
187 | return type.GetClass().GetNamespaceScopes().ToString() + "." + type.GetClass().GetName(); |
---|
188 | } |
---|
189 | return type.GetClass().GetName(); |
---|
190 | } |
---|
191 | } |
---|
192 | else if( type.IsProcPtr() ){ |
---|
193 | if( type.GetIndex() == 0 || type.GetIndex() == -1 ){ |
---|
194 | return "VoidPtr"; |
---|
195 | } |
---|
196 | else{ |
---|
197 | if( this->GetObjectModule().meta.GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){ |
---|
198 | return "*Sub"; |
---|
199 | } |
---|
200 | return "*Function"; |
---|
201 | } |
---|
202 | } |
---|
203 | else{ |
---|
204 | // 基本型 |
---|
205 | const char *lpszTypeName = Type::BasicTypeToCharPtr( type ); |
---|
206 | if( lpszTypeName ) |
---|
207 | { |
---|
208 | return (const string)lpszTypeName; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | SmoothieException::Throw( 1 ); |
---|
213 | |
---|
214 | return (string)"(null)"; |
---|
215 | } |
---|