Coverage Report

Created: 2017-08-21 19:50

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/External/isl/isl_stream.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2008-2009 Katholieke Universiteit Leuven
3
 *
4
 * Use of this software is governed by the MIT license
5
 *
6
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8
 */
9
10
#include <ctype.h>
11
#include <string.h>
12
#include <isl/ctx.h>
13
#include <isl_stream_private.h>
14
#include <isl/map.h>
15
#include <isl/aff.h>
16
#include <isl_val_private.h>
17
18
struct isl_keyword {
19
  char      *name;
20
  enum isl_token_type type;
21
};
22
23
static int same_name(const void *entry, const void *val)
24
0
{
25
0
  const struct isl_keyword *keyword = (const struct isl_keyword *)entry;
26
0
27
0
  return !strcmp(keyword->name, val);
28
0
}
29
30
enum isl_token_type isl_stream_register_keyword(__isl_keep isl_stream *s,
31
  const char *name)
32
0
{
33
0
  struct isl_hash_table_entry *entry;
34
0
  struct isl_keyword *keyword;
35
0
  uint32_t name_hash;
36
0
37
0
  if (
!s->keywords0
)
{0
38
0
    s->keywords = isl_hash_table_alloc(s->ctx, 10);
39
0
    if (!s->keywords)
40
0
      return ISL_TOKEN_ERROR;
41
0
    s->next_type = ISL_TOKEN_LAST;
42
0
  }
43
0
44
0
  
name_hash = isl_hash_string(0
isl_hash_init0
(), name);
45
0
46
0
  entry = isl_hash_table_find(s->ctx, s->keywords, name_hash,
47
0
          same_name, name, 1);
48
0
  if (!entry)
49
0
    return ISL_TOKEN_ERROR;
50
0
  
if (0
entry->data0
)
{0
51
0
    keyword = entry->data;
52
0
    return keyword->type;
53
0
  }
54
0
55
0
  
keyword = 0
isl_calloc_type0
(s->ctx, struct isl_keyword);
56
0
  if (!keyword)
57
0
    return ISL_TOKEN_ERROR;
58
0
  keyword->type = s->next_type++;
59
0
  keyword->name = strdup(name);
60
0
  if (
!keyword->name0
)
{0
61
0
    free(keyword);
62
0
    return ISL_TOKEN_ERROR;
63
0
  }
64
0
  entry->data = keyword;
65
0
66
0
  return keyword->type;
67
0
}
68
69
struct isl_token *isl_token_new(isl_ctx *ctx,
70
  int line, int col, unsigned on_new_line)
71
59.7k
{
72
59.7k
  struct isl_token *tok = isl_alloc_type(ctx, struct isl_token);
73
59.7k
  if (!tok)
74
0
    return NULL;
75
59.7k
  tok->line = line;
76
59.7k
  tok->col = col;
77
59.7k
  tok->on_new_line = on_new_line;
78
59.7k
  tok->is_keyword = 0;
79
59.7k
  tok->u.s = NULL;
80
59.7k
  return tok;
81
59.7k
}
82
83
/* Return the type of "tok".
84
 */
85
int isl_token_get_type(struct isl_token *tok)
86
0
{
87
0
  return tok ? 
tok->type0
:
ISL_TOKEN_ERROR0
;
88
0
}
89
90
/* Given a token of type ISL_TOKEN_VALUE, return the value it represents.
91
 */
92
__isl_give isl_val *isl_token_get_val(isl_ctx *ctx, struct isl_token *tok)
93
0
{
94
0
  if (!tok)
95
0
    return NULL;
96
0
  
if (0
tok->type != ISL_TOKEN_VALUE0
)
97
0
    isl_die(ctx, isl_error_invalid, "not a value token",
98
0
      return NULL);
99
0
100
0
  return isl_val_int_from_isl_int(ctx, tok->u.v);
101
0
}
102
103
/* Given a token with a string representation, return a copy of this string.
104
 */
105
__isl_give char *isl_token_get_str(isl_ctx *ctx, struct isl_token *tok)
106
714
{
107
714
  if (!tok)
108
0
    return NULL;
109
714
  
if (714
!tok->u.s714
)
110
0
    isl_die(ctx, isl_error_invalid,
111
714
      "token does not have a string representation",
112
714
      return NULL);
113
714
114
714
  return strdup(tok->u.s);
115
714
}
116
117
void isl_token_free(struct isl_token *tok)
118
66.9k
{
119
66.9k
  if (!tok)
120
7.22k
    return;
121
59.7k
  
if (59.7k
tok->type == ISL_TOKEN_VALUE59.7k
)
122
9.88k
    isl_int_clear(tok->u.v);
123
49.8k
  else 
if (49.8k
tok->type == ISL_TOKEN_MAP49.8k
)
124
163
    isl_map_free(tok->u.map);
125
49.6k
  else 
if (49.6k
tok->type == ISL_TOKEN_AFF49.6k
)
126
179
    isl_pw_aff_free(tok->u.pwaff);
127
49.6k
  else
128
49.4k
    free(tok->u.s);
129
59.7k
  free(tok);
130
66.9k
}
131
132
void isl_stream_error(__isl_keep isl_stream *s, struct isl_token *tok,
133
  char *msg)
