registerBridges static method
Registers all bridges with an interpreter.
importPath is the package import path that D4rt scripts will use
to access these classes (e.g., 'package:tom_build/tom.dart').
Implementation
static void registerBridges(D4rt interpreter, String importPath) {
// Step #17 — register deferred factory thunks (not pre-built
// BridgedClass objects): a script touching N of the M classes
// materializes ≈N (each thunk builds its class on first resolve).
final classThunks = bridgeClassThunks();
final classTypes = bridgeClassTypes();
final classSources = classSourceUris();
for (final entry in classThunks.entries) {
interpreter.registerBridgedClassLazy(
entry.key,
classTypes[entry.key]!,
entry.value,
importPath,
sourceUri: classSources[entry.key],
);
}
// Register the flattened native supertype table so
// interpreted subclasses pass subtype checks against bridged
// ancestors. Idempotent — safe to call per barrel.
BridgedClass.registerSupertypes(classSupertypes());
// Register bridged enums with source URIs for deduplication
final enums = bridgedEnums();
final enumSources = enumSourceUris();
for (final enumDef in enums) {
interpreter.registerBridgedEnum(
enumDef,
importPath,
sourceUri: enumSources[enumDef.name],
);
}
// Register global variables
registerGlobalVariables(interpreter, importPath);
// Register global functions with source URIs for deduplication
final funcs = globalFunctions();
final funcSources = globalFunctionSourceUris();
final funcSigs = globalFunctionSignatures();
for (final entry in funcs.entries) {
interpreter.registertopLevelFunction(
entry.key,
entry.value,
importPath,
sourceUri: funcSources[entry.key],
signature: funcSigs[entry.key],
);
}
// Register bridged extensions with source URIs for deduplication
final extensions = bridgedExtensions();
final extSources = extensionSourceUris();
for (final extDef in extensions) {
final extKey = '${extDef.name ?? '<unnamed>'}@${extDef.onTypeName}';
interpreter.registerBridgedExtension(
extDef,
importPath,
sourceUri: extSources[extKey],
);
}
// Register function typedefs for type resolution
final typedefs = functionTypedefs();
final typedefArity = functionTypedefArity();
for (final name in typedefs) {
final arity = typedefArity[name];
interpreter.registerFunctionTypedef(
name,
importPath,
requiredPositional: arity?.required,
maxPositional: arity?.max,
);
}
// GEN-107: Register library re-exports
for (final r in bridgeReExports()) {
interpreter.registerLibraryReExport(
r.source,
r.target,
show: r.show,
hide: r.hide,
);
}
}