#include "stdafx.h" #include #include #include Compiler compiler; void Compiler::StaticLink( ObjectModules &staticLibraries ) { BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries ) { // メタ情報 pNowObjectModule->StaticLink( *pStaticLibrary ); } } bool Compiler::StringToType( const string &typeName, Type &type ){ type.SetIndex( -1 ); ///////////////////////////////////////////////////////// // ☆★☆ ジェネリクスサポート ☆★☆ if( strstr( typeName.c_str(), "<" ) ) { // ジェネリッククラスをインスタンス化した型の場合 int i = 0; char className[VN_SIZE]; GetIdentifierToken( className, typeName.c_str(), i ); // ジェネリクスクラスを取得 const CClass *pGenericClass = this->GetObjectModule().meta.GetClasses().Find( className ); if( !pGenericClass ) { extern int cp; SetError(106, className, cp ); return false; } if( typeName[i] != '<' ) { Jenga::Throw( "StringToType内でジェネリクス構文の解析に失敗" ); } GenericTypes genericTypes; while( true ) { i++; char typeParameter[VN_SIZE]; GetIdentifierToken( typeParameter, typeName.c_str(), i ); // 型パラメータの型情報を取得 Type baseType; StringToType( typeParameter, baseType ); genericTypes.push_back( GenericType( "(non support)", baseType ) ); if( typeName[i] != ',' ) { break; } } // 基本型をセット type.SetBasicType( DEF_OBJECT ); // 拡張情報をセット type.SetClassPtr( pGenericClass ); type.SetActualGenericTypes( genericTypes ); return true; } // ///////////////////////////////////////////////////////// if( typeName[0] == '*' ){ if( typeName.size() >= 3 && typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){ //関数ポインタ(*Function) type.SetBasicType( DEF_PTR_PROC ); type.SetIndex( this->GetObjectModule().meta.GetProcPointers().Add( typeName ) ); return true; } const string &nextTypeName = typeName.substr( 1 ); if( !StringToType( nextTypeName, type ) ){ return false; } type.PtrLevelUp(); return true; } { int basicType; if( Type::StringToBasicType( typeName, basicType ) ){ // 基本型だったとき type.SetBasicType( basicType ); return true; } } // Object型だったとき if( typeName == "Object" ){ type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() ); return true; } // String型だったとき if( typeName == "String" ){ type.SetType( DEF_OBJECT, this->GetObjectModule().meta.GetClasses().GetStringClassPtr() ); return true; } //////////////////// // TypeDefされた型 //////////////////// int i=this->GetObjectModule().meta.GetTypeDefs().GetIndex( typeName ); if(i!=-1){ type = this->GetObjectModule().meta.GetTypeDefs()[i].GetBaseType(); return true; } //クラス const CClass *pobj_c = this->GetObjectModule().meta.GetClasses().Find( typeName ); if(pobj_c){ if( pobj_c->IsStructure() ){ type.SetBasicType( DEF_STRUCT ); } else{ type.SetBasicType( DEF_OBJECT ); } type.SetClassPtr( pobj_c ); return true; } ///////////////////////////////////////////////////////// // ☆★☆ ジェネリクスサポート ☆★☆ // 型パラメータ if( this->pCompilingClass ) { // クラスに属するメソッドをコンパイルしているとき int formalTypeIndex = this->pCompilingClass->GetFormalGenericTypeParameterIndex( typeName ); if( formalTypeIndex != -1 ) { // コンパイル中クラスにおけるジェネリクス用の型パラメータのとき type.SetBasicType( DEF_TYPE_PARAMETER ); type.SetClassPtr( this->GetObjectModule().meta.GetClasses().GetObjectClassPtr() ); type.SetFormalTypeName( typeName ); type.SetFormalTypeIndex( formalTypeIndex ); return true; } } // ///////////////////////////////////////////////////////// return false; } const string Compiler::TypeToString( const Type &type ) { if( PTR_LEVEL( type.GetBasicType() ) ){ //ポインタレベルが1以上の場合 Type tempType( type ); tempType.PtrLevelDown(); return (string)"*" + TypeToString( tempType ); } else if( type.IsObject() || type.IsStruct() ){ //オブジェクトまたは構造体 if( !( type.GetIndex() == 0 || type.GetIndex() == -1 ) ){ if( type.GetClass().GetNamespaceScopes().size() >= 1 ) { return type.GetClass().GetNamespaceScopes().ToString() + "." + type.GetClass().GetName(); } return type.GetClass().GetName(); } } else if( type.IsProcPtr() ){ if( type.GetIndex() == 0 || type.GetIndex() == -1 ){ return "VoidPtr"; } else{ if( this->GetObjectModule().meta.GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){ return "*Sub"; } return "*Function"; } } else{ // 基本型 const char *lpszTypeName = Type::BasicTypeToCharPtr( type ); if( lpszTypeName ) { return (const string)lpszTypeName; } } SmoothieException::Throw( 1 ); return (string)"(null)"; }