From 38e9518c97b2ae11b68382afa1ecae7feceeae2a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 31 Dec 2011 13:13:47 +0000 Subject: [PATCH] Better error checking. --- APIs/Makefile.am | 2 +- APIs/fileperm.api | 2 ++ APIs/mknod.api | 3 --- APIs/pathname.api | 2 ++ generator-lib/wrappi_accumulator.ml | 19 +++++++++++++------ 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 APIs/fileperm.api create mode 100644 APIs/pathname.api diff --git a/APIs/Makefile.am b/APIs/Makefile.am index 1ad90e5..74813ff 100644 --- a/APIs/Makefile.am +++ b/APIs/Makefile.am @@ -21,7 +21,7 @@ OCAMLOPTFLAGS = $(OCAMLCFLAGS) PP = -pp '$(CAMLP4O) ../generator-macros/pa_wrap.cmo -impl' #API_FILES = $(wildcard *.api) -API_FILES = mkdir.api mknod.api +API_FILES = fileperm.api mkdir.api mknod.api pathname.api OBJECTS = $(patsubst %.api,%.cmo,$(API_FILES)) diff --git a/APIs/fileperm.api b/APIs/fileperm.api new file mode 100644 index 0000000..38c654b --- /dev/null +++ b/APIs/fileperm.api @@ -0,0 +1,2 @@ +(* XXX preconditions XXX *) +typedef int fileperm diff --git a/APIs/mknod.api b/APIs/mknod.api index 6c06a5b..bc0ba02 100644 --- a/APIs/mknod.api +++ b/APIs/mknod.api @@ -1,6 +1,3 @@ -typedef int fileperm ;; (* XXX preconditions XXX *) -typedef string pathname ;; - entry_point err mknod_char (pathname path, fileperm perm, uint64 major, uint64 minor) << diff --git a/APIs/pathname.api b/APIs/pathname.api new file mode 100644 index 0000000..7398460 --- /dev/null +++ b/APIs/pathname.api @@ -0,0 +1,2 @@ +(* XXX precondition that this is non-empty *) +typedef string pathname diff --git a/generator-lib/wrappi_accumulator.ml b/generator-lib/wrappi_accumulator.ml index 1254979..e2af4f8 100644 --- a/generator-lib/wrappi_accumulator.ml +++ b/generator-lib/wrappi_accumulator.ml @@ -26,12 +26,12 @@ open Printf let check_not_defined name new_ map thing get_loc = try let old = StringMap.find name map in - eprintf "generator: %s %s redefined\n" thing name; + eprintf "generator: error: %s %s redefined\n" thing name; let old_loc = get_loc old in let new_loc = get_loc new_ in - eprintf " first definition at %s:%d\n" + eprintf " first definition at %s line %d\n" (Loc.file_name old_loc) (Loc.start_line old_loc); - eprintf " second definition at %s:%d\n" + eprintf " second definition at %s line %d\n" (Loc.file_name new_loc) (Loc.start_line new_loc); exit 1 with @@ -86,10 +86,17 @@ let rec resolve_typedefs thing name loc = function | TNullable t -> TNullable (resolve_typedefs thing name loc t) | TTypedef tname -> - try (StringMap.find tname !tds).td_type + try + let td = StringMap.find tname !tds in + let t = td.td_type in + (* The typedef may be a typedef, so we need to recursively + * resolve the type. + *) + resolve_typedefs "typedef" td.td_name td.td_loc t with Not_found -> - eprintf "generator: could not resolve typedef %s\n" tname; - eprintf " in definition of %s %s at %s:%d\n" + eprintf "generator: error: could not resolve typedef %s to a basic type\n" + tname; + eprintf " in definition of %s %s at %s line %d\n" thing name (Loc.file_name loc) (Loc.start_line loc); exit 1 -- 1.8.3.1