示例#1
0
  private void propagate(
      TypePattern pattern,
      HashMap<String, SemanticType> environment,
      HashSet<String> generics,
      WyalFile.Context context) {
    SemanticType type = builder.convert(pattern.toSyntacticType(), generics, context);

    if (pattern instanceof TypePattern.Tuple) {
      TypePattern.Tuple tt = (TypePattern.Tuple) pattern;
      for (TypePattern p : tt.patterns) {
        propagate(p, environment, generics, context);
      }
    }
    if (pattern.var != null) {
      environment.put(pattern.var, type);
    }
    if (pattern.source != null) {
      SemanticType ct = propagate(pattern.source, environment, generics, context);
      checkIsSubtype(SemanticType.SetAny, ct, pattern);
      // TODO: need effective set here
      SemanticType.Set set_t = (SemanticType.Set) ct;
      checkIsSubtype(type, set_t.element(), pattern);
    }
    if (pattern.constraint != null) {
      SemanticType ct = propagate(pattern.constraint, environment, generics, context);
      checkIsSubtype(SemanticType.Bool, ct, pattern);
    }

    pattern.attributes().add(new TypeAttribute(type));
  }
示例#2
0
  private void addNamedVariables(
      TypePattern pattern,
      HashMap<String, SemanticType> environment,
      HashSet<String> generics,
      WyalFile.Context context) {

    SemanticType type = builder.convert(pattern.toSyntacticType(), generics, context);

    if (pattern.var != null) {
      if (environment.containsKey(pattern.var)) {
        internalFailure("duplicate variable name encountered", filename, pattern);
      }
      environment.put(pattern.var, type);
    }

    if (pattern instanceof TypePattern.Tuple) {
      TypePattern.Tuple st = (TypePattern.Tuple) pattern;
      for (TypePattern t : st.patterns) {
        addNamedVariables(t, environment, generics, context);
      }
    }

    pattern.attributes().add(new TypeAttribute(type));
  }