Method and system for automatically generating corresponding macro judgment according to reference of macro definition content

An automated method and system for generating macro judgments in game development addresses manual errors by analyzing code scripts to ensure consistent macro definition usage, enhancing efficiency and reducing errors.

CN119166150APending Publication Date: 2024-12-20FUJIAN TQ DIGITAL
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310732391.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-20
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

Manual macro judgment in game development is error-prone and requires significant manpower, necessitating a more efficient and automated approach to ensure consistent macro definition usage across different platforms and plug-in versions.

Method used

An automated method and system for generating macro judgments by analyzing and adding macro definition conditions to code scripts, identifying and validating attribute and function calls within macro definitions to prevent errors.

Benefits of technology

Automatically adds macro judgments to ensure consistent macro definition usage, reducing manual effort and minimizing errors during compilation and execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166150A_ABST
    Figure CN119166150A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for automatically generating corresponding macro judgment for reference of macro definition content. The method comprises the following steps of: 1, reading all code scripts of a game project; 2, traversing all the read code scripts, and reading all contents in the macro definition according to the format of the macro definition; 3, traversing contents in the macro definition in the step 2 line by line, and reading all attribute names and function names defined in the macro definition and form parameters corresponding to function input according to parameters and function regular expressions; 4, traversing all code scripts in the project to judge whether the parameters and the function names of the macro definition in the step 3 appear line by line on code contents in non-macro definition; 5, for the attribute names and the function names with the macro definition in the step 4, judging whether the attribute names and the function names call parameters and functions in the macro definition or not; 6, adding corresponding macro judgment to code lines called by class attributes and class functions in the macro definition in the step 5; therefore, the situation that the macro definition content is reported to be wrong when the system is switched is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code macro definition addition and automatic generation, and in particular to a method and system for automatically generating corresponding macro judgments by quoting macro definition contents. Background Art

[0002] Macro definition is a common syntax provided by high-level language compilers. Its purpose is to use an identifier to identify a text string. When writing a program, if a certain data or a certain program fragment is used repeatedly in the program, you can consider defining this data or program fragment as a macro, and then replace each occurrence of the data or program fragment with the macro name.

[0003] The advantage of choosing macro definition is that the program is concise and readable, and when you need to modify these same program fragments, you only need to modify the string in the macro definition without having to modify multiple places.

[0004] In game development, it is often necessary to define different macros according to different platforms or different plug-in versions, and put different functions or parameters in the corresponding macro definitions according to conditions. Because the functions or parameters defined in the specified macro definition can only be called in the same macro, after defining the functions or parameters in the macro area, it is necessary to set the same macro in different calling places, so that no errors will be reported during compilation or running. This requires a lot of handwritten macro judgments and is prone to errors. Summary of the invention

[0005] To overcome the above problems, the purpose of the present invention is to provide a method for automatically generating corresponding macro judgments by citing macro definition content, which can automatically identify and add macro definition condition judgments, save manpower investment and reduce the probability of errors.

[0006] The present invention is implemented by the following scheme: a method for automatically generating corresponding macro judgments by citing macro definition content, the method comprising the following steps: step S1, reading all code scripts of a game project;

[0007] Step S2, traverse all the read code scripts, and read the contents of all macro definitions according to the format of the macro definition;

[0008] Step S3, traversing the content in the macro definition line by line, and reading all attribute names, function names and formal parameters corresponding to function inputs defined in the macro definition according to the parameters and function regular expressions;

[0009] Step S4, traverse all code scripts in the game project and determine line by line whether the formal parameters and function names of the macro definition in step 3 appear in the code content in non-macro definition; if not, do not process; if yes, go to step S5;

[0010] Step S5, determine whether the attribute name and function name of the macro definition appearing in step 4 are the parameters and function calls in the macro definition; if not, do not process and end the process; if yes, proceed to step S6;

