Code generation method and device, and storage medium

By parsing pseudocode and constructing a syntax tree, executable code is generated, solving the problems of difficult function memorization and high error rate in hot patch coding, and achieving more efficient code generation.

CN115878120BActive Publication Date: 2026-07-21TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2021-09-27
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In existing technologies, hot patching coding requires remembering multiple functions and their parameters, which is prone to coding errors, and the amount of code is large and the coding efficiency is low.

Method used

By parsing the target pseudocode, the statements to be transformed and the statements not to be transformed are determined. Based on the preset mapping information, a syntax tree is constructed to generate executable code.

Benefits of technology

It simplifies the syntax structure of pseudocode, improves coding efficiency and code readability, and reduces the amount of code by at least 40%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115878120B_ABST
    Figure CN115878120B_ABST
Patent Text Reader

Abstract

The application discloses a code generation method and device and a storage medium, which can be applied to various scenes such as cloud technology, artificial intelligence, intelligent transportation and Internet of Vehicles, and the method comprises the steps of: analyzing a target pseudo code to obtain an analysis statement; the target pseudo code is a repair code used for repairing a target application; determining a target to-be-converted statement and a non-converted statement based on the analysis statement; determining a target node corresponding to the target to-be-converted statement based on preset mapping information; the target node is a node of a target syntax structure; the preset mapping information represents a mapping relationship between a to-be-converted statement and a node; constructing a syntax tree based on the target node and a preset node; and generating executable code based on the syntax tree. The application converts and translates the pseudo code to make it executable code, realizes the same function with less code amount, and improves the coding efficiency and the readability of the code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a code generation method, apparatus and storage medium. Background Technology

[0002] Existing hot patch coding techniques require memorizing a large number of functions, such as replaceMethod, callObjcInstanceMethod, and callObjcClassMethod, and the meaning of each parameter in these functions must also be remembered, which can easily lead to coding errors. Furthermore, the amount of code is large, resulting in low coding efficiency.

[0003] Therefore, it is necessary to provide a code generation method, apparatus, and storage medium to improve the efficiency of executable code generation. Summary of the Invention

[0004] This application provides a code generation method, apparatus, and storage medium that can improve the efficiency of executable code generation.

[0005] On the one hand, this application provides a code generation method, the method comprising:

[0006] The target pseudocode is parsed to obtain parsing statements; the target pseudocode is repair code used to fix the target application.

[0007] Based on the parsed statements, the target statements to be converted and the statements not to be converted are determined;

[0008] Based on preset mapping information, the target node corresponding to the target statement to be converted is determined; the target node is a node of the target syntax structure; the preset mapping information represents the mapping relationship between the statement to be converted and the node;

[0009] A syntax tree is constructed based on the target node and the preset node; the target node represents the target statement to be converted, and the preset node represents the non-converted statement; the target node is used to store the attribute information of the target statement to be converted.

[0010] Based on the syntax tree, executable code is generated.

[0011] On the other hand, a code generation apparatus is provided, the apparatus comprising:

[0012] The parsing statement determination module is used to parse the target pseudocode to obtain the parsing statement; the target pseudocode is the repair code used to repair the target application;

[0013] The target statement to be converted module is used to determine the target statement to be converted and the non-converted statement based on the parsed statement;

[0014] The target node determination module is used to determine the target node corresponding to the target statement to be converted based on preset mapping information; the target node is a node of the target syntax structure; the preset mapping information represents the mapping relationship between the statement to be converted and the node;

[0015] A syntax tree construction module is used to construct a syntax tree based on the target node and preset nodes; the target node represents the target statement to be converted, and the preset node represents the non-converted statement; the target node is used to store the attribute information of the target statement to be converted.

[0016] The code generation module is used to generate executable code based on the syntax tree.

[0017] On the other hand, a code generation device is provided, the device including a processor and a memory, the memory storing at least one instruction or at least one program segment, the at least one instruction or the at least one program segment being loaded and executed by the processor to implement the code generation method as described above.

[0018] On the other hand, a computer storage medium is provided that stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the code generation method described above.

[0019] On the other hand, a computer program product is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the code generation method as described above.

[0020] The code generation method, apparatus, and storage medium provided in this application have the following technical advantages:

[0021] This application parses the target pseudocode to obtain parsed statements; based on the parsed statements, it determines the target statements to be converted and the statements not to be converted; thus, in the process of converting pseudocode into executable code, the pseudocode is first parsed into different statements, and then the statements are divided into two categories: one category is the statements to be converted, and the other category is the statements not to be converted; according to a preset mapping relationship, the target nodes of the target syntax structure corresponding to the target statements to be converted are determined, simplifying the syntax structure of the statements to be converted; and a syntax tree is constructed based on the target nodes to generate executable code; in the code conversion process, since only a part of the statements needs to be converted, the syntax tree structure built based on the nodes is simple, thus enabling the rapid generation of executable code. This application converts and translates pseudocode into executable code, realizing the same function with less code, improving coding efficiency and code readability. Attached Figure Description