134
6
{
135
6
  int line = tok ? 
tok->line6
:
s->line0
;
136
6
  int col = tok ? 
tok->col6
:
s->col0
;
137
6
  fprintf(stderr, "syntax error (%d, %d): %s\n", line, col, msg);
138
6
  if (
tok6
)
{6
139
6
    if (tok->type < 256)
140
2
      fprintf(stderr, "got '%c'\n", tok->type);
141
4
    else 
if (4
tok->type == ISL_TOKEN_IDENT4
)
142
0
      fprintf(stderr, "got ident '%s'\n", tok->u.s);
143
4
    else 
if (4
tok->is_keyword4
)
144
0
      fprintf(stderr, "got keyword '%s'\n", tok->u.s);
145
4
    else 
if (4
tok->type == ISL_TOKEN_VALUE4
)
{0
146
0
      fprintf(stderr, "got value '");
147
0
      isl_int_print(stderr, tok->u.v, 0);
148
0
      fprintf(stderr, "'\n");
149
4
    } else 
if (4
tok->type == ISL_TOKEN_MAP4
)
{0
150
0
      isl_printer *p;
151
0
      fprintf(stderr, "got map '");
152
0
      p = isl_printer_to_file(s->ctx, stderr);
153
0
      p = isl_printer_print_map(p, tok->u.map);
154
0
      isl_printer_free(p);
155
0
      fprintf(stderr, "'\n");
156
4
    } else 
if (4
tok->type == ISL_TOKEN_AFF4
)
{0
157
0
      isl_printer *p;
158
0
      fprintf(stderr, "got affine expression '");
159
0
      p = isl_printer_to_file(s->ctx, stderr);
160
0
      p = isl_printer_print_pw_aff(p, tok->u.pwaff);
161
0
      isl_printer_free(p);
162
0
      fprintf(stderr, "'\n");
163
4
    } else 
if (4
tok->u.s4
)
164
4
      fprintf(stderr, "got token '%s'\n", tok->u.s);
165
4
    else
166
0
      fprintf(stderr, "got token type %d\n", tok->type);
167
6
  }
168
6
}
169
170
static __isl_give isl_stream* isl_stream_new(struct isl_ctx *ctx)
171
2.79k
{
172
2.79k
  int i;
173
2.79k
  isl_stream *s = isl_calloc_type(ctx, struct isl_stream);
174
2.79k
  if (!s)
175
0
    return NULL;
176
2.79k
  s->ctx = ctx;
177
2.79k
  isl_ctx_ref(s->ctx);
178
2.79k
  s->file = NULL;
179
2.79k
  s->str = NULL;
180
2.79k
  s->len = 0;
181
2.79k
  s->line = 1;
182
2.79k
  s->col = 1;
183
2.79k
  s->eof = 0;
184
2.79k
  s->last_line = 0;
185
2.79k
  s->c = -1;
186
2.79k
  s->n_un = 0;
187
16.7k
  for (i = 0; 
i < 516.7k
;
++i13.9k
)
188
13.9k
    s->tokens[i] = NULL;
189
2.79k
  s->n_token = 0;
190
2.79k
  s->keywords = NULL;
191
2.79k
  s->size = 256;
192
2.79k
  s->buffer = isl_alloc_array(ctx, char, s->size);
193
2.79k
  if (!s->buffer)
194
0
    goto error;
195
2.79k
  return s;
196
2.79k
error:
197
0
  isl_stream_free(s);
198
2.79k
  return NULL;
199
2.79k
}
200
201
__isl_give isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file)
202
112
{
203
112
  isl_stream *s = isl_stream_new(ctx);
204
112
  if (!s)
205
0
    return NULL;
206
112
  s->file = file;
207
112
  return s;
208
112
}
209
210
__isl_give isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str)
211
2.68k
{
212
2.68k
  isl_stream *s;
213
2.68k
  if (!str)
214
0
    return NULL;
215
2.68k
  s = isl_stream_new(ctx);
216
2.68k
  if (!s)
217
0
    return NULL;
218
2.68k
  s->str = str;
219
2.68k
  return s;
220
2.68k
}
221
222
/* Read a character from the stream and advance s->line and s->col
223
 * to point to the next character.
224
 */
225
static int stream_getc(__isl_keep isl_stream *s)
226
178k
{
227
178k
  int c;
228
178k
  if (s->eof)
229
471
    return -1;
230
177k
  
if (177k
s->n_un177k
)
231
49.2k
    return s->c = s->un[--s->n_un];
232
128k
  
if (128k
s->file128k
)
233
10.6k
    c = fgetc(s->file);
234
128k
  else {
235
118k
    c = *s->str++;
236
118k
    if (c == '\0')
237
340
      c = -1;
238
128k
  }
239
128k
  if (c == -1)
240
340
    s->eof = 1;
241
128k
  else 
if (128k
c == '\n'128k
)
{613
242
613
    s->line++;
243
613
    s->col = 1;
244
128k
  } else
245
127k
    s->col++;
246
128k
  s->c = c;
247
177k
  return c;
248
178k
}
249
250
static void isl_stream_ungetc(__isl_keep isl_stream *s, int c)
251
49.2k
{
252
49.2k
  isl_assert(s->ctx, s->n_un < 5, return);
253
49.2k
  s->un[s->n_un++] = c;
254
49.2k
  s->c = -1;
255
49.2k
}
256
257
/* Read a character from the stream, skipping pairs of '\\' and '\n'.
258
 * Set s->start_line and s->start_col to the line and column
259
 * of the returned character.
260
 */
261
static int isl_stream_getc(__isl_keep isl_stream *s)
262
178k
{
263
178k
  int c;
264
178k
265
178k
  do {
266
178k
    s->start_line = s->line;
267
178k
    s->start_col = s->col;
268
178k
    c = stream_getc(s);
269
178k
    if (c != '\\')
270
178k
      return c;
271
178k
    c = stream_getc(s);
272
178k
  } while (c == '\n');
273
178k
274
178k
  isl_stream_ungetc(s, c);
275
0
276
178k
  return '\\';
277
178k
}
278
279
static int isl_stream_push_char(__isl_keep isl_stream *s, int c)
280
78.4k
{
281
78.4k
  if (
s->len >= s->size78.4k
)
{0
282
0
    char *buffer;
283
0
    s->size = (3*s->size)/2;
284
0
    buffer = isl_realloc_array(s->ctx, s->buffer, char, s->size);
285
0
    if (!buffer)
286
0
      return -1;
287
0
    s->buffer = buffer;
288
78.4k
  }
289
78.4k
  s->buffer[s->len++] = c;
290
78.4k
  return 0;
291
78.4k
}
292
293
void isl_stream_push_token(__isl_keep isl_stream *s, struct isl_token *tok)
294
190k
{
295
190k
  isl_assert(s->ctx, s->n_token < 5, return);
296
190k
  s->tokens[s->n_token++] = tok;
297
190k
}
298
299
static enum isl_token_type check_keywords(__isl_keep isl_stream *s)
300
17.4k
{
301
17.4k
  struct isl_hash_table_entry *entry;
302
17.4k
  struct isl_keyword *keyword;
303
17.4k
  uint32_t name_hash;
304
17.4k
305
17.4k
  if (!strcasecmp(s->buffer, "exists"))
306
131
    return ISL_TOKEN_EXISTS;
307
17.2k
  
if (17.2k
!strcasecmp(s->buffer, "and")17.2k
)
308
1.96k
    return ISL_TOKEN_AND;
309
15.3k
  
if (15.3k
!strcasecmp(s->buffer, "or")15.3k
)
310
151
    return ISL_TOKEN_OR;
311
15.1k
  
if (15.1k
!strcasecmp(s->buffer, "implies")15.1k
)
312
1
    return ISL_TOKEN_IMPLIES;
313
15.1k
  
if (15.1k
!strcasecmp(s->buffer, "not")15.1k
)
314
1
    return ISL_TOKEN_NOT;
315
15.1k
  
if (15.1k
!strcasecmp(s->buffer, "infty")15.1k
)
316
83
    return ISL_TOKEN_INFTY;
317
15.0k
  
if (15.0k
!strcasecmp(s->buffer, "infinity")15.0k
)
318
0
    return ISL_TOKEN_INFTY;
319
15.0k
  
if (15.0k
!strcasecmp(s->buffer, "NaN")15.0k
)
320
78
    return ISL_TOKEN_NAN;
321
15.0k
  
if (15.0k
!strcasecmp(s->buffer, "min")15.0k
)
322
5
    return ISL_TOKEN_MIN;
323
15.0k
  
if (15.0k
!strcasecmp(s->buffer, "max")15.0k
)
324
1
    return ISL_TOKEN_MAX;
325
15.0k
  
if (15.0k
!strcasecmp(s->buffer, "rat")15.0k
)
326
22
    return ISL_TOKEN_RAT;
327
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "true")14.9k
)
328
1
    return ISL_TOKEN_TRUE;
