fix generic pipeline params. add (non-generic, for now) capability list

This commit is contained in:
Vaci Koblizek 2020-11-02 17:33:48 +00:00
parent 407d25c8c2
commit 9d023f0449
4 changed files with 138 additions and 11 deletions

View file

@ -390,7 +390,7 @@ private:
return kj::strTree("org.capnproto.ListList.", suffix, "<", kj::mv(inner), ">"); return kj::strTree("org.capnproto.ListList.", suffix, "<", kj::mv(inner), ">");
} }
case schema::Type::INTERFACE: case schema::Type::INTERFACE:
return kj::strTree("org.capnproto.AnyPointer.", suffix); return kj::strTree("org.capnproto.CapabilityList.", suffix);
case schema::Type::ANY_POINTER: case schema::Type::ANY_POINTER:
KJ_FAIL_REQUIRE("unimplemented"); KJ_FAIL_REQUIRE("unimplemented");
} }
@ -1187,7 +1187,19 @@ private:
auto typeParamVec = getTypeParameters(field.getContainingStruct()); auto typeParamVec = getTypeParameters(field.getContainingStruct());
auto factoryArg = makeFactoryArg(field.getType()); auto factoryArg = makeFactoryArg(field.getType());
auto pipelineType = typeName(field.getType(), kj::str("Pipeline")).flatten();
kj::String pipelineType;
if (field.getType().asStruct().getProto().getIsGeneric()) {
auto typeArgs = getTypeArguments(structSchema, structSchema, kj::str("Reader"));
pipelineType = kj::strTree(
javaFullName(structSchema), ".Pipeline<",
kj::StringTree(KJ_MAP(arg, typeArgs){
return kj::strTree(arg);
}, ", "),
">").flatten();
} else {
pipelineType = typeName(field.getType(), kj::str("Pipeline")).flatten();
}
return FieldText { return FieldText {
kj::strTree( kj::strTree(

View file

@ -2,7 +2,6 @@ package org.capnproto;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage; import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
public final class Capability { public final class Capability {
@ -86,13 +85,6 @@ public final class Capability {
} }
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }
/*
default <Params, Results>
Request<Params, Results> newCall(FromPointerBuilder<Params> paramsFactory,
FromPointerReader<Results> resultsFactory,
long interfaceId, short methodId) {
return Request.fromTypeless(paramsFactory, resultsFactory, this.getHook().newCall(interfaceId, methodId));
}*/
default Request<AnyPointer.Builder> newCall(long interfaceId, short methodId) { default Request<AnyPointer.Builder> newCall(long interfaceId, short methodId) {
return this.getHook().newCall(interfaceId, methodId); return this.getHook().newCall(interfaceId, methodId);

View file

@ -0,0 +1,123 @@
// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
// Licensed under the MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package org.capnproto;
public final class CapabilityList {
public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (ElementSize.POINTER); }
public final Reader constructReader(SegmentReader segment,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount,
int nestingLimit) {
return new Reader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
}
public final Builder constructBuilder(SegmentBuilder segment,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount) {
return new Builder(segment, ptr, elementCount, step, structDataSize, structPointerCount);
}
}
public static final Factory factory = new Factory();
public static final class Reader extends ListReader implements Iterable<Capability.Client> {
public Reader(SegmentReader segment,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount,
int nestingLimit) {
super(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
}
public Capability.Client get(int index) {
return _getPointerElement(Capability.factory, index);
}
public final class Iterator implements java.util.Iterator<Capability.Client> {
public Reader list;
public int idx = 0;
public Iterator(Reader list) {
this.list = list;
}
public Capability.Client next() {
return this.list._getPointerElement(Capability.factory, idx++);
}
public boolean hasNext() {
return idx < list.size();
}
public void remove() {
throw new UnsupportedOperationException();
}
}
public java.util.Iterator<Capability.Client> iterator() {
return new Iterator(this);
}
}
public static final class Builder extends ListBuilder implements Iterable<Capability.Client> {
public Builder(SegmentBuilder segment, int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount){
super(segment, ptr, elementCount, step, structDataSize, structPointerCount);
}
public final Capability.Client get(int index) {
return _getPointerElement(Capability.factory, index);
}
public final void set(int index, Capability.Client value) {
_setPointerElement(Capability.factory, index, value);
}
public final Reader asReader() {
return new Reader(this.segment, this.ptr, this.elementCount, this.step,
this.structDataSize, this.structPointerCount,
Integer.MAX_VALUE);
}
public final class Iterator implements java.util.Iterator<Capability.Client> {
public Builder list;
public int idx = 0;
public Iterator(Builder list) {
this.list = list;
}
public Capability.Client next() {
return this.list._getPointerElement(Capability.factory, idx++);
}
public boolean hasNext() {
return this.idx < this.list.size();
}
public void remove() {
throw new UnsupportedOperationException();
}
}
public java.util.Iterator<Capability.Client> iterator() {
return new Iterator(this);
}
}
}

View file

@ -50,7 +50,7 @@ interface TestPipeline {
struct TestGenerics(Foo, Bar) { struct TestGenerics(Foo, Bar) {
foo @0 :Foo; foo @0 :Foo;
# rev @1 :TestGenerics(Bar, Foo); rev @1 :TestGenerics(Bar, Foo);
interface Interface(Qux) { interface Interface(Qux) {
} }