mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-02 13:01:07 +00:00
qapi-visit: Fix generated code when schema has forward refs
The visit_type_implicit_FOO() are generated on demand, right before their first use. Used by visit_type_STRUCT_fields() when STRUCT has base FOO, and by visit_type_UNION() when flat UNION has member a FOO. If the schema defines FOO after its first use as struct base or flat union member, visit_type_implicit_FOO() calls visit_type_implicit_FOO() before its definition, which doesn't compile. Rearrange qapi-schema-test.json to demonstrate the bug. Fix by generating the necessary forward declaration. Backports commit 8c3f8e77215bfedb7854221868f655e148506936 from qemu
This commit is contained in:
parent
389afaa743
commit
23d14a2921
|
@ -17,13 +17,23 @@ from qapi import *
|
||||||
import re
|
import re
|
||||||
|
|
||||||
implicit_structs = []
|
implicit_structs = []
|
||||||
|
struct_fields_seen = set()
|
||||||
|
|
||||||
def generate_visit_implicit_struct(type):
|
def generate_visit_implicit_struct(type):
|
||||||
global implicit_structs
|
global implicit_structs
|
||||||
if type in implicit_structs:
|
if type in implicit_structs:
|
||||||
return ''
|
return ''
|
||||||
implicit_structs.append(type)
|
implicit_structs.append(type)
|
||||||
return mcgen('''
|
ret = ''
|
||||||
|
if type not in struct_fields_seen:
|
||||||
|
# Need a forward declaration
|
||||||
|
ret += mcgen('''
|
||||||
|
|
||||||
|
static void visit_type_%(c_type)s_fields(Visitor *m, %(c_type)s **obj, Error **errp);
|
||||||
|
''',
|
||||||
|
c_type=type_name(type))
|
||||||
|
|
||||||
|
ret += mcgen('''
|
||||||
|
|
||||||
static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error **errp)
|
static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error **errp)
|
||||||
{
|
{
|
||||||
|
@ -38,8 +48,11 @@ static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error *
|
||||||
}
|
}
|
||||||
''',
|
''',
|
||||||
c_type=type_name(type))
|
c_type=type_name(type))
|
||||||
|
return ret
|
||||||
|
|
||||||
def generate_visit_struct_fields(name, members, base = None):
|
def generate_visit_struct_fields(name, members, base = None):
|
||||||
|
struct_fields_seen.add(name)
|
||||||
|
|
||||||
ret = ''
|
ret = ''
|
||||||
|
|
||||||
if base:
|
if base:
|
||||||
|
|
Loading…
Reference in a new issue