Coverage Report

Created: 2017-06-28 17:40

/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
57.2k
{
72
57.2k
  struct isl_token *tok = isl_alloc_type(ctx, struct isl_token);
73
57.2k
  if (!tok)
74
0
    return NULL;
75
57.2k
  tok->line = line;
76
57.2k
  tok->col = col;
77
57.2k
  tok->on_new_line = on_new_line;
78
57.2k
  tok->is_keyword = 0;
79
57.2k
  tok->u.s = NULL;
80
57.2k
  return tok;
81
57.2k
}
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
664
{
107
664
  if (!tok)
108
0
    return NULL;
109
664
  
if (664
!tok->u.s664
)
110
0
    isl_die(ctx, isl_error_invalid,
111
664
      "token does not have a string representation",
112
664
      return NULL);
113
664
114
664
  return strdup(tok->u.s);
115
664
}
116
117
void isl_token_free(struct isl_token *tok)
118
64.2k
{
119
64.2k
  if (!tok)
120
7.00k
    return;
121
57.2k
  
if (57.2k
tok->type == ISL_TOKEN_VALUE57.2k
)
122
9.69k
    isl_int_clear(tok->u.v);
123
47.5k
  else 
if (47.5k
tok->type == ISL_TOKEN_MAP47.5k
)
124
163
    isl_map_free(tok->u.map);
125
47.3k
  else 
if (47.3k
tok->type == ISL_TOKEN_AFF47.3k
)
126
179
    isl_pw_aff_free(tok->u.pwaff);
127
47.3k
  else
128
47.2k
    free(tok->u.s);
129
57.2k
  free(tok);
130
57.2k
}
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.65k
{
172
2.65k
  int i;
173
2.65k
  isl_stream *s = isl_calloc_type(ctx, struct isl_stream);
174
2.65k
  if (!s)
175
0
    return NULL;
176
2.65k
  s->ctx = ctx;
177
2.65k
  isl_ctx_ref(s->ctx);
178
2.65k
  s->file = NULL;
179
2.65k
  s->str = NULL;
180
2.65k
  s->len = 0;
181
2.65k
  s->line = 1;
182
2.65k
  s->col = 1;
183
2.65k
  s->eof = 0;
184
2.65k
  s->last_line = 0;
185
2.65k
  s->c = -1;
186
2.65k
  s->n_un = 0;
187
15.9k
  for (i = 0; 
i < 515.9k
;
++i13.2k
)
188
13.2k
    s->tokens[i] = NULL;
189
2.65k
  s->n_token = 0;
190
2.65k
  s->keywords = NULL;
191
2.65k
  s->size = 256;
192
2.65k
  s->buffer = isl_alloc_array(ctx, char, s->size);
193
2.65k
  if (!s->buffer)
194
0
    goto error;
195
2.65k
  return s;
196
0
error:
197
0
  isl_stream_free(s);
198
0
  return NULL;
199
2.65k
}
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.53k
{
212
2.53k
  isl_stream *s;
213
2.53k
  if (!str)
214
0
    return NULL;
215
2.53k
  s = isl_stream_new(ctx);
216
2.53k
  if (!s)
217
0
    return NULL;
218
2.53k
  s->str = str;
219
2.53k
  return s;
220
2.53k
}
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
170k
{
227
170k
  int c;
228
170k
  if (s->eof)
229
471
    return -1;
230
170k
  
if (170k
s->n_un170k
)
231
47.5k
    return s->c = s->un[--s->n_un];
232
122k
  
if (122k
s->file122k
)
233
10.6k
    c = fgetc(s->file);
234
111k
  else {
235
111k
    c = *s->str++;
236
111k
    if (c == '\0')
237
340
      c = -1;
238
111k
  }
239
122k
  if (c == -1)
240
340
    s->eof = 1;
241
122k
  else 
if (122k
c == '\n'122k
)
{613
242
613
    s->line++;
243
613
    s->col = 1;
244
613
  } else
245
121k
    s->col++;
246
122k
  s->c = c;
247
122k
  return c;
248
170k
}
249
250
static void isl_stream_ungetc(__isl_keep isl_stream *s, int c)
251
47.5k
{
252
47.5k
  isl_assert(s->ctx, s->n_un < 5, return);
253
47.5k
  s->un[s->n_un++] = c;
254
47.5k
  s->c = -1;
255
47.5k
}
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
170k
{
263
170k
  int c;
264
170k
265
170k
  do {
266
170k
    s->start_line = s->line;
267
170k
    s->start_col = s->col;
268
170k
    c = stream_getc(s);
269
170k
    if (c != '\\')
270
170k
      return c;
271
0
    c = stream_getc(s);
272
0
  } while (c == '\n');
273
170k
274
0
  isl_stream_ungetc(s, c);
275
0
276
0
  return '\\';
277
170k
}
278
279
static int isl_stream_push_char(__isl_keep isl_stream *s, int c)
280
74.3k
{
281
74.3k
  if (
s->len >= s->size74.3k
)
{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
0
  }
289
74.3k
  s->buffer[s->len++] = c;
290
74.3k
  return 0;
291
74.3k
}
292
293
void isl_stream_push_token(__isl_keep isl_stream *s, struct isl_token *tok)
294
182k
{
295
182k
  isl_assert(s->ctx, s->n_token < 5, return);
296
182k
  s->tokens[s->n_token++] = tok;
297
182k
}
298
299
static enum isl_token_type check_keywords(__isl_keep isl_stream *s)
300
16.6k
{
301
16.6k
  struct isl_hash_table_entry *entry;
302
16.6k
  struct isl_keyword *keyword;
303
16.6k
  uint32_t name_hash;
304
16.6k
305
16.6k
  if (!strcasecmp(s->buffer, "exists"))
306
131
    return ISL_TOKEN_EXISTS;
307
16.5k
  
if (16.5k
!strcasecmp(s->buffer, "and")16.5k
)
308
1.95k
    return ISL_TOKEN_AND;
309
14.5k
  
if (14.5k
!strcasecmp(s->buffer, "or")14.5k
)
310
151
    return ISL_TOKEN_OR;
311
14.4k
  
if (14.4k
!strcasecmp(s->buffer, "implies")14.4k
)
312
1
    return ISL_TOKEN_IMPLIES;
313
14.4k
  
if (14.4k
!strcasecmp(s->buffer, "not")14.4k
)
314
1
    return ISL_TOKEN_NOT;
315
14.4k
  
if (14.4k
!strcasecmp(s->buffer, "infty")14.4k
)
316
83
    return ISL_TOKEN_INFTY;
317
14.3k
  
if (14.3k
!strcasecmp(s->buffer, "infinity")14.3k
)
318
0
    return ISL_TOKEN_INFTY;
319
14.3k
  
if (14.3k
!strcasecmp(s->buffer, "NaN")14.3k
)
320
78
    return ISL_TOKEN_NAN;
321
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "min")14.2k
)
322
5
    return ISL_TOKEN_MIN;
