01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2000 Patrice Pominville and Feng Qian
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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:
28: import soot.*;
29: import soot.baf.BafBody;
30: import java.util.*;
31:
32: /** Interface to aggregate tags of units. */
33:
34: public abstract class TagAggregator extends BodyTransformer {
35: protected LinkedList<Tag> tags = new LinkedList<Tag>();
36: protected LinkedList<Unit> units = new LinkedList<Unit>();
37:
38: /** Decide whether this tag should be aggregated by this aggregator. */
39: public abstract boolean wantTag(Tag t);
40:
41: /** Aggregate the given tag assigned to the given unit */
42: public abstract void considerTag(Tag t, Unit u);
43:
44: /** Return name of the resulting aggregated tag. */
45: public abstract String aggregatedName();
46:
47: protected void internalTransform(Body b, String phaseName,
48: Map options) {
49: BafBody body = (BafBody) b;
50:
51: /* clear the aggregator first. */
52: tags.clear();
53: units.clear();
54:
55: /* aggregate all tags */
56: for (Iterator unitIt = body.getUnits().iterator(); unitIt
57: .hasNext();) {
58: final Unit unit = (Unit) unitIt.next();
59: for (Iterator tagIt = unit.getTags().iterator(); tagIt
60: .hasNext();) {
61: final Tag tag = (Tag) tagIt.next();
62: if (wantTag(tag))
63: considerTag(tag, unit);
64: }
65: }
66:
67: if (units.size() > 0) {
68: b.addTag(new CodeAttribute(aggregatedName(),
69: new LinkedList<Unit>(units), new LinkedList<Tag>(
70: tags)));
71: }
72: fini();
73: }
74:
75: /** Called after all tags for a method have been aggregated. */
76: public void fini() {
77: }
78:
79: }
|