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

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

ヘッダファイルを整理中

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