summaryrefslogtreecommitdiffstats
path: root/scripts/qapi/visit.py
diff options
context:
space:
mode:
authorJohn Snow2020-10-09 18:15:33 +0200
committerMarkus Armbruster2020-10-10 11:37:47 +0200
commitcbe8f87f975264ee5b61795dc86f70915fb5f5f3 (patch)
treed13a4d82f5a97832712b3861adf1269fe946709f /scripts/qapi/visit.py
parentqapi/common.py: Remove python compatibility workaround (diff)
downloadqemu-cbe8f87f975264ee5b61795dc86f70915fb5f5f3.tar.gz
qemu-cbe8f87f975264ee5b61795dc86f70915fb5f5f3.tar.xz
qemu-cbe8f87f975264ee5b61795dc86f70915fb5f5f3.zip
qapi/common.py: Add indent manager
Code style tools really dislike the use of global keywords, because it generally involves re-binding the name at runtime which can have strange effects depending on when and how that global name is referenced in other modules. Make a little indent level manager instead. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-12-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi/visit.py')
-rw-r--r--scripts/qapi/visit.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 9fdbe5b9ef..708f72c4a1 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -18,9 +18,8 @@ from .common import (
c_name,
gen_endif,
gen_if,
+ indent,
mcgen,
- pop_indent,
- push_indent,
)
from .gen import QAPISchemaModularCVisitor, ifcontext
from .schema import QAPISchemaObjectType
@@ -69,7 +68,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) {
''',
name=memb.name, c_name=c_name(memb.name))
- push_indent()
+ indent.increase()
ret += mcgen('''
if (!visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, errp)) {
return false;
@@ -78,7 +77,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
c_type=memb.type.c_name(), name=memb.name,
c_name=c_name(memb.name))
if memb.optional:
- pop_indent()
+ indent.decrease()
ret += mcgen('''
}
''')