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

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