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 java.util.*;
024: import soot.*;
025: import soot.jimple.*;
026: import soot.dava.internal.SET.*;
027: import soot.dava.toolkits.base.AST.analysis.*;
028:
029: public class ASTDoWhileNode extends ASTControlFlowNode {
030: private List<Object> body;
031:
032: public ASTDoWhileNode(SETNodeLabel label, ConditionExpr ce,
033: List<Object> body) {
034: super (label, ce);
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 ASTDoWhileNode(SETNodeLabel label, ASTCondition ce,
046: List<Object> body) {
047: super (label, ce);
048: this .body = body;
049:
050: subBodies.add(body);
051: }
052:
053: /*
054: Nomair A Naeem 20-FEB-2005
055: Added for UselessLabeledBlockRemover
056: */
057: public void replaceBody(List<Object> body) {
058: this .body = body;
059: subBodies = new ArrayList<Object>();
060: subBodies.add(body);
061: }
062:
063: public Object clone() {
064: return new ASTDoWhileNode(get_Label(), get_Condition(), body);
065: }
066:
067: public void toString(UnitPrinter up) {
068: label_toString(up);
069:
070: up.literal("do");
071: up.newline();
072:
073: up.literal("{");
074: up.newline();
075:
076: up.incIndent();
077: body_toString(up, body);
078: up.decIndent();
079:
080: up.literal("}");
081: up.newline();
082:
083: up.literal("while");
084: up.literal(" ");
085: up.literal("(");
086: condition.toString(up);
087: up.literal(")");
088: up.literal(";");
089: up.newline();
090: }
091:
092: public String toString() {
093: StringBuffer b = new StringBuffer();
094:
095: b.append(label_toString());
096:
097: b.append("do");
098: b.append(NEWLINE);
099:
100: b.append("{");
101: b.append(NEWLINE);
102:
103: b.append(body_toString(body));
104:
105: b.append("}");
106: b.append(NEWLINE);
107:
108: b.append("while (");
109: b.append(get_Condition().toString());
110: b.append(");");
111: b.append(NEWLINE);
112:
113: return b.toString();
114: }
115:
116: /*
117: Nomair A. Naeem, 7-FEB-05
118: Part of Visitor Design Implementation for AST
119: See: soot.dava.toolkits.base.AST.analysis For details
120: */
121: public void apply(Analysis a) {
122: a.caseASTDoWhileNode(this);
123: }
124: }
|