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
RevLine 
[520]1#pragma warning(disable : 4996)
2
3#include <map>
[404]4#include <string>
5#include <vector>
6#include <fstream>
[520]7#include <iostream>
[522]8#include <iomanip>
9#include <ios>
10#include <streambuf>
11#include <sstream>
[274]12
[404]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>
[520]21#include <process.h>
22#include <fcntl.h>
23#include <io.h>
24#include <shlwapi.h>
[522]25#include <tchar.h>
26#include <stdarg.h>
[404]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>
[523]50#include <boost/serialization/serialization.hpp>
51#include <boost/serialization/nvp.hpp>
52#include <boost/serialization/export.hpp>
[404]53
[520]54#include <jenga/include/jenga.h>
[600]55#include <abdev/ab_common/include/ab_common.h>
[505]56
[520]57#include "../common.h"
58#include "../BasicFixed.h"
59
[527]60#include <option.h>
61
[505]62using namespace ActiveBasic::Common::Lexical;
63
[524]64#include <NativeCode.h>
[522]65#include <Source.h>
[513]66#include <Type.h>
67#include <Method.h>
68#include <Interface.h>
[522]69#include <Member.h>
[511]70#include <Class.h>
[524]71#include <Parameter.h>
72#include <Variable.h>
[511]73#include <Procedure.h>
[524]74#include <TypeDef.h>
75#include <Const.h>
76#include <Delegate.h>
77#include <Enum.h>
78#include <Meta.h>
[594]79#include <DataTable.h>
80#include <ObjectModule.h>
[525]81
[274]82
83void ObjectModule::StaticLink( ObjectModule &objectModule )
84{
[587]85 long dataSectionBaseOffset = dataTable.GetSize();
86 int sourceIndexBase = (int)sources.size();
[280]87
[274]88 // メタ情報を結合
[280]89 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
[274]90
[395]91 // グローバル ネイティブコードを結合
[587]92 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
93 objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
94 globalNativeCode.PutEx( objectModule.globalNativeCode );
[276]95
[274]96 // データテーブルを結合
[587]97 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
98 dataTable.Add( objectModule.dataTable );
[280]99
100 // ソースコードを結合
[587]101 BOOST_FOREACH( const BasicSource &source, objectModule.sources )
[280]102 {
[587]103 this->sources.push_back( source );
[280]104 }
[282]105
106 // TODO: basbufがいらなくなったら消す
107 extern char *basbuf;
[587]108 basbuf = this->sources[0].GetBuffer();
[274]109}
[279]110
111bool ObjectModule::Read( const std::string &filePath )
112{
[587]113 // XMLとして読み込む
114 bool isSuccessful = false;
[404]115
[587]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 )
[279]131 {
[587]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 {
[404]140 return false;
141 }
142
[587]143 return true;
[279]144}
145bool ObjectModule::Write( const std::string &filePath ) const
146{
[587]147 bool isSuccessful = false;
[404]148
[587]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 )
[279]164 {
[587]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 {
[404]173 return false;
174 }
175
[587]176 return true;
[279]177}
[587]178bool ObjectModule::ReadString( const std::string &str )
[279]179{
[404]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
[523]189 std::istringstream iss( str, std::ios::in | std::ios::binary );
[404]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 )
[279]199 {
[404]200 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]201 }
[404]202 catch(...){
203 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
204 }
205
206 if( !isSuccessful )
207 {
208 return false;
209 }
210
211 return true;
[279]212}
[587]213bool ObjectModule::WriteString( std::string &str ) const
[279]214{
[404]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
[523]223 std::ostringstream oss( "", std::ios::out | std::ios::binary );
[404]224 boost::archive::binary_oarchive oa(oss);
225#endif
226
227 // 文字列ストリームに書き出し
228 oa << boost::serialization::make_nvp( RootTagName(), *this );
229
[587]230 str = oss.str();
[404]231
232 isSuccessful = true;
233 }
234 catch( boost::archive::archive_exception e )
[279]235 {
[404]236 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]237 }
[404]238 catch(...){
239 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
240 }
241
242 return isSuccessful;
[279]243}
Note: See TracBrowser for help on using the repository browser.