Skip to content
Snippets Groups Projects
Commit 806aa124 authored by Iustin Pop's avatar Iustin Pop
Browse files

Enhance convert-constants list generation


While looking at the hypervisor types in Constants.hs, I saw that the
'hyperTypes' list is using strings instead of names. This is due to
the fact that we require the entire elements in the list to be
identified (homogeneous lists), but the string "xen-pvm" is declared
by both 'defaultEnabledHypervisor' and 'htXenPvm'.

We can improve convert-constants by adding a list of names that we
know (statically) don't declare, but instead reuse values. Unless we
have an ADT parser, this is the best we can do, I think.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 998b6f8b
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,12 @@ PRIVATE_RE = re.compile("^__.+__$") ...@@ -39,6 +39,12 @@ PRIVATE_RE = re.compile("^__.+__$")
#: The type of regex objects #: The type of regex objects
RE_TYPE = type(CONSTANT_RE) RE_TYPE = type(CONSTANT_RE)
#: Keys which do not declare a value (manually maintained). By adding
# values here, we can make more lists use the actual names; otherwise
# we'll have (e.g.) both DEFAULT_ENABLED_HYPERVISOR and HT_XEN_PVM
# declare the same value, and thus the list of valid hypervisors will
# have strings instead of easily looked-up names.
IGNORED_DECL_NAMES = ["DEFAULT_ENABLED_HYPERVISOR"]
def NameRules(name): def NameRules(name):
"""Converts the upper-cased Python name to Haskell camelCase. """Converts the upper-cased Python name to Haskell camelCase.
...@@ -97,7 +103,8 @@ def IdentifyOrigin(all_items, value): ...@@ -97,7 +103,8 @@ def IdentifyOrigin(all_items, value):
@param value: the value for which we try to find an origin @param value: the value for which we try to find an origin
""" """
found = [name for (name, v) in all_items.items() if v is value] found = [name for (name, v) in all_items.items()
if v is value and name not in IGNORED_DECL_NAMES]
if len(found) == 1: if len(found) == 1:
return found[0] return found[0]
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment