diff options
author | Andrew Tridgell <tridge@samba.org> | 2000-05-14 14:05:10 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2000-05-14 14:05:10 +0000 |
commit | b7022e94d2ab62d522b0a7c2886cce3afaff6872 (patch) | |
tree | 6663fe08efd72d9a95d9cf4cf70baa07ded15aca /source3/aparser/parsetree.awk | |
parent | b7f9a2794273266a0c64a6c02f88d65d37554ea9 (diff) | |
download | samba-b7022e94d2ab62d522b0a7c2886cce3afaff6872.tar.gz samba-b7022e94d2ab62d522b0a7c2886cce3afaff6872.tar.bz2 samba-b7022e94d2ab62d522b0a7c2886cce3afaff6872.zip |
vastly improved awk based code generator
now handles recursive function definitions, unions etc
it is sufficient for some basic types like UNISTR2 and BUFFER5
to be defined in the *.struct file and used successfully
this generator uses templates (in *.tpl files) for all code
generation, allowing easy replacement of the backend functions
(This used to be commit 14ded82dc92ae6eff7639351f391a33b9cc31c0d)
Diffstat (limited to 'source3/aparser/parsetree.awk')
-rw-r--r-- | source3/aparser/parsetree.awk | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/source3/aparser/parsetree.awk b/source3/aparser/parsetree.awk new file mode 100644 index 0000000000..e0f946a663 --- /dev/null +++ b/source3/aparser/parsetree.awk @@ -0,0 +1,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=""; +} + |