X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=parser%2Fyang-parser-reactor%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FStatementContextBase.java;h=1be883cd2b2213fea83f50024247b09c67e87a7c;hb=710d9e5c81cde651ad0c1093fe93ab9e6f899e1e;hp=f5f85c37c412a94cd80f795e8546c8a84e5548c4;hpb=c135667661ba90e9b76ae29d26393db63bf2f3fb;p=yangtools.git diff --git a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index f5f85c37c4..1be883cd2b 100644 --- a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -30,6 +30,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; @@ -156,7 +157,16 @@ abstract class StatementContextBase, E extends private boolean implicitDeclaredFlag; // TODO: we a single byte of alignment shadow left, we should think how we can use it to cache information we build - // during buildEffective() + // during InferredStatementContext.tryToReusePrototype(). We usually end up being routed to + // copyAsChildOfImpl() -- which performs an eager instantiation and checks for changes afterwards. We should + // be able to capture how parent scope affects the copy in a few bits. If we can do that, than we can reap + // the benefits by just examining new parent context and old parent context contribution to the state. If + // their impact is the same, we can skip instantiation of statements and directly reuse them (individually, + // or as a complete file). + // + // Whatever we end up tracking, we need to track two views of that -- for the statement itself + // (sans substatements) and a summary of substatements. I think it should be possible to get this working + // with 2x5bits -- we have up to 15 mutable bits available if we share the field with implicitDeclaredFlag. // Copy constructor used by subclasses to implement reparent() StatementContextBase(final StatementContextBase original) { @@ -321,13 +331,12 @@ abstract class StatementContextBase, E extends @Override public final , Z extends EffectiveStatement> - Mutable addUndeclaredSubstatement(final StatementSupport support, final X arg) { + Mutable createUndeclaredSubstatement(final StatementSupport support, final X arg) { requireNonNull(support); checkArgument(support instanceof UndeclaredStatementFactory, "Unsupported statement support %s", support); final var ret = new UndeclaredStmtCtx<>(this, support, arg); support.onStatementAdded(ret); - addEffectiveSubstatement(ret); return ret; } @@ -342,6 +351,19 @@ abstract class StatementContextBase, E extends return resized; } + static final void afterAddEffectiveSubstatement(final Mutable substatement) { + // Undeclared statements still need to have 'onDeclarationFinished()' triggered + if (substatement instanceof UndeclaredStmtCtx) { + finishDeclaration((UndeclaredStmtCtx) substatement); + } + } + + // Split out to keep generics working without a warning + private static , Z extends EffectiveStatement> void finishDeclaration( + final UndeclaredStmtCtx substatement) { + substatement.definition().onDeclarationFinished(substatement, ModelProcessingPhase.FULL_DECLARATION); + } + @Override public final void addEffectiveSubstatements(final Collection> statements) { if (!statements.isEmpty()) { @@ -423,19 +445,6 @@ abstract class StatementContextBase, E extends abstract @NonNull E createEffective(@NonNull StatementFactory factory); - /** - * Routing of the request to build an effective statement from {@link InferredStatementContext} towards the original - * definition site. This is needed to pick the correct instantiation method: for declared statements we will - * eventually land in {@link AbstractResumedStatement}, for underclared statements that will be - * {@link UndeclaredStmtCtx}. - * - * @param factory Statement factory - * @param ctx Inferred statement context, i.e. where the effective statement is instantiated - * @return Built effective stateue - */ - abstract @NonNull E createInferredEffective(@NonNull StatementFactory factory, - @NonNull InferredStatementContext ctx); - /** * Return a stream of declared statements which can be built into an {@link EffectiveStatement}, as per * {@link StmtContext#buildEffective()} contract. @@ -734,7 +743,7 @@ abstract class StatementContextBase, E extends return Optional.ofNullable(copyAsChildOfImpl(parent, type, targetModule)); } - private ReactorStmtCtx copyAsChildOfImpl(final Mutable parent, final CopyType type, + private @Nullable ReactorStmtCtx copyAsChildOfImpl(final Mutable parent, final CopyType type, final QNameModule targetModule) { final StatementSupport support = definition.support(); final CopyPolicy policy = support.copyPolicy(); @@ -772,7 +781,7 @@ abstract class StatementContextBase, E extends return canReuseCurrent(copy) ? this : copy; } - private boolean canReuseCurrent(final ReactorStmtCtx copy) { + private boolean canReuseCurrent(final @NonNull ReactorStmtCtx copy) { // Defer to statement factory to see if we can reuse this object. If we can and have only context-independent // substatements we can reuse the object. More complex cases are handled indirectly via the copy. return definition.getFactory().canReuseCurrent(copy, this, buildEffective().effectiveSubstatements()) @@ -818,6 +827,7 @@ abstract class StatementContextBase, E extends copy = new InferredStatementContext<>(result, original, childCopyType, type, targetModule); result.addEffectiveSubstatement(copy); + result.definition.onStatementAdded(result); } else { result = copy = new InferredStatementContext<>(this, original, type, type, targetModule); }