| 1 | #pragma warning(disable : 4996)
|
|---|
| 2 |
|
|---|
| 3 | #include <map>
|
|---|
| 4 | #include <string>
|
|---|
| 5 | #include <vector>
|
|---|
| 6 | #include <fstream>
|
|---|
| 7 | #include <iostream>
|
|---|
| 8 | #include <iomanip>
|
|---|
| 9 | #include <ios>
|
|---|
| 10 | #include <streambuf>
|
|---|
| 11 | #include <sstream>
|
|---|
| 12 |
|
|---|
| 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>
|
|---|
| 21 | #include <process.h>
|
|---|
| 22 | #include <fcntl.h>
|
|---|
| 23 | #include <io.h>
|
|---|
| 24 | #include <shlwapi.h>
|
|---|
| 25 | #include <tchar.h>
|
|---|
| 26 | #include <stdarg.h>
|
|---|
| 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>
|
|---|
| 50 | #include <boost/serialization/serialization.hpp>
|
|---|
| 51 | #include <boost/serialization/nvp.hpp>
|
|---|
| 52 | #include <boost/serialization/export.hpp>
|
|---|
| 53 |
|
|---|
| 54 | #include <jenga/include/jenga.h>
|
|---|
| 55 |
|
|---|
| 56 | #include "../common.h"
|
|---|
| 57 | #include "../BasicFixed.h"
|
|---|
| 58 |
|
|---|
| 59 | #include <abdev/ab_common/include/ab_common.h>
|
|---|
| 60 |
|
|---|
| 61 | using namespace ActiveBasic::Common::Lexical;
|
|---|
| 62 |
|
|---|
| 63 | #include <option.h>
|
|---|
| 64 | #include <logger.h>
|
|---|
| 65 | #include <Configuration.h>
|
|---|
| 66 | #include <Binary.h>
|
|---|
| 67 | #include <NativeCode.h>
|
|---|
| 68 | #include <Source.h>
|
|---|
| 69 | #include <Type.h>
|
|---|
| 70 | #include <Method.h>
|
|---|
| 71 | #include <Interface.h>
|
|---|
| 72 | #include <Member.h>
|
|---|
| 73 | #include <Class.h>
|
|---|
| 74 | #include <Parameter.h>
|
|---|
| 75 | #include <Variable.h>
|
|---|
| 76 | #include <Procedure.h>
|
|---|
| 77 | #include <LexicalAnalyzer.h>
|
|---|
| 78 | #include <Program.h>
|
|---|
| 79 | #include <TypeDef.h>
|
|---|
| 80 | #include <Const.h>
|
|---|
| 81 | #include <Delegate.h>
|
|---|
| 82 | #include <Enum.h>
|
|---|
| 83 | #include <DataTable.h>
|
|---|
| 84 | #include <Exception.h>
|
|---|
| 85 | #include <Meta.h>
|
|---|
| 86 | #include <CodeGenerator.h>
|
|---|
| 87 | #include <Messenger.h>
|
|---|
| 88 | #include <ObjectModule.h>
|
|---|
| 89 | #include <Linker.h>
|
|---|
| 90 | #include <Compiler.h>
|
|---|
| 91 | #include <Debugger.h>
|
|---|
| 92 | #include <Program.h>
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
|---|
| 96 | {
|
|---|
| 97 | long dataSectionBaseOffset = dataTable.GetSize();
|
|---|
| 98 | int sourceIndexBase = (int)sources.size();
|
|---|
| 99 |
|
|---|
| 100 | // メタ情報を結合
|
|---|
| 101 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
|
|---|
| 102 |
|
|---|
| 103 | // グローバル ネイティブコードを結合
|
|---|
| 104 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 105 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
|
|---|
| 106 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
|---|
| 107 |
|
|---|
| 108 | // データテーブルを結合
|
|---|
| 109 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 110 | dataTable.Add( objectModule.dataTable );
|
|---|
| 111 |
|
|---|
| 112 | // ソースコードを結合
|
|---|
| 113 | BOOST_FOREACH( const BasicSource &source, objectModule.sources )
|
|---|
| 114 | {
|
|---|
| 115 | this->sources.push_back( source );
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | // TODO: basbufがいらなくなったら消す
|
|---|
| 119 | extern char *basbuf;
|
|---|
| 120 | basbuf = this->sources[0].GetBuffer();
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | bool ObjectModule::Read( const std::string &filePath )
|
|---|
| 124 | {
|
|---|
| 125 | // XMLとして読み込む
|
|---|
| 126 | bool isSuccessful = false;
|
|---|
| 127 |
|
|---|
| 128 | try{
|
|---|
| 129 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 130 | std::ifstream ifs( filePath.c_str() );
|
|---|
| 131 | boost::archive::xml_iarchive ia(ifs);
|
|---|
| 132 | #else
|
|---|
| 133 | std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary );
|
|---|
| 134 | boost::archive::binary_iarchive ia(ifs);
|
|---|
| 135 | #endif
|
|---|
| 136 |
|
|---|
| 137 | // ファイルから読込
|
|---|
| 138 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 139 |
|
|---|
| 140 | isSuccessful = true;
|
|---|
| 141 | }
|
|---|
| 142 | catch( boost::archive::archive_exception e )
|
|---|
| 143 | {
|
|---|
| 144 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 145 | }
|
|---|
| 146 | catch(...){
|
|---|
| 147 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | if( !isSuccessful )
|
|---|
| 151 | {
|
|---|
| 152 | return false;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | return true;
|
|---|
| 156 | }
|
|---|
| 157 | bool ObjectModule::Write( const std::string &filePath ) const
|
|---|
| 158 | {
|
|---|
| 159 | bool isSuccessful = false;
|
|---|
| 160 |
|
|---|
| 161 | try{
|
|---|
| 162 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 163 | std::ofstream ofs( filePath.c_str() );
|
|---|
| 164 | boost::archive::xml_oarchive oa(ofs);
|
|---|
| 165 | #else
|
|---|
| 166 | std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary );
|
|---|
| 167 | boost::archive::binary_oarchive oa(ofs);
|
|---|
| 168 | #endif
|
|---|
| 169 |
|
|---|
| 170 | // ファイルに書き出し
|
|---|
| 171 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 172 |
|
|---|
| 173 | isSuccessful = true;
|
|---|
| 174 | }
|
|---|
| 175 | catch( boost::archive::archive_exception e )
|
|---|
| 176 | {
|
|---|
| 177 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 178 | }
|
|---|
| 179 | catch(...){
|
|---|
| 180 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | if( !isSuccessful )
|
|---|
| 184 | {
|
|---|
| 185 | return false;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | return true;
|
|---|
| 189 | }
|
|---|
| 190 | bool ObjectModule::ReadString( const std::string &str )
|
|---|
| 191 | {
|
|---|
| 192 | bool isSuccessful = false;
|
|---|
| 193 |
|
|---|
| 194 | // 入力アーカイブの作成
|
|---|
| 195 |
|
|---|
| 196 | try{
|
|---|
| 197 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 198 | std::istringstream iss( str );
|
|---|
| 199 | boost::archive::xml_iarchive ia(iss);
|
|---|
| 200 | #else
|
|---|
| 201 | std::istringstream iss( str, std::ios::in | std::ios::binary );
|
|---|
| 202 | boost::archive::binary_iarchive ia(iss);
|
|---|
| 203 | #endif
|
|---|
| 204 |
|
|---|
| 205 | // 文字列ストリームから読込
|
|---|
| 206 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 207 |
|
|---|
| 208 | isSuccessful = true;
|
|---|
| 209 | }
|
|---|
| 210 | catch( boost::archive::archive_exception e )
|
|---|
| 211 | {
|
|---|
| 212 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 213 | }
|
|---|
| 214 | catch(...){
|
|---|
| 215 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | if( !isSuccessful )
|
|---|
| 219 | {
|
|---|
| 220 | return false;
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | return true;
|
|---|
| 224 | }
|
|---|
| 225 | bool ObjectModule::WriteString( std::string &str ) const
|
|---|
| 226 | {
|
|---|
| 227 | // 出力アーカイブの作成
|
|---|
| 228 |
|
|---|
| 229 | bool isSuccessful = false;
|
|---|
| 230 | try{
|
|---|
| 231 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 232 | std::ostringstream oss;
|
|---|
| 233 | boost::archive::xml_oarchive oa(oss);
|
|---|
| 234 | #else
|
|---|
| 235 | std::ostringstream oss( "", std::ios::out | std::ios::binary );
|
|---|
| 236 | boost::archive::binary_oarchive oa(oss);
|
|---|
| 237 | #endif
|
|---|
| 238 |
|
|---|
| 239 | // 文字列ストリームに書き出し
|
|---|
| 240 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 241 |
|
|---|
| 242 | str = oss.str();
|
|---|
| 243 |
|
|---|
| 244 | isSuccessful = true;
|
|---|
| 245 | }
|
|---|
| 246 | catch( boost::archive::archive_exception e )
|
|---|
| 247 | {
|
|---|
| 248 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 249 | }
|
|---|
| 250 | catch(...){
|
|---|
| 251 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | return isSuccessful;
|
|---|
| 255 | }
|
|---|