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