From ac1713af559335dbfd09f7218d90999f1652c84d Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 28 May 2013 12:04:06 +0200 Subject: [PATCH] add isl_token_get_str Signed-off-by: Sven Verdoolaege --- include/isl/stream.h | 1 + isl_stream.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/isl/stream.h b/include/isl/stream.h index 58c03cc..2e6e1b7 100644 --- a/include/isl/stream.h +++ b/include/isl/stream.h @@ -54,6 +54,7 @@ struct isl_token { }; __isl_give isl_val *isl_token_get_val(isl_ctx *ctx, struct isl_token *tok); +__isl_give char *isl_token_get_str(isl_ctx *ctx, struct isl_token *tok); void isl_token_free(struct isl_token *tok); struct isl_stream { diff --git a/isl_stream.c b/isl_stream.c index 7ead411..388c204 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -94,6 +94,19 @@ __isl_give isl_val *isl_token_get_val(isl_ctx *ctx, struct isl_token *tok) return isl_val_int_from_isl_int(ctx, tok->u.v); } +/* Given a token of type ISL_TOKEN_STRING, return the string it represents. + */ +__isl_give char *isl_token_get_str(isl_ctx *ctx, struct isl_token *tok) +{ + if (!tok) + return NULL; + if (tok->type != ISL_TOKEN_STRING) + isl_die(ctx, isl_error_invalid, "not a string token", + return NULL); + + return strdup(tok->u.s); +} + void isl_token_free(struct isl_token *tok) { if (!tok) -- 2.7.4