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

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

NamespaceScopes、NamespaceScopesCollectionクラスをab_commonプロジェクトに移動した。

File size: 5.1 KB
Line 
1#include <string>
2#include <vector>
3#include <fstream>
4
5#include <windows.h>
6#include <stdio.h>
7#include <string.h>
8#include <math.h>
9#include <commctrl.h>
10#include <time.h>
11#include <limits.h>
12#include <shlobj.h>
13
14//boost libraries
15#include <boost/foreach.hpp>
16
17#include <jenga/include/common/String.h>
18
19#include "../common.h"
20#include "../BasicFixed.h"
21
22
23// ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
24//#define OBJECT_MODULE_IS_NOT_BINARY
25
26
27#ifdef OBJECT_MODULE_IS_NOT_BINARY
28#include <boost/archive/xml_oarchive.hpp>
29#include <boost/archive/xml_iarchive.hpp>
30#else
31#include <boost/archive/binary_oarchive.hpp>
32#include <boost/archive/binary_iarchive.hpp>
33#endif
34#include <boost/serialization/string.hpp>
35#include <boost/serialization/access.hpp>
36#include <boost/serialization/level.hpp>
37#include <boost/serialization/vector.hpp>
38#include <boost/serialization/map.hpp>
39#include <boost/serialization/version.hpp>
40#include <boost/serialization/is_abstract.hpp>
41
42#include <BoostSerializationSupport.h>
43
44#include <abdev/ab_common/Environment.h>
45#include <abdev/ab_common/include/Namespace.h>
46
47using namespace ActiveBasic::Common::Lexical;
48
49#include <Hashmap.h>
50#include <Compiler.h>
51
52
53void ObjectModule::StaticLink( ObjectModule &objectModule )
54{
55 long dataSectionBaseOffset = dataTable.GetSize();
56 int sourceIndexBase = (int)sources.size();
57
58 // メタ情報を結合
59 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
60
61 // グローバル ネイティブコードを結合
62 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
63 objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
64 globalNativeCode.PutEx( objectModule.globalNativeCode );
65
66 // データテーブルを結合
67 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
68 dataTable.Add( objectModule.dataTable );
69
70 // ソースコードを結合
71 BOOST_FOREACH( const BasicSource &source, objectModule.sources )
72 {
73 this->sources.push_back( source );
74 }
75
76 // TODO: basbufがいらなくなったら消す
77 extern char *basbuf;
78 basbuf = this->sources[0].GetBuffer();
79}
80
81bool ObjectModule::Read( const std::string &filePath )
82{
83 // XMLとして読み込む
84 bool isSuccessful = false;
85
86 try{
87#ifdef OBJECT_MODULE_IS_NOT_BINARY
88 std::ifstream ifs( filePath.c_str() );
89 boost::archive::xml_iarchive ia(ifs);
90#else
91 std::ifstream ifs( filePath.c_str(), ios::in | ios::binary );
92 boost::archive::binary_iarchive ia(ifs);
93#endif
94
95 // ファイルから読込
96 ia >> boost::serialization::make_nvp( RootTagName(), *this );
97
98 isSuccessful = true;
99 }
100 catch( boost::archive::archive_exception e )
101 {
102 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
103 }
104 catch(...){
105 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
106 }
107
108 if( !isSuccessful )
109 {
110 return false;
111 }
112
113 return true;
114}
115bool ObjectModule::Write( const std::string &filePath ) const
116{
117 bool isSuccessful = false;
118
119 try{
120#ifdef OBJECT_MODULE_IS_NOT_BINARY
121 std::ofstream ofs( filePath.c_str() );
122 boost::archive::xml_oarchive oa(ofs);
123#else
124 std::ofstream ofs( filePath.c_str(), ios::out | ios::binary );
125 boost::archive::binary_oarchive oa(ofs);
126#endif
127
128 // ファイルに書き出し
129 oa << boost::serialization::make_nvp( RootTagName(), *this );
130
131 isSuccessful = true;
132 }
133 catch( boost::archive::archive_exception e )
134 {
135 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
136 }
137 catch(...){
138 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
139 }
140
141 if( !isSuccessful )
142 {
143 return false;
144 }
145
146 return true;
147}
148bool ObjectModule::ReadString( const std::string &str )
149{
150 bool isSuccessful = false;
151
152 // 入力アーカイブの作成
153
154 try{
155#ifdef OBJECT_MODULE_IS_NOT_BINARY
156 std::istringstream iss( str );
157 boost::archive::xml_iarchive ia(iss);
158#else
159 std::istringstream iss( str, ios::in | ios::binary );
160 boost::archive::binary_iarchive ia(iss);
161#endif
162
163 // 文字列ストリームから読込
164 ia >> boost::serialization::make_nvp( RootTagName(), *this );
165
166 isSuccessful = true;
167 }
168 catch( boost::archive::archive_exception e )
169 {
170 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
171 }
172 catch(...){
173 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
174 }
175
176 if( !isSuccessful )
177 {
178 return false;
179 }
180
181 return true;
182}
183bool ObjectModule::WriteString( std::string &str ) const
184{
185 // 出力アーカイブの作成
186
187 bool isSuccessful = false;
188 try{
189#ifdef OBJECT_MODULE_IS_NOT_BINARY
190 std::ostringstream oss;
191 boost::archive::xml_oarchive oa(oss);
192#else
193 std::ostringstream oss( "", ios::out | ios::binary );
194 boost::archive::binary_oarchive oa(oss);
195#endif
196
197 // 文字列ストリームに書き出し
198 oa << boost::serialization::make_nvp( RootTagName(), *this );
199
200 str = oss.str();
201
202 isSuccessful = true;
203 }
204 catch( boost::archive::archive_exception e )
205 {
206 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
207 }
208 catch(...){
209 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
210 }
211
212 return isSuccessful;
213}
Note: See TracBrowser for help on using the repository browser.