Beispiel #1
0
  public IValue buildCollection(Type type, List<Record> records, IEvaluatorContext ctx) {
    IWriter writer;
    while (type.isAliased()) {
      type = type.getAliased();
    }

    if (type.isList()) {
      writer = values.listWriter(type.getElementType());
    } else if (type.isRelation()) {
      writer = values.relationWriter(type.getElementType());
    } else {
      throw RuntimeExceptionFactory.illegalTypeArgument(
          "Invalid result type for CSV reading: " + type, ctx.getCurrentAST(), ctx.getStackTrace());
    }

    // reverse traversal so that the order in case of ListWriter is correct
    // (IWriter only supports inserts at the front).
    Type eltType = type.getElementType();
    for (int i = records.size() - 1; i >= 0; i--) {
      Record record = records.get(i);
      checkRecord(eltType, record, ctx);
      writer.insert(record.getTuple(eltType));
    }
    return writer.done();
  }
Beispiel #2
0
  public void generateTypedInterfaceInternal(
      IString tag, ISourceLocation uriLoc, IEvaluatorContext ctx) {
    IResource handler = Resource.getResourceHandler(uriLoc);
    String tagStr = tag.getValue();
    Type t = handler.getResourceType(ctx, uriLoc);
    PrintWriter currentOutStream = ctx.getStdOut();

    // Declare an alias to the type of the resource
    TypeStore ts = ctx.getCurrentEnvt().getStore();
    Type alias2t = TypeFactory.getInstance().aliasType(ts, tagStr + "Type", t);

    currentOutStream.println(
        "Generated type alias " + alias2t.toString() + ": " + alias2t.getAliased().toString());
    currentOutStream.flush();

    // Declare a function that just uses the given URI. This way, if we provide
    // the complete URI up front, we don't need to keep providing it later.
    StringBuilder sb = new StringBuilder();
    sb.append("public ").append(tagStr).append("Type ").append(tagStr).append("() { ");
    sb.append(" return getTypedResource(")
        .append(uriLoc.toString())
        .append(",#")
        .append(tagStr)
        .append("Type); }");
    IConstructor declTree =
        ctx.getEvaluator()
            .parseCommand(
                ctx.getEvaluator().getMonitor(),
                sb.toString(),
                ctx.getCurrentAST().getLocation().getURI());
    Command cmd = ctx.getEvaluator().getBuilder().buildCommand(declTree);
    Environment env = ctx.getCurrentEnvt();
    ctx.setCurrentEnvt(env.getRoot());
    Result<IValue> fun0 = ctx.getEvaluator().eval(ctx.getEvaluator().getMonitor(), cmd);
    ctx.unwind(env);

    currentOutStream.println("Generated function " + fun0.toString());
    currentOutStream.flush();
  }
Beispiel #3
0
 @Override
 public Class<?> visitAlias(org.eclipse.imp.pdb.facts.type.Type type) {
   return type.getAliased().accept(this);
 }