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