1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008, 2009 Henrik Tidefelt
24 #include <sys/types.h>
27 #include "Shapes_Ast_decls.h"
37 std::vector
< Ast::Node
* > topLevelNodes_
;
39 FileInfo( const std::string
& name
);
44 static const char * INPUTLIST_PREFIX
;
45 static const size_t INPUTLIST_PREFIX_LENGTH
;
48 typedef enum { NORMAL_FILE
, IN_MEMORY
, SPECIAL
, INTERNAL
} Kind
;
52 ino_t st_ino_
; /* Also used to index an IN_MEMORY */
53 const char * strData_
; /* A complete filename for a NORMAL_FILE, the identifier of a SPECIAL file, and unused for IN_MEMORY data. */
54 FileID( Kind kind
, dev_t st_dev
, ino_t st_ino
, const char * strData
);
56 static const FileID
* build_stat( const struct stat
& stat
, const std::string
& filename
);
57 static const FileID
* build_inMemory( ino_t index
, const std::string
& sourceName
);
58 static const FileID
* build_fresh_inMemory( );
59 static const FileID
* build_special( const char * specialName
);
60 static const FileID
* build_internal( const char * locationName
); /* Does not deep-copy locationName. Returns a new object each time, no matter is locationName has been used before! */
61 static bool is_inMemory( const std::string
& filename
, const FileID
** fileDst
);
63 std::vector
< Ast::Node
* > & nodes( ) const;
64 const char * name( ) const;
65 bool hasPosition( ) const;
66 std::istream
* open( std::ifstream
* ifsMem
, std::istringstream
* issMem
) const;
67 void setMem( const char * data
); /* Applicable only to IN_MEMORY objects. */
68 int inMemoryIndex( ) const;
69 bool operator < ( const FileID
& other
) const;
70 size_t byteColumnToUTF8Column( size_t line
, size_t byteCol
) const;
71 size_t UTF8ColumnTobyteColumn( size_t line
, size_t utf8Col
) const;
73 static size_t inputlistPrefixLength( );
74 static size_t UTF8ColumnTobyteColumn( const std::string
& line
, size_t utf8Col
);
75 static size_t byteColumnToUTF8Column( const std::string
& line
, size_t byteCol
);
78 void initInfo( const std::string
& name
) const;
84 bool operator () ( const FileID
* fid1
, const FileID
* fid2
) const
86 return (*fid1
) < (*fid2
);
93 static const FileID
* UNKNOWN_FILE
;
97 size_t firstColumn
; // In bytes, shall be converted to utf-8 position when displaying.
99 size_t lastColumn
; // In bytes, shall be converted to utf-8 position when displaying.
101 SourceLocation( ); /* A default constructor is required by Bison. Besides that, it should not be used! */
102 SourceLocation( const FileID
* file
);
103 SourceLocation( const SourceLocation
& orig
);
104 SourceLocation( const SourceLocation
& firstLoc
, const Ast::SourceLocation
& lastLoc
);
105 bool isUnknown( ) const;
106 bool contains( const SourceLocation
& loc2
) const;
107 friend std::ostream
& operator << ( std::ostream
& os
, const SourceLocation
& self
);
109 void copy( std::ostream
* os
) const;
110 Ast::Expression
* findExpression( ) const;
113 extern const SourceLocation THE_UNKNOWN_LOCATION
;
115 std::ostream
& operator << ( std::ostream
& os
, const SourceLocation
& self
);