diff options
Diffstat (limited to 'ast.c')
| -rw-r--r-- | ast.c | 30 |
1 files changed, 1 insertions, 29 deletions
@@ -136,7 +136,7 @@ CORD ast_to_xml(ast_t *ast) T(StructDef, "<StructDef name=\"%s\">%r<namespace>%r</namespace></StructDef>", data.name, arg_list_to_xml(data.fields), ast_to_xml(data.namespace)) T(EnumDef, "<EnumDef name=\"%s\"><tags>%r</tags><namespace>%r</namespace></EnumDef>", data.name, tags_to_xml(data.tags), ast_to_xml(data.namespace)) T(LangDef, "<LangDef name=\"%s\">%r</LangDef>", data.name, ast_to_xml(data.namespace)) - T(InterfaceDef, "<InterfaceDef name=\"%s\">%r%r</InterfaceDef>", data.name, type_ast_to_xml(data.type_parameter), arg_list_to_xml(data.fields)) + T(InterfaceDef, "<InterfaceDef name=\"%s\">%r</InterfaceDef>", data.name, arg_list_to_xml(data.fields)) T(Index, "<Index>%r%r</Index>", optional_tagged("indexed", data.indexed), optional_tagged("index", data.index)) T(FieldAccess, "<FieldAccess field=\"%s\">%r</FieldAccess>", data.field, ast_to_xml(data.fielded)) T(Optional, "<Optional>%r</Optional>", 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 |
