<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 25, 2021 at 1:25 AM Markus Armbruster <<a href="mailto:armbru@redhat.com">armbru@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">New enum QapiSpecialFeature enumerates the special feature flags.<br>
<br>
New helper gen_special_features() returns code to represent a<br>
collection of special feature flags as a bitset.<br>
<br>
The next few commits will put them to use.<br>
<br>
Signed-off-by: Markus Armbruster <<a href="mailto:armbru@redhat.com" target="_blank">armbru@redhat.com</a>><br>
---<br>
 include/qapi/util.h    |  4 ++++<br>
 scripts/qapi/gen.py    | 13 +++++++++++++<br>
 scripts/qapi/schema.py |  3 +++<br>
 3 files changed, 20 insertions(+)<br>
<br>
diff --git a/include/qapi/util.h b/include/qapi/util.h<br>
index 257c600f99..7a8d5c7d72 100644<br>
--- a/include/qapi/util.h<br>
+++ b/include/qapi/util.h<br>
@@ -11,6 +11,10 @@<br>
 #ifndef QAPI_UTIL_H<br>
 #define QAPI_UTIL_H<br>
<br>
+typedef enum {<br>
+    QAPI_DEPRECATED,<br>
+} QapiSpecialFeature;<br>
+<br>
 /* QEnumLookup flags */<br>
 #define QAPI_ENUM_DEPRECATED 1<br>
<br>
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py<br>
index 2ec1e7b3b6..9d07b88cf6 100644<br>
--- a/scripts/qapi/gen.py<br>
+++ b/scripts/qapi/gen.py<br>
@@ -29,6 +29,7 @@<br>
     mcgen,<br>
 )<br>
 from .schema import (<br>
+    QAPISchemaFeature,<br>
     QAPISchemaIfCond,<br>
     QAPISchemaModule,<br>
     QAPISchemaObjectType,<br>
@@ -37,6 +38,18 @@<br>
 from .source import QAPISourceInfo<br>
<br>
<br>
+def gen_special_features(features: QAPISchemaFeature):<br>
+    ret = ''<br>
+    sep = ''<br>
+<br>
+    for feat in features:<br>
+        if feat.is_special():<br>
+            ret += ('%s1u << QAPI_%s' % (sep, feat.name.upper()))<br></blockquote><div><br></div><div>Building the constant name here "feels" fragile, but I'll trust that the test suite and/or the compiler will catch us if we 
accidentally goof up this mapping. In the interest of simplicity, then, 
"sure, why not." <br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+            sep = ' | '<br>
+<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    return ret or '0'<br>
+<br></blockquote><div><br></div><div>Subjectively more pythonic:<br></div><div><br><div>special_features = [f"1u << QAPI_{feat.name.upper()}" for feat in features if feat.is_special()]</div><div>ret = ' | '.join(special_features)</div><div>return ret or '0'</div><div><br></div><div>A bit more dense, but more functional. Up to you, but I find join() easier to read and reason about for the presence of separators.<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
 class QAPIGen:<br>
     def __init__(self, fname: str):<br>
         self.fname = fname<br>
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py<br>
index 6d5f46509a..55f82d7389 100644<br>
--- a/scripts/qapi/schema.py<br>
+++ b/scripts/qapi/schema.py<br>
@@ -725,6 +725,9 @@ def connect_doc(self, doc):<br>
 class QAPISchemaFeature(QAPISchemaMember):<br>
     role = 'feature'<br>
<br>
+    def is_special(self):<br>
+        return <a href="http://self.name" rel="noreferrer" target="_blank">self.name</a> in ('deprecated')<br>
+<br></blockquote><div><br></div><div>alrighty.</div><div><br></div><div>(Briefly wondered: is it worth naming special features as a property of the class, but with only two names, it's probably fine enough to leave it embedded in the method logic. Only a style thing and doesn't have any actual impact that I can imagine, so ... nevermind.)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
 class QAPISchemaObjectTypeMember(QAPISchemaMember):<br>
     def __init__(self, name, info, typ, optional, ifcond=None, features=None):<br>
-- <br>
2.31.1<br>
<br></blockquote><div><br></div><div>Well, either way:</div><div><br></div><div>Reviewed-by: John Snow <<a href="mailto:jsnow@redhat.com">jsnow@redhat.com</a>><br></div></div></div>