blob: 95ac50de34eba0366164e4841fc8cdf08bc44d57 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#include <stdlib.h>
2#include <string.h>
3
4#include "asn1parser.h"
5
6/*
7 * Construct a new empty module.
8 */
9asn1p_module_t *
10asn1p_module_new() {
11 asn1p_module_t *mod;
12
13 mod = calloc(1, sizeof *mod);
14 if(mod) {
Lev Walkinf15320b2004-06-03 03:38:44 +000015 TQ_INIT(&(mod->exports));
Lev Walkina9532f42006-09-17 04:52:50 +000016 TQ_INIT(&(mod->imports));
Lev Walkinf15320b2004-06-03 03:38:44 +000017 TQ_INIT(&(mod->members));
18 }
19 return mod;
20}
21
22/*
23 * Destroy the module.
24 */
25void
26asn1p_module_free(asn1p_module_t *mod) {
27 if(mod) {
28 asn1p_expr_t *expr;
29
Lev Walkind8b83642016-03-14 02:00:27 -070030 free(mod->ModuleName);
Bi-Ruei, Chiu12021b52016-11-04 11:59:45 +080031 free(mod->source_file_name);
Lev Walkinf15320b2004-06-03 03:38:44 +000032
Lev Walkin13e57ef2016-03-14 02:05:23 -070033 asn1p_oid_free(mod->module_oid);
Lev Walkinf15320b2004-06-03 03:38:44 +000034
35 while((expr = TQ_REMOVE(&(mod->members), next)))
36 asn1p_expr_free(expr);
37
38 free(mod);
39 }
40}
41
42asn1p_t *
43asn1p_new() {
44 asn1p_t *asn;
45 asn = calloc(1, sizeof(*asn));
46 if(asn) {
47 TQ_INIT(&(asn->modules));
48 }
49 return asn;
50}
51
52
53void
Lev Walkin9b5df842006-09-12 04:21:30 +000054asn1p_delete(asn1p_t *asn) {
Lev Walkinf15320b2004-06-03 03:38:44 +000055 if(asn) {
56 asn1p_module_t *mod;
57 while((mod = TQ_REMOVE(&(asn->modules), mod_next)))
58 asn1p_module_free(mod);
59 free(asn);
60 }
61}