P4C
The P4 Compiler
Loading...
Searching...
No Matches
formulae.h
1/*
2 * SPDX-FileCopyrightText: 2022 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_COMMON_LIB_FORMULAE_H_
8#define BACKENDS_P4TOOLS_COMMON_LIB_FORMULAE_H_
9
10#include <functional>
11#include <string>
12
13#include "ir/ir.h"
14#include "ir/node.h"
15#include "lib/exceptions.h"
16
17namespace P4::P4Tools {
18
22template <class Self, class Node = IR::Expression>
24 protected:
25 std::reference_wrapper<const Node> node;
26
27 // Implicit conversions to allow implementations to be treated like a Node*.
28 operator const Node *() const { return &node.get(); }
29 const Node &operator*() const { return node.get(); }
30 const Node *operator->() const { return &node.get(); }
31
34 explicit AbstractRepCheckedNode(const Node *node, std::string classDesc) : node(*node) {
35 BUG_CHECK(Self::repOk(node), "%1%: Not a valid %2%.", node, classDesc);
36 }
37
38 DECLARE_TYPEINFO(AbstractRepCheckedNode);
39};
40
41} // namespace P4::P4Tools
42
43#endif /* BACKENDS_P4TOOLS_COMMON_LIB_FORMULAE_H_ */
Definition castable.h:27
Definition formulae.h:23
AbstractRepCheckedNode(const Node *node, std::string classDesc)
Definition formulae.h:34
Definition common/compiler/compiler_result.cpp:7