1
0
forked from GitHub/gf-core

remove the read and write modules from libgu. this simplifies the i/o layer

This commit is contained in:
kr.angelov
2013-09-05 11:20:39 +00:00
parent 504341dfba
commit 7c0bad5092
32 changed files with 418 additions and 670 deletions

View File

@@ -4,7 +4,7 @@
static int
pgf_graphviz_abstract_tree_(PgfExpr expr, int *pid,
GuWriter* wtr, GuExn* err)
GuOut* out, GuExn* err)
{
int id = -1;
@@ -15,52 +15,52 @@ pgf_graphviz_abstract_tree_(PgfExpr expr, int *pid,
break;
case PGF_EXPR_APP: {
PgfExprApp* app = ei.data;
id = pgf_graphviz_abstract_tree_(app->fun, pid, wtr, err);
int arg_id = pgf_graphviz_abstract_tree_(app->arg, pid, wtr, err);
gu_printf(wtr, err, "n%d -- n%d [style = \"solid\"]\n", id, arg_id);
id = pgf_graphviz_abstract_tree_(app->fun, pid, out, err);
int arg_id = pgf_graphviz_abstract_tree_(app->arg, pid, out, err);
gu_printf(out, err, "n%d -- n%d [style = \"solid\"]\n", id, arg_id);
break;
}
case PGF_EXPR_LIT: {
PgfExprLit* lit = ei.data;
id = (*pid)++;
gu_printf(wtr, err, "n%d[label = \"", id);
gu_printf(out, err, "n%d[label = \"", id);
GuVariantInfo ei = gu_variant_open(lit->lit);
switch (ei.tag) {
case PGF_LITERAL_STR: {
PgfLiteralStr* lit = ei.data;
gu_puts("\\\"", wtr, err);
gu_string_write(lit->val, wtr, err);
gu_puts("\\\"", wtr, err);
gu_puts("\\\"", out, err);
gu_string_write(lit->val, out, err);
gu_puts("\\\"", out, err);
break;
}
case PGF_LITERAL_INT: {
PgfLiteralInt* lit = ei.data;
gu_printf(wtr, err, "%d", lit->val);
gu_printf(out, err, "%d", lit->val);
break;
}
case PGF_LITERAL_FLT: {
PgfLiteralFlt* lit = ei.data;
gu_printf(wtr, err, "%lf", lit->val);
gu_printf(out, err, "%lf", lit->val);
break;
}
default:
gu_impossible();
}
gu_puts("\", style = \"solid\", shape = \"plaintext\"]\n", wtr, err);
gu_puts("\", style = \"solid\", shape = \"plaintext\"]\n", out, err);
break;
}
case PGF_EXPR_META:
id = (*pid)++;
gu_printf(wtr, err, "n%d[label = \"?\", style = \"solid\", shape = \"plaintext\"]\n", id);
gu_printf(out, err, "n%d[label = \"?\", style = \"solid\", shape = \"plaintext\"]\n", id);
break;
case PGF_EXPR_FUN: {
PgfExprFun* fun = ei.data;
id = (*pid)++;
gu_printf(wtr, err, "n%d[label = \"", id);
gu_string_write(fun->fun, wtr, err);
gu_puts("\", style = \"solid\", shape = \"plaintext\"]\n", wtr, err);
gu_printf(out, err, "n%d[label = \"", id);
gu_string_write(fun->fun, out, err);
gu_puts("\", style = \"solid\", shape = \"plaintext\"]\n", out, err);
break;
}
case PGF_EXPR_VAR:
@@ -68,12 +68,12 @@ pgf_graphviz_abstract_tree_(PgfExpr expr, int *pid,
break;
case PGF_EXPR_TYPED: {
PgfExprTyped* typed = ei.data;
id = pgf_graphviz_abstract_tree_(typed->expr, pid, wtr, err);
id = pgf_graphviz_abstract_tree_(typed->expr, pid, out, err);
break;
}
case PGF_EXPR_IMPL_ARG: {
PgfExprImplArg* implarg = ei.data;
id = pgf_graphviz_abstract_tree_(implarg->expr, pid, wtr, err);
id = pgf_graphviz_abstract_tree_(implarg->expr, pid, out, err);
break;
}
default:
@@ -84,13 +84,13 @@ pgf_graphviz_abstract_tree_(PgfExpr expr, int *pid,
}
void
pgf_graphviz_abstract_tree(PgfPGF* pgf, PgfExpr expr, GuWriter* wtr, GuExn* err)
pgf_graphviz_abstract_tree(PgfPGF* pgf, PgfExpr expr, GuOut* out, GuExn* err)
{
int id = 0;
gu_puts("graph {\n", wtr, err);
pgf_graphviz_abstract_tree_(expr, &id, wtr, err);
gu_puts("}", wtr, err);
gu_puts("graph {\n", out, err);
pgf_graphviz_abstract_tree_(expr, &id, out, err);
gu_puts("}", out, err);
}
typedef struct PgfParseNode PgfParseNode;
@@ -105,7 +105,7 @@ typedef struct {
PgfLinFuncs* funcs;
GuPool* pool;
GuWriter* wtr;
GuOut* out;
GuExn* err;
PgfParseNode* parent;
@@ -221,43 +221,43 @@ static PgfLinFuncs pgf_bracket_lin_funcs = {
};
static void
pgf_graphviz_parse_level(GuBuf* level, GuWriter* wtr, GuExn* err)
pgf_graphviz_parse_level(GuBuf* level, GuOut* out, GuExn* err)
{
gu_puts("\n subgraph {rank=same;\n", wtr, err);
gu_puts("\n subgraph {rank=same;\n", out, err);
size_t len = gu_buf_length(level);
if (len > 1)
gu_puts(" edge[style=invis]\n", wtr, err);
gu_puts(" edge[style=invis]\n", out, err);
for (size_t i = 0; i < len; i++) {
PgfParseNode* node = gu_buf_get(level, PgfParseNode*, i);
gu_printf(wtr, err, " n%d[label=\"", node->id);
gu_string_write(node->label, wtr, err);
gu_puts("\"]\n", wtr, err);
gu_printf(out, err, " n%d[label=\"", node->id);
gu_string_write(node->label, out, err);
gu_puts("\"]\n", out, err);
}
if (len > 1) {
for (size_t i = 0; i < len; i++) {
PgfParseNode* node = gu_buf_get(level, PgfParseNode*, i);
gu_puts((i == 0) ? " " : " -- ", wtr, err);
gu_printf(wtr, err, "n%d", node->id);
gu_puts((i == 0) ? " " : " -- ", out, err);
gu_printf(out, err, "n%d", node->id);
}
gu_puts("\n", wtr, err);
gu_puts("\n", out, err);
}
gu_puts(" }\n", wtr, err);
gu_puts(" }\n", out, err);
for (size_t i = 0; i < len; i++) {
PgfParseNode* node = gu_buf_get(level, PgfParseNode*, i);
if (node->parent != NULL)
gu_printf(wtr, err, " n%d -- n%d\n", node->parent->id, node->id);
gu_printf(out, err, " n%d -- n%d\n", node->parent->id, node->id);
}
}
void
pgf_graphviz_parse_tree(PgfConcr* concr, PgfExpr expr, GuWriter* wtr, GuExn* err)
pgf_graphviz_parse_tree(PgfConcr* concr, PgfExpr expr, GuOut* out, GuExn* err)
{
GuPool* tmp_pool = gu_local_pool();
@@ -269,13 +269,13 @@ pgf_graphviz_parse_tree(PgfConcr* concr, PgfExpr expr, GuWriter* wtr, GuExn* err
return;
}
gu_puts("graph {\n", wtr, err);
gu_puts(" node[shape=plaintext]\n", wtr, err);
gu_puts("graph {\n", out, err);
gu_puts(" node[shape=plaintext]\n", out, err);
PgfBracketLznState state;
state.funcs = &pgf_bracket_lin_funcs;
state.pool = tmp_pool;
state.wtr = wtr;
state.out = out;
state.err = err;
state.parent = NULL;
@@ -288,11 +288,11 @@ pgf_graphviz_parse_tree(PgfConcr* concr, PgfExpr expr, GuWriter* wtr, GuExn* err
size_t len = gu_buf_length(state.internals);
for (size_t i = 0; i < len; i++) {
GuBuf* level = gu_buf_get(state.internals, GuBuf*, i);
pgf_graphviz_parse_level(level, wtr, err);
pgf_graphviz_parse_level(level, out, err);
}
pgf_graphviz_parse_level(state.leaves, wtr, err);
pgf_graphviz_parse_level(state.leaves, out, err);
gu_puts("}", wtr, err);
gu_puts("}", out, err);
gu_pool_free(tmp_pool);
}