[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 |
|
---|
[527] | 59 | #include <option.h>
|
---|
| 60 |
|
---|
[515] | 61 | #include <abdev/ab_common/include/ab_common.h>
|
---|
[505] | 62 |
|
---|
| 63 | using namespace ActiveBasic::Common::Lexical;
|
---|
| 64 |
|
---|
[524] | 65 | #include <NativeCode.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>
|
---|
[524] | 72 | #include <Parameter.h>
|
---|
| 73 | #include <Variable.h>
|
---|
[511] | 74 | #include <Procedure.h>
|
---|
[524] | 75 | #include <TypeDef.h>
|
---|
| 76 | #include <Const.h>
|
---|
| 77 | #include <Delegate.h>
|
---|
| 78 | #include <Enum.h>
|
---|
| 79 | #include <Exception.h>
|
---|
| 80 | #include <Meta.h>
|
---|
[525] | 81 |
|
---|
[527] | 82 | #include <logger.h>
|
---|
| 83 | #include <Configuration.h>
|
---|
[524] | 84 | #include <CodeGenerator.h>
|
---|
| 85 | #include <Messenger.h>
|
---|
[532] | 86 | #include <DataTable.h>
|
---|
[524] | 87 | #include <ObjectModule.h>
|
---|
| 88 | #include <Linker.h>
|
---|
[274] | 89 | #include <Compiler.h>
|
---|
[508] | 90 | #include <Debugger.h>
|
---|
[522] | 91 | #include <Program.h>
|
---|
[525] | 92 | #include <LexicalAnalyzer.h>
|
---|
[274] | 93 |
|
---|
[279] | 94 |
|
---|
[525] | 95 |
|
---|
[274] | 96 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
---|
| 97 | {
|
---|
[585] | 98 | long dataSectionBaseOffset = this->nativeSection.dataTable.GetSize();
|
---|
| 99 | int sourceIndexBase = (int)nativeSection.GetSources().size();
|
---|
[280] | 100 |
|
---|
[274] | 101 | // メタ情報を結合
|
---|
[280] | 102 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
|
---|
[274] | 103 |
|
---|
[395] | 104 | // グローバル ネイティブコードを結合
|
---|
[585] | 105 | objectModule.nativeSection.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 106 | objectModule.nativeSection.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
|
---|
| 107 | nativeSection.globalNativeCode.PutEx( objectModule.nativeSection.globalNativeCode );
|
---|
[276] | 108 |
|
---|
[274] | 109 | // データテーブルを結合
|
---|
[585] | 110 | objectModule.nativeSection.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 111 | this->nativeSection.dataTable.Add( objectModule.nativeSection.dataTable );
|
---|
[280] | 112 |
|
---|
| 113 | // ソースコードを結合
|
---|
[585] | 114 | BOOST_FOREACH( const BasicSource &source, objectModule.nativeSection.GetSources() )
|
---|
[280] | 115 | {
|
---|
[585] | 116 | this->nativeSection.GetSources().push_back( source );
|
---|
[280] | 117 | }
|
---|
[282] | 118 |
|
---|
| 119 | // TODO: basbufがいらなくなったら消す
|
---|
| 120 | extern char *basbuf;
|
---|
[585] | 121 | basbuf = this->nativeSection.GetSources()[0].GetBuffer();
|
---|
[274] | 122 | }
|
---|
[279] | 123 |
|
---|
| 124 | bool ObjectModule::Read( const std::string &filePath )
|
---|
| 125 | {
|
---|
[585] | 126 | Jenga::Common::File file( filePath );
|
---|
[404] | 127 |
|
---|
[585] | 128 | Jenga::Common::Binary binary;
|
---|
| 129 | if( !file.ReadBinary( binary ) )
|
---|
[279] | 130 | {
|
---|
[404] | 131 | return false;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[585] | 134 | return Load( binary );
|
---|
[279] | 135 | }
|
---|
| 136 | bool ObjectModule::Write( const std::string &filePath ) const
|
---|
| 137 | {
|
---|
[585] | 138 | Jenga::Common::File file( filePath );
|
---|
[404] | 139 |
|
---|
[585] | 140 | Jenga::Common::Binary binary;
|
---|
| 141 | if( !Save( binary ) )
|
---|
[279] | 142 | {
|
---|
[404] | 143 | return false;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[585] | 146 | return file.WriteBinary( binary );
|
---|
[279] | 147 | }
|
---|
[585] | 148 | bool ObjectModule::Load( const Jenga::Common::Binary &binary )
|
---|
[279] | 149 | {
|
---|
[404] | 150 | bool isSuccessful = false;
|
---|
| 151 |
|
---|
| 152 | // 入力アーカイブの作成
|
---|
| 153 |
|
---|
| 154 | try{
|
---|
[585] | 155 | std::string str( binary.GetBuffer(), binary.GetSize() );
|
---|
| 156 |
|
---|
[404] | 157 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 158 | std::istringstream iss( str );
|
---|
| 159 | boost::archive::xml_iarchive ia(iss);
|
---|
| 160 | #else
|
---|
[523] | 161 | std::istringstream iss( str, std::ios::in | std::ios::binary );
|
---|
[404] | 162 | boost::archive::binary_iarchive ia(iss);
|
---|
| 163 | #endif
|
---|
| 164 |
|
---|
| 165 | // 文字列ストリームから読込
|
---|
| 166 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 167 |
|
---|
| 168 | isSuccessful = true;
|
---|
| 169 | }
|
---|
| 170 | catch( boost::archive::archive_exception e )
|
---|
[279] | 171 | {
|
---|
[404] | 172 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 173 | }
|
---|
[404] | 174 | catch(...){
|
---|
| 175 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | if( !isSuccessful )
|
---|
| 179 | {
|
---|
| 180 | return false;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | return true;
|
---|
[279] | 184 | }
|
---|
[585] | 185 | bool ObjectModule::Save( Jenga::Common::Binary &binary ) const
|
---|
[279] | 186 | {
|
---|
[404] | 187 | // 出力アーカイブの作成
|
---|
| 188 |
|
---|
| 189 | bool isSuccessful = false;
|
---|
| 190 | try{
|
---|
| 191 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 192 | std::ostringstream oss;
|
---|
| 193 | boost::archive::xml_oarchive oa(oss);
|
---|
| 194 | #else
|
---|
[523] | 195 | std::ostringstream oss( "", std::ios::out | std::ios::binary );
|
---|
[404] | 196 | boost::archive::binary_oarchive oa(oss);
|
---|
| 197 | #endif
|
---|
| 198 |
|
---|
| 199 | // 文字列ストリームに書き出し
|
---|
| 200 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 201 |
|
---|
[585] | 202 | binary.Put( oss.str().c_str(), static_cast<int>(oss.str().size()) );
|
---|
[404] | 203 |
|
---|
| 204 | isSuccessful = true;
|
---|
| 205 | }
|
---|
| 206 | catch( boost::archive::archive_exception e )
|
---|
[279] | 207 | {
|
---|
[404] | 208 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 209 | }
|
---|
[404] | 210 | catch(...){
|
---|
| 211 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | return isSuccessful;
|
---|
[279] | 215 | }
|
---|