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

Last change on this file since 600 was 600, checked in by dai_9181, 16 years ago

依存関係を整理中

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