FormalParamAST.py (6657:ef5fae93a3b2) FormalParamAST.py (6877:2a1a3d916ca8)
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2# Copyright (c) 2009 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 15 unchanged lines hidden (view full) ---

24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28from slicc.ast.AST import AST
29from slicc.symbols import Var
30
31class FormalParamAST(AST):
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2# Copyright (c) 2009 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 15 unchanged lines hidden (view full) ---

24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28from slicc.ast.AST import AST
29from slicc.symbols import Var
30
31class FormalParamAST(AST):
32 def __init__(self, slicc, type_ast, ident):
32 def __init__(self, slicc, type_ast, ident, default = None):
33 super(FormalParamAST, self).__init__(slicc)
34 self.type_ast = type_ast
35 self.ident = ident
33 super(FormalParamAST, self).__init__(slicc)
34 self.type_ast = type_ast
35 self.ident = ident
36 self.default = default
36
37 def __repr__(self):
38 return "[FormalParamAST: %s]" % self.ident
39
40 @property
41 def name(self):
42 return self.ident
43
44 def generate(self):
45 type = self.type_ast.type
46 param = "param_%s" % self.ident
47
48 # Add to symbol table
49 v = Var(self.symtab, self.ident, self.location, type, param,
50 self.pairs)
51 self.symtab.newSymbol(v)
52 return type, "%s %s" % (type.c_ident, param)
37
38 def __repr__(self):
39 return "[FormalParamAST: %s]" % self.ident
40
41 @property
42 def name(self):
43 return self.ident
44
45 def generate(self):
46 type = self.type_ast.type
47 param = "param_%s" % self.ident
48
49 # Add to symbol table
50 v = Var(self.symtab, self.ident, self.location, type, param,
51 self.pairs)
52 self.symtab.newSymbol(v)
53 return type, "%s %s" % (type.c_ident, param)