P4C
The P4 Compiler
Loading...
Searching...
No Matches
constantParsing.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 FRONTENDS_COMMON_CONSTANTPARSING_H_
18#define FRONTENDS_COMMON_CONSTANTPARSING_H_
19
20#include "lib/cstring.h"
21
22namespace P4::IR {
23class Constant;
24} // namespace P4::IR
25
26namespace P4::Util {
27class SourceInfo;
28} // namespace P4::Util
29
30namespace P4 {
31
32class JSONGenerator;
33class JSONLoader;
34
69 cstring text;
70 unsigned skip;
71 unsigned base;
72 bool hasWidth;
73 void toJSON(JSONGenerator &) const;
74 static UnparsedConstant fromJSON(JSONLoader &);
75};
76
77std::ostream &operator<<(std::ostream &out, const UnparsedConstant &constant);
78
79bool operator<(const UnparsedConstant &a, const UnparsedConstant &b);
80
89IR::Constant *parseConstant(const Util::SourceInfo &srcInfo, const UnparsedConstant &constant,
90 long defaultValue);
91
96int parseConstantChecked(const Util::SourceInfo &srcInfo, const UnparsedConstant &constant);
97
98} // namespace P4
99
100#endif /* FRONTENDS_COMMON_CONSTANTPARSING_H_ */
Definition json_generator.h:39
Definition json_loader.h:40
Definition source_file.h:132
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
IR::Constant * parseConstant(const Util::SourceInfo &srcInfo, const UnparsedConstant &constant, long defaultValue)
Definition constantParsing.cpp:81
int parseConstantChecked(const Util::SourceInfo &srcInfo, const UnparsedConstant &constant)
Definition constantParsing.cpp:94
Definition constantParsing.h:68
void toJSON(JSONGenerator &) const
If true, a bitwidth and separator are present.
Definition constantParsing.cpp:39
unsigned base
An ignored prefix of the numeric constant (e.g. '0x').
Definition constantParsing.h:71
unsigned skip
Raw P4 text which was recognized as a numeric constant.
Definition constantParsing.h:70
bool hasWidth
The base in which the constant is expressed.
Definition constantParsing.h:72