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