X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_stream.c;h=c40756ddf1997d573435fd7f11b734b38d8aa49d;hb=fdb480f065676f2358ea1178f9464a0cdb9bcaa5;hp=01a2caa117d1d7446315777232257ef58a3a079c;hpb=14102905bbd16f8e0a8342a4dd6e1433a7abacaf;p=platform%2Fupstream%2Fisl.git diff --git a/isl_stream.c b/isl_stream.c index 01a2caa..c40756d 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -1,7 +1,7 @@ /* * 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 @@ -14,6 +14,7 @@ #include #include #include +#include struct isl_keyword { char *name; @@ -80,6 +81,39 @@ struct isl_token *isl_token_new(isl_ctx *ctx, 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) @@ -173,7 +207,10 @@ struct isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file) 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; @@ -354,7 +391,6 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) c == '%' || c == '?' || c == '^' || - c == '=' || c == '@' || c == '$' || c == ',' || @@ -391,6 +427,7 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) } } if (c == '-' || isdigit(c)) { + int minus = c == '-'; tok = isl_token_new(s->ctx, line, col, old_line != line); if (!tok) return NULL; @@ -405,6 +442,15 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) isl_stream_ungetc(s, c); isl_stream_push_char(s, '\0'); isl_int_read(tok->u.v, s->buffer); + if (minus && isl_int_is_zero(tok->u.v)) { + tok->col++; + tok->on_new_line = 0; + isl_stream_push_token(s, tok); + tok = isl_token_new(s->ctx, line, col, old_line != line); + if (!tok) + return NULL; + tok->type = (enum isl_token_type) '-'; + } return tok; } if (isalpha(c) || c == '_') { @@ -446,6 +492,21 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) tok->u.s = strdup(s->buffer); return tok; } + if (c == '=') { + int c; + tok = isl_token_new(s->ctx, line, col, old_line != line); + if (!tok) + return NULL; + if ((c = isl_stream_getc(s)) == '=') { + tok->u.s = strdup("=="); + tok->type = ISL_TOKEN_EQ_EQ; + return tok; + } + if (c != -1) + isl_stream_ungetc(s, c); + tok->type = (enum isl_token_type) '='; + return tok; + } if (c == ':') { int c; tok = isl_token_new(s->ctx, line, col, old_line != line);