isl_stream: add some auxiliary functions
[isl.git] / isl_stream.h
blob905476bbedfb765238dce0a80019681ed600d161
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_STREAM_H
11 #define ISL_STREAM_H
13 #include <stdio.h>
15 #if defined(__cplusplus)
16 extern "C" {
17 #endif
19 enum isl_token_type { ISL_TOKEN_UNKNOWN = 256, ISL_TOKEN_VALUE,
20 ISL_TOKEN_IDENT, ISL_TOKEN_GE,
21 ISL_TOKEN_LE, ISL_TOKEN_GT, ISL_TOKEN_LT,
22 ISL_TOKEN_TO, ISL_TOKEN_AND,
23 ISL_TOKEN_OR, ISL_TOKEN_EXISTS,
24 ISL_TOKEN_DEF };
26 struct isl_token {
27 enum isl_token_type type;
29 unsigned int on_new_line : 1;
30 int line;
31 int col;
33 union {
34 isl_int v;
35 char *s;
36 } u;
39 void isl_token_free(struct isl_token *tok);
41 struct isl_stream {
42 struct isl_ctx *ctx;
43 FILE *file;
44 const char *str;
45 int line;
46 int col;
47 int eof;
49 char *buffer;
50 size_t size;
51 size_t len;
52 int c;
54 struct isl_token *tokens[5];
55 int n_token;
58 struct isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file);
59 struct isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str);
60 void isl_stream_free(struct isl_stream *s);
62 void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg);
64 struct isl_token *isl_stream_next_token(struct isl_stream *s);
65 struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s);
66 int isl_stream_next_token_is(struct isl_stream *s, int type);
67 void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok);
68 int isl_stream_eat_if_available(struct isl_stream *s, int type);
69 char *isl_stream_read_ident_if_available(struct isl_stream *s);
70 int isl_stream_eat(struct isl_stream *s, int type);
71 int isl_stream_is_empty(struct isl_stream *s);
73 #if defined(__cplusplus)
75 #endif
77 #endif