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
84
85
|
# build the parse tree for a struct file
function start_module(name)
{
module=name;
num_structs=0;
num_elements=0;
num_unions=0;
num_tests=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()
{
printf("struct %s with %d elements\n",
structs[num_structs, "name"],
structs[num_structs, "num_elems"]);
num_structs++;
current_struct="";
}
function add_element(type, elem, case,
LOCAL, elem_num, i, v)
{
elem_num=num_elements;
if (substr(elem, 1, 1) == "*") {
elem=substr(elem, 2);
elements[elem_num, "ptr"]=1;
}
i=match(elem,"[[]");
if (i != 0) {
v = substr(elem, i+1, length(elem)-i-1);
elem=substr(elem, 1, i-1);
if (type=="union") {
elements[elem_num, "switch"] = v;
} else {
elements[elem_num, "array_len"] = v;
}
}
elements[elem_num, "type"] = type;
elements[elem_num, "elem"] = elem;
elements[elem_num, "case"] = case;
num_elements++;
return elem_num;
}
function add_struct_elem(type, elem, case,
LOCAL, elem_num)
{
elem_num=structs[current_struct, "num_elems"];
structs[current_struct, elem_num] = add_element(type, elem, case);
structs[current_struct, "num_elems"]++;
return structs[current_struct, elem_num];
}
function start_union(elem)
{
current_union = add_struct_elem("union", elem);
unions[current_union, "num_elems"] = 0;
}
function parse_case(case, type, elem,
LOCAL, elem_num)
{
elem_num = unions[current_union, "num_elems"];
unions[current_union, elem_num] = add_element(type, elem, case);
unions[current_union, "num_elems"]++;
}
function end_union()
{
current_union="";
}
|