IfStatementAST.py (6657:ef5fae93a3b2) IfStatementAST.py (6999:f226c098c393)
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
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 m5.util import code_formatter
29
30from slicc.ast.StatementAST import StatementAST
31from slicc.symbols import Type
32
33class IfStatementAST(StatementAST):
34 def __init__(self, slicc, cond, then, else_):
35 super(IfStatementAST, self).__init__(slicc)
36
37 assert cond is not None
38 assert then is not None
39
40 self.cond = cond
41 self.then = then
42 self.else_ = else_
43
44 def __repr__(self):
45 return "[IfStatement: %r%r%r]" % (self.cond, self.then, self.else_)
46
47 def generate(self, code, return_type):
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):
48 cond_code = code_formatter()
46 cond_code = self.slicc.codeFormatter()
49 cond_type = self.cond.generate(cond_code)
50
51 if cond_type != self.symtab.find("bool", Type):
52 self.cond.error("Condition of if stmt must be bool, type was '%s'",
53 ctype)
54
55 # Conditional
56 code.indent()

--- 18 unchanged lines hidden ---
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 ---