17#ifndef FRONTENDS_P4_METHODINSTANCE_H_
18#define FRONTENDS_P4_METHODINSTANCE_H_
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "frontends/p4/parameterSubstitution.h"
22#include "frontends/p4/typeMap.h"
70 void bindParameters() {
71 auto params = getActualParameters();
76 const IR::MethodCallExpression *expr;
86 virtual bool isApply()
const {
return false; }
96 bool useExpressionType =
false,
101 return resolve(mce, refMap, typeMap,
false, ctxt, incomplete);
103 static MethodInstance *
resolve(
const IR::MethodCallStatement *mcs,
104 const DeclarationLookup *refMap, TypeMap *typeMap,
106 return resolve(mcs->methodCall, refMap, typeMap,
false, ctxt,
false);
108 static MethodInstance *
resolve(
const IR::MethodCallExpression *mce,
109 const DeclarationLookup *refMap,
111 return resolve(mce, refMap,
nullptr,
true, ctxt,
false);
113 static MethodInstance *
resolve(
const IR::MethodCallStatement *mcs,
114 const DeclarationLookup *refMap,
116 return resolve(mcs->methodCall, refMap,
nullptr,
true, ctxt,
false);
119 const IR::ParameterList *getOriginalParameters()
const {
122 const IR::ParameterList *getActualParameters()
const {
return actualMethodType->parameters; }
124 DECLARE_TYPEINFO(MethodInstance, InstanceBase);
131 const IR::IApply *applyObject)
133 applyObject->getApplyMethodType()),
134 applyObject(applyObject) {
135 CHECK_NULL(applyObject);
141 const IR::IApply *applyObject;
142 bool isApply()
const override {
return true; }
143 bool isTableApply()
const {
return object->
is<IR::P4Table>(); }
151 const IR::Method *method,
const IR::Type_Extern *originalExternType,
156 originalExternType(originalExternType),
157 actualExternType(actualExternType) {
159 CHECK_NULL(originalExternType);
160 CHECK_NULL(actualExternType);
163 typeSubstitution.setBindings(expr, method->type->typeParameters, expr->typeArguments);
168 const IR::Method *method;
169 const IR::Type_Extern *originalExternType;
170 const IR::Type_Extern *actualExternType;
175 std::vector<const IR::IDeclaration *>
mayCall()
const;
182 ExternFunction(
const IR::MethodCallExpression *expr,
const IR::Method *method,
189 typeSubstitution.setBindings(expr, method->type->typeParameters, expr->typeArguments);
194 const IR::Method *method;
204 ActionCall(
const IR::MethodCallExpression *expr,
const IR::P4Action *action,
205 const IR::Type_Action *actionType)
215 const IR::P4Action *action;
227 FunctionCall(
const IR::MethodCallExpression *expr,
const IR::Function *function,
231 CHECK_NULL(function);
235 expr->typeArguments);
240 const IR::Function *function;
257 const IR::Expression *appliedTo,
const IR::Type_Method *methodType)
258 :
MethodInstance(expr,
nullptr, methodType, methodType), name(name), appliedTo(appliedTo) {
259 CHECK_NULL(appliedTo);
265 const IR::Expression *appliedTo;
281 explicit ConstructorCall(
const IR::ConstructorCallExpression *cce) : cce(cce) {
286 const IR::ConstructorCallExpression *cce =
nullptr;
288 const IR::ParameterList *constructorParameters =
nullptr;
289 static ConstructorCall *resolve(
const IR::ConstructorCallExpression *cce,
297 const IR::Type_Extern *type,
const IR::Method *constructor)
300 CHECK_NULL(constructor);
305 const IR::Type_Extern *type;
306 const IR::Method *constructor;
315 const IR::IContainer *cont)
322 const IR::IContainer *container;
340 : instance(instance), typeArguments(typeArguments) {
341 CHECK_NULL(instance);
342 constructorArguments = instance->arguments;
345 const IR::Declaration_Instance *instance;
348 const IR::ParameterList *constructorParameters =
nullptr;
349 const IR::TypeParameters *typeParameters =
nullptr;
351 static Instantiation *resolve(
const IR::Declaration_Instance *instance,
362 auto constructor = type->lookupConstructor(constructorArguments);
363 BUG_CHECK(constructor,
"%1%: could not find constructor", type);
364 constructorParameters = constructor->type->parameters;
365 typeParameters = type->typeParameters;
368 const IR::Type_Extern *type;
378 constructorParameters = package->getConstructorParameters();
379 typeParameters = package->typeParameters;
382 const IR::Type_Package *package;
392 typeParameters = parser->type->typeParameters;
393 constructorParameters = parser->getConstructorParameters();
396 const IR::P4Parser *parser;
406 typeParameters = control->type->typeParameters;
407 constructorParameters = control->getConstructorParameters();
410 const IR::P4Control *control;
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition methodInstance.h:203
const IR::P4Action * specialize(const DeclarationLookup *refMap) const
Definition methodInstance.cpp:126
Definition methodInstance.h:129
Definition methodInstance.h:254
Definition methodInstance.h:278
Definition methodInstance.h:313
Definition methodInstance.h:401
Definition referenceMap.h:57
Definition methodInstance.h:295
Definition methodInstance.h:181
Definition methodInstance.h:357
Definition methodInstance.h:149
std::vector< const IR::IDeclaration * > mayCall() const
Set of IR::Method and IR::Function objects that may be called by this method.
Definition methodInstance.cpp:198
Definition methodInstance.h:226
Definition methodInstance.h:27
TypeVariableSubstitution typeSubstitution
Definition methodInstance.h:36
ParameterSubstitution substitution
For each callee parameter the corresponding argument.
Definition methodInstance.h:33
Used to resolve a Declaration_Instance.
Definition methodInstance.h:330
Definition methodInstance.h:56
const IR::Type_MethodBase * actualMethodType
Definition methodInstance.h:85
const IR::Type_MethodBase * originalMethodType
Definition methodInstance.h:82
static MethodInstance * resolve(const IR::MethodCallExpression *mce, const DeclarationLookup *refMap, TypeMap *typeMap, bool useExpressionType=false, const Visitor::Context *ctxt=nullptr, bool incomplete=false)
Definition methodInstance.cpp:27
const IR::IDeclaration * object
Definition methodInstance.h:79
Definition methodInstance.h:373
Definition parameterSubstitution.h:30
void populate(const IR::ParameterList *params, const IR::Vector< IR::Argument > *args)
Definition parameterSubstitution.cpp:34
Definition methodInstance.h:387
Definition typeSubstitution.h:73
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
bool is() const noexcept
Definition rtti.h:216