[0022] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 This is a schematic diagram of a code generation system provided in an embodiment of this application;

[0024] Figure 2 This is a flowchart illustrating a code generation method provided in an embodiment of this application;

[0025] Figure 3 This is a flowchart illustrating a method for generating a code parser provided in an embodiment of this application;

[0026] Figure 4 This is a flowchart illustrating a method for generating executable code according to an embodiment of this application;

[0027] Figure 5 This is a flowchart illustrating a method for executing the above-described executable code, provided in an embodiment of this application.

[0028] Figure 6 This is a syntax diagram of the pseudocode corresponding to a project in the existing technology;

[0029] Figure 7 This is a syntax diagram of pseudocode corresponding to a project provided in an embodiment of this application;

[0030] Figure 8 This is a syntax diagram of the pseudocode corresponding to another project in the existing technology;

[0031] Figure 9 This is a syntax diagram of the pseudocode corresponding to another project provided in an embodiment of this application;

[0032] Figure 10 This is a schematic diagram of the syntax structure of the statement to be converted provided in the embodiments of this application;

[0033] Figure 11 This is a schematic diagram of the syntax structure of nodes in the syntax tree provided in the embodiments of this application;

[0034] Figure 12 This is a schematic diagram of a pseudocode statement to be converted provided in an embodiment of this application;

[0035] Figure 13 This is a flowchart illustrating a method for constructing a code parser according to an embodiment of this application;

[0036] Figure 14 This is a flowchart illustrating a method for generating executable code according to an embodiment of this application;

[0037] Figure 15 This is a flowchart illustrating a method for converting pseudocode into executable code, as provided in an embodiment of this application.

[0038] Figure 16 This is a schematic diagram of a statement to be converted and a non-converted statement in target pseudocode provided in an embodiment of this application;

[0039] Figure 17 This is a schematic diagram of syntax analysis for a function call provided in an embodiment of this application;

[0040] Figure 18 This is a schematic diagram of the syntax parsing of pseudocode provided in an embodiment of this application;

[0041] Figure 19 This is a flowchart illustrating a method for calling a _c function provided in an embodiment of this application;

[0042] Figure 20 This is a schematic diagram of code conversion provided in an embodiment of this application;

[0043] Figure 21 This is provided by the embodiments of this application. Figure 16 A diagram illustrating the executable code after the corresponding pseudocode conversion;

[0044] Figure 22 It is a schematic diagram of executable code provided by existing technology;

[0045] Figure 23 This is a schematic diagram of executable code provided in an embodiment of this application;

[0046] Figure 24 yes Figure 22-23 A comparison chart of the code size of the two code types;

[0047] Figure 25 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application;

[0048] Figure 26 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation

[0049] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0050] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0051] The technical terms used in this application are defined as follows:

[0052] One Patch: A hot patching project for the iOS platform;

[0053] Hotfix: When an application encounters a problem after it has been launched and requires an emergency patch to fix it, this is called a hotfix.

[0054] Hot patch: Script code used for hotfixes is called a hot patch.

[0055] Code transformation: Converting simplified JavaScript pseudocode into executable JavaScript code.

[0056] JavaScript (JS for short) is a lightweight, interpreted or just-in-time (JIT) programming language with a function-first approach.

[0057] Objective-C, often written as ObjC or OC and less commonly as Objective C or Obj-C, is an object-oriented programming language that extends C.

[0058] Please see Figure 1 , Figure 1 This is a schematic diagram of a code generation system provided in an embodiment of this application, such as... Figure 1 As shown, the code generation system may include at least server 01 and client 02.

[0059] Specifically, in this embodiment, server 01 may include a standalone server, a distributed server, or a server cluster composed of multiple servers. It may also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Server 01 may include a network communication unit, a processor, and memory, etc. Specifically, server 01 can be used to convert pseudocode into executable code.

[0060] Specifically, in this embodiment, the client 02 may include physical devices such as smartphones, desktop computers, tablets, laptops, digital assistants, smart wearable devices, smart speakers, in-vehicle terminals, and smart TVs. It may also include software running on the physical device, such as web pages provided to users by service providers, or applications provided to users by those service providers. Specifically, the client 02 can be used to execute executable code.

[0061] The following describes a code generation method of this application. Figure 2 This is a flowchart illustrating a code generation method provided in an embodiment of this application. This specification provides the operational steps of the method described in the embodiments or flowchart, but based on conventional or non-inventive labor, more or fewer operational steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only possible execution order. In actual system or server product execution, the method can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment) as shown in the embodiments or accompanying drawings. Specifically, as... Figure 2 As shown, the method may include:

