From de6312eb6225188a7fe13c79580097816a956a3c Mon Sep 17 00:00:00 2001 From: Brian West Date: Thu, 22 Apr 2021 21:40:03 -0500 Subject: [PATCH] refactor: fix typos --- SCsub | 2 +- generate_builtin_api.py | 6 +- quickjs/builtin_binding_generator.py | 88 ++++++++++++++-------------- quickjs/quickjs_binder.cpp | 2 +- tools/editor_tools.cpp | 36 ++++++------ tools/editor_tools.h | 4 +- 6 files changed, 69 insertions(+), 69 deletions(-) diff --git a/SCsub b/SCsub index 7b2bce25..f5c932ba 100644 --- a/SCsub +++ b/SCsub @@ -57,7 +57,7 @@ sources = [ if env['tools']: with open_file("tools/godot.d.ts.gen.cpp", "w") as f: - text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::BUILTIN_DECLEARATION_TEXT = \n${source};'; + text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::BUILTIN_DECLARATION_TEXT = \n${source};' f.write(text.replace('${source}', dump_text_file_to_cpp("misc/godot.d.ts"))) with open_file("tools/tsconfig.json.gen.cpp", "w") as f: text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::TSCONFIG_CONTENT = \n${source};' diff --git a/generate_builtin_api.py b/generate_builtin_api.py index 45f72408..ec707e83 100755 --- a/generate_builtin_api.py +++ b/generate_builtin_api.py @@ -331,7 +331,7 @@ ] } -def apply_parttern(template, values): +def apply_pattern(template, values): for key in values: template = template.replace( '${' + key + '}', values[key]) return template @@ -405,7 +405,7 @@ def parse_class(cls): if class_name in IGNORED_PROPS and const_name in IGNORED_PROPS[class_name]: continue constants.append(dict(c.attrib)) - return json.loads(apply_parttern(json.dumps(ret), { + return json.loads(apply_pattern(json.dumps(ret), { 'class_name': class_name, })) @@ -413,7 +413,7 @@ def generate_api_json(MODULE_DIR): DOCS_DIR = os.path.abspath(os.path.join(MODULE_DIR, "../../doc/classes")) if not os.path.isdir(DOCS_DIR) and len(sys.argv) > 1: DOCS_DIR = sys.argv[-1] - OUTPUT_FILE = os.path.join(MODULE_DIR, "buitin_api.gen.json"); + OUTPUT_FILE = os.path.join(MODULE_DIR, "builtin_api.gen.json") classes = [] for cls in BUILTIN_CLASSES: diff --git a/quickjs/builtin_binding_generator.py b/quickjs/builtin_binding_generator.py index 13726841..5c1c339f 100644 --- a/quickjs/builtin_binding_generator.py +++ b/quickjs/builtin_binding_generator.py @@ -3,7 +3,7 @@ DIR = os.path.abspath( os.path.dirname(__file__) ) OUTPUT_FILE = os.path.join(DIR, "quickjs_builtin_binder.gen.cpp") -API = json.load(open(os.path.join(DIR, '..', 'buitin_api.gen.json'), 'r')) +API = json.load(open(os.path.join(DIR, '..', 'builtin_api.gen.json'), 'r')) VariantTypes = { "boolean": "Variant::BOOL", @@ -104,7 +104,7 @@ "Variant": 'QuickJSBinder::variant_to_var(ctx, ${arg})', } -def apply_parttern(template, values): +def apply_pattern(template, values): for key in values: template = template.replace( '${' + key + '}', values[key]) return template @@ -411,22 +411,22 @@ def generate_constructor(cls): } } ''', - "PoolByteArray": apply_parttern(TemplatePoolArrays, {"class": "PoolByteArray", "type": "Variant::POOL_BYTE_ARRAY", "element": "uint8_t"}), - "PoolIntArray": apply_parttern(TemplatePoolArrays, {"class": "PoolIntArray", "type": "Variant::POOL_INT_ARRAY", "element": "int"}), - "PoolRealArray": apply_parttern(TemplatePoolArrays, {"class": "PoolRealArray", "type": "Variant::POOL_REAL_ARRAY", "element": "real_t"}), - "PoolVector2Array": apply_parttern(TemplatePoolArrays, {"class": "PoolVector2Array", "type": "Variant::POOL_VECTOR2_ARRAY", "element": "Vector2"}), - "PoolVector3Array": apply_parttern(TemplatePoolArrays, {"class": "PoolVector3Array", "type": "Variant::POOL_VECTOR3_ARRAY", "element": "Vector3"}), - "PoolColorArray": apply_parttern(TemplatePoolArrays, {"class": "PoolColorArray", "type": "Variant::POOL_COLOR_ARRAY", "element": "Color"}), - "PoolStringArray": apply_parttern(TemplateSimplePoolArrays,{"class": "PoolStringArray", "type": "Variant::POOL_STRING_ARRAY", "element": "String"}), + "PoolByteArray": apply_pattern(TemplatePoolArrays, {"class": "PoolByteArray", "type": "Variant::POOL_BYTE_ARRAY", "element": "uint8_t"}), + "PoolIntArray": apply_pattern(TemplatePoolArrays, {"class": "PoolIntArray", "type": "Variant::POOL_INT_ARRAY", "element": "int"}), + "PoolRealArray": apply_pattern(TemplatePoolArrays, {"class": "PoolRealArray", "type": "Variant::POOL_REAL_ARRAY", "element": "real_t"}), + "PoolVector2Array": apply_pattern(TemplatePoolArrays, {"class": "PoolVector2Array", "type": "Variant::POOL_VECTOR2_ARRAY", "element": "Vector2"}), + "PoolVector3Array": apply_pattern(TemplatePoolArrays, {"class": "PoolVector3Array", "type": "Variant::POOL_VECTOR3_ARRAY", "element": "Vector3"}), + "PoolColorArray": apply_pattern(TemplatePoolArrays, {"class": "PoolColorArray", "type": "Variant::POOL_COLOR_ARRAY", "element": "Color"}), + "PoolStringArray": apply_pattern(TemplateSimplePoolArrays,{"class": "PoolStringArray", "type": "Variant::POOL_STRING_ARRAY", "element": "String"}), } class_name = cls['name'] - constructor_name = apply_parttern(TemplateConstructorName, {"class": class_name}) - constructor_declare = apply_parttern(TemplateConstructorDeclare, {"class": class_name}) + constructor_name = apply_pattern(TemplateConstructorName, {"class": class_name}) + constructor_declare = apply_pattern(TemplateConstructorDeclare, {"class": class_name}) initializer = '' if class_name in ConstructorInitializers: initializer = ConstructorInitializers[class_name] - consturctor = apply_parttern(TemplateConstructor, { + consturctor = apply_pattern(TemplateConstructor, { 'class': class_name, 'type': VariantTypes[class_name], 'func': constructor_name, @@ -479,21 +479,21 @@ def generate_members(cls): type = p['type'] name = p['name'] native_name = p['native'] - getters += apply_parttern(TemplateGetterItem, { + getters += apply_pattern(TemplateGetterItem, { 'index': str(i), - 'value': apply_parttern(GodotToJSTemplates[type], { 'arg': apply_parttern('ptr->${native}', {'native': native_name}) }) + 'value': apply_pattern(GodotToJSTemplates[type], { 'arg': apply_pattern('ptr->${native}', {'native': native_name}) }) }) - setters += apply_parttern(TemplateSetterItem, { + setters += apply_pattern(TemplateSetterItem, { 'index': str(i), 'name': name, 'native': native_name, 'type': VariantTypes[type], 'type_name': type, 'class': class_name, - 'value': apply_parttern(JSToGodotTemplates[type], {'arg': 'argv[0]'}) + 'value': apply_pattern(JSToGodotTemplates[type], {'arg': 'argv[0]'}) }) - bindings += apply_parttern(TemplateItemBinding, {'index': str(i), 'name': name, 'type': VariantTypes[class_name]}) - return apply_parttern(Template, { + bindings += apply_pattern(TemplateItemBinding, {'index': str(i), 'name': name, 'type': VariantTypes[class_name]}) + return apply_pattern(Template, { 'class': class_name, 'getters': getters, 'setters': setters, @@ -509,12 +509,12 @@ def generate_methods(cls): [](JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { ECMAScriptGCHandler *bind = BINDING_DATA_FROM_JS(ctx, this_val); ${class} *ptr = bind->get${class}();\ -${arg_declars} +${arg_declares} ${call} return ${return}; }, ${argc});''' - TemplateArgDeclear = ''' + TemplateArgDeclare = ''' #ifdef DEBUG_METHODS_ENABLED ERR_FAIL_COND_V(!QuickJSBinder::validate_type(ctx, ${type}, argv[${index}]), (JS_ThrowTypeError(ctx, "${type_name} expected for argument ${index} of ${class}.${name}"))); #endif @@ -524,31 +524,31 @@ def generate_methods(cls): bindings = '' for m in cls['methods']: args = '' - arg_declars = '' + arg_declares = '' for i in range(len(m['arguments'])): arg = m['arguments'][i] arg_type = arg['type'] - arg_declars += apply_parttern(TemplateArgDeclear, { + arg_declares += apply_pattern(TemplateArgDeclare, { 'index': str(i), 'type': VariantTypes[arg_type], 'type_name': arg_type, 'class': class_name, 'name': m['name'], - 'arg': apply_parttern(JSToGodotTemplates[arg_type], {'arg': 'argv[' + str(i) +']'}), + 'arg': apply_pattern(JSToGodotTemplates[arg_type], {'arg': 'argv[' + str(i) +']'}), 'godot_type': GodotTypeNames[arg_type], }) if i > 0: args += ', ' args += 'arg' + str(i) - CallTemplate = ('' if m['return'] == 'void' else (apply_parttern(TemplateReturnValue, {"godot_type": GodotTypeNames[m['return']]}))) + 'ptr->${native_method}(${args});' - call = apply_parttern(CallTemplate, {'native_method': m['native_method'], 'args': args}) - bindings += apply_parttern(TemplateMethod, { + CallTemplate = ('' if m['return'] == 'void' else (apply_pattern(TemplateReturnValue, {"godot_type": GodotTypeNames[m['return']]}))) + 'ptr->${native_method}(${args});' + call = apply_pattern(CallTemplate, {'native_method': m['native_method'], 'args': args}) + bindings += apply_pattern(TemplateMethod, { "class": class_name, "type": VariantTypes[class_name], "name": m['name'], "call": call, - "arg_declars": arg_declars, + "arg_declares": arg_declares, "argc": str(len(m['arguments'])), - "return": 'JS_UNDEFINED' if m['return'] == 'void' else apply_parttern(GodotToJSTemplates[m['return']], {'arg': 'ret'}), + "return": 'JS_UNDEFINED' if m['return'] == 'void' else apply_pattern(GodotToJSTemplates[m['return']], {'arg': 'ret'}), }) return bindings @@ -556,7 +556,7 @@ def generate_constants(cls): ConstTemplate = '\tbinder->get_builtin_binder().register_constant(${type}, "${name}", ${value});\n' bindings = '' for c in cls['constants']: - bindings += apply_parttern(ConstTemplate, { + bindings += apply_pattern(ConstTemplate, { "name": c['name'], "type": VariantTypes[class_name], "value": c['value'] @@ -572,7 +572,7 @@ def genertate_operators(cls): 'operator==': '==', 'operator<': '<' } - TargetDeclearTemplate = ''' + TargetDeclareTemplate = ''' #ifdef DEBUG_METHODS_ENABLED ERR_FAIL_COND_V(!QuickJSBinder::validate_type(ctx, ${type}, argv[1]), (JS_ThrowTypeError(ctx, "${target_class} expected for ${class}.${operator}"))); #endif @@ -584,7 +584,7 @@ def genertate_operators(cls): JS_NewCFunction(ctx, [](JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { ECMAScriptGCHandler *bind = BINDING_DATA_FROM_JS(ctx, argv[0]); ${class} *ptr = bind->get${class}();\ -${target_declear} +${target_declare} ${call} return ${return}; }, @@ -607,29 +607,29 @@ def genertate_operators(cls): js_op = 'neg' args = '' - target_declear = '' + target_declare = '' if argc > 1: arg_class = o['arguments'][0]['type'] - target_declear = apply_parttern(TargetDeclearTemplate, { + target_declare = apply_pattern(TargetDeclareTemplate, { 'target_class': arg_class, 'type': VariantTypes[arg_class], 'class': class_name, 'operator': o['native_method'], }) args = '*target' - CallTemplate = ('' if o['return'] == 'void' else apply_parttern(TemplateReturnValue, {'godot_type': GodotTypeNames[o['return']] })) + 'ptr->${op}(${args});' - call = apply_parttern(CallTemplate, {'op': op, 'args': args}) - bindings += apply_parttern(OperatorTemplate, { + CallTemplate = ('' if o['return'] == 'void' else apply_pattern(TemplateReturnValue, {'godot_type': GodotTypeNames[o['return']] })) + 'ptr->${op}(${args});' + call = apply_pattern(CallTemplate, {'op': op, 'args': args}) + bindings += apply_pattern(OperatorTemplate, { 'type': VariantTypes[class_name], 'class': class_name, 'js_op': js_op, 'call': call, 'name': o['name'], - 'target_declear': target_declear, - "return": 'JS_UNDEFINED' if o['return'] == 'void' else apply_parttern(GodotToJSTemplates[o['return']], {'arg': 'ret'}), + 'target_declare': target_declare, + "return": 'JS_UNDEFINED' if o['return'] == 'void' else apply_pattern(GodotToJSTemplates[o['return']], {'arg': 'ret'}), 'argc': str(argc) }) - bindings += apply_parttern(''' + bindings += apply_pattern(''' operators.push_back(base_operators); binder->get_builtin_binder().get_cross_type_operators(${type}, operators); binder->get_builtin_binder().register_operators(${type}, operators); @@ -646,21 +646,21 @@ def genertate_operators(cls): } ''' class_name = cls['name'] - property_declare = apply_parttern(TemplateDeclar, {"class": class_name}) - property_defines = apply_parttern(TemplateBindDefine, { + property_declare = apply_pattern(TemplateDeclar, {"class": class_name}) + property_defines = apply_pattern(TemplateBindDefine, { "class": class_name, "members": generate_members(cls) if len(cls['properties']) else '', "methods": generate_methods(cls), "constants": generate_constants(cls), "operators": genertate_operators(cls), }) - property_bind = apply_parttern(TemplateBind, {"class": class_name}) + property_bind = apply_pattern(TemplateBind, {"class": class_name}) return property_declare, property_defines, property_bind def generate_class_bind_action(cls, constructor): Template = '\tregister_builtin_class(${type}, "${class}", ${constructor}, ${argc});\n' - return apply_parttern(Template, { + return apply_pattern(Template, { 'class': cls['name'], 'constructor': constructor, 'type': VariantTypes[cls['name']], @@ -703,7 +703,7 @@ def generate_builtin_bindings(): definitions += property_defines bindings += property_bind - output = apply_parttern(Template, { + output = apply_pattern(Template, { 'declarations': declarations, 'bindings': bindings, 'definitions': definitions, diff --git a/quickjs/quickjs_binder.cpp b/quickjs/quickjs_binder.cpp index 29494495..76bbcf42 100644 --- a/quickjs/quickjs_binder.cpp +++ b/quickjs/quickjs_binder.cpp @@ -1153,7 +1153,7 @@ void QuickJSBinder::add_godot_globals() { } } - // buitin functions + // builtin functions for (int i = 0; i < Expression::FUNC_MAX; ++i) { Expression::BuiltinFunc func = (Expression::BuiltinFunc)i; String name = Expression::get_func_name(func); diff --git a/tools/editor_tools.cpp b/tools/editor_tools.cpp index 1b2229f4..d713232e 100644 --- a/tools/editor_tools.cpp +++ b/tools/editor_tools.cpp @@ -49,7 +49,7 @@ void ECMAScriptPlugin::_notification(int p_what) { void ECMAScriptPlugin::_on_menu_item_pressed(int item) { switch (item) { - case MenuItem::ITEM_GEN_DECLAR_FILE: + case MenuItem::ITEM_GEN_DECLARE_FILE: declaration_file_dialog->popup_centered_ratio(); break; case MenuItem::ITEM_GEN_TYPESCRIPT_PROJECT: @@ -65,7 +65,7 @@ ECMAScriptPlugin::ECMAScriptPlugin(EditorNode *p_node) { PopupMenu *menu = memnew(PopupMenu); add_tool_submenu_item(TTR("ECMAScript"), menu); - menu->add_item(TTR("Generate TypeScript Declaration File"), ITEM_GEN_DECLAR_FILE); + menu->add_item(TTR("Generate TypeScript Declaration File"), ITEM_GEN_DECLARE_FILE); menu->add_item(TTR("Generate Enumeration Binding Script"), ITEM_GEN_ENUM_BINDING_SCRIPT); menu->add_item(TTR("Generate TypeScript Project"), ITEM_GEN_TYPESCRIPT_PROJECT); menu->connect("id_pressed", this, "_on_menu_item_pressed"); @@ -105,8 +105,8 @@ ECMAScriptPlugin::ECMAScriptPlugin(EditorNode *p_node) { ts_ignore_errors.insert("SpriteBase3D", ts_ignore_error_members); } -static String applay_partern(const String &p_partern, const Dictionary &p_values) { - String ret = p_partern; +static String apply_pattern(const String &p_pattern, const Dictionary &p_values) { + String ret = p_pattern; for (const Variant *key = p_values.next(); key; key = p_values.next(key)) { String p = String("${") + String(*key) + "}"; String v = p_values.get(*key, p); @@ -277,7 +277,7 @@ String _export_method(const DocData::MethodDoc &p_method, bool is_function = fal method_template = method_template.replace("${TS_IGNORE}", ""); } } - return applay_partern(method_template, dict); + return apply_pattern(method_template, dict); } String _export_class(const DocData::ClassDoc &class_doc) { @@ -343,7 +343,7 @@ String _export_class(const DocData::ClassDoc &class_doc) { } else { const_str = const_str.replace("${TS_IGNORE}", ""); } - constants += applay_partern(const_str, dict); + constants += apply_pattern(const_str, dict); if (!const_doc.enumeration.empty()) { if (!enumerations.has(const_doc.enumeration)) { @@ -372,7 +372,7 @@ String _export_class(const DocData::ClassDoc &class_doc) { dict["description"] = format_doc_text(enums[i]->description, "\t\t\t "); dict["name"] = format_property_name(enums[i]->name); dict["value"] = enums[i]->value; - enum_str += applay_partern(const_str, dict); + enum_str += apply_pattern(const_str, dict); } enum_str += "\t\t}\n"; enumerations_str += enum_str; @@ -400,7 +400,7 @@ String _export_class(const DocData::ClassDoc &class_doc) { dict["name"] = format_property_name(prop_doc.name); dict["type"] = get_type_name(prop_doc.type); dict["static"] = Engine::get_singleton()->has_singleton(class_doc.name) ? "static " : ""; - properties += applay_partern(prop_str, dict); + properties += apply_pattern(prop_str, dict); if (!prop_doc.getter.empty()) { DocData::MethodDoc md; @@ -441,7 +441,7 @@ String _export_class(const DocData::ClassDoc &class_doc) { Dictionary dict; dict["description"] = format_doc_text(signal.description, "\t\t\t "); dict["name"] = signal.name; - signals += applay_partern(signal_str, dict); + signals += apply_pattern(signal_str, dict); } dict["signals"] = signals; @@ -467,7 +467,7 @@ String _export_class(const DocData::ClassDoc &class_doc) { } dict["extrals"] = extrals; - return applay_partern(class_template, dict); + return apply_pattern(class_template, dict); } void ECMAScriptPlugin::_export_typescript_declare_file(const String &p_path) { @@ -508,7 +508,7 @@ void ECMAScriptPlugin::_export_typescript_declare_file(const String &p_path) { Dictionary dict; const String godot_module = "// This file is generated by godot editor\n" - "${buitins}\n" + "${builtins}\n" "\n" "declare module " GODOT_OBJECT_NAME " {\n" "${constants}\n" @@ -582,7 +582,7 @@ void ECMAScriptPlugin::_export_typescript_declare_file(const String &p_path) { } else { dict["type"] = dict["value"]; } - constants += applay_partern(const_str, dict); + constants += apply_pattern(const_str, dict); if (!const_doc.enumeration.empty()) { if (!enumerations.has(const_doc.enumeration)) { @@ -606,7 +606,7 @@ void ECMAScriptPlugin::_export_typescript_declare_file(const String &p_path) { dict["description"] = format_doc_text(enums[i]->description, "\t\t\t "); dict["name"] = format_property_name(enums[i]->name); dict["value"] = enums[i]->value; - enum_str += applay_partern(const_str, dict); + enum_str += apply_pattern(const_str, dict); } enum_str += "\t}\n"; enumerations_str += enum_str; @@ -631,9 +631,9 @@ void ECMAScriptPlugin::_export_typescript_declare_file(const String &p_path) { dict["constants"] = constants; dict["enumerations"] = enumerations_str; dict["functions"] = functions; - dict["buitins"] = BUILTIN_DECLEARATION_TEXT; + dict["builtins"] = BUILTIN_DECLARATION_TEXT; - String text = applay_partern(godot_module, dict); + String text = apply_pattern(godot_module, dict); FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE); if (f.f && f->is_open()) { f->store_string(text); @@ -678,7 +678,7 @@ void ECMAScriptPlugin::_export_enumeration_binding_file(const String &p_path) { Dictionary dict; dict["name"] = format_enum_name(E->key()); dict["values"] = enum_items_text; - class_enums += applay_partern("\n\t\t${name}: { value: ${values} }", dict); + class_enums += apply_pattern("\n\t\t${name}: { value: ${values} }", dict); if (E->next()) { class_enums += ", "; } else { @@ -689,11 +689,11 @@ void ECMAScriptPlugin::_export_enumeration_binding_file(const String &p_path) { Dictionary dict; dict["class"] = class_name; dict["enumerations"] = class_enums; - enumerations += applay_partern(class_template, dict); + enumerations += apply_pattern(class_template, dict); } Dictionary dict; dict["enumerations"] = enumerations; - file_content = applay_partern(file_content, dict); + file_content = apply_pattern(file_content, dict); dump_to_file(p_path, file_content); } diff --git a/tools/editor_tools.h b/tools/editor_tools.h index c2617c63..ade484b8 100644 --- a/tools/editor_tools.h +++ b/tools/editor_tools.h @@ -8,7 +8,7 @@ class ECMAScriptPlugin : public EditorPlugin { GDCLASS(ECMAScriptPlugin, EditorPlugin); enum MenuItem { - ITEM_GEN_DECLAR_FILE, + ITEM_GEN_DECLARE_FILE, ITEM_GEN_TYPESCRIPT_PROJECT, ITEM_GEN_ENUM_BINDING_SCRIPT, }; @@ -18,7 +18,7 @@ class ECMAScriptPlugin : public EditorPlugin { const Dictionary *modified_api; protected: - static String BUILTIN_DECLEARATION_TEXT; + static String BUILTIN_DECLARATION_TEXT; static String TSCONFIG_CONTENT; static String TS_DECORATORS_CONTENT; static String PACKAGE_JSON_CONTENT;