[266] | 1 | #pragma once
|
---|
| 2 |
|
---|
[279] | 3 | class IncludedFilesRelation
|
---|
| 4 | {
|
---|
| 5 | std::vector<std::string> filePaths;
|
---|
| 6 | std::vector<int> lineFileNumbers;
|
---|
| 7 |
|
---|
| 8 | // XMLシリアライズ用
|
---|
| 9 | private:
|
---|
| 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 |
|
---|
| 17 | public:
|
---|
| 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 | {
|
---|
[308] | 39 | return (int)filePaths.size();
|
---|
[279] | 40 | }
|
---|
| 41 |
|
---|
| 42 | int AddFile( const std::string &filePath )
|
---|
| 43 | {
|
---|
| 44 | filePaths.push_back( filePath );
|
---|
[308] | 45 | return (int)filePaths.size()-1;
|
---|
[279] | 46 | }
|
---|
| 47 | void AddLine( int fileNumber )
|
---|
| 48 | {
|
---|
| 49 | lineFileNumbers.push_back( fileNumber );
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | int GetLineCounts() const
|
---|
| 53 | {
|
---|
[308] | 54 | return (int)lineFileNumbers.size();
|
---|
[279] | 55 | }
|
---|
| 56 | };
|
---|
| 57 |
|
---|
[266] | 58 | class Text{
|
---|
| 59 | protected:
|
---|
| 60 | char *buffer;
|
---|
| 61 | int length;
|
---|
| 62 |
|
---|
| 63 | public:
|
---|
| 64 |
|
---|
| 65 | Text(){
|
---|
| 66 | buffer = (char *)calloc( 1, 1 );
|
---|
| 67 | length = 0;
|
---|
| 68 | }
|
---|
[280] | 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 | }
|
---|
[266] | 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 );
|
---|
[700] | 86 | strcpy( buffer + length, str.c_str() );
|
---|
[266] | 87 | length += (int)str.size();
|
---|
| 88 | }
|
---|
[268] | 89 | void Add( const std::vector<char> &str )
|
---|
| 90 | {
|
---|
| 91 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
[700] | 92 | strcpy( buffer + length, &str[0] );
|
---|
[268] | 93 | length += (int)str.size();
|
---|
| 94 | }
|
---|
[266] | 95 |
|
---|
[523] | 96 | bool ReadFile( const std::string &filePath );
|
---|
[266] | 97 |
|
---|
| 98 | static void Text::SlideString(char *buffer, int slide){
|
---|
[700] | 99 | memmove(buffer+slide, buffer, strlen(buffer)+1);
|
---|
[266] | 100 | }
|
---|
| 101 | };
|
---|
| 102 |
|
---|
| 103 | class BasicSource : public Text
|
---|
| 104 | {
|
---|
[523] | 105 | static const std::string generateDirectiveName;
|
---|
[266] | 106 |
|
---|
[279] | 107 | IncludedFilesRelation includedFilesRelation;
|
---|
| 108 |
|
---|
| 109 | // XMLシリアライズ用
|
---|
| 110 | private:
|
---|
| 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 |
|
---|
| 152 | private:
|
---|
[281] | 153 | void Realloc( int newLength )
|
---|
| 154 | {
|
---|
| 155 | bool isEqualBasbuf = false;
|
---|
| 156 | extern char *basbuf;
|
---|
[282] | 157 | if( basbuf == buffer + 2 )
|
---|
[281] | 158 | {
|
---|
| 159 | isEqualBasbuf = true;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[266] | 162 | buffer = (char *)realloc( buffer, newLength + 255 );
|
---|
| 163 |
|
---|
| 164 | length = newLength;
|
---|
| 165 |
|
---|
[281] | 166 | if( isEqualBasbuf )
|
---|
| 167 | {
|
---|
| 168 | basbuf = buffer + 2;
|
---|
| 169 | }
|
---|
[266] | 170 | }
|
---|
| 171 |
|
---|
| 172 | void IncludeFiles();
|
---|
| 173 |
|
---|
| 174 | void ChangeReturnLineChar();
|
---|
| 175 |
|
---|
| 176 | void RemoveComments();
|
---|
| 177 |
|
---|
[523] | 178 | bool ReadFile_InIncludeDirective( const std::string &filePath );
|
---|
[602] | 179 | void DirectiveIncludeOrRequire( const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
---|
[266] | 180 |
|
---|
| 181 | void RemoveReturnLineUnderbar();
|
---|
| 182 |
|
---|
[322] | 183 | void Initialize( const std::string &source );
|
---|
| 184 |
|
---|
[266] | 185 | public:
|
---|
| 186 | BasicSource(){}
|
---|
[280] | 187 | BasicSource( const BasicSource &basicSource )
|
---|
| 188 | : Text( basicSource )
|
---|
| 189 | , includedFilesRelation( basicSource.includedFilesRelation )
|
---|
| 190 | {
|
---|
| 191 | }
|
---|
[322] | 192 | BasicSource( const std::string &source )
|
---|
| 193 | {
|
---|
| 194 | Initialize( source );
|
---|
| 195 | }
|
---|
[266] | 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 | }
|
---|
[304] | 209 | void _ResetLength()
|
---|
| 210 | {
|
---|
[700] | 211 | length = strlen( buffer );
|
---|
[304] | 212 | }
|
---|
[266] | 213 |
|
---|
[279] | 214 | const IncludedFilesRelation &GetIncludedFilesRelation() const
|
---|
| 215 | {
|
---|
| 216 | return includedFilesRelation;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
[266] | 219 | void SetBuffer( const char *buffer );
|
---|
| 220 |
|
---|
[602] | 221 | bool ReadFile( const std::string &filePath, bool isDebug, bool isDll, bool isUnicode, int majorVer, const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
---|
[266] | 222 |
|
---|
| 223 | void Addition( const char *buffer );
|
---|
| 224 |
|
---|
[280] | 225 | bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
|
---|
[279] | 226 |
|
---|
[266] | 227 | void operator = ( const BasicSource &source ){
|
---|
| 228 | Realloc( source.length );
|
---|
[700] | 229 | strcpy( buffer, source.buffer );
|
---|
[266] | 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 | }
|
---|
[555] | 240 |
|
---|
| 241 | std::string cannotIncludePath;
|
---|
| 242 | int cannotIncludeSourcePos;
|
---|
[266] | 243 | };
|
---|
[636] | 244 | class BasicSources
|
---|
| 245 | : public std::vector<BasicSource>
|
---|
| 246 | , public Jenga::Common::BoostSerializationSupport<BasicSources>
|
---|
| 247 | {
|
---|
| 248 | // XMLシリアライズ用
|
---|
| 249 | private:
|
---|
| 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 | };
|
---|
[632] | 260 |
|
---|
| 261 | class SourceCodePosition
|
---|
| 262 | {
|
---|
[637] | 263 | int relationalObjectModuleIndex;
|
---|
[632] | 264 | int pos;
|
---|
| 265 |
|
---|
| 266 | // XMLシリアライズ用
|
---|
| 267 | private:
|
---|
| 268 | friend class boost::serialization::access;
|
---|
| 269 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 270 | {
|
---|
[637] | 271 | ar & BOOST_SERIALIZATION_NVP( relationalObjectModuleIndex );
|
---|
[632] | 272 | ar & BOOST_SERIALIZATION_NVP( pos );
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | public:
|
---|
[637] | 276 | SourceCodePosition( int relationalObjectModuleIndex, int pos )
|
---|
| 277 | : relationalObjectModuleIndex( relationalObjectModuleIndex )
|
---|
[632] | 278 | , pos( pos )
|
---|
| 279 | {
|
---|
| 280 | }
|
---|
| 281 | SourceCodePosition()
|
---|
[637] | 282 | : relationalObjectModuleIndex( -1 )
|
---|
| 283 | , pos( -1 )
|
---|
[632] | 284 | {
|
---|
| 285 | }
|
---|
| 286 |
|
---|
[637] | 287 | int GetRelationalObjectModuleIndex() const;
|
---|
| 288 | void SetRelationalObjectModuleIndex( int relationalObjectModuleIndex )
|
---|
[632] | 289 | {
|
---|
[637] | 290 | this->relationalObjectModuleIndex = relationalObjectModuleIndex;
|
---|
[632] | 291 | }
|
---|
| 292 | int GetPos() const
|
---|
| 293 | {
|
---|
| 294 | return pos;
|
---|
| 295 | }
|
---|
[637] | 296 | void SetPos( int pos )
|
---|
| 297 | {
|
---|
| 298 | this->pos = pos;
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | bool IsNothing() const;
|
---|
[632] | 302 | };
|
---|