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

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