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/parsefn.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/parsefn.awk')
-rw-r--r-- | source3/aparser/parsefn.awk | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/source3/aparser/parsefn.awk b/source3/aparser/parsefn.awk new file mode 100644 index 0000000000..b3421a7e54 --- /dev/null +++ b/source3/aparser/parsefn.awk @@ -0,0 +1,123 @@ +# build parse functions for a parsed struct file + +function parse_elem(f, v, struct_num, elem_num, + LOCAL, type, elem) +{ + type = structs[struct_num, elem_num, "type"]; + elem = structs[struct_num, elem_num, "elem"]; + v["ELEM"] = noptr(elem); + v["TYPE"] = type; + if (structs[type] != "") { + if (isaptr(elem)) { + print_template(f, "prs_struct_alloc.tpl", v); + } else { + print_template(f, "prs_struct.tpl", v); + } + } else { + print_template(f, "prs_"type".tpl", v); + } +} + + +function parse_pointer(f, v, struct_num, elem_num, + LOCAL, elem) +{ + elem = structs[struct_num, elem_num, "elem"]; + v["ELEM"] = noptr(elem); + print_template(f, "prs_pointer.tpl", v); +} + +function parse_array(f, v, struct_num, elem_num, + LOCAL, elem, type) +{ + elem = structs[struct_num, elem_num, "elem"]; + type = structs[struct_num, elem_num, "type"]; + v["ARRAYLEN"] = structs[struct_num, elem_num, "array_len"] + v["ELEM"] = elem; + v["TYPE"] = type; + print_template(f, "prs_array.tpl", v); +} + +function parse_union(f, v, struct_num, elem_num, + LOCAL, union, type, i, elem, value) +{ + union = structs[struct_num, elem_num, "elem"]; + v["UNION"] = noptr(union); + v["SWITCH"] = structs[struct_num, "unions", union, "switch"]; + + print_template(f, "union_start.tpl", v); + for (i=0;i<structs[struct_num, "unions", union, "num_elems"];i++) { + elem = structs[struct_num, "unions", union, i, "elem"]; + type = structs[struct_num, "unions", union, i, "type"]; + value = structs[struct_num, "unions", union, i, "value"]; + v["ELEM"] = v["UNION"]"->"noptr(elem); + v["TYPE"] = type; + v["VALUE"] = value; + print_template(f, "prs_case.tpl", v); + if (structs[type] != "") { + print_template(f, "prs_struct.tpl", v); + } else { + print_template(f, "prs_"type".tpl", v); + } + print_template(f, "prs_case_end.tpl", v); + } + + print_template(f, "union_end.tpl", v); +} + +function parse_ptr_elem(f, v, struct_num, elem_num, + LOCAL, elem, type) +{ + elem = structs[struct_num, elem_num, "elem"]; + type = structs[struct_num, elem_num, "type"]; + v["ELEM"] = noptr(elem); + print_template(f, "ifptr_start.tpl", v); + if (type == "union") { + parse_union(f, v, struct_num, elem_num); + } else { + parse_elem(f, v, struct_num, elem_num); + } + print_template(f, "ifptr_end.tpl", v); +} + + +function struct_parser(f, v, struct_num, + LOCAL, i) +{ + v["STRUCTNAME"] = structs[struct_num, "name"]; + v["FUNCNAME"] = v["MODULE"] "_io_" v["STRUCTNAME"]; + print_template(f, "fn_start.tpl", v); + + # first all the structure pointers, scalars and arrays + for (i=0;i<structs[struct_num, "num_elems"];i++) { + if (isaptr(structs[struct_num, i, "elem"])) { + parse_pointer(f, v, struct_num, i); + } else if (structs[struct_num, i, "array_len"]) { + parse_array(f, v, struct_num, i); + } else { + parse_elem(f, v, struct_num, i); + } + } + + # now the structures + for (i=0;i<structs[struct_num, "num_elems"];i++) { + if (!isaptr(structs[struct_num, i, "elem"])) continue; + parse_ptr_elem(f, v, struct_num, i); + } + + print_template(f, "fn_end.tpl", v); +} + +function produce_parsers(f, + LOCAL, v) +{ + v["MODULE"]=module; + + print_template(f, "module_start.tpl", v); + + for (i=0;i < num_structs;i++) { + struct_parser(f, v, i); + } + + print_template(f, "module_end.tpl", v); +} |