[0062] S201: Parse the target pseudocode to obtain the parsing statement; the above target pseudocode is the repair code used to fix the target application.

[0063] In this application embodiment, pseudocode is an informal, English-structure-similar language used to describe module structure diagrams. The purpose of using pseudocode is to make the described algorithm easily implementable in any programming language (Pascal, C, Java, etc.). Pseudocode cannot be executed directly; for example, to use JavaScript pseudocode to call Objective-C code, code conversion is required for it to function correctly. The target pseudocode needs to be converted into executable code.

[0064] In this embodiment of the application, problems may occur during the operation of the application, requiring hotfix. The fix code for the target application in the hotfix is ​​hot patch code.

[0065] In this embodiment of the application, the above method further includes:

[0066] Based on the object-oriented dot notation syntax, construct the above target pseudocode; the structure of the above object-oriented dot notation syntax includes class name, method, and parameters.

[0067] In this application embodiment, the structure of the object-oriented dot call syntax includes class name, method, and parameters, and the pseudocode built based on this syntax is more concise; using the object-oriented dot call syntax to edit pseudocode simplifies the expression of function calls and property calls; the pseudocode of this application all adopts standard JavaScript syntax; for the same project, the syntax of the pseudocode in the prior art is as follows: Figure 6 As shown, the syntax of the pseudocode in this application is as follows: Figure 7 As shown; in another project, the syntax of the pseudocode for the existing technology is as follows: Figure 8 As shown, the syntax of the pseudocode in this application is as follows: Figure 9 As shown; obviously, compared with the prior art, the syntax for writing pseudocode in this application is simpler.

[0068] In this embodiment of the application, the above-mentioned parsing of the target pseudocode to obtain parsed statements includes:

[0069] The target pseudocode is parsed using a code parser to obtain the parsed statements;

[0070] In the embodiments of this application, such as Figure 3 As shown, the method for generating the above code parser includes:

[0071] S301: Based on lexical analysis tools, the preset lexical sequence is parsed to generate lexical analysis code;

[0072] In this embodiment of the application, the lexical analysis tool can be the flex tool, which is a tool for generating lexical analyzers. It can use regular expressions to generate C language code that matches the corresponding strings.

[0073] S303: Based on the syntax analysis tool, the above-mentioned statement to be converted is parsed to generate syntax analysis code; the above-mentioned statement to be converted is generated based on the above-mentioned preset lexical sequence;

[0074] In this embodiment of the application, the parsing tool can be the bison tool, which is a general parser generator that converts annotated context-free grammars into parsers that use parser tables.

[0075] In this embodiment of the application, the above-mentioned parsing of the statement to be converted based on a syntax analysis tool to generate syntax analysis code includes:

[0076] Determine the target syntax structure of the above statements to be converted;

[0077] Based on the above-mentioned syntax analysis tool, the above-mentioned statement to be converted is parsed according to the above-mentioned target syntax structure, and the above-mentioned syntax analysis code is generated.

[0078] In this embodiment of the application, a simplified syntax structure corresponding to each statement to be converted can be preset, thereby simplifying the converted executable code.

[0079] S305: The compiler compiles the above lexical analysis code and the above syntax analysis code to generate a code parser.

[0080] In this embodiment, the code parser may include a lexical analyzer and a syntax analyzer. The lexical analyzer is built based on lexical analysis code, and the syntax analyzer is built based on syntax analysis code.

[0081] In a specific embodiment, such as Figure 13 As shown, the code parser is constructed using the following methods:

[0082] S1301: Input the custom lexical code into the flex tool to obtain the lexical analysis code, that is, build the lexical analyzer;

[0083] S1303: Input the custom syntax into the Bison tool to obtain the parsing code, that is, build the parser;

[0084] In this embodiment, ANTLR can be used instead of Flex and Bison, although ANTLR is larger in size compared to Flex and Bison. ANTLR (Another Tool for Language Recognition) is an open-source parser that can automatically generate and visualize a syntax tree based on input.

[0085] S1305: Input the lexical analysis code and the syntax analysis code into GCC to build the code parser.

[0086] GCC (GNU Compiler Collection) is a programming language compiler developed by GNU. The GNU Compiler Collection includes front-ends for C, C++, Objective-C, Fortran, Java, Ada, and Go, as well as libraries for these languages.

[0087] In the embodiments of this application, such as Figure 14 As shown, the pseudocode and syntax node structure are defined as input code parsers, which are then converted into executable code.

[0088] In this embodiment of the application, the flowchart for converting pseudocode into executable code is as follows: Figure 15 As shown, it includes the following steps:

[0089] S1501: Input the patch pseudocode into the lexical analyzer and output the lexical unit;

[0090] S1503: Input the lexical unit into the parser to obtain statements to be converted and statements not to be converted; among them, statements to be converted include class definitions, method definitions, attribute calls, method calls, etc.; strings and other statements are statements not to be converted.

