moar capTable context maintenance

This commit is contained in:
Vaci Koblizek 2020-12-03 15:06:17 +00:00
parent 196b82515c
commit 25c50b105d
4 changed files with 67 additions and 10 deletions

View file

@ -49,12 +49,19 @@ public class ListBuilder extends Capability.BuilderContext {
public ListBuilder(SegmentBuilder segment, int ptr, public ListBuilder(SegmentBuilder segment, int ptr,
int elementCount, int step, int elementCount, int step,
int structDataSize, short structPointerCount) { int structDataSize, short structPointerCount) {
this(segment, null, ptr, elementCount, step, structDataSize, structPointerCount);
}
public ListBuilder(SegmentBuilder segment, CapTableBuilder capTable, int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount) {
this.segment = segment; this.segment = segment;
this.ptr = ptr; this.ptr = ptr;
this.elementCount = elementCount; this.elementCount = elementCount;
this.step = step; this.step = step;
this.structDataSize = structDataSize; this.structDataSize = structDataSize;
this.structPointerCount = structPointerCount; this.structPointerCount = structPointerCount;
this.capTable = capTable;
} }
public int size() { public int size() {

View file

@ -28,9 +28,9 @@ public class ListReader extends Capability.ReaderContext {
int elementCount, int step, int elementCount, int step,
int structDataSize, short structPointerCount, int structDataSize, short structPointerCount,
int nestingLimit); int nestingLimit);
default T constructReader(SegmentBuilder segment, CapTableReader capTable, int ptr, default T constructReader(SegmentReader segment, CapTableReader capTable, int ptr,
int elementCount, int step, int elementCount, int step,
int structDataSize, short structPointerCount, int nestingLimit) { int structDataSize, short structPointerCount, int nestingLimit) {
var result = constructReader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit); var result = constructReader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
if (result instanceof Capability.ReaderContext) { if (result instanceof Capability.ReaderContext) {
((Capability.ReaderContext) result).capTable = capTable; ((Capability.ReaderContext) result).capTable = capTable;
@ -55,12 +55,22 @@ public class ListReader extends Capability.ReaderContext {
this.structDataSize = 0; this.structDataSize = 0;
this.structPointerCount = 0; this.structPointerCount = 0;
this.nestingLimit = 0x7fffffff; this.nestingLimit = 0x7fffffff;
this.capTable = null;
} }
public ListReader(SegmentReader segment, int ptr, public ListReader(SegmentReader segment, int ptr,
int elementCount, int step, int elementCount, int step,
int structDataSize, short structPointerCount, int structDataSize, short structPointerCount,
int nestingLimit) { int nestingLimit) {
this(segment, null, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
}
public ListReader(SegmentReader segment,
CapTableReader capTable,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount,
int nestingLimit) {
this.segment = segment; this.segment = segment;
this.ptr = ptr; this.ptr = ptr;
this.elementCount = elementCount; this.elementCount = elementCount;
@ -68,12 +78,11 @@ public class ListReader extends Capability.ReaderContext {
this.structDataSize = structDataSize; this.structDataSize = structDataSize;
this.structPointerCount = structPointerCount; this.structPointerCount = structPointerCount;
this.nestingLimit = nestingLimit; this.nestingLimit = nestingLimit;
this.capTable = capTable;
} }
ListReader imbue(CapTableReader capTable) { ListReader imbue(CapTableReader capTable) {
var result = new ListReader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit); return new ListReader(segment, capTable, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
result.capTable = capTable;
return result;
} }
public int size() { public int size() {
@ -117,7 +126,7 @@ public class ListReader extends Capability.ReaderContext {
int structData = this.ptr + (int)(indexBit / Constants.BITS_PER_BYTE); int structData = this.ptr + (int)(indexBit / Constants.BITS_PER_BYTE);
int structPointers = structData + (this.structDataSize / Constants.BITS_PER_BYTE); int structPointers = structData + (this.structDataSize / Constants.BITS_PER_BYTE);
return factory.constructReader(this.segment, structData, structPointers / 8, this.structDataSize, return factory.constructReader(this.segment, this.capTable, structData, structPointers / 8, this.structDataSize,
this.structPointerCount, this.nestingLimit - 1); this.structPointerCount, this.nestingLimit - 1);
} }

View file

@ -55,6 +55,27 @@ public final class StructList {
return new Builder<ElementBuilder> (factory, segment, ptr, elementCount, step, structDataSize, structPointerCount); return new Builder<ElementBuilder> (factory, segment, ptr, elementCount, step, structDataSize, structPointerCount);
} }
@Override
public final Reader<ElementReader> constructReader(SegmentReader segment,
CapTableReader capTable,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount,
int nestingLimit) {
return new Reader<ElementReader>(factory, capTable,
segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
}
@Override
public final Builder<ElementBuilder> constructBuilder(SegmentBuilder segment,
CapTableBuilder capTable,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount) {
return new Builder<ElementBuilder> (factory, capTable,
segment, ptr, elementCount, step, structDataSize, structPointerCount);
}
@Override @Override
public final Builder<ElementBuilder> fromPointerBuilderRefDefault(SegmentBuilder segment, CapTableBuilder capTable, int pointer, public final Builder<ElementBuilder> fromPointerBuilderRefDefault(SegmentBuilder segment, CapTableBuilder capTable, int pointer,
SegmentReader defaultSegment, int defaultOffset) { SegmentReader defaultSegment, int defaultOffset) {
@ -97,6 +118,17 @@ public final class StructList {
this.factory = factory; this.factory = factory;
} }
public Reader(StructReader.Factory<T> factory,
CapTableReader capTable,
SegmentReader segment,
int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount,
int nestingLimit) {
super(segment, capTable, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
this.factory = factory;
}
public T get(int index) { public T get(int index) {
return _getStructElement(factory, index); return _getStructElement(factory, index);
} }
@ -132,7 +164,15 @@ public final class StructList {
SegmentBuilder segment, int ptr, SegmentBuilder segment, int ptr,
int elementCount, int step, int elementCount, int step,
int structDataSize, short structPointerCount){ int structDataSize, short structPointerCount){
super(segment, ptr, elementCount, step, structDataSize, structPointerCount); this(factory, null, segment, ptr, elementCount, step, structDataSize, structPointerCount);
}
public Builder(StructBuilder.Factory<T> factory,
CapTableBuilder capTable,
SegmentBuilder segment, int ptr,
int elementCount, int step,
int structDataSize, short structPointerCount) {
super(segment, capTable, ptr, elementCount, step, structDataSize, structPointerCount);
this.factory = factory; this.factory = factory;
} }

View file

@ -1222,7 +1222,7 @@ final class WireHelpers {
if (WirePointer.isNull(ref)) { if (WirePointer.isNull(ref)) {
if (defaultSegment == null) { if (defaultSegment == null) {
return factory.constructReader(SegmentReader.EMPTY, 0, 0, 0, 0, (short) 0, 0x7fffffff); return factory.constructReader(SegmentReader.EMPTY, capTable, 0, 0, 0, 0, (short) 0, 0x7fffffff);
} else { } else {
segment = defaultSegment; segment = defaultSegment;
refOffset = defaultOffset; refOffset = defaultOffset;
@ -1264,7 +1264,7 @@ final class WireHelpers {
// TODO check whether the size is compatible // TODO check whether the size is compatible
return factory.constructReader(resolved.segment, return factory.constructReader(resolved.segment, capTable,
ptr * Constants.BYTES_PER_WORD, ptr * Constants.BYTES_PER_WORD,
size, size,
wordsPerElement * Constants.BITS_PER_WORD, wordsPerElement * Constants.BITS_PER_WORD,
@ -1311,6 +1311,7 @@ final class WireHelpers {
} }
return factory.constructReader(resolved.segment, return factory.constructReader(resolved.segment,
capTable,
resolved.ptr * Constants.BYTES_PER_WORD, resolved.ptr * Constants.BYTES_PER_WORD,
ListPointer.elementCount(resolved.ref), ListPointer.elementCount(resolved.ref),
step, step,