KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > internal > AST > ASTNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
3  * Copyright (C) 2005 Nomair A. Naeem
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 package soot.dava.internal.AST;
22
23 import soot.*;
24 import java.util.*;
25 import soot.dava.toolkits.base.AST.*;
26 import soot.dava.toolkits.base.AST.analysis.*;
27
28 public abstract class ASTNode extends AbstractUnit
29 {
30     public static final String JavaDoc
31     TAB = " ",
32     NEWLINE = "\n";
33
34     protected List subBodies;
35
36     public ASTNode()
37     {
38     subBodies = new ArrayList();
39     }
40
41     public abstract void toString( UnitPrinter up );
42  
43     protected void body_toString( UnitPrinter up, List body )
44     {
45     Iterator it = body.iterator();
46     while (it.hasNext()) {
47         ((ASTNode) it.next()).toString( up );
48
49         if (it.hasNext())
50         up.newline();
51     }
52     }
53
54     protected String JavaDoc body_toString(List body)
55     {
56     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
57
58     Iterator it = body.iterator();
59     while (it.hasNext()) {
60         b.append( ((ASTNode) it.next()).toString());
61
62         if (it.hasNext())
63         b.append( NEWLINE);
64     }
65
66     return b.toString();
67     }
68
69     public List get_SubBodies()
70     {
71     return subBodies;
72     }
73
74
75     public abstract void perform_Analysis( ASTAnalysis a);
76
77     protected void perform_AnalysisOnSubBodies( ASTAnalysis a)
78     {
79     Iterator sbit = subBodies.iterator();
80     while (sbit.hasNext()) {
81         Object JavaDoc subBody = sbit.next();
82         Iterator it = null;
83
84         if (this instanceof ASTTryNode)
85         it = ((List) ((ASTTryNode.container) subBody).o).iterator();
86         else
87         it = ((List) subBody).iterator();
88         
89         while (it.hasNext())
90         ((ASTNode) it.next()).perform_Analysis( a);
91     }
92     
93     a.analyseASTNode( this);
94     }
95
96     public boolean fallsThrough()
97     {
98         return false;
99     }
100
101     public boolean branches()
102     {
103         return false;
104     }
105
106     /*
107       Nomair A. Naeem, 7-FEB-05
108       Part of Visitor Design Implementation for AST
109       See: soot.dava.toolkits.base.AST.analysis For details
110     */

111     public void apply(Analysis a){
112     throw new RuntimeException JavaDoc("Analysis invoked apply method on ASTNode");
113     }
114     
115 }
116
Popular Tags