[0091] S1505: Create a corresponding node for each statement to be converted; among them, attribute calls and method calls correspond to the same node "CallNode"; strings and other statements correspond to the same node "StringNode";

[0092] S1507: Construct a syntax chain (i.e., a syntax tree) based on the multiple nodes created;

[0093] S1509: Generate executable code based on the syntax chain.

[0094] In this embodiment of the application, the above-mentioned parsing of the target pseudocode to obtain parsed statements includes:

[0095] The target pseudocode above is parsed using a lexical analyzer to obtain a word sequence;

[0096] The parser analyzes the above word sequence to obtain the parsed statement.

[0097] In this embodiment of the application, a syntax tree can be quickly created using the syntax structure corresponding to each node, thereby quickly generating executable code.

[0098] S203: Based on the above parsing statements, determine the target statement to be converted and the statements not to be converted.

[0099] In the embodiments of this application, during the hot patching process of the target application, only certain statements need to be considered for the hot patch code, such as class definitions, method definitions, method calls, property calls, etc. These statements can be identified as statements to be converted, and statements other than these statements can be identified as non-conversion statements.

[0100] In the embodiments of this application, the target statement to be converted may include, but is not limited to, class definitions, method definitions, attribute calls, method calls, string content, etc.

[0101] In a specific embodiment, such as Figure 16 As shown, Figure 16 This includes class definitions, method definitions, property calls, and method call casting statements. Figure 16 Statements marked as "of interest" in the text. Figure 16 Statements marked as "not of interest" are those that do not require conversion. During parsing, it is determined whether method definitions and method calls contain parameters. Some statements to be converted contain hidden parameters. During the construction of the syntax tree, hidden parameters need to be replaced with nodes.

[0102] Existing technologies can convert pseudocode into executable code through simple regular expression string replacement. However, this method is prone to errors when converting string content and has complex conversion syntax. This embodiment analyzes the patched pseudocode and builds a syntax tree through lexical and syntactic analysis, and then performs semantic analysis before outputting executable code. This provides a strong ability to analyze and customize pseudocode, which is impossible with regular expression string replacement. However, performing lexical and syntactic analysis on all pseudocode is very complex and labor-intensive, equivalent to implementing the first half of a JavaScript compiler. For hot-patched code, only certain statements and scenarios are considered, such as class definitions, method definitions, method calls, and property calls. This embodiment divides the pseudocode into two parts based on the converted statements, allowing only the statements to be converted to be converted, thereby reducing the workload of code conversion and improving code conversion efficiency.

[0103] S205: Based on the preset mapping information, determine the target node corresponding to the above target statement to be converted; the above target node is a node of the target syntax structure; the above preset mapping information represents the mapping relationship between the statement to be converted and the node.

[0104] In this embodiment, the grammatical structure of each statement to be converted can be predetermined, that is, a grammatical definition is performed for each statement to be converted, and then a mapping relationship between the statements to be converted and nodes in the syntax tree is constructed; thereby simplifying the grammatical structure of the statements to be converted and improving the code conversion rate; in a specific embodiment, the grammatical definition is as follows: Figure 10 As shown in the figure, the syntax structure of each statement to be converted is defined. The statements to be converted include property calls, function calls, function parameter definitions, etc., and each statement has a fixed syntax structure. For example, the syntax structure of a property call includes three parts: ID.ID, property_call.ID, and function_call.ID, where ID is an identifier. In a specific embodiment, a property call may include: this.name, this.name.length, and this.getName().length.

[0105] In this embodiment, after matching the grammatical structure of the attribute call, the corresponding node in the syntax tree can be constructed. In a specific embodiment, the structure of the nodes in the syntax tree corresponding to the statement to be converted can be as follows: Figure 11 As shown, the statement to be converted corresponds to a parent node, and the word sequence of the statement to be converted according to the grammatical structure corresponds to multiple child nodes; for example, the class node includes child nodes such as class name and method definition.

[0106] S207: Construct a syntax tree based on the target node and the preset node; the target node represents the target statement to be converted, and the preset node represents the non-converted statement; the target node is used to store the attribute information of the target statement to be converted.

[0107] In the embodiments of this application, the attribute information of the target statement to be converted can characterize the syntactic structure of the target statement to be converted. For example, in the syntactic structure of attribute calls, ID.ID, property_call.ID, and function_call.ID are all attribute information of the target statement to be converted.

[0108] An example of syntax analysis for a function call in this application embodiment. Figure 17 As shown, function call statements can be identified, syntax nodes can be constructed, and finally a syntax tree can be formed.

[0109] In the embodiments of this application, such as Figure 18As shown, for statements that don't require attention (non-transformation statements), the statement unit in the parser can ensure that any lexical units that the lexical analyzer failed to process are processed here, thus avoiding parsing errors. In the statement unit, it's important to follow the longest completeness matching principle to ensure the parser prioritizes it. For example, for the statement `self.set`, during matching, match "self.set" instead of "self" to avoid parsing errors and improve parsing accuracy.

