Package org.eclipse.imp.pdb.facts.type

Examples of org.eclipse.imp.pdb.facts.type.Type


    Environment env = (Environment) environment;
   
    Result<IValue> var = env.getVariable("amb");
   
    if (var != null && var instanceof ICallableValue) {
      Type type = RascalTypeFactory.getInstance().nonTerminalType(ambCluster);
      ICallableValue func = (ICallableValue) var;
      try {
        Result<IValue> result = func.call(
            new Type[] {TF.setType(type)}, new IValue[] {alts}, null
        );
View Full Code Here


  public static final String TRIES = "tries";
  public static final String MAXDEPTH = "maxDepth";

  public static Type reifyType(IValue type) {
    Type reified = type.getType();
    if (!(reified instanceof ReifiedType)) {
      throw RuntimeExceptionFactory.illegalArgument(type, null, null,
          "A reified type is required instead of " + reified);
    }
    return reified.getTypeParameters().getFieldType(0);
  }
View Full Code Here

  }

  public IValue arbitrary(IValue type, IInteger depthLimit, IEvaluatorContext eval) {
    try {
      TypeParameterVisitor tpvisit = new TypeParameterVisitor();
      Type requestedType = Cobra.reifyType(type);
      HashMap<Type, Type> tpbindings = tpvisit.bindTypeParameters(requestedType);
      IValue result = quickcheck.arbitrary(requestedType,
          depthLimit.intValue(), eval.getCurrentEnvt().getRoot(),
          eval.getValueFactory(), tpbindings);
      return result;
View Full Code Here

        if (timer.hasExpired()) {
          throw RuntimeExceptionFactory.timeout(null, null);
        }
       
        if (expected != null) {
          Type typ = tr.valueToType((IConstructor) expected);
          if (!result.getType().isSubtypeOf(typ)) {
            throw new UnexpectedType(typ, result.getType(), ctx.getCurrentAST());
          }
        }
        return result;
View Full Code Here

   * Read relations from an AUT file. An AUT file contains ternary relations
   * in the following format: "(" <int> "," <string> ","<int>")". readAUT
   * takes an AUT file nameAUTFile and generates a rel[int, str, int]
   */
  public IValue readAUT(IString nameAUTFile){
    Type strType = types.stringType();
    Type intType = types.integerType();
    Type tupleType = types.tupleType(intType, strType, intType);
    java.lang.String fileName = nameAUTFile.getValue();
    ISetWriter rw = values.relationWriter(tupleType);
    BufferedReader bufRead = null;
    try{
      FileReader input = new FileReader(fileName);
View Full Code Here

    return typeParameters;
  }

  @Override
  public IValue visitParameter(Type parameterType) {
    Type type = typeParameters.get(parameterType);
    if(type == null){
      Type bound = parameterType.getBound();
      while (bound.isOpen()){
        bound = typeParameters.get(bound.getName());
      }
     
      do {
        type = randomType.getType(5);
      } while (bound != null && !type.isSubtypeOf(bound));
View Full Code Here

    return new DynamicGenerator(eval, getReturnType(), env, newGens);
  }

  @Override
  public Result<IValue> call(Type[] actualTypes, IValue[] actuals, Map<String, IValue> keyArgValues) {
    Type returnType = getReturnType();
    Type instantiatedReturnType = returnType.instantiate(ctx
        .getCurrentEnvt().getTypeBindings());

    IInteger maxDepth = (IInteger) actuals[0];

    RandomValueTypeVisitor v = new RandomValueTypeVisitor(
        getValueFactory(), (ModuleEnvironment) getEnv().getRoot(),
        maxDepth.intValue(), generators, ctx.getCurrentEnvt().getTypeBindings());

    IValue returnVal = instantiatedReturnType.accept(v);

    return makeResult(instantiatedReturnType, returnVal, eval);

  }
View Full Code Here

  }
 
  public IConstructor convertMapToGrammar(IMap definition) {
    TypeFactory TF = TypeFactory.getInstance();
    TypeStore TS = new TypeStore();
    Type Grammar = TF.abstractDataType(TS, "Grammar");
    Type Symbol = TF.abstractDataType(TS, "Symbol");
    Type Production = TF.abstractDataType(TS, "Production");
    Type grammar = TF.constructor(TS, Grammar, "grammar", TF.setType(Symbol), "starts", TF.mapType(Symbol, Production), "rules");

    return vf.constructor(grammar, vf.set(), definition);
  }
View Full Code Here

  private boolean generatorExists(Type t) {
    return generators.containsKey(t);
  }

  public IValue getGenerator(IValue t, IEvaluatorContext eval) {
    Type reified = Cobra.reifyType(t);
    if (generatorExists(reified)) {
      return generators.get(reified);
    }

    return new DynamicGenerator(eval.getEvaluator(), reified,
View Full Code Here

    String fname = function.getName();
 
    Environment declEnv = function.getEnv();
    IValueFactory vf = function.getEval().getValueFactory();
    Type formals = function.getFormals();
    String expected = null;
   
    if(function.hasTag(EXPECT_TAG)){
      expected = ((IString) function.getTag(EXPECT_TAG)).getValue();
    }
   

    Type[] types = new Type[formals.getArity()];
    IValue[] values = new IValue[formals.getArity()];

    for (int n = 0; n < formals.getArity(); n++) {
      types[n] = formals.getFieldType(n);
    }

    if (formals.getArity() == 0) {
      tries = 1;
    }

    TypeParameterVisitor tpvisit = new TypeParameterVisitor();
   
    for (int i = 0; i < tries; i++) {
      values = new IValue[formals.getArity()];

      HashMap<Type, Type> tpbindings = tpvisit.bindTypeParameters(formals);
      for (int n = 0; n < formals.getArity(); n++) {
        values[n] = arbitrary(types[n], maxDepth, declEnv.getRoot(), vf, tpbindings);
      }
      boolean expectedThrown = false;
      try {
        Type[] actualTypes = new Type[formals.getArity()];
        for(int j = 0; j < types.length; j ++) {
          actualTypes[j] = types[j].instantiate(tpbindings);
        }
        IValue result = function.call(actualTypes, values, null).getValue();
        function.getEval().getStdOut().flush();
        if (!((IBool) result).getValue()) {
          reportFailed(fname, "test returns false", tpbindings, formals, values, out);
          return false;
        } else if (verbose && formals.getArity() > 0) {
          out.println((i + 1) + ": Checked with " + Arrays.toString(values) + ": true");
        }
      } catch (Throw e){
        if(expected == null || !((IConstructor)e.getException()).getName().equals(expected)){
          return reportFailed(fname, e.getMessage(), tpbindings, formals, values, out);
        }
        expectedThrown = true;
      }
      catch (Throwable e) {
        if(expected == null || !e.getClass().toString().endsWith("." + expected)){
          return reportFailed(fname, e.getMessage(), tpbindings, formals, values, out);
        }
        expectedThrown = true;
      }
      if(expected != null && !expectedThrown){
        return reportMissingException(fname, expected, out);
      }
    }

    out.println("Test " + fname + (formals.getArity() > 0 ? " not refuted after " + tries + " tries with maximum depth " + maxDepth
        : " succeeded"));

    return true;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.type.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.