1 | /**************************************************************************/ |
2 | /* project_converter_3_to_4.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef PROJECT_CONVERTER_3_TO_4_H |
32 | #define PROJECT_CONVERTER_3_TO_4_H |
33 | |
34 | #ifndef DISABLE_DEPRECATED |
35 | |
36 | #include "modules/modules_enabled.gen.h" // For regex. |
37 | |
38 | #ifndef MODULE_REGEX_ENABLED |
39 | |
40 | #include "core/error/error_macros.h" |
41 | |
42 | class ProjectConverter3To4 { |
43 | public: |
44 | ProjectConverter3To4(int, int) {} |
45 | |
46 | bool validate_conversion() { |
47 | ERR_FAIL_V_MSG(false, "Can't validate conversion for Godot 3.x projects, because RegEx module is disabled." ); |
48 | } |
49 | |
50 | bool convert() { |
51 | ERR_FAIL_V_MSG(false, "Can't run converter for Godot 3.x projects, because RegEx module is disabled." ); |
52 | } |
53 | }; |
54 | |
55 | #else // Has regex. |
56 | |
57 | #include "core/string/ustring.h" |
58 | #include "core/templates/local_vector.h" |
59 | #include "core/templates/vector.h" |
60 | |
61 | struct SourceLine { |
62 | String line; |
63 | bool ; |
64 | }; |
65 | |
66 | class RegEx; |
67 | |
68 | class ProjectConverter3To4 { |
69 | class RegExContainer; |
70 | |
71 | uint64_t maximum_file_size; |
72 | uint64_t maximum_line_length; |
73 | |
74 | void fix_tool_declaration(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
75 | void fix_pause_mode(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
76 | |
77 | void rename_colors(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
78 | Vector<String> check_for_rename_colors(Vector<String> &lines, const RegExContainer ®_container); |
79 | |
80 | void rename_classes(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
81 | Vector<String> check_for_rename_classes(Vector<String> &lines, const RegExContainer ®_container); |
82 | |
83 | void rename_gdscript_functions(Vector<SourceLine> &source_lines, const RegExContainer ®_container, bool builtin); |
84 | Vector<String> check_for_rename_gdscript_functions(Vector<String> &lines, const RegExContainer ®_container, bool builtin); |
85 | void process_gdscript_line(String &line, const RegExContainer ®_container, bool builtin); |
86 | |
87 | void rename_csharp_functions(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
88 | Vector<String> check_for_rename_csharp_functions(Vector<String> &lines, const RegExContainer ®_container); |
89 | void process_csharp_line(String &line, const RegExContainer ®_container); |
90 | |
91 | void rename_csharp_attributes(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
92 | Vector<String> check_for_rename_csharp_attributes(Vector<String> &lines, const RegExContainer ®_container); |
93 | |
94 | void rename_gdscript_keywords(Vector<SourceLine> &r_source_lines, const RegExContainer &p_reg_container, bool p_builtin); |
95 | Vector<String> check_for_rename_gdscript_keywords(Vector<String> &r_lines, const RegExContainer &p_reg_container, bool p_builtin); |
96 | |
97 | void rename_input_map_scancode(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
98 | Vector<String> check_for_rename_input_map_scancode(Vector<String> &lines, const RegExContainer ®_container); |
99 | |
100 | void rename_joypad_buttons_and_axes(Vector<SourceLine> &source_lines, const RegExContainer ®_container); |
101 | Vector<String> check_for_rename_joypad_buttons_and_axes(Vector<String> &lines, const RegExContainer ®_container); |
102 | |
103 | void custom_rename(Vector<SourceLine> &source_lines, String from, String to); |
104 | Vector<String> check_for_custom_rename(Vector<String> &lines, String from, String to); |
105 | |
106 | void rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<SourceLine> &source_lines); |
107 | Vector<String> check_for_rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<String> &lines); |
108 | |
109 | Vector<String> check_for_files(); |
110 | |
111 | Vector<String> parse_arguments(const String &line); |
112 | int get_end_parenthesis(const String &line) const; |
113 | String connect_arguments(const Vector<String> &line, int from, int to = -1) const; |
114 | String get_starting_space(const String &line) const; |
115 | String get_object_of_execution(const String &line) const; |
116 | bool contains_function_call(String &line, String function) const; |
117 | |
118 | String line_formatter(int current_line, String from, String to, String line); |
119 | String simple_line_formatter(int current_line, String old_line, String line); |
120 | String collect_string_from_vector(Vector<SourceLine> &vector); |
121 | Vector<SourceLine> split_lines(const String &text); |
122 | |
123 | bool test_single_array(const char *array[][2], bool ignore_second_check = false); |
124 | bool test_conversion_gdscript_builtin(String name, String expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &, bool), String what, const RegExContainer ®_container, bool builtin); |
125 | bool test_conversion_with_regex(String name, String expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &), String what, const RegExContainer ®_container); |
126 | bool test_conversion_basic(String name, String expected, const char *array[][2], LocalVector<RegEx *> ®ex_cache, String what); |
127 | bool test_array_names(); |
128 | bool test_conversion(RegExContainer ®_container); |
129 | |
130 | public: |
131 | ProjectConverter3To4(int, int); |
132 | bool validate_conversion(); |
133 | bool convert(); |
134 | }; |
135 | |
136 | #endif // MODULE_REGEX_ENABLED |
137 | |
138 | #endif // DISABLE_DEPRECATED |
139 | |
140 | #endif // PROJECT_CONVERTER_3_TO_4_H |
141 | |