[0110] S209: Based on the above syntax tree, generate executable code.

[0111] In the embodiments of this application, such as Figure 4 As shown, before generating executable code based on the syntax tree, the above method also includes:

[0112] S2081: Construct the method call function for each node in the above syntax tree. The above method call function is used to determine the calling method for each node in the above syntax tree.

[0113] S2083: Generate executable code based on the statements represented by each node in the above syntax tree and the above method call functions.

[0114] In the embodiments of this application, such as Figure 21 As shown, Figure 21 for Figure 16 The corresponding executable code after pseudocode conversion.

[0115] In the embodiments of this application, such as Figure 5 As shown, the executable code includes at least two executable statements. After generating the executable code based on the syntax tree, the method further includes:

[0116] S2011: Determine the currently executable statement and the corresponding currently called method in the above executable code;

[0117] S2013: Obtain the method call function in the above executable code;

[0118] In this embodiment of the application, the method call function can be used to find the currently called method.

[0119] S2015: Based on the above method function call, determine whether the above currently called method exists in the first language object;

[0120] S2017: If it exists, call the currently invoked method to execute the executable code.

[0121] In this embodiment of the application, if the currently invoked method does not exist in the first language object, the method further includes:

[0122] S2019: Based on the above method call function, determine whether the above currently called method exists in the second language object.

[0123] S20111: If it exists, call the currently invoked method to execute the executable code.

[0124] In this embodiment of the application, during the execution of the executable code, the calling method corresponding to the executable code can be obtained through the method calling function.

[0125] In this embodiment of the application, if the currently invoked method does not exist in the second language object, the method further includes:

[0126] S20113: The above executable code has been determined to be an exception.

[0127] In this embodiment of the application, if the method calling function cannot obtain the corresponding calling method, it indicates that the executable code is abnormal code, that is, an error occurred in the conversion process of the code, and it needs to be investigated.

[0128] In this embodiment, the hot patch contains both JavaScript code and Objective-C pseudocode. The code parser cannot distinguish between these two types of code, so a method must be found to differentiate them at runtime to ensure correct invocation. Therefore, the code converter needs to convert all method calls into calls to a special "__c" method. This method is primarily responsible for distinguishing between JavaScript and Objective-C methods, ensuring correct invocation of these two different types of methods. For example... Figure 19 As shown, during the code conversion phase, all method calls are transformed into calls to the same __c method. Inside the __c method, the system first searches for the desired method in the JS object. If found, it's a JS method; otherwise, it jumps to the Objective-C layer, searching in the Objective-C object. If found, it's executed; otherwise, an exception is thrown. The code conversion process simply inserts the __c function. This ensures the method is called during code execution. In a specific embodiment, a code conversion diagram is shown below. Figure 20 As shown, the code before conversion cannot run. For example, in the line `self.setTitle()`, the `self` object doesn't exist, and this object might not even have a `setTitle` method, or it might be an Objective-C method. Therefore, the script execution functionality also needs to be implemented.

[0129] In this embodiment of the application, the aforementioned current invocation method includes a parameter-based invocation method and an actual parameter-based invocation method. The invocation of the aforementioned current invocation method to execute the aforementioned executable code includes:

[0130] Based on the above parameter calling method, determine the parameters of the currently executable statement;

[0131] Based on the above method of calling arguments, determine the arguments of the currently executable statement.

[0132] Based on the formal and actual parameters of the currently executable statement, execute the executable code.

[0133] In the embodiments of this application, for the same project, the prior art and the executable code of this application are as follows: Figure 22-23 As shown, Figure 24 A comparison chart of the code size for both; based on Figure 22-24 It is evident that the amount of code obtained by the method of this application is significantly greater than that of the prior art.

[0134] This application eliminates the need to memorize commonly used functions during code conversion; users do not need to know the existence of these functions, and it fully conforms to JavaScript syntax conventions. The coding syntax is entirely based on modern object-oriented programming languages, improving the convenience and readability of writing code; and the amount of code is reduced by at least 40%.

[0135] As can be seen from the technical solutions provided by the embodiments of this application above, the embodiments of this application parse the target pseudocode to obtain parsed statements; based on the parsed statements, the target statements to be converted and the statements not to be converted are determined; thus, in the process of converting pseudocode into executable code, the pseudocode is first parsed into different statements, and then the statements are divided into two categories: one category is the statements to be converted that need to be converted, and the other category is the statements that do not need to be converted; according to the preset mapping relationship, the target nodes of the target syntax structure corresponding to the target statements to be converted are determined, simplifying the syntax structure of the statements to be converted; and a syntax tree is constructed based on the target nodes to generate executable code; in the code conversion process, since only some statements need to be converted, the syntax tree structure constructed based on the nodes is simple, thus enabling the rapid generation of executable code. This application converts and translates pseudocode into executable code, realizing the same function with less code, improving coding efficiency and code readability.

