| 1 | #pragma warning(disable : 4996)
|
|---|
| 2 |
|
|---|
| 3 | #include <map>
|
|---|
| 4 | #include <string>
|
|---|
| 5 | #include <vector>
|
|---|
| 6 | #include <fstream>
|
|---|
| 7 | #include <iostream>
|
|---|
| 8 |
|
|---|
| 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>
|
|---|
| 17 | #include <process.h>
|
|---|
| 18 | #include <fcntl.h>
|
|---|
| 19 | #include <io.h>
|
|---|
| 20 | #include <shlwapi.h>
|
|---|
| 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 |
|
|---|
| 45 | #include <jenga/include/jenga.h>
|
|---|
| 46 |
|
|---|
| 47 | #include "../common.h"
|
|---|
| 48 | #include "../BasicFixed.h"
|
|---|
| 49 |
|
|---|
| 50 | #include <abdev/ab_common/include/ab_common.h>
|
|---|
| 51 |
|
|---|
| 52 | using namespace ActiveBasic::Common::Lexical;
|
|---|
| 53 |
|
|---|
| 54 | #include <Configuration.h>
|
|---|
| 55 | #include <Type.h>
|
|---|
| 56 | #include <Method.h>
|
|---|
| 57 | #include <Interface.h>
|
|---|
| 58 | #include <Class.h>
|
|---|
| 59 | #include <Procedure.h>
|
|---|
| 60 | #include <LexicalAnalyzer.h>
|
|---|
| 61 | #include <Program.h>
|
|---|
| 62 | #include <Compiler.h>
|
|---|
| 63 | #include <Debugger.h>
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
|---|
| 67 | {
|
|---|
| 68 | long dataSectionBaseOffset = dataTable.GetSize();
|
|---|
| 69 | int sourceIndexBase = (int)sources.size();
|
|---|
| 70 |
|
|---|
| 71 | // メタ情報を結合
|
|---|
| 72 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
|
|---|
| 73 |
|
|---|
| 74 | // グローバル ネイティブコードを結合
|
|---|
| 75 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 76 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
|
|---|
| 77 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
|---|
| 78 |
|
|---|
| 79 | // データテーブルを結合
|
|---|
| 80 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 81 | dataTable.Add( objectModule.dataTable );
|
|---|
| 82 |
|
|---|
| 83 | // ソースコードを結合
|
|---|
| 84 | BOOST_FOREACH( const BasicSource &source, objectModule.sources )
|
|---|
| 85 | {
|
|---|
| 86 | this->sources.push_back( source );
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | // TODO: basbufがいらなくなったら消す
|
|---|
| 90 | extern char *basbuf;
|
|---|
| 91 | basbuf = this->sources[0].GetBuffer();
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | bool ObjectModule::Read( const std::string &filePath )
|
|---|
| 95 | {
|
|---|
| 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 )
|
|---|
| 114 | {
|
|---|
| 115 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 116 | }
|
|---|
| 117 | catch(...){
|
|---|
| 118 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | if( !isSuccessful )
|
|---|
| 122 | {
|
|---|
| 123 | return false;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | return true;
|
|---|
| 127 | }
|
|---|
| 128 | bool ObjectModule::Write( const std::string &filePath ) const
|
|---|
| 129 | {
|
|---|
| 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 )
|
|---|
| 147 | {
|
|---|
| 148 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 149 | }
|
|---|
| 150 | catch(...){
|
|---|
| 151 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | if( !isSuccessful )
|
|---|
| 155 | {
|
|---|
| 156 | return false;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | return true;
|
|---|
| 160 | }
|
|---|
| 161 | bool ObjectModule::ReadString( const std::string &str )
|
|---|
| 162 | {
|
|---|
| 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 )
|
|---|
| 182 | {
|
|---|
| 183 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 184 | }
|
|---|
| 185 | catch(...){
|
|---|
| 186 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | if( !isSuccessful )
|
|---|
| 190 | {
|
|---|
| 191 | return false;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | return true;
|
|---|
| 195 | }
|
|---|
| 196 | bool ObjectModule::WriteString( std::string &str ) const
|
|---|
| 197 | {
|
|---|
| 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 )
|
|---|
| 218 | {
|
|---|
| 219 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 220 | }
|
|---|
| 221 | catch(...){
|
|---|
| 222 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | return isSuccessful;
|
|---|
| 226 | }
|
|---|