Changeset 589 in dev for trunk/ab5.0/abdev
- Timestamp:
- May 10, 2008, 3:37:40 PM (17 years ago)
- Location:
- trunk/ab5.0/abdev
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/include/DataTable.h
r520 r589 148 148 } 149 149 150 bool MakeConstObjectToProcessStaticBuffer( const CClass &objClass, const Jenga::Common::Strings &initMemberValues, int &dataTableOffset );151 bool MakeConstObjectToProcessStaticBuffer( const char *expression, Type &resultType, int &dataTableOffset );152 int MakeConstStringObjectToProcessStaticBuffer( const char *str );153 bool MakeLiteralArrayBuffer( const char *expression, const Type &baseType, int &dataTableOffset );154 155 private:156 int lastMadeConstObjectDataTableOffset;157 public:158 int GetLastMadeConstObjectDataTableOffset()159 {160 return lastMadeConstObjectDataTableOffset;161 }162 163 150 void ResetDataSectionBaseOffset( long dataSectionBaseOffset ); 164 151 }; -
trunk/ab5.0/abdev/BasicCompiler_Common/src/DataTable.cpp
r561 r589 82 82 } 83 83 84 bool DataTable::MakeConstObjectToProcessStaticBuffer( const CClass &objClass, const Jenga::Common::Strings &initMemberValues, int &dataTableOffset )85 {86 // クラスに必要なバッファサイズを取得87 int size = objClass.GetSize();88 89 // クラスのバッファイメージを作成90 BYTE *buffer = (BYTE *)calloc( size, 1 );91 92 // クラスのバッファイメージをデータ領域へ追加93 dataTableOffset = this->AddBinary( buffer, size );94 95 this->lastMadeConstObjectDataTableOffset = dataTableOffset;96 97 // com_vtblスケジュール98 this->schedules.push_back( Schedule( Schedule::ComVtbl, &objClass, dataTableOffset ) );99 100 // vtblスケジュール101 this->schedules.push_back( Schedule( Schedule::Vtbl, &objClass, dataTableOffset + PTR_SIZE ) );102 103 // TypeInfoスケジュール104 int offsetForTypeInfo = objClass.GetMemberOffset( "_system_object_member_typeInfo" );105 //this->schedules.push_back( Schedule( Schedule::TypeInfo, &objClass, dataTableOffset + offsetForTypeInfo ) );106 107 BOOST_FOREACH( const std::string &initMemberValue, initMemberValues )108 {109 int i = 0;110 111 // メンバ名112 char memberName[VN_SIZE];113 for( i=0; ; i++ )114 {115 if( initMemberValue[i] == '\0' )116 {117 // エラー118 compiler.errorMessenger.OutputFatalError();119 return false;120 }121 if( initMemberValue[i] == '=' )122 {123 memberName[i] = 0;124 break;125 }126 memberName[i] = initMemberValue[i];127 }128 129 // 初期値130 const char *initValue = initMemberValue.c_str() + i + 1;131 132 // メンバを取得133 const Member *member = objClass.FindDynamicMember( memberName );134 135 // メンバオフセットを取得136 int memberOffset = objClass.GetMemberOffset( member->GetName().c_str() );137 138 if( member->GetType().IsPointer() && initValue[0] == '[' )139 {140 // ポインタ型でバッファ指定のとき141 int memberDataTableOffset;142 if( !this->MakeLiteralArrayBuffer( initValue, member->GetType(),memberDataTableOffset ) )143 {144 return false;145 }146 147 this->Overwrite( dataTableOffset + memberOffset, memberDataTableOffset );148 this->schedules.push_back( Schedule( Schedule::DataTable, dataTableOffset + memberOffset ) );149 }150 else if( member->GetType().IsWhole() )151 {152 // 整数153 Type resultType;154 _int64 i64data;155 if( !StaticCalculation( true, initValue, member->GetType().GetBasicType(), &i64data, resultType ) ){156 return false;157 }158 159 this->Overwrite( dataTableOffset + memberOffset, static_cast<long>(i64data) );160 }161 else if( member->GetType().IsStringClass() )162 {163 // 文字列型164 char temporary[VN_SIZE];165 lstrcpy( temporary, initValue );166 RemoveStringQuotes( temporary );167 int memberDataTableOffset = MakeConstStringObjectToProcessStaticBuffer( temporary );168 this->Overwrite( dataTableOffset + memberOffset, memberDataTableOffset );169 this->schedules.push_back( Schedule( Schedule::DataTable, dataTableOffset + memberOffset ) );170 }171 }172 173 return true;174 }175 bool DataTable::MakeConstObjectToProcessStaticBuffer( const char *expression, Type &resultType, int &dataTableOffset )176 {177 char CreateParameter[VN_SIZE];178 int i,i2;179 180 i=0;181 182 // クラス名を取得183 char typeName[VN_SIZE];184 for(i2=0;;i++,i2++){185 if(expression[i]=='['){186 typeName[i2]=0;187 188 // メンバの初期値を取得189 i2=GetStringInBracket(CreateParameter,expression+i);190 RemoveStringBracket(CreateParameter);191 i+=i2;192 if(expression[i]!='\0'){193 compiler.errorMessenger.Output(42,NULL,cp);194 return false;195 }196 break;197 }198 typeName[i2]=expression[i];199 if(expression[i]=='\0'){200 CreateParameter[0]=0;201 break;202 }203 }204 205 // パラメータを取得206 Jenga::Common::Strings initMemberValues;207 SplitParameter( CreateParameter, initMemberValues );208 209 if( !compiler.StringToType( typeName, resultType ) ){210 compiler.errorMessenger.Output(3,typeName,cp);211 return false;212 }213 214 if( !resultType.IsObject() ){215 ////////////////////////216 // 通常のデータ型の場合217 ////////////////////////218 219 compiler.errorMessenger.Output(121,NULL,cp);220 return false;221 }222 223 return MakeConstObjectToProcessStaticBuffer( resultType.GetClass(), initMemberValues, dataTableOffset );224 }225 226 int DataTable::MakeConstStringObjectToProcessStaticBuffer( const char *str )227 {228 const CClass &strClass = *compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();229 const CClass &objClass = strClass.GetSuperClass();230 231 // クラスに必要なバッファサイズを取得232 int size = strClass.GetSize();233 234 // メンバ位置を取得235 int offsetForTypeInfo = strClass.GetMemberOffset( "_system_object_member_typeInfo" );236 int offsetForLength = strClass.GetMemberOffset( "m_Length" );237 int offsetForChars = strClass.GetMemberOffset( "Chars" );238 239 // 現在のデータ領域のヘッダ位置を取得240 int headOffset = this->GetSize();241 242 // クラスのバッファイメージを作成243 BYTE *buffer = (BYTE *)calloc( size, 1 );244 *(long *)(buffer + offsetForLength) = lstrlen( str );245 *(LONG_PTR *)(buffer + offsetForChars) = headOffset + size;246 247 // クラスのバッファイメージをデータ領域へ追加248 int dataTableOffset = this->AddBinary( buffer, size );249 250 // スケジューリング251 this->schedules.push_back( Schedule( Schedule::ComVtbl, &strClass, headOffset ) );252 this->schedules.push_back( Schedule( Schedule::Vtbl, &strClass, headOffset + PTR_SIZE ) );253 this->schedules.push_back( Schedule( Schedule::TypeInfo, &strClass, headOffset + offsetForTypeInfo ) );254 this->schedules.push_back( Schedule( Schedule::DataTable, headOffset + offsetForChars ) );255 256 // 文字列バッファをデータ領域へ追加257 this->AddString( str );258 259 return dataTableOffset;260 }261 262 bool DataTable::MakeLiteralArrayBuffer( const char *expression, const Type &baseType, int &dataTableOffset )263 {264 if( !baseType.IsPointer() ){265 compiler.errorMessenger.Output(1,NULL,cp);266 return false;267 }268 Type tempBaseType( baseType );269 tempBaseType.PtrLevelDown();270 271 char *buffer = (char *)malloc( lstrlen( expression ) + 1 );272 lstrcpy( buffer, expression );273 RemoveStringBracket( buffer );274 275 Jenga::Common::Strings parameters;276 SplitParameter( buffer, parameters );277 278 // アラインメント279 AddAlignment( tempBaseType.GetSize() );280 281 // データテーブルに空間を確保282 dataTableOffset = AddSpace( static_cast<int>(tempBaseType.GetSize() * parameters.size()) );283 284 bool isSuccessful = true;285 int i = 0;286 BOOST_FOREACH( const std::string ¶mStr, parameters )287 {288 if( paramStr.size() == 0 )289 {290 throw;291 }292 if( paramStr[0] == '\"' )293 {294 // 文字列295 std::string tempParamStr = paramStr;296 if( !RemoveStringQuotes( tempParamStr ) )297 {298 compiler.errorMessenger.OutputFatalError();299 }300 301 // 文字列を追加302 _int64 strOffset;303 if( tempBaseType.IsStringClass() )304 {305 // Stringクラス306 strOffset = MakeConstStringObjectToProcessStaticBuffer( tempParamStr.c_str() );307 }308 else309 {310 // Charポインタ311 strOffset = this->AddString( tempParamStr );312 }313 314 // ポインタ値を上書き315 int tempOffset = dataTableOffset + i * tempBaseType.GetSize();316 this->OverwriteBinary( tempOffset, &strOffset, tempBaseType.GetSize() );317 318 // DataTableスケジュール319 this->schedules.push_back( Schedule( Schedule::DataTable, tempOffset ) );320 }321 else322 {323 // 数値324 Type resultType;325 _int64 i64data;326 if( !StaticCalculation( true, paramStr.c_str(), tempBaseType.GetBasicType(), &i64data, resultType ) ){327 isSuccessful = false;328 break;329 }330 if( !resultType.IsWhole() ){331 // TODO: 実数に未対応332 compiler.errorMessenger.OutputFatalError();333 isSuccessful = false;334 break;335 }336 337 // 上書き338 this->OverwriteBinary( dataTableOffset + i * tempBaseType.GetSize(), &i64data, tempBaseType.GetSize() );339 }340 341 i++;342 }343 344 free( buffer );345 346 return isSuccessful;347 }348 349 84 void DataTable::ResetDataSectionBaseOffset( long dataSectionBaseOffset ) 350 85 { -
trunk/ab5.0/abdev/BasicCompiler_Common/src/ProcedureGenerator.cpp
r587 r589 113 113 114 114 objClass.SetTypeInfoDataTableOffset( 115 compiler.GetObjectModule().dataTable.GetLastMadeConstObjectDataTableOffset()115 DataTableGenerator::GetLastMadeConstObjectDataTableOffset() 116 116 ); 117 117 } -
trunk/ab5.0/abdev/compiler_x64/NumOpe.cpp
r587 r589 763 763 764 764 int dataTableOffset; 765 if( ! compiler.GetObjectModule().dataTable.MakeLiteralArrayBuffer(expression, baseType, dataTableOffset ) )765 if( !ActiveBasic::Compiler::DataTableGenerator::MakeLiteralArrayBuffer( compiler.GetObjectModule().dataTable, expression, baseType, dataTableOffset ) ) 766 766 { 767 767 return false; … … 866 866 // 静的領域にオブジェクトを生成 867 867 int dataTableOffset; 868 if( ! compiler.GetObjectModule().dataTable.MakeConstObjectToProcessStaticBuffer(expression + 2, resultType, dataTableOffset ) )868 if( !ActiveBasic::Compiler::DataTableGenerator::MakeConstObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, expression + 2, resultType, dataTableOffset ) ) 869 869 { 870 870 return false; … … 1020 1020 1021 1021 //String型オブジェクトを生成 1022 i2 = compiler.GetObjectModule().dataTable.MakeConstStringObjectToProcessStaticBuffer(term );1022 i2 = ActiveBasic::Compiler::DataTableGenerator::MakeConstStringObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, term ); 1023 1023 1024 1024 //mov reg,i2 -
trunk/ab5.0/abdev/compiler_x64/compiler_x64.vcproj
r584 r589 326 326 </File> 327 327 <File 328 RelativePath="..\BasicCompiler_Common\include\DataTableGenerator.h" 329 > 330 </File> 331 <File 328 332 RelativePath="..\BasicCompiler_Common\include\LexicalAnalyzer.h" 329 333 > … … 1224 1228 </File> 1225 1229 <File 1230 RelativePath="..\BasicCompiler_Common\src\DataTableGenerator.cpp" 1231 > 1232 </File> 1233 <File 1226 1234 RelativePath="..\BasicCompiler_Common\src\LexicalAnalyzer.cpp" 1227 1235 > -
trunk/ab5.0/abdev/compiler_x64/stdafx.h
r584 r589 73 73 #include <VtblGenerator.h> 74 74 #include <ProcedureGenerator.h> 75 #include <DataTableGenerator.h> -
trunk/ab5.0/abdev/compiler_x86/NumOpe.cpp
r587 r589 718 718 719 719 int dataTableOffset; 720 if( ! compiler.GetObjectModule().dataTable.MakeLiteralArrayBuffer(expression, baseType, dataTableOffset ) )720 if( !ActiveBasic::Compiler::DataTableGenerator::MakeLiteralArrayBuffer( compiler.GetObjectModule().dataTable, expression, baseType, dataTableOffset ) ) 721 721 { 722 722 return false; … … 798 798 // 静的領域にオブジェクトを生成 799 799 int dataTableOffset; 800 if( ! compiler.GetObjectModule().dataTable.MakeConstObjectToProcessStaticBuffer(expression + 2, resultType, dataTableOffset ) )800 if( !ActiveBasic::Compiler::DataTableGenerator::MakeConstObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, expression + 2, resultType, dataTableOffset ) ) 801 801 { 802 802 return false; … … 941 941 942 942 //String型オブジェクトを生成 943 i2 = compiler.GetObjectModule().dataTable.MakeConstStringObjectToProcessStaticBuffer(term );944 943 i2 = ActiveBasic::Compiler::DataTableGenerator::MakeConstStringObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, term ); 944 945 945 // push value 946 946 compiler.codeGenerator.op_push_V( i2, Schedule::DataTable ); -
trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj
r565 r589 1253 1253 </File> 1254 1254 <File 1255 RelativePath="..\BasicCompiler_Common\src\DataTableGenerator.cpp" 1256 > 1257 </File> 1258 <File 1255 1259 RelativePath="..\BasicCompiler_Common\src\LexicalAnalyzer.cpp" 1256 1260 > … … 1478 1482 </File> 1479 1483 <File 1484 RelativePath="..\BasicCompiler_Common\include\DataTableGenerator.h" 1485 > 1486 </File> 1487 <File 1480 1488 RelativePath="..\BasicCompiler_Common\include\LexicalAnalyzer.h" 1481 1489 > -
trunk/ab5.0/abdev/compiler_x86/stdafx.h
r565 r589 73 73 #include <VtblGenerator.h> 74 74 #include <ProcedureGenerator.h> 75 #include <DataTableGenerator.h>
Note:
See TracChangeset
for help on using the changeset viewer.