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; --- 11 unchanged lines hidden (view full) --- 20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 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.StatementAST import StatementAST 29from slicc.symbols import Type 30 31class IfStatementAST(StatementAST): 32 def __init__(self, slicc, cond, then, else_): 33 super(IfStatementAST, self).__init__(slicc) 34 35 assert cond is not None 36 assert then is not None 37 38 self.cond = cond 39 self.then = then 40 self.else_ = else_ 41 42 def __repr__(self): 43 return "[IfStatement: %r%r%r]" % (self.cond, self.then, self.else_) 44 45 def generate(self, code, return_type): |
46 cond_code = self.slicc.codeFormatter() |
47 cond_type = self.cond.generate(cond_code) 48 49 if cond_type != self.symtab.find("bool", Type): 50 self.cond.error("Condition of if stmt must be bool, type was '%s'", 51 ctype) 52 53 # Conditional 54 code.indent() --- 18 unchanged lines hidden --- |