Beispiel #1
0
    @Override
    public Type typeOf(Environment __eval) {
      String name;
      Type type = null;
      Environment theEnv = __eval.getHeap().getEnvironmentForName(this.getName(), __eval);

      name = org.rascalmpl.interpreter.utils.Names.typeName(this.getName());

      if (theEnv != null) {
        type = theEnv.lookupAlias(name);

        if (type == null) {
          type = theEnv.lookupAbstractDataType(name);
        }
      }

      if (type != null) {
        Map<Type, Type> bindings = new HashMap<Type, Type>();
        Type[] params = new Type[this.getParameters().size()];

        int i = 0;
        for (org.rascalmpl.ast.Type param : this.getParameters()) {
          params[i++] = param.typeOf(__eval);
        }

        // __eval has side-effects that we might need?
        type.getTypeParameters().match(TF.tupleType(params), bindings);

        // Instantiate first using the type actually given in the parameter,
        // e.g., for T[str], with data T[&U] = ..., instantate the binding
        // of &U = str, and then instantate using bindings from the current
        // environment (generally meaning we are inside a function with
        // type parameters, and those parameters are now bound to real types)
        return type.instantiate(bindings).instantiate(__eval.getTypeBindings());
      }

      throw new UndeclaredTypeError(name, this);
    }