Lev Walkin | d922184 | 2017-08-22 01:44:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Structures and prototypes related to parameterization |
| 3 | */ |
| 4 | #ifndef ASN1_NAMESPACE_H |
| 5 | #define ASN1_NAMESPACE_H |
| 6 | |
| 7 | struct asn1p_ref_s; /* Forward declaration */ |
| 8 | struct asn1p_expr_s; /* Forward declaration */ |
| 9 | struct asn1p_module_s; /* Forward declaration */ |
| 10 | |
| 11 | typedef struct asn1_namespace_s { |
| 12 | struct asn1_namespace_element_s { |
| 13 | enum { |
| 14 | NAM_SPACE, /* The whole search space (e.g. Module) */ |
| 15 | NAM_SYMBOL, /* A particular symbol */ |
| 16 | } selector; |
| 17 | union { |
| 18 | struct { |
| 19 | struct asn1p_module_s *module; |
| 20 | int stop_search; /* This module MUST contain the symbol */ |
| 21 | } space; |
| 22 | struct { |
| 23 | struct asn1p_ref_s *opt_governor; /* optional */ |
| 24 | char *identifier; |
| 25 | struct asn1p_expr_s *resolution; |
| 26 | } symbol; |
| 27 | } u; |
| 28 | } *elements; |
| 29 | size_t elements_count; |
| 30 | size_t elements_size; |
| 31 | } asn1_namespace_t; |
| 32 | |
| 33 | /* |
| 34 | * Set callback used to initialize standard namespaces. |
| 35 | */ |
| 36 | void asn1_namespace_add_standard_namespaces_callback( |
| 37 | void (*)(asn1_namespace_t *)); |
| 38 | |
| 39 | asn1_namespace_t *asn1_namespace_new(void); |
| 40 | void asn1_namespace_free(asn1_namespace_t *); |
| 41 | |
| 42 | asn1_namespace_t *asn1_namespace_clone(const asn1_namespace_t *); |
| 43 | |
| 44 | asn1_namespace_t *asn1_namespace_new_from_module(struct asn1p_module_s *mod, int stop_search); |
| 45 | |
| 46 | void asn1_namespace_add_module(asn1_namespace_t *, |
| 47 | struct asn1p_module_s *module, int stop_search); |
| 48 | |
| 49 | void asn1_namespace_add_symbol(asn1_namespace_t *, |
| 50 | struct asn1p_ref_s *opt_governor, |
| 51 | const char *identifier, |
| 52 | struct asn1p_expr_s *resolved_argument); |
| 53 | |
| 54 | /* |
| 55 | * Human-readable namespace layout. |
| 56 | * Returns a reference to a statically allocated string. |
| 57 | */ |
| 58 | const char *asn1_namespace_string(const asn1_namespace_t *); |
| 59 | |
| 60 | /* |
| 61 | * Create a new namespace by cloning (ns1) and adding (ns2) on top. |
| 62 | * Destroys (ns2). |
| 63 | */ |
| 64 | asn1_namespace_t *asn1_namespace_new_ND(const asn1_namespace_t *ns1, |
| 65 | asn1_namespace_t *ns2); |
| 66 | |
| 67 | /* |
| 68 | * Introduce and destroy namespace around the given code. |
| 69 | * This aids memory management around dynamic namespaces. |
| 70 | */ |
| 71 | #define WITH_MODULE_NAMESPACE(mod, ns_var, code) \ |
| 72 | ({ \ |
| 73 | struct asn1_namespace_s *ns_var = \ |
| 74 | asn1_namespace_new_from_module(mod, 1); \ |
| 75 | typeof(code) ret = code; \ |
| 76 | asn1_namespace_free(ns_var); \ |
| 77 | ret; \ |
| 78 | }) |
| 79 | |
| 80 | #endif /* ASN1_NAMESPACE_H */ |