diff options
author | Matthew Booth <mbooth@redhat.com> | 2012-01-09 10:16:35 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-01-10 15:41:15 +0000 |
commit | ae41a597178ece16e976fa9bdd0319745ad1e87a (patch) | |
tree | 00a4f45ae638683c1318743219500c45b448f531 /generator/generator_capitests.ml | |
parent | afc9f277733ae4f9b7599d50f4114b2d32725049 (diff) | |
download | libguestfs-ae41a597178ece16e976fa9bdd0319745ad1e87a.tar.gz libguestfs-ae41a597178ece16e976fa9bdd0319745ad1e87a.tar.xz libguestfs-ae41a597178ece16e976fa9bdd0319745ad1e87a.zip |
generator: Create a separate type for optional arguments
Previously, optional arguments had the same type as regular arguments, but were
constrained by various runtime tests to be only Bool, Int, Int64 or String. This
change makes the type of optional arguments stronger by giving them their own
type.
A convenience function, optargs_to_args is defined to convert optargs in the few
places where they are genuinely treated identically to mandatory arguments.
It also allows for future changes to optional arguments which do not affect
mandatory arguments.
RWMJ:
- removed redundant parens
- readded the check for > 64 optargs, but changed it to > 63
- changed the new function to args_of_optargs
(cherry picked from commit 0a7b734d2f54d4e98882532da9887feb66c9824a)
Diffstat (limited to 'generator/generator_capitests.ml')
-rw-r--r-- | generator/generator_capitests.ml | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/generator/generator_capitests.ml b/generator/generator_capitests.ml index fefc6e22..bbfdfc7a 100644 --- a/generator/generator_capitests.ml +++ b/generator/generator_capitests.ml @@ -820,29 +820,28 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = fun (shift, bitmask) optarg -> let is_set = match optarg with - | Bool n, "" -> false - | Bool n, "true" -> + | OBool n, "" -> false + | OBool n, "true" -> pr " optargs.%s = 1;\n" n; true - | Bool n, "false" -> + | OBool n, "false" -> pr " optargs.%s = 0;\n" n; true - | Bool n, arg -> + | OBool n, arg -> failwithf "boolean optional arg '%s' should be empty string or \"true\" or \"false\"" n - | Int n, "" -> false - | Int n, i -> + | OInt n, "" -> false + | OInt n, i -> let i = try int_of_string i with Failure _ -> failwithf "integer optional arg '%s' should be empty string or number" n in pr " optargs.%s = %d;\n" n i; true - | Int64 n, "" -> false - | Int64 n, i -> + | OInt64 n, "" -> false + | OInt64 n, i -> let i = try Int64.of_string i with Failure _ -> failwithf "int64 optional arg '%s' should be empty string or number" n in pr " optargs.%s = %Ld;\n" n i; true - | String n, "NOARG" -> false - | String n, arg -> - pr " optargs.%s = \"%s\";\n" n (c_quote arg); true - | _ -> assert false in + | OString n, "NOARG" -> false + | OString n, arg -> + pr " optargs.%s = \"%s\";\n" n (c_quote arg); true in let bit = if is_set then Int64.shift_left 1L shift else 0L in let bitmask = Int64.logor bitmask bit in let shift = shift + 1 in |