[0136] This application also provides a code generation apparatus, such as... Figure 25 As shown, the device includes:

[0137] The parsing statement determination module 2510 is used to parse the target pseudocode to obtain the parsing statement; the aforementioned target pseudocode is the repair code used to repair the target application;

[0138] The target statement to be converted module 2520 is used to determine the target statement to be converted and the non-converted statement based on the above parsed statement;

[0139] The target node determination module 2530 is used to determine the target node corresponding to the above-mentioned target statement to be converted based on preset mapping information; the above-mentioned target node is a node of the target syntax structure; the above-mentioned preset mapping information represents the mapping relationship between the statement to be converted and the node;

[0140] The syntax tree construction module 2540 is used to construct a syntax tree based on the target node and the preset node; the target node represents the target statement to be converted, and the preset node represents the non-converted statement; the target node is used to store the attribute information of the target statement to be converted.

[0141] The code generation module 2550 is used to generate executable code based on the above syntax tree.

[0142] In some embodiments, the above-mentioned parsing statement determination module includes:

[0143] The parsing statement determination unit is used to parse the target pseudocode mentioned above based on the code parser to obtain the parsing statement.

[0144] In some embodiments, the above-described apparatus may further include:

[0145] The lexical analysis code generation module is used to parse a preset lexical sequence based on a lexical analysis tool and generate lexical analysis code.

[0146] The syntax analysis code generation module is used to parse the above-mentioned statement to be converted based on the syntax analysis tool and generate syntax analysis code; the above-mentioned statement to be converted is generated based on the above-mentioned preset lexical sequence;

[0147] The code parser generation module is used to compile the above lexical analysis code and the above syntax analysis code based on the compiler to generate the above code parser.

[0148] In some embodiments, the above-described syntax analysis code generation module may include:

[0149] The target syntax structure determination unit is used to determine the target syntax structure of the above-mentioned statement to be converted.

[0150] The syntax analysis code generation unit is used to parse the above-mentioned statement to be converted according to the above-mentioned target syntax structure based on the above-mentioned syntax analysis tool, and generate the above-mentioned syntax analysis code.

[0151] In some embodiments, the above-described apparatus may further include:

[0152] The method call function building module is used to construct the method call function for each node in the above syntax tree. The method call function is used to determine the calling method for each node in the above syntax tree.

[0153] The executable code generation module is used to generate executable code based on the statements represented by each node in the above syntax tree and the above method call functions.

[0154] In some embodiments, the executable code includes at least two executable statements, and the apparatus may further include:

[0155] The information determination module is used to determine the currently executable statement and the corresponding currently called method in the above executable code.

[0156] The method call function retrieval module is used to retrieve the method call functions in the executable code above.

[0157] The first judgment module is used to determine whether the above-mentioned currently called method exists in the first language object based on the function call method described above.

[0158] The first execution module is used to execute the executable code by calling the currently invoked method if the first language object contains the aforementioned currently invoked method.

[0159] In some embodiments, if the currently invoked method does not exist in the first language object, the apparatus may further include:

[0160] The second judgment module is used to determine whether the currently called method exists in the second language object based on the function call method described above.

[0161] The second execution module is used to execute the executable code by calling the currently invoked method if the second language object contains the aforementioned currently invoked method.

[0162] In some embodiments, the current invocation method described above includes a parameter-based invocation method and an actual parameter-based invocation method, and the first execution module or the second execution module described above may include:

[0163] The parameter determination unit is used to determine the formal parameters of the currently executable statement based on the above-mentioned formal parameter calling method.

[0164] The argument determination unit is used to determine the arguments of the currently executable statement based on the above-mentioned argument invocation method.

[0165] The code execution unit is used to execute the executable code based on the formal and actual parameters of the currently executable statement.

[0166] In some embodiments, the above-described apparatus may further include:

[0167] The target pseudocode construction module is used to construct the above target pseudocode based on the object-oriented dot notation syntax; the structure of the above object-oriented dot notation syntax includes class name, method, and parameters.

[0168] The apparatus and method embodiments described herein are based on the same inventive concept.

[0169] This application provides a code generation device, which includes a processor and a memory. The memory stores at least one instruction or at least one program segment, which is loaded and executed by the processor to implement the code generation method provided in the above method embodiments.

[0170] Embodiments of this application also provide a computer storage medium, which can be disposed in a terminal to store at least one instruction or at least one program related to implementing a code generation method in the method embodiment. The at least one instruction or at least one program is loaded and executed by the processor to implement the code generation method provided in the above method embodiment.

[0171] Embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the code generation method provided in the above-described method embodiments.

