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