329
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "false")14.9k
)
330
7
    return ISL_TOKEN_FALSE;
331
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "ceild")14.9k
)
332
0
    return ISL_TOKEN_CEILD;
333
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "floord")14.9k
)
334
1
    return ISL_TOKEN_FLOORD;
335
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "mod")14.9k
)
336
58
    return ISL_TOKEN_MOD;
337
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "ceil")14.9k
)
338
0
    return ISL_TOKEN_CEIL;
339
14.9k
  
if (14.9k
!strcasecmp(s->buffer, "floor")14.9k
)
340
142
    return ISL_TOKEN_FLOOR;
341
14.9k
342
14.7k
  
if (14.7k
!s->keywords14.7k
)
343
14.7k
    return ISL_TOKEN_IDENT;
344
14.7k
345
0
  
name_hash = isl_hash_string(0
isl_hash_init0
(), s->buffer);
346
0
  entry = isl_hash_table_find(s->ctx, s->keywords, name_hash, same_name,
347
0
          s->buffer, 0);
348
0
  if (
entry0
)
{0
349
0
    keyword = entry->data;
350
0
    return keyword->type;
351
0
  }
352
0
353
0
  return ISL_TOKEN_IDENT;
354
17.4k
}
355
356
int isl_stream_skip_line(__isl_keep isl_stream *s)
357
14
{
358
14
  int c;
359
14
360
478
  while (
(c = isl_stream_getc(s)) != -1 && 478
c != '\n'478
)
361
14
    /* nothing */
362
464
    ;
363
14
364
14
  return c == -1 ? 
-10
:
014
;
365
14
}
366
367
static struct isl_token *next_token(__isl_keep isl_stream *s, int same_line)
368
250k
{
369
250k
  int c;
370
250k
  struct isl_token *tok = NULL;
371
250k
  int line, col;
372
250k
  int old_line = s->last_line;
373
250k
374
250k
  if (
s->n_token250k
)
{190k
375
190k
    if (
same_line && 190k
s->tokens[s->n_token - 1]->on_new_line105
)
376
0
      return NULL;
377
190k
    return s->tokens[--s->n_token];
378
250k
  }
379
250k
380
60.1k
  
if (60.1k
same_line && 60.1k
s->c == '\n'210
)
381
0
    return NULL;
382
60.1k
383
60.1k
  s->len = 0;
384
60.1k
385
60.1k
  /* skip spaces and comment lines */
386
98.5k
  while (
(c = isl_stream_getc(s)) != -198.5k
)
{98.1k
387
98.1k
    if (
c == '#'98.1k
)
{14
388
14
      if (isl_stream_skip_line(s) < 0)
389
0
        break;
390
14
      c = '\n';
391
14
      if (same_line)
392
0
        break;
393
98.1k
    } else 
if (98.1k
!isspace(c) || 98.1k
(same_line && 38.6k
c == '\n'212
))
394
59.7k
      break;
395
98.1k
  }
396
60.1k
397
60.1k
  line = s->start_line;
398
60.1k
  col = s->start_col;
399
60.1k
400
60.1k
  if (
c == -1 || 60.1k
(same_line && 59.7k
c == '\n'210
))
401
568
    return NULL;
402
60.1k
  s->last_line = line;
403
59.5k
404
59.5k
  if (c == '(' ||
405
58.8k
      c == ')' ||
406
58.1k
      c == '+' ||
407
56.7k
      c == '*' ||
408
56.6k
      c == '%' ||
409
56.5k
      c == '?' ||
410
56.5k
      c == '^' ||
411
56.5k
      c == '@' ||
412
56.5k
      c == '$' ||
413
56.5k
      c == ',' ||
414
53.5k
      c == '.' ||
415
53.5k
      c == ';' ||
416
52.9k
      c == '[' ||
417
47.3k
      c == ']' ||
418
41.7k
      c == '{' ||
419
59.5k
      
c == '}'39.3k
)
{22.5k
420
22.5k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
421
22.5k
    if (!tok)
422
0
      return NULL;
423
22.5k
    tok->type = (enum isl_token_type)c;
424
22.5k
    return tok;
425
59.5k
  }
426
36.9k
  
if (36.9k
c == '-'36.9k
)
{4.49k
427
4.49k
    int c;
428
4.49k
    if (
(c = isl_stream_getc(s)) == '>'4.49k
)
{2.55k
429
2.55k
      tok = isl_token_new(s->ctx, line, col, old_line != line);
430
2.55k
      if (!tok)
431
0
        return NULL;
432
2.55k
      tok->u.s = strdup("->");
433
2.55k
      tok->type = ISL_TOKEN_TO;
434
2.55k
      return tok;
435
4.49k
    }
436
1.93k
    
if (1.93k
c != -11.93k
)
437
1.93k
      isl_stream_ungetc(s, c);
438
1.93k
    if (
!isdigit(c)1.93k
)
{669
439
669
      tok = isl_token_new(s->ctx, line, col, old_line != line);
440
669
      if (!tok)
441
0
        return NULL;
442
669
      tok->type = (enum isl_token_type) '-';
443
669
      return tok;
444
1.93k
    }
445
36.9k
  }
446
33.7k
  
if (33.7k
c == '-' || 33.7k
isdigit(c)32.4k
)
{9.88k
447
9.88k
    int minus = c == '-';
448
9.88k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
449
9.88k
    if (!tok)
450
0
      return NULL;
451
9.88k
    tok->type = ISL_TOKEN_VALUE;
452
9.88k
    isl_int_init(tok->u.v);
453
9.88k
    if (isl_stream_push_char(s, c))
454
0
      goto error;
455
14.4k
    
while (9.88k
(c = isl_stream_getc(s)) != -1 && 14.4k
isdigit(c)14.2k
)
456
4.55k
      
if (4.55k
isl_stream_push_char(s, c)4.55k
)
457
0
        goto error;
458
9.88k
    
if (9.88k
c != -19.88k
)
459
9.68k
      isl_stream_ungetc(s, c);
460
9.88k
    isl_stream_push_char(s, '\0');
461
9.88k
    isl_int_read(tok->u.v, s->buffer);
462
9.88k
    if (
minus && 9.88k
isl_int_is_zero1.27k
(tok->u.v))
{1
463
1
      tok->col++;
464
1
      tok->on_new_line = 0;
465
1
      isl_stream_push_token(s, tok);
466
1
      tok = isl_token_new(s->ctx, line, col, old_line != line);
467
1
      if (!tok)
468
0
        return NULL;
469
1
      tok->type = (enum isl_token_type) '-';
470
9.88k
    }
471
9.88k
    return tok;
472
33.7k
  }
473
23.8k
  
if (23.8k
isalpha(c) || 23.8k
c == '_'6.43k
)
{17.4k
474
17.4k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
475
17.4k
    if (!tok)
476
0
      return NULL;
477
17.4k
    isl_stream_push_char(s, c);
478
36.5k
    while ((c = isl_stream_getc(s)) != -1 &&
479
36.4k
        
(isalnum(c) || 36.4k
c == '_'18.4k
))
480
19.1k
      isl_stream_push_char(s, c);
481
17.4k
    if (c != -1)
482
17.2k
      isl_stream_ungetc(s, c);
483
17.5k
    while (
(c = isl_stream_getc(s)) != -1 && 17.5k
c == '\''17.3k
)
484
94
      isl_stream_push_char(s, c);
485
17.4k
    if (c != -1)
486
17.2k
      isl_stream_ungetc(s, c);
487
17.4k
    isl_stream_push_char(s, '\0');
488
17.4k
    tok->type = check_keywords(s);
489
17.4k
    if (tok->type != ISL_TOKEN_IDENT)
490
2.64k
      tok->is_keyword = 1;
491
17.4k
    tok->u.s = strdup(s->buffer);
492
17.4k
    if (!tok->u.s)
493
0
      goto error;
494
17.4k
    return tok;
495
23.8k
  }
496
6.43k
  
if (6.43k
c == '"'6.43k
)
{0
497
0
    tok = isl_token_new(s->ctx, line, col, old_line != line);
498
0
    if (!tok)
499
0
      return NULL;
500
0
    tok->type = ISL_TOKEN_STRING;
501
0
    tok->u.s = NULL;
502
0
    while (
(c = isl_stream_getc(s)) != -1 && 0
c != '"'0
&&
c != '\n'0
)
503
0
      isl_stream_push_char(s, c);
504
0
    if (
c != '"'0
)
{0
505
0
      isl_stream_error(s, NULL, "unterminated string");
506
0
      goto error;
507
0
    }
508
0
    isl_stream_push_char(s, '\0');
509
0
    tok->u.s = strdup(s->buffer);
510
0
    return tok;
511
6.43k
  }
512
6.43k
  
if (6.43k
c == '='6.43k
)
{632
513
632
    int c;
514
632
    tok = isl_token_new(s->ctx, line, col, old_line != line);
515
632
    if (!tok)
516
0
      return NULL;
517
632
    
if (632
(c = isl_stream_getc(s)) == '='632
)
{0
518
0
      tok->u.s = strdup("==");
519
0
      tok->type = ISL_TOKEN_EQ_EQ;
520
0
      return tok;
521
632
    }
522
632
    
if (632
c != -1632
)
523
632
      isl_stream_ungetc(s, c);
524
632
    tok->type = (enum isl_token_type) '=';
525
632
    return tok;
526
6.43k
  }
527
5.80k
  
if (5.80k
c == ':'5.80k
)
{1.57k
528
1.57k
    int c;
529
1.57k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
530
1.57k
    if (!tok)
531
0
      return NULL;
532
1.57k
    
if (1.57k
(c = isl_stream_getc(s)) == '='1.57k
)
{0
533
0
      tok->u.s = strdup(":=");
534
0
      tok->type = ISL_TOKEN_DEF;
535
0
      return tok;
536
1.57k
    }
537
1.57k
    
if (1.57k
c != -11.57k
)
538
1.57k
      isl_stream_ungetc(s, c);
539
1.57k
    tok->type = (enum isl_token_type) ':';
540
1.57k
    return tok;
541
5.80k
  }
542
4.22k
  
if (4.22k
c == '>'4.22k
)
{1.18k
543
1.18k
    int c;
544
1.18k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
545
1.18k
    if (!tok)
546
0
      return NULL;
547
1.18k
    
if (1.18k
(c = isl_stream_getc(s)) == '='1.18k
)
{1.13k
548
1.13k
      tok->u.s = strdup(">=");
549
1.13k
      tok->type = ISL_TOKEN_GE;
550
1.13k
      return tok;
551
1.18k
    } else 
if (55
c == '>'55
)
{2
552
2
      if (
(c = isl_stream_getc(s)) == '='2
)
{1
553
1
        tok->u.s = strdup(">>=");
554
1
        tok->type = ISL_TOKEN_LEX_GE;
555
1
        return tok;
556
2
      }
557
2
      tok->u.s = strdup(">>");
558
1
      tok->type = ISL_TOKEN_LEX_GT;
559
55
    } else {
560
53
      tok->u.s = strdup(">");
561
53
      tok->type = ISL_TOKEN_GT;
562
1.18k
    }
563
54
    
if (54
c != -154
)
564
54
      isl_stream_ungetc(s, c);
565
1.18k
    return tok;
566
4.22k
  }
567
3.03k
  
if (3.03k
c == '<'3.03k
)
{2.54k
568
2.54k
    int c;
569
2.54k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
570
2.54k
    if (!tok)
571
0
      return NULL;
572
2.54k
    
if (2.54k
(c = isl_stream_getc(s)) == '='2.54k
)
{2.20k
573
2.20k
      tok->u.s = strdup("<=");
574
2.20k
      tok->type = ISL_TOKEN_LE;
575
2.20k
      return tok;
576
2.54k
    } else 
if (340
c == '<'340
)
{2
577
2
      if (
(c = isl_stream_getc(s)) == '='2
)
{1
578
1
        tok->u.s = strdup("<<=");
579
1
        tok->type = ISL_TOKEN_LEX_LE;
580
1
        return tok;
581
2
      }
582
2
      tok->u.s = strdup("<<");
583
1
      tok->type = ISL_TOKEN_LEX_LT;
584
340
    } else {
585
338
      tok->u.s = strdup("<");
586
338
      tok->type = ISL_TOKEN_LT;
587
2.54k
    }
588
339
    
if (339
c != -1339
)
589
339
      isl_stream_ungetc(s, c);
590
2.54k
    return tok;
591
3.03k
  }
592
492
  
if (492
c == '&'492
)
{104
593
104
    tok = isl_token_new(s->ctx, line, col, old_line != line);
594
104
    if (!tok)
595
0
      return NULL;
596
104
    tok->type = ISL_TOKEN_AND;
597
104
    if (
(c = isl_stream_getc(s)) != '&' && 104
c != -197
)
{97
598
97
      tok->u.s = strdup("&");
599
97
      isl_stream_ungetc(s, c);
600
104
    } else
601
7
      tok->u.s = strdup("&&");
602
104
    return tok;
603
492
  }
604
388
  
if (388
c == '|'388
)
{1
605
1
    tok = isl_token_new(s->ctx, line, col, old_line != line);
606
1
    if (!tok)
607
0
      return NULL;
608
1
    tok->type = ISL_TOKEN_OR;
609
1
    if (
(c = isl_stream_getc(s)) != '|' && 1
c != -10
)
{0
610
0
      tok->u.s = strdup("|");
611
0
      isl_stream_ungetc(s, c);
612
1
    } else
613
1
      tok->u.s = strdup("||");
614
1
    return tok;
615
388
  }
616
387
  
if (387
c == '/'387
)
{375
617
375
    tok = isl_token_new(s->ctx, line, col, old_line != line);
618
375
    if (!tok)
619
0
      return NULL;
620
375
    
if (375
(c = isl_stream_getc(s)) != '\\' && 375
c != -1375
)
{375
621
375
      tok->type = (enum isl_token_type) '/';
622
375
      isl_stream_ungetc(s, c);
623
375
    } else {
624
0
      tok->u.s = strdup("/\\");
625
0
      tok->type = ISL_TOKEN_AND;
626
375
    }
627
375
    return tok;
628
387
  }
629
12
  
if (12
c == '\\'12
)
{0
630
0
    tok = isl_token_new(s->ctx, line, col, old_line != line);
631
0
    if (!tok)
632
0
      return NULL;
633
0
    
if (0
(c = isl_stream_getc(s)) != '/' && 0
c != -10
)
{0
634
0
      tok->type = (enum isl_token_type) '\\';
635
0
      isl_stream_ungetc(s, c);
636
0
    } else {
637
0
      tok->u.s = strdup("\\/");
638
0
      tok->type = ISL_TOKEN_OR;
639
0
    }
640
0
    return tok;
641
12
  }
642
12
  
if (12
c == '!'12
)
{12
643
12
    tok = isl_token_new(s->ctx, line, col, old_line != line);
644
12
    if (!tok)
645
0
      return NULL;
646
12
    
if (12
(c = isl_stream_getc(s)) == '='12
)
{12
647
12
      tok->u.s = strdup("!=");
648
12
      tok->type = ISL_TOKEN_NE;
649
12
      return tok;
650
12
    } else {
651
0
      tok->type = ISL_TOKEN_NOT;
652
0
      tok->u.s = strdup("!");
653
12
    }
654
0
    
if (0
c != -10
)
655
0
      isl_stream_ungetc(s, c);
656
12
    return tok;
657
12
  }
658
12
659
12
  tok = isl_token_new(s->ctx, line, col, old_line != line);
660
0
  if (!tok)
661
0
    return NULL;
662
0
  tok->type = ISL_TOKEN_UNKNOWN;
663
0
  return tok;
664
0
error:
665
0
  isl_token_free(tok);
666
0
  return NULL;
667
250k
}
668
669
struct isl_token *isl_stream_next_token(__isl_keep isl_stream *s)
670
250k
{
671
250k
  return next_token(s, 0);
672
250k
}
673
674
struct isl_token *isl_stream_next_token_on_same_line(__isl_keep isl_stream *s)
675
315
{
676
315
  return next_token(s, 1);
677
315
}
678
679
int isl_stream_eat_if_available(__isl_keep isl_stream *s, int type)
680
86.3k
{
681
86.3k
  struct isl_token *tok;
682
86.3k
683
86.3k
  tok = isl_stream_next_token(s);
684
86.3k
  if (!tok)
685
343
    return 0;
686
85.9k
  
if (85.9k
tok->type == type85.9k
)
{3.45k
687
3.45k
    isl_token_free(tok);
688
3.45k
    return 1;
689
85.9k
  }
690
85.9k
  isl_stream_push_token(s, tok);
691
85.9k
  return 0;
692
86.3k
}
693
694
int isl_stream_next_token_is(__isl_keep isl_stream *s, int type)
695
35.5k
{
696
35.5k
  struct isl_token *tok;
697
35.5k
  int r;
698
35.5k
699
35.5k
  tok = isl_stream_next_token(s);
700
35.5k
  if (!tok)
701
15
    return 0;
702
35.5k
  r = tok->type == type;
703
35.5k
  isl_stream_push_token(s, tok);
704
35.5k
  return r;
705
35.5k
}
706
707
char *isl_stream_read_ident_if_available(__isl_keep isl_stream *s)
708
0
{
709
0
  struct isl_token *tok;
710
0
711
0
  tok = isl_stream_next_token(s);
712
0
  if (!tok)
713
0
    return NULL;
714
0
  
if (0
tok->type == ISL_TOKEN_IDENT0
)
{0
715
0
    char *ident = strdup(tok->u.s);
716
0
    isl_token_free(tok);
717
0
    return ident;
718
0
  }
719
0
  isl_stream_push_token(s, tok);
720
0
  return NULL;
721
0
}
722
723
int isl_stream_eat(__isl_keep isl_stream *s, int type)
724
12.9k
{
725
12.9k
  struct isl_token *tok;
726
12.9k
727
12.9k
  tok = isl_stream_next_token(s);
728
12.9k
  if (!tok)
729
0
    return -1;
730
12.9k
  
if (12.9k
tok->type == type12.9k
)
{12.9k
731
12.9k
    isl_token_free(tok);
732
12.9k
    return 0;
733
12.9k
  }
734
12.9k
  isl_stream_error(s, tok, "expecting other token");
735
2
  isl_stream_push_token(s, tok);
736
12.9k
  return -1;
737
12.9k
}
738
739
int isl_stream_is_empty(__isl_keep isl_stream *s)
740
0
{
741
0
  struct isl_token *tok;
742
0
743
0
  tok = isl_stream_next_token(s);
744
0
745
0
  if (!tok)
746
0
    return 1;
747
0
748
0
  isl_stream_push_token(s, tok);
749
0
  return 0;
750
0
}
751
752
static isl_stat free_keyword(void **p, void *user)
753
0
{
754
0
  struct isl_keyword *keyword = *p;
755
0
756
0
  free(keyword->name);
757
0
  free(keyword);
758
0
759
0
  return isl_stat_ok;
760
0
}
761
762
void isl_stream_flush_tokens(__isl_keep isl_stream *s)
763
0
{
764
0
  int i;
765
0
766
0
  if (!s)
767
0
    return;
768
0
  
for (i = 0; 0
i < s->n_token0
;
++i0
)
769
0
    isl_token_free(s->tokens[i]);
770
0
  s->n_token = 0;
771
0
}
772
773
isl_ctx *isl_stream_get_ctx(__isl_keep isl_stream *s)
774
0
{
775
0
  return s ? s->ctx : NULL;
776
0
}
777
778
void isl_stream_free(__isl_take isl_stream *s)
779
2.79k
{
780
2.79k
  if (!s)
781
0
    return;
782
2.79k
  free(s->buffer);
783
2.79k
  if (
s->n_token != 02.79k
)
{3
784
3
    struct isl_token *tok = isl_stream_next_token(s);
785
3
    isl_stream_error(s, tok, "unexpected token");
786
3
    isl_token_free(tok);
787
2.79k
  }
788
2.79k
  if (
s->keywords2.79k
)
{0
789
0
    isl_hash_table_foreach(s->ctx, s->keywords, &free_keyword, NULL);
790
0
    isl_hash_table_free(s->ctx, s->keywords);
791
2.79k
  }
792
2.79k
  free(s->yaml_state);
793
2.79k
  free(s->yaml_indent);
794
2.79k
  isl_ctx_deref(s->ctx);
795
2.79k
  free(s);
796
2.79k
}
797
798
/* Push "state" onto the stack of currently active YAML elements.
799
 * The caller is responsible for setting the corresponding indentation.
800
 * Return 0 on success and -1 on failure.
801
 */
