Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4df0c27

Browse files
author
Vano
committedOct 3, 2024·
Sync with 8568824
1 parent abb21d7 commit 4df0c27

File tree

2 files changed

+70
-36
lines changed

2 files changed

+70
-36
lines changed
 

‎godot_cppscript.cmake

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
856867
def 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'

‎godot_cppscript.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@
194194
#define GABSTRACT_CLASS(CLASS_NAME, CLASS_NAME_INH) GCLASS(CLASS_NAME, CLASS_NAME_INH)
195195
#define GINTERNAL_CLASS(CLASS_NAME, CLASS_NAME_INH) GCLASS(CLASS_NAME, CLASS_NAME_INH)
196196
197-
#define GENERATE_GETTER_DECLARATION(function, property) \\
198-
decltype(property) function();
197+
#define GENERATE_GETTER_DECLARATION(function, prop_type) \\
198+
prop_type function();
199199
200-
#define GENERATE_SETTER_DECLARATION(function, property) \\
201-
void function(decltype(property));
200+
#define GENERATE_SETTER_DECLARATION(function, prop_type) \\
201+
void function(prop_type);
202202
203-
#define GENERATE_GETTER(function, property) \\
204-
decltype(property) function() { \\
203+
#define GENERATE_GETTER(function, property, prop_type) \\
204+
prop_type function() { \\
205205
return property; \\
206206
}
207207
208-
#define GENERATE_SETTER(function, property) \\
209-
void function(decltype(property) value) { \\
208+
#define GENERATE_SETTER(function, property, prop_type) \\
209+
void function(prop_type value) { \\
210210
this->property = value; \\
211211
}
212212
@@ -540,16 +540,16 @@ def expand_property_info_list(cls, args):
540540
}}
541541
"""
542542

543-
# (class_name_full, method_name, property_name)
544-
GENERATE_GETTER = 'GENERATE_GETTER({0}::{1}, {0}::{2});\n'
543+
# (class_name_full, method_name, property_name, property_type)
544+
GENERATE_GETTER = 'GENERATE_GETTER({0}::{1}, {0}::{2}, {3});\n'
545545

546-
# (method_name, property_name)
546+
# (method_name, property_type)
547547
GENERATE_GETTER_DECLARATION = 'GENERATE_GETTER_DECLARATION({0}, {1})'
548548

549-
# (class_name_full, method_name, property_name)
550-
GENERATE_SETTER = 'GENERATE_SETTER({0}::{1}, {0}::{2});\n'
549+
# (class_name_full, method_name, property_name, property_type)
550+
GENERATE_SETTER = 'GENERATE_SETTER({0}::{1}, {0}::{2}, {3});\n'
551551

552-
# (method_name, property_name)
552+
# (method_name, property_type)
553553
GENERATE_SETTER_DECLARATION = 'GENERATE_SETTER_DECLARATION({0}, {1})'
554554

555555
# (group_name, groug_name_expanded)
@@ -835,6 +835,17 @@ def is_virtual_method(cursor):
835835
return False
836836

837837

838+
def cursor_get_field_type(cursor):
839+
spelling = cursor.spelling
840+
tokens = list(cursor.get_tokens())
841+
for i in range(len(tokens)):
842+
if tokens[i].kind == TokenKind.IDENTIFIER and tokens[i].spelling == spelling:
843+
return ''.join(t.spelling for t in tokens[:i])
844+
845+
raise CppScriptException('{}:{}:{}: error: cannot extract type from property "{}"'
846+
.format(cursor.location.file.name, cursor.location.line, cursor.location.column, cursor.spelling))
847+
848+
838849
# Builder
839850
def generate_header_emitter(target, source, env):
840851
generated = [env.File(filename_to_gen_filename(str(i), env['cppscript_env'])) for i in source]
@@ -929,6 +940,9 @@ def parse_class(parent, class_cursors):
929940
class_cursors.append(cursor)
930941

931942
case CursorKind.FIELD_DECL:
943+
print(f"Cursor '{cursor.spelling}'")
944+
print(f"Type '{cursor.type.spelling}'")
945+
print([(i.kind, i.spelling) for i in cursor.get_tokens()])
932946
class_cursors.append(cursor)
933947

934948
case CursorKind.ENUM_DECL:
@@ -1185,6 +1199,7 @@ def apply_macros(item, macros):
11851199
if process_macros(item, macros, properties, True):
11861200
properties |= {
11871201
'name': item.spelling,
1202+
'type' : cursor_get_field_type(item),
11881203
'group' : group,
11891204
'subgroup' : subgroup,
11901205
'is_static' : item.is_static_method()
@@ -1291,7 +1306,8 @@ def write_header(file, defs, env):
12911306
property_set_get_defs += CODE_FORMAT.GENERATE_GETTER.format(
12921307
class_name_full,
12931308
prop["getter"],
1294-
prop["name"]
1309+
prop["name"],
1310+
prop["type"]
12951311
)
12961312
gen_getters.append([prop["getter"], prop["name"]])
12971313

@@ -1306,7 +1322,8 @@ def write_header(file, defs, env):
13061322
property_set_get_defs += CODE_FORMAT.GENERATE_SETTER.format(
13071323
class_name_full,
13081324
prop["setter"],
1309-
prop["name"]
1325+
prop["name"],
1326+
prop["type"]
13101327
)
13111328
gen_setters.append([prop["setter"], prop["name"]])
13121329

@@ -1526,9 +1543,9 @@ def write_property_header(new_defs, env):
15261543
classcontent = filecontent['content']
15271544
for class_name_full, content in classcontent.items():
15281545
gen_setgets = [
1529-
' \\\n' + CODE_FORMAT.GENERATE_GETTER_DECLARATION.format(method, property)
1546+
' \\\n' + CODE_FORMAT.GENERATE_GETTER_DECLARATION.format(method, next(prop['type'] for prop in content['properties'] if prop['name'] == property))
15301547
for method, property in content['gen_getters']] + [
1531-
' \\\n' + CODE_FORMAT.GENERATE_SETTER_DECLARATION.format(method, property)
1548+
' \\\n' + CODE_FORMAT.GENERATE_SETTER_DECLARATION.format(method, next(prop['type'] for prop in content['properties'] if prop['name'] == property))
15321549
for method, property in content['gen_setters']]
15331550

15341551
body += f'#define GSETGET_{content["class_name"]}' + ''.join(gen_setgets) + '\n\n'

0 commit comments

Comments
 (0)
Please sign in to comment.