17#ifndef FRONTENDS_PARSERS_PARSERDRIVER_H_
18#define FRONTENDS_PARSERS_PARSERDRIVER_H_
24#include "frontends/p4/symbol_table.h"
25#include "frontends/parsers/p4/abstractP4Lexer.hpp"
26#include "frontends/parsers/p4/p4AnnotationLexer.hpp"
28#include "lib/cstring.h"
29#include "lib/source_file.h"
87 int lineDirectiveLine = 0;
112 static const IR::P4Program *
parse(std::istream &in,
const char *sourceFile,
113 unsigned sourceLine = 1);
114 static const IR::P4Program *
parse(FILE *in,
const char *sourceFile,
unsigned sourceLine = 1);
126 static const IR::IndexedVector<IR::NamedExpression> *parseKvList(
139 static const IR::Expression *parseExpression(
const Util::SourceInfo &srcInfo,
145 static const IR::Expression *parseConstantOrStringLiteral(
148 static const IR::StringLiteral *parseStringLiteral(
const Util::SourceInfo &srcInfo,
176 friend class P4::P4Lexer;
177 friend class P4::P4Parser;
199 bool template_args =
false;
205 bool parse(AbstractP4Lexer &lexer,
const char *sourceFile,
unsigned sourceLine = 1);
208 template <
typename T>
215 IR::Type_Error *allErrors =
nullptr;
241 static const IR::V1Program *
parse(std::istream &in,
const char *sourceFile,
242 unsigned sourceLine = 1);
243 static const IR::V1Program *
parse(FILE *in,
const char *sourceFile,
unsigned sourceLine = 1);
246 friend class V1::V1Lexer;
247 friend class V1::V1Parser;
Definition externInstance.h:33
Definition parserDriver.h:38
void onParseError(const Util::SourceInfo &location, const std::string &message)
Definition parserDriver.cpp:101
Util::SourceInfo yylloc
The location of the most recent token.
Definition parserDriver.h:80
void onReadToken(const char *text)
Notify that the lexer read a token. @text is the matched source text.
Definition parserDriver.cpp:72
void onReadComment(const char *text, bool lineComment)
Definition parserDriver.cpp:90
void onReadFileName(const char *text)
Notify that the lexer read a filename from a #line directive.
Definition parserDriver.cpp:94
void onReadLineNumber(const char *text)
Notify that the lexer read a line number from a #line directive.
Definition parserDriver.cpp:79
int saveState
Scratch storage for the lexer to remember its previous state.
Definition parserDriver.h:83
Util::InputSources * sources
The input sources that comprise the P4 program we're parsing.
Definition parserDriver.h:77
void onReadIdentifier(cstring id)
Notify that the lexer read an identifier, @id.
Definition parserDriver.cpp:99
A ParserDriver that can parse P4-16 programs.
Definition parserDriver.h:97
Util::ProgramStructure * structure
Semantic information about the program being parsed.
Definition parserDriver.h:187
void onReadErrorDeclaration(IR::Type_Error *error)
Notify that the parser parsed a P4 error declaration.
Definition parserDriver.cpp:271
static const IR::Vector< IR::Expression > * parseExpressionList(const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
Definition parserDriver.cpp:164
static const IR::P4Program * parse(std::istream &in, const char *sourceFile, unsigned sourceLine=1)
Definition parserDriver.cpp:135
IR::Vector< IR::Node > * nodes
Definition parserDriver.h:191
std::string stringLiteral
Definition parserDriver.h:195
Definition symbol_table.h:39
Definition source_file.h:126
A ParserDriver that can parse P4-14 programs.
Definition parserDriver.h:226
IR::Vector< IR::Expression > makeExpressionList(const IR::NameList *list)
Definition parserDriver.cpp:319
void clearPragmas()
Clear the list of active pragmas.
Definition parserDriver.cpp:325
const IR::Annotations * takePragmasAsAnnotations()
Definition parserDriver.cpp:337
IR::V1Program * global
The root of the IR tree we're constructing.
Definition parserDriver.h:281
IR::Vector< IR::Annotation > takePragmasAsVector()
Definition parserDriver.cpp:331
void addPragma(IR::Annotation *pragma)
Add @pragma to the list of active pragmas.
Definition parserDriver.cpp:327
static const IR::V1Program * parse(std::istream &in, const char *sourceFile, unsigned sourceLine=1)
Definition parserDriver.cpp:286
IR::Constant * constantFold(IR::Expression *expr)
Definition parserDriver.cpp:313
Definition applyOptionsPragmas.cpp:24