[266] | 1 | #pragma once
|
---|
| 2 |
|
---|
[735] | 3 | int ChangeReturnCodeImpl(char *buffer);
|
---|
| 4 |
|
---|
[279] | 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 | }
|
---|
[810] | 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 | }
|
---|
[279] | 33 | ~IncludedFilesRelation()
|
---|
| 34 | {
|
---|
| 35 | }
|
---|
[810] | 36 | IncludedFilesRelation& operator =(IncludedFilesRelation&& y)
|
---|
| 37 | {
|
---|
| 38 | filePaths = std::move(y.filePaths);
|
---|
| 39 | lineFileNumbers = std::move(y.lineFileNumbers);
|
---|
| 40 | return *this;
|
---|
| 41 | }
|
---|
[279] | 42 |
|
---|
[810] | 43 | IncludedFilesRelation& operator =(IncludedFilesRelation const& y)
|
---|
| 44 | {
|
---|
| 45 | return *this = std::move(IncludedFilesRelation(y));
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[279] | 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 | {
|
---|
[308] | 62 | return (int)filePaths.size();
|
---|
[279] | 63 | }
|
---|
| 64 |
|
---|
| 65 | int AddFile( const std::string &filePath )
|
---|
| 66 | {
|
---|
| 67 | filePaths.push_back( filePath );
|
---|
[308] | 68 | return (int)filePaths.size()-1;
|
---|
[279] | 69 | }
|
---|
| 70 | void AddLine( int fileNumber )
|
---|
| 71 | {
|
---|
| 72 | lineFileNumbers.push_back( fileNumber );
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | int GetLineCounts() const
|
---|
| 76 | {
|
---|
[308] | 77 | return (int)lineFileNumbers.size();
|
---|
[279] | 78 | }
|
---|
| 79 | };
|
---|
| 80 |
|
---|
[266] | 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 | }
|
---|
[280] | 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 | }
|
---|
[810] | 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 | }
|
---|
[816] | 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 | }
|
---|
[266] | 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 );
|
---|
[700] | 125 | strcpy( buffer + length, str.c_str() );
|
---|
[266] | 126 | length += (int)str.size();
|
---|
| 127 | }
|
---|
[268] | 128 | void Add( const std::vector<char> &str )
|
---|
| 129 | {
|
---|
| 130 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
[700] | 131 | strcpy( buffer + length, &str[0] );
|
---|
[268] | 132 | length += (int)str.size();
|
---|
| 133 | }
|
---|
[266] | 134 |
|
---|
[523] | 135 | bool ReadFile( const std::string &filePath );
|
---|
[266] | 136 |
|
---|
[735] | 137 | static void SlideString(char *buffer, int slide){
|
---|
[700] | 138 | memmove(buffer+slide, buffer, strlen(buffer)+1);
|
---|
[266] | 139 | }
|
---|
[810] | 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 | }
|
---|
[266] | 147 | };
|
---|
| 148 |
|
---|
| 149 | class BasicSource : public Text
|
---|
| 150 | {
|
---|
[523] | 151 | static const std::string generateDirectiveName;
|
---|
[266] | 152 |
|
---|
[279] | 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:
|
---|
[281] | 199 | void Realloc( int newLength )
|
---|
| 200 | {
|
---|
| 201 | bool isEqualBasbuf = false;
|
---|
| 202 | extern char *basbuf;
|
---|
[282] | 203 | if( basbuf == buffer + 2 )
|
---|
[281] | 204 | {
|
---|
| 205 | isEqualBasbuf = true;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[266] | 208 | buffer = (char *)realloc( buffer, newLength + 255 );
|
---|
| 209 |
|
---|
| 210 | length = newLength;
|
---|
| 211 |
|
---|
[281] | 212 | if( isEqualBasbuf )
|
---|
| 213 | {
|
---|
| 214 | basbuf = buffer + 2;
|
---|
| 215 | }
|
---|
[266] | 216 | }
|
---|
| 217 |
|
---|
| 218 | void IncludeFiles();
|
---|
| 219 |
|
---|
| 220 | void ChangeReturnLineChar();
|
---|
| 221 |
|
---|
| 222 | void RemoveComments();
|
---|
| 223 |
|
---|
[523] | 224 | bool ReadFile_InIncludeDirective( const std::string &filePath );
|
---|
[602] | 225 | void DirectiveIncludeOrRequire( const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
---|
[266] | 226 |
|
---|
| 227 | void RemoveReturnLineUnderbar();
|
---|
| 228 |
|
---|
[322] | 229 | void Initialize( const std::string &source );
|
---|
| 230 |
|
---|
[266] | 231 | public:
|
---|
| 232 | BasicSource(){}
|
---|
[280] | 233 | BasicSource( const BasicSource &basicSource )
|
---|
| 234 | : Text( basicSource )
|
---|
| 235 | , includedFilesRelation( basicSource.includedFilesRelation )
|
---|
| 236 | {
|
---|
| 237 | }
|
---|
[810] | 238 | BasicSource(BasicSource&& basicSource)
|
---|
| 239 | : Text(std::move(basicSource))
|
---|
| 240 | , includedFilesRelation(std::move(basicSource.includedFilesRelation))
|
---|
| 241 | {
|
---|
| 242 | }
|
---|
[322] | 243 | BasicSource( const std::string &source )
|
---|
| 244 | {
|
---|
| 245 | Initialize( source );
|
---|
| 246 | }
|
---|
[266] | 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 | }
|
---|
[304] | 260 | void _ResetLength()
|
---|
| 261 | {
|
---|
[739] | 262 | length = static_cast<int>(strlen( buffer ));
|
---|
[304] | 263 | }
|
---|
[266] | 264 |
|
---|
[739] | 265 | // 指定したインデックスが何行目かを取得
|
---|
| 266 | bool GetLineFromIndex( int index, int &result ) const;
|
---|
| 267 |
|
---|
[279] | 268 | const IncludedFilesRelation &GetIncludedFilesRelation() const
|
---|
| 269 | {
|
---|
| 270 | return includedFilesRelation;
|
---|
| 271 | }
|
---|
| 272 |
|
---|
[266] | 273 | void SetBuffer( const char *buffer );
|
---|
| 274 |
|
---|
[602] | 275 | bool ReadFile( const std::string &filePath, bool isDebug, bool isDll, bool isUnicode, int majorVer, const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
---|
[266] | 276 |
|
---|
| 277 | void Addition( const char *buffer );
|
---|
| 278 |
|
---|
[280] | 279 | bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
|
---|
[279] | 280 |
|
---|
[810] | 281 | BasicSource& operator =(const BasicSource &source)
|
---|
| 282 | {
|
---|
[266] | 283 | Realloc( source.length );
|
---|
[700] | 284 | strcpy( buffer, source.buffer );
|
---|
[810] | 285 | return *this;
|
---|
[266] | 286 | }
|
---|
[810] | 287 | BasicSource& operator =(BasicSource&& source)
|
---|
| 288 | {
|
---|
| 289 | Text::SwapImpl(*this, source);
|
---|
| 290 | return *this;
|
---|
| 291 | }
|
---|
[266] | 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 | }
|
---|
[555] | 301 |
|
---|
| 302 | std::string cannotIncludePath;
|
---|
| 303 | int cannotIncludeSourcePos;
|
---|
[266] | 304 | };
|
---|
[636] | 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 | }
|
---|
[816] | 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 | }
|
---|
[636] | 334 | };
|
---|
[632] | 335 |
|
---|
| 336 | class SourceCodePosition
|
---|
| 337 | {
|
---|
[637] | 338 | int relationalObjectModuleIndex;
|
---|
[632] | 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 | {
|
---|
[637] | 346 | ar & BOOST_SERIALIZATION_NVP( relationalObjectModuleIndex );
|
---|
[632] | 347 | ar & BOOST_SERIALIZATION_NVP( pos );
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | public:
|
---|
[637] | 351 | SourceCodePosition( int relationalObjectModuleIndex, int pos )
|
---|
| 352 | : relationalObjectModuleIndex( relationalObjectModuleIndex )
|
---|
[632] | 353 | , pos( pos )
|
---|
| 354 | {
|
---|
| 355 | }
|
---|
| 356 | SourceCodePosition()
|
---|
[637] | 357 | : relationalObjectModuleIndex( -1 )
|
---|
| 358 | , pos( -1 )
|
---|
[632] | 359 | {
|
---|
| 360 | }
|
---|
[816] | 361 | SourceCodePosition(SourceCodePosition const& y)
|
---|
| 362 | : relationalObjectModuleIndex(y.relationalObjectModuleIndex)
|
---|
| 363 | , pos(y.pos)
|
---|
| 364 | {
|
---|
| 365 | }
|
---|
[632] | 366 |
|
---|
[816] | 367 | SourceCodePosition& operator =(SourceCodePosition const& y)
|
---|
| 368 | {
|
---|
| 369 | relationalObjectModuleIndex = y.relationalObjectModuleIndex;
|
---|
| 370 | pos = y.pos;
|
---|
| 371 | return *this;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
[637] | 374 | int GetRelationalObjectModuleIndex() const;
|
---|
| 375 | void SetRelationalObjectModuleIndex( int relationalObjectModuleIndex )
|
---|
[632] | 376 | {
|
---|
[637] | 377 | this->relationalObjectModuleIndex = relationalObjectModuleIndex;
|
---|
[632] | 378 | }
|
---|
| 379 | int GetPos() const
|
---|
| 380 | {
|
---|
| 381 | return pos;
|
---|
| 382 | }
|
---|
[637] | 383 | void SetPos( int pos )
|
---|
| 384 | {
|
---|
| 385 | this->pos = pos;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | bool IsNothing() const;
|
---|
[632] | 389 | };
|
---|