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
51class ValidateParsedProgram final : public Inspector {
52 void container(const IR::IContainer *type);
53 // Make sure that type, apply and constructor parameters are distinct
54 void distinctParameters(const IR::TypeParameters *typeParams, const IR::ParameterList *apply,
55 const IR::ParameterList *constr);
56
57 public:
58 ValidateParsedProgram() { setName("ValidateParsedProgram"); }
59 void postorder(const IR::Annotations *annotations) override;
60 void postorder(const IR::P4Program *program) override;
61 void postorder(const IR::Constant *c) override;
62 void postorder(const IR::SwitchStatement *statement) override;
63 void postorder(const IR::Method *t) override;
64 void postorder(const IR::StructField *f) override;
65 void postorder(const IR::ParserState *s) override;
66 void postorder(const IR::P4Table *t) override;
67 void postorder(const IR::Type_Bits *type) override;
68 void postorder(const IR::Type_Varbits *type) override;
69 void postorder(const IR::ConstructorCallExpression *expression) override;
70 void postorder(const IR::Declaration_Variable *decl) override;
71 void postorder(const IR::Declaration_Instance *inst) override;
72 void postorder(const IR::Declaration_Constant *decl) override;
73 void postorder(const IR::EntriesList *l) override;
74 void postorder(const IR::ReturnStatement *statement) override;
75 void postorder(const IR::ExitStatement *statement) override;
76 void postorder(const IR::Type_Package *package) override { container(package); }
77 void postorder(const IR::P4Control *control) override {
78 container(control);
79 distinctParameters(control->getTypeParameters(), control->getApplyParameters(),
80 control->getConstructorParameters());
81 }
82 void postorder(const IR::P4Parser *parser) override {
83 auto start = parser->states.getDeclaration("start");
84 if (!start) {
85 ::error(ErrorType::ERR_INVALID, "Parser %1% has no 'start' state", parser);
86 }
87 container(parser);
88 distinctParameters(parser->getTypeParameters(), parser->getApplyParameters(),
89 parser->getConstructorParameters());
90 }
91 void postorder(const IR::Dots *dots) override;
92};
93
94} // namespace P4
95
96#endif /* P4_VALIDATEPARSEDPROGRAM_H_ */
Definition validateParsedProgram.h:51
void postorder(const IR::Annotations *annotations) override
Structured annotations cannot reuse names.
Definition validateParsedProgram.cpp:52
Definition applyOptionsPragmas.cpp:24