#include #include #include bool Compiler::StringToType( const string &typeName, Type &type ){ type.SetIndex( -1 ); 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( compiler.GetMeta().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, compiler.GetMeta().GetClasses().GetObjectClassPtr() ); return true; } // String型だったとき if( typeName == "String" ){ type.SetType( DEF_OBJECT, compiler.GetMeta().GetClasses().GetStringClassPtr() ); return true; } //////////////////// // TypeDefされた型 //////////////////// int i=compiler.GetMeta().GetTypeDefs().GetIndex( typeName ); if(i!=-1){ type = compiler.GetMeta().GetTypeDefs()[i].GetBaseType(); return true; } //クラス const CClass *pobj_c = compiler.GetMeta().GetClasses().Find( typeName ); if(pobj_c){ type.SetClassPtr( pobj_c ); if( pobj_c->IsStructure() ){ type.SetBasicType( DEF_STRUCT ); } else{ type.SetBasicType( DEF_OBJECT ); } 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( type ); } 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( compiler.GetMeta().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)"; }