def apply_annots(postfix, annots, expr): """Copies the method call""" copy_error = lambda node_id: addError( 'transforming hlir', f'Recursion found during deep-copy on node {node_id}') mcall = expr.methodCall method = mcall.method method.action_ref = deep_copy(method.action_ref, on_error=copy_error) method.type = deep_copy(method.type, on_error=copy_error) method.action_ref.name += f"_{postfix}" method.path.name += f"_{postfix}" method.type.name += f"_{postfix}" mapars = method.action_ref.type.parameters.parameters mtpars = method.type.parameters.parameters mcargs = mcall.arguments extra_args = annots.flatmap('expr') mapars.vec += extra_args.map(copy_arg) # TODO is using deep_copy OK in all cases, or is a separate method like copy_arg needed? mtpars.vec += extra_args.map('type').map(deep_copy) mcargs.vec += extra_args # remove "checksum" del mapars.vec[2] del mtpars.vec[2] del mcargs.vec[2] # remove "condition" del mapars.vec[0] del mtpars.vec[0] del mcargs.vec[0]
def apply_annotations(postfix, extra_args, expr): if expr.methodCall.method.node_type != "PathExpression": return expr on_error = lambda node_id: addError('transforming hlir16', 'Recursion found during deep-copy on node {}'.format(node_id)) def make_node(arg): node = P4Node() node.node_type = 'Parameter' node.type = arg.type node.name = postfix + "_extra_param" node.direction = 'in' node.declid = 0 #TODO: is this important? node.annotations = [] return node extra_args_types = [make_node(arg) for arg in extra_args] new_decl = deep_copy(expr.methodCall.method.ref, on_error) new_decl.name += "_" + postfix new_decl.type.parameters.parameters.vec += extra_args_types del new_decl.type.parameters.parameters.vec[:2] expr.methodCall.method.ref = new_decl expr.methodCall.method.path.name += "_" + postfix expr.methodCall.arguments.vec += extra_args del expr.methodCall.arguments.vec[:2] return x
def apply_annotations(postfix, extra_args, x): if (x.methodCall.method.node_type=="PathExpression") : new_decl = deep_copy(x.methodCall.method.ref) new_decl.name += "_" + postfix extra_args_types = [ P4Node({'id' : get_fresh_node_id(), 'node_type' : 'Parameter', 'type' : arg.type, 'name' : postfix + "_extra_param", 'direction' : 'in', 'declid' : 0, #TODO: is this important? 'annotations' : [] }) for arg in extra_args ] new_decl.type.parameters.parameters.vec += extra_args_types x.methodCall.method.ref = new_decl x.methodCall.method.path.name += "_" + postfix x.methodCall.arguments.vec += extra_args del new_decl.type.parameters.parameters.vec[:2] del x.methodCall.arguments.vec[:2] return x