Merge branch 'maint'
[platform/upstream/isl.git] / include / isl / stream.h
1 /*
2  * Copyright 2008-2009 Katholieke Universiteit Leuven
3  *
4  * Use of this software is governed by the GNU LGPLv2.1 license
5  *
6  * Written by Sven Verdoolaege, K.U.Leuven, Departement
7  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8  */
9
10 #ifndef ISL_STREAM_H
11 #define ISL_STREAM_H
12
13 #include <stdio.h>
14 #include <isl/hash.h>
15 #include <isl/obj.h>
16
17 #if defined(__cplusplus)
18 extern "C" {
19 #endif
20
21 enum isl_token_type { ISL_TOKEN_ERROR = -1,
22                         ISL_TOKEN_UNKNOWN = 256, ISL_TOKEN_VALUE,
23                         ISL_TOKEN_IDENT, ISL_TOKEN_GE,
24                         ISL_TOKEN_LE, ISL_TOKEN_GT, ISL_TOKEN_LT,
25                         ISL_TOKEN_NE,
26                         ISL_TOKEN_LEX_GE, ISL_TOKEN_LEX_LE,
27                         ISL_TOKEN_LEX_GT, ISL_TOKEN_LEX_LT,
28                         ISL_TOKEN_TO, ISL_TOKEN_AND,
29                         ISL_TOKEN_OR, ISL_TOKEN_EXISTS, ISL_TOKEN_NOT,
30                         ISL_TOKEN_DEF, ISL_TOKEN_INFTY, ISL_TOKEN_NAN,
31                         ISL_TOKEN_MIN, ISL_TOKEN_MAX, ISL_TOKEN_RAT,
32                         ISL_TOKEN_TRUE, ISL_TOKEN_FALSE,
33                         ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD, ISL_TOKEN_MOD,
34                         ISL_TOKEN_STRING,
35                         ISL_TOKEN_MAP, ISL_TOKEN_AFF,
36                         ISL_TOKEN_LAST };
37
38 struct isl_token {
39         enum isl_token_type  type;
40
41         unsigned int on_new_line : 1;
42         unsigned is_keyword : 1;
43         int line;
44         int col;
45
46         union {
47                 isl_int v;
48                 char    *s;
49                 isl_map *map;
50                 isl_pw_aff *pwaff;
51         } u;
52 };
53
54 void isl_token_free(struct isl_token *tok);
55
56 struct isl_stream {
57         struct isl_ctx  *ctx;
58         FILE            *file;
59         const char      *str;
60         int             line;
61         int             col;
62         int             eof;
63
64         char            *buffer;
65         size_t          size;
66         size_t          len;
67         int             c;
68         int             un[5];
69         int             n_un;
70
71         struct isl_token        *tokens[5];
72         int             n_token;
73
74         struct isl_hash_table   *keywords;
75         enum isl_token_type      next_type;
76 };
77
78 struct isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file);
79 struct isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str);
80 void isl_stream_free(struct isl_stream *s);
81
82 void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg);
83
84 struct isl_token *isl_stream_next_token(struct isl_stream *s);
85 struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s);
86 int isl_stream_next_token_is(struct isl_stream *s, int type);
87 void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok);
88 void isl_stream_flush_tokens(struct isl_stream *s);
89 int isl_stream_eat_if_available(struct isl_stream *s, int type);
90 char *isl_stream_read_ident_if_available(struct isl_stream *s);
91 int isl_stream_eat(struct isl_stream *s, int type);
92 int isl_stream_is_empty(struct isl_stream *s);
93 int isl_stream_skip_line(struct isl_stream *s);
94
95 enum isl_token_type isl_stream_register_keyword(struct isl_stream *s,
96         const char *name);
97
98 struct isl_obj isl_stream_read_obj(struct isl_stream *s);
99 __isl_give isl_map *isl_stream_read_map(struct isl_stream *s, int nparam);
100 __isl_give isl_set *isl_stream_read_set(struct isl_stream *s, int nparam);
101 __isl_give isl_pw_qpolynomial *isl_stream_read_pw_qpolynomial(
102         struct isl_stream *s);
103 __isl_give isl_union_map *isl_stream_read_union_map(struct isl_stream *s);
104
105 #if defined(__cplusplus)
106 }
107 #endif
108
109 #endif