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 ASTWhileNode extends ASTControlFlowNode {
030: private List<Object> body;
031:
032: public ASTWhileNode(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 ASTWhileNode(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 ASTWhileNode(get_Label(), get_Condition(), body);
065: }
066:
067: public void toString(UnitPrinter up) {
068: label_toString(up);
069:
070: up.literal("while");
071: up.literal(" ");
072: up.literal("(");
073: condition.toString(up);
074: up.literal(")");
075: up.newline();
076:
077: up.literal("{");
078: up.newline();
079:
080: up.incIndent();
081: body_toString(up, body);
082: up.decIndent();
083:
084: up.literal("}");
085: up.newline();
086: }
087:
088: public String toString() {
089: StringBuffer b = new StringBuffer();
090:
091: b.append(label_toString());
092:
093: b.append("while (");
094: b.append(get_Condition().toString());
095: b.append(")");
096: b.append(NEWLINE);
097:
098: b.append("{");
099: b.append(NEWLINE);
100:
101: b.append(body_toString(body));
102:
103: b.append("}");
104: b.append(NEWLINE);
105:
106: return b.toString();
107: }
108:
109: /*
110: Nomair A. Naeem, 7-FEB-05
111: Part of Visitor Design Implementation for AST
112: See: soot.dava.toolkits.base.AST.analysis For details
113: */
114: public void apply(Analysis a) {
115: a.caseASTWhileNode(this);
116: }
117: }
|