P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::TypeMap Class Referencefinal

#include <typeMap.h>

Inheritance diagram for P4::TypeMap:
[legend]

Public Member Functions

void addSubstitutions (const TypeVariableSubstitution *tvs)
 
void clear ()
 
void cloneExpressionProperties (const IR::Expression *to, const IR::Expression *from)
 
bool contains (const IR::Node *element)
 
void dbprint (std::ostream &out) const
 
bool equivalent (const IR::Type *left, const IR::Type *right, bool strict=false) const
 
const IR::Type * getCanonical (const IR::Type *type)
 
const IR::Type * getSubstitution (const IR::ITypeVar *var)
 
const TypeVariableSubstitutiongetSubstitutions () const
 
const IR::Type * getType (const IR::Node *element, bool notNull=false) const
 
const IR::Type * getTypeType (const IR::Node *element, bool notNull) const
 
bool implicitlyConvertibleTo (const IR::Type *from, const IR::Type *to) const
 
bool isCompileTimeConstant (const IR::Expression *expression) const
 
bool isLeftValue (const IR::Expression *expression) const
 
void setCompileTimeConstant (const IR::Expression *expression)
 
void setLeftValue (const IR::Expression *expression)
 
void setStrictStruct (bool value)
 
void setType (const IR::Node *element, const IR::Type *type)
 
size_t size () const
 
bool typeIsEmpty (const IR::Type *type) const
 True is type occupies no storage.
 
int widthBits (const IR::Type *type, const IR::Node *errorPosition, bool max) const
 
- Public Member Functions inherited from P4::ProgramMap
bool checkMap (const IR::Node *node) const
 
void clear ()
 
void updateMap (const IR::Node *node)
 
void validateMap (const IR::Node *node) const
 
- Public Member Functions inherited from P4::IHasDbPrint
void print () const
 

Public Attributes

bool strictStruct
 

Additional Inherited Members

- Protected Member Functions inherited from P4::ProgramMap
 ProgramMap (std::string_view kind)
 
- Protected Attributes inherited from P4::ProgramMap
const IR::P4Program * fake = new IR::P4Program()
 
cstring mapKind
 
const IR::P4Program * program = nullptr
 

Detailed Description

Maps nodes to their canonical types. Not all Node objects have types. The type of each node is maintained in the typeMap. Objects that have a type in the map:

  • all Expression objects (includes Literals)
  • function parameters
  • variables and constant declarations
  • functors (control, parser, etc.)
  • functions
  • interfaces
  • enum fields (pointing to the enclosing enum)
  • error (pointing to the error type)
  • type declarations - map name to the actual type

Member Function Documentation

◆ dbprint()

void P4::TypeMap::dbprint ( std::ostream & out) const
virtual

Implements P4::IHasDbPrint.

◆ equivalent()

bool P4::TypeMap::equivalent ( const IR::Type * left,
const IR::Type * right,
bool strict = false ) const

Check deep structural equivalence; defined between canonical types only.

Parameters
strictIf true use strict equivalence checks, irrespective of the strictStruct flag, else use the strictStruct flag value.

◆ implicitlyConvertibleTo()

bool P4::TypeMap::implicitlyConvertibleTo ( const IR::Type * from,
const IR::Type * to ) const

This is the same as equivalence, but it also allows some legal implicit conversions, such as a tuple type to a struct type, which is used when initializing a struct with a list expression.

◆ widthBits()

int P4::TypeMap::widthBits ( const IR::Type * type,
const IR::Node * errorPosition,
bool max ) const

The width in bits of this type. If the width is not well-defined this will report an error and return -1. max indicates whether we want the max width or min width.

Member Data Documentation

◆ strictStruct

bool P4::TypeMap::strictStruct

If true we require structs to have the same name to be equivalent, if false only that the have the same fields.