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
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 {
38 Jenga::Throw( "StringToType内のジェネリクスクラス取得部分でpGenericClassがNULL" );
39 }
[290]40
[301]41 if( typeName[i] != '<' )
42 {
43 Jenga::Throw( "StringToType内でジェネリクス構文の解析に失敗" );
44 }
45
[290]46 GenericTypes genericTypes;
[301]47 while( true )
48 {
49 i++;
[290]50
[301]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
[290]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
[193]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 );
[299]85 type.SetIndex( this->GetObjectModule().meta.GetProcPointers().Add( typeName ) );
[193]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" ){
[299]111 type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() );
[193]112 return true;
113 }
114
115 // String型だったとき
116 if( typeName == "String" ){
[299]117 type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetStringClassPtr() );
[193]118 return true;
119 }
120
121
122 ////////////////////
123 // TypeDefされた型
124 ////////////////////
[299]125 int i=this->GetObjectModule().meta.GetTypeDefs().GetIndex( typeName );
[193]126 if(i!=-1){
[299]127 type = this->GetObjectModule().meta.GetTypeDefs()[i].GetBaseType();
[193]128 return true;
129 }
130
131 //クラス
[299]132 const CClass *pobj_c = this->GetObjectModule().meta.GetClasses().Find( typeName );
[193]133 if(pobj_c){
134 if( pobj_c->IsStructure() ){
135 type.SetBasicType( DEF_STRUCT );
136 }
137 else{
138 type.SetBasicType( DEF_OBJECT );
139 }
[290]140 type.SetClassPtr( pobj_c );
[193]141 return true;
142 }
143
[290]144
145 /////////////////////////////////////////////////////////
146 // ☆★☆ ジェネリクスサポート ☆★☆
147
148 // 型パラメータ
[299]149 if( this->pCompilingClass )
[290]150 {
151 // クラスに属するメソッドをコンパイルしているとき
[299]152 int formalTypeIndex = this->pCompilingClass->GetFormalGenericTypeParameterIndex( typeName );
153 if( formalTypeIndex != -1 )
[290]154 {
155 // コンパイル中クラスにおけるジェネリクス用の型パラメータのとき
156 type.SetBasicType( DEF_TYPE_PARAMETER );
[299]157 type.SetClassPtr( this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() );
158 type.SetFormalTypeName( typeName );
159 type.SetFormalTypeIndex( formalTypeIndex );
[290]160 return true;
161 }
162 }
163
164 //
165 /////////////////////////////////////////////////////////
166
[193]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
[196]177 return (string)"*" + TypeToString( tempType );
[193]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{
[299]195 if( this->GetObjectModule().meta.GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){
[193]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.