Code automatic generation method and device, equipment, program product and medium

By obtaining the strings and shaping variables in the loop statement, writing annotation script configuration templates and generating target loop control information tables, the problem of low code generation efficiency in complex loop scenarios in the existing technology is solved, and efficient and simplified automatic code generation is achieved .

CN119088400APending Publication Date: 2024-12-06WUXI GUOXINWEI HIGH-TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411300449.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-18
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

When writing code for complex loop scenarios, the existing technology needs to generate code separately, resulting in high repetition and low efficiency, and cannot effectively simplify the code generation process.

Method used

By obtaining string variables and shaping variables in loop statements, writing annotation script configuration templates, using template control logic to generate target loop control information tables, and generating target codes based on this table to reduce template configuration and repetitive workload.

Benefits of technology

It realizes efficient automatic generation of complex loop scenario code, reduces repetitive workload, enhances the practicality of scripts, simplifies template control logic, and supports infinite loops that mix shaping and string variables.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088400A_ABST
    Figure CN119088400A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic code generation method and device, equipment, a program product and a medium, and relates to the technical field of chip design. The method comprises the following steps: acquiring a loop statement needing to generate a code; determining a character string variable and a shaping variable in the loop statement; aiming at the loop statement, writing a corresponding annotation script configuration template by respectively taking the character string variable and the shaping variable as control variables; and obtaining a target loop control information table from the annotation script configuration template by using a template control logic preset for the annotation script configuration template, so as to generate a target code corresponding to the loop statement based on the target loop control information table. According to the technical scheme, the template control logic can be simplified, and the repeated workload can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of chip design technology, and in particular to a method, device, equipment, program product and medium for automatic code generation. Background Art

[0002] During the code writing process, for scenarios where the language's own loops cannot be used, a large amount of highly repetitive code needs to be written manually. Generally, a script is written to automatically generate this code based on the number of loops. Figure 1 As shown in the figure, for C++ language: the code on the left can be simplified to the code on the right by the loop supported by C++ language itself; however, Figure 2 As shown, the code cannot be simplified by looping in the language itself. Figure 3 As shown, you can write a script to achieve automatic code expansion. At this time, the script can read the control logic in the comment, X loops from 0 to 3, and then automatically generates the required code. Automatically generating code through scripts can greatly reduce repetitive coding work.

[0003] However, for more complex loop scenarios, if you need to generate Figure 4 The code shown, the existing script needs to be generated separately, such as Figure 5 As shown. It can be seen that due to the high repetitiveness of the upper and lower parts of the code, the existing commonly used scripts need to be written in two sections, and the generation logic is obviously inefficient. Therefore, how to provide a solution to the above technical problems is a problem that technicians in this field currently need to solve. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide a method, device, equipment, program product and medium for automatic code generation, which can improve the efficiency of code generation and reduce the amount of repeated work. The specific scheme is as follows:

[0005] In a first aspect, the present application discloses a method for automatically generating code, comprising:

[0006] Get the loop statement that needs to generate code;

[0007] Determine the string variable and the integer variable in the loop statement;

[0008] For the loop statement, the string variable and the integer variable are used as control variables to write corresponding annotation script configuration templates;

[0009] The target loop control information table is obtained from the annotation script configuration template by utilizing the template control logic pre-set for the annotation script configuration template, so as to generate the target code corresponding to the loop statement based on the target loop control information table.

[0010] Optionally, the obtaining a target loop control information table from the annotation script configuration template by using a template control logic pre-set for the annotation script configuration template includes:

[0011] Determine a first keyword and a second keyword in the annotation script configuration template;

[0012] Obtaining the string variable defined by the first keyword, and determining a corresponding string variable list according to preset symbol identifiers between the string variables, and then adding corresponding first index information, first type information, first start and end condition information, and first current value to the string variable, so as to determine first loop control information based on the string variable, the string variable list, the first index information, the first type information, the first start and end condition information, and the first current value;

[0013] Obtain an integer variable defined by the second keyword, and add corresponding second index information, second type information, second start and end condition information, and second current value to the integer variable, so as to determine second loop control information based on the integer variable, the second index information, the second type information, the second start and end condition information, and the second current value;

[0014] The target loop control information table is generated based on the first loop control information and the second loop control information.

[0015] Optionally, the starting value in the first starting and ending condition information is equal to the first current value, and the starting value in the second starting and ending condition information is equal to the second current value.

