Package org.eclipse.imp.pdb.facts

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


  private IConstructor resolveImports(IRascalMonitor monitor, IConstructor moduleParseTree) {
    ISet imports = (ISet) eval.call(monitor, "importedModules", moduleParseTree);
   
    eval.getStdErr().println("imports: " + imports);
   
    IMapWriter mw = VF.mapWriter();
   
    for (IValue i : imports) {
      URI uri = URIUtil.createRascalModule(((IString) i).getValue());
      mw.put(i, VF.sourceLocation(uri));
    }
   
    eval.getStdErr().println("locations: " + mw.done());
   
    return (IConstructor) eval.call(monitor, "linkImportedModules", moduleParseTree, mw.done());
  }
View Full Code Here


        initMethodAndStatusValues(ctx);
        return statusValues.get(cons);
      }

      private IMap makeMap(Map<String, String> headers) {
        IMapWriter writer = vf.mapWriter();
        for (Entry<String, String> entry : headers.entrySet()) {
          writer.put(vf.string(entry.getKey()), vf.string(entry.getValue()));
        }
        return writer.done();
      }

      private IConstructor makeMethod(Method method) {
        initMethodAndStatusValues(ctx);
        return methodValues.get(method);
View Full Code Here

    return genList(type);
  }

  @Override
  public IValue visitMap(Type type) {
    IMapWriter writer = vf.mapWriter(); // type.writer(vf);

    if (maxDepth <= 0 || (stRandom.nextInt(2) == 0)) {
      return writer.done();
    } else {

      RandomValueTypeVisitor visitor = descend();
      IValue key = visitor.generate(type.getKeyType());
      IValue value = visitor.generate(type.getValueType());

      if (key != null && value != null) {
        writer.put(key, value);
      }

      writer.putAll((IMap) visitor.generate(type));
      return writer.done();
    }
  }
View Full Code Here

        result.put(keyResult.getValue(), valueResult.getValue());
      }

      Type type = TF.mapType(keyType, valueType);
      IMapWriter w = __eval.__getVf().mapWriter();
      w.putAll(result);

      return org.rascalmpl.interpreter.result.ResultFactory.makeResult(
          type, w.done(), __eval);

    }
View Full Code Here

      break;
    }
   
    case "params" : {
      String query = value.hasQuery() ? value.getQuery() : "";
      IMapWriter res = vf.mapWriter(tf.stringType(), tf.stringType());
     
      if (query != null && query.length() > 0) {
        String[] params = query.split("&");
        for (String param : params) {
          String[] keyValue = param.split("=");
          res.put(vf.string(keyValue[0]), vf.string(keyValue[1]));
        }
      }
     
      IMap map = res.done();
      return makeResult(map.getType(), map, ctx);
    }

    default:
      throw new UndeclaredField(name, getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
View Full Code Here

        w.append(loadRec(elt, anchors, visited, ctx));
      }
      result = values.constructor(Node_sequence, w.done());
    }
    else if (obj instanceof Map) {
      IMapWriter w = values.mapWriter(Node, Node);
      Map<Object, Object> m = (Map<Object,Object>)obj;
      for (Map.Entry<Object,Object> e: m.entrySet()) {
        w.put(loadRec(e.getKey(), anchors, visited, ctx), loadRec(e.getValue(), anchors, visited, ctx));
      }
      result = values.constructor(Node_mapping, w.done());
    }
    else {
      throw RuntimeExceptionFactory.illegalArgument(
          values.string(obj.toString() + " (class=" + obj.getClass() + ")"),
          ctx.getCurrentAST(), ctx.getStackTrace());
View Full Code Here

    return genList(type);
  }

  @Override
  public IValue visitMap(Type type) {
    IMapWriter writer = vf.mapWriter(); // type.writer(vf);

    if (maxDepth <= 0 || (stRandom.nextInt(2) == 0)) {
      return writer.done();
    } else {

      RandomValueTypeVisitor visitor = descend();
      IValue key = visitor.generate(type.getKeyType());
      IValue value = visitor.generate(type.getValueType());

      if (key != null && value != null) {
        writer.put(key, value);
      }

      writer.putAll((IMap) visitor.generate(type));
      return writer.done();
    }
  }
View Full Code Here

    return result;
  }

  private IValue readMap(Map<?,?> o, Set<Class<?>> includes, Map<Object, IValue> cache, Stack<Object> stack) {
    IValue result;
    IMapWriter w = vf.mapWriter();

    try {
      for (Entry<?,?> e : o.entrySet()) {
        Object ok = e.getKey();
        IValue key = readObject(ok, includes, cache, stack);

        if (key == null) {
          continue;
        }

        Object ov = e.getValue();
        IValue val = readObject(ov, includes, cache, stack);

        if (val == null) {
          continue;
        }

        w.put(key, val);
      }

      result = w.done();
    }
    catch (UnsupportedOperationException e) {
      // some maps don't support the full map interface, so we default to normal objects
      String name = o.getClass().getCanonicalName();
      Map<String,IValue> fields = getFields(o, o.getClass(), includes, cache, stack);
View Full Code Here

      System.err.println("ParseMap1:" + expected);
    if (!expected.isMap())
      expected = tf.mapType(tf.stringType(), tf.valueType());
    if (debug)
      System.err.println("ParseMap2:" + expected);
    IMapWriter w = vf.mapWriter(expected);
    if (c == -1) {
      throw new FactParseError("premature EOF encountered.",
          reader.getPosition());
    }
    if (reader.getLastChar() == '}') {
      reader.readSkippingWS();
      return w.done();
    }
    ITuple term = parseEntry(reader, expected);
    w.put(term.get(0), term.get(1));
    while (reader.getLastChar() == ',') {
      reader.readSkippingWS();
      term = parseEntry(reader, expected);
      w.put(term.get(0), term.get(1));
    }
    if (reader.getLastChar() != '}') {
      throw new FactParseError("expected '}' but got '"
          + (char) reader.getLastChar() + "'", reader.getPosition());
    }
    reader.readSkippingWS();
    return w.done();
  }
View Full Code Here

    Iterator<IValue> it = t.iterator();
    for (int i = 0; i < t.size(); i++) {
      a1[i] = buildTerm(it.next(), keyType);
      a2[i] = buildTerm(t.get(a1[i]), valueType);
    }
    IMapWriter w = vf.mapWriter();
    for (int i = 0; i < t.size(); i++) {
      w.put(a1[i], a2[i]);
    }
    return w.done();
  }
View Full Code Here

TOP

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

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.