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