summaryrefslogtreecommitdiff
path: root/source3/aparser/parsetree.awk
blob: e0f946a663ed51d67c71b3b88924ee1d1c30dd9c (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
# build the parse tree for a struct file

function start_module(name) 
{
	module=name;
	num_structs=0;
}

function start_struct(name) 
{
	current_struct=num_structs;
	structs[name]=current_struct;
	structs[current_struct, "name"]=name;
	structs[current_struct, "num_elems"]=0;
	structs[current_struct, "num_unions"]=0;
}

function end_struct() 
{
	num_structs++;
	current_struct="";
}

function add_elem(type, elem,
		  LOCAL, elem_num)
{
	elem_num=structs[current_struct, "num_elems"];
	structs[current_struct, elem_num, "type"] = type;
	structs[current_struct, elem_num, "elem"] = elem;
	structs[current_struct, elem_num, "array_len"] = "";
	structs[current_struct, "num_elems"]++;
	return elem_num;
}

function add_array(array_len, type, elem,
		   LOCAL, elem_num)
{
	elem_num=add_elem(type, elem);
	structs[current_struct, elem_num, "array_len"] = array_len;
}

function start_union(switch, elem) 
{
	current_union=elem;
	add_elem("union", elem);
	structs[current_struct, "unions", current_union, "switch"] = switch;
	structs[current_struct, "unions", current_union, "num_elems"] = 0;
}

function parse_case(value, type, elem,
		    LOCAL, elem_num) 
{
	elem_num =structs[current_struct, "unions", current_union, "num_elems"];
	structs[current_struct, "unions", current_union, elem_num, "type"] = type;
	structs[current_struct, "unions", current_union, elem_num, "elem"] = elem;
	structs[current_struct, "unions", current_union, elem_num, "value"] = value;
	structs[current_struct, "unions", current_union, "num_elems"]++;
}

function end_union() 
{
	current_union="";
}