Compare commits

...

2 Commits

2 changed files with 21 additions and 8 deletions

View File

@ -77,7 +77,7 @@ def extract_array_count(value, name=''):
return count return count
return None return None
def get_type_info(types, typename): def get_type_info(types, typename, serverbound=None):
name = extract_array_type(typename) name = extract_array_type(typename)
if not name in types: if not name in types:
@ -86,14 +86,25 @@ def get_type_info(types, typename):
type: name type: name
} }
tp = types[name] tp = types[name].copy()
# apply serverbound or clientbound specific info, if relevant (serverbound=None means don't care)
if serverbound and 'severbound' in tp:
sbdata = tp['serverbound']
for key in sbdata:
tp[key] = sbdata[key]
elif serverbound == False and 'clientbound' in tp:
cbdata = tp['clientbound']
for key in cbdata:
tp[key] = cbdata[key]
if 'alias' in tp: if 'alias' in tp:
alias = tp['alias'] alias = tp['alias']
enum = tp['enum'] if 'enum' in tp else False enum = tp['enum'] if 'enum' in tp else False
tp = tp.copy() realtype = get_type_info(types, tp['alias'], serverbound)
realtype = get_type_info(types, tp['alias'])
# copy certain properties from real type # copy certain properties from real type
if 'generic' in realtype: tp['generic'] = realtype['generic'] if 'generic' in realtype: tp['generic'] = realtype['generic']
if 'method' in realtype: tp['method'] = realtype['method'] if 'method' in realtype: tp['method'] = realtype['method']
@ -132,14 +143,14 @@ def resolve_name(types, name, value, decl=False):
return name return name
def resolve_type(types, value): def resolve_type(types, value, serverbound=None):
if isinstance(value, dict): if isinstance(value, dict):
warn('WARNING: Attempted to call resolve_type on object type') warn('WARNING: Attempted to call resolve_type on object type')
return "" return ""
typename = value typename = value
tp = get_type_info(types, typename) tp = get_type_info(types, typename, serverbound)
if 'type' in tp: if 'type' in tp:
return tp['type'] return tp['type']
else: else:
@ -378,7 +389,7 @@ def print_definition(types, name, value, serverbound):
unindent() unindent()
add_text('}} {};', resolved_name) add_text('}} {};', resolved_name)
else: else:
resolved_type = resolve_type(types, value) resolved_type = resolve_type(types, value, serverbound)
add_text('{} {};', resolved_type, resolved_name) add_text('{} {};', resolved_type, resolved_name)

View File

@ -20,7 +20,9 @@
} }
string: { string: {
type: std::string_view type: std::string
clientbound: {type: 'const std::string&'}
method: String method: String
// requires count: e.g. string[256] // requires count: e.g. string[256]
// generated C type will not be an array // generated C type will not be an array