blob: 1ae3d7b911242c897ea09b1e66322328211d2deb [file] [log] [blame]
Lev Walkind9221842017-08-22 01:44:56 -07001/*
2 * Structures and prototypes related to parameterization
3 */
4#ifndef ASN1_NAMESPACE_H
5#define ASN1_NAMESPACE_H
6
7struct asn1p_ref_s; /* Forward declaration */
8struct asn1p_expr_s; /* Forward declaration */
9struct asn1p_module_s; /* Forward declaration */
10
11typedef 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 */
36void asn1_namespace_add_standard_namespaces_callback(
37 void (*)(asn1_namespace_t *));
38
39asn1_namespace_t *asn1_namespace_new(void);
40void asn1_namespace_free(asn1_namespace_t *);
41
42asn1_namespace_t *asn1_namespace_clone(const asn1_namespace_t *);
43
44asn1_namespace_t *asn1_namespace_new_from_module(struct asn1p_module_s *mod, int stop_search);
45
46void asn1_namespace_add_module(asn1_namespace_t *,
47 struct asn1p_module_s *module, int stop_search);
48
49void 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 */
58const 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 */
64asn1_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 */