MCPcopy Create free account
hub / github.com/LunarG/VulkanTools / get_array_length

Function get_array_length

scripts/generators/api_dump_generator.py:267–305  ·  view source on GitHub ↗
(var, parent)

Source from the content-addressed store, hash-verified

265 return custom_type
266
267def get_array_length(var, parent):
268 # If the length member contains an expression, like '(rasterizationSamples + 31)/32', we need to add 'object.' inside of the expression
269 if isinstance(parent, Struct) and len(var.length.split(',')) == 1:
270 for member in parent.members:
271 if member.name in var.length and member.name != var.length: # Don't match if the length is just another member
272 index = var.length.find(member.name)
273 return var.length[:index] + 'object.'+var.length[index:]
274
275 lengthIsMember = False
276 lengthIsPointer = False
277 first_length = var.length.split(',')[0]
278 for local in [x for x in (parent.params if isinstance(parent, Command) else parent.members)]:
279 if local.name == first_length:
280 lengthIsMember = True
281 if local.pointer:
282 lengthIsPointer = True
283 break
284
285 # Some lengths come from 'parent' structures that aren't available without first stashing the length value in the ApiDumpInstance
286 if parent.name in SPECIAL_LENGTH:
287 if var.name in SPECIAL_LENGTH[parent.name]:
288 return SPECIAL_LENGTH[parent.name][var.name]
289
290 # If the length is a number or an API Constant, just return it
291 if not lengthIsMember:
292 return '*'.join(var.length.split(','))
293
294 # While the array might have a fixed size in memory, we want to use the 'real' length. But, if that length hasn't been initialized, we need to cap it to the fixed size length
295 if len(var.fixedSizeArray) > 0:
296 return f'std::min(object.{var.length}, {"*".join(var.fixedSizeArray)})'
297
298 # If the length is a pointer, we need to dereference it
299 deref = '*' if lengthIsPointer else ''
300
301 # If the variable is from a struct, we need to use `object.` to access it.
302 if isinstance(parent, Struct):
303 return deref + 'object.' + '*'.join(var.length.split(','))
304 else:
305 return deref + '*'.join(var.length.split(','))
306
307def get_fixed_array_length(fixed_length, var, parent):
308 lengthIsMember = False

Callers 1

write_valueMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected