01: /* IIncOperator Copyright (C) 1998-2002 Jochen Hoenicke.
02: *
03: * This program is free software; you can redistribute it and/or modify
04: * it under the terms of the GNU Lesser General Public License as published by
05: * the Free Software Foundation; either version 2, or (at your option)
06: * any later version.
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program; see the file COPYING.LESSER. If not, write to
15: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16: *
17: * $Id: IIncOperator.java,v 4.17.2.2 2002/05/28 17:34:06 hoenicke Exp $
18: */
19:
20: package jode.expr;
21:
22: import jode.type.Type;
23: import jode.decompiler.LocalInfo;
24: import jode.decompiler.TabbedPrintWriter;
25:
26: public class IIncOperator extends Operator implements
27: CombineableOperator {
28: int value;
29:
30: public IIncOperator(LocalStoreOperator localStore, int value,
31: int operator) {
32: super (Type.tVoid, operator);
33: this .value = value;
34: initOperands(1);
35: setSubExpressions(0, localStore);
36: }
37:
38: public LValueExpression getLValue() {
39: return (LValueExpression) subExpressions[0];
40: }
41:
42: public int getValue() {
43: return value;
44: }
45:
46: public int getPriority() {
47: return 100;
48: }
49:
50: public void updateSubTypes() {
51: subExpressions[0]
52: .setType(type != Type.tVoid ? type : Type.tInt);
53: }
54:
55: public void updateType() {
56: if (type != Type.tVoid)
57: updateParentType(subExpressions[0].getType());
58: }
59:
60: /**
61: * Makes a non void expression out of this store instruction.
62: */
63: public void makeNonVoid() {
64: if (type != Type.tVoid)
65: throw new jode.AssertError("already non void");
66: type = subExpressions[0].getType();
67: }
68:
69: public boolean lvalueMatches(Operator loadop) {
70: return getLValue().matches(loadop);
71: }
72:
73: public Expression simplify() {
74: if (value == 1) {
75: int op = (getOperatorIndex() == OPASSIGN_OP + ADD_OP) ? INC_OP
76: : DEC_OP;
77: return new PrePostFixOperator(getType(), op, getLValue(),
78: isVoid()).simplify();
79: }
80: return super .simplify();
81: }
82:
83: public void dumpExpression(TabbedPrintWriter writer)
84: throws java.io.IOException {
85: writer.startOp(writer.NO_PAREN, 2);
86: subExpressions[0].dumpExpression(writer);
87: writer.endOp();
88: writer.print(getOperatorString() + value);
89: }
90: }
|