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