Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.IListWriter


          STREAM_READ_SEGMENT_SIZE);
    }
    java.lang.String b = java.lang.String.valueOf(input);
    java.lang.String[] d = regex_replacement.length == 0 ? b.split("\n")
        : new java.lang.String[] { b };
    IListWriter r = values.listWriter(TypeFactory.getInstance()
        .stringType());
    Pattern p = Pattern.compile("\\(\\w*\\)[ \t]*$");
    java.lang.String found = null;
    for (java.lang.String e : d) {
      if (regex_replacement.length == 8) {
        java.lang.String[] f = e.split(regex_replacement[0]);
        StringBuffer a = new StringBuffer();
        for (int i = 0; i < f.length; i++) {
          if (i % 2 != 0) {
            a.append(regex_replacement[1]);
            if (found!=null) {
              // System.err.println("found"+found);
              a.append(found);
              found = null;
            }
            a.append(regex_replacement[0]);
            java.lang.String q = f[i];
            q=q.replaceAll(regex_replacement[2],
                regex_replacement[3]);
            q=q.replaceAll(regex_replacement[4],
                regex_replacement[5]);
            q=q.replaceAll(regex_replacement[6],
                regex_replacement[7]);
            a.append(q);
            a.append(regex_replacement[0]);
            a.append(regex_replacement[1]);
          } else {
            Matcher m = p.matcher(f[i]);
            boolean z = m.find();
            if (z) {
              found = m.group();
              a.append(m.replaceFirst(""));
                }
            else a.append(f[i]);
              }
        }
        e = a.toString();
      }
      r.append(values.string(e));
    }
    return r.done();
  }
View Full Code Here


  }

  @SuppressWarnings("deprecation")
  @Override
  public IValue visitList(Type type) throws IOException {
    IListWriter w = vf.listWriter(elementType(type));
    List l = (List)stack.peek();
    for (Object e: l) {
      stack.push(e);
      w.append(read(elementType(type)));
      stack.pop();
    }
    return w.done();
  }