802
static int push_state(__isl_keep isl_stream *s, enum isl_yaml_state state)
803
0
{
804
0
  if (
s->yaml_size < s->yaml_depth + 10
)
{0
805
0
    int *indent;
806
0
    enum isl_yaml_state *state;
807
0
808
0
    state = isl_realloc_array(s->ctx, s->yaml_state,
809
0
          enum isl_yaml_state, s->yaml_depth + 1);
810
0
    if (!state)
811
0
      return -1;
812
0
    s->yaml_state = state;
813
0
814
0
    indent = isl_realloc_array(s->ctx, s->yaml_indent,
815
0
          int, s->yaml_depth + 1);
816
0
    if (!indent)
817
0
      return -1;
818
0
    s->yaml_indent = indent;
819
0
820
0
    s->yaml_size = s->yaml_depth + 1;
821
0
  }
822
0
823
0
  s->yaml_state[s->yaml_depth] = state;
824
0
  s->yaml_depth++;
825
0
826
0
  return 0;
827
0
}
828
829
/* Remove the innermost active YAML element from the stack.
830
 * Return 0 on success and -1 on failure.
831
 */
832
static int pop_state(__isl_keep isl_stream *s)
833
0
{
834
0
  if (!s)
835
0
    return -1;
836
0
  
if (0
s->yaml_depth < 10
)
837
0
    isl_die(isl_stream_get_ctx(s), isl_error_invalid,
838
0
      "not in YAML construct", return -1);
839
0
840
0
  s->yaml_depth--;
841
0
842
0
  return 0;
843
0
}
844
845
/* Set the state of the innermost active YAML element to "state".
846
 * Return 0 on success and -1 on failure.
847
 */
