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

soot.jimple.IntConstant Maven / Gradle / Ivy

package soot.jimple;

/*-
 * #%L
 * Soot - a J*va Optimization Framework
 * %%
 * Copyright (C) 1997 - 1999 Raja Vallee-Rai
 * %%
 * 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 soot.IntType;
import soot.Type;
import soot.util.Switch;

public class IntConstant extends ArithmeticConstant {
  public final int value;

  protected IntConstant(int value) {
    this.value = value;
  }

  public static IntConstant v(int value) {
    return new IntConstant(value);
  }

  public boolean equals(Object c) {
    return c instanceof IntConstant && ((IntConstant) c).value == value;
  }

  public int hashCode() {
    return value;
  }

  // PTC 1999/06/28
  public NumericConstant add(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value + ((IntConstant) c).value);
  }

  public NumericConstant subtract(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value - ((IntConstant) c).value);
  }

  public NumericConstant multiply(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value * ((IntConstant) c).value);
  }

  public NumericConstant divide(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value / ((IntConstant) c).value);
  }

  public NumericConstant remainder(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value % ((IntConstant) c).value);
  }

  public NumericConstant equalEqual(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v((this.value == ((IntConstant) c).value) ? 1 : 0);
  }

  public NumericConstant notEqual(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v((this.value != ((IntConstant) c).value) ? 1 : 0);
  }

  public NumericConstant lessThan(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v((this.value < ((IntConstant) c).value) ? 1 : 0);
  }

  public NumericConstant lessThanOrEqual(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v((this.value <= ((IntConstant) c).value) ? 1 : 0);
  }

  public NumericConstant greaterThan(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v((this.value > ((IntConstant) c).value) ? 1 : 0);
  }

  public NumericConstant greaterThanOrEqual(NumericConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v((this.value >= ((IntConstant) c).value) ? 1 : 0);
  }

  public NumericConstant negate() {
    return IntConstant.v(-(this.value));
  }

  public ArithmeticConstant and(ArithmeticConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value & ((IntConstant) c).value);
  }

  public ArithmeticConstant or(ArithmeticConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value | ((IntConstant) c).value);
  }

  public ArithmeticConstant xor(ArithmeticConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value ^ ((IntConstant) c).value);
  }

  public ArithmeticConstant shiftLeft(ArithmeticConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value << ((IntConstant) c).value);
  }

  public ArithmeticConstant shiftRight(ArithmeticConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value >> ((IntConstant) c).value);
  }

  public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c) {
    if (!(c instanceof IntConstant)) {
      throw new IllegalArgumentException("IntConstant expected");
    }
    return IntConstant.v(this.value >>> ((IntConstant) c).value);
  }

  public String toString() {
    return new Integer(value).toString();
  }

  public Type getType() {
    return IntType.v();
  }

  public void apply(Switch sw) {
    ((ConstantSwitch) sw).caseIntConstant(this);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy