1 | #pragma once
|
---|
2 |
|
---|
3 | int ChangeReturnCodeImpl(char *buffer);
|
---|
4 |
|
---|
5 | class IncludedFilesRelation
|
---|
6 | {
|
---|
7 | std::vector<std::string> filePaths;
|
---|
8 | std::vector<int> lineFileNumbers;
|
---|
9 |
|
---|
10 | // XMLシリアライズ用
|
---|
11 | private:
|
---|
12 | friend class boost::serialization::access;
|
---|
13 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
14 | {
|
---|
15 | ar & BOOST_SERIALIZATION_NVP( filePaths );
|
---|
16 | ar & BOOST_SERIALIZATION_NVP( lineFileNumbers );
|
---|
17 | }
|
---|
18 |
|
---|
19 | public:
|
---|
20 | IncludedFilesRelation()
|
---|
21 | {
|
---|
22 | }
|
---|
23 | IncludedFilesRelation(IncludedFilesRelation const& y)
|
---|
24 | : filePaths(y.filePaths)
|
---|
25 | , lineFileNumbers(y.lineFileNumbers)
|
---|
26 | {
|
---|
27 | }
|
---|
28 | IncludedFilesRelation(IncludedFilesRelation&& y)
|
---|
29 | : filePaths(std::move(y.filePaths))
|
---|
30 | , lineFileNumbers(std::move(y.lineFileNumbers))
|
---|
31 | {
|
---|
32 | }
|
---|
33 | ~IncludedFilesRelation()
|
---|
34 | {
|
---|
35 | }
|
---|
36 | IncludedFilesRelation& operator =(IncludedFilesRelation&& y)
|
---|
37 | {
|
---|
38 | filePaths = std::move(y.filePaths);
|
---|
39 | lineFileNumbers = std::move(y.lineFileNumbers);
|
---|
40 | return *this;
|
---|
41 | }
|
---|
42 |
|
---|
43 | IncludedFilesRelation& operator =(IncludedFilesRelation const& y)
|
---|
44 | {
|
---|
45 | return *this = std::move(IncludedFilesRelation(y));
|
---|
46 | }
|
---|
47 |
|
---|
48 | const int GetFileNumber( int lineNumber ) const
|
---|
49 | {
|
---|
50 | return lineFileNumbers[lineNumber];
|
---|
51 | }
|
---|
52 | const std::string &GetFilePath( int lineNumber ) const
|
---|
53 | {
|
---|
54 | return filePaths[GetFileNumber( lineNumber )];
|
---|
55 | }
|
---|
56 | const std::string &GetFilePathFromFileNumber( int fileNumber ) const
|
---|
57 | {
|
---|
58 | return filePaths[fileNumber];
|
---|
59 | }
|
---|
60 | int GetFileCounts() const
|
---|
61 | {
|
---|
62 | return (int)filePaths.size();
|
---|
63 | }
|
---|
64 |
|
---|
65 | int AddFile( const std::string &filePath )
|
---|
66 | {
|
---|
67 | filePaths.push_back( filePath );
|
---|
68 | return (int)filePaths.size()-1;
|
---|
69 | }
|
---|
70 | void AddLine( int fileNumber )
|
---|
71 | {
|
---|
72 | lineFileNumbers.push_back( fileNumber );
|
---|
73 | }
|
---|
74 |
|
---|
75 | int GetLineCounts() const
|
---|
76 | {
|
---|
77 | return (int)lineFileNumbers.size();
|
---|
78 | }
|
---|
79 | };
|
---|
80 |
|
---|
81 | class Text{
|
---|
82 | protected:
|
---|
83 | char *buffer;
|
---|
84 | int length;
|
---|
85 |
|
---|
86 | public:
|
---|
87 |
|
---|
88 | Text(){
|
---|
89 | buffer = (char *)calloc( 1, 1 );
|
---|
90 | length = 0;
|
---|
91 | }
|
---|
92 | Text( const Text &text )
|
---|
93 | : length( text.length )
|
---|
94 | {
|
---|
95 | buffer = (char *)malloc( length + 1 );
|
---|
96 | memcpy( buffer, text.buffer, length );
|
---|
97 | buffer[length] = 0;
|
---|
98 | }
|
---|
99 | Text(Text&& text)
|
---|
100 | : length( text.length )
|
---|
101 | {
|
---|
102 | buffer = text.buffer;
|
---|
103 | text.buffer = static_cast<char*>(calloc(1, 1));
|
---|
104 | text.length = 0;
|
---|
105 | }
|
---|
106 | Text& operator =(Text&& y)
|
---|
107 | {
|
---|
108 | SwapImpl(*this, y);
|
---|
109 | return *this;
|
---|
110 | }
|
---|
111 | Text& operator =(Text const& y)
|
---|
112 | {
|
---|
113 | return *this = std::move(Text(y));
|
---|
114 | }
|
---|
115 | ~Text(){
|
---|
116 | free( buffer );
|
---|
117 | }
|
---|
118 | void Clear()
|
---|
119 | {
|
---|
120 | length = 0;
|
---|
121 | }
|
---|
122 | void Add( const std::string &str )
|
---|
123 | {
|
---|
124 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
125 | strcpy( buffer + length, str.c_str() );
|
---|
126 | length += (int)str.size();
|
---|
127 | }
|
---|
128 | void Add( const std::vector<char> &str )
|
---|
129 | {
|
---|
130 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
131 | strcpy( buffer + length, &str[0] );
|
---|
132 | length += (int)str.size();
|
---|
133 | }
|
---|
134 |
|
---|
135 | bool ReadFile( const std::string &filePath );
|
---|
136 |
|
---|
137 | static void SlideString(char *buffer, int slide){
|
---|
138 | memmove(buffer+slide, buffer, strlen(buffer)+1);
|
---|
139 | }
|
---|
140 |
|
---|
141 | protected:
|
---|
142 | static void SwapImpl(Text& lhs, Text& rhs)
|
---|
143 | {
|
---|
144 | std::swap(lhs.buffer, rhs.buffer);
|
---|
145 | std::swap(lhs.length, rhs.length);
|
---|
146 | }
|
---|
147 | };
|
---|
148 |
|
---|
149 | class BasicSource : public Text
|
---|
150 | {
|
---|
151 | static const std::string generateDirectiveName;
|
---|
152 |
|
---|
153 | IncludedFilesRelation includedFilesRelation;
|
---|
154 |
|
---|
155 | // XMLシリアライズ用
|
---|
156 | private:
|
---|
157 | friend class boost::serialization::access;
|
---|
158 | BOOST_SERIALIZATION_SPLIT_MEMBER();
|
---|
159 | template<class Archive> void load(Archive& ar, const unsigned int version)
|
---|
160 | {
|
---|
161 | std::string _buffer;
|
---|
162 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
163 | ar & BOOST_SERIALIZATION_NVP( length );
|
---|
164 | ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
|
---|
165 |
|
---|
166 | // 読み込み後の処理
|
---|
167 | Realloc( length );
|
---|
168 | for( int i=0; i<length; i++ )
|
---|
169 | {
|
---|
170 | ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
|
---|
171 | ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
|
---|
172 | ULONG_PTR l = l1 + l2;
|
---|
173 | buffer[i] = static_cast<char>(l);
|
---|
174 | }
|
---|
175 | buffer[length] = 0;
|
---|
176 | }
|
---|
177 | template<class Archive> void save(Archive& ar, const unsigned int version) const
|
---|
178 | {
|
---|
179 | // 保存準備
|
---|
180 | char *tempCode = (char *)calloc( (length+1) * 3, 1 );
|
---|
181 | for( int i=0; i<length; i++ )
|
---|
182 | {
|
---|
183 | char temp[32];
|
---|
184 | sprintf( temp, "%02x,", (unsigned char)buffer[i] );
|
---|
185 | tempCode[i*3] = temp[0];
|
---|
186 | tempCode[i*3+1] = temp[1];
|
---|
187 | tempCode[i*3+2] = temp[2];
|
---|
188 | }
|
---|
189 |
|
---|
190 | std::string _buffer = tempCode;
|
---|
191 | free( tempCode );
|
---|
192 |
|
---|
193 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
194 | ar & BOOST_SERIALIZATION_NVP( length );
|
---|
195 | ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
|
---|
196 | }
|
---|
197 |
|
---|
198 | private:
|
---|
199 | void Realloc( int newLength )
|
---|
200 | {
|
---|
201 | bool isEqualBasbuf = false;
|
---|
202 | extern char *basbuf;
|
---|
203 | if( basbuf == buffer + 2 )
|
---|
204 | {
|
---|
205 | isEqualBasbuf = true;
|
---|
206 | }
|
---|
207 |
|
---|
208 | buffer = (char *)realloc( buffer, newLength + 255 );
|
---|
209 |
|
---|
210 | length = newLength;
|
---|
211 |
|
---|
212 | if( isEqualBasbuf )
|
---|
213 | {
|
---|
214 | basbuf = buffer + 2;
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | void IncludeFiles();
|
---|
219 |
|
---|
220 | void ChangeReturnLineChar();
|
---|
221 |
|
---|
222 | void RemoveComments();
|
---|
223 |
|
---|
224 | bool ReadFile_InIncludeDirective( const std::string &filePath );
|
---|
225 | void DirectiveIncludeOrRequire( const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
---|
226 |
|
---|
227 | void RemoveReturnLineUnderbar();
|
---|
228 |
|
---|
229 | void Initialize( const std::string &source );
|
---|
230 |
|
---|
231 | public:
|
---|
232 | BasicSource(){}
|
---|
233 | BasicSource( const BasicSource &basicSource )
|
---|
234 | : Text( basicSource )
|
---|
235 | , includedFilesRelation( basicSource.includedFilesRelation )
|
---|
236 | {
|
---|
237 | }
|
---|
238 | BasicSource(BasicSource&& basicSource)
|
---|
239 | : Text(std::move(basicSource))
|
---|
240 | , includedFilesRelation(std::move(basicSource.includedFilesRelation))
|
---|
241 | {
|
---|
242 | }
|
---|
243 | BasicSource( const std::string &source )
|
---|
244 | {
|
---|
245 | Initialize( source );
|
---|
246 | }
|
---|
247 | ~BasicSource(){}
|
---|
248 |
|
---|
249 | char *GetBuffer(){
|
---|
250 | return buffer+2;
|
---|
251 | }
|
---|
252 | const char *GetBuffer() const
|
---|
253 | {
|
---|
254 | return buffer+2;
|
---|
255 | }
|
---|
256 | int GetLength() const
|
---|
257 | {
|
---|
258 | return length-2;
|
---|
259 | }
|
---|
260 | void _ResetLength()
|
---|
261 | {
|
---|
262 | length = static_cast<int>(strlen( buffer ));
|
---|
263 | }
|
---|
264 |
|
---|
265 | // 指定したインデックスが何行目かを取得
|
---|
266 | bool GetLineFromIndex( int index, int &result ) const;
|
---|
267 |
|
---|
268 | const IncludedFilesRelation &GetIncludedFilesRelation() const
|
---|
269 | {
|
---|
270 | return includedFilesRelation;
|
---|
271 | }
|
---|
272 |
|
---|
273 | void SetBuffer( const char *buffer );
|
---|
274 |
|
---|
275 | bool ReadFile( const std::string &filePath, bool isDebug, bool isDll, bool isUnicode, int majorVer, const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
---|
276 |
|
---|
277 | void Addition( const char *buffer );
|
---|
278 |
|
---|
279 | bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
|
---|
280 |
|
---|
281 | BasicSource& operator =(const BasicSource &source)
|
---|
282 | {
|
---|
283 | Realloc( source.length );
|
---|
284 | strcpy( buffer, source.buffer );
|
---|
285 | return *this;
|
---|
286 | }
|
---|
287 | BasicSource& operator =(BasicSource&& source)
|
---|
288 | {
|
---|
289 | Text::SwapImpl(*this, source);
|
---|
290 | return *this;
|
---|
291 | }
|
---|
292 |
|
---|
293 | char operator[]( int index ) const
|
---|
294 | {
|
---|
295 | if( index>GetLength() )
|
---|
296 | {
|
---|
297 | Jenga::Throw( "BasicSource bad access" );
|
---|
298 | }
|
---|
299 | return buffer[2+index];
|
---|
300 | }
|
---|
301 |
|
---|
302 | std::string cannotIncludePath;
|
---|
303 | int cannotIncludeSourcePos;
|
---|
304 | };
|
---|
305 | class BasicSources
|
---|
306 | : public std::vector<BasicSource>
|
---|
307 | , public Jenga::Common::BoostSerializationSupport<BasicSources>
|
---|
308 | {
|
---|
309 | // XMLシリアライズ用
|
---|
310 | private:
|
---|
311 | virtual const char *RootTagName() const
|
---|
312 | {
|
---|
313 | return "basicSources";
|
---|
314 | }
|
---|
315 | friend class boost::serialization::access;
|
---|
316 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
317 | {
|
---|
318 | ar & boost::serialization::make_nvp("vector_BasicSource", boost::serialization::base_object<std::vector<BasicSource>>(*this));
|
---|
319 | }
|
---|
320 |
|
---|
321 | public:
|
---|
322 | BasicSources() {}
|
---|
323 | BasicSources(BasicSources&& y) : std::vector<BasicSource>(std::move(y)) {}
|
---|
324 | BasicSources(BasicSources const& y) : std::vector<BasicSource>(y) {}
|
---|
325 | BasicSources operator =(BasicSources&& y)
|
---|
326 | {
|
---|
327 | std::vector<BasicSource>::operator =(std::move(y));
|
---|
328 | return *this;
|
---|
329 | }
|
---|
330 | BasicSources operator =(BasicSources const& y)
|
---|
331 | {
|
---|
332 | return *this = std::move(BasicSources(y));
|
---|
333 | }
|
---|
334 | };
|
---|
335 |
|
---|
336 | class SourceCodePosition
|
---|
337 | {
|
---|
338 | int relationalObjectModuleIndex;
|
---|
339 | int pos;
|
---|
340 |
|
---|
341 | // XMLシリアライズ用
|
---|
342 | private:
|
---|
343 | friend class boost::serialization::access;
|
---|
344 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
345 | {
|
---|
346 | ar & BOOST_SERIALIZATION_NVP( relationalObjectModuleIndex );
|
---|
347 | ar & BOOST_SERIALIZATION_NVP( pos );
|
---|
348 | }
|
---|
349 |
|
---|
350 | public:
|
---|
351 | SourceCodePosition( int relationalObjectModuleIndex, int pos )
|
---|
352 | : relationalObjectModuleIndex( relationalObjectModuleIndex )
|
---|
353 | , pos( pos )
|
---|
354 | {
|
---|
355 | }
|
---|
356 | SourceCodePosition()
|
---|
357 | : relationalObjectModuleIndex( -1 )
|
---|
358 | , pos( -1 )
|
---|
359 | {
|
---|
360 | }
|
---|
361 | SourceCodePosition(SourceCodePosition const& y)
|
---|
362 | : relationalObjectModuleIndex(y.relationalObjectModuleIndex)
|
---|
363 | , pos(y.pos)
|
---|
364 | {
|
---|
365 | }
|
---|
366 |
|
---|
367 | SourceCodePosition& operator =(SourceCodePosition const& y)
|
---|
368 | {
|
---|
369 | relationalObjectModuleIndex = y.relationalObjectModuleIndex;
|
---|
370 | pos = y.pos;
|
---|
371 | return *this;
|
---|
372 | }
|
---|
373 |
|
---|
374 | int GetRelationalObjectModuleIndex() const;
|
---|
375 | void SetRelationalObjectModuleIndex( int relationalObjectModuleIndex )
|
---|
376 | {
|
---|
377 | this->relationalObjectModuleIndex = relationalObjectModuleIndex;
|
---|
378 | }
|
---|
379 | int GetPos() const
|
---|
380 | {
|
---|
381 | return pos;
|
---|
382 | }
|
---|
383 | void SetPos( int pos )
|
---|
384 | {
|
---|
385 | this->pos = pos;
|
---|
386 | }
|
---|
387 |
|
---|
388 | bool IsNothing() const;
|
---|
389 | };
|
---|