All Downloads are FREE. Search and download functionalities are using the official Maven repository.

soot.tagkit.TagAggregator Maven / Gradle / Ivy

package soot.tagkit;

/*-
 * #%L
 * Soot - a J*va Optimization Framework
 * %%
 * Copyright (C) 2000 Patrice Pominville and Feng Qian
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;

import soot.Body;
import soot.BodyTransformer;
import soot.Unit;
import soot.baf.BafBody;

/** Interface to aggregate tags of units. */

public abstract class TagAggregator extends BodyTransformer {
  /** Decide whether this tag should be aggregated by this aggregator. */
  public abstract boolean wantTag(Tag t);

  /** Aggregate the given tag assigned to the given unit */
  public abstract void considerTag(Tag t, Unit u, LinkedList tags, LinkedList units);

  /** Return name of the resulting aggregated tag. */
  public abstract String aggregatedName();

  protected void internalTransform(Body b, String phaseName, Map options) {
    BafBody body = (BafBody) b;

    LinkedList tags = new LinkedList();
    LinkedList units = new LinkedList();

    /* aggregate all tags */
    for (Iterator unitIt = body.getUnits().iterator(); unitIt.hasNext();) {
      final Unit unit = unitIt.next();
      for (Iterator tagIt = unit.getTags().iterator(); tagIt.hasNext();) {
        final Tag tag = tagIt.next();
        if (wantTag(tag)) {
          considerTag(tag, unit, tags, units);
        }
      }
    }

    if (units.size() > 0) {
      b.addTag(new CodeAttribute(aggregatedName(), new LinkedList(units), new LinkedList(tags)));
    }
    fini();
  }

  /** Called after all tags for a method have been aggregated. */
  public void fini() {
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy