From 7fc725fdb55e192520c148c87ec44f75f5d07ad0 Mon Sep 17 00:00:00 2001 From: Nilay Vaish Date: Fri, 14 Aug 2015 19:28:43 -0500 Subject: ruby: slicc: avoid duplicate code for function argument check Both FuncCallExprAST and MethodCallExprAST had code for checking the arguments with which a function is being called. The patch does away with this duplication. Now the code for checking function call arguments resides in the Func class. --- src/mem/slicc/symbols/Func.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/mem/slicc/symbols/Func.py') diff --git a/src/mem/slicc/symbols/Func.py b/src/mem/slicc/symbols/Func.py index d50d0309f..6da74002a 100644 --- a/src/mem/slicc/symbols/Func.py +++ b/src/mem/slicc/symbols/Func.py @@ -62,6 +62,27 @@ class Func(Symbol): def writeCodeFiles(self, path, includes): return + def checkArguments(self, args): + if len(args) != len(self.param_types): + self.error("Wrong number of arguments passed to function : '%s'" +\ + " Expected %d, got %d", self.c_ident, + len(self.param_types), len(args)) + + cvec = [] + type_vec = [] + for expr,expected_type in zip(args, self.param_types): + # Check the types of the parameter + actual_type,param_code = expr.inline(True) + if str(actual_type) != 'OOD' and \ + str(actual_type) != str(expected_type) and \ + str(actual_type["interface"]) != str(expected_type): + expr.error("Type mismatch: expected: %s actual: %s" % \ + (expected_type, actual_type)) + cvec.append(param_code) + type_vec.append(expected_type) + + return cvec, type_vec + def generateCode(self): '''This write a function of object Chip''' if "external" in self: -- cgit v1.2.3