Class ObligationCensus
- All Implemented Interfaces:
Consumer<org.antlr.v4.runtime.tree.ParseTree>
ValueTrackingAnalyzer, enumerating the contract/partiality obligations in each
callable body and marking those an existing analysis already discharges, then squirrelling the tally
(OBLIGATIONS_TOTAL/DISCHARGED/UNDISCHARGED) on the construct symbol — the same static,
every-build role InputVarietyDenominatorRecorder plays for input variety, and the same
squirrel lifecycle as COMPLEXITY/INPUT_VARIETY_*.
Why inline, not a post-hoc exit walk. Discharge for a guarded division
(if y <> 0 then x / y) or a provably-true require depends on the narrowed
value state at the obligation's own program point — state ValueTrackingAnalyzer holds only
during the walk and merges away by construct exit. So detection happens inline at the
obligation node (checkArithmetic(EK9Parser.ExpressionContext) from exitExpression, checkRequire(EK9Parser.RequireStatementContext) from
enterRequireStatement), reading the live narrowed state exactly as the sibling flow checkers
(FlowConditionOrError, RedundantIsSetCheckOrError) do (§2.5). Only the squirrel — the
pop of the finished tally — happens at construct exit, wired into the same exit .andThen
chain as InputVarietyDenominatorRecorder.
A per-callable scope stack isolates nested callables (a dynamic function's obligations never fold into the enclosing method). Advisory only — the census emits no error; undischarged obligations are the Layer-2 solver's candidates, surfaced by the ungated Contract roundel.
-
Constructor Summary
ConstructorsConstructorDescriptionObligationCensus(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker, LiteralExtractor literalExtractor) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(org.antlr.v4.runtime.tree.ParseTree node) Close the current callable's obligation scope and squirrel its tally on the construct symbol.(package private) voidCount a division / modulo / remainder as aDIV_BY_ZEROobligation, discharged when the divisor is provably non-zero from the narrowed flow state.(package private) voidCount a constrained-type construction (Age(expr)forAge constrain as ...) as aCONSTRAINED_CONSTRUCTIONobligation — a construction-timePanicrisk.(package private) voidCount each container unwrap (Optional.get/Result.ok/error/Iterator.next) in an object-access chain as aCONTAINER_UNWRAPobligation, GUARD-discharged when the access is safe.(package private) voidCount arequireas aREQUIREobligation, discharged when its expression is provably true from the narrowed flow state at the require's program point.(package private) voidOpen a fresh obligation scope on entry of a callable (function / method / operator / service operation / dynamic function).
-
Constructor Details
-
ObligationCensus
ObligationCensus(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker, LiteralExtractor literalExtractor)
-
-
Method Details
-
enterConstruct
void enterConstruct()Open a fresh obligation scope on entry of a callable (function / method / operator / service operation / dynamic function). Paired withaccept(ParseTree)on the callable's exit. -
accept
public void accept(org.antlr.v4.runtime.tree.ParseTree node) Close the current callable's obligation scope and squirrel its tally on the construct symbol. Wired as aConsumer<ParseTree>into the exit.andThenchain, so it runs after the body walk has filled the tally (and aftervalueTracker.exitCallableScope()— the tally is already complete, no live value state is read here). -
checkArithmetic
Count a division / modulo / remainder as aDIV_BY_ZEROobligation, discharged when the divisor is provably non-zero from the narrowed flow state. Called fromexitExpressionso theValueTrackingAnalyzernarrowing is settled (insideif y <> 0the divisor is narrowed to exclude zero). -
checkRequire
Count arequireas aREQUIREobligation, discharged when its expression is provably true from the narrowed flow state at the require's program point. Called fromenterRequireStatement; the state read is what is known before the require, which is exactly the question "does this precondition already hold here?". -
checkContainerUnwrap
Count each container unwrap (Optional.get/Result.ok/error/Iterator.next) in an object-access chain as aCONTAINER_UNWRAPobligation, GUARD-discharged when the access is safe. Delegates the chain walk + guard decision toContainerUnwrapObligations, which reuses the same predicates as the E08030 checker. -
checkConstrainedConstruction
Count a constrained-type construction (Age(expr)forAge constrain as ...) as aCONSTRAINED_CONSTRUCTIONobligation — a construction-timePanicrisk. Discharged only when the argument is a literal the compile-time evaluator proves inside the interval; a computed argument stays undischarged (the Layer-2 candidate). ReusesConstrainedConstructionResolver— the same site definition the E07xxx checker uses.
-