KickJava   Java API By Example, From Geeks To Geeks.

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


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

19
20 package soot.dava.internal.AST;
21
22 import soot.*;
23 import soot.dava.*;
24 import soot.dava.toolkits.base.AST.analysis.*;
25
26 public class ASTAndCondition extends ASTAggregatedCondition{
27
28     public ASTAndCondition(ASTCondition left, ASTCondition right){
29     super(left,right);
30       }
31
32     public void apply(Analysis a){
33     a.caseASTAndCondition(this);
34     }
35
36     public String JavaDoc toString(){
37     if(left instanceof ASTUnaryBinaryCondition){
38        if(right instanceof ASTUnaryBinaryCondition){
39            if(not)
40            return "!("+ left.toString() + " && "+ right.toString()+")";
41            else
42            return left.toString() + " && "+ right.toString();
43        }
44        else{ //right is ASTAggregatedCondition
45
if(not)
46            return "!("+left.toString() + " && ("+right.toString() +" ))";
47            else
48            return left.toString() + " && ("+right.toString() +" )";
49            }
50         }
51     else{ //left is ASTAggregatedCondition
52
if(right instanceof ASTUnaryBinaryCondition){
53            if(not)
54            return "!(( "+left.toString() + ") && "+ right.toString()+")";
55            else
56            return "( "+left.toString() + ") && "+ right.toString();
57        }
58        else{ //right is ASTAggregatedCondition also
59
if(not)
60            return "!(( "+left.toString() + ") && ("+right.toString() +" ))";
61            else
62            return "( "+left.toString() + ") && ("+right.toString() +" )";
63            }
64     }
65     }
66
67     public void toString(UnitPrinter up){
68     if(up instanceof DavaUnitPrinter){
69         
70         if(not){
71         //print !
72
((DavaUnitPrinter)up).addNot();
73         //print left paren
74
((DavaUnitPrinter)up).addLeftParen();
75         }
76
77         if(left instanceof ASTUnaryBinaryCondition){
78         if(right instanceof ASTUnaryBinaryCondition){
79             
80             left.toString(up);
81             
82             ((DavaUnitPrinter)up).addAggregatedAnd();
83             
84             right.toString(up);
85         }
86         else{ //right is ASTAggregatedCondition
87

88             left.toString(up);
89             
90             ((DavaUnitPrinter)up).addAggregatedAnd();
91             
92             ((DavaUnitPrinter)up).addLeftParen();
93             right.toString(up);
94             ((DavaUnitPrinter)up).addRightParen();
95         }
96         }
97         else{ //left is ASTAggregatedCondition
98
if(right instanceof ASTUnaryBinaryCondition){
99             
100             ((DavaUnitPrinter)up).addLeftParen();
101             left.toString(up);
102             ((DavaUnitPrinter)up).addRightParen();
103             
104             ((DavaUnitPrinter)up).addAggregatedAnd();
105             
106             right.toString(up);
107         }
108         else{ //right is ASTAggregatedCondition also
109

110             ((DavaUnitPrinter)up).addLeftParen();
111             left.toString(up);
112             ((DavaUnitPrinter)up).addRightParen();
113             
114             ((DavaUnitPrinter)up).addAggregatedAnd();
115             
116             ((DavaUnitPrinter)up).addLeftParen();
117             right.toString(up);
118             ((DavaUnitPrinter)up).addRightParen();
119         }
120         }
121
122         if(not){
123         //print right paren
124
((DavaUnitPrinter)up).addRightParen();
125         }
126     }
127     else
128         throw new RuntimeException JavaDoc();
129     }
130     
131 }
132
Popular Tags