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

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

#include <parserDriver.h>

Inheritance diagram for P4::P4ParserDriver:
[legend]

Static Public Member Functions

static const IR::P4Program * parse (FILE *in, std::string_view sourceFile, unsigned sourceLine=1)
 
static const IR::P4Program * parse (std::istream &in, std::string_view sourceFile, unsigned sourceLine=1)
 
static const IR::Constant * parseConstant (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseConstantList (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Expression * parseConstantOrStringLiteral (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseConstantOrStringLiteralList (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseConstantPair (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseConstantTriple (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Expression * parseExpression (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseExpressionList (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseExpressionPair (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseExpressionTriple (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::IndexedVector< IR::NamedExpression > * parseKvList (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseP4rtTranslationAnnotation (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static std::pair< const IR::P4Program *, const Util::InputSources * > parseProgramSources (FILE *in, std::string_view sourceFile, unsigned sourceLine=1)
 
static std::pair< const IR::P4Program *, const Util::InputSources * > parseProgramSources (std::istream &in, std::string_view sourceFile, unsigned sourceLine=1)
 
static const IR::StringLiteral * parseStringLiteral (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseStringLiteralList (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseStringLiteralPair (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 
static const IR::Vector< IR::Expression > * parseStringLiteralTriple (const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
 

Protected Member Functions

void onReadErrorDeclaration (IR::Type_Error *error)
 Notify that the parser parsed a P4 error declaration.
 
- 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::Vector< IR::Node > * nodes = nullptr
 
std::string stringLiteral
 
Util::ProgramStructurestructure = nullptr
 Semantic information about the program being parsed.
 
bool template_args = false
 
- 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 P4::P4Lexer
 
class P4::P4Parser
 

Detailed Description

A ParserDriver that can parse P4-16 programs.

Member Function Documentation

◆ parse()

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

Parse a P4-16 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 P4Program object if parsing was successful, or null otherwise.

◆ parseExpressionList()

const IR::Vector< IR::Expression > * P4::P4ParserDriver::parseExpressionList ( const Util::SourceInfo & srcInfo,
const IR::Vector< IR::AnnotationToken > & body )
static

Parses a P4-16 annotation body.

Parameters
bodyThe unparsed annotation body.
Returns
an AST node if parsing was successful, or null otherwise.

◆ parseProgramSources()

std::pair< const IR::P4Program *, const Util::InputSources * > P4::P4ParserDriver::parseProgramSources ( std::istream & in,
std::string_view sourceFile,
unsigned sourceLine = 1 )
static

Parses the input and returns a pair with the P4Program and InputSources. Use this when both the parsed P4Program and InputSources are required, as opposed to the parse method, which only returns the P4Program.

Member Data Documentation

◆ nodes

IR::Vector<IR::Node>* P4::P4ParserDriver::nodes = nullptr
protected

The top-level nodes that make up the P4 program (or program fragment) we're parsing.

◆ stringLiteral

std::string P4::P4ParserDriver::stringLiteral
protected

A scratch buffer to hold the current string literal. (They're lexed incrementally, so we need to hold some state between tokens.)