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