From 9ba02574cefd8004e30d2f15b1eac0a7b395f681 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 16 Nov 2012 14:24:20 +0100 Subject: [PATCH] Add custom code for CV_E* constants to convert-constants Currently, the cluster verify errors are defined as follows: CV_ECLUSTER_FOO = (TCLUSTER, "ECLUSTER_FOO", "description") This means there's no standalone name for the string "ECLUSTER_FOO", which makes it hard to derive automatically a type for this union in Haskell. There are three possible fixes: - manually separate the CV_ECLUSTER_FOO_STR = "ECLUSTER_FOO" in constants.py - manually extract the strings in Haskell code - change convert-constants to automatically export virtual constants for those After discussion on IRC, I've taken the latter approach; even though a bit hack-ish, it avoids manual work and potential errors. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- autotools/convert-constants | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autotools/convert-constants b/autotools/convert-constants index 1d18540cd..e61a72336 100755 --- a/autotools/convert-constants +++ b/autotools/convert-constants @@ -231,6 +231,13 @@ def ConvertVariable(prefix, name, value, all_items): value[k], all_items)) elif isinstance(value, tuple): tvs = [HaskellTypeVal(elem) for elem in value] + # Custom rule for special cluster verify error tuples + if name.startswith("CV_E") and len(value) == 3 and tvs[1][0] is not None: + cv_ename = hs_name + "Code" + lines.append("-- | Special cluster verify code %s" % name) + lines.append("%s :: %s" % (cv_ename, tvs[1][0])) + lines.append("%s = %s" % (cv_ename, tvs[1][1])) + lines.append("") if compat.all(e is not None for e in tvs): ttypes = ", ".join(e[0] for e in tvs) tvals = FormatListElems(all_items, pfx_name, value, [e[1] for e in tvs]) -- GitLab