848
static int update_state(__isl_keep isl_stream *s, enum isl_yaml_state state)
849
0
{
850
0
  if (!s)
851
0
    return -1;
852
0
  
if (0
s->yaml_depth < 10
)
853
0
    isl_die(isl_stream_get_ctx(s), isl_error_invalid,
854
0
      "not in YAML construct", return -1);
855
0
856
0
  s->yaml_state[s->yaml_depth - 1] = state;
857
0
858
0
  return 0;
859
0
}
860
861
/* Return the state of the innermost active YAML element.
862
 * Return isl_yaml_none if we are not inside any YAML element.
863
 */
864
static enum isl_yaml_state current_state(__isl_keep isl_stream *s)
865
0
{
866
0
  if (!s)
867
0
    return isl_yaml_none;
868
0
  
if (0
s->yaml_depth < 10
)
869
0
    return isl_yaml_none;
870
0
  return s->yaml_state[s->yaml_depth - 1];
871
0
}
872
873
/* Set the indentation of the innermost active YAML element to "indent".
874
 * If "indent" is equal to ISL_YAML_INDENT_FLOW, then this means
875
 * that the current elemient is in flow format.
876
 */
877
static int set_yaml_indent(__isl_keep isl_stream *s, int indent)
878
0
{
879
0
  if (s->yaml_depth < 1)
880
0
    isl_die(s->ctx, isl_error_internal,
881
0
      "not in YAML element", return -1);
882
0
883
0
  s->yaml_indent[s->yaml_depth - 1] = indent;
884
0
885
0
  return 0;
886
0
}
887
888
/* Return the indentation of the innermost active YAML element
889
 * of -1 on error.
890
 */
