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

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

Interfaceクラスを独自ファイルにした。

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