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