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"
58 MethodInstance(
const IR::MethodCallExpression *mce,
const IR::IDeclaration *decl,
70 void bindParameters() {
71 auto params = getActualParameters();
76 const IR::MethodCallExpression *expr;
86 virtual bool isApply()
const {
return false; }
95 TypeMap *typeMap,
bool useExpressionType =
false,
96 const Visitor::Context *ctxt =
nullptr,
bool incomplete =
false);
98 TypeMap *typeMap,
const Visitor::Context *ctxt,
99 bool incomplete =
false) {
100 return resolve(mce, refMap, typeMap,
false, ctxt, incomplete);
102 static MethodInstance *resolve(
const IR::MethodCallStatement *mcs, DeclarationLookup *refMap,
103 TypeMap *typeMap,
const Visitor::Context *ctxt =
nullptr) {
104 return resolve(mcs->methodCall, refMap, typeMap,
false, ctxt,
false);
106 static MethodInstance *
resolve(
const IR::MethodCallExpression *mce, DeclarationLookup *refMap,
107 const Visitor::Context *ctxt =
nullptr) {
108 return resolve(mce, refMap,
nullptr,
true, ctxt,
false);
110 static MethodInstance *
resolve(
const IR::MethodCallStatement *mcs, DeclarationLookup *refMap,
111 const Visitor::Context *ctxt =
nullptr) {
112 return resolve(mcs->methodCall, refMap,
nullptr,
true, ctxt,
false);
114 const IR::ParameterList *getOriginalParameters()
const {
117 const IR::ParameterList *getActualParameters()
const {
return actualMethodType->parameters; }
119 DECLARE_TYPEINFO(MethodInstance, InstanceBase);
125 ApplyMethod(
const IR::MethodCallExpression *expr,
const IR::IDeclaration *decl,
126 const IR::IApply *applyObject)
128 applyObject->getApplyMethodType()),
129 applyObject(applyObject) {
130 CHECK_NULL(applyObject);
136 const IR::IApply *applyObject;
137 bool isApply()
const override {
return true; }
138 bool isTableApply()
const {
return object->
is<IR::P4Table>(); }
145 ExternMethod(
const IR::MethodCallExpression *expr,
const IR::IDeclaration *decl,
146 const IR::Method *method,
const IR::Type_Extern *originalExternType,
151 originalExternType(originalExternType),
152 actualExternType(actualExternType) {
154 CHECK_NULL(originalExternType);
155 CHECK_NULL(actualExternType);
158 typeSubstitution.setBindings(expr, method->type->typeParameters, expr->typeArguments);
163 const IR::Method *method;
164 const IR::Type_Extern *originalExternType;
165 const IR::Type_Extern *actualExternType;
170 std::vector<const IR::IDeclaration *>
mayCall()
const;
177 ExternFunction(
const IR::MethodCallExpression *expr,
const IR::Method *method,
184 typeSubstitution.setBindings(expr, method->type->typeParameters, expr->typeArguments);
189 const IR::Method *method;
199 ActionCall(
const IR::MethodCallExpression *expr,
const IR::P4Action *action,
200 const IR::Type_Action *actionType)
210 const IR::P4Action *action;
222 FunctionCall(
const IR::MethodCallExpression *expr,
const IR::Function *function,
226 CHECK_NULL(function);
230 expr->typeArguments);
235 const IR::Function *function;
251 BuiltInMethod(
const IR::MethodCallExpression *expr, IR::ID name,
252 const IR::Expression *appliedTo,
const IR::Type_Method *methodType)
253 :
MethodInstance(expr,
nullptr, methodType, methodType), name(name), appliedTo(appliedTo) {
254 CHECK_NULL(appliedTo);
260 const IR::Expression *appliedTo;
276 explicit ConstructorCall(
const IR::ConstructorCallExpression *cce) : cce(cce) {
281 const IR::ConstructorCallExpression *cce =
nullptr;
283 const IR::ParameterList *constructorParameters =
nullptr;
284 static ConstructorCall *resolve(
const IR::ConstructorCallExpression *cce,
292 const IR::Type_Extern *type,
const IR::Method *constructor)
295 CHECK_NULL(constructor);
300 const IR::Type_Extern *type;
301 const IR::Method *constructor;
310 const IR::IContainer *cont)
317 const IR::IContainer *container;
335 : instance(instance), typeArguments(typeArguments) {
336 CHECK_NULL(instance);
337 constructorArguments = instance->arguments;
340 const IR::Declaration_Instance *instance;
343 const IR::ParameterList *constructorParameters =
nullptr;
344 const IR::TypeParameters *typeParameters =
nullptr;
346 static Instantiation *resolve(
const IR::Declaration_Instance *instance,
357 auto constructor = type->lookupConstructor(constructorArguments);
358 BUG_CHECK(constructor,
"%1%: could not find constructor", type);
359 constructorParameters = constructor->type->parameters;
360 typeParameters = type->typeParameters;
363 const IR::Type_Extern *type;
373 constructorParameters = package->getConstructorParameters();
374 typeParameters = package->typeParameters;
377 const IR::Type_Package *package;
387 typeParameters = parser->type->typeParameters;
388 constructorParameters = parser->getConstructorParameters();
391 const IR::P4Parser *parser;
401 typeParameters = control->type->typeParameters;
402 constructorParameters = control->getConstructorParameters();
405 const IR::P4Control *control;
Definition externInstance.h:33
Definition methodInstance.h:198
const IR::P4Action * specialize(ReferenceMap *refMap) const
Definition methodInstance.cpp:126
Definition methodInstance.h:124
Definition methodInstance.h:249
Definition methodInstance.h:273
Definition methodInstance.h:308
Definition methodInstance.h:396
Definition referenceMap.h:57
Definition methodInstance.h:290
Definition methodInstance.h:176
Definition methodInstance.h:352
Definition methodInstance.h:144
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:221
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:325
Definition methodInstance.h:56
const IR::Type_MethodBase * actualMethodType
Definition methodInstance.h:85
static MethodInstance * resolve(const IR::MethodCallExpression *mce, DeclarationLookup *refMap, TypeMap *typeMap, bool useExpressionType=false, const Visitor::Context *ctxt=nullptr, bool incomplete=false)
Definition methodInstance.cpp:26
const IR::Type_MethodBase * originalMethodType
Definition methodInstance.h:82
const IR::IDeclaration * object
Definition methodInstance.h:79
Definition methodInstance.h:368
Definition parameterSubstitution.h:31
void populate(const IR::ParameterList *params, const IR::Vector< IR::Argument > *args)
Definition parameterSubstitution.cpp:34
Definition methodInstance.h:382
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeSubstitution.h:73
Definition applyOptionsPragmas.cpp:24
bool is() const noexcept
Definition rtti.h:216