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
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>
50
[520]51#include <jenga/include/jenga.h>
[505]52
[520]53#include "../common.h"
54#include "../BasicFixed.h"
55
[515]56#include <abdev/ab_common/include/ab_common.h>
[505]57
58using namespace ActiveBasic::Common::Lexical;
59
[522]60#include <option.h>
61#include <logger.h>
[508]62#include <Configuration.h>
[522]63#include <Source.h>
[513]64#include <Type.h>
65#include <Method.h>
66#include <Interface.h>
[522]67#include <Member.h>
[511]68#include <Class.h>
69#include <Procedure.h>
[508]70#include <LexicalAnalyzer.h>
71#include <Program.h>
[274]72#include <Compiler.h>
[508]73#include <Debugger.h>
[522]74#include <Program.h>
[274]75
[279]76
[274]77void ObjectModule::StaticLink( ObjectModule &objectModule )
78{
[280]79 long dataSectionBaseOffset = dataTable.GetSize();
[308]80 int sourceIndexBase = (int)sources.size();
[280]81
[274]82 // メタ情報を結合
[280]83 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
[274]84
[395]85 // グローバル ネイティブコードを結合
[280]86 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
87 objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
[287]88 globalNativeCode.PutEx( objectModule.globalNativeCode );
[276]89
[274]90 // データテーブルを結合
[355]91 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
[274]92 dataTable.Add( objectModule.dataTable );
[280]93
94 // ソースコードを結合
95 BOOST_FOREACH( const BasicSource &source, objectModule.sources )
96 {
97 this->sources.push_back( source );
98 }
[282]99
100 // TODO: basbufがいらなくなったら消す
101 extern char *basbuf;
102 basbuf = this->sources[0].GetBuffer();
[274]103}
[279]104
105bool ObjectModule::Read( const std::string &filePath )
106{
[404]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 )
[279]125 {
[404]126 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]127 }
[404]128 catch(...){
129 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
130 }
131
132 if( !isSuccessful )
133 {
134 return false;
135 }
136
137 return true;
[279]138}
139bool ObjectModule::Write( const std::string &filePath ) const
140{
[404]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 )
[279]158 {
[404]159 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]160 }
[404]161 catch(...){
162 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
163 }
164
165 if( !isSuccessful )
166 {
167 return false;
168 }
169
170 return true;
[279]171}
172bool ObjectModule::ReadString( const std::string &str )
173{
[404]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 )
[279]193 {
[404]194 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]195 }
[404]196 catch(...){
197 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
198 }
199
200 if( !isSuccessful )
201 {
202 return false;
203 }
204
205 return true;
[279]206}
207bool ObjectModule::WriteString( std::string &str ) const
208{
[404]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 )
[279]229 {
[404]230 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]231 }
[404]232 catch(...){
233 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
234 }
235
236 return isSuccessful;
[279]237}
Note: See TracBrowser for help on using the repository browser.