ROSE 0.11.145.147
|
Information about a source location.
A SourceLocation object is simply a file name, line number, and optional column number. However, since file names are shared by many objects certain optimizations can be made to reduce the total amount of storage occupied by all the objects collectively. Although the file name storage is optimized, the objects behave as if each object has its own file name data member.
This class attempts to correct a number of issues encountered with Sg_File_Info and to make the class more suitable for use in binary analysis. Some of the corrected problems are:
boost::filesystem::path
instead of std::string
, therefore there is no need for constantly converting between the two types (good user code should not use std::string for file names).size_t
since they're conceptually unsigned sizes. This avoids having to cast in well-written user code.Line and column numbers are conventionally one-origin values, but nothing in this API or the implementation prevents you from storing line zero and/or column zero. You're free to use zero-origin number if you desire.
This class is intended to be extended through derivation to provide additional location features such as scope information, but those things are not included here because they're not always needed or even available.
Definition at line 69 of file SourceLocation.h.
#include <Rose/SourceLocation.h>
Public Member Functions | |
SourceLocation () | |
Default constructor. | |
SourceLocation (const boost::filesystem::path &fileName, size_t line, const Sawyer::Optional< size_t > &column=Sawyer::Nothing()) | |
Construct a new source location. | |
virtual | ~SourceLocation () |
Destructor. | |
virtual std::string | toString () const override |
Convert location to string. | |
virtual void | print (std::ostream &) const override |
Output location to a stream. | |
virtual std::string | printableName () const override |
Convert location to escaped string. | |
virtual bool | isEqual (const Location &) const override |
Equality and inequality. | |
virtual bool | isValid () const override |
Test whether this object is valid. | |
virtual const boost::filesystem::path & | fileName () const |
File name associated with this location. | |
virtual size_t | line () const |
Line number. | |
virtual const Sawyer::Optional< size_t > & | column () const |
Column number. | |
virtual bool | operator< (const Location &) const override |
Ordered comparison. | |
virtual bool | operator<= (const Location &) const override |
Ordered comparison. | |
virtual bool | operator> (const Location &) const override |
Ordered comparison. | |
virtual bool | operator>= (const Location &) const override |
Ordered comparison. | |
Public Member Functions inherited from Rose::Location | |
virtual bool | operator== (const Location &other) const final |
Equality and inequality. | |
virtual bool | operator!= (const Location &other) const final |
Equality and inequality. | |
virtual | operator bool () const final |
Test whether this object is valid. | |
virtual bool | operator! () const final |
Test whether this object is empty. | |
virtual bool | isEmpty () const final |
Test whether this object is empty. | |
Static Public Member Functions | |
static SourceLocation | parse (const std::string &) |
Construct a new source location by parsing a string. | |
|
inline |
Default constructor.
The default constructor creates a location with an empty name, line zero, and no column. It's intended mainly for use in containers that require a default constructor.
Definition at line 112 of file SourceLocation.h.
Rose::SourceLocation::SourceLocation | ( | const boost::filesystem::path & | fileName, |
size_t | line, | ||
const Sawyer::Optional< size_t > & | column = Sawyer::Nothing() |
||
) |
Construct a new source location.
The behavior of this constructor is as if the file name, line, and column were all copied into data members of the new object. However, the implementation is optimized to store only one copy of each unique file name across all objects.
|
virtual |
Destructor.
A special destructor is used in order to free file names that are no longer referenced by any SourceLocation object.
|
static |
Construct a new source location by parsing a string.
If the string ends with ":N:M" then N and M are the line and column numbers. Otherwise, if the string ends with ":N" then it has only a line number and no column number. Otherwise the line number is zero and there is no column number. Everything before the line and column is the file name. If the file name is surrounded by double quotes then the entire name is parsed as if it were a C string literal.
|
overridevirtual |
Convert location to string.
Converts this location to a file name, line number, and optional column number. Special characters in the file name are not escaped nor is the file name enclosed in quotes. The file name is separated from the line number by a colon (no white space), and if the location has a column, the column number is separated from the line number by a colon (also no white space). An empty (default constructed) object returns an empty string.
Implements Rose::Location.
|
overridevirtual |
Output location to a stream.
The format is the same as the toString method.
Implements Rose::Location.
|
overridevirtual |
Convert location to escaped string.
Prints the location in a safe manner by printing the file name as a C-style string literal (with double quotes) and with all non-graphic characters except ASCII SPC escaped using only graphic characters (the usual C syntax). An empty (default constructed) object returns an empty string.
Implements Rose::Location.
|
overridevirtual |
Equality and inequality.
Two objects are equal if they have the same file name (exact match), same line number, and either the same column number or both have no column.
Implements Rose::Location.
|
overridevirtual |
Ordered comparison.
Compares by file name, line number, and column number, in that order. Although the sort is stable, file names are not compared lexicographically. That is, the sort will not be alphabetical – if you want an alphabetical sort then you'll need to provide a different comparator. A location with a non-existing column number is considered less than a location with column number zero.
Implements Rose::Location.
|
overridevirtual |
Ordered comparison.
Compares by file name, line number, and column number, in that order. Although the sort is stable, file names are not compared lexicographically. That is, the sort will not be alphabetical – if you want an alphabetical sort then you'll need to provide a different comparator. A location with a non-existing column number is considered less than a location with column number zero.
Implements Rose::Location.
|
overridevirtual |
Ordered comparison.
Compares by file name, line number, and column number, in that order. Although the sort is stable, file names are not compared lexicographically. That is, the sort will not be alphabetical – if you want an alphabetical sort then you'll need to provide a different comparator. A location with a non-existing column number is considered less than a location with column number zero.
Implements Rose::Location.
|
overridevirtual |
Ordered comparison.
Compares by file name, line number, and column number, in that order. Although the sort is stable, file names are not compared lexicographically. That is, the sort will not be alphabetical – if you want an alphabetical sort then you'll need to provide a different comparator. A location with a non-existing column number is considered less than a location with column number zero.
Implements Rose::Location.
|
overridevirtual |
Test whether this object is valid.
Implements Rose::Location.
|
virtual |
File name associated with this location.
The behavior is as if the file name were stored as a data member of this object; that is, the reference is valid as long as this object is valid. The actual implementation optimizes name storage and therefore the reference is likely (but not guaranteed) to be valid longer than the life time of this object.
Thread safety: The referenced name is guaranteed to not change for its entire lifetime.
|
inlinevirtual |
Line number.
Definition at line 185 of file SourceLocation.h.
|
inlinevirtual |
Column number.
Definition at line 190 of file SourceLocation.h.