[0016] Optionally, after obtaining the target loop control information table from the annotated script configuration template by using the template control logic pre-set for the annotated script configuration template, the method further includes:

[0017] Flipping the loop control information in the target loop control information table to flip the last acquired loop control information as the first loop control information;

[0018] Iteratively generate a first code based on the first loop control information, and iterate the next level of loop control information of the first loop control information to generate a second code when the first loop control information meets the next level of iteration condition;

[0019] After all loop control information iterations are completed, a target code corresponding to the loop statement is determined based on the first code and the second code.

[0020] Optionally, the iteratively generating a first code based on the first loop control information includes:

[0021] Determine a third current value based on the first loop control information, and determine a corresponding first loop control information table based on the third current value;

[0022] generating a third code according to the first loop control information table, and then adding one to the third current value to obtain a next current value;

[0023] The next current value of the third current value is used as the third current value, and then the step of determining the corresponding first loop control information table based on the third current value is triggered until the first loop control information meets the next level iteration condition, and the first code is generated through the third code.

[0024] Optionally, when the first loop control information satisfies a next-level iteration condition, iterating next-level loop control information of the first loop control information to generate a second code includes:

[0025] When the third current value in the first loop control information is greater than the end value in the start end condition information, determining a fourth current value based on the next level loop control information;

[0026] Add one to the fourth current value to obtain a next current value, and use the start value in the start and end condition information in the first loop control information as the third current value, and then determine the corresponding second loop control information table based on the third current value and the next current value obtained by adding one to the fourth current value;

[0027] generating a fourth code according to the second loop control information table, and then adding one to the third current value to obtain a next current value;

[0028] Taking the next current value of the third current value as the third current value, and then triggering the step of determining the corresponding second loop control information table based on the next current value obtained by adding one to the third current value and the fourth current value;

[0029] When the first loop control information satisfies the next level iteration condition again, jump to the step of determining the fourth current value based on the next level loop control information; when the fourth current value in the last loop control information is greater than the end value in the start and end condition information, generate the second code through the fourth code.

[0030] In a second aspect, the present application discloses a device for automatically generating code, comprising:

[0031] A loop statement acquisition module is used to acquire loop statements for which codes need to be generated;

[0032] A variable determination module, used for determining the string variables and the integer variables in the loop statement;

[0033] A template writing module, used for writing corresponding annotation script configuration templates respectively using the string variable and the integer variable as control variables for the loop statement;

[0034] The code generation module is used to obtain a target loop control information table from the annotation script configuration template by using the template control logic pre-set for the annotation script configuration template, so as to generate code corresponding to the loop statement based on the target loop control information table.

[0035] In a third aspect, the present application discloses an electronic device, comprising a processor and a memory; wherein the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the automatic code generation method as described above.

[0036] In a fourth aspect, the present application discloses a computer program product, including a computer program / instructions, which implement the steps of the aforementioned automatic code generation method when executed by a processor.

[0037] In a fifth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the automatic code generation method as described above.

[0038] The present application provides a method for automatic code generation, including: obtaining a loop statement for which code needs to be generated; determining a string variable and an integer variable in the loop statement; for the loop statement, writing a corresponding annotation script configuration template using the string variable and the integer variable as control variables respectively; and obtaining a target loop control information table from the annotation script configuration template using a template control logic pre-set for the annotation script configuration template, so as to generate a target code corresponding to the loop statement based on the target loop control information table.

[0039] The beneficial technical effect of the present application is: for loop statements that need to generate code, by modifying the script to support mixed loops of lists and integer data, the string variables and integer variables in the loop statements are used as control variables, and the corresponding annotation script configuration template is written. Then, based on the template control logic pre-set for the annotation script configuration template, the loop control information is obtained from the annotation script configuration template to automatically generate code. In this way, the configuration of the template is reduced, and infinite loops mixed with integer and string variables are supported. It not only enhances the practicality of the script, simplifies the template control logic, and reduces the repetitive workload, but also can be applied to a variety of programming languages.

[0040] In addition, the present application provides a code automatic generation device, equipment, program product and medium, which correspond to the above-mentioned code automatic generation method and have the same effect as above. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0042] Figure 1 A simplified code diagram for a loop supported by the C++ language itself;

[0043] Figure 2 A simplified code diagram for a loop that is not supported by the C++ language;

[0044] Figure 3 A schematic diagram of automatically generating codes through scripts;

