52 #ifndef GENERIC_MAPPING_INCLUDED
53 #define GENERIC_MAPPING_INCLUDED
72 #define GENERIC_MAPPING(PREFIX, name, result, type) \
73 static type##_mapping name##_map = hash_table_undefined; \
74 PREFIX bool __attribute__ ((unused)) name##_map_undefined_p() { \
75 return name##_map == hash_table_undefined; \
77 PREFIX void __attribute__ ((unused)) set_##name##_map(type##_mapping m) { \
78 message_assert("mapping undefined", name##_map == hash_table_undefined); \
81 PREFIX type##_mapping __attribute__ ((unused)) get_##name##_map() { \
84 PREFIX void __attribute__ ((unused)) reset_##name##_map() { \
85 name##_map = hash_table_undefined; \
87 PREFIX void __attribute__ ((unused)) free_##name##_map() { \
88 hash_table_free(name##_map); name##_map = hash_table_undefined; \
90 PREFIX void __attribute__ ((unused)) make_##name##_map() { \
91 name##_map = hash_table_make(hash_pointer, HASH_DEFAULT_SIZE); \
93 PREFIX result __attribute__ ((unused)) load_##type##_##name(type s) { \
95 message_assert("key defined", s != type##_undefined); \
96 t = (result)(intptr_t) hash_get((hash_table) (name##_map), (void*) (s)); \
97 if (t ==(result)(intptr_t) HASH_UNDEFINED_VALUE) \
98 t = result##_undefined; \
101 PREFIX void __attribute__ ((unused)) delete_##type##_##name(type s) { \
102 message_assert("key defined", s != type##_undefined); \
103 (void) hash_del((hash_table) (name##_map), (void*) (s)); \
105 PREFIX bool __attribute__ ((unused)) type##_##name##_undefined_p(type s) { \
106 return(load_##type##_##name(s)==result##_undefined); \
108 PREFIX void __attribute__ ((unused)) store_##type##_##name(type s, result t) { \
109 message_assert("key defined", s != type##_undefined); \
110 message_assert("value defined", t != result##_undefined); \
111 hash_put((hash_table) name##_map, (void*) s, (void*)(intptr_t) t); \
113 PREFIX void __attribute__ ((unused)) update_##type##_##name(type s, result t) { \
114 message_assert("key defined", s != type##_undefined); \
115 message_assert("value defined", t != result##_undefined); \
116 hash_update((hash_table) name##_map, (void*) s, (void*)(intptr_t) t); \
119 #define GENERIC_CURRENT_MAPPING(name, result, type) \
120 GENERIC_MAPPING(extern, name, result, type)
126 #define GENERIC_LOCAL_MAPPING(name, result, type) \
127 GENERIC_MAPPING(static, name, result, type)