From 3c52a756339a2d96824d21a7d3ad5de7fc1085a0 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 27 Mar 2025 17:26:51 -0400 Subject: Deprecate custom printf specifiers in favor of print() function that uses _Generic() to generically convert any value to a string or print as a string. --- src/ast.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/ast.c') diff --git a/src/ast.c b/src/ast.c index 9f1bc42b..d04fa437 100644 --- a/src/ast.c +++ b/src/ast.c @@ -1,7 +1,6 @@ // Some basic operations defined on AST nodes, mainly converting to // strings for debugging. #include -#include #include #include "ast.h" @@ -174,6 +173,11 @@ CORD ast_to_xml(ast_t *ast) } } +const char *ast_to_str(ast_t *ast) +{ + return CORD_to_const_char_star(ast_to_xml(ast)); +} + CORD type_ast_to_xml(type_ast_t *t) { if (!t) return "NULL"; @@ -195,19 +199,6 @@ CORD type_ast_to_xml(type_ast_t *t) } } -int printf_ast(FILE *stream, const struct printf_info *info, const void *const args[]) -{ - ast_t *ast = *(ast_t**)(args[0]); - if (ast) { - if (info->alt) - return fprintf(stream, "%.*s", (int)(ast->end - ast->start), ast->start); - else - return CORD_put(ast_to_xml(ast), stream); - } else { - return fputs("(null)", stream); - } -} - PUREFUNC bool is_idempotent(ast_t *ast) { switch (ast->tag) { -- cgit v1.2.3