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