Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/codegen/expressions/method-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
FunctionNode,
MemberAccessNode,
InterfaceDeclaration,
InterfaceField,
SourceLocation,
} from "../../ast/types.js";
import type { SymbolTable } from "../infrastructure/symbol-table.js";
Expand Down Expand Up @@ -250,6 +251,7 @@ export interface MethodCallGeneratorContext {
getThisFieldMapKeyType(expr: Expression): string | null;
getThisFieldSetValueType(expr: Expression): string | null;
};
getAllInterfaceFields(iface: InterfaceDeclaration): InterfaceField[];
ensureDouble(value: string): string;
ensureI64(value: string): string;
getWantsBinaryReturn(): boolean;
Expand Down
37 changes: 20 additions & 17 deletions src/codegen/expressions/method-calls/class-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,37 @@ type ClassNode = {
typeParameters?: string[];
};

export function getInterfaceFromAST(
export function getInterfaceDecl(
ctx: MethodCallGeneratorContext,
name: string,
): InterfaceDefInfo | null {
): InterfaceDeclaration | null {
const len = ctx.getAstInterfacesLength();
for (let i = 0; i < len; i++) {
const ifaceName = ctx.getAstInterfaceNameAt(i);
if (ifaceName === name) {
const ifaceItem = ctx.getAstInterfaceAt(i);
if (!ifaceItem) continue;
const properties: { name: string; type: string }[] = [];
for (let j = 0; j < ifaceItem.fields.length; j++) {
const field = ifaceItem.fields[j] as { name: string; type: string };
properties.push({ name: field.name, type: field.type });
}
return { properties };
return ctx.getAstInterfaceAt(i);
}
}
return null;
}

export function getInterfaceDecl(
export function getInterfaceFromAST(
ctx: MethodCallGeneratorContext,
name: string,
): InterfaceDeclaration | null {
): InterfaceDefInfo | null {
const len = ctx.getAstInterfacesLength();
for (let i = 0; i < len; i++) {
const ifaceName = ctx.getAstInterfaceNameAt(i);
if (ifaceName === name) {
return ctx.getAstInterfaceAt(i);
const ifaceItem = ctx.getAstInterfaceAt(i);
if (!ifaceItem) continue;
const allFields = ctx.getAllInterfaceFields(ifaceItem);
const properties: { name: string; type: string }[] = [];
for (let j = 0; j < allFields.length; j++) {
const field = allFields[j] as { name: string; type: string };
properties.push({ name: field.name, type: field.type });
}
return { properties };
}
}
return null;
Expand Down Expand Up @@ -388,8 +389,9 @@ export function resolveNestedMemberAccessType(
const interfaceDecl = interfaceDeclResult as InterfaceDeclaration;
if (interfaceDeclResult) {
let fieldResult: InterfaceField | null = null;
for (let i = 0; i < interfaceDecl.fields.length; i++) {
const f = interfaceDecl.fields[i] as { name: string; type: string };
const allIfaceFields = ctx.getAllInterfaceFields(interfaceDecl);
for (let i = 0; i < allIfaceFields.length; i++) {
const f = allIfaceFields[i] as { name: string; type: string };
if (f.name === memberAccess.property) {
fieldResult = f;
break;
Expand Down Expand Up @@ -641,8 +643,9 @@ export function handleClassMethods(
const interfaceDeclResult = getInterfaceDecl(ctx, interfaceType);
if (interfaceDeclResult) {
const interfaceDecl = interfaceDeclResult as InterfaceDeclaration;
for (let i = 0; i < interfaceDecl.fields.length; i++) {
const f = interfaceDecl.fields[i] as { name: string; type: string };
const allDispatchFields = ctx.getAllInterfaceFields(interfaceDecl);
for (let i = 0; i < allDispatchFields.length; i++) {
const f = allDispatchFields[i] as { name: string; type: string };
if (f.name === memberAccess.property) {
let fieldType = f.type;
if (fieldType.endsWith(" | null") || fieldType.endsWith(" | undefined")) {
Expand Down
Loading