[0045] Figure 4 is a schematic diagram of an example cycle scenario;

[0046] Figure 5 A schematic diagram of automatically generating code through a script for an example loop scenario;

[0047] Figure 6 A flow chart of a code automatic generation method disclosed in this application;

[0048] Figure 7 A loop control information representation disclosed in this application;

[0049] Figure 8 A schematic diagram of a cyclic control information table flipping disclosed in this application;

[0050] Fig. 9 A schematic diagram of a control loop variable disclosed in the present application;

[0051] Fig.10 A schematic diagram of a control loop variable disclosed in the present application;

[0052] Fig.11 A schematic diagram of a variable for ending a control loop disclosed in the present application;

[0053] Fig.12 A schematic diagram of automatic code generation disclosed in this application;

[0054] Fig.13This is a schematic diagram of the structure of a code automatic generation device disclosed in this application;

[0055] Fig.14 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0056] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0057] Currently, for some loop scenarios where automatic code generation cannot be achieved through the language's own loop, scripts are often written to achieve automatic code expansion. However, some of the existing commonly used scripts have highly repetitive content, and the generation logic is obviously inefficient.

[0058] To this end, the present application provides a code automatic generation solution that can improve code generation efficiency and reduce repetitive workload.

[0059] The embodiment of the present invention discloses a method for automatically generating code. Figure 6 As shown, the method includes:

[0060] Step S11: Obtain the loop statement for which code needs to be generated.

[0061] In the embodiment of the present application, for the loop statement scenario where code needs to be generated, the loop statement that needs to generate code is first obtained. Figure 4 A cycle scenario is described. A person skilled in the art can understand that the cycle scenario is only for illustration and does not limit the above cycle scenario. The following specific implementations are described by taking the cycle scenario as an example, and will not be described in detail later.

[0062] Step S12: Determine the string variables and the integer variables in the loop statement.

[0063] After determining the loop statements that need to generate codes, determine the string variables and integer variables in the loop statements, and reduce the configuration of the template by modifying the script to support mixed loops of list and integer data.

[0064] It should be pointed out that the string variables correspond to a and c in the loop statement, and the corresponding string variable list [a, c] can be determined based on the string variables; the integer variables correspond to 0-3 in the loop statement.

[0065] Step S13: For the loop statement, write a corresponding annotation script configuration template by taking the string variable and the integer variable as control variables respectively.

[0066] It is understandable that, currently in the process of generating code, since only the integer variable attached to the string variable is used as a control variable, code generation is performed for a0-a3 and c0-c3 respectively, resulting in a high repeatability of the two parts. In the embodiment of the present application, the string variable is also used as a control variable to write the annotation script configuration template for this problem. In this way, in the process of generating code, the string variable and the integer variable in the annotation script configuration template can be obtained cyclically, and the loop variable is judged by the template control logic, so as to realize code generation and reduce the workload of repeatedly writing code.

[0067] Step S14: utilizing the template control logic pre-set for the annotation script configuration template, obtaining a target loop control information table from the annotation script configuration template, so as to generate a target code corresponding to the loop statement based on the target loop control information table.

[0068] In the embodiment of the present application, the code is automatically generated for the annotation script configuration template through the pre-set template control logic. First, loop control information needs to be obtained from the template configuration, and a target loop control information table is generated based on different loop control information. The specific implementation process includes the following steps:

[0069] Step 1: Determine the first keyword and the second keyword in the annotation script configuration template;

[0070] Step 2: Obtain the string variable defined by the first keyword, and determine the corresponding string variable list according to the preset symbol identifiers between the string variables, and then add the corresponding first index information, first type information, first start and end condition information and first current value to the string variable, so as to determine the first loop control information based on the string variable, the string variable list, the first index information, the first type information, the first start and end condition information and the first current value;

[0071] Step 3: Obtain an integer variable defined by the second keyword, and add corresponding second index information, second type information, second start and end condition information, and second current value to the integer variable, so as to determine second loop control information based on the integer variable, the second index information, the second type information, the second start and end condition information, and the second current value;

[0072] Step 4: Generate the target loop control information table based on the first loop control information and the second loop control information.

[0073] For the convenience of description, the above steps are combined for explanation.

