P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Util::SourceInfo Class Referencefinal

#include <source_file.h>

Public Member Functions

 SourceInfo ()=default
 Creates an "invalid" SourceInfo.
 
 SourceInfo (const InputSources *sources, SourcePosition point)
 Creates a SourceInfo for a 'point' in the source, or invalid.
 
 SourceInfo (const InputSources *sources, SourcePosition start, SourcePosition end)
 
 SourceInfo (const SourceInfo &other)=default
 
 SourceInfo (cstring filename, int line, int column, cstring srcBrief)
 
void dbprint (std::ostream &out) const
 
const SourcePositiongetEnd () const
 
cstring getLineNum () const
 
cstring getSourceFile () const
 
const SourcePositiongetStart () const
 
bool isValid () const
 
 operator bool () const
 
SourceInfo operator+ (const SourceInfo &rhs) const
 
SourceInfooperator+= (const SourceInfo &rhs)
 
bool operator< (const SourceInfo &rhs) const
 
bool operator<= (const SourceInfo &rhs) const
 
SourceInfooperator= (const SourceInfo &other)=default
 
bool operator== (const SourceInfo &rhs) const
 
bool operator> (const SourceInfo &rhs) const
 
bool operator>= (const SourceInfo &rhs) const
 
cstring toBriefSourceFragment () const
 
SourceFileLine toPosition () const
 
cstring toPositionString () const
 
cstring toSourceFragment (bool useMarker) const
 
cstring toSourceFragment (int trimWidth=-1, bool useMarker=true) const
 
cstring toSourcePositionData (unsigned *outLineNumber, unsigned *outColumnNumber) const
 
cstring toString () const
 

Public Attributes

int column = -1
 
cstring filename = ""_cs
 
int line = -1
 
cstring srcBrief = ""_cs
 

Friends

std::ostream & operator<< (std::ostream &os, const SourceInfo &info)
 

Detailed Description

Information about the source position of a language element - a range of position within an InputSources. Can only be interpreted relative to some InputSources.

For a program element, the start is inclusive and the end is exclusive (the first position after the language element).

SourceInfo can also be "invalid"

Member Function Documentation

◆ operator+()

SourceInfo P4::Util::SourceInfo::operator+ ( const SourceInfo & rhs) const
inline

A SourceInfo that spans both this and rhs. However, if this or rhs is invalid, it is not taken into account

◆ operator<()

bool P4::Util::SourceInfo::operator< ( const SourceInfo & rhs) const
inline

True if this comes 'before' this source position. 'invalid' source positions come first. This is true if the start of other is strictly before the start of this.

◆ toSourceFragment()

cstring P4::Util::SourceInfo::toSourceFragment ( int trimWidth = -1,
bool useMarker = true ) const

Create a string with a line of source, optionally with carets on the following line marking the spot of this SourceInfo. If trimWidth is >= 10, trim the line to be at most trimWidth characters, as too-long lines are unreadable. trimWidth = -1 defaults to 0 (disable) if useMarker is false or the COLUMNS envvar or 100 if useMarker is true