KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > expr > IIncOperator


1 /* IIncOperator Copyright (C) 1998-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * 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 import jode.type.Type;
22 import jode.decompiler.LocalInfo;
23 import jode.decompiler.TabbedPrintWriter;
24
25 public class IIncOperator extends Operator
26     implements CombineableOperator {
27     int value;
28
29     public IIncOperator(LocalStoreOperator localStore, int value,
30             int operator) {
31         super(Type.tVoid, operator);
32     this.value = value;
33     initOperands(1);
34     setSubExpressions(0, localStore);
35     }
36
37     public LValueExpression getLValue() {
38     return (LValueExpression) subExpressions[0];
39     }
40
41     public int getValue() {
42     return value;
43     }
44
45     public int getPriority() {
46         return 100;
47     }
48
49     public void updateSubTypes() {
50     subExpressions[0].setType(type != Type.tVoid ? type : Type.tInt);
51     }
52
53
54     public void updateType() {
55     if (type != Type.tVoid)
56         updateParentType(subExpressions[0].getType());
57     }
58
59     /**
60      * Makes a non void expression out of this store instruction.
61      */

62     public void makeNonVoid() {
63         if (type != Type.tVoid)
64             throw new jode.AssertError("already non void");
65         type = subExpressions[0].getType();
66     }
67
68     public boolean lvalueMatches(Operator loadop) {
69     return getLValue().matches(loadop);
70     }
71
72     public Expression simplify() {
73         if (value == 1) {
74             int op = (getOperatorIndex() == OPASSIGN_OP+ADD_OP)
75                 ? INC_OP : DEC_OP;
76             return new PrePostFixOperator
77                 (getType(), op, getLValue(), isVoid()).simplify();
78         }
79         return super.simplify();
80     }
81
82     public void dumpExpression(TabbedPrintWriter writer)
83     throws java.io.IOException JavaDoc {
84     writer.startOp(writer.NO_PAREN, 2);
85     subExpressions[0].dumpExpression(writer);
86     writer.endOp();
87     writer.print(getOperatorString() + value);
88     }
89 }
90
Popular Tags