/*
* Copyright 2008-2009 Katholieke Universiteit Leuven
*
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, K.U.Leuven, Departement
* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
#include <isl_stream_private.h>
#include <isl/map.h>
#include <isl/aff.h>
+#include <isl_val_private.h>
struct isl_keyword {
char *name;
return tok;
}
+/* Return the type of "tok".
+ */
+int isl_token_get_type(struct isl_token *tok)
+{
+ return tok ? tok->type : ISL_TOKEN_ERROR;
+}
+
+/* Given a token of type ISL_TOKEN_VALUE, return the value it represents.
+ */
+__isl_give isl_val *isl_token_get_val(isl_ctx *ctx, struct isl_token *tok)
+{
+ if (!tok)
+ return NULL;
+ if (tok->type != ISL_TOKEN_VALUE)
+ isl_die(ctx, isl_error_invalid, "not a value token",
+ return NULL);
+
+ 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)
struct isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str)
{
- struct isl_stream *s = isl_stream_new(ctx);
+ struct isl_stream *s;
+ if (!str)
+ return NULL;
+ s = isl_stream_new(ctx);
if (!s)
return NULL;
s->str = str;