KickJava   Java API By Example, From Geeks To Geeks.

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


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 ASTOrCondition extends ASTAggregatedCondition{
27     public ASTOrCondition(ASTCondition left, ASTCondition right){
28     super(left,right);
29     }
30     
31     public void apply(Analysis a){
32     a.caseASTOrCondition(this);
33     }
34
35     public String JavaDoc toString(){
36     if(left instanceof ASTUnaryBinaryCondition){
37         if(right instanceof ASTUnaryBinaryCondition){
38         if(not)
39             return "!(" + left.toString() + " || "+ right.toString()+")";
40         else
41             return left.toString() + " || "+ right.toString();
42         }
43         else{ //right is ASTAggregatedCondition
44
if(not)
45             return "!("+left.toString() + " || ("+right.toString() +" ))";
46         else
47             return left.toString() + " || ("+right.toString() +" )";
48         }
49         }
50     else{ //left is ASTAggregatedCondition
51
if(right instanceof ASTUnaryBinaryCondition){
52         if(not)
53             return "!(( "+ left.toString() + ") || "+ right.toString()+")";
54         else
55             return "( "+ left.toString() + ") || "+ right.toString();
56         }
57         else{ //right is ASTAggregatedCondition also
58
if(not)
59             return "!(( "+left.toString() + ") || ("+right.toString() +" ))";
60         else
61             return "( "+left.toString() + ") || ("+right.toString() +" )";
62         }
63     }
64     }
65
66     public void toString(UnitPrinter up){
67     if(up instanceof DavaUnitPrinter){
68         
69         if(not){
70         //print !
71
((DavaUnitPrinter)up).addNot();
72         //print LeftParen
73
((DavaUnitPrinter)up).addLeftParen();
74         }
75         if(left instanceof ASTUnaryBinaryCondition){
76         if(right instanceof ASTUnaryBinaryCondition){
77             
78             left.toString(up);
79             
80             ((DavaUnitPrinter)up).addAggregatedOr();
81             
82             right.toString(up);
83         }
84         else{ //right is ASTAggregatedCondition
85

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

108             ((DavaUnitPrinter)up).addLeftParen();
109             left.toString(up);
110             ((DavaUnitPrinter)up).addRightParen();
111             
112             ((DavaUnitPrinter)up).addAggregatedOr();
113             
114             ((DavaUnitPrinter)up).addLeftParen();
115             right.toString(up);
116             ((DavaUnitPrinter)up).addRightParen();
117         }
118         }
119         if(not)
120         ((DavaUnitPrinter)up).addRightParen();
121     }
122     else
123         throw new RuntimeException JavaDoc();
124     }
125     
126 }
127
Popular Tags