[0172] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0173] The memory described in this application embodiment can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for the functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.

[0174] The code generation method embodiments provided in this application can be executed on mobile terminals, computer terminals, servers, or similar computing devices. Taking running on a server as an example, Figure 26 This is a hardware structure block diagram of a server for a code generation method provided in an embodiment of this application. For example... Figure 26 As shown, the server 2600 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 2610 (CPUs 2610 may include, but are not limited to, microprocessors (MCUs) or programmable logic devices (FPGAs), a memory 2630 for storing data, and one or more storage media 2620 (e.g., one or more mass storage devices) for storing application programs 2623 or data 2622. The memory 2630 and storage media 2620 may be temporary or persistent storage. The program stored in the storage media 2620 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 2610 may be configured to communicate with the storage media 2620 and execute the series of instruction operations stored in the storage media 2620 on the server 2600. Server 2600 may also include one or more power supplies 2660, one or more wired or wireless network interfaces 2650, one or more input / output interfaces 2640, and / or one or more operating systems 2621, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0175] The input / output interface 2640 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 2600. In one example, the input / output interface 2640 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the input / output interface 2640 may be a radio frequency (RF) module for wireless communication with the Internet.

[0176] Those skilled in the art will understand that Figure 26 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 2600 may also include... Figure 26 The more or fewer components shown, or having the same Figure 26The different configurations shown.

[0177] As can be seen from the embodiments of the code generation method, apparatus, device, or storage medium provided in this application, this application parses the target pseudocode to obtain parsed statements; based on the parsed statements, it determines the target statements to be converted and the statements not to be converted; thus, in the process of converting pseudocode into executable code, the pseudocode is first parsed into different statements, and then the statements are divided into two categories: one category is the statements to be converted that need to be converted, and the other category is the statements that do not need to be converted; according to the preset mapping relationship, the target node of the target syntax structure corresponding to the target statement to be converted is determined, which simplifies the syntax structure of the statement to be converted; and a syntax tree is constructed based on the target node to generate executable code; in the code conversion process, since only some statements need to be converted, the syntax tree structure constructed based on the node is simple, thus enabling the rapid generation of executable code. This application converts and translates pseudocode into executable code, realizing the same function with less code, improving coding efficiency and code readability.

[0178] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0179] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, devices, and storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0180] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer storage medium, such as a read-only memory, a disk, or an optical disk.

[0181] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A code generation method, characterized in that, The method includes: Based on object-oriented dot notation syntax, target pseudocode using JavaScript syntax is constructed; the structure of the object-oriented dot notation syntax includes class name, method, and parameters; The target pseudocode is parsed to obtain parsing statements; the target pseudocode is repair code used to fix the target application. Based on the parsed statements, the target statements to be converted and the statements not to be converted are determined; the target statements to be converted include at least one of the following statements in the hotfix process of the target application: class definition, method definition, method call, and attribute call; Based on preset mapping information, the target node corresponding to the target statement to be converted is determined; the target node is a node of the target grammatical structure; the preset mapping information represents the mapping relationship between the statement to be converted and the node; the method for constructing the preset mapping information includes: defining the grammar of each statement to be converted to obtain the grammatical structure of each statement to be converted; based on the grammatical structure, constructing the mapping relationship between each statement to be converted and the nodes in the syntax tree; each statement to be converted corresponds to a parent node, and the word sequence of each statement to be converted according to the grammatical structure corresponds to multiple child nodes; based on the target node and the preset node, constructing the syntax tree; the target node represents the target statement to be converted, and the preset node represents the non-converted statement; the target node is used to store the attribute information of the target statement to be converted. Based on the syntax tree, executable code is generated.

2. The method according to claim 1, characterized in that, The parsing of the target pseudocode to obtain parsed statements includes: The target pseudocode is parsed using a code parser to obtain parsed statements; The method for generating the code parser includes: Based on lexical analysis tools, a preset lexical sequence is parsed to generate lexical analysis code; The statement to be converted is parsed using a syntax analysis tool to generate syntax analysis code; the statement to be converted is generated based on the preset lexical sequence. The compiler compiles the lexical analysis code and the syntax analysis code to generate the code parser.

3. The method according to claim 2, characterized in that, The syntax analysis tool parses the statement to be converted and generates syntax analysis code, including: Determine the target syntax structure of the statement to be converted; Based on the syntax analysis tool, the statement to be converted is parsed according to the target syntax structure to generate the syntax analysis code.

4. The method according to claim 1, characterized in that, Before generating executable code based on the syntax tree, the method further includes: Construct the method call function for each node in the syntax tree, wherein the method call function is used to determine the calling method for each node in the syntax tree; Executable code is generated based on the statements represented by each node in the syntax tree and the method call function.

