[404] | 1 | #include <string>
|
---|
| 2 | #include <vector>
|
---|
| 3 | #include <fstream>
|
---|
[274] | 4 |
|
---|
[404] | 5 | #include <windows.h>
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <string.h>
|
---|
| 8 | #include <math.h>
|
---|
| 9 | #include <commctrl.h>
|
---|
| 10 | #include <time.h>
|
---|
| 11 | #include <limits.h>
|
---|
| 12 | #include <shlobj.h>
|
---|
| 13 |
|
---|
| 14 | //boost libraries
|
---|
| 15 | #include <boost/foreach.hpp>
|
---|
| 16 |
|
---|
| 17 | #include <jenga/include/common/String.h>
|
---|
| 18 |
|
---|
| 19 | #include "../common.h"
|
---|
[461] | 20 | #include "../BasicFixed.h"
|
---|
[404] | 21 |
|
---|
| 22 |
|
---|
| 23 | // ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
|
---|
| 24 | //#define OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 28 | #include <boost/archive/xml_oarchive.hpp>
|
---|
| 29 | #include <boost/archive/xml_iarchive.hpp>
|
---|
| 30 | #else
|
---|
| 31 | #include <boost/archive/binary_oarchive.hpp>
|
---|
| 32 | #include <boost/archive/binary_iarchive.hpp>
|
---|
| 33 | #endif
|
---|
| 34 | #include <boost/serialization/string.hpp>
|
---|
| 35 | #include <boost/serialization/access.hpp>
|
---|
| 36 | #include <boost/serialization/level.hpp>
|
---|
| 37 | #include <boost/serialization/vector.hpp>
|
---|
| 38 | #include <boost/serialization/map.hpp>
|
---|
| 39 | #include <boost/serialization/version.hpp>
|
---|
| 40 | #include <boost/serialization/is_abstract.hpp>
|
---|
| 41 |
|
---|
| 42 | #include <BoostSerializationSupport.h>
|
---|
[505] | 43 |
|
---|
| 44 | #include <abdev/ab_common/Environment.h>
|
---|
| 45 | #include <abdev/ab_common/include/Namespace.h>
|
---|
| 46 |
|
---|
| 47 | using namespace ActiveBasic::Common::Lexical;
|
---|
| 48 |
|
---|
[404] | 49 | #include <Hashmap.h>
|
---|
[274] | 50 | #include <Compiler.h>
|
---|
| 51 |
|
---|
[279] | 52 |
|
---|
[274] | 53 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
---|
| 54 | {
|
---|
[280] | 55 | long dataSectionBaseOffset = dataTable.GetSize();
|
---|
[308] | 56 | int sourceIndexBase = (int)sources.size();
|
---|
[280] | 57 |
|
---|
[274] | 58 | // メタ情報を結合
|
---|
[280] | 59 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
|
---|
[274] | 60 |
|
---|
[395] | 61 | // グローバル ネイティブコードを結合
|
---|
[280] | 62 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 63 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
|
---|
[287] | 64 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
---|
[276] | 65 |
|
---|
[274] | 66 | // データテーブルを結合
|
---|
[355] | 67 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
[274] | 68 | dataTable.Add( objectModule.dataTable );
|
---|
[280] | 69 |
|
---|
| 70 | // ソースコードを結合
|
---|
| 71 | BOOST_FOREACH( const BasicSource &source, objectModule.sources )
|
---|
| 72 | {
|
---|
| 73 | this->sources.push_back( source );
|
---|
| 74 | }
|
---|
[282] | 75 |
|
---|
| 76 | // TODO: basbufがいらなくなったら消す
|
---|
| 77 | extern char *basbuf;
|
---|
| 78 | basbuf = this->sources[0].GetBuffer();
|
---|
[274] | 79 | }
|
---|
[279] | 80 |
|
---|
| 81 | bool ObjectModule::Read( const std::string &filePath )
|
---|
| 82 | {
|
---|
[404] | 83 | // XMLとして読み込む
|
---|
| 84 | bool isSuccessful = false;
|
---|
| 85 |
|
---|
| 86 | try{
|
---|
| 87 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 88 | std::ifstream ifs( filePath.c_str() );
|
---|
| 89 | boost::archive::xml_iarchive ia(ifs);
|
---|
| 90 | #else
|
---|
| 91 | std::ifstream ifs( filePath.c_str(), ios::in | ios::binary );
|
---|
| 92 | boost::archive::binary_iarchive ia(ifs);
|
---|
| 93 | #endif
|
---|
| 94 |
|
---|
| 95 | // ファイルから読込
|
---|
| 96 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 97 |
|
---|
| 98 | isSuccessful = true;
|
---|
| 99 | }
|
---|
| 100 | catch( boost::archive::archive_exception e )
|
---|
[279] | 101 | {
|
---|
[404] | 102 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 103 | }
|
---|
[404] | 104 | catch(...){
|
---|
| 105 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | if( !isSuccessful )
|
---|
| 109 | {
|
---|
| 110 | return false;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | return true;
|
---|
[279] | 114 | }
|
---|
| 115 | bool ObjectModule::Write( const std::string &filePath ) const
|
---|
| 116 | {
|
---|
[404] | 117 | bool isSuccessful = false;
|
---|
| 118 |
|
---|
| 119 | try{
|
---|
| 120 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 121 | std::ofstream ofs( filePath.c_str() );
|
---|
| 122 | boost::archive::xml_oarchive oa(ofs);
|
---|
| 123 | #else
|
---|
| 124 | std::ofstream ofs( filePath.c_str(), ios::out | ios::binary );
|
---|
| 125 | boost::archive::binary_oarchive oa(ofs);
|
---|
| 126 | #endif
|
---|
| 127 |
|
---|
| 128 | // ファイルに書き出し
|
---|
| 129 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 130 |
|
---|
| 131 | isSuccessful = true;
|
---|
| 132 | }
|
---|
| 133 | catch( boost::archive::archive_exception e )
|
---|
[279] | 134 | {
|
---|
[404] | 135 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 136 | }
|
---|
[404] | 137 | catch(...){
|
---|
| 138 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | if( !isSuccessful )
|
---|
| 142 | {
|
---|
| 143 | return false;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | return true;
|
---|
[279] | 147 | }
|
---|
| 148 | bool ObjectModule::ReadString( const std::string &str )
|
---|
| 149 | {
|
---|
[404] | 150 | bool isSuccessful = false;
|
---|
| 151 |
|
---|
| 152 | // 入力アーカイブの作成
|
---|
| 153 |
|
---|
| 154 | try{
|
---|
| 155 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 156 | std::istringstream iss( str );
|
---|
| 157 | boost::archive::xml_iarchive ia(iss);
|
---|
| 158 | #else
|
---|
| 159 | std::istringstream iss( str, ios::in | ios::binary );
|
---|
| 160 | boost::archive::binary_iarchive ia(iss);
|
---|
| 161 | #endif
|
---|
| 162 |
|
---|
| 163 | // 文字列ストリームから読込
|
---|
| 164 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 165 |
|
---|
| 166 | isSuccessful = true;
|
---|
| 167 | }
|
---|
| 168 | catch( boost::archive::archive_exception e )
|
---|
[279] | 169 | {
|
---|
[404] | 170 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 171 | }
|
---|
[404] | 172 | catch(...){
|
---|
| 173 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | if( !isSuccessful )
|
---|
| 177 | {
|
---|
| 178 | return false;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | return true;
|
---|
[279] | 182 | }
|
---|
| 183 | bool ObjectModule::WriteString( std::string &str ) const
|
---|
| 184 | {
|
---|
[404] | 185 | // 出力アーカイブの作成
|
---|
| 186 |
|
---|
| 187 | bool isSuccessful = false;
|
---|
| 188 | try{
|
---|
| 189 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 190 | std::ostringstream oss;
|
---|
| 191 | boost::archive::xml_oarchive oa(oss);
|
---|
| 192 | #else
|
---|
| 193 | std::ostringstream oss( "", ios::out | ios::binary );
|
---|
| 194 | boost::archive::binary_oarchive oa(oss);
|
---|
| 195 | #endif
|
---|
| 196 |
|
---|
| 197 | // 文字列ストリームに書き出し
|
---|
| 198 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 199 |
|
---|
| 200 | str = oss.str();
|
---|
| 201 |
|
---|
| 202 | isSuccessful = true;
|
---|
| 203 | }
|
---|
| 204 | catch( boost::archive::archive_exception e )
|
---|
[279] | 205 | {
|
---|
[404] | 206 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 207 | }
|
---|
[404] | 208 | catch(...){
|
---|
| 209 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | return isSuccessful;
|
---|
[279] | 213 | }
|
---|