View Full Code Here

      public IValue visitList(IList o) throws RuntimeException {
        List<IValue> elements = new ArrayList<IValue>(o.length());
        for (IValue e : o) {
          elements.add(e.accept(this));
        }
        IListWriter writer = vf.listWriter(calcLub(elements));
        writer.appendAll(elements);
        return writer.done();
      }

      @Override
      public IValue visitRelation(ISet o) throws RuntimeException {
        List<IValue> elements = new ArrayList<IValue>(o.size());
        for (IValue e : o) {
          elements.add(e.accept(this));
        }
        ISetWriter writer = vf.relationWriter(calcLub(elements));
        writer.insertAll(elements);
        return writer.done();
      }

      @Override
      public IValue visitListRelation(IList o) throws RuntimeException {
        List<IValue> elements = new ArrayList<IValue>(o.length());
        for (IValue e : o) {
          elements.add(e.accept(this));
        }
        IListWriter writer = vf.listRelationWriter(calcLub(elements));
        writer.appendAll(elements);
        return writer.done();
      }

      @Override
      public IValue visitSet(ISet o) throws RuntimeException {
        List<IValue> elements = new ArrayList<IValue>(o.size());
        for (IValue e : o) {
          elements.add(e.accept(this));
        }
        ISetWriter writer = vf.setWriter(calcLub(elements));
        writer.insertAll(elements);
        return writer.done();
      }
      @Override
      public IValue visitTuple(ITuple o) throws RuntimeException {
        IValue[] elements = new IValue[o.arity()];
        Type[] types = new Type[o.arity()];
        for (int i = 0; i < elements.length; i++) {
          elements[i] = o.get(i).accept(this);
          types[i] = elements[i].getType();
        }

        return vf.tuple(tf.tupleType(types), elements);
      }

      @Override
      public IValue visitNode(INode o) throws RuntimeException {
        IValue[] children = new IValue[o.arity()];
        for (int i = 0; i < children.length; i++) {
          children[i] = o.get(i).accept(this);
        }
        if (o.mayHaveKeywordParameters()) {
          IWithKeywordParameters<? extends INode> okw = o.asWithKeywordParameters();
          Map<String, IValue> oldKwParams = okw.getParameters();
          Map<String, IValue> kwParams = new HashMap<>(oldKwParams.size());
          for (String key : oldKwParams.keySet()) {
            kwParams.put(key, oldKwParams.get(key).accept(this));

          }
          return vf.node(o.getName(), children, kwParams);
        }

        return vf.node(o.getName(), children);
      }

      @Override
      public IValue visitMap(IMap o) throws RuntimeException {
        Iterator<Entry<IValue,IValue>> entries = o.entryIterator();
        Map<IValue, IValue> newEntries = new HashMap<>(o.size());
        while (entries.hasNext()) {
          Entry<IValue, IValue> ent = entries.next();
          newEntries.put(ent.getKey().accept(this), ent.getValue().accept(this));
        }

        IMapWriter writer = vf.mapWriter(calcLub(newEntries.keySet()), calcLub(newEntries.values()));
        writer.putAll(newEntries);
        return writer.done();
      }

      @Override
      public IValue visitConstructor(IConstructor o)
          throws RuntimeException {
View Full Code Here

      }

      @Override
      public IValue visitList(Type type) {
        if(type.isListRelation()) {
          IListWriter w = vf.listWriter();

          if (type.hasFieldNames()) {
            for (int i = 0; i < type.getArity(); i++) {
              w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
            }
          } else {
            if (type.getFieldTypes().isBottom()) {
              return vf.constructor(Factory.Symbol_List, vf.constructor(Factory.Symbol_Void));
            }
         
            for (Type f : type.getFieldTypes()) {
              w.append(f.accept(this));
            }
          }
       
          return vf.constructor(Factory.Symbol_ListRel, w.done());
        }
        return vf.constructor(Factory.Symbol_List, type.getElementType().accept(this));
      }

      @Override
      public IValue visitMap(Type type) {
        if (type.hasFieldNames()) {
          return vf.constructor(Factory.Symbol_Map, vf.constructor(Factory.Symbol_Label, vf.string(type.getKeyLabel()), type.getKeyType().accept(this)), vf.constructor(Factory.Symbol_Label, vf.string(type.getValueLabel()), type.getValueType().accept(this)));
        } else {
          return vf.constructor(Factory.Symbol_Map, type.getKeyType().accept(this), type.getValueType().accept(this));
        }
      }

      @Override
      public IValue visitNumber(Type type) {
        return vf.constructor(Factory.Symbol_Num);
      }

      @Override
      public IValue visitAlias(Type type) {
        IListWriter w = vf.listWriter();
        Type params = type.getTypeParameters();
       
        if (params.getArity() > 0) {
          for (Type t : params) {
            w.append(t.accept(this));
          }
        }
       
        return vf.constructor(Factory.Symbol_Alias, vf.string(type.getName()), w.done(), type.getAliased().accept(this));
      }

      @Override
      public IValue visitSet(Type type) {
        if(type.isRelation()) {
          IListWriter w = vf.listWriter();

          if (type.hasFieldNames()) {
            for (int i = 0; i < type.getArity(); i++) {
              w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
            }
          } else {
            if (type.getFieldTypes().isBottom()) {
              return vf.constructor(Factory.Symbol_Set, vf.constructor(Factory.Symbol_Void));
            }
            for (Type f : type.getFieldTypes()) {
              w.append(f.accept(this));
            }
          }
       
          return vf.constructor(Factory.Symbol_Rel, w.done());
        }
        return vf.constructor(Factory.Symbol_Set, type.getElementType().accept(this));
      }

      @Override
      public IValue visitSourceLocation(Type type) {
        return vf.constructor(Factory.Symbol_Loc);
      }

      @Override
      public IValue visitString(Type type) {
        return vf.constructor(Factory.Symbol_Str);
      }

      @Override
      public IValue visitNode(Type type) {
        return vf.constructor(Factory.Symbol_Node);
      }
     
      @Override
      public IValue visitConstructor(Type type) {
        IValue adt = cache.get(type.getAbstractDataType());
       
        if (adt == null) {
          visitAbstractData(type.getAbstractDataType());
        }
       
        IValue result = cache.get(type);
        if (result == null) {
          IListWriter w = vf.listWriter();

          if (type.hasFieldNames()) {
            for (int i = 0; i < type.getArity(); i++) {
              w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
            }
          }
          else {
            for (Type field : type.getFieldTypes()) {
              w.append(field.accept(this));
            }
          }
          result = vf.constructor(Factory.Symbol_Cons, vf.constructor(Factory.Symbol_Label, vf.string(type.getName()), adt), w.done());
          cache.put(type, result);
        }
       
        return result;
      }
     
      @Override
      public IValue visitAbstractData(Type type) {
        IValue sym = cache.get(type);
       
        if (sym == null) {
          IListWriter w = vf.listWriter();
          Type params = type.getTypeParameters();
          if (params.getArity() > 0) {
            for (Type param : params) {
              w.append(param.accept(this));
            }
          }
         
          sym = vf.constructor(Factory.Symbol_Adt, vf.string(type.getName()), w.done());
          cache.put(type, sym);     

          // make sure to find the type by the uninstantiated adt
          Type adt = typeStore.lookupAbstractDataType(type.getName());
          for (Type cons : typeStore.lookupAlternatives(adt)) {
            cons.accept(this);
          }
        }
       
        return sym;
      }

      @Override
      public IValue visitTuple(Type type) {
        IListWriter w = vf.listWriter();
       
        if (type.hasFieldNames()) {
          for (int i = 0; i < type.getArity(); i++) {
            w.append(vf.constructor(Factory.Symbol_Label, vf.string(type.getFieldName(i)), type.getFieldType(i).accept(this)));
          }
        }
        else {
          for (Type f : type) {
            w.append(f.accept(this));
          }
        }

        return vf.constructor(Factory.Symbol_Tuple, w.done());
      }

      @Override
      public IValue visitValue(Type type) {
        return vf.constructor(Factory.Symbol_Value);
      }

      @Override
      public IValue visitVoid(Type type) {
        return vf.constructor(Factory.Symbol_Void);
      }

      @Override
      public IValue visitBool(Type boolType) {
        return vf.constructor(Factory.Symbol_Bool);
      }

      @Override
      public IValue visitParameter(Type parameterType) {
        return vf.constructor(Factory.Symbol_BoundParameter, vf.string(parameterType.getName()), parameterType.getBound().accept(this));
      }

      @Override
      public IValue visitExternal(Type externalType) {
        if (externalType instanceof NonTerminalType) {
          return visitNonTerminalType((NonTerminalType) externalType);
        }
        else if (externalType instanceof ReifiedType) {
          return visitReifiedType((ReifiedType) externalType);
        }
        else if (externalType instanceof FunctionType) {
          return visitFunctionType((FunctionType) externalType);
        }
       
        throw new CompilerError("unable to reify " + externalType);
      }

      private IValue visitFunctionType(FunctionType externalType) {
        IListWriter w = vf.listWriter();
        for (Type arg : externalType.getArgumentTypes()) {
          w.append(arg.accept(this));
        }
       
        return vf.constructor(Factory.Symbol_Func, externalType.getReturnType().accept(this), w.done());
      }

      private IValue visitReifiedType(ReifiedType externalType) {
        return vf.constructor(Factory.Symbol_ReifiedType, externalType.getTypeParameters().getFieldType(0).accept(this));
      }
