From 3481042259c1db4d9fb4e50d5e91e8c58e8cdac5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 12 May 2024 15:56:24 -0400 Subject: Simplify interfaces by requiring all functions are pointer methods --- ast.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'ast.c') diff --git a/ast.c b/ast.c index c13c562a..9199a567 100644 --- a/ast.c +++ b/ast.c @@ -136,7 +136,7 @@ CORD ast_to_xml(ast_t *ast) T(StructDef, "%r%r", data.name, arg_list_to_xml(data.fields), ast_to_xml(data.namespace)) T(EnumDef, "%r%r", data.name, tags_to_xml(data.tags), ast_to_xml(data.namespace)) T(LangDef, "%r", data.name, ast_to_xml(data.namespace)) - T(InterfaceDef, "%r%r", data.name, type_ast_to_xml(data.type_parameter), arg_list_to_xml(data.fields)) + T(InterfaceDef, "%r", data.name, arg_list_to_xml(data.fields)) T(Index, "%r%r", optional_tagged("indexed", data.indexed), optional_tagged("index", data.index)) T(FieldAccess, "%r", data.field, ast_to_xml(data.fielded)) T(Optional, "%r", ast_to_xml(data.value)) @@ -236,32 +236,4 @@ bool type_ast_eq(type_ast_t *x, type_ast_t *y) return true; } -type_ast_t *replace_type_ast(type_ast_t *t, type_ast_t *target, type_ast_t *replacement) -{ - if (!t) return t; - if (type_ast_eq(t, target)) - return replacement; - -#define REPLACED_MEMBER(t, tag, member) ({ t = memcpy(GC_MALLOC(sizeof(type_ast_t)), (t), sizeof(type_ast_t)); Match((struct type_ast_s*)(t), tag)->member = replace_type_ast(Match((t), tag)->member, target, replacement); t; }) - switch (t->tag) { - case UnknownTypeAST: - case VarTypeAST: return t; - case PointerTypeAST: return REPLACED_MEMBER(t, PointerTypeAST, pointed); - case ArrayTypeAST: return REPLACED_MEMBER(t, ArrayTypeAST, item); - case TableTypeAST: { - t = REPLACED_MEMBER(t, TableTypeAST, key); - return REPLACED_MEMBER(t, TableTypeAST, value); - } - case FunctionTypeAST: { - auto fn = Match(t, FunctionTypeAST); - t = REPLACED_MEMBER(t, FunctionTypeAST, ret); - arg_ast_t *args = LIST_MAP(fn->args, old_arg, .type=replace_type_ast(old_arg->type, target, replacement)); - Match((struct type_ast_s*)t, FunctionTypeAST)->args = args; - return t; - } - } - return t; -#undef REPLACED_MEMBER -} - // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 -- cgit v1.2.3