| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 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 | trace_for_serialize( "serializing - IncludedFilesRelation" );
|
|---|
| 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 | {
|
|---|
| 41 | return (int)filePaths.size();
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | int AddFile( const std::string &filePath )
|
|---|
| 45 | {
|
|---|
| 46 | filePaths.push_back( filePath );
|
|---|
| 47 | return (int)filePaths.size()-1;
|
|---|
| 48 | }
|
|---|
| 49 | void AddLine( int fileNumber )
|
|---|
| 50 | {
|
|---|
| 51 | lineFileNumbers.push_back( fileNumber );
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | int GetLineCounts() const
|
|---|
| 55 | {
|
|---|
| 56 | return (int)lineFileNumbers.size();
|
|---|
| 57 | }
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 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 | }
|
|---|
| 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 | }
|
|---|
| 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 );
|
|---|
| 88 | lstrcpy( buffer + length, str.c_str() );
|
|---|
| 89 | length += (int)str.size();
|
|---|
| 90 | }
|
|---|
| 91 | void Add( const std::vector<char> &str )
|
|---|
| 92 | {
|
|---|
| 93 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
|---|
| 94 | lstrcpy( buffer + length, &str[0] );
|
|---|
| 95 | length += (int)str.size();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | bool ReadFile( const std::string &filePath );
|
|---|
| 99 |
|
|---|
| 100 | static void Text::SlideString(char *buffer, int slide){
|
|---|
| 101 | char *temp;
|
|---|
| 102 | temp=(char *)malloc(lstrlen(buffer)+1);
|
|---|
| 103 | lstrcpy(temp,buffer);
|
|---|
| 104 | lstrcpy(buffer+slide,temp);
|
|---|
| 105 | free(temp);
|
|---|
| 106 | }
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | class BasicSource : public Text
|
|---|
| 110 | {
|
|---|
| 111 | static const std::string generateDirectiveName;
|
|---|
| 112 |
|
|---|
| 113 | IncludedFilesRelation includedFilesRelation;
|
|---|
| 114 |
|
|---|
| 115 | // XMLシリアライズ用
|
|---|
| 116 | private:
|
|---|
| 117 | friend class boost::serialization::access;
|
|---|
| 118 | BOOST_SERIALIZATION_SPLIT_MEMBER();
|
|---|
| 119 | template<class Archive> void load(Archive& ar, const unsigned int version)
|
|---|
| 120 | {
|
|---|
| 121 | trace_for_serialize( "serializing(load) - BasicSource" );
|
|---|
| 122 |
|
|---|
| 123 | std::string _buffer;
|
|---|
| 124 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
|---|
| 125 | ar & BOOST_SERIALIZATION_NVP( length );
|
|---|
| 126 | ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
|
|---|
| 127 |
|
|---|
| 128 | // 読み込み後の処理
|
|---|
| 129 | Realloc( length );
|
|---|
| 130 | for( int i=0; i<length; i++ )
|
|---|
| 131 | {
|
|---|
| 132 | ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
|
|---|
| 133 | ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
|
|---|
| 134 | ULONG_PTR l = l1 + l2;
|
|---|
| 135 | buffer[i] = static_cast<char>(l);
|
|---|
| 136 | }
|
|---|
| 137 | buffer[length] = 0;
|
|---|
| 138 | }
|
|---|
| 139 | template<class Archive> void save(Archive& ar, const unsigned int version) const
|
|---|
| 140 | {
|
|---|
| 141 | trace_for_serialize( "serializing(save) - BasicSource" );
|
|---|
| 142 |
|
|---|
| 143 | // 保存準備
|
|---|
| 144 | char *tempCode = (char *)calloc( (length+1) * 3, 1 );
|
|---|
| 145 | for( int i=0; i<length; i++ )
|
|---|
| 146 | {
|
|---|
| 147 | char temp[32];
|
|---|
| 148 | sprintf( temp, "%02x,", (unsigned char)buffer[i] );
|
|---|
| 149 | tempCode[i*3] = temp[0];
|
|---|
| 150 | tempCode[i*3+1] = temp[1];
|
|---|
| 151 | tempCode[i*3+2] = temp[2];
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | std::string _buffer = tempCode;
|
|---|
| 155 | free( tempCode );
|
|---|
| 156 |
|
|---|
| 157 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
|---|
| 158 | ar & BOOST_SERIALIZATION_NVP( length );
|
|---|
| 159 | ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | private:
|
|---|
| 163 | void Realloc( int newLength )
|
|---|
| 164 | {
|
|---|
| 165 | bool isEqualBasbuf = false;
|
|---|
| 166 | extern char *basbuf;
|
|---|
| 167 | if( basbuf == buffer + 2 )
|
|---|
| 168 | {
|
|---|
| 169 | isEqualBasbuf = true;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | buffer = (char *)realloc( buffer, newLength + 255 );
|
|---|
| 173 |
|
|---|
| 174 | length = newLength;
|
|---|
| 175 |
|
|---|
| 176 | if( isEqualBasbuf )
|
|---|
| 177 | {
|
|---|
| 178 | basbuf = buffer + 2;
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | void IncludeFiles();
|
|---|
| 183 |
|
|---|
| 184 | void ChangeReturnLineChar();
|
|---|
| 185 |
|
|---|
| 186 | void RemoveComments();
|
|---|
| 187 |
|
|---|
| 188 | bool ReadFile_InIncludeDirective( const std::string &filePath );
|
|---|
| 189 | void DirectiveIncludeOrRequire( const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
|---|
| 190 |
|
|---|
| 191 | void RemoveReturnLineUnderbar();
|
|---|
| 192 |
|
|---|
| 193 | void Initialize( const std::string &source );
|
|---|
| 194 |
|
|---|
| 195 | public:
|
|---|
| 196 | BasicSource(){}
|
|---|
| 197 | BasicSource( const BasicSource &basicSource )
|
|---|
| 198 | : Text( basicSource )
|
|---|
| 199 | , includedFilesRelation( basicSource.includedFilesRelation )
|
|---|
| 200 | {
|
|---|
| 201 | }
|
|---|
| 202 | BasicSource( const std::string &source )
|
|---|
| 203 | {
|
|---|
| 204 | Initialize( source );
|
|---|
| 205 | }
|
|---|
| 206 | ~BasicSource(){}
|
|---|
| 207 |
|
|---|
| 208 | char *GetBuffer(){
|
|---|
| 209 | return buffer+2;
|
|---|
| 210 | }
|
|---|
| 211 | const char *GetBuffer() const
|
|---|
| 212 | {
|
|---|
| 213 | return buffer+2;
|
|---|
| 214 | }
|
|---|
| 215 | int GetLength() const
|
|---|
| 216 | {
|
|---|
| 217 | return length-2;
|
|---|
| 218 | }
|
|---|
| 219 | void _ResetLength()
|
|---|
| 220 | {
|
|---|
| 221 | length = lstrlen( buffer );
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | const IncludedFilesRelation &GetIncludedFilesRelation() const
|
|---|
| 225 | {
|
|---|
| 226 | return includedFilesRelation;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | void SetBuffer( const char *buffer );
|
|---|
| 230 |
|
|---|
| 231 | bool ReadFile( const std::string &filePath, bool isDebug, bool isDll, bool isUnicode, int majorVer, const std::string &mainSourceFilePath, const std::string &includeDirPath );
|
|---|
| 232 |
|
|---|
| 233 | void Addition( const char *buffer );
|
|---|
| 234 |
|
|---|
| 235 | bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
|
|---|
| 236 |
|
|---|
| 237 | void operator = ( const BasicSource &source ){
|
|---|
| 238 | Realloc( source.length );
|
|---|
| 239 | lstrcpy( buffer, source.buffer );
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | char operator[]( int index ) const
|
|---|
| 243 | {
|
|---|
| 244 | if( index>GetLength() )
|
|---|
| 245 | {
|
|---|
| 246 | Jenga::Throw( "BasicSource bad access" );
|
|---|
| 247 | }
|
|---|
| 248 | return buffer[2+index];
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | std::string cannotIncludePath;
|
|---|
| 252 | int cannotIncludeSourcePos;
|
|---|
| 253 | };
|
|---|
| 254 | typedef std::vector<BasicSource> BasicSources;
|
|---|
| 255 |
|
|---|
| 256 | class SourceCodePosition
|
|---|
| 257 | {
|
|---|
| 258 | std::string objectModuleName;
|
|---|
| 259 | int pos;
|
|---|
| 260 |
|
|---|
| 261 | // XMLシリアライズ用
|
|---|
| 262 | private:
|
|---|
| 263 | friend class boost::serialization::access;
|
|---|
| 264 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
|---|
| 265 | {
|
|---|
| 266 | trace_for_serialize( "serializing - IncludedFilesRelation" );
|
|---|
| 267 |
|
|---|
| 268 | ar & BOOST_SERIALIZATION_NVP( objectModuleName );
|
|---|
| 269 | ar & BOOST_SERIALIZATION_NVP( pos );
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | public:
|
|---|
| 273 | SourceCodePosition( const std::string &objectModuleName, int pos )
|
|---|
| 274 | : objectModuleName( objectModuleName )
|
|---|
| 275 | , pos( pos )
|
|---|
| 276 | {
|
|---|
| 277 | }
|
|---|
| 278 | SourceCodePosition()
|
|---|
| 279 | : pos( -1 )
|
|---|
| 280 | {
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | const std::string &GetObjectModuleName() const
|
|---|
| 284 | {
|
|---|
| 285 | return objectModuleName;
|
|---|
| 286 | }
|
|---|
| 287 | int GetPos() const
|
|---|
| 288 | {
|
|---|
| 289 | return pos;
|
|---|
| 290 | }
|
|---|
| 291 | };
|
|---|