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