@@ -214,19 +214,19 @@ private:
214214#define GABSTRACT_CLASS(CLASS_NAME, CLASS_NAME_INH) GCLASS(CLASS_NAME, CLASS_NAME_INH)
215215#define GINTERNAL_CLASS(CLASS_NAME, CLASS_NAME_INH) GCLASS(CLASS_NAME, CLASS_NAME_INH)
216216
217- #define GENERATE_GETTER_DECLARATION(function, property ) \\
218- decltype(property) function();
217+ #define GENERATE_GETTER_DECLARATION(function, prop_type ) \\
218+ prop_type function();
219219
220- #define GENERATE_SETTER_DECLARATION(function, property ) \\
221- void function(decltype(property) );
220+ #define GENERATE_SETTER_DECLARATION(function, prop_type ) \\
221+ void function(prop_type );
222222
223- #define GENERATE_GETTER(function, property) \\
224- decltype(property) function() { \\
223+ #define GENERATE_GETTER(function, property, prop_type ) \\
224+ prop_type function() { \\
225225 return property; \\
226226}
227227
228- #define GENERATE_SETTER(function, property) \\
229- void function(decltype(property) value) { \\
228+ #define GENERATE_SETTER(function, property, prop_type ) \\
229+ void function(prop_type value) { \\
230230 this->property = value; \\
231231}
232232
@@ -557,16 +557,16 @@ struct StaticAccess {{
557557 }}
558558\"\"\"
559559
560- # (class_name_full, method_name, property_name)
561- GENERATE_GETTER = 'GENERATE_GETTER({0}::{1}, {0}::{2});\\ n'
560+ # (class_name_full, method_name, property_name, property_type )
561+ GENERATE_GETTER = 'GENERATE_GETTER({0}::{1}, {0}::{2}, {3} );\\ n'
562562
563- # (method_name, property_name )
563+ # (method_name, property_type )
564564 GENERATE_GETTER_DECLARATION = 'GENERATE_GETTER_DECLARATION({0}, {1})'
565565
566- # (class_name_full, method_name, property_name)
567- GENERATE_SETTER = 'GENERATE_SETTER({0}::{1}, {0}::{2});\\ n'
566+ # (class_name_full, method_name, property_name, property_type )
567+ GENERATE_SETTER = 'GENERATE_SETTER({0}::{1}, {0}::{2}, {3} );\\ n'
568568
569- # (method_name, property_name )
569+ # (method_name, property_type )
570570 GENERATE_SETTER_DECLARATION = 'GENERATE_SETTER_DECLARATION({0}, {1})'
571571
572572 # (group_name, groug_name_expanded)
@@ -852,6 +852,17 @@ def is_virtual_method(cursor):
852852 return False
853853
854854
855+ def cursor_get_field_type(cursor):
856+ spelling = cursor.spelling
857+ tokens = list(cursor.get_tokens())
858+ for i in range(len(tokens)):
859+ if tokens[i].kind == TokenKind.IDENTIFIER and tokens[i].spelling == spelling:
860+ return ''.join(t.spelling for t in tokens[:i])
861+
862+ raise CppScriptException('{}:{}:{}: error: cannot extract type from property \" {}\" '
863+ .format(cursor.location.file.name, cursor.location.line, cursor.location.column, cursor.spelling))
864+
865+
855866# Builder
856867def generate_header_emitter(target, source, env):
857868 generated = [env.File(filename_to_gen_filename(str(i), env['cppscript_env'])) for i in source]
@@ -946,6 +957,9 @@ def parse_header(index, filename, filecontent, env):
946957 class_cursors.append(cursor)
947958
948959 case CursorKind.FIELD_DECL:
960+ print(f\" Cursor '{cursor.spelling}'\" )
961+ print(f\" Type '{cursor.type.spelling}'\" )
962+ print([(i.kind, i.spelling) for i in cursor.get_tokens()])
949963 class_cursors.append(cursor)
950964
951965 case CursorKind.ENUM_DECL:
@@ -1202,6 +1216,7 @@ def parse_header(index, filename, filecontent, env):
12021216 if process_macros(item, macros, properties, True):
12031217 properties |= {
12041218 'name': item.spelling,
1219+ 'type' : cursor_get_field_type(item),
12051220 'group' : group,
12061221 'subgroup' : subgroup,
12071222 'is_static' : item.is_static_method()
@@ -1308,7 +1323,8 @@ def write_header(file, defs, env):
13081323 property_set_get_defs += CODE_FORMAT.GENERATE_GETTER.format(
13091324 class_name_full,
13101325 prop[\" getter\" ],
1311- prop[\" name\" ]
1326+ prop[\" name\" ],
1327+ prop[\" type\" ]
13121328 )
13131329 gen_getters.append([prop[\" getter\" ], prop[\" name\" ]])
13141330
@@ -1323,7 +1339,8 @@ def write_header(file, defs, env):
13231339 property_set_get_defs += CODE_FORMAT.GENERATE_SETTER.format(
13241340 class_name_full,
13251341 prop[\" setter\" ],
1326- prop[\" name\" ]
1342+ prop[\" name\" ],
1343+ prop[\" type\" ]
13271344 )
13281345 gen_setters.append([prop[\" setter\" ], prop[\" name\" ]])
13291346
@@ -1543,9 +1560,9 @@ def write_property_header(new_defs, env):
15431560 classcontent = filecontent['content']
15441561 for class_name_full, content in classcontent.items():
15451562 gen_setgets = [
1546- ' \\\\\\ n' + CODE_FORMAT.GENERATE_GETTER_DECLARATION.format(method, property)
1563+ ' \\\\\\ n' + CODE_FORMAT.GENERATE_GETTER_DECLARATION.format(method, next(prop['type'] for prop in content['properties'] if prop['name'] == property) )
15471564 for method, property in content['gen_getters']] + [
1548- ' \\\\\\ n' + CODE_FORMAT.GENERATE_SETTER_DECLARATION.format(method, property)
1565+ ' \\\\\\ n' + CODE_FORMAT.GENERATE_SETTER_DECLARATION.format(method, next(prop['type'] for prop in content['properties'] if prop['name'] == property) )
15491566 for method, property in content['gen_setters']]
15501567
15511568 body += f'#define GSETGET_{content[\" class_name\" ]}' + ''.join(gen_setgets) + '\\ n\\ n'
0 commit comments