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