[0011] Step S6 is to add corresponding macro judgment to the code lines of class attributes and class function calls in the macro definition for parameters and function calls in the macro definition.

[0012] Furthermore, the step S3 is further specified as follows: traversing the content in the macro definition line by line, reading all class attribute names defined in the macro definition according to the regular expression defined in the class attribute, and reading the function names of all classes defined in the macro definition and 0 or more formal parameter types corresponding to the function according to the regular expression defined in the class function.

[0013] Furthermore, the step S5 is further specified as follows: the external script calls the parameter or function in the macro definition as an instance or static call, and determines whether the parameter or function call is a function or parameter in the macro definition based on the class name or static class name at other locations where the instance name appears in the script, and performs corresponding processing based on the judgment.

[0014] Furthermore, the step S6 is further specified as follows: the class attributes and class functions in the macro definition are used to identify whether such attributes and functions are valid or callable under the set macro conditions. When calling the parameters and functions in the macro definition, a macro judgment is added to the place where the class attributes and class functions in the macro definition are called to prevent the parameters and functions in the macro definition from being called without the set macro definition conditions, so as to avoid compilation and running errors.

[0015] The present invention provides a system for automatically generating corresponding macro judgments based on the reference of macro definition content, the system comprising: a script reading module, a macro definition content acquisition module, a macro definition content acquisition information module, a judgment module, a call processing module, and a macro judgment adding module;

[0016] The script reading module reads all the code scripts of the game project;

[0017] The module for obtaining macro definition content traverses all the code scripts read and reads the content in all macro definitions according to the format of the macro definition;

[0018] The module for obtaining macro definition content information traverses the content of the macro definition line by line, and reads all attribute names, function names and formal parameters corresponding to function inputs defined in the macro definition according to parameters and function regular expressions;

[0019] The judgment module traverses all code scripts in the game project and judges line by line whether the formal parameters and function names of the macro definitions in the module for obtaining macro definition content information appear; if not, no processing is performed; if yes, the calling processing module is executed;

[0020] The calling processing module determines whether the attribute name and function name of the macro definition are calling the parameters and functions in the macro definition; if not, no processing is performed and the process ends; if yes, the adding macro judgment module is executed;

[0021] The added macro judgment module is for parameters and function calls in macro definitions, and corresponding macro judgments are added to the code lines of class attributes and class function calls in the macro definitions.

[0022] Furthermore, the module for obtaining macro definition content information is further specified as follows: traversing the content in the macro definition line by line, reading all class attribute names defined in the macro definition according to the regular expression defined in the class attribute, and reading the function names of all classes defined in the macro definition and 0 or more formal parameter types corresponding to the function according to the regular expression defined in the class function.

[0023] Furthermore, the call processing module is further specified as follows: the external script calls the parameter or function in the macro definition as an instance or static call, and determines whether the parameter or function call is a function or parameter in the macro definition based on the class name or static class name at other locations where the instance name appears in the script, and performs corresponding processing based on the judgment.

[0024] Furthermore, the added macro judgment module is further specified as follows: the class attributes and class functions in the macro definition are used to identify whether such attributes and functions are valid or callable under the set macro conditions. When calling the parameters and functions in the macro definition, macro judgment is added to the place where the class attributes and class functions in the macro definition are called to prevent the parameters and functions in the macro definition from being called without the set macro definition conditions, so as to avoid compilation and running errors.

[0025] The beneficial effects of the present invention are as follows: the present invention automatically adds corresponding macro definition judgments to the attributes and function calls in the existing macro definition, increases the scope of the existing macro definition, and prevents external code from calling codes that are not within the macro definition conditions and causing errors; the present invention adds corresponding macro judgments to the attributes and functions defined in the macro definition when calling out, so that the definition and calling macro judgment types are consistent, avoiding errors. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 It is a schematic flow chart of the method of the present invention.

[0027] Figure 2 It is an example diagram of the regular expression of the present invention.

[0028] Figure 3 It is a system framework principle diagram of the present invention. DETAILED DESCRIPTION

