001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jerome Miecznikowski
003: * Copyright (C) 2004-2005 Nomair A. Naeem
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the
017: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
018: * Boston, MA 02111-1307, USA.
019: */
020:
021: package soot.dava.internal.AST;
022:
023: import soot.*;
024: import java.util.*;
025: import soot.jimple.*;
026: import soot.dava.internal.SET.*;
027: import soot.dava.toolkits.base.AST.analysis.*;
028:
029: public class ASTIfNode extends ASTControlFlowNode {
030: private List<Object> body;
031:
032: public ASTIfNode(SETNodeLabel label, ConditionExpr condition,
033: List<Object> body) {
034: super (label, condition);
035: this .body = body;
036:
037: subBodies.add(body);
038: }
039:
040: /*
041: Nomair A. Naeem 17-FEB-05
042: Needed because of change of grammar of condition being stored as a ASTCondition rather
043: than the ConditionExpr which was the case before
044: */
045: public ASTIfNode(SETNodeLabel label, ASTCondition condition,
046: List<Object> body) {
047: super (label, condition);
048: this .body = body;
049:
050: subBodies.add(body);
051: }
052:
053: /*
054: Nomair A. Naeem 21-FEB-05
055: Used by OrAggregatorTwo
056: */
057: public List<Object> getIfBody() {
058: return body;
059: }
060:
061: public Object clone() {
062: return new ASTIfNode(get_Label(), get_Condition(), body);
063: }
064:
065: /*
066: Nomair A. Naeem 19-FEB-2005
067: Added to support aggregation of conditions
068: */
069: public void replace(SETNodeLabel label, ASTCondition condition,
070: List<Object> body) {
071: this .body = body;
072: subBodies = new ArrayList<Object>();
073: subBodies.add(body);
074: set_Condition(condition);
075: set_Label(label);
076: }
077:
078: /*
079: Nomair A Naeem 20-FEB-2005
080: Added for UselessLabeledBlockRemover
081: */
082: public void replaceBody(List<Object> body) {
083: this .body = body;
084: subBodies = new ArrayList<Object>();
085: subBodies.add(body);
086: }
087:
088: public void toString(UnitPrinter up) {
089: label_toString(up);
090:
091: up.literal("if");
092: up.literal(" ");
093: up.literal("(");
094: condition.toString(up);
095: up.literal(")");
096: up.newline();
097:
098: up.literal("{");
099: up.newline();
100:
101: up.incIndent();
102: body_toString(up, body);
103: up.decIndent();
104:
105: up.literal("}");
106: up.newline();
107: }
108:
109: public String toString() {
110: StringBuffer b = new StringBuffer();
111:
112: b.append(label_toString());
113:
114: b.append("if (");
115: b.append(get_Condition().toString());
116: b.append(")");
117: b.append(NEWLINE);
118:
119: b.append("{");
120: b.append(NEWLINE);
121:
122: b.append(body_toString(body));
123:
124: b.append("}");
125: b.append(NEWLINE);
126:
127: return b.toString();
128: }
129:
130: /*
131: Nomair A. Naeem, 7-FEB-05
132: Part of Visitor Design Implementation for AST
133: See: soot.dava.toolkits.base.AST.analysis For details
134: */
135: public void apply(Analysis a) {
136: a.caseASTIfNode(this);
137: }
138: }
|