source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Source.h@ 700

Last change on this file since 700 was 700, checked in by イグトランス (egtra), 16 years ago

CRequireFilesの管理をhash_setベースへ。保存時にFileIndexの記録を行っていなかった問題を修正。rev.669でコミットし忘れのcompiler_x86/NumOpe.cppを追加。

File size: 6.8 KB
Line 
1#pragma once
2
3class IncludedFilesRelation
4{
5 std::vector<std::string> filePaths;
6 std::vector<int> lineFileNumbers;
7
8 // XMLシリアライズ用
9private:
10 friend class boost::serialization::access;
11 template<class Archive> void serialize(Archive& ar, const unsigned int version)
12 {
13 ar & BOOST_SERIALIZATION_NVP( filePaths );
14 ar & BOOST_SERIALIZATION_NVP( lineFileNumbers );
15 }
16
17public:
18 IncludedFilesRelation()
19 {
20 }
21 ~IncludedFilesRelation()
22 {
23 }
24
25 const int GetFileNumber( int lineNumber ) const
26 {
27 return lineFileNumbers[lineNumber];
28 }
29 const std::string &GetFilePath( int lineNumber ) const
30 {
31 return filePaths[GetFileNumber( lineNumber )];
32 }
33 const std::string &GetFilePathFromFileNumber( int fileNumber ) const
34 {
35 return filePaths[fileNumber];
36 }
37 int GetFileCounts() const
38 {
39 return (int)filePaths.size();
40 }
41
42 int AddFile( const std::string &filePath )
43 {
44 filePaths.push_back( filePath );
45 return (int)filePaths.size()-1;
46 }
47 void AddLine( int fileNumber )
48 {
49 lineFileNumbers.push_back( fileNumber );
50 }
51
52 int GetLineCounts() const
53 {
54 return (int)lineFileNumbers.size();
55 }
56};
57
58class Text{
59protected:
60 char *buffer;
61 int length;
62
63public:
64
65 Text(){
66 buffer = (char *)calloc( 1, 1 );
67 length = 0;
68 }
69 Text( const Text &text )
70 : length( text.length )
71 {
72 buffer = (char *)malloc( length + 1 );
73 memcpy( buffer, text.buffer, length );
74 buffer[length] = 0;
75 }
76 ~Text(){
77 free( buffer );
78 }
79 void Clear()
80 {
81 length = 0;
82 }
83 void Add( const std::string &str )
84 {
85 buffer = (char *)realloc( buffer, length + str.size() + 1 );
86 strcpy( buffer + length, str.c_str() );
87 length += (int)str.size();
88 }
89 void Add( const std::vector<char> &str )
90 {
91 buffer = (char *)realloc( buffer, length + str.size() + 1 );
92 strcpy( buffer + length, &str[0] );
93 length += (int)str.size();
94 }
95
96 bool ReadFile( const std::string &filePath );
97
98 static void Text::SlideString(char *buffer, int slide){
99 memmove(buffer+slide, buffer, strlen(buffer)+1);
100 }
101};
102
103class BasicSource : public Text
104{
105 static const std::string generateDirectiveName;
106
107 IncludedFilesRelation includedFilesRelation;
108
109 // XMLシリアライズ用
110private:
111 friend class boost::serialization::access;
112 BOOST_SERIALIZATION_SPLIT_MEMBER();
113 template<class Archive> void load(Archive& ar, const unsigned int version)
114 {
115 std::string _buffer;
116 ar & BOOST_SERIALIZATION_NVP( _buffer );
117 ar & BOOST_SERIALIZATION_NVP( length );
118 ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
119
120 // 読み込み後の処理
121 Realloc( length );
122 for( int i=0; i<length; i++ )
123 {
124 ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
125 ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
126 ULONG_PTR l = l1 + l2;
127 buffer[i] = static_cast<char>(l);
128 }
129 buffer[length] = 0;
130 }
131 template<class Archive> void save(Archive& ar, const unsigned int version) const
132 {
133 // 保存準備
134 char *tempCode = (char *)calloc( (length+1) * 3, 1 );
135 for( int i=0; i<length; i++ )
136 {
137 char temp[32];
138 sprintf( temp, "%02x,", (unsigned char)buffer[i] );
139 tempCode[i*3] = temp[0];
140 tempCode[i*3+1] = temp[1];
141 tempCode[i*3+2] = temp[2];
142 }
143
144 std::string _buffer = tempCode;
145 free( tempCode );
146
147 ar & BOOST_SERIALIZATION_NVP( _buffer );
148 ar & BOOST_SERIALIZATION_NVP( length );
149 ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
150 }
151
152private:
153 void Realloc( int newLength )
154 {
155 bool isEqualBasbuf = false;
156 extern char *basbuf;
157 if( basbuf == buffer + 2 )
158 {
159 isEqualBasbuf = true;
160 }
161
162 buffer = (char *)realloc( buffer, newLength + 255 );
163
164 length = newLength;
165
166 if( isEqualBasbuf )
167 {
168 basbuf = buffer + 2;
169 }
170 }
171
172 void IncludeFiles();
173
174 void ChangeReturnLineChar();
175
176 void RemoveComments();
177
178 bool ReadFile_InIncludeDirective( const std::string &filePath );
179 void DirectiveIncludeOrRequire( const std::string &mainSourceFilePath, const std::string &includeDirPath );
180
181 void RemoveReturnLineUnderbar();
182
183 void Initialize( const std::string &source );
184
185public:
186 BasicSource(){}
187 BasicSource( const BasicSource &basicSource )
188 : Text( basicSource )
189 , includedFilesRelation( basicSource.includedFilesRelation )
190 {
191 }
192 BasicSource( const std::string &source )
193 {
194 Initialize( source );
195 }
196 ~BasicSource(){}
197
198 char *GetBuffer(){
199 return buffer+2;
200 }
201 const char *GetBuffer() const
202 {
203 return buffer+2;
204 }
205 int GetLength() const
206 {
207 return length-2;
208 }
209 void _ResetLength()
210 {
211 length = strlen( buffer );
212 }
213
214 const IncludedFilesRelation &GetIncludedFilesRelation() const
215 {
216 return includedFilesRelation;
217 }
218
219 void SetBuffer( const char *buffer );
220
221 bool ReadFile( const std::string &filePath, bool isDebug, bool isDll, bool isUnicode, int majorVer, const std::string &mainSourceFilePath, const std::string &includeDirPath );
222
223 void Addition( const char *buffer );
224
225 bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
226
227 void operator = ( const BasicSource &source ){
228 Realloc( source.length );
229 strcpy( buffer, source.buffer );
230 }
231
232 char operator[]( int index ) const
233 {
234 if( index>GetLength() )
235 {
236 Jenga::Throw( "BasicSource bad access" );
237 }
238 return buffer[2+index];
239 }
240
241 std::string cannotIncludePath;
242 int cannotIncludeSourcePos;
243};
244class BasicSources
245 : public std::vector<BasicSource>
246 , public Jenga::Common::BoostSerializationSupport<BasicSources>
247{
248 // XMLシリアライズ用
249private:
250 virtual const char *RootTagName() const
251 {
252 return "basicSources";
253 }
254 friend class boost::serialization::access;
255 template<class Archive> void serialize(Archive& ar, const unsigned int version)
256 {
257 ar & boost::serialization::make_nvp("vector_BasicSource", boost::serialization::base_object<std::vector<BasicSource>>(*this));
258 }
259};
260
261class SourceCodePosition
262{
263 int relationalObjectModuleIndex;
264 int pos;
265
266 // XMLシリアライズ用
267private:
268 friend class boost::serialization::access;
269 template<class Archive> void serialize(Archive& ar, const unsigned int version)
270 {
271 ar & BOOST_SERIALIZATION_NVP( relationalObjectModuleIndex );
272 ar & BOOST_SERIALIZATION_NVP( pos );
273 }
274
275public:
276 SourceCodePosition( int relationalObjectModuleIndex, int pos )
277 : relationalObjectModuleIndex( relationalObjectModuleIndex )
278 , pos( pos )
279 {
280 }
281 SourceCodePosition()
282 : relationalObjectModuleIndex( -1 )
283 , pos( -1 )
284 {
285 }
286
287 int GetRelationalObjectModuleIndex() const;
288 void SetRelationalObjectModuleIndex( int relationalObjectModuleIndex )
289 {
290 this->relationalObjectModuleIndex = relationalObjectModuleIndex;
291 }
292 int GetPos() const
293 {
294 return pos;
295 }
296 void SetPos( int pos )
297 {
298 this->pos = pos;
299 }
300
301 bool IsNothing() const;
302};
Note: See TracBrowser for help on using the repository browser.