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,
105 const Visitor::Context *ctxt =
nullptr) {
106 return resolve(mcs->methodCall, refMap, typeMap,
false, ctxt,
false);
108 static MethodInstance *
resolve(
const IR::MethodCallExpression *mce,
109 const DeclarationLookup *refMap,
110 const Visitor::Context *ctxt =
nullptr) {
111 return resolve(mce, refMap,
nullptr,
true, ctxt,
false);
113 static MethodInstance *
resolve(
const IR::MethodCallStatement *mcs,
114 const DeclarationLookup *refMap,
115 const Visitor::Context *ctxt =
nullptr) {
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>(); }
158 typeSubstitution.setBindings(expr, method->type->typeParameters, expr->typeArguments);
162 const IR::Method *method;
170 const IR::Method *method,
const IR::Type_Extern *originalExternType,
174 originalExternType(originalExternType),
175 actualExternType(actualExternType) {
176 CHECK_NULL(originalExternType);
177 CHECK_NULL(actualExternType);
182 const IR::Type_Extern *originalExternType;
183 const IR::Type_Extern *actualExternType;
188 std::vector<const IR::IDeclaration *>
mayCall()
const;
195 ExternFunction(
const IR::MethodCallExpression *expr,
const IR::Method *method,
210 ActionCall(
const IR::MethodCallExpression *expr,
const IR::P4Action *action,
211 const IR::Type_Action *actionType)
221 const IR::P4Action *action;
233 FunctionCall(
const IR::MethodCallExpression *expr,
const IR::Function *function,
237 CHECK_NULL(function);
241 expr->typeArguments);
246 const IR::Function *function;
263 const IR::Expression *appliedTo,
const IR::Type_Method *methodType)
264 :
MethodInstance(expr,
nullptr, methodType, methodType), name(name), appliedTo(appliedTo) {
265 CHECK_NULL(appliedTo);
271 const IR::Expression *appliedTo;
287 explicit ConstructorCall(
const IR::ConstructorCallExpression *cce) : cce(cce) {
292 const IR::ConstructorCallExpression *cce =
nullptr;
294 const IR::ParameterList *constructorParameters =
nullptr;
295 static ConstructorCall *resolve(
const IR::ConstructorCallExpression *cce,
303 const IR::Type_Extern *type,
const IR::Method *constructor)
306 CHECK_NULL(constructor);
311 const IR::Type_Extern *type;
312 const IR::Method *constructor;
321 const IR::IContainer *cont)
328 const IR::IContainer *container;
346 : instance(instance), typeArguments(typeArguments) {
347 CHECK_NULL(instance);
348 constructorArguments = instance->arguments;
351 const IR::Declaration_Instance *instance;
354 const IR::ParameterList *constructorParameters =
nullptr;
355 const IR::TypeParameters *typeParameters =
nullptr;
357 static Instantiation *resolve(
const IR::Declaration_Instance *instance,
368 auto constructor = type->lookupConstructor(constructorArguments);
369 BUG_CHECK(constructor,
"%1%: could not find constructor", type);
370 constructorParameters = constructor->type->parameters;
371 typeParameters = type->typeParameters;
374 const IR::Type_Extern *type;
384 constructorParameters = package->getConstructorParameters();
385 typeParameters = package->typeParameters;
388 const IR::Type_Package *package;
398 typeParameters = parser->type->typeParameters;
399 constructorParameters = parser->getConstructorParameters();
402 const IR::P4Parser *parser;
412 typeParameters = control->type->typeParameters;
413 constructorParameters = control->getConstructorParameters();
416 const IR::P4Control *control;
Definition methodInstance.h:209
const IR::P4Action * specialize(const DeclarationLookup *refMap) const
Definition methodInstance.cpp:126
Definition methodInstance.h:129
Definition methodInstance.h:260
Definition methodInstance.h:284
Definition methodInstance.h:319
Definition methodInstance.h:407
Definition referenceMap.h:57
Definition methodInstance.h:149
Definition methodInstance.h:301
Definition methodInstance.h:194
Definition methodInstance.h:363
Definition methodInstance.h:168
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:232
The Declaration interface, representing objects with names.
Definition declaration.h:26
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:336
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:379
Definition parameterSubstitution.h:30
void populate(const IR::ParameterList *params, const IR::Vector< IR::Argument > *args)
Definition parameterSubstitution.cpp:34
Definition methodInstance.h:393
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