[0029] The present invention will be further described below in conjunction with the accompanying drawings.

[0030] See also Figure 1 As shown, a method of automatically generating a corresponding macro judgment by citing macro definition content of the present invention comprises the following steps: step S1, reading all code scripts of a game project;

[0031] Step S2, traverse all the read code scripts, and read the contents of all macro definitions according to the format of the macro definition;

[0032] Step S3, traverse the content in the macro definition line by line, and read all attribute names, function names and formal parameters corresponding to function inputs defined in the macro definition according to parameters and function regular expressions; the step S3 is further specifically as follows: traverse the content in the macro definition line by line, read all class attribute names defined in the macro definition according to the regular expression defined by the class attribute, and read the function names of all classes defined in the macro definition and 0 or more formal parameter types corresponding to the function according to the regular expression defined by the class function.

[0033] Step S4, traverse all code scripts in the game project and determine line by line whether the formal parameters and function names of the macro definition in step 3 appear in the code content in non-macro definition; if not, do not process; if yes, go to step S5;

[0034] Step S5, determine whether the attribute name and function name of the macro definition appearing in step 4 are parameters and function calls in the macro definition; if not, do not process and end the process; if yes, enter step S6; step S5 is further specified as follows: the external script calls the parameters or function calls in the macro definition as instances or static calls, and determines whether the parameters or function calls are functions or parameters in the macro definition according to the class names or static class names at other locations where the instance names appear in the script, and performs corresponding processing according to the judgment.

[0035] Step S6, for the parameters and function calls in the macro definition, the corresponding macro judgment is added to the code lines of the class attributes and class function calls in the macro definition. The step S6 is further specifically as follows: the class attributes and class functions in the macro definition are used to identify whether such attributes and functions are valid or callable under the set macro conditions. When the parameters and functions in the macro definition are called, the macro judgment is added to the place where the class attributes and class functions in the macro definition are called to prevent the parameters and functions in the macro definition from being called without the set macro definition conditions, so as to avoid compilation and operation errors.

[0036] The present invention will be further described below in conjunction with a specific embodiment:

[0037] 1. Read all code scripts in the game project according to the file format such as .cs;

[0038] 2. Taking C# as an example, the macro definition starts with the #if macro definition format and ends with the #endif macro definition format. All code scripts are traversed line by line, and the script contents that start with the #if macro definition format and end with the #endif macro definition format are cached;

[0039] 3. For the content cached in step 2, judge all the formal parameters and functions in all the macro definitions in step 2 and their corresponding macro definitions and class names according to the regular expressions of parameters and functions. The formal parameter format takes C# as an example. The formal parameter format is (private int Level;) or (int Level;). The regular expression uses spaces to judge two or three strings, of which the first or the second is the parameter type and ends with (;). The function format takes C# as an example. The format is (publicvoid Test()) or (public void Test(int number)). The regular expression ends with (), and the parameters are in brackets, separated by spaces. The function type is in the middle or in front. The regular expression refers to Figure 2 shown.

[0040] 4. Traverse all code scripts except those in the macro definition, and cache the parameters and function names and their corresponding macro definition types for the parameters and function names in the macro definition in step 3;

[0041] 5. When an external script calls a parameter or function in a macro definition as an instance or static call, it determines whether the parameter or function call is a function or parameter in the macro definition based on the class name or static class name in other locations where the instance name appears, because other non-macro-defined classes may also have parameters or functions with the same name;

[0042] 6. For all calls to macro definition parameters and functions in step 5, add corresponding macro definition judgments using the script string writing method.

[0043] See also Figure 3 As shown, the present invention provides a system for automatically generating corresponding macro judgments based on the reference of macro definition content, the system comprising: a script reading module, a macro definition content acquisition module, a macro definition content acquisition information module, a judgment module, a call processing module, and a macro judgment module;

[0044] The script reading module reads all the code scripts of the game project;

