1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

- added typedefs

- added parse error checking
- made parser more flexible
(This used to be commit ab0beaf357)
This commit is contained in:
Andrew Tridgell 2000-05-17 06:53:21 +00:00
parent c560164030
commit ba2f726efd
7 changed files with 130 additions and 64 deletions

View File

@ -2,6 +2,12 @@
file=$1
igawk -f main.awk $file
if ! igawk -f main.awk $file; then
echo parse failed;
exit 1;
fi
echo compiling vluke
gcc -Wall -g -o vluke parser.c vluke.c
echo done.

View File

@ -1,57 +1,22 @@
# the main program
@include dump.awk
@include parsetree.awk
@include header.awk
@include util.awk
@include template.awk
@include parsefn.awk
@include harness.awk
/^module/ {
start_module($2);
next;
}
/^test/ {
add_test($2);
next;
}
/^struct.*\{/ {
start_struct($2);
next;
}
/^[ \t]*union.*\{/ {
start_union($2);
next;
}
/^[ \t]*case.*;/ {
split($0,a,"[ \t;]*");
parse_case(a[3],a[4],a[5]);
next;
}
/^\};/ {
end_struct();
next;
}
/^[ \t]*\}/ {
end_union();
next;
}
/.*;/ {
split($0,a,"[ \t;]*");
add_struct_elem(a[2], a[3]);
}
@include parsetree.awk
@include token.awk
END {
dump_structs("debug.out");
dump_structs("dump.out");
printf("Producing headers...\n");
produce_headers("prs_"module".h");
printf("Producing parsers...\n");
produce_parsers("prs_"module".c");
printf("Producing harness...\n");
produce_harness("test.h");
printf("Done.\n");
exit 0;
}

View File

@ -15,7 +15,7 @@ function parse_array(f, v, elnum, flags,
v["FLAGS"] = flags;
v["ARRAY_LEN"] = elements[elnum, "array_len"];
if (type == "uint16") {
if (type == "wchar") {
print_template(f, "prs_wstring.tpl", v);
} else {
print_template(f, "prs_array.tpl", v);

View File

@ -25,6 +25,7 @@
typedef int BOOL;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned short wchar;
typedef unsigned uint32;
#define False 0

View File

@ -9,6 +9,19 @@ function start_module(name)
num_tests=0;
}
function parse_typedef(type1, type2,
LOCAL, type, i)
{
type=type2;
if (substr(type,1,1)=="*") type=substr(type,2);
i=match(type,"[[]");
if (i != 0) type = substr(type, 1, i-1);
start_struct(type);
add_struct_elem(type1, type2);
end_struct("");
}
function start_struct(name)
{
current_struct=num_structs;
@ -18,8 +31,9 @@ function start_struct(name)
structs[current_struct, "num_unions"]=0;
}
function end_struct()
function end_struct(name)
{
if (name!="") structs[num_structs, "name"]=name;
printf("struct %s with %d elements\n",
structs[num_structs, "name"],
structs[num_structs, "num_elems"]);

View File

@ -1,28 +1,16 @@
module srvsvc
#define SRV_NETCONNENUM 0x08
#define SRV_NETFILEENUM 0x09
#define SRV_NETSESSENUM 0x0c
#define SRV_NETSHAREENUM 0x0f
#define SRV_NET_SHARE_GET_INFO 0x10
#define SRV_NET_SRV_GET_INFO 0x15
#define SRV_NET_SRV_SET_INFO 0x16
#define SRV_NET_REMOTE_TOD 0x1c
typedef uint32 LONG;
typedef uint32 *ENUM_HND;
struct UNISTR2 {
typedef struct _UNISTR2 {
uint32 max_len;
uint32 undoc;
uint32 str_len;
uint16 buffer[str_len];
};
wchar buffer[str_len];
} UNISTR2;
struct LPWSTR {
UNISTR2 *str;
};
struct ENUM_HND {
uint32 *handle; /* enumeration handle */
};
typedef UNISTR2 *LPWSTR;
/* function 8 */
struct CONN_INFO_0 {

92
source3/aparser/token.awk Normal file
View File

@ -0,0 +1,92 @@
# tokenise the input file
function parse_error(msg) {
printf("PARSE ERROR: %s\nLine "NR" : "$0"\n", msg);
exit 1;
}
# ignore blank lines
/^[ \t]*$/ {
next;
}
# ignore comments
/^[ \t]*\#/ {
next;
}
# ignore C comments
/^[ \t]*\/\*.*\*\// {
next;
}
/^[ \t]*module/ {
{if (module!="") parse_error("you can only specify one module name");}
start_module($2);
next;
}
{if (module=="") parse_error("you must specify the module name first");}
/^[ \t]*typedef struct.*\{/ {
{if (current_struct!="") parse_error("you cannot have nested structures");}
start_struct($3);
next;
}
/^[ \t]*typedef.*;/ {
{if (current_struct!="") parse_error("typedefs must be global");}
split($0,a,"[ \t;]*");
parse_typedef(a[2], a[3]);
next;
}
/^[ \t]*struct.*\{/ {
{if (current_struct!="") parse_error("you cannot have nested structures");}
start_struct($2);
next;
}
{if (current_struct=="") parse_error("this must appear inside a structure");}
/^[ \t]*union.*\{/ {
{if (current_union!="") parse_error("you cannot have nested unions");}
start_union($2);
next;
}
/^[ \t]*case.*;/ {
{if (current_union=="") parse_error("this must appear inide a union");}
split($0,a,"[ \t;]*");
parse_case(a[3],a[4],a[5]);
next;
}
/^[ \t]*\}$/ {
{if (current_union=="") parse_error("this must appear inside a union");}
end_union();
next;
}
{if (current_union!="") parse_error("this cannot appear inside a union");}
/^[ \t]*\};/ {
end_struct("");
next;
}
/^[ \t]*\} .*;/ {
split($0,a,"[ \t;]*");
end_struct(a[2]);
next;
}
/^.*;/ {
split($0,a,"[ \t;]*");
add_struct_elem(a[2], a[3]);
next;
}
{
parse_error("Unknown construct.");
}