001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jerome Miecznikowski
003: * Copyright (C) 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.dava.toolkits.base.AST.*;
026: import soot.dava.toolkits.base.AST.analysis.*;
027:
028: public abstract class ASTNode extends AbstractUnit {
029: public static final String TAB = " ", NEWLINE = "\n";
030:
031: protected List<Object> subBodies;
032:
033: public ASTNode() {
034: subBodies = new ArrayList<Object>();
035: }
036:
037: public abstract void toString(UnitPrinter up);
038:
039: protected void body_toString(UnitPrinter up, List<Object> body) {
040: Iterator<Object> it = body.iterator();
041: while (it.hasNext()) {
042: ((ASTNode) it.next()).toString(up);
043:
044: if (it.hasNext())
045: up.newline();
046: }
047: }
048:
049: protected String body_toString(List<Object> body) {
050: StringBuffer b = new StringBuffer();
051:
052: Iterator<Object> it = body.iterator();
053: while (it.hasNext()) {
054: b.append(((ASTNode) it.next()).toString());
055:
056: if (it.hasNext())
057: b.append(NEWLINE);
058: }
059:
060: return b.toString();
061: }
062:
063: public List<Object> get_SubBodies() {
064: return subBodies;
065: }
066:
067: public abstract void perform_Analysis(ASTAnalysis a);
068:
069: protected void perform_AnalysisOnSubBodies(ASTAnalysis a) {
070: Iterator<Object> sbit = subBodies.iterator();
071: while (sbit.hasNext()) {
072: Object subBody = sbit.next();
073: Iterator it = null;
074:
075: if (this instanceof ASTTryNode)
076: it = ((List) ((ASTTryNode.container) subBody).o)
077: .iterator();
078: else
079: it = ((List) subBody).iterator();
080:
081: while (it.hasNext())
082: ((ASTNode) it.next()).perform_Analysis(a);
083: }
084:
085: a.analyseASTNode(this );
086: }
087:
088: public boolean fallsThrough() {
089: return false;
090: }
091:
092: public boolean branches() {
093: return false;
094: }
095:
096: /*
097: Nomair A. Naeem, 7-FEB-05
098: Part of Visitor Design Implementation for AST
099: See: soot.dava.toolkits.base.AST.analysis For details
100: */
101: public void apply(Analysis a) {
102: throw new RuntimeException(
103: "Analysis invoked apply method on ASTNode");
104: }
105:
106: }
|