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/dump.awk | |
parent | b7f9a2794273266a0c64a6c02f88d65d37554ea9 (diff) | |
download | samba-b7022e94d2ab62d522b0a7c2886cce3afaff6872.tar.gz |
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/dump.awk')
-rw-r--r-- | source3/aparser/dump.awk | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source3/aparser/dump.awk b/source3/aparser/dump.awk new file mode 100644 index 00000000000..0a72bb84143 --- /dev/null +++ b/source3/aparser/dump.awk @@ -0,0 +1,55 @@ +# dump the current parse tree + +function dump_union(f, struct_num, union, + LOCAL, i) +{ + xprintf(f,"\tunion %s %s {\n", + structs[struct_num, "unions", union, "switch"], + union); + for (i=0;i<structs[struct_num, "unions", union, "num_elems"];i++) { + xprintf(f,"\t\tcase %d %s %s;\n", + structs[struct_num, "unions", union, i, "value"], + structs[struct_num, "unions", union, i, "type"], + structs[struct_num, "unions", union, i, "elem"]); + } + xprintf(f,"\t}\n"); +} + +function dump_array(f, struct_num, elem_num, + LOCAL, i) +{ + xprintf(f,"\t{%s} %s %s;\n", + structs[struct_num, elem_num, "array_len"], + structs[struct_num, elem_num, "type"], + structs[struct_num, elem_num, "elem"]); +} + +function dump_elem(f, struct_num, elem_num) +{ + if (structs[struct_num, elem_num, "type"] == "union") { + dump_union(f, struct_num, structs[struct_num, elem_num, "elem"]); + } else if (structs[struct_num, elem_num, "array_len"]) { + dump_array(f, struct_num, elem_num); + } else { + xprintf(f,"\t%s %s;\n", + structs[struct_num, elem_num, "type"], + structs[struct_num, elem_num, "elem"]); + } +} + +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"); +} + + |