KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > tagkit > TagAggregator


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Patrice Pominville and Feng Qian
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 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot.tagkit;
27 import soot.*;
28 import soot.baf.BafBody;
29 import java.util.*;
30
31 /** Interface to aggregate tags of units. */
32
33 public abstract class TagAggregator extends BodyTransformer {
34     protected LinkedList tags = new LinkedList();
35     protected LinkedList units = new LinkedList();
36
37     /** Decide whether this tag should be aggregated by this aggregator. */
38     public abstract boolean wantTag( Tag t );
39     /** Aggregate the given tag assigned to the given unit */
40     public abstract void considerTag( Tag t, Unit u );
41
42     /** Return name of the resulting aggregated tag. */
43     public abstract String JavaDoc aggregatedName();
44
45     protected void internalTransform(Body b, String JavaDoc phaseName, Map options)
46     {
47         BafBody body = (BafBody) b;
48        
49     /* clear the aggregator first. */
50         tags.clear();
51     units.clear();
52
53     /* aggregate all tags */
54         for( Iterator unitIt = body.getUnits().iterator(); unitIt.hasNext(); ) {
55             final Unit unit = (Unit) unitIt.next();
56             for( Iterator tagIt = unit.getTags().iterator(); tagIt.hasNext(); ) {
57                 final Tag tag = (Tag) tagIt.next();
58                 if( wantTag( tag ) ) considerTag( tag, unit );
59         }
60         }
61
62     if(units.size() > 0) {
63             b.addTag( new CodeAttribute(aggregatedName(),
64                  new LinkedList(units), new LinkedList(tags)) );
65         }
66         fini();
67     }
68
69     /** Called after all tags for a method have been aggregated. */
70     public void fini() {}
71
72
73 }
74
Popular Tags