P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::V1::V1ParserDriver Class Referencefinal

A ParserDriver that can parse P4-14 programs. More...

#include <parserDriver.h>

Inheritance diagram for P4::V1::V1ParserDriver:
[legend]

Static Public Member Functions

static const IR::V1Program * parse (FILE *in, std::string_view sourceFile, unsigned sourceLine=1)
 
static const IR::V1Program * parse (std::istream &in, std::string_view sourceFile, unsigned sourceLine=1)
 

Protected Member Functions

void addPragma (IR::Annotation *pragma)
 Add @pragma to the list of active pragmas.
 
void clearPragmas ()
 Clear the list of active pragmas.
 
IR::Constant * constantFold (IR::Expression *expr)
 
IR::Vector< IR::Expression > makeExpressionList (const IR::NameList *list)
 
IR::Vector< IR::Annotation > takePragmasAsVector ()
 
- Protected Member Functions inherited from P4::AbstractParserDriver
void onParseError (const Util::SourceInfo &location, const std::string &message)
 
void onReadComment (const char *text, bool lineComment)
 
void onReadFileName (const char *text)
 Notify that the lexer read a filename from a line directive.
 
void onReadIdentifier (cstring id)
 Notify that the lexer read an identifier, @id.
 
void onReadLineNumber (const char *text)
 Notify that the lexer read a line number from a line directive.
 
void onReadToken (const char *text)
 Notify that the lexer read a token. @text is the matched source text.
 

Protected Attributes

IR::V1Program * global = nullptr
 The root of the IR tree we're constructing.
 
- Protected Attributes inherited from P4::AbstractParserDriver
int saveState = -1
 Scratch storage for the lexer to remember its previous state.
 
Util::InputSourcessources
 The input sources that comprise the P4 program we're parsing.
 
Util::SourceInfo yylloc
 The location of the most recent token.
 

Friends

class V1::V1Lexer
 
class V1::V1Parser
 

Detailed Description

A ParserDriver that can parse P4-14 programs.

Member Function Documentation

◆ constantFold()

IR::Constant * P4::V1::V1ParserDriver::constantFold ( IR::Expression * expr)
protected

The P4-14 parser performs constant folding to ensure that constant expressions in the grammar actually produce IR::Constant values in the resulting IR.

Returns
an IR::Constant containing the value of @expr, if @expr is a constant expression, or null otherwise.

◆ makeExpressionList()

IR::Vector< IR::Expression > P4::V1::V1ParserDriver::makeExpressionList ( const IR::NameList * list)
protected
Returns
a vector of IR::Expressions containing an IR::StringLiteral for name in @list.

◆ parse()

const IR::V1Program * P4::V1::V1ParserDriver::parse ( std::istream & in,
std::string_view sourceFile,
unsigned sourceLine = 1 )
static

Parse a P4-14 program.

Parameters
inThe input source to read the program from.
sourceFileThe logical source filename. This doesn't have to be a real filename, though it normally will be. This is used for logging and to set the initial source location.
sourceLineThe logical source line number. For programs parsed from a file, this will normally be 1. This is used to set the initial source location.
Returns
a V1Program object if parsing was successful, or null otherwise.

◆ takePragmasAsVector()

IR::Vector< IR::Annotation > P4::V1::V1ParserDriver::takePragmasAsVector ( )
protected
Returns
a IR::Vector containing the active pragmas, and clear the list.