[0074] like Figure 7 As shown, the left side is based on Figure 4 The configuration information in the partial annotation script configuration template obtained from the loop statement scenario in the target loop control information table is shown on the right. The first keyword STR is followed by a string variable, and the second keyword VAR is followed by an integer variable. In the target loop control information table, each row corresponds to a loop control information. The string variable and the integer variable are respectively added with index information, type information, start and end condition information (start value, end value), and current value. According to the string variable, the corresponding string variable list [a, c] can be determined as additional information. For the string variable, the start value is 0 when extracted, and the end value is the list length. The list is obtained by splitting the subsequent strings by commas.

[0075] It should be noted that before the code is generated, the current value and the starting value are equal. Specifically, the starting value in the first starting and ending condition information is equal to the first current value, and the starting value in the second starting and ending condition information is equal to the second current value.

[0076] Furthermore, after the target loop control information table is generated, the loop control information table is reversed, the last loop variable obtained is flipped to the first one, and the iterative code generation starts. Specifically, the loop control information in the target loop control information table is flipped to flip the last loop control information obtained as the first loop control information; the first code is iteratively generated based on the first loop control information, and when the first loop control information meets the next level iteration condition, the next level loop control information of the first loop control information is iterated to generate the second code; when all loop control information iterations are completed, the target code corresponding to the loop statement is determined based on the first code and the second code.

[0077] like Figure 8 The following is a schematic diagram of flipping the target loop control information table. In the flipped target loop control information table, the loop control information corresponding to the integer variable is flipped as the first loop control information. At this time, a code is generated and output:

[0078] The current value of X is 0, and name is 0 (the corresponding string is a in the additional information);

[0079] Template: [name][X]+=1;

[0080] We get: a[0]+=1.

[0081] Next, the loop variable is controlled, and the current value in the first loop control information is increased by 1 to become 1. At this time, a code is generated and output to obtain a[1]+=1, such as Fig. 9 Specifically, a third current value is determined based on the first loop control information, and a corresponding first loop control information table is determined based on the third current value; a third code is generated according to the first loop control information table, and then the third current value is increased by one to obtain a next current value; the next current value of the third current value is used as the third current value, and then the step of determining the corresponding first loop control information table based on the third current value is triggered, until the first loop control information meets the next level iteration condition, and the first code is generated through the third code.

[0082] The third current value is the value currently corresponding to the current value in the first loop control information when each code is generated. Before the first loop control information meets the next level iteration condition, each third current value corresponds to a third code. When the first loop control information meets the next level iteration condition, the third code output obtained each time is used to jointly determine the first code.

[0083] It should be noted that in the embodiment of the present application, the next level iteration condition for the first loop control information is to determine whether the current value is greater than the end value. If the current value is greater than the end value, the current value is changed back to the starting value, and then the current value of the next level loop is increased by one. Fig.10 As shown in the figure, after the current value of the next level loop is increased by 1, the code output starts for the string c in the additional information. At this time, name=c, x is 0, and the output again will get: c[0]+=1.

[0084] Specifically, when the first loop control information satisfies the next level iteration condition, iterating the next level loop control information of the first loop control information to generate the second code specifically includes the following steps:

[0085] When the third current value in the first loop control information is greater than the end value in the start end condition information, determining a fourth current value based on the next level loop control information;

[0086] Add one to the fourth current value to obtain a next current value, and use the start value in the start and end condition information in the first loop control information as the third current value, and then determine the corresponding second loop control information table based on the third current value and the next current value obtained by adding one to the fourth current value;

[0087] generating a fourth code according to the second loop control information table, and then adding one to the third current value to obtain a next current value;

[0088] Taking the next current value of the third current value as the third current value, and then triggering the step of determining the corresponding second loop control information table based on the next current value obtained by adding one to the third current value and the fourth current value;

[0089] When the first loop control information satisfies the next level iteration condition again, jump to the step of determining the fourth current value based on the next level loop control information; when the fourth current value in the last loop control information is greater than the end value in the start and end condition information, generate the second code through the fourth code.

[0090] It can be understood that the fourth current value is the value currently corresponding to the current value in the next level loop control information each time the code is generated. When the code output is performed for the string c in the additional information, the first loop control information is continued to be iterated, that is, the code outputs from c[0]+=1 to c[3]+=1 are determined in sequence. Fig.11 As shown, when the current value of the last loop variable is greater than the end value, it indicates that the loop is ended, otherwise it continues to the next level of iteration and restarts the iteration of the first loop control information.

