예제 #1
0
  @Override
  public Type getType(Environment env, HashMap<String, IVarPattern> patternVars) {
    if (patternSize == 0) {
      return tf.listType(tf.voidType());
    }

    Type elemType = tf.voidType();
    for (int i = 0; i < patternSize; i += delta) {
      IMatchingResult child = patternChildren.get(i);
      Type childType = child.getType(env, patternVars);
      patternVars = merge(patternVars, patternChildren.get(i).getVariables());
      boolean isMultiVar =
          child instanceof MultiVariablePattern || child instanceof TypedMultiVariablePattern;

      if (childType.isList() && isMultiVar) {
        elemType = elemType.lub(childType.getElementType());
      } else {
        elemType = elemType.lub(childType);
      }
    }
    if (debug) {
      System.err.println("ListPattern.getType: " + tf.listType(elemType));
    }
    return tf.listType(elemType);
  }
예제 #2
0
  public ISet intersect(ISet other) {
    ShareableValuesHashSet commonData = new ShareableValuesHashSet();
    Iterator<IValue> setIterator;

    ISet theOtherSet;

    if (other.size() <= size()) {
      setIterator = other.iterator();
      theOtherSet = this;
    } else {
      setIterator = iterator();
      theOtherSet = other;
    }

    Type newElementType = TypeFactory.getInstance().voidType();
    while (setIterator.hasNext()) {
      IValue value = setIterator.next();
      if (theOtherSet.contains(value)) {
        newElementType = newElementType.lub(value.getType());
        commonData.add(value);
      }
    }

    return new SetWriter(newElementType, commonData).done();
  }
예제 #3
0
  public ISet insert(IValue value) {
    if (!contains(value)) {
      ShareableValuesHashSet newData = new ShareableValuesHashSet(data);
      newData.add(value);

      Type type = elementType.lub(value.getType());
      return new SetWriter(type, newData).done();
    } else {
      return this;
    }
  }
예제 #4
0
  public ISet subtract(ISet other) {
    ShareableValuesHashSet newData = new ShareableValuesHashSet(data);

    Iterator<IValue> setIterator = other.iterator();
    while (setIterator.hasNext()) {
      newData.remove(setIterator.next());
    }
    Type newElementType = TypeFactory.getInstance().voidType();
    for (IValue el : newData) newElementType = newElementType.lub(el.getType());
    return new SetWriter(newElementType, newData).done();
  }
예제 #5
0
  public ISet delete(IValue value) {
    if (contains(value)) {
      ShareableValuesHashSet newData = new ShareableValuesHashSet(data);
      newData.remove(value);

      Type newElementType = TypeFactory.getInstance().voidType();
      for (IValue el : newData) {
        newElementType = newElementType.lub(el.getType());
      }
      return new SetWriter(newElementType, newData).done();
    } else {
      return this;
    }
  }
예제 #6
0
  public ISet union(ISet other) {
    ShareableValuesHashSet newData;
    Iterator<IValue> setIterator;

    Set otherSet = (Set) other;

    if (otherSet.size() <= size()) {
      newData = new ShareableValuesHashSet(data);
      setIterator = otherSet.iterator();
    } else {
      newData = new ShareableValuesHashSet(otherSet.data);
      setIterator = iterator();
    }

    while (setIterator.hasNext()) {
      newData.add(setIterator.next());
    }

    Type newElementType = elementType.lub(otherSet.elementType);
    return new SetWriter(newElementType, newData).done();
  }