mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-23 16:08:43 +00:00
add post-analysis AST prints to AST-trace output (UT bigdiff)
This commit is contained in:
parent
bb16b88f52
commit
7fb3f4e671
2 changed files with 33 additions and 5 deletions
|
|
@ -350,8 +350,11 @@ static mapper_t* shared_parse_cli(int* pargi, int argc, char** argv,
|
|||
|
||||
// For just dev-testing the parser, you can do
|
||||
// mlr put -v 'expression goes here' /dev/null
|
||||
if (print_ast)
|
||||
if (print_ast) {
|
||||
printf("RAW AST:\n");
|
||||
printf("\n");
|
||||
mlr_dsl_ast_print(past);
|
||||
}
|
||||
|
||||
*pargi = argi;
|
||||
return mapper_put_or_filter_alloc(mlr_dsl_expression, print_ast, comment_stripped_mlr_dsl_expression,
|
||||
|
|
|
|||
|
|
@ -81,15 +81,29 @@ mlr_dsl_cst_t* mlr_dsl_cst_alloc(mlr_dsl_ast_t* past, int print_ast, int type_in
|
|||
pcst->psubr_callsite_statements_to_resolve = sllv_alloc();
|
||||
pcst->flush_every_record = flush_every_record;
|
||||
|
||||
if (print_ast) {
|
||||
printf("\n");
|
||||
printf("ANALYZED AST:\n");
|
||||
}
|
||||
|
||||
for (sllve_t* pe = pcst->paast->pfunc_defs->phead; pe != NULL; pe = pe->pnext) {
|
||||
mlr_dsl_ast_node_t* pnode = pe->pvvalue;
|
||||
if (print_ast) {
|
||||
printf("\n");
|
||||
printf("FUNCTION DEFINITION:\n");
|
||||
mlr_dsl_ast_node_print(pnode);
|
||||
}
|
||||
udf_defsite_state_t* pudf_defsite_state = mlr_dsl_cst_alloc_udf(pcst, pnode, type_inferencing, context_flags);
|
||||
fmgr_install_udf(pcst->pfmgr, pudf_defsite_state);
|
||||
}
|
||||
|
||||
for (sllve_t* pe = pcst->paast->psubr_defs->phead; pe != NULL; pe = pe->pnext) {
|
||||
mlr_dsl_ast_node_t* pnode = pe->pvvalue;
|
||||
if (print_ast) {
|
||||
printf("\n");
|
||||
printf("SUBROUTINE DEFINITION:\n");
|
||||
mlr_dsl_ast_node_print(pnode);
|
||||
}
|
||||
subr_defsite_t* psubr_defsite = mlr_dsl_cst_alloc_subroutine(pcst, pnode, type_inferencing, context_flags);
|
||||
if (lhmsv_get(pcst->psubr_defsites, psubr_defsite->name)) {
|
||||
fprintf(stderr, "%s: subroutine named \"%s\" has already been defined.\n",
|
||||
|
|
@ -101,6 +115,11 @@ mlr_dsl_cst_t* mlr_dsl_cst_alloc(mlr_dsl_ast_t* past, int print_ast, int type_in
|
|||
|
||||
for (sllve_t* pe = pcst->paast->pbegin_blocks->phead; pe != NULL; pe = pe->pnext) {
|
||||
mlr_dsl_ast_node_t* pnode = pe->pvvalue;
|
||||
if (print_ast) {
|
||||
printf("\n");
|
||||
printf("BEGIN-BLOCK:\n");
|
||||
mlr_dsl_ast_node_print(pnode);
|
||||
}
|
||||
sllv_t* pblock = sllv_alloc();
|
||||
for (sllve_t* pf = pnode->pchildren->phead; pf != NULL; pf = pf->pnext) {
|
||||
mlr_dsl_ast_node_t* plistnode = get_list_for_block(pnode);
|
||||
|
|
@ -115,6 +134,11 @@ mlr_dsl_cst_t* mlr_dsl_cst_alloc(mlr_dsl_ast_t* past, int print_ast, int type_in
|
|||
|
||||
for (sllve_t* pe = pcst->paast->pend_blocks->phead; pe != NULL; pe = pe->pnext) {
|
||||
mlr_dsl_ast_node_t* pnode = pe->pvvalue;
|
||||
if (print_ast) {
|
||||
printf("\n");
|
||||
printf("END-BLOCK:\n");
|
||||
mlr_dsl_ast_node_print(pnode);
|
||||
}
|
||||
sllv_t* pblock = sllv_alloc();
|
||||
for (sllve_t* pf = pnode->pchildren->phead; pf != NULL; pf = pf->pnext) {
|
||||
mlr_dsl_ast_node_t* plistnode = get_list_for_block(pnode);
|
||||
|
|
@ -127,6 +151,11 @@ mlr_dsl_cst_t* mlr_dsl_cst_alloc(mlr_dsl_ast_t* past, int print_ast, int type_in
|
|||
sllv_append(pcst->pend_blocks, pblock);
|
||||
}
|
||||
|
||||
if (print_ast) {
|
||||
printf("\n");
|
||||
printf("MAIN BLOCK:\n");
|
||||
mlr_dsl_ast_node_print(pcst->paast->pmain_block);
|
||||
}
|
||||
for (sllve_t* pe = pcst->paast->pmain_block->pchildren->phead; pe != NULL; pe = pe->pnext) {
|
||||
mlr_dsl_ast_node_t* pnode = pe->pvvalue;
|
||||
|
||||
|
|
@ -140,10 +169,6 @@ mlr_dsl_cst_t* mlr_dsl_cst_alloc(mlr_dsl_ast_t* past, int print_ast, int type_in
|
|||
}
|
||||
}
|
||||
|
||||
if (print_ast) {
|
||||
// xxx
|
||||
}
|
||||
|
||||
// Now that all subroutine/function definitions have been done, resolve
|
||||
// their callsites whose locations we stashed during the CST build. (Without
|
||||
// this delayed resolution, there could be no recursion, and subroutines
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue