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/FormalParamAST.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/FormalParamAST.py')
-rw-r--r-- | src/mem/slicc/ast/FormalParamAST.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/mem/slicc/ast/FormalParamAST.py b/src/mem/slicc/ast/FormalParamAST.py index ce73304f1..ef39b40f0 100644 --- a/src/mem/slicc/ast/FormalParamAST.py +++ b/src/mem/slicc/ast/FormalParamAST.py @@ -46,6 +46,9 @@ class FormalParamAST(AST): def generate(self): type = self.type_ast.type param = "param_%s" % self.ident + proto = "" + body = "" + default = False # Add to symbol table v = Var(self.symtab, self.ident, self.location, type, param, @@ -56,6 +59,21 @@ class FormalParamAST(AST): "interface" in type and ( type["interface"] == "AbstractCacheEntry" or type["interface"] == "AbstractEntry")): - return type, "%s* %s" % (type.c_ident, param) + proto = "%s* %s" % (type.c_ident, param) + body = proto + elif self.default != None: + value = "" + if self.default == True: + value = "true" + elif self.default == False: + value = "false" + else: + value = "%s" % self.default + proto = "const %s& %s = %s" % (type.c_ident, param, value) + body = "const %s& %s" % (type.c_ident, param) + default = True else: - return type, "const %s& %s" % (type.c_ident, param) + proto = "const %s& %s" % (type.c_ident, param) + body = proto + + return type, proto, body, default |