summaryrefslogtreecommitdiff
path: root/src/mem/slicc/ast
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2015-08-14 19:28:43 -0500
committerNilay Vaish <nilay@cs.wisc.edu>2015-08-14 19:28:43 -0500
commit7fc725fdb55e192520c148c87ec44f75f5d07ad0 (patch)
tree077503f95730d91127d88bcd0101c38096f8aadb /src/mem/slicc/ast
parentf391cee5e1f9192bc35978df236e15f921a690cf (diff)
downloadgem5-7fc725fdb55e192520c148c87ec44f75f5d07ad0.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/ast')
-rw-r--r--src/mem/slicc/ast/FuncCallExprAST.py17
-rw-r--r--src/mem/slicc/ast/MethodCallExprAST.py21
2 files changed, 5 insertions, 33 deletions
diff --git a/src/mem/slicc/ast/FuncCallExprAST.py b/src/mem/slicc/ast/FuncCallExprAST.py
index 9336a2297..0c9880d6d 100644
--- a/src/mem/slicc/ast/FuncCallExprAST.py
+++ b/src/mem/slicc/ast/FuncCallExprAST.py
@@ -93,22 +93,7 @@ class FuncCallExprAST(ExprAST):
if func is None:
self.error("Unrecognized function name: '%s'", func_name_args)
- if len(self.exprs) != len(func.param_types):
- self.error("Wrong number of arguments passed to function : '%s'" +\
- " Expected %d, got %d", self.proc_name,
- len(func.param_types), len(self.exprs))
-
- cvec = []
- type_vec = []
- for expr,expected_type in zip(self.exprs, func.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):
- expr.error("Type mismatch: expected: %s actual: %s" % \
- (expected_type, actual_type))
- cvec.append(param_code)
- type_vec.append(expected_type)
+ cvec, type_vec = func.checkArguments(self.exprs)
# OK, the semantics of "trigger" here is that, ports in the
# machine have different priorities. We always check the first
diff --git a/src/mem/slicc/ast/MethodCallExprAST.py b/src/mem/slicc/ast/MethodCallExprAST.py
index 8be319a40..104d6f8df 100644
--- a/src/mem/slicc/ast/MethodCallExprAST.py
+++ b/src/mem/slicc/ast/MethodCallExprAST.py
@@ -56,20 +56,8 @@ class MethodCallExprAST(ExprAST):
self.error("Invalid method call: Type '%s' does not have a method '%s'",
obj_type, methodId)
- if len(self.expr_ast_vec) != \
- len(obj_type.methods[methodId].param_types):
- # Right number of parameters
- self.error("Wrong number of parameters for function name: '%s', " + \
- "expected: , actual: ", proc_name,
- len(obj_type.methods[methodId].param_types),
- len(self.expr_ast_vec))
-
- for actual_type, expected_type in \
- zip(paramTypes, obj_type.methods[methodId].param_types):
- if actual_type != expected_type and \
- str(actual_type["interface"]) != str(expected_type):
- self.error("Type mismatch: expected: %s actual: %s",
- expected_type, actual_type)
+ func = obj_type.methods[methodId]
+ func.checkArguments(self.expr_ast_vec)
# Return the return type of the method
return obj_type.methods[methodId].return_type
@@ -78,10 +66,9 @@ class MethodCallExprAST(ExprAST):
pass
class MemberMethodCallExprAST(MethodCallExprAST):
- def __init__(self, slicc, obj_expr_ast, proc_name, expr_ast_vec):
+ def __init__(self, slicc, obj_expr_ast, func_call):
s = super(MemberMethodCallExprAST, self)
- s.__init__(slicc, proc_name, expr_ast_vec)
-
+ s.__init__(slicc, func_call.proc_name, func_call.exprs)
self.obj_expr_ast = obj_expr_ast
def __repr__(self):