aboutsummaryrefslogtreecommitdiff
path: root/node.c
blob: bde1ed6e80132694bb9254c023ddc2ca3cd29473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "node.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

/*constructor*/
node* mknode(str)
char *str;
{
	node *p = malloc(sizeof(node));
	assert(p);

	p->name = str;
	p->next = NULL;

	p->var_type = -1;

	p->func_info = NULL;
	p->array_info = NULL;

	return p;
}

/* helpers */
node* list_search(root, str)
node *root;
char *str;
{
	node *p = root;
	while (p) {
		if (!strcmp(p->name, str)) {
			return p;
		}
		p = p->next;
	}
	return NULL;
}

node* list_insert(root, str)
node *root;
char * str;
{
	node *p = mknode( str );
	p->next = root;
	return p;
}
void free_node(n)
node *n;
{
	free(n->name);
	n->name = NULL;

	if (n->func_info) {
		if(n->func_info->argv)
			free(n->func_info->argv);
		n->func_info->argv = NULL;

		free(n->func_info);
	}
	n->func_info = NULL;

	if (n->array_info)
		free(n->array_info);
	n->array_info = NULL;

	free(n);
	n = NULL;
}

void free_list(n)
node *n;
{
	node *tmp;

	tmp = n;
	while(tmp) {
		n = tmp->next;
		free_node(tmp);
		tmp = n;
	}
}