891
static int get_yaml_indent(__isl_keep isl_stream *s)
892
0
{
893
0
  if (s->yaml_depth < 1)
894
0
    isl_die(s->ctx, isl_error_internal,
895
0
      "not in YAML element", return -1);
896
0
897
0
  return s->yaml_indent[s->yaml_depth - 1];
898
0
}
899
900
/* Move to the next state at the innermost level.
901
 * Return 1 if successful.
902
 * Return 0 if we are at the end of the innermost level.
903
 * Return -1 on error.
904
 *
905
 * If we are in state isl_yaml_mapping_key_start, then we have just
906
 * started a mapping and we are expecting a key.  If the mapping started
907
 * with a '{', then we check if the next token is a '}'.  If so,
908
 * then the mapping is empty and there is no next state at this level.
909
 * Otherwise, we assume that there is at least one key (the one from
910
 * which we derived the indentation in isl_stream_yaml_read_start_mapping.
911
 *
912
 * If we are in state isl_yaml_mapping_key, then the we expect a colon
913
 * followed by a value, so there is always a next state unless
914
 * some error occurs.
915
 *
916
 * If we are in state isl_yaml_mapping_val, then there may or may
917
 * not be a subsequent key in the same mapping.
918
 * In flow format, the next key is preceded by a comma.
919
 * In block format, the next key has the same indentation as the first key.
920
 * If the first token has a smaller indentation, then we have reached
921
 * the end of the current mapping.
922
 *
923
 * If we are in state isl_yaml_sequence_start, then we have just
924
 * started a sequence.  If the sequence started with a '[',
925
 * then we check if the next token is a ']'.  If so, then the sequence
926
 * is empty and there is no next state at this level.
927
 * Otherwise, we assume that there is at least one element in the sequence
928
 * (the one from which we derived the indentation in
929
 * isl_stream_yaml_read_start_sequence.
930
 *
931
 * If we are in state isl_yaml_sequence, then there may or may
932
 * not be a subsequent element in the same sequence.
933
 * In flow format, the next element is preceded by a comma.
934
 * In block format, the next element is introduced by a dash with
935
 * the same indentation as that of the first element.
936
 * If the first token is not a dash or if it has a smaller indentation,
937
 * then we have reached the end of the current sequence.
938
 */
