Skip to content

fix(vba): conditional-compilation evaluator — Win32/Win16, True=-1 semantics, #Const support #51

Description

@ardelperal

Priority

P3 — robustness. Today's fixtures pass, but the failure mode is silent loss of ACTIVE code.

Context

preprocessConditionalCompilation (src/extraction/vba-preprocess.ts ~198) blanks inactive #If/#ElseIf/#Else/#End If branches, evaluating expressions with VBA7=true, Win64=true, Mac=false and a strict character whitelist; anything unrecognized evaluates to false — which blanks the branch and silently drops real symbols.

Current gaps

  1. Win32 / Win16 unmapped#If Win32 Then (very common legacy guard; Win32 is True on all modern Windows VBA) evaluates false and its ACTIVE branch is blanked.
  2. True maps to JS true, not VBA's -1 — numeric comparisons diverge: real VBA evaluates #If Win64 = -1 Then as True; the whitelist also rejects -1 outright (no - allowed), so the branch blanks.
  3. No #Const support#Const MODO_DEBUG = True + #If MODO_DEBUG Then blanks the branch even though the user set it True (the identifier fails the whitelist). The #Const line itself also passes through to the sweeps as a normal line (harmless today, but inconsistent).

Expected behavior

  • Win32 → true (-1), Win16 → false (0) alongside the existing three constants.
  • Truth values evaluate numerically as -1/0 so = -1, = 0, = 1 comparisons match genuine VBA semantics; whitelist accepts unary minus.
  • A file-scoped #Const NAME = <literal or const-expression> table, consulted before the unknown-identifier fallback; #Const lines are blanked like other directives.
  • Unknown identifiers still evaluate false (unchanged, conservative).

Implementation sketch

  • Build the eval on integers: substitute constants with -1/0, translate And/Or/Not/<>/= as bitwise/comparison on numbers (VBA CC operators are logical on True=-1 — document the chosen simplification), extend the whitelist with -.
  • Parse #Const in the main directive loop (before the generic line pass), storing into a per-call map; evaluate its RHS with the same evaluator.
  • Keep the hard guarantee: line-count parity and "never throw" (fall back to false on any evaluation error).

Acceptance criteria

  • #If Win32 Then / <code> / #End If keeps <code>.
  • #Const X = True + #If X Then keeps the branch; #Const X = False blanks it.
  • #If Win64 = -1 Then keeps the branch.
  • All existing extraction-vba-preprocess.test.ts cases green; line-count parity preserved.

Validation

Re-index C:\Proyectos\dysflow\E2E_testing\src (uses #If Win64 = 1, #ElseIf VBA7, #If Mac); node counts must not regress; any delta must be explainable as newly-active branches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vbaVBA/Access-specific work (parent codegraph product)bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions