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

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