Commit 88a1b71d authored by Guillaume Charifi's avatar Guillaume Charifi

Merge branch 'debug' into 'master'

Improve debugging of remaining nodes

See merge request !10
parents 9ffc3f99 bde6e751
Pipeline #424 passed with stages
in 1 minute and 48 seconds
......@@ -256,3 +256,29 @@ const wchar_t *debug_annotation_type(enum bm_ast_annotation_type type)
return L"<unknown annotation>";
}
const wchar_t *debug_val_imm_type(enum bm_ast_val_imm_type type)
{
switch (type)
{
case BM_AST_VALUE_IMM_BOOL: return L"bool";
case BM_AST_VALUE_IMM_CHAR: return L"char";
case BM_AST_VALUE_IMM_FLOAT: return L"float";
case BM_AST_VALUE_IMM_INT: return L"int";
case BM_AST_VALUE_IMM_STRING: return L"string";
case BM_AST_VALUE_IMM_UINT: return L"uint";
}
return L"<unknown value imm>";
}
const wchar_t *debug_bool(enum bm_ast_bool b)
{
switch (b)
{
case BM_AST_BOOL_FALSE: return L"false";
case BM_AST_BOOL_TRUE: return L"true";
}
return L"<unknown bool>";
}
......@@ -29,5 +29,7 @@ extern const wchar_t *debug_token_type(enum bm_token_type type);
extern const wchar_t *debug_node_type(enum bm_ast_node_type type);
extern const wchar_t *debug_visibility(enum bm_ast_visibility visibility);
extern const wchar_t *debug_annotation_type(enum bm_ast_annotation_type type);
extern const wchar_t *debug_val_imm_type(enum bm_ast_val_imm_type type);
extern const wchar_t *debug_bool(enum bm_ast_bool b);
#endif
......@@ -20,6 +20,7 @@
#include "common/utils.h"
#include "ast.h"
#include "debug.h"
#include "parser.h"
#include "parser_priv.h"
......@@ -44,6 +45,42 @@ static int val_imm_dtor(struct bm_ast_node *node)
return 0;
}
static int val_imm_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_val_imm *data = &node->data.as_val_imm;
wprintf(L",\n%*ls\"value_type\": \"%ls\"", indent_lvl * 2, L"", debug_val_imm_type(data->type));
wprintf(L",\n%*ls\"value\": ", indent_lvl * 2, L"");
switch (data->type)
{
case BM_AST_VALUE_IMM_BOOL:
wprintf(L"%ls", debug_bool(data->data.as_imm_bool));
break;
case BM_AST_VALUE_IMM_CHAR:
wprintf(L"\"%lc\"", data->data.as_imm_char);
break;
case BM_AST_VALUE_IMM_FLOAT:
wprintf(L"%f", data->data.as_imm_float);
break;
case BM_AST_VALUE_IMM_INT:
wprintf(L"%d", data->data.as_imm_int);
break;
case BM_AST_VALUE_IMM_STRING:
wprintf(L"\"%ls\"", data->data.as_imm_string);
break;
case BM_AST_VALUE_IMM_UINT:
wprintf(L"%u", data->data.as_imm_uint);
break;
}
return 0;
}
static int parse_val_imm(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out)
{
unsigned long i = *cur_tok_id;
......@@ -51,6 +88,7 @@ static int parse_val_imm(struct parser_ctx *ctx, unsigned long *cur_tok_id, stru
parser_node_init(&val, BM_AST_NODE_VAL_IMM);
val.dtor = val_imm_dtor;
val.debug_data = val_imm_debug_data;
switch (ctx->in->tokens[i].type)
{
......@@ -178,6 +216,24 @@ static int val_var_ext_dtor(struct bm_ast_node *node)
return 0;
}
static int val_var_ext_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_val_var_ext *data = &node->data.as_val_var_ext;
int result;
wprintf(L",\n%*ls\"class\": \"", indent_lvl * 2, L"");
result = debug_class_path(&data->class_path);
if (result == 0)
wprintf(L".");
wprintf(L"%ls\"", data->class_name);
wprintf(L",\n%*ls\"name\": \"%ls\"", indent_lvl * 2, L"", data->name);
return 0;
}
static int parse_val_var_ext(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out)
{
int result;
......@@ -186,6 +242,7 @@ static int parse_val_var_ext(struct parser_ctx *ctx, unsigned long *cur_tok_id,
parser_node_init(&val, BM_AST_NODE_VAL_VAR_EXT);
val.dtor = val_var_ext_dtor;
val.debug_data = val_var_ext_debug_data;
val.data.as_val_var_ext.class_name = NULL;
val.data.as_val_var_ext.name = NULL;
......@@ -247,6 +304,15 @@ static int val_var_sub_dtor(struct bm_ast_node *node)
return 0;
}
static int val_var_sub_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_val_var_sub *data = &node->data.as_val_var_sub;
wprintf(L",\n%*ls\"name\": \"%ls\"", indent_lvl * 2, L"", data->name);
return 0;
}
static int parse_val_var_sub(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *left_expr, struct bm_ast_node *out)
{
int result;
......@@ -259,6 +325,7 @@ static int parse_val_var_sub(struct parser_ctx *ctx, unsigned long *cur_tok_id,
parser_node_init(&val, BM_AST_NODE_VAL_VAR_SUB);
val.dtor = val_var_sub_dtor;
val.debug_data = val_var_sub_debug_data;
if (ctx->in->tokens[i].type == BM_TOK_IDENTIFIER)
{
......@@ -463,6 +530,17 @@ static int op_cast_dtor(struct bm_ast_node *node)
return 0;
}
static int op_cast_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_op_cast *data = &node->data.as_op_cast;
wprintf(L",\n%*ls\"cast_type\": \"", indent_lvl * 2, L"");
debug_type(&data->type);
wprintf(L"\"");
return 0;
}
static int parse_op_cast(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out)
{
int result;
......@@ -476,6 +554,7 @@ static int parse_op_cast(struct parser_ctx *ctx, unsigned long *cur_tok_id, stru
parser_node_init(&cast, BM_AST_NODE_OP_CAST);
cast.dtor = op_cast_dtor;
cast.debug_data = op_cast_debug_data;
result = parse_type(ctx, &i, &cast.data.as_op_cast.type);
if (result < 0)
......@@ -820,6 +899,15 @@ failed:
return -1;
}
static int loop_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_loop *data = &node->data.as_loop;
wprintf(L",\n%*ls\"count\": %d", indent_lvl * 2, L"", data->count);
return 0;
}
static int parse_loop(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out)
{
int result;
......@@ -832,6 +920,7 @@ static int parse_loop(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct
i++;
parser_node_init(&loop, BM_AST_NODE_LOOP);
loop.debug_data = loop_debug_data;
loop.data.as_loop.count = -1;
if (ctx->in->tokens[i].type == BM_TOK_IMM_INT)
......
......@@ -66,6 +66,15 @@ static int instr_decl_dtor(struct bm_ast_node *node)
return destroy_decl(&node->data.as_instr_decl.base);
}
static int instr_decl_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_instr_decl *data = &node->data.as_instr_decl;
debug_decl(&data->base, indent_lvl);
return 0;
}
/* Handles decl_assign too. */
static int parse_instr_decl(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out)
{
......@@ -75,6 +84,7 @@ static int parse_instr_decl(struct parser_ctx *ctx, unsigned long *cur_tok_id, s
parser_node_init(&decl, BM_AST_NODE_INSTR_DECL);
decl.dtor = instr_decl_dtor;
decl.debug_data = instr_decl_debug_data;
result = parse_decl(ctx, &i, &decl.data.as_instr_decl.base);
if (result < 0)
......
......@@ -289,7 +289,7 @@ int destroy_class_path(struct bm_ast_class_path *class_path)
return 0;
}
static int debug_class_path(const struct bm_ast_class_path *class_path)
int debug_class_path(const struct bm_ast_class_path *class_path)
{
wchar_t *path = NULL;
......@@ -694,7 +694,7 @@ int destroy_decl(struct bm_ast_decl *decl)
return 0;
}
static int debug_decl(const struct bm_ast_decl *decl, int indent_lvl)
int debug_decl(const struct bm_ast_decl *decl, int indent_lvl)
{
wprintf(L",\n%*ls\"name\": \"%ls\"", indent_lvl * 2, L"", decl->name);
wprintf(L",\n%*ls\"decl_type\": \"", indent_lvl * 2, L"");
......
......@@ -39,12 +39,14 @@ extern int parse_class_name(wchar_t *name);
extern int parse_interface_name(wchar_t *name);
extern int parse_var_name(wchar_t *name);
extern int destroy_class_path(struct bm_ast_class_path *class_path);
extern int debug_class_path(const struct bm_ast_class_path *class_path);
extern int parse_class_path(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_class_path *out);
extern int destroy_type(struct bm_ast_type *type);
extern int debug_type(const struct bm_ast_type *type);
extern int parse_type(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_type *out);
extern int parser_node_init_unknown(struct bm_ast_node *node);
extern int destroy_decl(struct bm_ast_decl *decl);
extern int debug_decl(const struct bm_ast_decl *decl, int indent_lvl);
extern int parse_decl(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_decl *out);
extern int parse_block(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment