Skip to content

Location

class Location

Represents a location within a file, including the file name, start position, and end position.

Line and column numbers are 1-based, and 0 indicates that it is not specified.

class Position

A position within a file.

Line and column numbers are 1-based, and 0 indicates that it is not specified.

constructor Position()

Create an empty position.

constructor Position(size_t line_number, size_t column)

Create a position.

ParameterDescription
line_number

The line number, or 0 if the line number is not specified.

TYPE: size_t

column

The column number, or 0 if the column number is not specified.

TYPE: size_t

method size_t column_index()

Get the 0-based column index of the position. If the column number is not specified, 0 is returned.

ReturnsDescription
size_t

The 0-based column index of the position, or 0 if the column number is not specified.

method bool empty()

Check if the position is empty (i.e. has no line number).

ReturnsDescription
bool

method size_t line_index()

Get the 0-based line index of the position. If the line number is not specified, 0 is returned.

ReturnsDescription
size_t

The 0-based line index of the position, or 0 if the line number is not specified.

method operator bool()

method bool operator!=(const Position &other)

Check if two positions are not equal.

ParameterDescription
other

The position to compare with.

TYPE: const Position &

ReturnsDescription
bool

true if the positions are not equal, false otherwise.

method bool operator<(const Position &other)

Check if this position is before another position.

ParameterDescription
other

The position to compare with.

TYPE: const Position &

ReturnsDescription
bool

true if this position is before the other position, false otherwise.

method bool operator<=(const Position &other)

Check if this position is before or equal to another position.

ParameterDescription
other

The position to compare with.

TYPE: const Position &

ReturnsDescription
bool

true if this position is before or equal to the other position, false otherwise.

method bool operator==(const Position &other)

Check if two positions are equal.

ParameterDescription
other

The position to compare with.

TYPE: const Position &

ReturnsDescription
bool

true if the positions are equal, false otherwise.

method bool operator>(const Position &other)

Check if this position is after another position.

ParameterDescription
other

The position to compare with.

TYPE: const Position &

ReturnsDescription
bool

true if this position is after the other position, false otherwise.

method bool operator>=(const Position &other)

Check if this position is after or equal to another position.

ParameterDescription
other

The position to compare with.

TYPE: const Position &

ReturnsDescription
bool

true if this position is after or equal to the other position, false otherwise.

method std::string to_string()

Convert the position to a string representation.

ReturnsDescription
std::string

The string representation of the position.

member size_t column

The column number, or 0 if the column number is not specified.

member size_t line_number

The line number, or 0 if the line number is not specified.

constructor Location()

Empty location.

constructor Location(const Location &a, const Location &b)

Create a location that covers the range from the start of one location to the end of another location. If the two locations are in different files, the second location will be ignored.

ParameterDescription
a

The first location.

TYPE: const Location &

b

The second location.

TYPE: const Location &

constructor Location(Symbol file, size_t line_number, size_t start_column, size_t end_column)

Create a location.

ParameterDescription
file

TYPE: Symbol

line_number

The line number, or 0 if the line number is not specified.

TYPE: size_t

start_column

The starting column number, or 0 if the column number is not specified.

TYPE: size_t

end_column

The ending column number, or 0 if the column number is not specified.

TYPE: size_t

constructor Location(Symbol file, size_t start_line_number, size_t start_column, size_t end_line_number, size_t end_column)

Create a location with a file name, line number, and column range.

ParameterDescription
file

The file symbol.

TYPE: Symbol

start_line_number

The starting line number, or 0 if the line number is not specified.

TYPE: size_t

start_column

The starting column number, or 0 if the column number is not specified.

TYPE: size_t

end_line_number

The ending line number, or 0 if the line number is not specified.

TYPE: size_t

end_column

The ending column number, or 0 if the column number is not specified.

TYPE: size_t

constructor Location(const std::string &file_name)

Create a location with only a file name.

ParameterDescription
file_name

The name of the file.

TYPE: const std::string &

method bool empty()

Check if the location is empty (i.e. has no file).

ReturnsDescription
bool

true if the location is empty, false otherwise.

method void extend(size_t amount)

Extend the location by a number of columns.

ParameterDescription
amount

The number of columns to extend the location by.

TYPE: size_t

method void extend(const Location &other)

Extend the location to include another location. If the other location is not in the same file, it will be ignored.

ParameterDescription
other

TYPE: const Location &

method bool is_one_line()

Check if the location is within a single line.

ReturnsDescription
bool

true if the location is within a single line, false otherwise.

method bool operator!=(const Location &other)

Check if two locations are not equal.

ParameterDescription
other

TYPE: const Location &

ReturnsDescription
bool

method bool operator<(const Location &other)

Check if this location is before another location.

Locations are ordered first by line number, then by column number. Locations in different files are not comparable.

ParameterDescription
other

The location to compare with.

TYPE: const Location &

ReturnsDescription
bool

true if this location is before the other location, false otherwise.

method bool operator==(const Location &other)

Check if two locations are equal.

ParameterDescription
other

The location to compare with.

TYPE: const Location &

ReturnsDescription
bool

true if the locations are equal, false otherwise.

method bool operator>(const Location &other)

Check if this location is after another location.

Locations are ordered first by line number, then by column number. Locations in different files are not comparable.

ParameterDescription
other

The location to compare with.

TYPE: const Location &

ReturnsDescription
bool

true if this location is after the other location, false otherwise.

method std::string to_string()

Convert the location to a string representation of the start of the location.

ReturnsDescription
std::string

A string representation of the start of the location.

method size_t width()

Get the width of the location in columns.

If the location is not on a single line, or no start or end column is known, 0 is returned.

ReturnsDescription
size_t

The width of the location in columns, or 0 if it is not well defined.

member end

The position where the location ends.

member file

The file.

member start

The position where the location starts.