MCPcopy Create free account
hub / github.com/defold/defold / gen_struct

Function gen_struct

engine/jni/scripts/gen_java.py:314–411  ·  view source on GitHub ↗
(decl, namespace)

Source from the content-addressed store, hash-verified

312 return as_c_arg_type(result_type, prefix)
313
314def gen_struct(decl, namespace):
315 global struct_types
316 struct_name = check_override(decl['name'])
317 l(f" public static class {struct_name} {{")
318 for field in decl['fields']:
319 field_name = check_override(field['name'])
320 jni_field_name = to_jni_camel_case(field_name, 'm_')
321 field_type = check_override(f'{struct_name}.{jni_field_name}', default=field['type'])
322
323 field_type = field_type.replace(f'{namespace}::', '')
324
325 if is_prim_type(field_type):
326 if field_name.endswith('Count') and has_array(decl['fields'], namespace, field_name.replace('Count', '')):
327 continue
328
329 jni_type = c_type_to_java_type.get(field_type);
330 suffix = ''
331 if jni_type == 'float':
332 suffix = 'f'
333 l(f" public {jni_type} {jni_field_name} = {type_default_value(field_type)}{suffix};")
334 elif is_struct_type(field_type):
335 l(f" public {field_type} {jni_field_name};")
336 elif is_enum_type(field_type):
337 l(f" public {field_type} {jni_field_name} = {field_type}.{enum_default_item(field_type)};")
338 elif util.is_string_ptr(field_type):
339 l(f" public String {jni_field_name};")
340 elif util.is_const_void_ptr(field_type) or util.is_void_ptr(field_type):
341 l(f" public long {jni_field_name};")
342 elif util.is_dmarray_type(field_type):
343 field_type = util.extract_dmarray_type(field_type)
344 c_type, _ = util.extract_ptr_type2(field_type)
345 java_type = c_type_to_java_type.get(c_type, c_type)
346 l(f" public {java_type}[] {jni_field_name};")
347
348 elif is_prim_ptr(field_type) or is_struct_ptr(field_type):
349 c_type, _ = util.extract_ptr_type2(field_type)
350 jni_type = c_type_to_java_type.get(c_type, c_type)
351
352 # Checking if it's an array: need a variable that designates the array size
353 count_name = field_name+'Count'
354 count = get_array_count_field(decl, count_name)
355
356 if not count:
357 l(f" public {jni_type} {jni_field_name};")
358 else:
359 l(f" public {jni_type}[] {jni_field_name};")
360
361 elif util.is_1d_array_type(field_type):
362 array_type = util.extract_array_type(field_type)
363 array_sizes = util.extract_array_sizes(field_type)
364
365 if is_prim_ptr(array_type) or is_struct_ptr(array_type):
366 c_type, _ = util.extract_ptr_type2(array_type)
367 jni_type = c_type_to_java_type.get(c_type, c_type)
368
369 l(f" public {jni_type}[] {jni_field_name};")
370
371 elif util.is_func_ptr(field_type):

Callers 1

gen_namespaceFunction · 0.85

Calls 15

check_overrideFunction · 0.85
to_jni_camel_caseFunction · 0.85
is_prim_typeFunction · 0.85
has_arrayFunction · 0.85
type_default_valueFunction · 0.85
is_struct_typeFunction · 0.85
is_enum_typeFunction · 0.85
enum_default_itemFunction · 0.85
is_prim_ptrFunction · 0.85
is_struct_ptrFunction · 0.85
get_array_count_fieldFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected