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

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


      __eval.notifyAboutSuspension(this);     
     
      java.util.List<org.rascalmpl.ast.Expression> elements = this
          .getElements0();

      Type elementType = TF.voidType();
      java.util.List<IValue> results = new ArrayList<IValue>();

      for (org.rascalmpl.ast.Expression expr : elements) {
        Result<IValue> resultElem;
       
        if(expr.isSplice() || expr.isSplicePlus()){
          resultElem = expr.getArgument().interpret(__eval);
          if (resultElem.getType().isBottom()) {
            throw new NonVoidTypeRequired(expr.getArgument());
          }

          if (resultElem.getType().isSet() || resultElem.getType().isList()){
            /*
             * Splice the elements in the set
             * __eval.
             */
            elementType = elementType.lub(resultElem.getType().getElementType());
            for (IValue val : (Iterable<IValue>) resultElem.getValue()) {
              results.add(val);
            }
          continue;
          }
        } else {
          resultElem = expr.interpret(__eval);
          if (resultElem.getType().isBottom()) {
            throw new NonVoidTypeRequired(expr);
          }
        }
        elementType = elementType.lub(resultElem.getType());
        results.add(results.size(), resultElem.getValue());
      }
      Type resultType = TF.setType(elementType);
      ISetWriter w = __eval.__getVf().setWriter();
      w.insertAll(results);
      // Was: return makeResult(resultType, applyRules(w.done()));
      return org.rascalmpl.interpreter.result.ResultFactory.makeResult(
          resultType, w.done(), __eval);