[0045] The module for obtaining macro definition content traverses all the code scripts read and reads the content in all macro definitions according to the format of the macro definition;

[0046] The module for obtaining macro definition content information traverses the content of the macro definition line by line, and reads all attribute names, function names and formal parameters corresponding to function inputs defined in the macro definition according to parameters and function regular expressions;

[0047] The module for obtaining macro definition content information is further specified as follows: traversing the content in the macro definition line by line, reading all class attribute names defined in the macro definition according to the regular expression defined in the class attribute, and reading the function names of all classes defined in the macro definition and 0 or more parameter types corresponding to the function according to the regular expression defined in the class function.

[0048] The judgment module traverses all code scripts in the game project and judges line by line whether the formal parameters and function names of the macro definitions in the module for obtaining macro definition content information appear; if not, no processing is performed; if yes, the calling processing module is executed;

[0049] The calling processing module determines whether the attribute name and function name of the macro definition are calling the parameters and functions in the macro definition; if not, no processing is performed and the process ends; if yes, the adding macro judgment module is executed;

[0050] The call processing module is further specified as follows: the external script calls the parameter or function in the macro definition as an instance or static call, and determines whether the parameter or function call is a function or parameter in the macro definition based on the class name or static class name at other locations where the instance name appears in the script, and performs corresponding processing based on the judgment.

[0051] The added macro judgment module is for parameters and function calls in macro definitions, and corresponding macro judgments are added to the code lines of class attributes and class function calls in the macro definitions.

[0052] The added macro judgment module is further specified as follows: the class attributes and class functions in the macro definition are used to identify whether such attributes and functions are valid or callable under the set macro conditions. When calling the parameters and functions in the macro definition, macro judgments should be added to the places where the class attributes and class functions in the macro definition are called to prevent the parameters and functions in the macro definition from being called without the set macro definition conditions, so as to avoid compilation and running errors.

[0053] The present invention is aimed at the properties and functions in a certain macro definition, such as the properties and functions in the macro definition of the Android platform. When calling these properties and functions of the Android platform macro definition in other code classes, the calling code also needs to add the macro judgment of the Android platform to prevent the current game project from reporting an error when compiling or running on the Android platform. If it is switched to the Apple platform, the code line that calls the properties and functions of the Android platform macro definition will report an error. All properties or functions in the specific macro definition need to add the corresponding macro definition judgment to the calling code line; the present invention automatically adds the corresponding macro definition judgment to the property and function calls in the existing macro definition, which is The scope of the existing macro definition is increased to prevent external code from calling codes that are not within the macro definition conditions and causing errors; if the current platform is Android, when other types of code use the properties and functions in the Android macro definition to reference, no compilation and operation errors will be caused, so people often forget to add the macro definition that can only be run on the Android platform to the code line that calls the properties and functions in the macro definition. At this time, if you switch to other platforms such as the Apple platform, it will cause a large number of errors. The manual addition of functions is large and prone to errors; the present invention adds corresponding macro judgments to the properties and functions defined in the macro definition when calling out the matching, so that the definition and calling macro judgment types are consistent, avoiding errors.

[0054] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.

Claims

1. A method for automatically generating corresponding macro judgments by quoting macro definition content, characterized in that: The method comprises the following steps: Step S1, reading all code scripts of the game project; Step S2, traverse all the read code scripts, and read the contents of all macro definitions according to the format of the macro definition; Step S3, traversing the content in the macro definition line by line, and reading all attribute names, function names and formal parameters corresponding to function inputs defined in the macro definition according to the parameters and function regular expressions; Step S4, traverse all code scripts in the game project and determine line by line whether the formal parameters and function names of the macro definition in step 3 appear in the code content in non-macro definition; if not, do not process; if yes, go to step S5; Step S5, determine whether the attribute name and function name of the macro definition appearing in step 4 are the parameters and function calls in the macro definition; if not, do not process and end the process; if yes, proceed to step S6; Step S6 is to add corresponding macro judgment to the code lines of class attributes and class function calls in the macro definition for parameters and function calls in the macro definition.

