[PATCH 03/14] qapi: cope with special feature names containing a '-'

Daniel P. Berrangé posted 14 patches 5 months, 3 weeks ago
[PATCH 03/14] qapi: cope with special feature names containing a '-'
Posted by Daniel P. Berrangé 5 months, 3 weeks ago
When we shortly allow custom special feature names to be defined, it
will be valid to include a '-', which must be translated to a '_'
when generating code.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/qapi/gen.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 9c590a1c2e..650efc59ed 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -41,7 +41,7 @@
 
 
 def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str:
-    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper()}"
+    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper().replace('-','_')}"
                         for feat in features if feat.is_special()]
     return ' | '.join(special_features) or '0'
 
-- 
2.45.1


Re: [PATCH 03/14] qapi: cope with special feature names containing a '-'
Posted by Markus Armbruster 4 months, 2 weeks ago
Daniel P. Berrangé <berrange@redhat.com> writes:

> When we shortly allow custom special feature names to be defined, it
> will be valid to include a '-', which must be translated to a '_'
> when generating code.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/qapi/gen.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
> index 9c590a1c2e..650efc59ed 100644
> --- a/scripts/qapi/gen.py
> +++ b/scripts/qapi/gen.py
> @@ -41,7 +41,7 @@
>  
>  
>  def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str:
> -    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper()}"
> +    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper().replace('-','_')}"
>                          for feat in features if feat.is_special()]
>      return ' | '.join(special_features) or '0'

I'd prefer something like

    f"1 << {c_enum_const('QAPI_FEATURE', feat.name)}"