P4C
The P4 Compiler
Loading...
Searching...
No Matches
validateParsedProgram.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef P4_VALIDATEPARSEDPROGRAM_H_
18#define P4_VALIDATEPARSEDPROGRAM_H_
19
20#include "ir/ir.h"
21#include "ir/visitor.h"
22
23namespace P4 {
24
25using namespace literals;
26
54class ValidateParsedProgram final : public Inspector {
55 void container(const IR::IContainer *type);
56 // Make sure that type, apply and constructor parameters are distinct
57 void distinctParameters(const IR::TypeParameters *typeParams, const IR::ParameterList *apply,
58 const IR::ParameterList *constr);
59
60 public:
61 ValidateParsedProgram() { setName("ValidateParsedProgram"); }
62 void postorder(const IR::Annotations *annotations) override;
63 void postorder(const IR::P4Program *program) override;
64 void postorder(const IR::Constant *c) override;
65 void postorder(const IR::SwitchStatement *statement) override;
66 void postorder(const IR::Method *t) override;
67 void postorder(const IR::StructField *f) override;
68 void postorder(const IR::ParserState *s) override;
69 void postorder(const IR::P4Table *t) override;
70 void postorder(const IR::Type_Bits *type) override;
71 void postorder(const IR::Type_Varbits *type) override;
72 void postorder(const IR::ConstructorCallExpression *expression) override;
73 void postorder(const IR::Declaration_Variable *decl) override;
74 void postorder(const IR::Declaration_Instance *inst) override;
75 void postorder(const IR::Declaration_Constant *decl) override;
76 void postorder(const IR::EntriesList *l) override;
77 void postorder(const IR::ReturnStatement *statement) override;
78 void postorder(const IR::ExitStatement *statement) override;
79 void postorder(const IR::Type_Package *package) override { container(package); }
80 void postorder(const IR::P4Control *control) override {
81 container(control);
82 distinctParameters(control->getTypeParameters(), control->getApplyParameters(),
83 control->getConstructorParameters());
84 }
85 void postorder(const IR::P4Parser *parser) override {
86 auto start = parser->states.getDeclaration(IR::ParserState::start);
87 if (!start) {
88 ::P4::error(ErrorType::ERR_INVALID, "Parser %1% has no 'start' state", parser);
89 }
90 container(parser);
91 distinctParameters(parser->getTypeParameters(), parser->getApplyParameters(),
92 parser->getConstructorParameters());
93 }
94 void postorder(const IR::Dots *dots) override;
95 void postorder(const IR::BreakStatement *s) override;
96 void postorder(const IR::ContinueStatement *s) override;
97};
98
99} // namespace P4
100
101#endif /* P4_VALIDATEPARSEDPROGRAM_H_ */
Definition visitor.h:400
Definition validateParsedProgram.h:54
void postorder(const IR::Annotations *annotations) override
Structured annotations cannot reuse names.
Definition validateParsedProgram.cpp:53
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition error.h:51