ROSE  0.11.109.0
Classes | Public Member Functions | Static Public Member Functions | List of all members
Rose::SourceLocation Class Reference

Description

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:

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 59 of file SourceLocation.h.

#include <Rose/SourceLocation.h>

Inheritance diagram for Rose::SourceLocation:
Inheritance graph
[legend]
Collaboration diagram for Rose::SourceLocation:
Collaboration graph
[legend]

Public Member Functions

 SourceLocation ()
 Default constructor. More...
 
 SourceLocation (const boost::filesystem::path &fileName, size_t line, const Sawyer::Optional< size_t > &column=Sawyer::Nothing())
 Construct a new source location. More...
 
virtual ~SourceLocation ()
 Destructor. More...
 
virtual std::string toString () const override
 Convert location to string. More...
 
virtual void print (std::ostream &) const override
 Output location to a stream. More...
 
virtual std::string printableName () const override
 Convert location to escaped string. More...
 
virtual bool isEqual (const Location &) const override
 Equality and inequality. More...
 
virtual bool isValid () const override
 Test whether this object is valid.
 
virtual const boost::filesystem::path & fileName () const
 File name associated with this location. More...
 
virtual size_t line () const
 Line number. More...
 
virtual const Sawyer::Optional< size_t > & column () const
 Column number. More...
 
virtual bool operator< (const Location &) const override
 Ordered comparison. More...
 
virtual bool operator<= (const Location &) const override
 Ordered comparison. More...
 
virtual bool operator> (const Location &) const override
 Ordered comparison. More...
 
virtual bool operator>= (const Location &) const override
 Ordered comparison. More...
 
- Public Member Functions inherited from Rose::Location
virtual bool operator== (const Location &other) const final
 Equality and inequality. More...
 
virtual bool operator!= (const Location &other) const final
 Equality and inequality. More...
 
virtual operator bool () const final
 Test whether this object is valid.
 
virtual bool operator! () const final
 Test whether this object is empty. More...
 
virtual bool isEmpty () const final
 Test whether this object is empty. More...
 

Static Public Member Functions

static SourceLocation parse (const std::string &)
 Construct a new source location by parsing a string. More...
 

Constructor & Destructor Documentation

Rose::SourceLocation::SourceLocation ( )
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 91 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 Rose::SourceLocation::~SourceLocation ( )
virtual

Destructor.

A special destructor is used in order to free file names that are no longer referenced by any SourceLocation object.

Member Function Documentation

static SourceLocation Rose::SourceLocation::parse ( const std::string &  )
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.

virtual std::string Rose::SourceLocation::toString ( ) const
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.

virtual void Rose::SourceLocation::print ( std::ostream &  ) const
overridevirtual

Output location to a stream.

The format is the same as the toString method.

Implements Rose::Location.

virtual std::string Rose::SourceLocation::printableName ( ) const
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.

virtual bool Rose::SourceLocation::isEqual ( const Location ) const
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.

virtual bool Rose::SourceLocation::operator< ( const Location ) const
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.

virtual bool Rose::SourceLocation::operator<= ( const Location ) const
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.

virtual bool Rose::SourceLocation::operator> ( const Location ) const
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.

virtual bool Rose::SourceLocation::operator>= ( const Location ) const
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.

virtual const boost::filesystem::path& Rose::SourceLocation::fileName ( ) const
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.

virtual size_t Rose::SourceLocation::line ( ) const
inlinevirtual

Line number.

Definition at line 164 of file SourceLocation.h.

virtual const Sawyer::Optional<size_t>& Rose::SourceLocation::column ( ) const
inlinevirtual

Column number.

Definition at line 169 of file SourceLocation.h.


The documentation for this class was generated from the following file: