mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 18:39:24 +00:00
* fix(managed): preserve duplicate GUID stream ambiguity * fix(managed): preserve ambiguous metadata stream declarations (#12226) Use one stream declaration owner for heap and table diagnostics. Keep user strings and row-layout uncertainty separate from independent PE/CLI observations. * test(managed): separate heap entries from cache behavior * fix(managed): preserve duplicate blob heap ambiguity (#12258) Resolve #Blob in the shared stream layout. Preserve nil references and independent facts without emitting unsupported keys, signatures or hashes.
103 lines
3.4 KiB
TypeScript
103 lines
3.4 KiB
TypeScript
import type { ManagedTypeReferenceLookup } from "../domain/managed/managedTypeReferences.js";
|
|
import type { ManagedParseIssue } from "../domain/managed/managedArtifact.js";
|
|
import {
|
|
fullName,
|
|
specSignatureFacts,
|
|
type SignatureTypeName,
|
|
type TypeRange,
|
|
} from "../domain/managed/managedMemberInspectorCore.js";
|
|
import {
|
|
metadataRowOffset,
|
|
type ManagedMetadataLayout,
|
|
} from "../domain/managed/managedMetadataLayout.js";
|
|
import {
|
|
metadataRowCursor,
|
|
type MetadataTokenFact,
|
|
metadataToken,
|
|
readMetadataBlob,
|
|
} from "../domain/managed/managedMetadataHeaps.js";
|
|
import { readManagedValue } from "../domain/managed/managedReaderFailure.js";
|
|
|
|
/**
|
|
* Name the type a TypeDef, TypeRef, or generic-instantiation TypeSpec token
|
|
* denotes, in the namespace-qualified form TypeDef `full_name` uses, once per
|
|
* token. Other decoded TypeSpecs retain a null display name while a resolved
|
|
* signature can still establish a local row. Malformed or
|
|
* unsupported rows and blobs are reported to `issues` and also stay null,
|
|
* except that a TypeRef with an invalid ResolutionScope keeps its readable name.
|
|
*/
|
|
export const typeNameLookup = (
|
|
bytes: Buffer,
|
|
layout: ManagedMetadataLayout,
|
|
ranges: readonly TypeRange[],
|
|
issues: ManagedParseIssue[],
|
|
references: ManagedTypeReferenceLookup,
|
|
signatureTypeName: SignatureTypeName,
|
|
): {
|
|
readonly name: (reference: TypeReference) => string | null;
|
|
readonly isResolvedTypeSpec: (reference: TypeReference) => boolean;
|
|
} => {
|
|
type Facts = { readonly name: string | null; readonly resolvedSpec: boolean };
|
|
const unknown: Facts = { name: null, resolvedSpec: false };
|
|
const names = new Map<string, Facts>();
|
|
const definitionName = (table: 1 | 2, row: number): string | null => {
|
|
if (table === 2) {
|
|
metadataRowOffset(layout, 2, row);
|
|
return ranges[row - 1]?.fullName ?? null;
|
|
}
|
|
const reference = references(row);
|
|
return reference === null
|
|
? null
|
|
: fullName(reference.namespace, reference.name);
|
|
};
|
|
const specName = (row: number): Facts => {
|
|
const cursor = metadataRowCursor(bytes, layout, 27, row);
|
|
const spec = readMetadataBlob(
|
|
bytes,
|
|
layout,
|
|
cursor.readIndex(layout.blobIndexSize),
|
|
);
|
|
const owner = {
|
|
form: "type",
|
|
scope: `metadata.TypeSpec:${metadataToken(27, row)}`,
|
|
offset: cursor.start,
|
|
} as const;
|
|
const { nominalGenericType, resolvedSha256 } = specSignatureFacts(
|
|
layout,
|
|
spec,
|
|
owner,
|
|
signatureTypeName,
|
|
);
|
|
return {
|
|
name:
|
|
nominalGenericType === null
|
|
? null
|
|
: definitionName(nominalGenericType.table, nominalGenericType.row),
|
|
resolvedSpec: resolvedSha256 !== null,
|
|
};
|
|
};
|
|
const read = (reference: TypeReference): Facts => {
|
|
if (reference === null) return unknown;
|
|
const { token, table, row } = reference;
|
|
if (names.has(token)) return names.get(token) ?? unknown;
|
|
const name =
|
|
readManagedValue(
|
|
() =>
|
|
table === 27
|
|
? specName(row)
|
|
: table === 1 || table === 2
|
|
? { name: definitionName(table, row), resolvedSpec: false }
|
|
: unknown,
|
|
issues,
|
|
) ?? unknown;
|
|
names.set(token, name);
|
|
return name;
|
|
};
|
|
return {
|
|
name: (reference) => read(reference).name,
|
|
isResolvedTypeSpec: (reference) => read(reference).resolvedSpec,
|
|
};
|
|
};
|
|
|
|
type TypeReference = Pick<MetadataTokenFact, "table" | "row" | "token"> | null;
|