From e9014902ef76db0be6ba258473bb01b3b539f125 Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Mon, 23 Jan 2012 10:17:20 +0000 Subject: [PATCH] libpgf: printing of literals and flags --- src/runtime/c/pgf/expr.c | 34 +++++++++++++++++++++++++++++++++- src/runtime/c/pgf/expr.h | 5 ++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c index 105a3db9d..73ed251d1 100644 --- a/src/runtime/c/pgf/expr.c +++ b/src/runtime/c/pgf/expr.c @@ -291,6 +291,34 @@ pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err) return expr; } +void +pgf_print_literal(PgfLiteral lit, + GuWriter* wtr, GuExn* err) +{ + GuVariantInfo ei = gu_variant_open(lit); + switch (ei.tag) { + case PGF_LITERAL_STR: { + PgfLiteralStr* lit = ei.data; + gu_putc('"', wtr, err); + gu_string_write(lit->val, wtr, err); + gu_putc('"', wtr, err); + break; + } + case PGF_LITERAL_INT: { + PgfLiteralInt* lit = ei.data; + gu_printf(wtr, err, "%d", lit->val); + break; + } + case PGF_LITERAL_FLT: { + PgfLiteralFlt* lit = ei.data; + gu_printf(wtr, err, "%f", lit->val); + break; + } + default: + gu_impossible(); + } +} + void pgf_print_expr(PgfExpr expr, int prec, GuWriter* wtr, GuExn* err) @@ -316,7 +344,11 @@ pgf_print_expr(PgfExpr expr, int prec, break; } case PGF_EXPR_ABS: - case PGF_EXPR_LIT: + case PGF_EXPR_LIT: { + PgfExprLit* lit = ei.data; + pgf_print_literal(lit->lit, wtr, err); + break; + } case PGF_EXPR_META: case PGF_EXPR_VAR: case PGF_EXPR_TYPED: diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index 65e2d66a9..003102792 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -40,7 +40,7 @@ typedef enum { } PgfLiteralTag; typedef struct { - GuStr val; + GuString val; } PgfLiteralStr; typedef struct { @@ -146,6 +146,9 @@ pgf_expr_unapply(PgfExpr expr, GuPool* pool); PgfExpr pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err); +void +pgf_print_literal(PgfLiteral lit, GuWriter* wtr, GuExn* err); + void pgf_print_expr(PgfExpr expr, int prec, GuWriter* wtr, GuExn* err);