Skip to content

Commit

Permalink
qapi: Tools for sets of special feature flags in generated code
Browse files Browse the repository at this point in the history
New enum QapiSpecialFeature enumerates the special feature flags.

New helper gen_special_features() returns code to represent a
collection of special feature flags as a bitset.

The next few commits will put them to use.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-Id: <20211028102520.747396-5-armbru@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
  • Loading branch information
Markus Armbruster committed Oct 29, 2021
1 parent 9bafe07 commit c67db1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/qapi/util.h
Expand Up @@ -11,6 +11,10 @@
#ifndef QAPI_UTIL_H
#define QAPI_UTIL_H

typedef enum {
QAPI_DEPRECATED,
} QapiSpecialFeature;

/* QEnumLookup flags */
#define QAPI_ENUM_DEPRECATED 1

Expand Down
8 changes: 8 additions & 0 deletions scripts/qapi/gen.py
Expand Up @@ -18,6 +18,7 @@
Dict,
Iterator,
Optional,
Sequence,
Tuple,
)

Expand All @@ -29,6 +30,7 @@
mcgen,
)
from .schema import (
QAPISchemaFeature,
QAPISchemaIfCond,
QAPISchemaModule,
QAPISchemaObjectType,
Expand All @@ -37,6 +39,12 @@
from .source import QAPISourceInfo


def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str:
special_features = [f"1u << QAPI_{feat.name.upper()}"
for feat in features if feat.is_special()]
return ' | '.join(special_features) or '0'


class QAPIGen:
def __init__(self, fname: str):
self.fname = fname
Expand Down
3 changes: 3 additions & 0 deletions scripts/qapi/schema.py
Expand Up @@ -725,6 +725,9 @@ def connect_doc(self, doc):
class QAPISchemaFeature(QAPISchemaMember):
role = 'feature'

def is_special(self):
return self.name in ('deprecated')


class QAPISchemaObjectTypeMember(QAPISchemaMember):
def __init__(self, name, info, typ, optional, ifcond=None, features=None):
Expand Down

0 comments on commit c67db1e

Please sign in to comment.