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

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

64bit版でコンパイルできるようにした。

File size: 5.0 KB
RevLine 
[206]1#include "stdafx.h"
2
[193]3#include <jenga/include/smoothie/SmoothieException.h>
4
[184]5#include <Compiler.h>
[206]6#include <Type.h>
[184]7
[195]8Compiler compiler;
[193]9
[270]10void Compiler::StaticLink( ObjectModules &staticLibraries )
11{
12 BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries )
13 {
14 // メタ情報
[273]15 pNowObjectModule->StaticLink( *pStaticLibrary );
[270]16 }
17}
18
[193]19bool Compiler::StringToType( const string &typeName, Type &type ){
20 type.SetIndex( -1 );
21
[290]22
23 /////////////////////////////////////////////////////////
24 // ☆★☆ ジェネリクスサポート ☆★☆
25
26 if( strstr( typeName.c_str(), "<" ) )
27 {
28 // ジェネリッククラスをインスタンス化した型の場合
29 int i = 0;
[301]30 char className[VN_SIZE];
[290]31 GetIdentifierToken( className, typeName.c_str(), i );
32
33 // ジェネリクスクラスを取得
[299]34 const CClass *pGenericClass = this->GetObjectModule().meta.GetClasses().Find( className );
[290]35
[301]36 if( !pGenericClass )
37 {
[318]38 extern int cp;
39 SetError(106, className, cp );
40 return false;
[301]41 }
[290]42
[301]43 if( typeName[i] != '<' )
44 {
45 Jenga::Throw( "StringToType内でジェネリクス構文の解析に失敗" );
46 }
47
[290]48 GenericTypes genericTypes;
[301]49 while( true )
50 {
51 i++;
[290]52
[301]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
[290]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
[193]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 );
[299]87 type.SetIndex( this->GetObjectModule().meta.GetProcPointers().Add( typeName ) );
[193]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" ){
[299]113 type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() );
[193]114 return true;
115 }
116
117 // String型だったとき
118 if( typeName == "String" ){
[299]119 type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetStringClassPtr() );
[193]120 return true;
121 }
122
123
124 ////////////////////
125 // TypeDefされた型
126 ////////////////////
[299]127 int i=this->GetObjectModule().meta.GetTypeDefs().GetIndex( typeName );
[193]128 if(i!=-1){
[299]129 type = this->GetObjectModule().meta.GetTypeDefs()[i].GetBaseType();
[193]130 return true;
131 }
132
133 //クラス
[299]134 const CClass *pobj_c = this->GetObjectModule().meta.GetClasses().Find( typeName );
[193]135 if(pobj_c){
136 if( pobj_c->IsStructure() ){
137 type.SetBasicType( DEF_STRUCT );
138 }
139 else{
140 type.SetBasicType( DEF_OBJECT );
141 }
[290]142 type.SetClassPtr( pobj_c );
[193]143 return true;
144 }
145
[290]146
147 /////////////////////////////////////////////////////////
148 // ☆★☆ ジェネリクスサポート ☆★☆
149
150 // 型パラメータ
[299]151 if( this->pCompilingClass )
[290]152 {
153 // クラスに属するメソッドをコンパイルしているとき
[299]154 int formalTypeIndex = this->pCompilingClass->GetFormalGenericTypeParameterIndex( typeName );
155 if( formalTypeIndex != -1 )
[290]156 {
157 // コンパイル中クラスにおけるジェネリクス用の型パラメータのとき
158 type.SetBasicType( DEF_TYPE_PARAMETER );
[299]159 type.SetClassPtr( this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() );
160 type.SetFormalTypeName( typeName );
161 type.SetFormalTypeIndex( formalTypeIndex );
[290]162 return true;
163 }
164 }
165
166 //
167 /////////////////////////////////////////////////////////
168
[193]169 return false;
170}
171
172const string Compiler::TypeToString( const Type &type )
173{
174 if( PTR_LEVEL( type.GetBasicType() ) ){
175 //ポインタレベルが1以上の場合
176 Type tempType( type );
177 tempType.PtrLevelDown();
178
[196]179 return (string)"*" + TypeToString( tempType );
[193]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{
[299]197 if( this->GetObjectModule().meta.GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){
[193]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}
Note: See TracBrowser for help on using the repository browser.