AssignStatementAST.py revision 6999
12068SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
22068SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
32068SN/A# All rights reserved.
42068SN/A#
52068SN/A# Redistribution and use in source and binary forms, with or without
62068SN/A# modification, are permitted provided that the following conditions are
72068SN/A# met: redistributions of source code must retain the above copyright
82068SN/A# notice, this list of conditions and the following disclaimer;
92068SN/A# redistributions in binary form must reproduce the above copyright
102068SN/A# notice, this list of conditions and the following disclaimer in the
112068SN/A# documentation and/or other materials provided with the distribution;
122068SN/A# neither the name of the copyright holders nor the names of its
132068SN/A# contributors may be used to endorse or promote products derived from
142068SN/A# this software without specific prior written permission.
152068SN/A#
162068SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172068SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182068SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192068SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202068SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212068SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222068SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232068SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242068SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252068SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262068SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272068SN/A
282665Ssaidi@eecs.umich.edufrom slicc.ast.StatementAST import StatementAST
292665Ssaidi@eecs.umich.edu
302665Ssaidi@eecs.umich.educlass AssignStatementAST(StatementAST):
312068SN/A    def __init__(self, slicc, lvalue, rvalue):
322649Ssaidi@eecs.umich.edu        super(AssignStatementAST, self).__init__(slicc)
332649Ssaidi@eecs.umich.edu        self.lvalue = lvalue
342649Ssaidi@eecs.umich.edu        self.rvalue = rvalue
352649Ssaidi@eecs.umich.edu
362649Ssaidi@eecs.umich.edu    def __repr__(self):
372068SN/A        return "[AssignStatementAST: %r := %r]" % (self.lvalue, self.rvalue)
382068SN/A
392068SN/A    def generate(self, code, return_type):
402068SN/A        lcode = self.slicc.codeFormatter()
412068SN/A        rcode = self.slicc.codeFormatter()
422068SN/A
432068SN/A        ltype = self.lvalue.generate(lcode)
442068SN/A        rtype = self.rvalue.generate(rcode)
452068SN/A
462068SN/A        code("$lcode = $rcode;")
472068SN/A
482107SN/A        if ltype != rtype:
492068SN/A            # FIXME - beckmann
502107SN/A            # the following if statement is a hack to allow NetDest
512068SN/A            # objects to be assigned to Sets this allows for the
522068SN/A            # previous NetworkMessage Destiantion 'Set class' to
532227SN/A            # migrate to the new NetworkMessage Destiantion 'NetDest
542107SN/A            # class'
552107SN/A            if str(ltype) != "NetDest" and str(rtype) != "Set":
562068SN/A                self.error("Assignment type mismatch '%s' and '%s'",
572068SN/A                           ltype, rtype)
582068SN/A