Make all ints size_t
We should be consistent when we declare index types. Nlohmann uses an
underlying uint64_t as the integer type, so use that for all index
types.
Size_t is directly creatable from it in both 32 and 64 bit modes.
Tested: On last patch in series.
Change-Id: Id1da0e7be2e2046bdbd732247d208b6e9e8c008c
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index a7eb5bf..ceb781f 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -237,47 +237,41 @@
def make_error_function(entry_id, entry, is_header):
-
- arg_as_url = {
- "AccessDenied": [1],
- "CouldNotEstablishConnection": [1],
- "GenerateSecretKeyRequired": [1],
- "InvalidObject": [1],
- "PasswordChangeRequired": [1],
- "PropertyValueResourceConflict": [3],
- "ResetRequired": [1],
- "ResourceAtUriInUnknownFormat": [1],
- "ResourceAtUriUnauthorized": [1],
- "ResourceCreationConflict": [1],
- "ResourceMissingAtURI": [1],
- "SourceDoesNotSupportProtocol": [1],
- }
-
- arg_as_json = {
- "ActionParameterValueError": [1],
- "ActionParameterValueFormatError": [1],
- "ActionParameterValueTypeError": [1],
- "PropertyValueExternalConflict": [2],
- "PropertyValueFormatError": [1],
- "PropertyValueIncorrect": [2],
- "PropertyValueModified": [2],
- "PropertyValueNotInList": [1],
- "PropertyValueOutOfRange": [1],
- "PropertyValueResourceConflict": [2],
- "PropertyValueTypeError": [1],
- "QueryParameterValueFormatError": [1],
- "QueryParameterValueTypeError": [1],
- }
-
- arg_as_int = {
- "StringValueTooLong": [2],
- }
-
- arg_as_uint64 = {
- "ArraySizeTooLong": [2],
- }
- arg_as_int64 = {
- "InvalidIndex": [1],
+ arg_nonstring_types = {
+ "const boost::urls::url_view_base&": {
+ "AccessDenied": [1],
+ "CouldNotEstablishConnection": [1],
+ "GenerateSecretKeyRequired": [1],
+ "InvalidObject": [1],
+ "PasswordChangeRequired": [1],
+ "PropertyValueResourceConflict": [3],
+ "ResetRequired": [1],
+ "ResourceAtUriInUnknownFormat": [1],
+ "ResourceAtUriUnauthorized": [1],
+ "ResourceCreationConflict": [1],
+ "ResourceMissingAtURI": [1],
+ "SourceDoesNotSupportProtocol": [1],
+ },
+ "const nlohmann::json&": {
+ "ActionParameterValueError": [1],
+ "ActionParameterValueFormatError": [1],
+ "ActionParameterValueTypeError": [1],
+ "PropertyValueExternalConflict": [2],
+ "PropertyValueFormatError": [1],
+ "PropertyValueIncorrect": [2],
+ "PropertyValueModified": [2],
+ "PropertyValueNotInList": [1],
+ "PropertyValueOutOfRange": [1],
+ "PropertyValueResourceConflict": [2],
+ "PropertyValueTypeError": [1],
+ "QueryParameterValueFormatError": [1],
+ "QueryParameterValueTypeError": [1],
+ },
+ "uint64_t": {
+ "ArraySizeTooLong": [2],
+ "InvalidIndex": [1],
+ "StringValueTooLong": [2],
+ },
}
out = ""
@@ -285,18 +279,11 @@
argtypes = []
for arg_index, arg in enumerate(entry.get("ParamTypes", [])):
arg_index += 1
- if arg_index in arg_as_url.get(entry_id, []):
- typename = "const boost::urls::url_view_base&"
- elif arg_index in arg_as_json.get(entry_id, []):
- typename = "const nlohmann::json&"
- elif arg_index in arg_as_int.get(entry_id, []):
- typename = "int"
- elif arg_index in arg_as_uint64.get(entry_id, []):
- typename = "uint64_t"
- elif arg_index in arg_as_int64.get(entry_id, []):
- typename = "int64_t"
- else:
- typename = "std::string_view"
+ typename = "std::string_view"
+ for typestring, entries in arg_nonstring_types.items():
+ if arg_index in entries.get(entry_id, []):
+ typename = typestring
+
argtypes.append(typename)
args.append(f"{typename} arg{arg_index}")
function_name = entry_id[0].lower() + entry_id[1:]
@@ -314,7 +301,7 @@
index += 1
if typename == "const nlohmann::json&":
out += f"std::string arg{index}Str = arg{index}.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);\n"
- elif typename in ("int64_t", "int", "uint64_t"):
+ elif typename == "uint64_t":
out += f"std::string arg{index}Str = std::to_string(arg{index});\n"
for index, typename in enumerate(argtypes):
@@ -325,13 +312,12 @@
elif typename == "const nlohmann::json&":
outargs.append(f"arg{index}Str")
to_array_type = "<std::string_view>"
- elif typename in ("int64_t", "int", "uint64_t"):
+ elif typename == "uint64_t":
outargs.append(f"arg{index}Str")
to_array_type = "<std::string_view>"
else:
outargs.append(f"arg{index}")
argstring = ", ".join(outargs)
- # out += f" std::array<std::string_view, {len(argtypes)}> args{{{argstring}}};\n"
if argtypes:
arg_param = f"std::to_array{to_array_type}({{{argstring}}})"