323
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "max")14.2k
)
324
1
    return ISL_TOKEN_MAX;
325
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "rat")14.2k
)
326
22
    return ISL_TOKEN_RAT;
327
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "true")14.2k
)
328
1
    return ISL_TOKEN_TRUE;
329
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "false")14.2k
)
330
7
    return ISL_TOKEN_FALSE;
331
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "ceild")14.2k
)
332
0
    return ISL_TOKEN_CEILD;
333
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "floord")14.2k
)
334
1
    return ISL_TOKEN_FLOORD;
335
14.2k
  
if (14.2k
!strcasecmp(s->buffer, "mod")14.2k
)
336
58
    return ISL_TOKEN_MOD;
337
14.1k
  
if (14.1k
!strcasecmp(s->buffer, "ceil")14.1k
)
338
0
    return ISL_TOKEN_CEIL;
339
14.1k
  
if (14.1k
!strcasecmp(s->buffer, "floor")14.1k
)
340
136
    return ISL_TOKEN_FLOOR;
341
14.1k
342
14.0k
  
if (14.0k
!s->keywords14.0k
)
343
14.0k
    return ISL_TOKEN_IDENT;
344
14.0k
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
0
}
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
240k
{
369
240k
  int c;
370
240k
  struct isl_token *tok = NULL;
371
240k
  int line, col;
372
240k
  int old_line = s->last_line;
373
240k
374
240k
  if (
s->n_token240k
)
{182k
375
182k
    if (
same_line && 182k
s->tokens[s->n_token - 1]->on_new_line105
)
376
0
      return NULL;
377
182k
    return s->tokens[--s->n_token];
378
182k
  }
379
240k
380
57.6k
  
if (57.6k
same_line && 57.6k
s->c == '\n'210
)
381
0
    return NULL;
382
57.6k
383
57.6k
  s->len = 0;
384
57.6k
385
57.6k
  /* skip spaces and comment lines */
386
94.8k
  while (
(c = isl_stream_getc(s)) != -194.8k
)
{94.5k
387
94.5k
    if (
c == '#'94.5k
)
{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
94.5k
    } else 
if (94.5k
!isspace(c) || 94.5k
(same_line && 37.4k
c == '\n'212
))
394
57.2k
      break;
395
94.5k
  }
396
57.6k
397
57.6k
  line = s->start_line;
398
57.6k
  col = s->start_col;
399
57.6k
400
57.6k
  if (
c == -1 || 57.6k
(same_line && 57.2k
c == '\n'210
))
401
568
    return NULL;
402
57.0k
  s->last_line = line;
403
57.0k
404
57.0k
  if (c == '(' ||
405
56.3k
      c == ')' ||
406
55.7k
      c == '+' ||
407
54.2k
      c == '*' ||
408
54.1k
      c == '%' ||
409
54.1k
      c == '?' ||
410
54.1k
      c == '^' ||
411
54.1k
      c == '@' ||
412
54.1k
      c == '$' ||
413
54.1k
      c == ',' ||
414
51.3k
      c == '.' ||
415
51.3k
      c == ';' ||
416
50.7k
      c == '[' ||
417
45.4k
      c == ']' ||
418
40.1k
      c == '{' ||
419
37.8k
      
c == '}'37.8k
)
{21.4k
420
21.4k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
421
21.4k
    if (!tok)
422
0
      return NULL;
423
21.4k
    tok->type = (enum isl_token_type)c;
424
21.4k
    return tok;
425
21.4k
  }
426
35.6k
  
if (35.6k
c == '-'35.6k
)
{4.25k
427
4.25k
    int c;
428
4.25k
    if (
(c = isl_stream_getc(s)) == '>'4.25k
)
{2.35k
429
2.35k
      tok = isl_token_new(s->ctx, line, col, old_line != line);
430
2.35k
      if (!tok)
431
0
        return NULL;
432
2.35k
      tok->u.s = strdup("->");
433
2.35k
      tok->type = ISL_TOKEN_TO;
434
2.35k
      return tok;
435
2.35k
    }
436
1.90k
    
if (1.90k
c != -11.90k
)
437
1.90k
      isl_stream_ungetc(s, c);
438
1.90k
    if (
!isdigit(c)1.90k
)
{653
439
653
      tok = isl_token_new(s->ctx, line, col, old_line != line);
440
653
      if (!tok)
441
0
        return NULL;
442
653
      tok->type = (enum isl_token_type) '-';
443
653
      return tok;
444
653
    }
445
1.90k
  }
446
32.6k
  
if (32.6k
c == '-' || 32.6k
isdigit(c)31.4k
)
{9.69k
447
9.69k
    int minus = c == '-';
448
9.69k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
449
9.69k
    if (!tok)
450
0
      return NULL;
451
9.69k
    tok->type = ISL_TOKEN_VALUE;
452
9.69k
    isl_int_init(tok->u.v);
453
9.69k
    if (isl_stream_push_char(s, c))
454
0
      goto error;
455
13.9k
    
while (9.69k
(c = isl_stream_getc(s)) != -1 && 13.9k
isdigit(c)13.7k
)
456
4.24k
      
if (4.24k
isl_stream_push_char(s, c)4.24k
)
457
0
        goto error;
458
9.69k
    
if (9.69k
c != -19.69k
)
459
9.50k
      isl_stream_ungetc(s, c);
460
9.69k
    isl_stream_push_char(s, '\0');
461
9.69k
    isl_int_read(tok->u.v, s->buffer);
462
9.69k
    if (
minus && 9.69k
isl_int_is_zero1.24k
(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
1
    }
471
9.69k
    return tok;
472
9.69k
  }
473
22.9k
  
if (22.9k
isalpha(c) || 22.9k
c == '_'6.27k
)
{16.6k
474
16.6k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
475
16.6k
    if (!tok)
476
0
      return NULL;
477
16.6k
    isl_stream_push_char(s, c);
478
33.9k
    while ((c = isl_stream_getc(s)) != -1 &&
479
33.8k
        
(isalnum(c) || 33.8k
c == '_'17.5k
))
480
17.2k
      isl_stream_push_char(s, c);
481
16.6k
    if (c != -1)
482
16.5k
      isl_stream_ungetc(s, c);
483
16.7k
    while (
(c = isl_stream_getc(s)) != -1 && 16.7k
c == '\''16.6k
)
484
94
      isl_stream_push_char(s, c);
485
16.6k
    if (c != -1)
486
16.5k
      isl_stream_ungetc(s, c);
487
16.6k
    isl_stream_push_char(s, '\0');
488
16.6k
    tok->type = check_keywords(s);
489
16.6k
    if (tok->type != ISL_TOKEN_IDENT)
490
2.63k
      tok->is_keyword = 1;
491
16.6k
    tok->u.s = strdup(s->buffer);
492
16.6k
    if (!tok->u.s)
493
0
      goto error;
494
16.6k
    return tok;
495
16.6k
  }
496
6.27k
  
if (6.27k
c == '"'6.27k
)
{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
0
  }
512
6.27k
  
if (6.27k
c == '='6.27k
)
{631
513
631
    int c;
514
631
    tok = isl_token_new(s->ctx, line, col, old_line != line);
515
631
    if (!tok)
516
0
      return NULL;
517
631
    
if (631
(c = isl_stream_getc(s)) == '='631
)
{0
518
0
      tok->u.s = strdup("==");
519
0
      tok->type = ISL_TOKEN_EQ_EQ;
520
0
      return tok;
521
0
    }
522
631
    
if (631
c != -1631
)
523
631
      isl_stream_ungetc(s, c);
524
631
    tok->type = (enum isl_token_type) '=';
525
631
    return tok;
526
631
  }
527
5.64k
  
if (5.64k
c == ':'5.64k
)
{1.52k
528
1.52k
    int c;
529
1.52k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
530
1.52k
    if (!tok)
531
0
      return NULL;
532
1.52k
    
if (1.52k
(c = isl_stream_getc(s)) == '='1.52k
)
{0
533
0
      tok->u.s = strdup(":=");
534
0
      tok->type = ISL_TOKEN_DEF;
535
0
      return tok;
536
0
    }
537
1.52k
    
if (1.52k
c != -11.52k
)
538
1.52k
      isl_stream_ungetc(s, c);
539
1.52k
    tok->type = (enum isl_token_type) ':';
540
1.52k
    return tok;
541
1.52k
  }
542
4.12k
  
if (4.12k
c == '>'4.12k
)
{1.17k
543
1.17k
    int c;
544
1.17k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
545
1.17k
    if (!tok)
546
0
      return NULL;
547
1.17k
    
if (1.17k
(c = isl_stream_getc(s)) == '='1.17k
)
{1.12k
548
1.12k
      tok->u.s = strdup(">=");
549
1.12k
      tok->type = ISL_TOKEN_GE;
550
1.12k
      return tok;
551
52
    } else 
if (52
c == '>'52
)
{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
1
      }
557
1
      tok->u.s = strdup(">>");
558
1
      tok->type = ISL_TOKEN_LEX_GT;
559
50
    } else {
560
50
      tok->u.s = strdup(">");
561
50
      tok->type = ISL_TOKEN_GT;
562
50
    }
563
51
    
if (51
c != -151
)
564
51
      isl_stream_ungetc(s, c);
565
51
    return tok;
566
1.17k
  }
567
2.94k
  
if (2.94k
c == '<'2.94k
)
{2.45k
568
2.45k
    int c;
569
2.45k
    tok = isl_token_new(s->ctx, line, col, old_line != line);
570
2.45k
    if (!tok)
571
0
      return NULL;
572
2.45k
    
if (2.45k
(c = isl_stream_getc(s)) == '='2.45k
)
{2.13k
573
2.13k
      tok->u.s = strdup("<=");
574
2.13k
      tok->type = ISL_TOKEN_LE;
575
2.13k
      return tok;
576
320
    } else 
if (320
c == '<'320
)
{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
1
      }
582
1
      tok->u.s = strdup("<<");
583
1
      tok->type = ISL_TOKEN_LEX_LT;
584
318
    } else {
585
318
      tok->u.s = strdup("<");
586
318
      tok->type = ISL_TOKEN_LT;
587
318
    }
588
319
    
if (319
c != -1319
)
589
319
      isl_stream_ungetc(s, c);
590
319
    return tok;
591
2.45k
  }
