FormalParamAST.py revision 8192
1545SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
22512SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
3545SN/A# All rights reserved.
4545SN/A#
5545SN/A# Redistribution and use in source and binary forms, with or without
6545SN/A# modification, are permitted provided that the following conditions are
7545SN/A# met: redistributions of source code must retain the above copyright
8545SN/A# notice, this list of conditions and the following disclaimer;
9545SN/A# redistributions in binary form must reproduce the above copyright
10545SN/A# notice, this list of conditions and the following disclaimer in the
11545SN/A# documentation and/or other materials provided with the distribution;
12545SN/A# neither the name of the copyright holders nor the names of its
13545SN/A# contributors may be used to endorse or promote products derived from
14545SN/A# this software without specific prior written permission.
15545SN/A#
16545SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17545SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18545SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19545SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20545SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21545SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22545SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23545SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24545SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25545SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26545SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27545SN/A
28545SN/Afrom slicc.ast.AST import AST
292657Ssaidi@eecs.umich.edufrom slicc.symbols import Var
30545SN/A
31679SN/Aclass FormalParamAST(AST):
32545SN/A    def __init__(self, slicc, type_ast, ident, default = None, pointer = False):
332489SN/A        super(FormalParamAST, self).__init__(slicc)
342497SN/A        self.type_ast = type_ast
352640Sstever@eecs.umich.edu        self.ident = ident
362489SN/A        self.default = default
372489SN/A        self.pointer = pointer
382489SN/A
392489SN/A    def __repr__(self):
402630SN/A        return "[FormalParamAST: %s]" % self.ident
412489SN/A
422489SN/A    @property
432489SN/A    def name(self):
442489SN/A        return self.ident
452489SN/A
462630SN/A    def generate(self):
472489SN/A        type = self.type_ast.type
482489SN/A        param = "param_%s" % self.ident
492489SN/A
502489SN/A        # Add to symbol table
512489SN/A        v = Var(self.symtab, self.ident, self.location, type, param,
522521SN/A                self.pairs)
532489SN/A        self.symtab.newSymbol(v)
542521SN/A        if self.pointer or str(type) == "TBE" or (
552521SN/A           "interface" in type and type["interface"] == "AbstractCacheEntry"):
562489SN/A
572489SN/A            return type, "%s* %s" % (type.c_ident, param)
582489SN/A        else:
592657Ssaidi@eecs.umich.edu            return type, "%s %s" % (type.c_ident, param)
602489SN/A