2. The method for automatically generating corresponding macro judgments by quoting macro definition content according to claim 1, characterized in that: The step S3 is further specified as follows: traversing the content in the macro definition line by line, reading all class attribute names defined in the macro definition according to the regular expression defined in the class attribute, and reading the function names of all classes defined in the macro definition and 0 or more parameter types corresponding to the function according to the regular expression defined in the class function.

3. The method for automatically generating corresponding macro judgments by quoting macro definition content according to claim 1, characterized in that: The step S5 is further specified as follows: the external script calls the parameter or function in the macro definition as an instance or static call, and determines whether the parameter or function call is a function or parameter in the macro definition based on the class name or static class name at other locations where the instance name appears in the script, and performs corresponding processing based on the judgment.

4. The method for automatically generating corresponding macro judgments by quoting macro definition content according to claim 1, characterized in that: The step S6 is further specified as follows: the class attributes and class functions in the macro definition are used to identify whether such attributes and functions are valid or callable under the set macro conditions. When calling the parameters and functions in the macro definition, macro judgments should be added to the places where the class attributes and class functions in the macro definition are called to prevent the parameters and functions in the macro definition from being called without the set macro definition conditions, so as to avoid compilation and running errors.

5. A system for automatically generating corresponding macro judgments based on the references to macro definition contents, characterized in that: The system comprises: a script reading module, a macro definition content acquisition module, a macro definition content information acquisition module, a judgment module, a call processing module, and a macro adding judgment module; The script reading module reads all the code scripts of the game project; The module for obtaining macro definition content traverses all the code scripts read and reads the content in all macro definitions according to the format of the macro definition; The module for obtaining macro definition content information traverses the content of the macro definition line by line, and reads all attribute names, function names and formal parameters corresponding to function inputs defined in the macro definition according to parameters and function regular expressions; The judgment module traverses all code scripts in the game project and judges line by line whether the formal parameters and function names of the macro definitions in the module for obtaining macro definition content information appear; if not, no processing is performed; if yes, the calling processing module is executed; The calling processing module determines whether the attribute name and function name of the macro definition are calling the parameters and functions in the macro definition; if not, no processing is performed and the process ends; if yes, the adding macro judgment module is executed; The added macro judgment module is for parameters and function calls in macro definitions, and corresponding macro judgments are added to the code lines of class attributes and class function calls in the macro definitions.

6. The system for automatically generating corresponding macro judgments by citing macro definition contents according to claim 5, characterized in that: The module for obtaining macro definition content information is further specified as follows: traversing the content in the macro definition line by line, reading all class attribute names defined in the macro definition according to the regular expression defined in the class attribute, and reading the function names of all classes defined in the macro definition and 0 or more parameter types corresponding to the function according to the regular expression defined in the class function.

7. The system for automatically generating corresponding macro judgments by citing macro definition contents according to claim 5, characterized in that: The call processing module is further specified as follows: the external script calls the parameter or function in the macro definition as an instance or static call, and determines whether the parameter or function call is a function or parameter in the macro definition based on the class name or static class name at other locations where the instance name appears in the script, and performs corresponding processing based on the judgment.

8. The system for automatically generating corresponding macro judgments by citing macro definition content according to claim 5, characterized in that: The added macro judgment module is further specified as follows: the class attributes and class functions in the macro definition are used to identify whether such attributes and functions are valid or callable under the set macro conditions. When calling the parameters and functions in the macro definition, macro judgments should be added to the places where the class attributes and class functions in the macro definition are called to prevent the parameters and functions in the macro definition from being called without the set macro definition conditions, so as to avoid compilation and running errors.

Citation Information

Cited By

  • Non-intra-macro identifier processing method in macro reference row, electronic equipment and medium

    CN121300758A