View Full Code Here


    }

    @Override
    public Type typeOf(Environment env, boolean instantiateTypeParameters, IEvaluator<Result<IValue>> eval) {
      Type elementType = TF.voidType();

      for (org.rascalmpl.ast.Expression elt : getElements0()) {
        Type eltType = elt.typeOf(env, instantiateTypeParameters, eval);
       
        // TODO: here we need to properly deal with splicing operators!!!
        if (eltType.isSet()) {
          eltType = eltType.getElementType();
        }
        elementType = elementType.lub(eltType);
      }

      return TF.setType(elementType);
View Full Code Here

    initListPatternDelegate(list);
    //System.err.println("ConcreteListPattern");
  }

  private void initListPatternDelegate(List<IMatchingResult> list) {
    Type type = getType(null, null);
   
    if (type instanceof NonTerminalType) {
      IConstructor rhs = ((NonTerminalType) type).getSymbol();

       if (SymbolAdapter.isIterPlus(rhs) || SymbolAdapter.isIterStar(rhs)) {
View Full Code Here

 
 
  @Override
  public <V extends IValue> LessThanOrEqualResult lessThanOrEqual(Result<V> that) {
    Type thisRuntimeType = getValue().getType();
    Type thatRuntimeType = that.getValue().getType();
   
    if (thisRuntimeType.comparable(thatRuntimeType)) {
      return makeResult(thisRuntimeType, getValue(), ctx).lessThanOrEqual(makeResult(thatRuntimeType, that.getValue(), ctx));
    }
    else {
View Full Code Here

  @Override
  public void initMatch(Result<IValue> subject) {
    super.initMatch(subject);
   
    Type runType = subject.getValue().getType();
   
    if(runType.isSubtypeOf(tf.stringType())) {
      this.subject = ((IString) subject.getValue()).getValue();
    }
    else {
      hasNext = false;
      return;
View Full Code Here

     
      IMatchingResult[] matchers = prepareFormals(ctx);
      ctx.setAccumulators(accumulators);
      ctx.pushEnv();

      Type actualTypesTuple = TF.tupleType(actualTypes);
      if (hasVarArgs) {
        actuals = computeVarArgsActuals(actuals, getFormals());
        actualTypesTuple = computeVarArgsActualTypes(actualTypes, getFormals());
      }

      int size = actuals.length;
      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]);
View Full Code Here

  }

  private Result<IValue> computeReturn(Return e) {
    Result<IValue> result = e.getValue();

    Type returnType = getReturnType();
    Type instantiatedReturnType = returnType.instantiate(ctx.getCurrentEnvt().getTypeBindings());

    if(!result.getType().isSubtypeOf(instantiatedReturnType)){
      throw new UnexpectedType(instantiatedReturnType, result.getType(), e.getLocation());
    }
View Full Code Here

   
    for (i = 0; i < arity - 1; i++) {
      types[i] = actualTypes[i];
    }
   
    Type lub = TF.voidType();
    for (int j = i; j < actualTypes.length; j++) {
      lub = lub.lub(actualTypes[j]);
    }
   
    types[i] = TF.listType(lub);
   
    return TF.tupleType(types);
View Full Code Here

      isBindingVar[i] = false;
      Environment env = ctx.getCurrentEnvt();

      if (child instanceof TypedMultiVariablePattern) {
        TypedMultiVariablePattern tmvVar = (TypedMultiVariablePattern) child;
        Type tmvType = tmvVar.getType(env, null);
        String name = tmvVar.getName();

        varName[i] = name;
        isListVar[i] = true;
        listVarOccurrences[i] = 1;
        ++nListVar;

        if(!tmvVar.isAnonymous() && allVars.contains(name)) {
          throw new RedeclaredVariable(name, getAST());
        } else if(tmvType.comparable(listSubject.getType().getElementType())
            || (tmvVar.bindingInstance() && tmvType.comparable(listSubject.getType()))) {
          tmvVar.convertToListType();
          if (!tmvVar.isAnonymous()) {
            allVars.add(name);
          }
          isBindingVar[i] = true;
        } else {
          hasNext = false;
          return;
        }
      }
      else if(child instanceof MultiVariablePattern){
        MultiVariablePattern multiVar = (MultiVariablePattern) child;
        String name = multiVar.getName();
        varName[i] = name;
        isListVar[i] = true;
        nListVar++;

        if(!multiVar.isAnonymous() && allVars.contains(name)){
          isBindingVar[i] = false;
        } else if(multiVar.isAnonymous()){
          isBindingVar[i] = true;
        } else {
          allVars.add(name);
          Result<IValue> varRes = env.getVariable(name);

          if (varRes == null || multiVar.bindingInstance()) {
            isBindingVar[i] = true;
          } else {
            isBindingVar[i] = false;
            Type varType = varRes.getType();
            if (isAnyListType(varType)){ 
              if (!varType.comparable(listSubjectType)) {    
                hasNext = false;
                return;
              }
            } else {
              if(!(varType instanceof NonTerminalType) && !(varType.comparable(staticListSubjectElementType))) {
                hasNext = false;
                return;
              }
            }
          }
        }
      }
      else if (child instanceof ConcreteListVariablePattern) {
        ConcreteListVariablePattern listVar = (ConcreteListVariablePattern) child;
        String name = listVar.getName();
        varName[i] = name;
        isListVar[i] = true;
        if (!listVar.isAnonymous()) {
          allVars.add(name);
        }
        plusList[i] = listVar.isPlusList();
        isBindingVar[i] = true;
        listVarOccurrences[i] = 1;
        nListVar++;
      }
      else if(child instanceof QualifiedNamePattern){
        QualifiedNamePattern qualName = (QualifiedNamePattern) child;
        String name = qualName.getName();
        varName[i] = name;
        if(!qualName.isAnonymous() && allVars.contains(name)){
          /*
           * A variable that was declared earlier in the pattern
           */
          isListVar[i] = true;
          nListVar++;
          listVarOccurrences[i]++;
        } else if(qualName.isAnonymous()){
          /*
           * Nothing to do
           */
        } else {
          Result<IValue> varRes = env.getVariable(name);

          if(varRes == null || qualName.bindingInstance()){
            // A completely new non-list variable, nothing to do
          } else {
            Type varType = varRes.getType();
            if (isAnyListType(varType)){ 
              /*
               * A variable declared in the current scope.
               */
              if(varType.comparable(listSubjectType)){    
                isListVar[i] = true;
                isBindingVar[i] = varRes.getValue() == null;
                nListVar++;                
              } else {
                hasNext = false;
                return;
              }
            } else {
              if(varType instanceof NonTerminalType){
                // suppress comparable test for Nonterminal types
                // TODO: this should be done better
              } else
                if(!varType.comparable(staticListSubjectElementType)){
                  hasNext = false;
                  return;
                }
            }
          }
        }
      }
      else if(child instanceof VariableBecomesPattern){
        // Nothing to do
      }
      else {
        if (debug) {
          System.err.println("List: child " + child);
          System.err.println("List: child is a" + child.getClass());
        }
        Type childType = child.getType(env, null);

        // TODO: pattern matching should be specialized such that matching appl(prod...)'s does not
        // need to use list matching on the fixed arity children of the application of a production
        if(!(childType instanceof NonTerminalType) && !childType.comparable(staticListSubjectElementType)){
          hasNext = false;
          return;
        }
        java.util.List<IVarPattern> childVars = child.getVariables();
        if(!childVars.isEmpty()){
View Full Code Here

    }

    @Override
    public Type typeOf(Environment env, boolean instantiateTypeParameters, IEvaluator<Result<IValue>> eval) {
      java.util.List<org.rascalmpl.ast.Expression> fields = getElements();
      Type fieldTypes[] = new Type[fields.size()];

      for (int i = 0; i < fields.size(); i++) {
        fieldTypes[i] = fields.get(i).typeOf(env, instantiateTypeParameters, eval);
      }
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.