summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-09 21:05:28 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-09 21:07:28 +0800
commit2389c7b3b3e8d3621342d2122f4299a5a1082cec (patch)
treeedb6ddb22d799a8162888e3eec09473a00f1b181
parent308b49b1c30e669521bf015b1be6fb6eb6c45348 (diff)
downloadcompiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.tar
compiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.tar.gz
compiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.tar.bz2
compiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.tar.lz
compiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.tar.xz
compiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.tar.zst
compiler2015-2389c7b3b3e8d3621342d2122f4299a5a1082cec.zip
Use regular tree representation in AST drawer
Left-child right-sibling representation is hard to read.
-rw-r--r--src/draw.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/draw.c b/src/draw.c
index 9eff352..603afc5 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -198,23 +198,17 @@ static int printGVNode(FILE *fp, CcmmcAst *node, int count)
return count;
int currentNodeCount = count;
- fprintf(fp, "node%d [label =\"", count);
+ fprintf(fp, "node%d [shape=box] [label =\"", count);
printLabelString(fp, node);
fprintf(fp, "\"]\n");
- ++count;
- int countAfterCheckChildren = count;
- if (node->child) {
- countAfterCheckChildren = printGVNode(fp, node->child, count);
- fprintf(fp, "node%d -> node%d [style = bold]\n", currentNodeCount, count);
- }
- int countAfterCheckSibling = countAfterCheckChildren;
- if (node->right_sibling) {
- countAfterCheckSibling = printGVNode(fp, node->right_sibling, countAfterCheckChildren);
- fprintf(fp, "node%d -> node%d [style = dashed]\n", currentNodeCount, countAfterCheckChildren);
+ for (CcmmcAst *child = node->child; child != NULL; child = child->right_sibling) {
+ int this_count = count + 1;
+ count = printGVNode(fp, child, this_count);
+ fprintf(fp, "node%d -> node%d [style = bold]\n", currentNodeCount, this_count);
}
- return countAfterCheckSibling;
+ return count;
}
void ccmmc_draw_ast(FILE *fp, const char *name, CcmmcAst *root)