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

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

BasicFixed.hをab_commonプロジェクトに移動。

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