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