939
int isl_stream_yaml_next(__isl_keep isl_stream *s)
940
0
{
941
0
  struct isl_token *tok;
942
0
  enum isl_yaml_state state;
943
0
  int indent;
944
0
945
0
  state = current_state(s);
946
0
  if (state == isl_yaml_none)
947
0
    isl_die(s->ctx, isl_error_invalid,
948
0
      "not in YAML element", return -1);
949
0
  switch (state) {
950
0
  case isl_yaml_mapping_key_start:
951
0
    if (
get_yaml_indent(s) == 0
ISL_YAML_INDENT_FLOW0
&&
952
0
        isl_stream_next_token_is(s, '}'))
953
0
      return 0;
954
0
    
if (0
update_state(s, isl_yaml_mapping_key) < 00
)
955
0
      return -1;
956
0
    return 1;
957
0
  case isl_yaml_mapping_key:
958
0
    tok = isl_stream_next_token(s);
959
0
    if (
!tok0
)
{0
960
0
      if (s->eof)
961
0
        isl_stream_error(s, NULL, "unexpected EOF");
962
0
      return -1;
963
0
    }
964
0
    
if (0
tok->type == ':'0
)
{0
965
0
      isl_token_free(tok);
966
0
      if (update_state(s, isl_yaml_mapping_val) < 0)
967
0
        return -1;
968
0
      return 1;
969
0
    }
970
0
    isl_stream_error(s, tok, "expecting ':'");
971
0
    isl_stream_push_token(s, tok);
972
0
    return -1;
973
0
  case isl_yaml_mapping_val:
974
0
    if (
get_yaml_indent(s) == 0
ISL_YAML_INDENT_FLOW0
)
{0
975
0
      if (!isl_stream_eat_if_available(s, ','))
976
0
        return 0;
977
0
      
if (0
update_state(s, isl_yaml_mapping_key) < 00
)
978
0
        return -1;
979
0
      return 1;
980
0
    }
981
0
    tok = isl_stream_next_token(s);
982
0
    if (!tok)
983
0
      return 0;
984
0
    indent = tok->col - 1;
985
0
    isl_stream_push_token(s, tok);
986
0
    if (indent < get_yaml_indent(s))
987
0
      return 0;
988
0
    
if (0
update_state(s, isl_yaml_mapping_key) < 00
)
989
0
      return -1;
990
0
    return 1;
991
0
  case isl_yaml_sequence_start:
992
0
    if (
get_yaml_indent(s) == 0
ISL_YAML_INDENT_FLOW0
)
{0
993
0
      if (isl_stream_next_token_is(s, ']'))
994
0
        return 0;
995
0
      
if (0
update_state(s, isl_yaml_sequence) < 00
)
996
0
        return -1;
997
0
      return 1;
998
0
    }
999
0
    tok = isl_stream_next_token(s);
1000
0
    if (
!tok0
)
{0
1001
0
      if (s->eof)
1002
0
        isl_stream_error(s, NULL, "unexpected EOF");
1003
0
      return -1;
1004
0
    }
1005
0
    
if (0
tok->type == '-'0
)
{0
1006
0
      isl_token_free(tok);
1007
0
      if (update_state(s, isl_yaml_sequence) < 0)
1008
0
        return -1;
1009
0
      return 1;
1010
0
    }
1011
0
    isl_stream_error(s, tok, "expecting '-'");
1012
0
    isl_stream_push_token(s, tok);
1013
0
    return 0;
1014
0
  case isl_yaml_sequence:
1015
0
    if (
get_yaml_indent(s) == 0
ISL_YAML_INDENT_FLOW0
)
1016
0
      return isl_stream_eat_if_available(s, ',');
1017
0
    tok = isl_stream_next_token(s);
1018
0
    if (!tok)
1019
0
      return 0;
1020
0
    indent = tok->col - 1;
1021
0
    if (
indent < get_yaml_indent(s) || 0
tok->type != '-'0
)
{0
1022
0
      isl_stream_push_token(s, tok);
1023
0
      return 0;
1024
0
    }
1025
0
    isl_token_free(tok);
1026
0
    return 1;
1027
0
  default:
1028
0
    isl_die(s->ctx, isl_error_internal,
1029
0
      "unexpected state", return 0);
1030
0
  }
1031
0
}
1032
1033
/* Start reading a YAML mapping.
1034
 * Return 0 on success and -1 on error.
1035
 *
1036
 * If the first token on the stream is a '{' then we remove this token
1037
 * from the stream and keep track of the fact that the mapping
1038
 * is given in flow format.
1039
 * Otherwise, we assume the first token is the first key of the mapping and
1040
 * keep track of its indentation, but keep the token on the stream.
1041
 * In both cases, the next token we expect is the first key of the mapping.
1042
 */
