Esempio n. 1
0
  // public boolean canAccept( List<ModifiedType> inputTypes, SubstitutionType substitutionType,
  // List<String> reasons )
  public boolean canAccept(
      SequenceType inputTypes, SubstitutionKind substitutionType, List<TypeCheckException> errors) {
    if (types.size() != inputTypes.size()) {
      BaseChecker.addError(
          errors,
          Error.INVALID_ASSIGNMENT,
          "Sequence type "
              + inputTypes
              + " does not have the same number of elements as sequence type "
              + this);
      return false;
    }

    for (int i = 0; i < types.size(); i++) {
      if (types.get(i) != null) {
        ModifiedType left = types.get(i);
        ModifiedType right = inputTypes.get(i);

        if (!BaseChecker.checkAssignment(
            left, right, AssignmentType.EQUAL, substitutionType, errors)) return false;
      }
    }

    return true;
  }
Esempio n. 2
0
  @Override
  public boolean isSubtype(Type t) {
    if (equals(t)) return true;

    if (t instanceof SequenceType) {
      SequenceType inputTypes = (SequenceType) t;

      if (types.size() != inputTypes.size()) return false;

      for (int i = 0; i < types.size(); i++) {
        if (types.get(i) != null) {
          Type inputType = inputTypes.get(i).getType();
          Modifiers inputModifiers = inputTypes.get(i).getModifiers();
          Type type = types.get(i).getType();
          Modifiers modifiers = types.get(i).getModifiers();

          if (!type.isSubtype(inputType)) return false;

          // if either type is immutable, it will work out no matter what
          // if both are mutable, their modifiers had better both be immutable or both mutable
          if (!type.getModifiers().isImmutable() && !inputType.getModifiers().isImmutable()) {
            // inputModifiers = modifiers

            // if this is immutable, storage reference must be readonly or immutable (temporary
            // readonly isn't good enough)
            if (modifiers.isImmutable()
                && !inputModifiers.isImmutable()
                && !inputModifiers.isReadonly()) return false;

            // you can't put a readonly thing into a mutable reference
            // but you can put a mutable thing into a readonly reference (but not an immutable one)
            if (modifiers.isReadonly() && !inputModifiers.isReadonly()) return false;

            if (inputModifiers.isImmutable() && !modifiers.isImmutable()) return false;
          }

          if (modifiers.isNullable() && !inputModifiers.isNullable()) return false;
        }
      }
      return true;
    } else return false;
  }
Esempio n. 3
0
  @Override
  public boolean equals(Type type) {
    if (type == Type.NULL) return true;

    if (type != null && type instanceof SequenceType) {
      SequenceType inputTypes = (SequenceType) type;

      if (types.size() != inputTypes.size()) return false;

      for (int i = 0; i < types.size(); i++)
        if (inputTypes.get(i) == null
            || types.get(i) == null
            || !inputTypes.get(i).getType().equals(getType(i))
            || !inputTypes.get(i).getModifiers().equals(get(i).getModifiers())) return false;

      return true;
    }

    return false;
  }