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

#include <source_file.h>

Public Member Functions

void addComment (SourceInfo srcInfo, bool singleLine, cstring body)
 
void appendText (const char *text)
 Append this text; it is either a newline or a text with no newlines.
 
const std::vector< Comment * > & getAllComments () const
 Returns a list of all the comments found in the file, stored as a part of InputSources
 
cstring getBriefSourceFragment (const SourceInfo &position) const
 
unsigned getCurrentLineNumber () const
 
SourcePosition getCurrentPosition () const
 
std::string_view getLine (unsigned lineNumber) const
 
cstring getSourceFragment (const SourceInfo &position, int trimWidth, bool useMarker) const
 
cstring getSourceFragment (const SourcePosition &position, int trimWidth, bool useMarker) const
 
SourceFileLine getSourceLine (unsigned line) const
 Original source line that produced the line with the specified number.
 
unsigned lineCount () const
 
void mapLine (std::string_view file, unsigned originalSourceLineNo)
 
void seal ()
 Prevents further changes; currently not used.
 
cstring toDebugString () const
 

Detailed Description

Information about all the input sources that comprise a P4 program that is being compiled. The inputSources can be seen as a simple file produced by the preprocessor, but also as a set of fragments of input files which were stitched by the preprocessor.

The mutable part of the API is tailored for interaction with the lexer. After the lexer is done this object can be "sealed" and never changes again.

This class implements a singleton pattern: there is a single instance of this class.

Member Function Documentation

◆ getSourceFragment()

cstring P4::Util::InputSources::getSourceFragment ( const SourcePosition & position,
int trimWidth,
bool useMarker ) const

The following return a nice (multi-line, newline-terminated) string describing a position in the sources, e.g.: int<32> variable; ^^^^^^^^

◆ mapLine()

void P4::Util::InputSources::mapLine ( std::string_view file,
unsigned originalSourceLineNo )

Map the next line in the file to the line with number 'originalSourceLine' from file 'file'.

◆ seal()

void P4::Util::InputSources::seal ( )

Prevents further changes; currently not used.

prevent further changes