View Full Code Here

        w.put(vf.string((String) k), convertToIValue(map.get(k)))
      }
      return vf.constructor(JSON_object, w.done());
    }
    if (obj instanceof List) {
      IListWriter w = vf.listWriter();
      for (Object k: (List)obj) {
        w.append(convertToIValue(k))
      }
      return vf.constructor(JSON_array, w.done());
    }
    if (obj instanceof Double) {
      return vf.constructor(JSON_null);
     
    }
View Full Code Here

    return values.real(new org.apache.commons.math.stat.correlation.PearsonsCorrelation().correlation(xvalues, yvalues));
  }
 
  private IList RealMatrix2List(RealMatrix m){
    Type listType = types.listType(types.realType());
    IListWriter w = values.listWriter(listType.getElementType());
    int n = m.getColumnDimension();
    for(int i = 0; i < n; i++){
      w.append(values.real(m.getEntry(i,0)));
    }
    return w.done();
  }
View Full Code Here

      return methodSymbol(decl, typeParameters, retSymbol,  parameters);
    }
  }

  private IList computeTypes(ITypeBinding[] bindings, boolean isDeclaration) {
    IListWriter parameters = values.listWriter();
    for (ITypeBinding parameterType: bindings) {
      IConstructor arg = resolveType(parameterType, isDeclaration);
        parameters.append(arg);
    }
    return parameters.done();
  }
View Full Code Here

    if (constant) {
      return makeResult(type, node, eval);
    }
   
    // TODO add function calling
    IListWriter w = eval.getValueFactory().listWriter(Factory.Tree);
    for (org.rascalmpl.ast.Expression arg : args) {
      w.append(arg.interpret(eval).getValue());
    }
   
    ISourceLocation location = getLocation();
   
    if (location != null) {
      java.util.Map<String,IValue> annos = new HashMap<String,IValue>();
      annos.put("loc", location);
      return makeResult(type, eval.getValueFactory().constructor(Factory.Tree_Appl, annos, production, w.done()), eval);
    }
    else {
      return makeResult(type, eval.getValueFactory().constructor(Factory.Tree_Appl, production, w.done()), eval);
    }
  }
View Full Code Here

    Type lub = TF.voidType();
    for (int j = i; j < actuals.length; j++) {
      lub = lub.lub(actuals[j].getType());
    }
   
    IListWriter list = vf.listWriter();
    list.insertAt(0, actuals, i, actuals.length - arity + 1);
    newActuals[i] = list.done();
    return newActuals;
  }
View Full Code Here

    if(result instanceof Thrown) {
      ((Thrown) result).printStackTrace(stdout);
      return vf.string(((Thrown) result).toString());
    }
    if(result instanceof Object[]) {
      IListWriter w = vf.listWriter();
      Object[] lst = (Object[]) result;
      for(int i = 0; i < lst.length; i++){
        w.append(narrow(lst[i]));
      }
      return w.done();
    }
    throw new CompilerError("Cannot convert object back to IValue: " + result);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.IListWriter

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.