/* * Copyright 2011 INRIA Saclay * Copyright 2013 Ecole Normale Superieure * * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France, * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod, * 91893 Orsay, France * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France */ #include <isl/ctx.h> #include <isl/hash.h> #include <isl/stream.h> #define ISL_xCAT(A,B) … #define ISL_CAT(A,B) … #define ISL_xFN(TYPE,NAME) … #define ISL_FN(TYPE,NAME) … #define ISL_xS(TYPE1,TYPE2,NAME) … #define ISL_yS(TYPE1,TYPE2,NAME) … #define ISL_S(NAME) … struct ISL_HMAP { … }; ISL_S(pair) { … }; __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,alloc)(isl_ctx *ctx, int min_size) { … } static isl_stat free_pair(void **entry, void *user) { … } __isl_null ISL_HMAP *ISL_FN(ISL_HMAP,free)(__isl_take ISL_HMAP *hmap) { … } isl_ctx *ISL_FN(ISL_HMAP,get_ctx)(__isl_keep ISL_HMAP *hmap) { … } /* Add a mapping from "key" to "val" to the associative array * pointed to by user. */ static isl_stat add_key_val(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user) { … } __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,dup)(__isl_keep ISL_HMAP *hmap) { … } __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,cow)(__isl_take ISL_HMAP *hmap) { … } __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,copy)(__isl_keep ISL_HMAP *hmap) { … } static isl_bool has_key(const void *entry, const void *c_key) { … } /* If "hmap" contains a value associated to "key", then return * (isl_bool_true, copy of value). * Otherwise, return * (isl_bool_false, NULL). * If an error occurs, then return * (isl_bool_error, NULL). */ __isl_give ISL_MAYBE(ISL_VAL) ISL_FN(ISL_HMAP,try_get)( __isl_keep ISL_HMAP *hmap, __isl_keep ISL_KEY *key) { … } /* If "hmap" contains a value associated to "key", then return * isl_bool_true. Otherwise, return isl_bool_false. * Return isl_bool_error on error. */ isl_bool ISL_FN(ISL_HMAP,has)(__isl_keep ISL_HMAP *hmap, __isl_keep ISL_KEY *key) { … } /* If "hmap" contains a value associated to "key", then return * a copy of that value. Otherwise, return NULL. * Return NULL on error. */ __isl_give ISL_VAL *ISL_FN(ISL_HMAP,get)(__isl_keep ISL_HMAP *hmap, __isl_take ISL_KEY *key) { … } /* Remove the mapping between "key" and its associated value (if any) * from "hmap". * * If "key" is not mapped to anything, then we leave "hmap" untouched" */ __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,drop)(__isl_take ISL_HMAP *hmap, __isl_take ISL_KEY *key) { … } /* Add a mapping from "key" to "val" to "hmap". * If "key" was already mapped to something else, then that mapping * is replaced. * If key happened to be mapped to "val" already, then we leave * "hmap" untouched. */ __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,set)(__isl_take ISL_HMAP *hmap, __isl_take ISL_KEY *key, __isl_take ISL_VAL *val) { … } /* Internal data structure for isl_*_to_*_foreach. * * fn is the function that should be called on each entry. * user is the user-specified final argument to fn. */ ISL_S(foreach_data) { … }; /* Call data->fn on a copy of the key and value in *entry. */ static isl_stat call_on_copy(void **entry, void *user) { … } /* Call "fn" on each pair of key and value in "hmap". */ isl_stat ISL_FN(ISL_HMAP,foreach)(__isl_keep ISL_HMAP *hmap, isl_stat (*fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user), void *user) { … } /* Internal data structure for isl_*_to_*_every. * * "test" is the function that should be called on each entry, * until any invocation returns isl_bool_false. * "test_user" is the user-specified final argument to "test". */ ISL_S(every_data) { … }; /* Call data->test on the key and value in *entry. */ static isl_bool call_on_pair(void **entry, void *user) { … } /* Does "test" succeed on every entry of "hmap"? */ isl_bool ISL_FN(ISL_HMAP,every)(__isl_keep ISL_HMAP *hmap, isl_bool (*test)(__isl_keep ISL_KEY *key, __isl_keep ISL_VAL *val, void *user), void *user) { … } #ifdef ISL_HMAP_IS_EQUAL /* Does "hmap" have an entry with key "key" and value "val"? */ static isl_bool has_entry(__isl_keep ISL_KEY *key, __isl_keep ISL_VAL *val, void *user) { … } /* Is "hmap1" (obviously) equal to "hmap2"? * * In particular, do the two associative arrays have * the same number of entries and does every entry of the first * also appear in the second? */ isl_bool ISL_HMAP_IS_EQUAL(__isl_keep ISL_HMAP *hmap1, __isl_keep ISL_HMAP *hmap2) { … } #endif /* Internal data structure for print_pair. * * p is the printer on which the associative array is being printed. * first is set if the current key-value pair is the first to be printed. */ ISL_S(print_data) { … }; /* Print the given key-value pair to data->p. */ static isl_stat print_pair(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user) { … } /* Print the associative array to "p". */ __isl_give isl_printer *ISL_FN(isl_printer_print,ISL_HMAP_SUFFIX)( __isl_take isl_printer *p, __isl_keep ISL_HMAP *hmap) { … } void ISL_FN(ISL_HMAP,dump)(__isl_keep ISL_HMAP *hmap) { … } /* Return a string representation of "hmap". */ __isl_give char *ISL_FN(ISL_HMAP,to_str)(__isl_keep ISL_HMAP *hmap) { … } #ifdef ISL_HMAP_HAVE_READ_FROM_STR /* Read an associative array from "s". * The input format corresponds to the way associative arrays are printed * by isl_printer_print_*_to_*. * In particular, each key-value pair is separated by a colon, * the key-value pairs are separated by a comma and * the entire associative array is surrounded by braces. */ __isl_give ISL_HMAP *ISL_FN(isl_stream_read,ISL_HMAP_SUFFIX)(isl_stream *s) { … } /* Read an associative array from the string "str". * The input format corresponds to the way associative arrays are printed * by isl_printer_print_*_to_*. * In particular, each key-value pair is separated by a colon, * the key-value pairs are separated by a comma and * the entire associative array is surrounded by braces. */ __isl_give ISL_HMAP *ISL_FN(ISL_HMAP,read_from_str)(isl_ctx *ctx, const char *str) { … } #endif