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