diff options
author | Nilay Vaish <nilay@cs.wisc.edu> | 2015-08-30 10:52:58 -0500 |
---|---|---|
committer | Nilay Vaish <nilay@cs.wisc.edu> | 2015-08-30 10:52:58 -0500 |
commit | 426e38af8b112c5b78dd36f88e66e28f55f27ecd (patch) | |
tree | 816058a6290c911cac7bbca9e478b2bf3d4ec9a5 /src/mem/slicc/symbols | |
parent | 4727fc26f885d09f07f18a10fabe6c75dffe165f (diff) | |
download | gem5-426e38af8b112c5b78dd36f88e66e28f55f27ecd.tar.xz |
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.
Diffstat (limited to 'src/mem/slicc/symbols')
-rw-r--r-- | src/mem/slicc/symbols/Func.py | 21 |
1 files changed, 21 insertions, 0 deletions
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: |