P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::UnparsedConstant Struct Reference

#include <constantParsing.h>

Public Member Functions

void toJSON (JSONGenerator &) const
 If true, a bitwidth and separator are present.
 

Static Public Member Functions

static UnparsedConstant fromJSON (JSONLoader &)
 

Public Attributes

unsigned base
 An ignored prefix of the numeric constant (e.g. '0x').
 
bool hasWidth
 The base in which the constant is expressed.
 
unsigned skip
 Raw P4 text which was recognized as a numeric constant.
 
cstring text
 

Detailed Description

An unparsed numeric constant. We produce these as token values during lexing. The parser is responsible for actually interpreting the raw text as a numeric value and transforming it into an IR::Constant using parseConstant().

To illustrate how a numeric constant is represented using this struct, here is a breakdown of '16w0x12':

     ___
    /                                    ___
    |                                   /
    |   bitwidth (if @hasWidth)        |       16
    |                                   \___
    |
    |                                    ___
    |                                   /
    |   separator (if @hasWidth)       |       w
    |                                   \___

@text | | ___ | / | ignored prefix of length

| ___ | | ___ | / | numeric value in base @base | w | ___ ___

Simple numeric constants like '5' are specified by setting @hasWidth to false and providing a