source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp@ 465

Last change on this file since 465 was 465, checked in by dai_9181, 16 years ago

Messenger/ErrorMessengerクラスを導入。SetError関数によるエラー生成を廃止した。

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