@@ -209,20 +209,18 @@ class IfCond:
return NotImplemented
return self.ifcond == other.ifcond
-
-def gen_if(c: IfCond) -> str:
- ret = ''
- for ifc in c.ifcond:
- ret += mcgen('''
+ def gen_if(self) -> str:
+ ret = ''
+ for ifc in self.ifcond:
+ ret += mcgen('''
#if %(cond)s
''', cond=ifc)
- return ret
-
+ return ret
-def gen_endif(c: IfCond) -> str:
- ret = ''
- for ifc in reversed(c.ifcond):
- ret += mcgen('''
+ def gen_endif(self) -> str:
+ ret = ''
+ for ifc in reversed(self.ifcond):
+ ret += mcgen('''
#endif /* %(cond)s */
''', cond=ifc)
- return ret
+ return ret
@@ -26,8 +26,6 @@ from .common import (
IfCond,
c_fname,
c_name,
- gen_endif,
- gen_if,
guardend,
guardstart,
mcgen,
@@ -92,9 +90,9 @@ def _wrap_ifcond(ifcond: IfCond, before: str, after: str) -> str:
if added[0] == '\n':
out += '\n'
added = added[1:]
- out += gen_if(ifcond)
+ out += ifcond.gen_if()
out += added
- out += gen_endif(ifcond)
+ out += ifcond.gen_endif()
return out
@@ -23,8 +23,6 @@ from typing import (
from .common import (
IfCond,
c_name,
- gen_endif,
- gen_if,
mcgen,
)
from .gen import QAPISchemaMonolithicCVisitor
@@ -77,10 +75,10 @@ def _tree_to_qlit(obj: TreeNode, level: int = 0,
if obj.comment:
ret += indent(level) + '/* %s */\n' % obj.comment
if obj.ifcond:
- ret += gen_if(obj.ifcond)
+ ret += obj.ifcond.gen_if()
ret += _tree_to_qlit(obj.data, level)
if obj.ifcond:
- ret += '\n' + gen_endif(obj.ifcond)
+ ret += '\n' + obj.ifcond.gen_endif()
return ret
ret = ''
@@ -19,8 +19,6 @@ from .common import (
IfCond,
c_enum_const,
c_name,
- gen_endif,
- gen_if,
mcgen,
)
from .gen import QAPISchemaModularCVisitor, ifcontext
@@ -51,13 +49,13 @@ const QEnumLookup %(c_name)s_lookup = {
''',
c_name=c_name(name))
for memb in members:
- ret += gen_if(memb.ifcond)
+ ret += memb.ifcond.gen_if()
index = c_enum_const(name, memb.name, prefix)
ret += mcgen('''
[%(index)s] = "%(name)s",
''',
index=index, name=memb.name)
- ret += gen_endif(memb.ifcond)
+ ret += memb.ifcond.gen_endif()
ret += mcgen('''
},
@@ -81,12 +79,12 @@ typedef enum %(c_name)s {
c_name=c_name(name))
for memb in enum_members:
- ret += gen_if(memb.ifcond)
+ ret += memb.ifcond.gen_if()
ret += mcgen('''
%(c_enum)s,
''',
c_enum=c_enum_const(name, memb.name, prefix))
- ret += gen_endif(memb.ifcond)
+ ret += memb.ifcond.gen_endif()
ret += mcgen('''
} %(c_name)s;
@@ -126,7 +124,7 @@ struct %(c_name)s {
def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str:
ret = ''
for memb in members:
- ret += gen_if(memb.ifcond)
+ ret += memb.ifcond.gen_if()
if memb.optional:
ret += mcgen('''
bool has_%(c_name)s;
@@ -136,7 +134,7 @@ def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str:
%(c_type)s %(c_name)s;
''',
c_type=memb.type.c_type(), c_name=c_name(memb.name))
- ret += gen_endif(memb.ifcond)
+ ret += memb.ifcond.gen_endif()
return ret
@@ -159,7 +157,7 @@ def gen_object(name: str, ifcond: IfCond,
ret += mcgen('''
''')
- ret += gen_if(ifcond)
+ ret += ifcond.gen_if()
ret += mcgen('''
struct %(c_name)s {
''',
@@ -193,7 +191,7 @@ struct %(c_name)s {
ret += mcgen('''
};
''')
- ret += gen_endif(ifcond)
+ ret += ifcond.gen_endif()
return ret
@@ -220,13 +218,13 @@ def gen_variants(variants: QAPISchemaVariants) -> str:
for var in variants.variants:
if var.type.name == 'q_empty':
continue
- ret += gen_if(var.ifcond)
+ ret += var.ifcond.gen_if()
ret += mcgen('''
%(c_type)s %(c_name)s;
''',
c_type=var.type.c_unboxed_type(),
c_name=c_name(var.name))
- ret += gen_endif(var.ifcond)
+ ret += var.ifcond.gen_endif()
ret += mcgen('''
} u;
@@ -19,8 +19,6 @@ from .common import (
IfCond,
c_enum_const,
c_name,
- gen_endif,
- gen_if,
indent,
mcgen,
)
@@ -78,7 +76,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
c_type=base.c_name())
for memb in members:
- ret += gen_if(memb.ifcond)
+ ret += memb.ifcond.gen_if()
if memb.optional:
ret += mcgen('''
if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) {
@@ -97,7 +95,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
ret += mcgen('''
}
''')
- ret += gen_endif(memb.ifcond)
+ ret += memb.ifcond.gen_endif()
if variants:
tag_member = variants.tag_member
@@ -111,7 +109,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
for var in variants.variants:
case_str = c_enum_const(tag_member.type.name, var.name,
tag_member.type.prefix)
- ret += gen_if(var.ifcond)
+ ret += var.ifcond.gen_if()
if var.type.name == 'q_empty':
# valid variant and nothing to do
ret += mcgen('''
@@ -127,7 +125,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
case=case_str,
c_type=var.type.c_name(), c_name=c_name(var.name))
- ret += gen_endif(var.ifcond)
+ ret += var.ifcond.gen_endif()
ret += mcgen('''
default:
abort();
@@ -213,7 +211,7 @@ bool visit_type_%(c_name)s(Visitor *v, const char *name,
c_name=c_name(name))
for var in variants.variants:
- ret += gen_if(var.ifcond)
+ ret += var.ifcond.gen_if()
ret += mcgen('''
case %(case)s:
''',
@@ -239,7 +237,7 @@ bool visit_type_%(c_name)s(Visitor *v, const char *name,
ret += mcgen('''
break;
''')
- ret += gen_endif(var.ifcond)
+ ret += var.ifcond.gen_endif()
ret += mcgen('''
case QTYPE_NONE: