P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::MethodInstance Class Reference

#include <methodInstance.h>

Inheritance diagram for P4::MethodInstance:
[legend]

Public Member Functions

 DECLARE_TYPEINFO (MethodInstance, InstanceBase)
 
const IR::ParameterList * getActualParameters () const
 
const IR::ParameterList * getOriginalParameters () const
 
virtual bool isApply () const
 
- Public Member Functions inherited from P4::InstanceBase
 DECLARE_TYPEINFO (InstanceBase)
 
- Public Member Functions inherited from P4::ICastable
template<typename T >
T & as ()
 Tries to convert the class to type T. A BUG occurs if the cast fails.
 
template<typename T >
const T & as () const
 Tries to convert the class to type T. A BUG occurs if the cast fails.
 
template<typename T >
T * checkedTo ()
 Performs a checked cast. A BUG occurs if the cast fails.
 
template<typename T >
const T * checkedTo () const
 Performs a checked cast. A BUG occurs if the cast fails.
 
- Public Member Functions inherited from P4::RTTI::Base
template<typename T >
bool is () const noexcept
 
virtual bool isA (TypeId typeId) const noexcept=0
 
template<typename T >
const T * to () const noexcept
 Same as to, but returns const pointer to T.
 
template<typename T >
T * to () noexcept
 
virtual TypeId typeId () const noexcept=0
 

Static Public Member Functions

static MethodInstanceresolve (const IR::MethodCallExpression *mce, const DeclarationLookup *refMap, const Visitor::Context *ctxt=nullptr)
 
static MethodInstanceresolve (const IR::MethodCallExpression *mce, const DeclarationLookup *refMap, TypeMap *typeMap, bool useExpressionType=false, const Visitor::Context *ctxt=nullptr, bool incomplete=false)
 
static MethodInstanceresolve (const IR::MethodCallExpression *mce, const DeclarationLookup *refMap, TypeMap *typeMap, const Visitor::Context *ctxt, bool incomplete=false)
 
static MethodInstanceresolve (const IR::MethodCallStatement *mcs, const DeclarationLookup *refMap, const Visitor::Context *ctxt=nullptr)
 
static MethodInstanceresolve (const IR::MethodCallStatement *mcs, const DeclarationLookup *refMap, TypeMap *typeMap, const Visitor::Context *ctxt=nullptr)
 

Public Attributes

const IR::Type_MethodBase * actualMethodType
 
const IR::MethodCallExpression * expr
 
const IR::IDeclarationobject
 
const IR::Type_MethodBase * originalMethodType
 
- Public Attributes inherited from P4::InstanceBase
ParameterSubstitution substitution
 For each callee parameter the corresponding argument.
 
TypeVariableSubstitution typeSubstitution
 

Protected Member Functions

 MethodInstance (const IR::MethodCallExpression *mce, const IR::IDeclaration *decl, const IR::Type_MethodBase *originalMethodType, const IR::Type_MethodBase *actualMethodType)
 
void bindParameters ()
 
- Protected Member Functions inherited from P4::InstanceBase
- Protected Member Functions inherited from P4::RTTI::Base
virtual const void * toImpl (TypeId typeId) const noexcept=0
 

Detailed Description

This class is very useful for extracting information out of MethodCallExpressions. Since there are no function pointers in P4, methods can completely be resolved at compilation time. The static method 'resolve' will categorize each method call into one of several kinds:

  • apply method, could be of a table, control or parser
  • extern function
  • extern method (method of an extern object)
  • action call
  • built-in method (there are five of these: setValid, setInvalid, isValid, push, pop

See also the ConstructorCall class and the MethodCallDescription class below.

Member Function Documentation

◆ resolve()

MethodInstance * P4::MethodInstance::resolve ( const IR::MethodCallExpression * mce,
const DeclarationLookup * refMap,
TypeMap * typeMap,
bool useExpressionType = false,
const Visitor::Context * ctxt = nullptr,
bool incomplete = false )
static
Parameters
useExpressionTypeIf true, the typeMap can be nullptr, and then mce->type is used. For some technical reasons neither the refMap or the typeMap are const here.
incompleteIf true we do not expect to have all type arguments.

Member Data Documentation

◆ actualMethodType

const IR::Type_MethodBase* P4::MethodInstance::actualMethodType

Type of called method, with instantiated type parameters.

◆ object

const IR::IDeclaration* P4::MethodInstance::object

Declaration of object that method is applied to. May be null for plain functions.

◆ originalMethodType

const IR::Type_MethodBase* P4::MethodInstance::originalMethodType

The type of the original called method, without instantiated type parameters.