[0091] like Fig.12 The figure below is a schematic diagram of the final automatic code generation. At this point, the code generation is finished. It can be seen that the string list does not need to be generated separately after being used as a variable. It not only supports the automatic generation of infinite loop codes for mixed integer and list variables, but also can be applied to multiple programming languages. It enhances the practicality of the script, simplifies the template control logic, and reduces the repetitive workload.

[0092] The present application provides a method for automatic code generation, including: obtaining a loop statement for which code needs to be generated; determining a string variable and an integer variable in the loop statement; for the loop statement, writing a corresponding annotation script configuration template using the string variable and the integer variable as control variables respectively; and obtaining a target loop control information table from the annotation script configuration template using a template control logic pre-set for the annotation script configuration template, so as to generate a target code corresponding to the loop statement based on the target loop control information table.

[0093] The beneficial technical effect of the present application is: for loop statements that need to generate code, by modifying the script to support mixed loops of lists and integer data, the string variables and integer variables in the loop statements are used as control variables, and the corresponding annotation script configuration template is written. Then, based on the template control logic pre-set for the annotation script configuration template, the loop control information is obtained from the annotation script configuration template to automatically generate code. In this way, the configuration of the template is reduced, and infinite loops mixed with integer and string variables are supported. It not only enhances the practicality of the script, simplifies the template control logic, and reduces the repetitive workload, but also can be applied to a variety of programming languages.

[0094] Correspondingly, the present application also discloses a device for automatically generating codes, see Fig.13 As shown, the device comprises:

[0095] A loop statement acquisition module 11 is used to acquire a loop statement for which code generation is required;

[0096] A variable determination module 12, used for determining the string variables and the integer variables in the loop statement;

[0097] The template writing module 13 is used for writing corresponding annotation script configuration templates respectively using the string variable and the integer variable as control variables for the loop statement;

[0098] The code generation module 14 is used to obtain a target loop control information table from the annotation script configuration template by using the template control logic pre-set for the annotation script configuration template, so as to generate code corresponding to the loop statement based on the target loop control information table.

[0099] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0100] It can be seen that the above scheme of this embodiment includes: obtaining the loop statement for which code needs to be generated; determining the string variables and the integer variables in the loop statement; for the loop statement, writing a corresponding annotation script configuration template using the string variables and the integer variables as control variables respectively; and obtaining a target loop control information table from the annotation script configuration template by using the template control logic pre-set for the annotation script configuration template, so as to generate a target code corresponding to the loop statement based on the target loop control information table.

[0101] The beneficial technical effect of the present application is: for loop statements that need to generate code, by modifying the script to support mixed loops of lists and integer data, the string variables and integer variables in the loop statements are used as control variables, and the corresponding annotation script configuration template is written. Then, based on the template control logic pre-set for the annotation script configuration template, the loop control information is obtained from the annotation script configuration template to automatically generate code. In this way, the configuration of the template is reduced, and infinite loops mixed with integer and string variables are supported. It not only enhances the practicality of the script, simplifies the template control logic, and reduces the repetitive workload, but also can be applied to a variety of programming languages.

[0102] Furthermore, the present application also discloses an electronic device. Fig.14 This is a structural diagram of an electronic device 20 according to an exemplary embodiment, and the content in the diagram cannot be considered as any limitation on the scope of use of the present application.

[0103] Fig.14 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the automatic code generation method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be a computer.

[0104] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0105] In addition, the memory 22 as a carrier for resource storage may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222 and data 223, etc. The data 223 may include various data. The storage method may be temporary storage or permanent storage.

[0106] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the code automatic generation method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0107] Further, the embodiment of the present application also discloses a computer-readable storage medium, wherein the computer-readable storage medium mentioned here includes a random access memory (Random Access Memory, RAM), a memory, a read-only memory (Read-Only Memory, ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a magnetic disk or an optical disk, or any other form of storage medium known in the technical field. Wherein, when the computer program is executed by the processor, the aforementioned code automatic generation method is implemented. For the specific steps of the method, reference can be made to the corresponding contents disclosed in the aforementioned embodiment, and no further description will be given here.

[0108] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0109] The steps of the code automatic generation method or algorithm described in conjunction with the embodiments disclosed herein can be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module can be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the technical field.