1043
int isl_stream_yaml_read_start_mapping(__isl_keep isl_stream *s)
1044
0
{
1045
0
  struct isl_token *tok;
1046
0
  int indent;
1047
0
1048
0
  if (push_state(s, isl_yaml_mapping_key_start) < 0)
1049
0
    return -1;
1050
0
1051
0
  tok = isl_stream_next_token(s);
1052
0
  if (
!tok0
)
{0
1053
0
    if (s->eof)
1054
0
      isl_stream_error(s, NULL, "unexpected EOF");
1055
0
    return -1;
1056
0
  }
1057
0
  
if (0
isl_token_get_type(tok) == '{'0
)
{0
1058
0
    isl_token_free(tok);
1059
0
    return set_yaml_indent(s, ISL_YAML_INDENT_FLOW);
1060
0
  }
1061
0
  indent = tok->col - 1;
1062
0
  isl_stream_push_token(s, tok);
1063
0
1064
0
  return set_yaml_indent(s, indent);
1065
0
}
1066
1067
/* Finish reading a YAML mapping.
1068
 * Return 0 on success and -1 on error.
1069
 *
1070
 * If the mapping started with a '{', then we expect a '}' to close
1071
 * the mapping.
1072
 * Otherwise, we double-check that the next token (if any)
1073
 * has a smaller indentation than that of the current mapping.
1074
 */
1075
int isl_stream_yaml_read_end_mapping(__isl_keep isl_stream *s)
1076
0
{
1077
0
  struct isl_token *tok;
1078
0
  int indent;
1079
0
1080
0
  if (
get_yaml_indent(s) == 0
ISL_YAML_INDENT_FLOW0
)
{0
1081
0
    if (isl_stream_eat(s, '}') < 0)
1082
0
      return -1;
1083
0
    return pop_state(s);
1084
0
  }
1085
0
1086
0
  tok = isl_stream_next_token(s);
1087
0
  if (!tok)
1088
0
    return pop_state(s);
1089
0
1090
0
  indent = tok->col - 1;
1091
0
  isl_stream_push_token(s, tok);
1092
0
1093
0
  if (indent >= get_yaml_indent(s))
1094
0
    isl_die(isl_stream_get_ctx(s), isl_error_invalid,
1095
0
      "mapping not finished", return -1);
1096
0
1097
0
  return pop_state(s);
1098
0
}
1099
1100
/* Start reading a YAML sequence.
1101
 * Return 0 on success and -1 on error.
1102
 *
1103
 * If the first token on the stream is a '[' then we remove this token
1104
 * from the stream and keep track of the fact that the sequence
1105
 * is given in flow format.
1106
 * Otherwise, we assume the first token is the dash that introduces
1107
 * the first element of the sequence and keep track of its indentation,
1108
 * but keep the token on the stream.
1109
 * In both cases, the next token we expect is the first element
1110
 * of the sequence.
1111
 */
1112
int isl_stream_yaml_read_start_sequence(__isl_keep isl_stream *s)
1113
0
{
1114
0
  struct isl_token *tok;
1115
0
  int indent;
1116
0
1117
0
  if (push_state(s, isl_yaml_sequence_start) < 0)
1118
0
    return -1;
1119
0
1120
0
  tok = isl_stream_next_token(s);
1121
0
  if (
!tok0
)
{0
1122
0
    if (s->eof)
1123
0
      isl_stream_error(s, NULL, "unexpected EOF");
1124
0
    return -1;
1125
0
  }
1126
0
  
if (0
isl_token_get_type(tok) == '['0
)
{0
1127
0
    isl_token_free(tok);
1128
0
    return set_yaml_indent(s, ISL_YAML_INDENT_FLOW);
1129
0
  }
1130
0
  indent = tok->col - 1;
1131
0
  isl_stream_push_token(s, tok);
1132
0
1133
0
  return set_yaml_indent(s, indent);
1134
0
}
1135
1136
/* Finish reading a YAML sequence.
1137
 * Return 0 on success and -1 on error.
1138
 *
1139
 * If the sequence started with a '[', then we expect a ']' to close
1140
 * the sequence.
1141
 * Otherwise, we double-check that the next token (if any)
1142
 * is not a dash or that it has a smaller indentation than
1143
 * that of the current sequence.
1144
 */
1145
int isl_stream_yaml_read_end_sequence(__isl_keep isl_stream *s)
1146
0
{
1147
0
  struct isl_token *tok;
1148
0
  int indent;
1149
0
  int dash;
1150
0
1151
0
  if (
get_yaml_indent(s) == 0
ISL_YAML_INDENT_FLOW0
)
{0
1152
0
    if (isl_stream_eat(s, ']') < 0)
1153
0
      return -1;
1154
0
    return pop_state(s);
1155
0
  }
1156
0
1157
0
  tok = isl_stream_next_token(s);
1158
0
  if (!tok)
1159
0
    return pop_state(s);
1160
0
1161
0
  indent = tok->col - 1;
1162
0
  dash = tok->type == '-';
1163
0
  isl_stream_push_token(s, tok);
1164
0
1165
0
  if (
indent >= get_yaml_indent(s) && 0
dash0
)
1166
0
    isl_die(isl_stream_get_ctx(s), isl_error_invalid,
1167
0
      "sequence not finished", return -1);
1168
0
1169
0
  return pop_state(s);
1170
0
}