Polly 20.0.0git
extract_key.c
Go to the documentation of this file.
1/*
2 * Copyright 2013 Ecole Normale Superieure
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8 */
9
10#include <string.h>
11
12/* Extract a mapping key from the token "tok".
13 * Return KEY_ERROR on error, i.e., if "tok" does not
14 * correspond to any known key.
15 */
17{
18 isl_bool has_string;
19 char *name;
20 KEY key;
21 isl_ctx *ctx;
22
23 has_string = isl_token_has_str(tok);
24 if (has_string < 0)
25 return KEY_ERROR;
26 if (!has_string) {
27 isl_stream_error(s, tok, "expecting key");
28 return KEY_ERROR;
29 }
30
31 ctx = isl_stream_get_ctx(s);
32 name = isl_token_get_str(ctx, tok);
33 if (!name)
34 return KEY_ERROR;
35
36 for (key = 0; key < KEY_END; ++key) {
37 if (KEY_STR[key] && !strcmp(name, KEY_STR[key]))
38 break;
39 }
40 free(name);
41
42 if (key >= KEY_END)
43 isl_die(ctx, isl_error_invalid, "unknown key",
44 return KEY_ERROR);
45 return key;
46}
47
48/* Read a key from "s" and return the corresponding enum.
49 * Return KEY_ERROR on error, i.e., if the first token
50 * on the stream does not correspond to any known key.
51 */
53{
54 struct isl_token *tok;
55 KEY key;
56
58 key = KEY_EXTRACT(s, tok);
59 isl_token_free(tok);
60
61 return key;
62}
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
#define __isl_keep
Definition: ctx.h:25
isl_bool
Definition: ctx.h:89
isl_bool __isl_keep ISL_KEY * key
Definition: hmap.h:27
#define KEY_EXTRACT
Definition: isl_ast.c:3342
#define KEY_GET
Definition: isl_ast.c:3344
#define KEY
Definition: isl_ast.c:3334
#define KEY_END
Definition: isl_ast.c:3338
#define KEY_STR
Definition: isl_ast.c:3340
#define KEY_ERROR
Definition: isl_ast.c:3336
const char * name
Definition: isl_test.c:10938
void isl_stream_error(__isl_keep isl_stream *s, struct isl_token *tok, char *msg)
Definition: isl_stream.c:142
void isl_token_free(struct isl_token *tok)
Definition: isl_stream.c:127
isl_ctx * isl_stream_get_ctx(__isl_keep isl_stream *s)
Definition: isl_stream.c:800
struct isl_token * isl_stream_next_token(__isl_keep isl_stream *s)
Definition: isl_stream.c:693
__isl_give char * isl_token_get_str(isl_ctx *ctx, struct isl_token *tok)
Definition: isl_stream.c:115
isl_bool isl_token_has_str(struct isl_token *tok)
Definition: isl_stream.c:106