Class IntScopeCounter

java.lang.Object
org.ek9lang.compiler.phase5.IntScopeCounter
Direct Known Subclasses:
InjectionCounter, StatementCounter

class IntScopeCounter extends Object
A stack of integer counters, one per nested function/method/operator scope, accumulated during AST traversal. Shared scaffolding for the per-scope metric counters; pushScope()/popScope() bracket a scope and incrementInnermost() bumps the count of the innermost open scope.

Subclasses provide their own incrementCount so each can choose its empty-stack policy deliberately: a statement is always inside a scope (so StatementCounter asserts), whereas a counted construct may legitimately occur outside any function/method scope (so InjectionCounter silently ignores it). A popScope() must always be balanced by a push, so it asserts here.

  • Constructor Details

    • IntScopeCounter

      IntScopeCounter()
  • Method Details

    • pushScope

      void pushScope()
      Push a new scope, initialising its count to zero.
    • popScope

      int popScope()
      Pop the innermost scope and return its accumulated count.
    • isNotEmpty

      boolean isNotEmpty()
      Whether any scope is currently open.
    • incrementInnermost

      protected void incrementInnermost()
      Add one to the innermost open scope's count. Caller must ensure a scope is open.