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