[0110] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0111] The above is a detailed introduction to a code automatic generation method, device, equipment, program product and medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A method for automatic code generation, It is characterized in that include: Get the loop statement that needs to generate code; Determine the string variable and the integer variable in the loop statement; For the loop statement, the string variable and the integer variable are used as control variables to write corresponding annotation script configuration templates; The target loop control information table is obtained from the annotation script configuration template by utilizing the template control logic pre-set for the annotation script configuration template, so as to generate the target code corresponding to the loop statement based on the target loop control information table.

2. The method for automatically generating code according to claim 1, It is characterized in that The step of obtaining a target loop control information table from the annotation script configuration template by using the template control logic pre-set for the annotation script configuration template includes: Determine a first keyword and a second keyword in the annotation script configuration template; Obtaining the string variable defined by the first keyword, and determining a corresponding string variable list according to preset symbol identifiers between the string variables, and then adding corresponding first index information, first type information, first start and end condition information, and first current value to the string variable, so as to determine first loop control information based on the string variable, the string variable list, the first index information, the first type information, the first start and end condition information, and the first current value; Obtain an integer variable defined by the second keyword, and add corresponding second index information, second type information, second start and end condition information, and second current value to the integer variable, so as to determine second loop control information based on the integer variable, the second index information, the second type information, the second start and end condition information, and the second current value; The target loop control information table is generated based on the first loop control information and the second loop control information.

3. The method for automatically generating code according to claim 2, It is characterized in that The starting value in the first starting and ending condition information is equal to the first current value, and the starting value in the second starting and ending condition information is equal to the second current value.

4. The method for automatically generating code according to claim 2, It is characterized in that After obtaining the target loop control information table from the annotation script configuration template by using the template control logic pre-set for the annotation script configuration template, the method further includes: Flipping the loop control information in the target loop control information table to flip the last acquired loop control information as the first loop control information; Iteratively generate a first code based on the first loop control information, and iterate the next level of loop control information of the first loop control information to generate a second code when the first loop control information meets the next level of iteration condition; After all loop control information iterations are completed, a target code corresponding to the loop statement is determined based on the first code and the second code.

5. The method for automatically generating code according to claim 4, It is characterized in that The iterative generation of the first code based on the first loop control information includes: Determine a third current value based on the first loop control information, and determine a corresponding first loop control information table based on the third current value; generating a third code according to the first loop control information table, and then adding one to the third current value to obtain a next current value; The next current value of the third current value is used as the third current value, and then the step of determining the corresponding first loop control information table based on the third current value is triggered until the first loop control information meets the next level iteration condition, and the first code is generated through the third code.

6. The method for automatically generating code according to claim 5, It is characterized in that When the first loop control information satisfies a next-level iteration condition, iterating next-level loop control information of the first loop control information to generate a second code, including: When the third current value in the first loop control information is greater than the end value in the start end condition information, determining a fourth current value based on the next level loop control information; Add one to the fourth current value to obtain a next current value, and use the start value in the start and end condition information in the first loop control information as the third current value, and then determine the corresponding second loop control information table based on the third current value and the next current value obtained by adding one to the fourth current value; generating a fourth code according to the second loop control information table, and then adding one to the third current value to obtain a next current value; Taking the next current value of the third current value as the third current value, and then triggering the step of determining the corresponding second loop control information table based on the next current value obtained by adding one to the third current value and the fourth current value; When the first loop control information satisfies the next level iteration condition again, jump to the step of determining the fourth current value based on the next level loop control information; when the fourth current value in the last loop control information is greater than the end value in the start and end condition information, generate the second code through the fourth code.

7. A code automatic generation device, It is characterized in that include: A loop statement acquisition module is used to acquire loop statements for which codes need to be generated; A variable determination module, used for determining the string variables and the integer variables in the loop statement; A template writing module, used for writing corresponding annotation script configuration templates respectively using the string variable and the integer variable as control variables for the loop statement; The code generation module is used to obtain a target loop control information table from the annotation script configuration template by using the template control logic pre-set for the annotation script configuration template, so as to generate code corresponding to the loop statement based on the target loop control information table.

8. An electronic device, It is characterized in that The electronic device comprises a processor and a memory; wherein the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the code automatic generation method according to any one of claims 1 to 6.

9. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instructions are executed by a processor, the steps of the code automatic generation method according to any one of claims 1 to 6 are implemented.

10. A computer-readable storage medium, It is characterized in that Used to store a computer program; wherein when the computer program is executed by a processor, the code automatic generation method according to any one of claims 1 to 6 is implemented.