ast: implement to_string for int and double nodes
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
|
#include "../parse/token.h"
|
||||||
#include "ast.h"
|
#include "ast.h"
|
||||||
|
|
||||||
|
#include <fx/stream.h>
|
||||||
|
|
||||||
|
static void to_string(const struct ast_node *node, fx_bstr *out)
|
||||||
|
{
|
||||||
|
struct double_ast_node *i = (struct double_ast_node *)node;
|
||||||
|
fx_value_to_string(&i->n_value->tok_number, (fx_stream *)out, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
struct ast_node_definition double_ast_node = {
|
struct ast_node_definition double_ast_node = {
|
||||||
.def_id = AST_DOUBLE,
|
.def_id = AST_DOUBLE,
|
||||||
.def_node_size = sizeof(struct double_ast_node),
|
.def_node_size = sizeof(struct double_ast_node),
|
||||||
|
.def_to_string = to_string,
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-1
@@ -1,10 +1,12 @@
|
|||||||
#include "../parse/token.h"
|
#include "../parse/token.h"
|
||||||
#include "ast.h"
|
#include "ast.h"
|
||||||
|
|
||||||
|
#include <fx/stream.h>
|
||||||
|
|
||||||
static void to_string(const struct ast_node *node, fx_bstr *out)
|
static void to_string(const struct ast_node *node, fx_bstr *out)
|
||||||
{
|
{
|
||||||
struct int_ast_node *i = (struct int_ast_node *)node;
|
struct int_ast_node *i = (struct int_ast_node *)node;
|
||||||
fx_bstr_write_fmt(out, NULL, "%lld", i->n_value->tok_int);
|
fx_value_to_string(&i->n_value->tok_number, (fx_stream *)out, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ast_node_definition int_ast_node = {
|
struct ast_node_definition int_ast_node = {
|
||||||
|
|||||||
Reference in New Issue
Block a user