source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/ObjectModule.cpp@ 528

Last change on this file since 528 was 527, checked in by dai_9181, 17 years ago

ヘッダファイルを整理中

File size: 6.1 KB
Line 
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 <option.h>
60
61#include <abdev/ab_common/include/ab_common.h>
62
63using namespace ActiveBasic::Common::Lexical;
64
65#include <Binary.h>
66#include <NativeCode.h>
67#include <Source.h>
68#include <Type.h>
69#include <Method.h>
70#include <Interface.h>
71#include <Member.h>
72#include <Class.h>
73#include <Parameter.h>
74#include <Variable.h>
75#include <Procedure.h>
76#include <TypeDef.h>
77#include <Const.h>
78#include <Delegate.h>
79#include <Enum.h>
80#include <DataTable.h>
81#include <Exception.h>
82#include <Meta.h>
83
84#include <logger.h>
85#include <Configuration.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#include <LexicalAnalyzer.h>
94
95
96
97void 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
125bool 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}
159bool 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}
192bool 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}
227bool 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}
Note: See TracBrowser for help on using the repository browser.