Use TypeRef.index instead of TypeRef.getIndex()
This commit is contained in:
Родитель
dbc2ce5e63
Коммит
61af96b4e8
|
@ -828,7 +828,7 @@ export abstract class ConvenienceRenderer extends Renderer {
|
|||
}
|
||||
|
||||
protected makeHandlebarsContextForType(t: Type): StringMap {
|
||||
const value: StringMap = { type: { kind: t.kind, index: t.typeRef.getIndex() } };
|
||||
const value: StringMap = { type: { kind: t.kind, index: t.typeRef.index } };
|
||||
const maybeName = this.nameStoreView.tryGet(t);
|
||||
if (maybeName !== undefined) {
|
||||
value.assignedName = this.names.get(maybeName);
|
||||
|
@ -872,7 +872,7 @@ export abstract class ConvenienceRenderer extends Renderer {
|
|||
value.members = members;
|
||||
}
|
||||
|
||||
const index = t.typeRef.getIndex();
|
||||
const index = t.typeRef.index;
|
||||
while (allTypes.length <= index) {
|
||||
allTypes.push(undefined);
|
||||
}
|
||||
|
@ -881,13 +881,13 @@ export abstract class ConvenienceRenderer extends Renderer {
|
|||
|
||||
const namedTypes: any[] = [];
|
||||
const addNamedType = (t: Type): void => {
|
||||
namedTypes.push(allTypes[t.typeRef.getIndex()]);
|
||||
namedTypes.push(allTypes[t.typeRef.index]);
|
||||
};
|
||||
this.forEachNamedType("none", addNamedType, addNamedType, addNamedType);
|
||||
|
||||
const topLevels: StringMap = {};
|
||||
this.topLevels.forEach((t, name) => {
|
||||
const value = allTypes[t.typeRef.getIndex()];
|
||||
const value = allTypes[t.typeRef.index];
|
||||
value.assignedTopLevelName = this.names.get(this.nameStoreView.getForTopLevel(name));
|
||||
topLevels[name] = value;
|
||||
});
|
||||
|
|
|
@ -86,7 +86,7 @@ export function declarationsForGraph(
|
|||
): DeclarationIR {
|
||||
/*
|
||||
function nodeTitle(t: Type): string {
|
||||
const indexAndKind = `${t.typeRef.getIndex()} ${t.kind}`;
|
||||
const indexAndKind = `${t.typeRef.index} ${t.kind}`;
|
||||
if (t.hasNames) {
|
||||
return `${indexAndKind} ${t.getCombinedName()}`;
|
||||
} else {
|
||||
|
|
|
@ -28,7 +28,7 @@ export function isPrimitiveTypeKind(kind: TypeKind): kind is PrimitiveTypeKind {
|
|||
}
|
||||
|
||||
function triviallyStructurallyCompatible(x: Type, y: Type): boolean {
|
||||
if (x.typeRef.getIndex() === y.typeRef.getIndex()) return true;
|
||||
if (x.typeRef.index === y.typeRef.index) return true;
|
||||
if (x.kind === "none" || y.kind === "none") return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -102,13 +102,13 @@ export abstract class Type {
|
|||
|
||||
while (workList.length > 0) {
|
||||
let [a, b] = defined(workList.pop());
|
||||
if (a.typeRef.getIndex() > b.typeRef.getIndex()) {
|
||||
if (a.typeRef.index > b.typeRef.index) {
|
||||
[a, b] = [b, a];
|
||||
}
|
||||
|
||||
if (!a.isPrimitive()) {
|
||||
let ai = a.typeRef.getIndex();
|
||||
let bi = b.typeRef.getIndex();
|
||||
let ai = a.typeRef.index;
|
||||
let bi = b.typeRef.index;
|
||||
|
||||
let found = false;
|
||||
for (const [dai, dbi] of done) {
|
||||
|
|
|
@ -33,14 +33,10 @@ import { defined, assert, panic, assertNever, setUnion, mapOptional } from "./Su
|
|||
|
||||
// FIXME: Get rid of this eventually
|
||||
export class TypeRef {
|
||||
constructor(readonly graph: TypeGraph, readonly maybeIndex: number) {}
|
||||
|
||||
getIndex(): number {
|
||||
return this.maybeIndex;
|
||||
}
|
||||
constructor(readonly graph: TypeGraph, readonly index: number) {}
|
||||
|
||||
deref(): [Type, TypeAttributes] {
|
||||
return this.graph.atIndex(this.getIndex());
|
||||
return this.graph.atIndex(this.index);
|
||||
}
|
||||
|
||||
equals(other: any): boolean {
|
||||
|
@ -48,17 +44,17 @@ export class TypeRef {
|
|||
return false;
|
||||
}
|
||||
assert(this.graph === other.graph, "Comparing type refs of different graphs");
|
||||
return this.maybeIndex === other.maybeIndex;
|
||||
return this.index === other.index;
|
||||
}
|
||||
|
||||
hashCode(): number {
|
||||
return this.maybeIndex | 0;
|
||||
return this.index | 0;
|
||||
}
|
||||
}
|
||||
|
||||
function provenanceToString(p: Set<TypeRef>): string {
|
||||
return p
|
||||
.map(r => r.getIndex())
|
||||
.map(r => r.index)
|
||||
.toList()
|
||||
.sort()
|
||||
.map(i => i.toString())
|
||||
|
@ -112,7 +108,7 @@ export class TypeBuilder {
|
|||
addTopLevel(name: string, tref: TypeRef): void {
|
||||
// assert(t.typeGraph === this.typeGraph, "Adding top-level to wrong type graph");
|
||||
assert(!this.topLevels.has(name), "Trying to add top-level with existing name");
|
||||
assert(this.types[tref.getIndex()] !== undefined, "Trying to add a top-level type that doesn't exist (yet?)");
|
||||
assert(this.types[tref.index] !== undefined, "Trying to add a top-level type that doesn't exist (yet?)");
|
||||
this.topLevels = this.topLevels.set(name, tref);
|
||||
}
|
||||
|
||||
|
@ -129,7 +125,7 @@ export class TypeBuilder {
|
|||
}
|
||||
|
||||
private commitType = (tref: TypeRef, t: Type): void => {
|
||||
const index = tref.getIndex();
|
||||
const index = tref.index;
|
||||
// const name = names !== undefined ? ` ${names.combinedName}` : "";
|
||||
// console.log(`committing ${t.kind}${name} to ${index}`);
|
||||
assert(this.types[index] === undefined, "A type index was committed twice");
|
||||
|
@ -141,8 +137,8 @@ export class TypeBuilder {
|
|||
creator: (tref: TypeRef) => T,
|
||||
attributes: TypeAttributes | undefined
|
||||
): TypeRef {
|
||||
if (forwardingRef !== undefined && forwardingRef.maybeIndex !== undefined) {
|
||||
assert(this.types[forwardingRef.maybeIndex] === undefined);
|
||||
if (forwardingRef !== undefined && forwardingRef.index !== undefined) {
|
||||
assert(this.types[forwardingRef.index] === undefined);
|
||||
}
|
||||
const tref = forwardingRef !== undefined ? forwardingRef : this.reserveTypeRef();
|
||||
if (attributes !== undefined) {
|
||||
|
@ -166,12 +162,12 @@ export class TypeBuilder {
|
|||
if (attributes === undefined) {
|
||||
attributes = Map();
|
||||
}
|
||||
const index = tref.getIndex();
|
||||
const index = tref.index;
|
||||
this.typeAttributes[index] = combineTypeAttributes(this.typeAttributes[index], attributes);
|
||||
}
|
||||
|
||||
makeNullable(tref: TypeRef, attributes: TypeAttributes): TypeRef {
|
||||
const t = defined(this.types[tref.getIndex()]);
|
||||
const t = defined(this.types[tref.index]);
|
||||
if (t.kind === "null" || t.kind === "any") {
|
||||
return tref;
|
||||
}
|
||||
|
@ -752,11 +748,11 @@ export class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|||
|
||||
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
||||
|
||||
const first = this.reconstitutedTypes.get(this.getMapTarget(typeRefs[0]).getIndex());
|
||||
const first = this.reconstitutedTypes.get(this.getMapTarget(typeRefs[0]).index);
|
||||
if (first === undefined) return undefined;
|
||||
|
||||
for (let i = 1; i < typeRefs.length; i++) {
|
||||
const other = this.reconstitutedTypes.get(this.getMapTarget(typeRefs[i]).getIndex());
|
||||
const other = this.reconstitutedTypes.get(this.getMapTarget(typeRefs[i]).index);
|
||||
if (first !== other) return undefined;
|
||||
}
|
||||
|
||||
|
@ -777,7 +773,7 @@ export class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|||
attributes = combineTypeAttributesOfTypes(attributeSources);
|
||||
}
|
||||
|
||||
const index = originalRef.getIndex();
|
||||
const index = originalRef.index;
|
||||
|
||||
if (this.debugPrint) {
|
||||
console.log(`${this.debugPrintIndentation}reconstituting ${index}`);
|
||||
|
@ -787,7 +783,7 @@ export class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|||
const reconstituter = new TypeReconstituter(this, this.alphabetizeProperties, attributes, undefined, tref => {
|
||||
if (this.debugPrint) {
|
||||
this.changeDebugPrintIndent(-1);
|
||||
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${tref.getIndex()}`);
|
||||
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${tref.index}`);
|
||||
}
|
||||
|
||||
const alreadyReconstitutedType = this.reconstitutedTypes.get(index);
|
||||
|
@ -830,7 +826,7 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
for (const types of setsToReplace) {
|
||||
const set = Set(types);
|
||||
set.forEach(t => {
|
||||
const index = t.typeRef.getIndex();
|
||||
const index = t.typeRef.index;
|
||||
assert(!this._setsToReplaceByMember.has(index), "A type is member of more than one set to be replaced");
|
||||
this._setsToReplaceByMember = this._setsToReplaceByMember.set(index, set);
|
||||
});
|
||||
|
@ -862,15 +858,15 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
if (this.debugPrint) {
|
||||
console.log(
|
||||
`${this.debugPrintIndentation}replacing set ${typesToReplace
|
||||
.map(t => t.typeRef.getIndex().toString())
|
||||
.join(",")} as ${forwardingRef.getIndex()}`
|
||||
.map(t => t.typeRef.index.toString())
|
||||
.join(",")} as ${forwardingRef.index}`
|
||||
);
|
||||
this.changeDebugPrintIndent(1);
|
||||
}
|
||||
|
||||
typesToReplace.forEach(t => {
|
||||
const originalRef = t.typeRef;
|
||||
const index = originalRef.getIndex();
|
||||
const index = originalRef.index;
|
||||
this.reconstitutedTypes = this.reconstitutedTypes.set(index, forwardingRef);
|
||||
this._setsToReplaceByMember = this._setsToReplaceByMember.remove(index);
|
||||
});
|
||||
|
@ -881,8 +877,8 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
this.changeDebugPrintIndent(-1);
|
||||
console.log(
|
||||
`${this.debugPrintIndentation}replaced set ${typesToReplace
|
||||
.map(t => t.typeRef.getIndex().toString)
|
||||
.join(",")} as ${forwardingRef.getIndex()}`
|
||||
.map(t => t.typeRef.index.toString)
|
||||
.join(",")} as ${forwardingRef.index}`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -892,7 +888,7 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
|
||||
protected forceReconstituteTypeRef(originalRef: TypeRef, maybeForwardingRef?: TypeRef): TypeRef {
|
||||
const [originalType, originalAttributes] = originalRef.deref();
|
||||
const index = originalRef.getIndex();
|
||||
const index = originalRef.index;
|
||||
|
||||
if (this.debugPrint) {
|
||||
console.log(`${this.debugPrintIndentation}reconstituting ${index}`);
|
||||
|
@ -907,7 +903,7 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
tref => {
|
||||
if (this.debugPrint) {
|
||||
this.changeDebugPrintIndent(-1);
|
||||
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${tref.getIndex()}`);
|
||||
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${tref.index}`);
|
||||
}
|
||||
|
||||
if (maybeForwardingRef !== undefined) {
|
||||
|
@ -936,11 +932,11 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
|
||||
// Check whether we have already reconstituted them. That means ensuring
|
||||
// that they all have the same target type.
|
||||
let maybeRef = this.reconstitutedTypes.get(typeRefs[0].getIndex());
|
||||
let maybeRef = this.reconstitutedTypes.get(typeRefs[0].index);
|
||||
if (maybeRef !== undefined && maybeRef !== forwardingRef) {
|
||||
let allEqual = true;
|
||||
for (let i = 1; i < typeRefs.length; i++) {
|
||||
if (this.reconstitutedTypes.get(typeRefs[i].getIndex()) !== maybeRef) {
|
||||
if (this.reconstitutedTypes.get(typeRefs[i].index) !== maybeRef) {
|
||||
allEqual = false;
|
||||
break;
|
||||
}
|
||||
|
@ -957,12 +953,12 @@ export class GraphRewriteBuilder<T extends Type> extends BaseGraphRewriteBuilder
|
|||
}
|
||||
|
||||
// Is this set requested to be replaced? If not, we're out of options.
|
||||
const maybeSet = this._setsToReplaceByMember.get(typeRefs[0].getIndex());
|
||||
const maybeSet = this._setsToReplaceByMember.get(typeRefs[0].index);
|
||||
if (maybeSet === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
for (let i = 1; i < typeRefs.length; i++) {
|
||||
if (this._setsToReplaceByMember.get(typeRefs[i].getIndex()) !== maybeSet) {
|
||||
if (this._setsToReplaceByMember.get(typeRefs[i].index) !== maybeSet) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ export class TypeAttributeStore {
|
|||
private getTypeIndex(t: Type): number {
|
||||
const tref = t.typeRef;
|
||||
assert(tref.graph === this._typeGraph, "Using the wrong type attribute store");
|
||||
return tref.getIndex();
|
||||
return tref.index;
|
||||
}
|
||||
|
||||
attributesForType(t: Type): TypeAttributes {
|
||||
|
@ -356,13 +356,13 @@ export class TypeGraph {
|
|||
const parents = defined(this._types).map(_ => Set());
|
||||
this.allTypesUnordered().forEach(p => {
|
||||
p.children.forEach(c => {
|
||||
const index = c.typeRef.getIndex();
|
||||
const index = c.typeRef.index;
|
||||
parents[index] = parents[index].add(p);
|
||||
});
|
||||
});
|
||||
this._parents = parents;
|
||||
}
|
||||
return this._parents[t.typeRef.getIndex()];
|
||||
return this._parents[t.typeRef.index];
|
||||
}
|
||||
|
||||
printGraph(): void {
|
||||
|
@ -373,7 +373,7 @@ export class TypeGraph {
|
|||
parts.push(`${t.kind}${t.hasNames ? ` ${t.getCombinedName()}` : ""}`);
|
||||
const children = t.children;
|
||||
if (!children.isEmpty()) {
|
||||
parts.push(`children ${children.map(c => c.typeRef.getIndex()).join(",")}`);
|
||||
parts.push(`children ${children.map(c => c.typeRef.index).join(",")}`);
|
||||
}
|
||||
t.getAttributes().forEach((value, kind) => {
|
||||
const maybeString = kind.stringify(value);
|
||||
|
|
Загрузка…
Ссылка в новой задаче