Add nullable attribute to AST nodes for function parameters in API introspection. Fixes #309

This change introduces an `nullable` flag to `ArrayType`, `PointerType`, and `FunctionParameterDecl`. The code generation process now parses function comments from `mujoco.h` to identify parameters marked as "Nullable" and sets this flag accordingly.

PiperOrigin-RevId: 797870883
Change-Id: Ic7cac5a7a9c14177fbf97b8655c5c4809d4ef683
This commit is contained in:
Google DeepMind
2025-08-21 12:33:58 -07:00
committed by Copybara-Service
parent 3dec35a91e
commit ecfe65242f
5 changed files with 148 additions and 10 deletions
@@ -174,6 +174,29 @@ class AstNodesTest(absltest.TestCase):
self.assertEqual(str(union), 'union {int foo; float bar[3];}')
self.assertEqual(union.decl('var'), 'union {int foo; float bar[3];} var')
def test_function_parameter_decl_nullable(self):
param_ptr_nullable = ast_nodes.FunctionParameterDecl(
name='ptr_param',
type=ast_nodes.PointerType(ast_nodes.ValueType('int')),
nullable=True
)
self.assertTrue(param_ptr_nullable.nullable)
self.assertEqual(str(param_ptr_nullable), 'int * ptr_param')
param_ptr_not_nullable = ast_nodes.FunctionParameterDecl(
name='ptr_param',
type=ast_nodes.PointerType(ast_nodes.ValueType('int')),
)
self.assertFalse(param_ptr_not_nullable.nullable)
self.assertEqual(str(param_ptr_not_nullable), 'int * ptr_param')
param_array_nullable = ast_nodes.FunctionParameterDecl(
name='array_param',
type=ast_nodes.ArrayType(ast_nodes.ValueType('float'), (10,)),
nullable=True
)
self.assertTrue(param_array_nullable.nullable)
self.assertEqual(str(param_array_nullable), 'float array_param[10]')
if __name__ == '__main__':
absltest.main()