From: Richard W.M. Jones Date: Sun, 1 Jan 2012 21:22:30 +0000 (+0000) Subject: More enums. X-Git-Url: http://git.annexia.org/?p=wrappi.git;a=commitdiff_plain;h=653a290091bdfafadcb92e09c1dbe6c2edb1cc79 More enums. --- diff --git a/generator/wrappi_c.ml b/generator/wrappi_c.ml index 80b832b..bdf65c8 100644 --- a/generator/wrappi_c.ml +++ b/generator/wrappi_c.ml @@ -111,9 +111,6 @@ typedef struct wrap_h wrap_h; pr " WRAP_%s_%s = %d,\n" (String.uppercase name) (String.uppercase id) i ) en.en_identifiers; - - pr " WRAP_%s_ENUM_MAX = %d\n" - (String.uppercase name) (Array.length en.en_identifiers); pr "};\n"; pr "typedef int wrap_%s_enum;\n" name; pr "\n"; diff --git a/generator/wrappi_enums.ml b/generator/wrappi_enums.ml index 3b33ec5..0e2c32c 100644 --- a/generator/wrappi_enums.ml +++ b/generator/wrappi_enums.ml @@ -86,7 +86,25 @@ let extend_api api = ep_includes = [] } in - eps := StringMap.add fname ep !eps + eps := StringMap.add fname ep !eps; + + (* Add an entry point wrap__enum_nr. *) + let fname = sprintf "%s_enum_nr" name in + let code = sprintf " return %d;\n" (Array.length en.en_identifiers) in + let c_code = { + cc_loc = Loc.ghost; + cc_code = code; + } in + let ep = { + ep_loc = Loc.ghost; + ep_local = true; + ep_name = fname; + ep_ftype = Return TInt, [], []; + ep_code = Some c_code; + ep_includes = [] + } in + + eps := StringMap.add fname ep !eps; ); { api with api_entry_points = !eps } diff --git a/lib/.gitignore b/lib/.gitignore index 2f8a6ba..846aa7f 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -6,5 +6,6 @@ /error-get_error_func.c /mkdir-mkdir.c /mknod-mknod_char.c +/ghost-location-scheme_enum_nr.c /ghost-location-scheme_enum_to_string.c /ghost-location-scheme_string_to_enum.c diff --git a/lib/implementation_files.mk b/lib/implementation_files.mk index 8290343..c0abae2 100644 --- a/lib/implementation_files.mk +++ b/lib/implementation_files.mk @@ -25,6 +25,7 @@ local_implementation_files := \ error-get_errno.c \ error-get_error.c \ error-get_error_func.c \ + ghost-location-scheme_enum_nr.c \ ghost-location-scheme_enum_to_string.c \ ghost-location-scheme_string_to_enum.c