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 <Program.h> |
---|
78 | #include <TypeDef.h> |
---|
79 | #include <Const.h> |
---|
80 | #include <Delegate.h> |
---|
81 | #include <Enum.h> |
---|
82 | #include <DataTable.h> |
---|
83 | #include <Exception.h> |
---|
84 | #include <Meta.h> |
---|
85 | |
---|
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 | #include <LexicalAnalyzer.h> |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | void ObjectModule::StaticLink( ObjectModule &objectModule ) |
---|
98 | { |
---|
99 | long dataSectionBaseOffset = dataTable.GetSize(); |
---|
100 | int sourceIndexBase = (int)sources.size(); |
---|
101 | |
---|
102 | // メタ情報を結合 |
---|
103 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase ); |
---|
104 | |
---|
105 | // グローバル ネイティブコードを結合 |
---|
106 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset ); |
---|
107 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase ); |
---|
108 | globalNativeCode.PutEx( objectModule.globalNativeCode ); |
---|
109 | |
---|
110 | // データテーブルを結合 |
---|
111 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset ); |
---|
112 | dataTable.Add( objectModule.dataTable ); |
---|
113 | |
---|
114 | // ソースコードを結合 |
---|
115 | BOOST_FOREACH( const BasicSource &source, objectModule.sources ) |
---|
116 | { |
---|
117 | this->sources.push_back( source ); |
---|
118 | } |
---|
119 | |
---|
120 | // TODO: basbufがいらなくなったら消す |
---|
121 | extern char *basbuf; |
---|
122 | basbuf = this->sources[0].GetBuffer(); |
---|
123 | } |
---|
124 | |
---|
125 | bool ObjectModule::Read( const std::string &filePath ) |
---|
126 | { |
---|
127 | // XMLとして読み込む |
---|
128 | bool isSuccessful = false; |
---|
129 | |
---|
130 | try{ |
---|
131 | #ifdef OBJECT_MODULE_IS_NOT_BINARY |
---|
132 | std::ifstream ifs( filePath.c_str() ); |
---|
133 | boost::archive::xml_iarchive ia(ifs); |
---|
134 | #else |
---|
135 | std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary ); |
---|
136 | boost::archive::binary_iarchive ia(ifs); |
---|
137 | #endif |
---|
138 | |
---|
139 | // ファイルから読込 |
---|
140 | ia >> boost::serialization::make_nvp( RootTagName(), *this ); |
---|
141 | |
---|
142 | isSuccessful = true; |
---|
143 | } |
---|
144 | catch( boost::archive::archive_exception e ) |
---|
145 | { |
---|
146 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); |
---|
147 | } |
---|
148 | catch(...){ |
---|
149 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); |
---|
150 | } |
---|
151 | |
---|
152 | if( !isSuccessful ) |
---|
153 | { |
---|
154 | return false; |
---|
155 | } |
---|
156 | |
---|
157 | return true; |
---|
158 | } |
---|
159 | bool ObjectModule::Write( const std::string &filePath ) const |
---|
160 | { |
---|
161 | bool isSuccessful = false; |
---|
162 | |
---|
163 | try{ |
---|
164 | #ifdef OBJECT_MODULE_IS_NOT_BINARY |
---|
165 | std::ofstream ofs( filePath.c_str() ); |
---|
166 | boost::archive::xml_oarchive oa(ofs); |
---|
167 | #else |
---|
168 | std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary ); |
---|
169 | boost::archive::binary_oarchive oa(ofs); |
---|
170 | #endif |
---|
171 | |
---|
172 | // ファイルに書き出し |
---|
173 | oa << 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::ReadString( const std::string &str ) |
---|
193 | { |
---|
194 | bool isSuccessful = false; |
---|
195 | |
---|
196 | // 入力アーカイブの作成 |
---|
197 | |
---|
198 | try{ |
---|
199 | #ifdef OBJECT_MODULE_IS_NOT_BINARY |
---|
200 | std::istringstream iss( str ); |
---|
201 | boost::archive::xml_iarchive ia(iss); |
---|
202 | #else |
---|
203 | std::istringstream iss( str, std::ios::in | std::ios::binary ); |
---|
204 | boost::archive::binary_iarchive ia(iss); |
---|
205 | #endif |
---|
206 | |
---|
207 | // 文字列ストリームから読込 |
---|
208 | ia >> boost::serialization::make_nvp( RootTagName(), *this ); |
---|
209 | |
---|
210 | isSuccessful = true; |
---|
211 | } |
---|
212 | catch( boost::archive::archive_exception e ) |
---|
213 | { |
---|
214 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); |
---|
215 | } |
---|
216 | catch(...){ |
---|
217 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); |
---|
218 | } |
---|
219 | |
---|
220 | if( !isSuccessful ) |
---|
221 | { |
---|
222 | return false; |
---|
223 | } |
---|
224 | |
---|
225 | return true; |
---|
226 | } |
---|
227 | bool ObjectModule::WriteString( std::string &str ) const |
---|
228 | { |
---|
229 | // 出力アーカイブの作成 |
---|
230 | |
---|
231 | bool isSuccessful = false; |
---|
232 | try{ |
---|
233 | #ifdef OBJECT_MODULE_IS_NOT_BINARY |
---|
234 | std::ostringstream oss; |
---|
235 | boost::archive::xml_oarchive oa(oss); |
---|
236 | #else |
---|
237 | std::ostringstream oss( "", std::ios::out | std::ios::binary ); |
---|
238 | boost::archive::binary_oarchive oa(oss); |
---|
239 | #endif |
---|
240 | |
---|
241 | // 文字列ストリームに書き出し |
---|
242 | oa << boost::serialization::make_nvp( RootTagName(), *this ); |
---|
243 | |
---|
244 | str = oss.str(); |
---|
245 | |
---|
246 | isSuccessful = true; |
---|
247 | } |
---|
248 | catch( boost::archive::archive_exception e ) |
---|
249 | { |
---|
250 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); |
---|
251 | } |
---|
252 | catch(...){ |
---|
253 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); |
---|
254 | } |
---|
255 | |
---|
256 | return isSuccessful; |
---|
257 | } |
---|