/* * Copyright 2008-2009 Katholieke Universiteit Leuven * * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ #include <ctype.h> #include <string.h> #include <isl_ctx_private.h> #include <isl_stream_private.h> #include <isl/map.h> #include <isl/aff.h> #include <isl_val_private.h> #include <isl_options_private.h> struct isl_keyword { … }; static isl_bool same_name(const void *entry, const void *val) { … } enum isl_token_type isl_stream_register_keyword(__isl_keep isl_stream *s, const char *name) { … } struct isl_token *isl_token_new(isl_ctx *ctx, int line, int col, unsigned on_new_line) { … } /* Return the type of "tok". */ int isl_token_get_type(struct isl_token *tok) { … } /* Given a token of type ISL_TOKEN_VALUE, return the value it represents. */ __isl_give isl_val *isl_token_get_val(isl_ctx *ctx, struct isl_token *tok) { … } /* Does the given token have a string representation? */ isl_bool isl_token_has_str(struct isl_token *tok) { … } /* Given a token with a string representation, return a copy of this string. */ __isl_give char *isl_token_get_str(isl_ctx *ctx, struct isl_token *tok) { … } void isl_token_free(struct isl_token *tok) { … } void isl_stream_error(__isl_keep isl_stream *s, struct isl_token *tok, char *msg) { … } static __isl_give isl_stream* isl_stream_new(struct isl_ctx *ctx) { … } __isl_give isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file) { … } __isl_give isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str) { … } /* Read a character from the stream and advance s->line and s->col * to point to the next character. */ static int stream_getc(__isl_keep isl_stream *s) { … } static void isl_stream_ungetc(__isl_keep isl_stream *s, int c) { … } /* Read a character from the stream, skipping pairs of '\\' and '\n'. * Set s->start_line and s->start_col to the line and column * of the returned character. */ static int isl_stream_getc(__isl_keep isl_stream *s) { … } static int isl_stream_push_char(__isl_keep isl_stream *s, int c) { … } void isl_stream_push_token(__isl_keep isl_stream *s, struct isl_token *tok) { … } static enum isl_token_type check_keywords(__isl_keep isl_stream *s) { … } int isl_stream_skip_line(__isl_keep isl_stream *s) { … } static struct isl_token *next_token(__isl_keep isl_stream *s, int same_line) { … } struct isl_token *isl_stream_next_token(__isl_keep isl_stream *s) { … } struct isl_token *isl_stream_next_token_on_same_line(__isl_keep isl_stream *s) { … } int isl_stream_eat_if_available(__isl_keep isl_stream *s, int type) { … } int isl_stream_next_token_is(__isl_keep isl_stream *s, int type) { … } char *isl_stream_read_ident_if_available(__isl_keep isl_stream *s) { … } int isl_stream_eat(__isl_keep isl_stream *s, int type) { … } int isl_stream_is_empty(__isl_keep isl_stream *s) { … } static isl_stat free_keyword(void **p, void *user) { … } void isl_stream_flush_tokens(__isl_keep isl_stream *s) { … } isl_ctx *isl_stream_get_ctx(__isl_keep isl_stream *s) { … } void isl_stream_free(__isl_take isl_stream *s) { … } /* Push "state" onto the stack of currently active YAML elements. * The caller is responsible for setting the corresponding indentation. * Return 0 on success and -1 on failure. */ static int push_state(__isl_keep isl_stream *s, enum isl_yaml_state state) { … } /* Remove the innermost active YAML element from the stack. * Return isl_stat_ok on success and isl_stat_error on failure. */ static isl_stat pop_state(__isl_keep isl_stream *s) { … } /* Set the state of the innermost active YAML element to "state". * Return 0 on success and -1 on failure. */ static int update_state(__isl_keep isl_stream *s, enum isl_yaml_state state) { … } /* Return the state of the innermost active YAML element. * Return isl_yaml_none if we are not inside any YAML element. */ static enum isl_yaml_state current_state(__isl_keep isl_stream *s) { … } /* Set the indentation of the innermost active YAML element to "indent". * If "indent" is equal to ISL_YAML_INDENT_FLOW, then this means * that the current element is in flow format. */ static isl_stat set_yaml_indent(__isl_keep isl_stream *s, int indent) { … } /* Return the indentation of the innermost active YAML element * of -1 on error. */ static int get_yaml_indent(__isl_keep isl_stream *s) { … } /* Move to the next state at the innermost level. * Return isl_bool_true if successful. * Return isl_bool_false if we are at the end of the innermost level. * Return isl_bool_error on error. * * If we are in state isl_yaml_mapping_key_start, then we have just * started a mapping and we are expecting a key. If the mapping started * with a '{', then we check if the next token is a '}'. If so, * then the mapping is empty and there is no next state at this level. * Otherwise, we assume that there is at least one key (the one from * which we derived the indentation in isl_stream_yaml_read_start_mapping. * * If we are in state isl_yaml_mapping_key, then the we expect a colon * followed by a value, so there is always a next state unless * some error occurs. * * If we are in state isl_yaml_mapping_val, then there may or may * not be a subsequent key in the same mapping. * In flow format, the next key is preceded by a comma. * In block format, the next key has the same indentation as the first key. * If the first token has a smaller indentation, then we have reached * the end of the current mapping. * * If we are in state isl_yaml_sequence_start, then we have just * started a sequence. If the sequence started with a '[', * then we check if the next token is a ']'. If so, then the sequence * is empty and there is no next state at this level. * Otherwise, we assume that there is at least one element in the sequence * (the one from which we derived the indentation in * isl_stream_yaml_read_start_sequence. * * If we are in state isl_yaml_sequence, then there may or may * not be a subsequent element in the same sequence. * In flow format, the next element is preceded by a comma. * In block format, the next element is introduced by a dash with * the same indentation as that of the first element. * If the first token is not a dash or if it has a smaller indentation, * then we have reached the end of the current sequence. */ isl_bool isl_stream_yaml_next(__isl_keep isl_stream *s) { … } /* Start reading a YAML mapping. * Return isl_stat_ok on success and isl_stat_error on error. * * If the first token on the stream is a '{' then we remove this token * from the stream and keep track of the fact that the mapping * is given in flow format. * Otherwise, we assume the first token is the first key of the mapping and * keep track of its indentation, but keep the token on the stream. * In both cases, the next token we expect is the first key of the mapping. */ isl_stat isl_stream_yaml_read_start_mapping(__isl_keep isl_stream *s) { … } /* Finish reading a YAML mapping. * Return isl_stat_ok on success and isl_stat_error on error. * * If the mapping started with a '{', then we expect a '}' to close * the mapping. * Otherwise, we double-check that the next token (if any) * has a smaller indentation than that of the current mapping. */ isl_stat isl_stream_yaml_read_end_mapping(__isl_keep isl_stream *s) { … } /* Start reading a YAML sequence. * Return isl_stat_ok on success and isl_stat_error on error. * * If the first token on the stream is a '[' then we remove this token * from the stream and keep track of the fact that the sequence * is given in flow format. * Otherwise, we assume the first token is the dash that introduces * the first element of the sequence and keep track of its indentation, * but keep the token on the stream. * In both cases, the next token we expect is the first element * of the sequence. */ isl_stat isl_stream_yaml_read_start_sequence(__isl_keep isl_stream *s) { … } /* Finish reading a YAML sequence. * Return isl_stat_ok on success and isl_stat_error on error. * * If the sequence started with a '[', then we expect a ']' to close * the sequence. * Otherwise, we double-check that the next token (if any) * is not a dash or that it has a smaller indentation than * that of the current sequence. */ isl_stat isl_stream_yaml_read_end_sequence(__isl_keep isl_stream *s) { … }