5. The method according to any one of claims 1-4, characterized in that, The executable code includes at least two executable statements. After generating the executable code based on the syntax tree, the method further includes: Determine the currently executable statement and its corresponding currently invoked method in the executable code; Obtain the method call function in the executable code; Based on the function call described above, determine whether the currently called method exists in the first language object; If it exists, the currently invoked method is called to execute the executable code.

6. The method according to claim 5, characterized in that, If the currently invoked method does not exist in the first language object, the method further includes: Based on the method call function, determine whether the currently called method exists in the second language object; If it exists, the currently invoked method is called to execute the executable code.

7. The method according to claim 6, characterized in that, The currently invoked method includes a parameter-based invocation method and an argument-based invocation method. Invoking the currently invoked method to execute the executable code includes: Based on the parameter calling method, determine the formal parameters of the currently executable statement; Based on the argument invocation method, determine the arguments of the currently executable statement; The executable code is executed based on the formal and actual parameters of the currently executable statement.

8. A code generation device, characterized in that, The device includes: The target pseudocode construction module is used to construct the target pseudocode based on the object-oriented dot notation syntax; the structure of the object-oriented dot notation syntax includes class name, method, and formal parameters; The parsing statement determination module is used to parse the target pseudocode to obtain the parsing statement; the target pseudocode is repair code used to repair the target application; The statement determination module is used to determine the target statement to be converted and the non-converted statement based on the parsed statement; the target statement to be converted includes at least one of the following statements in the hotfix process of the target application: class definition, method definition, method call, and attribute call; The target node determination module is used to determine the target node corresponding to the target statement to be converted based on preset mapping information; the target node is a node of the target grammatical structure; the preset mapping information represents the mapping relationship between the statement to be converted and the node; the method for constructing the preset mapping information includes: defining the grammar of each statement to be converted to obtain the grammatical structure of each statement to be converted; constructing the mapping relationship between each statement to be converted and the node in the syntax tree based on the grammatical structure; each statement to be converted corresponds to a parent node, and the word sequence of each statement to be converted decomposed according to the grammatical structure corresponds to multiple child nodes; A syntax tree construction module is used to construct a syntax tree based on the target node and preset nodes; the target node represents the target statement to be converted, and the preset node represents the non-converted statement; the target node is used to store the attribute information of the target statement to be converted. The code generation module is used to generate executable code based on the syntax tree.

9. The apparatus according to claim 8, characterized in that, The device further includes: The lexical analysis code generation module is used to parse a preset lexical sequence based on a lexical analysis tool and generate lexical analysis code. The syntax analysis code generation module is used to parse the statement to be converted based on a syntax analysis tool and generate syntax analysis code; the statement to be converted is generated based on the preset lexical sequence. The code parser generation module is used to compile the lexical analysis code and the syntax analysis code based on the compiler to generate the code parser.

10. The apparatus according to claim 9, characterized in that, The syntax analysis code generation module includes: The target syntax structure determination unit is used to determine the target syntax structure of the statement to be converted; the syntax analysis code generation unit is used to parse the statement to be converted according to the target syntax structure based on the syntax analysis tool and generate the syntax analysis code.

11. The apparatus according to claim 8, characterized in that, The device further includes: A method call function construction module is used to construct the method call function for each node in the syntax tree, and the method call function is used to determine the calling method for each node in the syntax tree; An executable code generation module is used to generate executable code based on the statements represented by each node in the syntax tree and the method call function.

12. The apparatus according to any one of claims 8-11, characterized in that, The executable code includes at least two executable statements, and the device further includes: The information determination module is used to determine the currently executable statement and the corresponding currently called method in the executable code; The method call function acquisition module is used to acquire the method call functions in the executable code; The first judgment module is used to determine whether the currently called method exists in the first language object based on the function called by the method; The first execution module is configured to, if the currently invoked method exists in the first language object, invoke the currently invoked method to execute the executable code.

13. The apparatus according to claim 12, characterized in that, If the currently invoked method does not exist in the first language object, the apparatus further includes: The second judgment module is used to determine whether the currently called method exists in the second language object based on the function called by the method; The second execution module is used to execute the executable code by invoking the currently invoked method if the currently invoked method exists in the second language object.

14. The apparatus according to claim 13, characterized in that, The current invocation method includes a parameter-based invocation method and an argument-based invocation method, and the first execution module or the second execution module includes: The parameter determination unit is used to determine the formal parameters of the currently executable statement based on the formal parameter calling method. The actual parameter determination unit is used to determine the actual parameters of the currently executable statement based on the actual parameter invocation method; The code execution unit is used to execute the executable code based on the formal and actual parameters of the currently executable statement.

15. A code generation device, characterized in that, The device includes a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the code generation method as described in any one of claims 1-7.

16. A computer storage medium, characterized in that, The computer storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the code generation method as described in any one of claims 1-7.

17. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the code generation method as described in any one of claims 1-7.