diff options
author | Nilay Vaish <nilay@cs.wisc.edu> | 2015-08-14 19:28:43 -0500 |
---|---|---|
committer | Nilay Vaish <nilay@cs.wisc.edu> | 2015-08-14 19:28:43 -0500 |
commit | 9648c05db19292ddd285a80914593cc0631403ff (patch) | |
tree | 501c8342d95b1c87f988a2fd3be2d17f63b86f0e /src/mem/slicc/ast/FuncDeclAST.py | |
parent | 7fc725fdb55e192520c148c87ec44f75f5d07ad0 (diff) | |
download | gem5-9648c05db19292ddd285a80914593cc0631403ff.tar.xz |
ruby: slicc: use default argument value
Before this patch, while one could declare / define a function with default
argument values, but the actual function call would require one to specify
all the arguments. This patch changes the check for function arguments.
Now a function call needs to specify arguments that are at least as much as
those with default values and at most the total number of arguments taken
as input by the function.
Diffstat (limited to 'src/mem/slicc/ast/FuncDeclAST.py')
-rw-r--r-- | src/mem/slicc/ast/FuncDeclAST.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/mem/slicc/ast/FuncDeclAST.py b/src/mem/slicc/ast/FuncDeclAST.py index 47ae7076e..4e64c0ba5 100644 --- a/src/mem/slicc/ast/FuncDeclAST.py +++ b/src/mem/slicc/ast/FuncDeclAST.py @@ -45,7 +45,9 @@ class FuncDeclAST(DeclAST): def generate(self, parent = None): types = [] - params = [] + proto_params = [] + body_params = [] + default_count = 0 void_type = self.symtab.find("void", Type) # Generate definition code @@ -58,13 +60,17 @@ class FuncDeclAST(DeclAST): for formal in self.formals: # Lookup parameter types try: - type, ident = formal.generate() + type, proto, body, default = formal.generate() types.append(type) - params.append(ident) + proto_params.append(proto) + body_params.append(body) + if default: + default_count += 1 except AttributeError: types.append(formal.type) - params.append(None) + proto_params.append(None) + body_params.append(None) body = self.slicc.codeFormatter() if self.statements is None: @@ -87,7 +93,8 @@ class FuncDeclAST(DeclAST): machine = self.state_machine func = Func(self.symtab, func_name_args, self.ident, self.location, - return_type, types, params, str(body), self.pairs) + return_type, types, proto_params, + body_params, str(body), self.pairs, default_count) if parent is not None: if not parent.addFunc(func): |