[520] | 1 | #pragma warning(disable : 4996)
|
---|
| 2 |
|
---|
| 3 | #include <map>
|
---|
[404] | 4 | #include <string>
|
---|
| 5 | #include <vector>
|
---|
| 6 | #include <fstream>
|
---|
[520] | 7 | #include <iostream>
|
---|
[522] | 8 | #include <iomanip>
|
---|
| 9 | #include <ios>
|
---|
| 10 | #include <streambuf>
|
---|
| 11 | #include <sstream>
|
---|
[274] | 12 |
|
---|
[750] | 13 | #define WIN32_LEAN_AND_MEAN
|
---|
[404] | 14 | #include <windows.h>
|
---|
| 15 | #include <stdio.h>
|
---|
| 16 | #include <string.h>
|
---|
| 17 | #include <math.h>
|
---|
| 18 | #include <time.h>
|
---|
| 19 | #include <limits.h>
|
---|
| 20 | #include <shlobj.h>
|
---|
[522] | 21 | #include <tchar.h>
|
---|
[404] | 22 |
|
---|
| 23 | //boost libraries
|
---|
| 24 | #include <boost/foreach.hpp>
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | // ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
|
---|
| 28 | //#define OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 32 | #include <boost/archive/xml_oarchive.hpp>
|
---|
| 33 | #include <boost/archive/xml_iarchive.hpp>
|
---|
| 34 | #else
|
---|
| 35 | #include <boost/archive/binary_oarchive.hpp>
|
---|
| 36 | #include <boost/archive/binary_iarchive.hpp>
|
---|
| 37 | #endif
|
---|
| 38 | #include <boost/serialization/string.hpp>
|
---|
| 39 | #include <boost/serialization/access.hpp>
|
---|
| 40 | #include <boost/serialization/level.hpp>
|
---|
| 41 | #include <boost/serialization/vector.hpp>
|
---|
| 42 | #include <boost/serialization/map.hpp>
|
---|
| 43 | #include <boost/serialization/version.hpp>
|
---|
| 44 | #include <boost/serialization/is_abstract.hpp>
|
---|
[523] | 45 | #include <boost/serialization/serialization.hpp>
|
---|
| 46 | #include <boost/serialization/nvp.hpp>
|
---|
| 47 | #include <boost/serialization/export.hpp>
|
---|
[404] | 48 |
|
---|
[750] | 49 | #define foreach(v, c) for each (v in c)
|
---|
| 50 |
|
---|
[520] | 51 | #include <jenga/include/jenga.h>
|
---|
[600] | 52 | #include <abdev/ab_common/include/ab_common.h>
|
---|
[505] | 53 |
|
---|
[520] | 54 |
|
---|
[637] | 55 | void ObjectModule::StaticLink( ObjectModule &objectModule, bool isSll )
|
---|
[274] | 56 | {
|
---|
[636] | 57 | const std::vector<int> relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames );
|
---|
| 58 |
|
---|
[587] | 59 | long dataSectionBaseOffset = dataTable.GetSize();
|
---|
[280] | 60 |
|
---|
[274] | 61 | // メタ情報を結合
|
---|
[636] | 62 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable );
|
---|
[274] | 63 |
|
---|
[637] | 64 | if( !isSll )
|
---|
| 65 | {
|
---|
| 66 | // グローバル ネイティブコードを結合
|
---|
| 67 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 68 | objectModule.globalNativeCode.ResetRelationalObjectModuleIndex( relationTable );
|
---|
| 69 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
---|
[276] | 70 |
|
---|
[637] | 71 | // データテーブルを結合
|
---|
| 72 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 73 | dataTable.Add( objectModule.dataTable );
|
---|
| 74 | }
|
---|
[280] | 75 |
|
---|
[636] | 76 | // TODO: basbufがいらなくなったら消す
|
---|
| 77 | extern char *basbuf;
|
---|
| 78 | basbuf = this->source.GetBuffer();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[640] | 81 | void ObjectModule::Resolve( ResolveErrors &resolveErrors )
|
---|
[637] | 82 | {
|
---|
[640] | 83 | this->meta.Resolve( *this, resolveErrors );
|
---|
[637] | 84 |
|
---|
| 85 | // グローバルネイティブコードを解決(スケジュールを解決する)
|
---|
[640] | 86 | this->globalNativeCode.Resolve( *this, resolveErrors );
|
---|
[637] | 87 |
|
---|
| 88 | // データテーブルを解決(スケジュールを解決する)
|
---|
[640] | 89 | this->dataTable.Resolve( *this, resolveErrors );
|
---|
[637] | 90 | }
|
---|
| 91 |
|
---|
[636] | 92 | const std::vector<int> ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames )
|
---|
| 93 | {
|
---|
| 94 | // 要素 = 古いインデックス、値 = 新しいインデックス
|
---|
| 95 | std::vector<int> relationTable;
|
---|
| 96 |
|
---|
| 97 | // リレーションテーブルを構築
|
---|
[750] | 98 | foreach( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames )
|
---|
[280] | 99 | {
|
---|
[636] | 100 | bool isMatch = false;
|
---|
| 101 | for( int i=0; i<static_cast<int>(this->relationalObjectModuleNames.size()); i++ )
|
---|
| 102 | {
|
---|
| 103 | if( oldRelationalObjectModuleName == this->relationalObjectModuleNames[i] )
|
---|
| 104 | {
|
---|
| 105 | isMatch = true;
|
---|
| 106 | relationTable.push_back( i );
|
---|
| 107 | break;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | if( !isMatch )
|
---|
| 112 | {
|
---|
| 113 | // エラー
|
---|
| 114 | _ASSERT( false );
|
---|
| 115 | }
|
---|
[280] | 116 | }
|
---|
[282] | 117 |
|
---|
[636] | 118 | return relationTable;
|
---|
[274] | 119 | }
|
---|
[279] | 120 |
|
---|
| 121 | bool ObjectModule::Read( const std::string &filePath )
|
---|
| 122 | {
|
---|
[587] | 123 | // XMLとして読み込む
|
---|
| 124 | bool isSuccessful = false;
|
---|
[404] | 125 |
|
---|
[587] | 126 | try{
|
---|
| 127 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 128 | std::ifstream ifs( filePath.c_str() );
|
---|
| 129 | boost::archive::xml_iarchive ia(ifs);
|
---|
| 130 | #else
|
---|
| 131 | std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary );
|
---|
| 132 | boost::archive::binary_iarchive ia(ifs);
|
---|
| 133 | #endif
|
---|
| 134 |
|
---|
| 135 | // ファイルから読込
|
---|
| 136 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 137 |
|
---|
| 138 | isSuccessful = true;
|
---|
| 139 | }
|
---|
[750] | 140 | catch( boost::archive::archive_exception& e )
|
---|
[279] | 141 | {
|
---|
[587] | 142 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
| 143 | }
|
---|
| 144 | catch(...){
|
---|
| 145 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | if( !isSuccessful )
|
---|
| 149 | {
|
---|
[404] | 150 | return false;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[587] | 153 | return true;
|
---|
[279] | 154 | }
|
---|
| 155 | bool ObjectModule::Write( const std::string &filePath ) const
|
---|
| 156 | {
|
---|
[587] | 157 | bool isSuccessful = false;
|
---|
[404] | 158 |
|
---|
[587] | 159 | try{
|
---|
| 160 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 161 | std::ofstream ofs( filePath.c_str() );
|
---|
| 162 | boost::archive::xml_oarchive oa(ofs);
|
---|
| 163 | #else
|
---|
| 164 | std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary );
|
---|
| 165 | boost::archive::binary_oarchive oa(ofs);
|
---|
| 166 | #endif
|
---|
| 167 |
|
---|
| 168 | // ファイルに書き出し
|
---|
| 169 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 170 |
|
---|
| 171 | isSuccessful = true;
|
---|
| 172 | }
|
---|
[750] | 173 | catch( boost::archive::archive_exception& e )
|
---|
[279] | 174 | {
|
---|
[587] | 175 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
| 176 | }
|
---|
| 177 | catch(...){
|
---|
| 178 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | if( !isSuccessful )
|
---|
| 182 | {
|
---|
[404] | 183 | return false;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[587] | 186 | return true;
|
---|
[279] | 187 | }
|
---|
[587] | 188 | bool ObjectModule::ReadString( const std::string &str )
|
---|
[279] | 189 | {
|
---|
[404] | 190 | bool isSuccessful = false;
|
---|
| 191 |
|
---|
| 192 | // 入力アーカイブの作成
|
---|
| 193 |
|
---|
| 194 | try{
|
---|
| 195 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 196 | std::istringstream iss( str );
|
---|
| 197 | boost::archive::xml_iarchive ia(iss);
|
---|
| 198 | #else
|
---|
[523] | 199 | std::istringstream iss( str, std::ios::in | std::ios::binary );
|
---|
[404] | 200 | boost::archive::binary_iarchive ia(iss);
|
---|
| 201 | #endif
|
---|
| 202 |
|
---|
| 203 | // 文字列ストリームから読込
|
---|
| 204 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 205 |
|
---|
| 206 | isSuccessful = true;
|
---|
| 207 | }
|
---|
[750] | 208 | catch( boost::archive::archive_exception& e )
|
---|
[279] | 209 | {
|
---|
[404] | 210 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 211 | }
|
---|
[404] | 212 | catch(...){
|
---|
| 213 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | if( !isSuccessful )
|
---|
| 217 | {
|
---|
| 218 | return false;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | return true;
|
---|
[279] | 222 | }
|
---|
[587] | 223 | bool ObjectModule::WriteString( std::string &str ) const
|
---|
[279] | 224 | {
|
---|
[404] | 225 | // 出力アーカイブの作成
|
---|
| 226 |
|
---|
| 227 | bool isSuccessful = false;
|
---|
| 228 | try{
|
---|
| 229 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 230 | std::ostringstream oss;
|
---|
| 231 | boost::archive::xml_oarchive oa(oss);
|
---|
| 232 | #else
|
---|
[523] | 233 | std::ostringstream oss( "", std::ios::out | std::ios::binary );
|
---|
[404] | 234 | boost::archive::binary_oarchive oa(oss);
|
---|
| 235 | #endif
|
---|
| 236 |
|
---|
| 237 | // 文字列ストリームに書き出し
|
---|
| 238 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 239 |
|
---|
[587] | 240 | str = oss.str();
|
---|
[404] | 241 |
|
---|
| 242 | isSuccessful = true;
|
---|
| 243 | }
|
---|
[750] | 244 | catch( boost::archive::archive_exception &e )
|
---|
[279] | 245 | {
|
---|
[404] | 246 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 247 | }
|
---|
[404] | 248 | catch(...){
|
---|
| 249 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | return isSuccessful;
|
---|
[279] | 253 | }
|
---|