OperatorExprAST.py (10521:ca248520649f) OperatorExprAST.py (10965:6f433e7f9767)
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;

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

102
103 def __repr__(self):
104 return "[PrefixExpr: %s %r]" % (self.op, self.operand)
105
106 def generate(self, code):
107 opcode = self.slicc.codeFormatter()
108 optype = self.operand.generate(opcode)
109
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;

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

102
103 def __repr__(self):
104 return "[PrefixExpr: %s %r]" % (self.op, self.operand)
105
106 def generate(self, code):
107 opcode = self.slicc.codeFormatter()
108 optype = self.operand.generate(opcode)
109
110 # Figure out what the input and output types should be
111 opmap = {"!": "bool", "-": "int", "++": "Scalar"}
112 if self.op in opmap:
113 output = opmap[self.op]
114 type_in_symtab = self.symtab.find(opmap[self.op], Type)
115 if (optype != type_in_symtab):
116 self.error("Type mismatch: right operand of " +
117 "unary operator '%s' must be of type '%s'. ",
118 self.op, type_in_symtab)
119 else:
120 self.error("Invalid prefix operator '%s'",
121 self.op)
122
123 # All is well
110 fix = code.nofix()
111 code("(${{self.op}} $opcode)")
112 code.fix(fix)
113
124 fix = code.nofix()
125 code("(${{self.op}} $opcode)")
126 code.fix(fix)
127
114 return self.symtab.find("void", Type)
128 return self.symtab.find(output, Type)