summaryrefslogtreecommitdiff
path: root/source3/aparser/dump.awk
blob: 65e5675513eb1ad3e2871bc0813976394b8b11c1 (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
# dump the current parse tree


function element_string(elnum,
			LOCAL, elem)
{
	elem = elements[elnum, "elem"];
	if (elements[elnum, "ptr"]=="1") elem="*"elem;
	if (elements[elnum, "array_len"]!="") 
		elem=elem"["elements[elnum, "array_len"]"]";
	if (elements[elnum, "switch"]!="") 
		elem=elem"["elements[elnum, "switch"]"]";
	return elem;
}

function dump_element(f, elnum,
		      LOCAL, elem, type)
{
	type = elements[elnum, "type"];
	case = elements[elnum, "case"];
	elem = element_string(elnum);
	if (case != "") {
		xprintf(f,"\t\tcase %d %s %s;\n", case, type, elem);
	} else {
		xprintf(f,"\t%s %s;\n", type, elem);
	}
}

function dump_union(f, elnum,
		    LOCAL, i) 
{
	xprintf(f,"\tunion %s {\n", element_string(elnum));
	for (i=0;i<unions[elnum, "num_elems"];i++) {
		dump_element(f, unions[elnum, i]);
	}
	xprintf(f,"\t}\n");
}

function dump_elem(f, struct_num, elem_num,
		   LOCAL, enum) 
{
	elnum = structs[struct_num, elem_num];

	if (elements[elnum, "type"] == "union") {
		dump_union(f, elnum);
	} else {
		dump_element(f, elnum);
	}
}

function dump_structs(f, NIL,
		      LOCAL, i, j) 
{
	xprintf(f,"/* dump of parsed structures */\n\n\n");
	for (i=0;i < num_structs;i++) {
		xprintf(f,"/* structure %d */\n", i);
		xprintf(f,"struct %s {\n", structs[i, "name"]);
		for (j=0;j<structs[i, "num_elems"];j++) {
			dump_elem(f, i, j);
		}
		xprintf(f,"};\n\n");
	}
	xprintf(f,"/* end dump */\n\n");
}