592
486
  
if (486
c == '&'486
)
{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
97
    } else
601
7
      tok->u.s = strdup("&&");
602
104
    return tok;
603
104
  }
604
382
  
if (382
c == '|'382
)
{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
0
    } else
613
1
      tok->u.s = strdup("||");
614
1
    return tok;
615
1
  }
616
381
  
if (381
c == '/'381
)
{369
617
369
    tok = isl_token_new(s->ctx, line, col, old_line != line);
618
369
    if (!tok)
619
0
      return NULL;
620
369
    
if (369
(c = isl_stream_getc(s)) != '\\' && 369
c != -1369
)
{369
621
369
      tok->type = (enum isl_token_type) '/';
622
369
      isl_stream_ungetc(s, c);
623
0
    } else {
624
0
      tok->u.s = strdup("/\\");
625
0
      tok->type = ISL_TOKEN_AND;
626
0
    }
627
369
    return tok;
628
369
  }
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
0
  }
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
0
    } else {
651
0
      tok->type = ISL_TOKEN_NOT;
652
0
      tok->u.s = strdup("!");
653
0
    }
654
0
    
if (0
c != -10
)
655
0
      isl_stream_ungetc(s, c);
656
0
    return tok;
657
12
  }
658
12
659
0
  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
0
}
668
669
struct isl_token *isl_stream_next_token(__isl_keep isl_stream *s)
670
240k
{
671
240k
  return next_token(s, 0);
672
240k
}
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
83.7k
{
681
83.7k
  struct isl_token *tok;
682
83.7k
683
83.7k
  tok = isl_stream_next_token(s);
684
83.7k
  if (!tok)
685
343
    return 0;
686
83.3k
  
if (83.3k
tok->type == type83.3k
)
{3.43k
687
3.43k
    isl_token_free(tok);
688
3.43k
    return 1;
689
3.43k
  }
690
79.9k
  isl_stream_push_token(s, tok);
691
79.9k
  return 0;
692
83.3k
}
693
694
int isl_stream_next_token_is(__isl_keep isl_stream *s, int type)
695
33.9k
{
696
33.9k
  struct isl_token *tok;
697
33.9k
  int r;
698
33.9k
699
33.9k
  tok = isl_stream_next_token(s);
700
33.9k
  if (!tok)
701
15
    return 0;
702
33.9k
  r = tok->type == type;
703
33.9k
  isl_stream_push_token(s, tok);
704
33.9k
  return r;
705
33.9k
}
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.2k
{
725
12.2k
  struct isl_token *tok;
726
12.2k
727
12.2k
  tok = isl_stream_next_token(s);
728
12.2k
  if (!tok)
729
0
    return -1;
730
12.2k
  
if (12.2k
tok->type == type12.2k
)
{12.2k
731
12.2k
    isl_token_free(tok);
732
12.2k
    return 0;
733
12.2k
  }
734
2
  isl_stream_error(s, tok, "expecting other token");
735
2
  isl_stream_push_token(s, tok);
736
2
  return -1;
737
12.2k
}
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.65k
{
780
2.65k
  if (!s)
781
0
    return;
782
2.65k
  free(s->buffer);
783
2.65k
  if (
s->n_token != 02.65k
)
{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
3
  }
788
2.65k
  if (
s->keywords2.65k
)
{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
0
  }
792
2.65k
  free(s->yaml_state);
793
2.65k
  free(s->yaml_indent);
794
2.65k
  isl_ctx_deref(s->ctx);
795
2.65k
  free(s);
796
2.65k
}
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
}