/** * AST-based type inference for BrightScript. * * Tracks the possible types of variables through: * - CreateObject("roFoo") → type is "roFoo" * - Parameter type annotations: `param as Integer` → "Integer" * - Numeric/string/boolean literal assignments * - Return type annotations on functions * - Type designator suffixes: `x$` → String, `x%` → Integer, etc. * * `TypeMap` stays a flat `Map` — same shape as before — * for source compatibility with existing consumers (`getVariableType` reads * it exactly as it always has). What changed is that every binding now also * records the function scope it was collected in (`scopeOwner`), so a * scope-aware caller can use `getVariableTypeInScope` to resolve a name the * way BrightScript actually would: `x` in one function must never resolve to * an unrelated `x` local to a different function, and neither should resolve * to an `m.x` field — those live in a third, distinct namespace. The legacy * `getVariableType(typeMap, name)` is unchanged and still doesn't make this * distinction; prefer `getVariableTypeInScope` for anything scope-sensitive. */ import { SyntaxNode } from '../syntaxNode.js'; import { Scope } from '../scope.js'; /** * The scope a `TypeBinding` was collected in: a function/sub `SyntaxNode`, * `null` for file (top-level) scope, or the sentinel `'m-context'` for an * `m.field = value` binding — `m` fields live in a namespace of their own, * not a particular function's locals, so they never match a plain-variable * scope lookup in `getVariableTypeInScope`. */ export type TypeScopeOwner = SyntaxNode | 'm-context' | null; export interface TypeBinding { name: string; typeName: string; source: 'createobject' | 'param-annotation' | 'literal' | 'return-type' | 'designator'; line: number; column: number; /** See `TypeScopeOwner`. */ scopeOwner: TypeScopeOwner; } export type TypeMap = Map; export declare function inferTypesFromAst(root: SyntaxNode): TypeMap; /** * Legacy, scope-blind lookup: the first matching binding across the WHOLE * file, regardless of which function it came from. Two different functions' * same-named locals collide here — kept unchanged for existing callers; * prefer `getVariableTypeInScope` for anything that needs to be correct * across more than one function. */ export declare function getVariableType(typeMap: TypeMap, varName: string): string | undefined; /** * Scope-correct lookup: resolves `varName` the way BrightScript would, * walking from `scope` up through enclosing function scopes (mirroring * `resolve()` in scope.ts) and only considering bindings whose `scopeOwner` * is one of those scopes' owners. Never matches an `m-context` binding — * pass `varName` of `'m'` field name and check `getVariableType`'s * `m-context`-scoped bindings separately (or use `analyzeContext` from * `contextAnalysis.ts`, the dedicated `m` API) if that's what's needed. */ export declare function getVariableTypeInScope(typeMap: TypeMap, varName: string, scope: Scope): string | undefined; //# sourceMappingURL=typeInference.d.ts.map