@@ -66,16 +66,16 @@ def expand_property_info_list(cls, args):
6666 }}
6767"""
6868
69- # (class_name_full, method_name, property_name)
70- GENERATE_GETTER = 'GENERATE_GETTER({0}::{1}, {0}::{2});\n '
69+ # (class_name_full, method_name, property_name, property_type )
70+ GENERATE_GETTER = 'GENERATE_GETTER({0}::{1}, {0}::{2}, {3} );\n '
7171
72- # (method_name, property_name )
72+ # (method_name, property_type )
7373 GENERATE_GETTER_DECLARATION = 'GENERATE_GETTER_DECLARATION({0}, {1})'
7474
75- # (class_name_full, method_name, property_name)
76- GENERATE_SETTER = 'GENERATE_SETTER({0}::{1}, {0}::{2});\n '
75+ # (class_name_full, method_name, property_name, property_type )
76+ GENERATE_SETTER = 'GENERATE_SETTER({0}::{1}, {0}::{2}, {3} );\n '
7777
78- # (method_name, property_name )
78+ # (method_name, property_type )
7979 GENERATE_SETTER_DECLARATION = 'GENERATE_SETTER_DECLARATION({0}, {1})'
8080
8181 # (group_name, groug_name_expanded)
@@ -361,6 +361,17 @@ def is_virtual_method(cursor):
361361 return False
362362
363363
364+ def cursor_get_field_type (cursor ):
365+ spelling = cursor .spelling
366+ tokens = list (cursor .get_tokens ())
367+ for i in range (len (tokens )):
368+ if tokens [i ].kind == TokenKind .IDENTIFIER and tokens [i ].spelling == spelling :
369+ return '' .join (t .spelling for t in tokens [:i ])
370+
371+ raise CppScriptException ('{}:{}:{}: error: cannot extract type from property "{}"'
372+ .format (cursor .location .file .name , cursor .location .line , cursor .location .column , cursor .spelling ))
373+
374+
364375# Builder
365376def generate_header_emitter (target , source , env ):
366377 generated = [env .File (filename_to_gen_filename (str (i ), env ['cppscript_env' ])) for i in source ]
@@ -455,6 +466,9 @@ def parse_class(parent, class_cursors):
455466 class_cursors .append (cursor )
456467
457468 case CursorKind .FIELD_DECL :
469+ print (f"Cursor '{ cursor .spelling } '" )
470+ print (f"Type '{ cursor .type .spelling } '" )
471+ print ([(i .kind , i .spelling ) for i in cursor .get_tokens ()])
458472 class_cursors .append (cursor )
459473
460474 case CursorKind .ENUM_DECL :
@@ -711,6 +725,7 @@ def apply_macros(item, macros):
711725 if process_macros (item , macros , properties , True ):
712726 properties |= {
713727 'name' : item .spelling ,
728+ 'type' : cursor_get_field_type (item ),
714729 'group' : group ,
715730 'subgroup' : subgroup ,
716731 'is_static' : item .is_static_method ()
@@ -817,7 +832,8 @@ def write_header(file, defs, env):
817832 property_set_get_defs += CODE_FORMAT .GENERATE_GETTER .format (
818833 class_name_full ,
819834 prop ["getter" ],
820- prop ["name" ]
835+ prop ["name" ],
836+ prop ["type" ]
821837 )
822838 gen_getters .append ([prop ["getter" ], prop ["name" ]])
823839
@@ -832,7 +848,8 @@ def write_header(file, defs, env):
832848 property_set_get_defs += CODE_FORMAT .GENERATE_SETTER .format (
833849 class_name_full ,
834850 prop ["setter" ],
835- prop ["name" ]
851+ prop ["name" ],
852+ prop ["type" ]
836853 )
837854 gen_setters .append ([prop ["setter" ], prop ["name" ]])
838855
@@ -1052,9 +1069,9 @@ def write_property_header(new_defs, env):
10521069 classcontent = filecontent ['content' ]
10531070 for class_name_full , content in classcontent .items ():
10541071 gen_setgets = [
1055- ' \\ \n ' + CODE_FORMAT .GENERATE_GETTER_DECLARATION .format (method , property )
1072+ ' \\ \n ' + CODE_FORMAT .GENERATE_GETTER_DECLARATION .format (method , next ( prop [ 'type' ] for prop in content [ 'properties' ] if prop [ 'name' ] == property ) )
10561073 for method , property in content ['gen_getters' ]] + [
1057- ' \\ \n ' + CODE_FORMAT .GENERATE_SETTER_DECLARATION .format (method , property )
1074+ ' \\ \n ' + CODE_FORMAT .GENERATE_SETTER_DECLARATION .format (method , next ( prop [ 'type' ] for prop in content [ 'properties' ] if prop [ 'name' ] == property ) )
10581075 for method , property in content ['gen_setters' ]]
10591076
10601077 body += f'#define GSETGET_{ content ["class_name" ]} ' + '' .join (gen_setgets ) + '\n \n '
0 commit comments