Package org.rascalmpl.interpreter.control_exceptions

Examples of org.rascalmpl.interpreter.control_exceptions.MatchFailed


    if (result == null && defaultCandidates.size() > 0) {
      result = callWith(defaultCandidates, argTypes, argValues, keyArgValues, true);
    }

    if (result == null) {
      throw new MatchFailed();
    }

    return result;
  }
View Full Code Here


      return new ConcreteConstructorFunction(ast, eval, declarationEnvironment).call(actualTypes, actuals, keyArgValues);
    }
   
    Map<Type,Type> bindings = new HashMap<Type,Type>();
    if (!constructorType.getFieldTypes().match(TF.tupleType(actualTypes), bindings)) {
      throw new MatchFailed();
    }
    Type formalTypeParameters = constructorType.getAbstractDataType().getTypeParameters();
    Type instantiated = constructorType;

    if (!formalTypeParameters.isBottom()) {
View Full Code Here

      Environment[] olds = new Environment[size];
      int i = 0;
     
     
      if (!hasVarArgs && size != this.formals.size()) {
        throw new MatchFailed();
      }

      if (size == 0) {
        try {
          bindKeywordArgs(keyArgValues);
          result = runBody();
          storeMemoizedResult(actuals,keyArgValues, result);
          return result;
        }
        catch (Return e) {
          result = computeReturn(e);
          storeMemoizedResult(actuals,keyArgValues, result);
          return result;
        }
      }
     
      matchers[0].initMatch(makeResult(actualTypesTuple.getFieldType(0), actuals[0], ctx));
      olds[0] = ctx.getCurrentEnvt();
      ctx.pushEnv();

      // pattern matching requires backtracking due to list, set and map matching and
      // non-linear use of variables between formal parameters of a function...
     
      while (i >= 0 && i < size) {
        if (ctx.isInterrupted()) {
          throw new InterruptException(ctx.getStackTrace(), currentAST.getLocation());
        }
        if (matchers[i].hasNext() && matchers[i].next()) {
          if (i == size - 1) {
            // formals are now bound by side effect of the pattern matcher
            try {
              bindKeywordArgs(keyArgValues);
              result = runBody();
              storeMemoizedResult(actuals,keyArgValues, result);
              return result;
            }
            catch (Failure e) {
              // backtrack current pattern assignment
              if (!e.hasLabel() || e.hasLabel() && e.getLabel().equals(getName())) {
                continue;
              }
              else {
                throw new UnguardedFail(getAst(), e);
              }
            }
          }
          else {
            i++;
            matchers[i].initMatch(makeResult(actualTypesTuple.getFieldType(i), actuals[i], ctx));
            olds[i] = ctx.getCurrentEnvt();
            ctx.pushEnv();
          }
        } else {
          ctx.unwind(olds[i]);
          i--;
          ctx.pushEnv();
        }
      }
     
      // backtrack to other function body
      throw new MatchFailed();
    }
    catch (Return e) {
      result = computeReturn(e);
      storeMemoizedResult(actuals,keyArgValues, result);
      return result;
View Full Code Here

      actualTypesTuple = TF.tupleType(actualTypes);
    }
   
    if (!actualTypesTuple.isSubtypeOf(formals)) {
      // resolve overloading
      throw new MatchFailed();
    }
   
    oActuals = addKeywordActuals(oActuals, formals, keyArgValues);

    if (hasReflectiveAccess) {
View Full Code Here

  @Override
  public Result<IValue> call(Type[] argTypes, IValue[] argValues, Map<String, IValue> keyArgValues) {
    String label = null;
   
    if (argTypes.length == 0) {
      throw new MatchFailed();
    }
   
    if (argTypes[0].isAbstractData() || argTypes[0].isConstructor()) {
      label = ((IConstructor) argValues[0]).getConstructorType().getName();
      List<AbstractFunction> funcs = alternatives.get(label);
     
      if (funcs != null) {
        for (AbstractFunction candidate : funcs) {
          if ((candidate.hasVarArgs() && argValues.length >= candidate.getArity() - 1)
              || candidate.getArity() == argValues.length) {
            try {
              return candidate.call(argTypes, argValues, keyArgValues);
            }
            catch (MatchFailed m) {
              // could happen if pattern dispatched
            }
            catch (Failure e) {
              // could happen if function body throws fail
            }
          }
        }

        throw new MatchFailed();
      }
    }
   
    throw new MatchFailed();
  }
View Full Code Here

 
  protected void bindTypeParameters(Type actualTypes, Type formals, Environment env) {
    try {
      Map<Type, Type> bindings = new HashMap<Type, Type>();
      if (!formals.match(actualTypes, bindings)) {
        throw new MatchFailed();
      }
      env.storeTypeBindings(bindings);
    }
    catch (FactTypeUseException e) {
      throw new UnexpectedType(formals, actualTypes, ast);
View Full Code Here

  @Override
  public Result<IValue> call(IRascalMonitor monitor, Type[] argTypes, IValue[] argValues, Map<String, IValue> keyArgValues) {
    IConstructor label = null;
   
    if (argTypes.length == 0) {
      throw new MatchFailed();
    }
   
    if (argTypes[0].isSubtypeOf(Factory.Tree)) {
      if (!TreeAdapter.isAppl((IConstructor) argValues[0])) {
        throw new MatchFailed();
      }
      label = TreeAdapter.getProduction((IConstructor) argValues[0]);
      List<AbstractFunction> funcs = alternatives.get(label);
     
      if (funcs != null) {
        for (AbstractFunction candidate : funcs) {
          if ((candidate.hasVarArgs() && argValues.length >= candidate.getArity() - 1)
              || candidate.getArity() == argValues.length) {
            try {
              return candidate.call(argTypes, argValues, keyArgValues);
            }
            catch (MatchFailed m) {
              // could happen if pattern dispatched
            }
            catch (Failure e) {
              // could happen if function body throws fail
            }
          }
        }

        throw new MatchFailed();
      }
    }
   
    throw new MatchFailed();
  }
View Full Code Here

TOP

Related Classes of org.rascalmpl.interpreter.control_exceptions.MatchFailed

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.