Class NestingDepthCounter

java.lang.Object
org.ek9lang.compiler.phase5.NestingDepthCounter

class NestingDepthCounter extends Object
Tracks nesting depth within functions/methods/operators. Increments on entering control structures (if, while, for, switch, try, etc.), decrements on exit. Records maximum depth reached per function scope. This is used to enforce nesting depth limits, preventing deeply nested code that becomes hard to read and maintain.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    Increment depth when entering a control structure.
    (package private) void
    Decrement depth when exiting a control structure.
    (package private) boolean
    Check if there are any scopes on the stack.
    (package private) int
    Pop scope and return max depth reached.
    (package private) void
    Push new scope when entering function/method/operator.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NestingDepthCounter

      NestingDepthCounter()
  • Method Details

    • pushScope

      void pushScope()
      Push new scope when entering function/method/operator.
    • popScope

      int popScope()
      Pop scope and return max depth reached. Called when exiting function/method/operator.
      Returns:
      the maximum nesting depth reached in this scope
    • enterNesting

      void enterNesting()
      Increment depth when entering a control structure. Updates max depth if this is the deepest we've been.
    • exitNesting

      void exitNesting()
      Decrement depth when exiting a control structure.
    • isEmpty

      boolean isEmpty()
      Check if there are any scopes on the stack.
      Returns:
      true if stack has no contents