def _check_function(self, pytd_function, f, node, skip_self=False): """Check that a function or method is compatible with its PYTD.""" for sig in pytd_function.signatures: args = [self._create_call_arg(name, t, node) for name, t in sig.params[(1 if skip_self else 0):]] nominal_return = self.convert_constant_to_value("ret", sig.return_type) for val in f.values: fvar = val.AssignToNewVariable("f", node) _, retvar = self.call_function_in_frame( node, fvar, args, {}, None, None) if retvar.values: for combination in utils.deep_variable_product([retvar]): view = {value.variable: value for value in combination} match = abstract.match_var_against_type(retvar, nominal_return, {}, node, view) if match is None: if isinstance(val.data, (abstract.InterpreterFunction, abstract.BoundInterpreterFunction)): self.errorlog.bad_return_type( val.data.get_first_opcode(), pytd_function, view[retvar].data, sig.return_type) else: log.error("%s is not a function?", val.data.name) else: log.error("Couldn't call %s", pytd_function.name)
def testDeepVariableProductWithEmptyTopLayer(self): x1 = DummyValue(1) v1 = self.prog.NewVariable([x1], [], self.current_location) v2 = self.prog.NewVariable([], [], self.current_location) product = utils.deep_variable_product([v1, v2]) rows = [{a.data for a in row} for row in product] self.assertItemsEqual(rows, [{x1}])
def testDeepVariableProductWithEmptyTopLayer(self): x1 = DummyValue(1) v1 = self.prog.NewVariable("v1", [x1], [], self.current_location) v2 = self.prog.NewVariable("v2", [], [], self.current_location) product = utils.deep_variable_product([v1, v2]) rows = [{a.data for a in row} for row in product] self.assertItemsEqual(rows, [{x1}])
def testDeepVariableProductWithEmptyVariables(self): x1 = DummyValue(1) v1 = self.prog.NewVariable("v1", [x1], [], self.current_location) v2 = self.prog.NewVariable("v2", [], [], self.current_location) x1.set_parameters([v2]) product = utils.deep_variable_product([v1]) rows = [{a.data for a in row} for row in product] self.assertItemsEqual(rows, [{x1}])
def testDeepVariableProduct(self): x1, x2, x3, x4, x5, x6 = [DummyValue(i + 1) for i in range(6)] v1 = self.prog.NewVariable([x1, x2], [], self.current_location) v2 = self.prog.NewVariable([x3], [], self.current_location) v3 = self.prog.NewVariable([x4, x5], [], self.current_location) v4 = self.prog.NewVariable([x6], [], self.current_location) x1.set_parameters([v2, v3]) product = utils.deep_variable_product([v1, v4]) rows = [{a.data for a in row} for row in product] self.assertItemsEqual(rows, [ {x1, x3, x4, x6}, {x1, x3, x5, x6}, {x2, x6}, ])
def testDeepVariableProduct(self): x1, x2, x3, x4, x5, x6 = [DummyValue(i + 1) for i in range(6)] v1 = self.prog.NewVariable("v1", [x1, x2], [], self.current_location) v2 = self.prog.NewVariable("v2", [x3], [], self.current_location) v3 = self.prog.NewVariable("v3", [x4, x5], [], self.current_location) v4 = self.prog.NewVariable("v4", [x6], [], self.current_location) x1.set_parameters([v2, v3]) product = utils.deep_variable_product([v1, v4]) rows = [{a.data for a in row} for row in product] self.assertItemsEqual(rows, [ {x1, x3, x4, x6}, {x1, x3, x5, x6}, {x2, x6}, ])
def _check_function(self, pytd_function, f, node, skip_self=False): """Check that a function or method is compatible with its PYTD.""" for sig in pytd_function.signatures: args = [self._create_call_arg(name, t, node) for name, t in sig.params[(1 if skip_self else 0):]] nominal_return = self.convert_constant_to_value("ret", sig.return_type) for val in f.values: fvar = val.AssignToNewVariable("f", node) _, retvar = self.call_function_in_frame(node, fvar, args, None, None) if retvar.values: for combination in utils.deep_variable_product([retvar]): view = {value.variable: value for value in combination} match = abstract.match_var_against_type(retvar, nominal_return, {}, node, view) if match is None: if isinstance(val.data, (abstract.InterpreterFunction, abstract.BoundInterpreterFunction)): self.errorlog.bad_return_type( val.data.get_first_opcode(), pytd_function, view[retvar].data, sig.return_type) else: log.error("%s is not a function?", val.data.name) else: log.error("Couldn't call %s", pytd_function.name)