| 1 | #include <isl/stream.h> |
| 2 | |
| 3 | #define xCAT(A,B) A ## B |
| 4 | #define CAT(A,B) xCAT(A,B) |
| 5 | #undef TYPE |
| 6 | #define TYPE CAT(isl_,BASE) |
| 7 | #define xFN(TYPE,NAME) TYPE ## _ ## NAME |
| 8 | #define FN(TYPE,NAME) xFN(TYPE,NAME) |
| 9 | |
| 10 | /* Read an object of type TYPE from "s", where the object may |
| 11 | * either be specified directly or as a string. |
| 12 | * |
| 13 | * First check if the next token in "s" is a string. If so, try and |
| 14 | * extract the object from the string. |
| 15 | * Otherwise, try and read the object directly from "s". |
| 16 | */ |
| 17 | static __isl_give TYPE *FN(read,BASE)(__isl_keep isl_stream *s) |
| 18 | { |
| 19 | struct isl_token *tok; |
| 20 | int type; |
| 21 | |
| 22 | tok = isl_stream_next_token(s); |
| 23 | type = isl_token_get_type(tok); |
| 24 | if (type == ISL_TOKEN_STRING) { |
| 25 | char *str; |
| 26 | isl_ctx *ctx; |
| 27 | TYPE *res; |
| 28 | |
| 29 | ctx = isl_stream_get_ctx(s); |
| 30 | str = isl_token_get_str(ctx, tok); |
| 31 | res = FN(TYPE,read_from_str)(ctx, str); |
| 32 | free(ptr: str); |
| 33 | isl_token_free(tok); |
| 34 | return res; |
| 35 | } |
| 36 | isl_stream_push_token(s, tok); |
| 37 | return FN(isl_stream_read,BASE)(s); |
| 38 | } |
| 39 | |