15 int expressionPrecedence;
18 bool noIncludes =
false;
25 VecPrint(
const char *sep,
const char *term) : separator(sep), terminator(term) {}
32 ListPrint(
const char *start,
const char *end) : start(start), end(end) {}
36 std::vector<VecPrint> vectorSeparator;
37 size_t vectorSeparator_init_apply_size = 0;
38 std::vector<ListPrint> listTerminators;
39 size_t listTerminators_init_apply_size = 0;
41 void setVecSep(
const char *sep,
const char *term =
nullptr) {
42 vectorSeparator.push_back(VecPrint(sep, term));
45 BUG_CHECK(!vectorSeparator.empty(),
"Empty vectorSeparator");
46 vectorSeparator.pop_back();
49 BUG_CHECK(!vectorSeparator.empty(),
"Empty vectorSeparator");
50 return vectorSeparator.back();
54 BUG_CHECK(!listTerminators.empty(),
"Empty listTerminators");
55 listTerminators.pop_back();
63 WithSeparator(
P4Formatter &fmt,
const char *sep,
const char *term =
nullptr)
65 formatter.setVecSep(sep, term);
68 ~WithSeparator() { formatter.doneVec(); }
73 template <
typename Collection,
typename Func>
74 void visitCollection(
const Collection &collection,
const std::string &separator,
77 for (
const auto &elem : collection) {
79 builder.append(separator);
87 template <
typename Enumerator,
typename Func>
88 void visitCollection(Enumerator &enumerator,
const std::string &separator, Func visitFunc) {
90 while (enumerator.moveNext()) {
92 builder.append(separator);
95 visitFunc(enumerator.getCurrent());
99 bool isSystemFile(std::filesystem::path &file);
100 std::filesystem::path ifSystemFile(
110 std::ostream *outStream;
117 : expressionPrecedence(DBPrint::Prec_Low),
119 withinArgument(false),
123 visitDagOnce =
false;
124 setName(
"P4Formatter");
127 : expressionPrecedence(DBPrint::Prec_Low),
129 withinArgument(false),
130 builder(*new Util::SourceCodeBuilder()),
131 outStream(outStream),
133 visitDagOnce =
false;
134 setName(
"P4Formatter");
138 expressionPrecedence(DBPrint::Prec_Low),
140 withinArgument(false),
141 builder(*new Util::SourceCodeBuilder()),
142 outStream(&
std::cout),
144 visitDagOnce =
false;
145 setName(
"P4Formatter");
148 void setnoIncludesArg(
bool condition) { noIncludes = condition; }
150 void setListTerm(
const char *start,
const char *end) {
151 listTerminators.push_back(ListPrint(start, end));
153 Visitor::profile_t init_apply(
const IR::Node *node)
override;
154 void end_apply(
const IR::Node *node)
override;
156 bool process(
const IR::Type_StructLike *t,
const char *name);
158 bool preorder(
const IR::Node *node)
override;
159 bool printAnnotations(
const IR::IAnnotated *ann);
162 bool preorder(
const IR::Type_Boolean *t)
override;
163 bool preorder(
const IR::Type_Varbits *t)
override;
164 bool preorder(
const IR::Type_Bits *t)
override;
165 bool preorder(
const IR::Type_InfInt *t)
override;
166 bool preorder(
const IR::Type_String *t)
override;
167 bool preorder(
const IR::Type_Var *t)
override;
168 bool preorder(
const IR::Type_Dontcare *t)
override;
169 bool preorder(
const IR::Type_Void *t)
override;
170 bool preorder(
const IR::Type_Error *t)
override;
171 bool preorder(
const IR::Type_Struct *t)
override {
return process(t,
"struct"); }
172 bool preorder(
const IR::Type_Header *t)
override {
return process(t,
"header"); }
173 bool preorder(
const IR::Type_HeaderUnion *t)
override {
return process(t,
"header_union"); }
174 bool preorder(
const IR::Type_Package *t)
override;
175 bool preorder(
const IR::Type_Parser *t)
override;
176 bool preorder(
const IR::Type_Control *t)
override;
177 bool preorder(
const IR::Type_Name *t)
override;
178 bool preorder(
const IR::Type_Stack *t)
override;
179 bool preorder(
const IR::Type_Specialized *t)
override;
180 bool preorder(
const IR::Type_Enum *t)
override;
181 bool preorder(
const IR::Type_SerEnum *t)
override;
182 bool preorder(
const IR::Type_Typedef *t)
override;
183 bool preorder(
const IR::Type_Newtype *t)
override;
184 bool preorder(
const IR::Type_Extern *t)
override;
185 bool preorder(
const IR::Type_Unknown *t)
override;
186 bool preorder(
const IR::Type_BaseList *t)
override;
187 bool preorder(
const IR::Type *t)
override {
188 builder.append(t->toString());
191 bool preorder(
const IR::Type_SpecializedCanonical *t)
override {
192 BUG(
"%1%: specialized canonical type in IR tree", t);
197 bool preorder(
const IR::Declaration_Constant *cst)
override;
198 bool preorder(
const IR::Declaration_Variable *v)
override;
199 bool preorder(
const IR::Declaration_Instance *t)
override;
200 bool preorder(
const IR::Declaration_MatchKind *d)
override;
203 bool preorder(
const IR::Dots *e)
override;
204 bool preorder(
const IR::NamedDots *e)
override;
205 bool preorder(
const IR::Constant *c)
override;
206 bool preorder(
const IR::Slice *slice)
override;
207 bool preorder(
const IR::BoolLiteral *b)
override;
208 bool preorder(
const IR::StringLiteral *s)
override;
209 bool preorder(
const IR::PathExpression *p)
override;
210 bool preorder(
const IR::Cast *c)
override;
211 bool preorder(
const IR::Operation_Binary *b)
override;
212 bool preorder(
const IR::Operation_Unary *u)
override;
213 bool preorder(
const IR::ArrayIndex *a)
override;
214 bool preorder(
const IR::TypeNameExpression *e)
override;
215 bool preorder(
const IR::Mux *a)
override;
216 bool preorder(
const IR::ConstructorCallExpression *e)
override;
217 bool preorder(
const IR::Member *e)
override;
218 bool preorder(
const IR::SelectCase *e)
override;
219 bool preorder(
const IR::SelectExpression *e)
override;
220 bool preorder(
const IR::ListExpression *e)
override;
221 bool preorder(
const IR::P4ListExpression *e)
override;
222 bool preorder(
const IR::StructExpression *e)
override;
223 bool preorder(
const IR::Invalid *e)
override;
224 bool preorder(
const IR::InvalidHeader *e)
override;
225 bool preorder(
const IR::InvalidHeaderUnion *e)
override;
226 bool preorder(
const IR::HeaderStackExpression *e)
override;
227 bool preorder(
const IR::MethodCallExpression *e)
override;
228 bool preorder(
const IR::DefaultExpression *e)
override;
229 bool preorder(
const IR::This *e)
override;
232 bool preorder(
const IR::Vector<IR::ActionListElement> *v)
override;
233 bool preorder(
const IR::Vector<IR::Annotation> *v)
override;
234 bool preorder(
const IR::Vector<IR::Entry> *v)
override;
235 bool preorder(
const IR::Vector<IR::Expression> *v)
override;
236 bool preorder(
const IR::Vector<IR::Argument> *v)
override;
237 bool preorder(
const IR::Vector<IR::KeyElement> *v)
override;
238 bool preorder(
const IR::Vector<IR::Method> *v)
override;
239 bool preorder(
const IR::Vector<IR::Node> *v)
override;
240 bool preorder(
const IR::Vector<IR::SelectCase> *v)
override;
241 bool preorder(
const IR::Vector<IR::SwitchCase> *v)
override;
242 bool preorder(
const IR::Vector<IR::Type> *v)
override;
243 bool preorder(
const IR::IndexedVector<IR::Declaration_ID> *v)
override;
244 bool preorder(
const IR::IndexedVector<IR::Declaration> *v)
override;
245 bool preorder(
const IR::IndexedVector<IR::Node> *v)
override;
246 bool preorder(
const IR::IndexedVector<IR::ParserState> *v)
override;
247 bool preorder(
const IR::IndexedVector<IR::StatOrDecl> *v)
override;
250 bool preorder(
const IR::AssignmentStatement *s)
override;
251 bool preorder(
const IR::BlockStatement *s)
override;
252 bool preorder(
const IR::MethodCallStatement *s)
override;
253 bool preorder(
const IR::EmptyStatement *s)
override;
254 bool preorder(
const IR::ReturnStatement *s)
override;
255 bool preorder(
const IR::BreakStatement *s)
override;
256 bool preorder(
const IR::ContinueStatement *s)
override;
257 bool preorder(
const IR::ExitStatement *s)
override;
258 bool preorder(
const IR::SwitchCase *s)
override;
259 bool preorder(
const IR::SwitchStatement *s)
override;
260 bool preorder(
const IR::IfStatement *s)
override;
261 bool preorder(
const IR::ForStatement *s)
override;
262 bool preorder(
const IR::ForInStatement *s)
override;
265 bool preorder(
const IR::NamedExpression *ne)
override;
266 bool preorder(
const IR::Argument *arg)
override;
267 bool preorder(
const IR::Path *p)
override;
268 bool preorder(
const IR::Parameter *p)
override;
269 bool preorder(
const IR::Annotation *a)
override;
270 bool preorder(
const IR::P4Program *program)
override;
271 bool preorder(
const IR::P4Control *c)
override;
272 bool preorder(
const IR::P4Action *c)
override;
273 bool preorder(
const IR::ParserState *s)
override;
274 bool preorder(
const IR::P4Parser *c)
override;
275 bool preorder(
const IR::TypeParameters *p)
override;
276 bool preorder(
const IR::ParameterList *p)
override;
277 bool preorder(
const IR::Method *p)
override;
278 bool preorder(
const IR::Function *function)
override;
280 bool preorder(
const IR::ExpressionValue *v)
override;
281 bool preorder(
const IR::ActionListElement *ale)
override;
282 bool preorder(
const IR::ActionList *v)
override;
283 bool preorder(
const IR::Key *v)
override;
284 bool preorder(
const IR::Property *p)
override;
285 bool preorder(
const IR::TableProperties *t)
override;
286 bool preorder(
const IR::EntriesList *l)
override;
287 bool preorder(
const IR::Entry *e)
override;
288 bool preorder(
const IR::P4Table *c)
override;
289 bool preorder(
const IR::P4ValueSet *c)
override;
292 bool preorder(
const IR::V1Program *)
override {
return false; }
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35