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

soot.jimple.toolkits.typing.fast.AugHierarchy Maven / Gradle / Ivy

package soot.jimple.toolkits.typing.fast;

/*-
 * #%L
 * Soot - a J*va Optimization Framework
 * %%
 * Copyright (C) 2008 Ben Bellamy
 *
 * All rights reserved.
 * %%
 * 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.Collection;
import java.util.Collections;

import soot.BooleanType;
import soot.ByteType;
import soot.CharType;
import soot.IntType;
import soot.IntegerType;
import soot.ShortType;
import soot.Type;

/**
 * @author Ben Bellamy
 */
public class AugHierarchy implements IHierarchy {
  public Collection lcas(Type a, Type b) {
    return lcas_(a, b);
  }

  public static Collection lcas_(Type a, Type b) {
    if (TypeResolver.typesEqual(a, b)) {
      return Collections.singletonList(a);
    } else if (a instanceof BottomType) {
      return Collections.singletonList(b);
    } else if (b instanceof BottomType) {
      return Collections.singletonList(a);
    } else if (a instanceof IntegerType && b instanceof IntegerType) {
      if (a instanceof Integer1Type) {
        return Collections.singletonList(b);
      } else if (b instanceof Integer1Type) {
        return Collections.singletonList(a);
      } else if (a instanceof BooleanType || b instanceof BooleanType) {
        return Collections.emptyList();
      } else if ((a instanceof ByteType && b instanceof Integer32767Type)
          || (b instanceof ByteType && a instanceof Integer32767Type)) {
        return Collections.singletonList(ShortType.v());
      } else if ((a instanceof CharType && (b instanceof ShortType || b instanceof ByteType))
          || (b instanceof CharType && (a instanceof ShortType || a instanceof ByteType))) {
        return Collections.singletonList(IntType.v());
      } else if (ancestor_(a, b)) {
        return Collections.singletonList(a);
      } else {
        return Collections.singletonList(b);
      }
    } else if (a instanceof IntegerType || b instanceof IntegerType) {
      return Collections.emptyList();
    } else {
      return BytecodeHierarchy.lcas_(a, b);
    }
  }

  public boolean ancestor(Type ancestor, Type child) {
    return ancestor_(ancestor, child);
  }

  public static boolean ancestor_(Type ancestor, Type child) {
    if (TypeResolver.typesEqual(ancestor, child)) {
      return true;
    } else if (ancestor instanceof Integer1Type) {
      if (child instanceof BottomType) {
        return true;
      } else {
        return false;
      }
    } else if (ancestor instanceof BooleanType) {
      if (child instanceof BottomType || child instanceof Integer1Type) {
        return true;
      } else {
        return false;
      }
    } else if (ancestor instanceof Integer127Type) {
      if (child instanceof BottomType || child instanceof Integer1Type) {
        return true;
      } else {
        return false;
      }
    } else if (ancestor instanceof ByteType || ancestor instanceof Integer32767Type) {
      if (child instanceof BottomType || child instanceof Integer1Type || child instanceof Integer127Type) {
        return true;
      } else {
        return false;
      }
    } else if (ancestor instanceof CharType) {
      if (child instanceof BottomType || child instanceof Integer1Type || child instanceof Integer127Type
          || child instanceof Integer32767Type) {
        return true;
      } else {
        return false;
      }
    } else if (ancestor instanceof ShortType) {
      if (child instanceof BottomType || child instanceof Integer1Type || child instanceof Integer127Type
          || child instanceof Integer32767Type || child instanceof ByteType) {
        return true;
      } else {
        return false;
      }
    } else if (ancestor instanceof IntType) {
      if (child instanceof BottomType || child instanceof Integer1Type || child instanceof Integer127Type
          || child instanceof Integer32767Type || child instanceof ByteType || child instanceof CharType
          || child instanceof ShortType) {
        return true;
      } else {
        return false;
      }
    } else if (child instanceof IntegerType) {
      return false;
    } else {
      return BytecodeHierarchy.ancestor_(ancestor, child);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy