Class SentenceIndexCounterDependency
- Namespace
- Hi.NcParsers.Dependencys.SystemWired
- Assembly
- HiMech.dll
Per-session monotonically-increasing SentenceIndex allocator. Holds the counter as a private field; Allocate() returns the next unused value and increments. OnSessionReset() rewinds to 0 — the owning RunNcLines(string, IEnumerable<string>, MachiningSession, StepDiagnosticProgress, NcDiagnosticProgress, CancellationToken) invokes it via the ISessionResettable sweep on the same edge that initializes a fresh NcRunnerSessionState, so a controller power-reset clears both the syntax-piece pipeline and this counter in lock-step.
This dependency exists to fix the sentence-index double-booking bug:
before it, the host file's lazy enumerator numbered pieces from
layers[0].Count captured at file-append time while subprogram /
macro / control-flow re-segmentation numbered from
layers[0].Last.Value.SentenceIndex + 1 — two independent
sequences that overlap as soon as a call is inlined mid-stream
(host blocks after M98 and the inlined body shared the same
indices). With this counter, GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken)
allocates one value per piece at materialization time, which the lazy
pipeline pulls in execution order — indices are session-globally
unique and strictly increasing along the executed stream, at the cost
of no longer being contiguous per file (eager label scans discard
their pre-label prefix, leaving gaps).
Values are never negative, preserving the -1 "not in pipeline"
sentinel used by SentenceIndex and
SentenceIndex.
When this dependency is absent from the pipeline list,
GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) falls back to the
caller-supplied begin-index numbering — the legacy colliding behavior.
Only code-built runners can hit that fallback: XML rehydration back-fills
a missing instance (the SoftNcRunner XML constructor's
system-wired back-fill), because saves that predate this dependency
never self-heal by round-tripping — re-saving stamps a new
ApiVersion on the same incomplete list.
public class SentenceIndexCounterDependency : INcDependency, IMakeXmlSource, ISessionResettable
- Inheritance
-
SentenceIndexCounterDependency
- Implements
- Inherited Members
- Extension Methods
Constructors
SentenceIndexCounterDependency()
Initializes a new instance with the counter at 0.
public SentenceIndexCounterDependency()
Properties
XName
XML element name used to register this dependency with XFactory.
public static string XName { get; }
Property Value
Methods
Allocate()
Returns the next unused sentence index and post-increments the counter. First call after construction or OnSessionReset() returns 0.
public int Allocate()
Returns
MakeXmlSource(string, string, bool)
Runtime-only dependency — the live counter value is per-session and not meaningful to persist; serialization writes only the empty element so the dependency survives an XML round-trip with the counter implicitly reset to 0.
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
Parameters
Returns
OnSessionReset()
Rewinds the counter to 0. Called by RunNcLines(string, IEnumerable<string>, MachiningSession, StepDiagnosticProgress, NcDiagnosticProgress, CancellationToken) via the ISessionResettable sweep on the same edge that initializes a fresh session pipeline so a single brand-preset runner can be reused across sessions without leaking sentence indices from the previous session.
public void OnSessionReset()
Reg(XFactory)
Registers this type's deserializer with the given XFactory
(or Default when factory is
null). Idempotent.
public static void Reg(XFactory factory = null)
Parameters
factoryXFactory