KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > FlowList


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: FlowList.java,v 1.6 2004/02/16 22:24:29 minchau Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import com.sun.org.apache.bcel.internal.generic.BranchHandle;
26 import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
27 import com.sun.org.apache.bcel.internal.generic.InstructionList;
28
29 /**
30  * @author Jacek Ambroziak
31  * @author Santiago Pericas-Geertsen
32  */

33 public final class FlowList {
34     private Vector JavaDoc _elements;
35
36     public FlowList() {
37     _elements = null;
38     }
39
40     public FlowList(InstructionHandle bh) {
41     _elements = new Vector JavaDoc();
42     _elements.addElement(bh);
43     }
44
45     public FlowList(FlowList list) {
46     _elements = list._elements;
47     }
48
49     public FlowList add(InstructionHandle bh) {
50     if (_elements == null) {
51         _elements = new Vector JavaDoc();
52     }
53     _elements.addElement(bh);
54     return this;
55     }
56
57     public FlowList append(FlowList right) {
58     if (_elements == null) {
59         _elements = right._elements;
60     }
61     else {
62         final Vector JavaDoc temp = right._elements;
63         if (temp != null) {
64         final int n = temp.size();
65         for (int i = 0; i < n; i++) {
66             _elements.addElement(temp.elementAt(i));
67         }
68         }
69     }
70     return this;
71     }
72
73     /**
74      * Back patch a flow list. All instruction handles must be branch handles.
75      */

76     public void backPatch(InstructionHandle target) {
77     if (_elements != null) {
78         final int n = _elements.size();
79         for (int i = 0; i < n; i++) {
80         BranchHandle bh = (BranchHandle)_elements.elementAt(i);
81         bh.setTarget(target);
82         }
83         _elements.clear(); // avoid backpatching more than once
84
}
85     }
86
87     /**
88      * Redirect the handles from oldList to newList. "This" flow list
89      * is assumed to be relative to oldList.
90      */

91     public FlowList copyAndRedirect(InstructionList oldList,
92     InstructionList newList)
93     {
94     final FlowList result = new FlowList();
95     if (_elements == null) {
96         return result;
97     }
98
99     final int n = _elements.size();
100     final Iterator JavaDoc oldIter = oldList.iterator();
101     final Iterator JavaDoc newIter = newList.iterator();
102     
103     while (oldIter.hasNext()) {
104         final InstructionHandle oldIh = (InstructionHandle) oldIter.next();
105         final InstructionHandle newIh = (InstructionHandle) newIter.next();
106
107         for (int i = 0; i < n; i++) {
108         if (_elements.elementAt(i) == oldIh) {
109             result.add(newIh);
110         }
111         }
112     }
113     return result;
114     }
115 }
116
Popular Tags