Skip to main content

Module canonical

Module canonical 

Source
Expand description

IR canonicalization.

Walks an Expr / Statement tree and applies two normalising passes so downstream consumers (lineage, bindgen, symbol cross-check) work against a single canonical shape:

  1. Fully-qualify names. A bare reference like employees in a routine declared in schema HR is rewritten to HR.EMPLOYEES. The caller supplies a CanonicalisationContext carrying the active schema + the package containing the reference (if any) so the resolver knows what scope to consult.
  2. Desugar implicit cursor FOR loops. PL/SQL accepts FOR row IN (SELECT … FROM …) LOOP … as syntactic sugar for an explicit cursor declaration. The canonicaliser rewrites this shape into ForLoop whose range_text carries the SELECT and whose body_text is the same; the side-effect is to flag the loop’s iterator as having an implicit %ROWTYPE of the select projection so the bindings layer can resolve it.

Anything outside these two passes is left untouched — the canonicaliser is a thin layer above the IR shape ships from expr.rs + stmt.rs.

§/oracle evidence

  • DATABASE-REFERENCE.md PL/SQL Language Reference — Naming chapter governs how a bare reference resolves against the current schema; the Cursor FOR Loop section spells out the implicit-cursor desugaring rule.
  • LOW-LEVEL-CATALOGS.md Data Dictionary View Families — ALL_OBJECTS is the server-side authority for whether a fully-qualified name actually exists; the offline canonicaliser defers that cross-check to a later stage.

Structs§

CanonicalisationContext
Caller-supplied state that drives canonicalization. The active schema is required; an optional active package scopes references to package-local names first.
CanonicalisationStats

Functions§

canonicalize_expr
Canonicalize one expression against ctx. Returns the rewritten Expr plus the stats.
canonicalize_statements
Canonicalize a statement-body slice. Walks every statement and applies expression canonicalization to embedded rhs_text / cond_text slices (re-lowered through lower_expression first).