From b7022e94d2ab62d522b0a7c2886cce3afaff6872 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 14 May 2000 14:05:10 +0000 Subject: 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) --- source3/aparser/parsefn.awk | 123 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 source3/aparser/parsefn.awk (limited to 'source3/aparser/parsefn.awk') 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"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