Code generation method, electronic equipment, storage medium and program product
By finding and splicing the code characteristics of the target components in the code base, the problem of generating independent component code in the dynamic development environment is solved, and automated code generation and verification is realized, improving the flexibility and accuracy of the code.
Patent Information
- Application Number
- CN202411976230.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-05-02
AI Technical Summary
It is difficult for prior art to generate complete and available independent component code in dynamic and variable development environments, especially when component dependencies change or new complex dependencies are added.
By finding the first code in the code base according to the code characteristics of the target component, and splicing it into the second code with the dependency code with the dependency identifier. Then, the second code is verified in syntax checksum function, its effectiveness is determined, and when valid, it is rendered as the object code.
It realizes the automatic generation of independently running component code in a dynamic and changeable development environment, overcomes the inflexibility of manually determining dependencies and finding logic, and ensures the availability and accuracy of generated code.
Smart Images

Figure CN119917091A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to technical fields such as data processing, and in particular to a code generation method, an electronic device, a storage medium, and a program product. Background Art
[0002] Obtaining sufficient training data is an important step in generating large models. Usually, existing component codes in public code libraries are used as training data for large models to overcome the problem of difficulty in obtaining training data. However, during the rendering and application process, component codes have a strong dependence on style descriptions, processing logic, interaction logic, and other contents recorded in external modules. In related technologies, fixed search logic for component dependencies is usually determined manually. If the dependency relationship of a component changes or a complex dependency relationship is added, this method will make it difficult to generate complete and usable independent component code. This method is not flexible and efficient in a dynamic and changing development environment. Summary of the invention
[0003] The present disclosure provides a code generation method, an electronic device, a storage medium, and a program product.
[0004] According to one aspect of the present disclosure, a code generation method is provided, comprising: according to code features of a target component, the code features include a first feature and a second feature, the first feature characterizing a target code framework on which the target component depends, and the second feature is a grammatical feature of the component code, finding a first code of the target component in a code library, the first code recording a component feature of the target component and a dependency identifier of the component feature, the dependency identifier being used to mark a dependent code capable of realizing the component feature; concatenating the first code and the dependent code having the dependency identifier into a second code; determining the validity of the second code, the validity including valid and invalid, the validity being used to measure the grammatical state and functional state of the second code; and in the case where the validity is valid, taking the second code as the target code, the target code being able to obtain the target component having the component feature after rendering.
[0005] In some embodiments, based on the code features of the target component, finding the first code of the target component in a code library includes: searching the code library for multiple candidate codes having the code features; and performing feature review and analysis on the multiple candidate codes to determine the first code having the code features.
[0006] In some embodiments, determining the validity of the second code includes: performing a syntax check on the second code to obtain a check result and a check suggestion; if the check result is a failure, adjusting the syntax of the second code according to the check suggestion to obtain a grammatically correct second code; and performing a functional verification on the grammatically correct second code to obtain the validity of the second code.
[0007] In some embodiments, a grammatically correct second code is functionally verified to obtain the validity of the second code, including: determining an input structure of the target component in the grammatically correct second code, the input structure representing a data category that the target component needs to obtain from the outside world; calling a simulation data model to generate multiple sets of simulation data according to the input structure, the simulation data being the simulated input content of the input structure; performing functional verification on the grammatically correct second code using the simulation data to obtain a verification result, the functional verification including input verification and output verification, the input verification being used to determine the running state of the second code after receiving the simulation data, and the output verification being used to determine whether a processing result of the second code on the simulation data matches an expected result; and determining the validity of the second code based on the verification result.
[0008] In some embodiments, the second code is functionally verified using the simulation data, including: rendering the second code to obtain a component to be verified; determining a first verification result of the component to be verified based on feedback from the component to be verified on the input simulation data, the first verification result representing the operating state of the component to be verified after receiving the simulation data; when the first verification result is normal operation, controlling the component to be verified to process the simulation data, comparing the processing result of the component to be verified with the expected result, and obtaining a second verification result, the second verification result representing the consistency between the processing result and the expected result.
[0009] In some embodiments, the validity of the second code is determined based on the verification result, including: when the first verification result is abnormal operation, determining that the second code is invalid; when the second verification result is inconsistent, determining that the second code is invalid; or when the second verification result is consistent, determining that the second code is valid.
[0010] In some embodiments, before finding the first code of the target component in the code library, the method includes: determining a code library corresponding to a target code framework among multiple candidate code libraries, wherein the code library records the code created via the target code framework, and the target code framework is a code framework on which the target component depends for creation.
[0011] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, so that the processor executes the code generation method of any embodiment of the present disclosure.
[0012] According to another aspect of the present disclosure, a readable storage medium is provided, in which execution instructions are stored. When the execution instructions are executed by a processor, the code generation method of any embodiment of the present disclosure is implemented.
[0013] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the code generation method of any embodiment of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings illustrate exemplary embodiments of the present disclosure and together with the description serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.
[0015] Figure 1 It is a schematic diagram of an application scenario of the code generation method according to an embodiment of the present disclosure.
[0016] Figure 2 It is a flow chart of a code generation method according to an embodiment of the present disclosure.
[0017] Figure 3 It is a schematic diagram of the target code acquisition process according to the embodiment of the present disclosure.
[0018] Figure 4 It is a schematic diagram of the verification process of the second code according to an embodiment of the present disclosure.
[0019] Figure 5 It is a schematic diagram of display when the component to be verified according to an embodiment of the present disclosure operates normally.
[0020] Figure 6 It is a display schematic diagram when the processing result of the component to be verified according to the embodiment of the present disclosure is consistent with the expected result.
[0021] Figure 7 It is a schematic block diagram of the structure of a code generation device according to an embodiment of the present disclosure.
[0022] Figure 8 It is a schematic block diagram of the structure of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0023] The present disclosure is further described in detail below in conjunction with the accompanying drawings and examples. It is understood that the specific examples described herein are only used to explain the relevant content, rather than to limit the present disclosure. It should also be noted that, for ease of description, only the parts related to the present disclosure are shown in the accompanying drawings.
[0024] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The technical solution of the present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0025] The code base stores codes involved in various development projects, including component codes, internal processing logic codes, etc. Development projects can be, for example, website creation projects. Some component codes in the code base can be used as training data for component code generation models, which can reduce the time spent on writing component codes. However, component codes usually only record component features and dependency identifiers of dependency codes of each feature; component features include component style selection, some processing logic or interaction logic in the implementation process of component functions, and even external processing modules such as large language models required by components to complete a certain function. Obviously, most component codes do not have the ability to run independently. If you want them to run independently, you should extract the dependencies of the components and then merge them into the component code to obtain new code. In the related art, the general search logic for component dependencies is manually defined. If the dependency relationship of a component changes, or a complex dependency relationship is added, it is difficult to obtain complete and accurate dependency code through the inherent logic defined by the human, and the new code finally obtained is unlikely to have the ability to independently implement its functions. The above method is not flexible and efficient in a dynamic and changeable development environment.
[0026] To this end, the present disclosure proposes a code generation method.
[0027] Figure 1 Schematic diagram of an application scenario of the code generation method according to an embodiment of the present disclosure. Figure 1 As shown, in this application scenario, a server 100 and a terminal device 200 may be included. The server 100 and the terminal device 200 may be connected via a network or Bluetooth to exchange data. The server 100 may be a cloud server or a physical server, and the terminal device 200 may be a smart device such as a computer, a mobile phone, or a tablet. The server 100 is used to provide the basic data required to run the code generation method, and the terminal device 200 executes the code generation method of the present disclosure based on the basic data provided by the server 100.
[0028] For the convenience of description and to make the technical solutions of the specific implementation methods of the present disclosure easier to understand, before describing the code generation method implemented in the present disclosure, the technical terms involved in the specific implementation methods of the present disclosure are explained as follows:
[0029] Target component: a component generated via a target code framework. The target component has a first feature and a second feature. The first feature is an inherent feature of the code generated via the target code framework, and the second feature is a grammatical feature of the component code. The first feature can be used to determine that the code framework on which the generated component depends is the target code framework, and the second feature can be used to determine that the object described by the code is a component. Any component that needs to obtain an independently running code using the method disclosed in the present invention can be used as a target component.
[0030] First code: code used to describe the component features of the target component, and also records the dependency identifiers of the dependencies of the target component to implement the component features. The component features are the component functions and component styles of the target component. However, when rendering the first code, it is necessary to call the rendering method code to render the component style; in actual application, it is necessary to call the logic code, interaction code, external module code, etc. that support its function implementation to implement its component function. In other words, it is usually difficult to obtain a target component with a specified style and function implementation capabilities only through the first code.
[0031] Dependency code: It is the logic code, interaction code, external module code, rendering mode code, associated component code, Hooks, etc. determined according to the dependency identifier in the first code. It is the code of some dependencies that the target component must have when implementing its component features. These dependency codes are usually recorded in the code library. Among them, the associated component code is the parent component code of the target component, and the associated component code can also be obtained by the method disclosed in this disclosure.
[0032] Second code: is the result of splicing the first code and the second code. The second code has the complete code content required for the target component to be rendered and applied, but there may be some syntax or logic problems, so it needs to be verified before it can be used as the target code.
[0033] Target code: is the result of correcting the second code according to the feedback suggestions after multiple rounds of verification such as syntax verification and functional verification. Of course, if the second code is qualified after multiple rounds of verification, then the second code is the target code. After being run independently, the target code can render a target component with component characteristics, overcoming the reliance of the first code on external dependencies at runtime.
[0034] Figure 2 is a flow chart of a code generation method according to an embodiment of the present disclosure. Figure 2, showing the various steps of the code generation method M200, the data for implementing the method M200 can be recorded in Figure 1 The method M200 can be executed by the agent in the terminal device 200 in the server 100 to obtain the target code.
[0035] In step S210, the first code of the target component is found in the code library according to the code feature of the target component.
[0036] The code features include a first feature and a second feature. The first feature characterizes the target code framework on which the target component depends, and the second feature is the grammatical feature of the component code.
[0037] Component code is generally generated by a code framework, such as the React framework. The codes generated by different code frameworks use different syntax structures and have different file extensions. If the target code framework of the target component is the React framework, the code generated by the framework usually uses JSX (JavaScript XML) syntax to describe component features, and uses ".jsx" or ".js" as the extension of the file storing the component code. When searching for the first code of the target component, the syntax structure or file extension of the target code framework that the target component depends on is used as the first feature, and then the component code belonging to the framework can be identified through the first feature.
[0038] Component code focuses more on the style of the component in the user interface, and usually embeds HTML (Hyper Text Markup Language) tags in the return value, such as " <h1>”、" <button>" and other tags, among which " <h1> " can be a title, such as "Welcome to my website", "< / h1> < / button> <button>"It can be a button with "Click" written on it. When the user clicks this button, a warning box will pop up "Button clicked!" and so on. When the description object of a certain code is a component, there will be the grammatical features mentioned above, so it can be determined that the description object of the code is a component based on the second feature. Of course, the grammatical features of the component code can also be other, which are not limited here.
[0039] According to the code features, each code file in the code library is traversed to find the first code of the target code obtained through the target code framework in the code library.
[0040] In step S220, the first code and the dependent code having the dependent identifier are concatenated into a second code.
[0041] The first code records the dependency identifiers of the dependencies that implement the component features. Therefore, based on these dependency identifiers, the dependency codes of these dependencies are located in the code base.
[0042] For example, the first code contains the following content: "import '. / MyComponent.css'; / / Import CSS file; importlogo from '. / logo.png'; / / Import picture", which means importing CSS style from the CSS (Cascading Style Sheets) file named "MyComponent.css", and importing pictures from the file named "logo.png". Then "MyComponent.css" and "logo.png" are dependency identifiers, their respective corresponding files are dependencies, and the file contents are dependency codes. Dependencies can be located through these dependency identifiers and their contents can be obtained. Dependencies can be tool functions, Hooks, and external processing modules that implement component functions. Hooks can call the data processing logic of other functions or modules, and the hooked data processing logic is suitable for the implementation of component functions.
[0043] Then, the first code and the dependent code are spliced together to obtain the second code. When obtaining the second code, the dependency order of each dependency item is managed, and namespace conflicts are handled to avoid duplicate definition problems. The second code has rendering logic code for rendering component style and processing logic code, interaction logic code, etc. for implementing component functions. In theory, it should be possible to render the target component by running independently. However, in order to improve the availability and accuracy of the obtained code, the effectiveness of the second code is verified through step S230, so that the valid second code can be used as the target code for training a large model for generating automatic component code to avoid interference from invalid second code.
[0044] In step S230, the validity of the second code is determined.
[0045] The second code includes two validity states: valid and invalid. The validity is used to measure the grammatical state and functional state of the second code. When the second code is valid, it can be used as the target code in scenarios such as model training. If the second code is invalid, the second code should be adjusted to correct its problems until the second code is valid; or, the second code should be abandoned to avoid interference of the invalid second code on the application scenario.
[0046] Verifying the validity of the second code includes at least two verification processes, such as syntax verification and functional verification. During syntax verification, the syntax processing model can be used to determine the syntax status of the second code. If there is a syntax problem, the syntax processing model is controlled to correct the problem part to obtain a grammatically correct second code.
[0047] Furthermore, the second code with correct syntax is functionally verified to determine the functional status of the second code. Functional verification includes input verification and output verification. Input verification means that the component to be verified rendered by the second code can display or feedback reasonable results according to the input simulation data. For example, if a number is entered in the input box for gender, a prompt such as "wrong entry" can be displayed instead of displaying wrong input or garbled characters. Output verification means that the processing result of the input simulation data is consistent with the expected result; for example, after the target component is filled with simulation data, you want to trigger the submission function of the target component by clicking the "Submit" button. If the simulation data recorded by the target component is submitted to the corresponding location after clicking the "Submit" button, it proves that the processing result is consistent with the expected result; on the contrary, if the simulation data is not submitted to the corresponding location after the "Submit" function is triggered, or is submitted to an error, then the output verification indicates that the processing result is inconsistent with the expected result.
[0048] In step S240, if the validity is valid, the second code is used as the target code. That is, if the second code has no grammatical problems and passes the functional verification, it can be used as the target code for training the large model for generating automatic component code. Otherwise, it should be used as the target code after being modified to have no grammatical problems and pass the functional verification, or it should be directly discarded.
[0049] The present invention locates the first code and the dependent code in the code base according to the code features and dependency identifiers, and then obtains the second code spliced by the above two, realizing an automated independent code generation process, overcoming the problem of manually determining the dependency relationship and the inflexibility of the search logic. And through multiple rounds of verification of the second code, the availability and accuracy of the target code finally put into use are guaranteed, avoiding the interference of the error code.
[0050] Figure 3 This is a schematic diagram of the target code acquisition process according to the embodiment of the present disclosure. Figure 3 Describe the complete process of obtaining the target code.
[0051] Component code is usually generated by a code framework. The syntax structures of different code frameworks are different. For example, the React framework uses JSX syntax. In the scenario of training a large model for automatically generating component code, a large amount of component code that can run independently is required as training data. If you want the style of the component code generated by the large model to be the same or similar to the code output by the React framework, then you need to use the component code generated by the React framework as training data. Similarly, if you want the large model to generate code that is the same or similar to the style of other component code frameworks, then use the code output by the corresponding component code framework as training data.
[0052] Different code frameworks have different characteristics when writing code. The unique characteristics formed by the code framework when writing code are used as the first characteristics. Similarly, the code describes different objects in different ways. When identifying component code, the grammatical style of describing the component is used as the second characteristic of the code. The specific explanation of the first and second characteristics can be found in the previous text and will not be repeated here.
[0053] In a complete project code set, by running the component code, a component with a specified style and capable of implementing some component functions can be obtained. However, when generating a component, the component code will call some codes that are not part of the component, such as CSS files in the project code set that are specifically used to record component styles. Usually, this complete project code set is recorded in a code library. Therefore, after determining the target code framework required for subsequent applications, the characteristics of the target code framework are used as the first characteristics; after determining that the code description object required for subsequent applications is a component, the grammatical characteristics of the component are used as the second characteristics, then the component with the first characteristics and the second characteristics is called the target component. Furthermore, based on the first characteristics and the second characteristics of the target component, multiple first codes that take into account both the first characteristics and the second characteristics are found in the code library. The number of first codes can be N, where N is any positive integer.
[0054] Different target components have different dependencies. For example, when the target component is a table, the dependencies may be a file that records the logic of the sorting function, a file that records the logic of the filtering function, a file that records the submission component code, and a CSS file that records the table style. For another example, when the target component is a "submit" button, the dependencies may be a CSS file that records the button style and a file that records the interaction logic of the submission function. Each target component has a dependency set, and the types and quantities of the dependencies in the dependency set are usually different. In the present disclosure, it is set that there are M dependencies for the target component, where M is any positive integer. The content of each dependency is the dependency code; for example, the sorting logic code in the file that records the logic of the sorting function is the dependency code of the first code, and the first code can only realize the sorting function of the data therein after calling the sorting logic code. In order to run the target component independently, the first code and the dependency code need to be spliced into a whole. In this way, when the sorting function of the target component is called, sorting can be achieved by running its own code.
[0055] That is to say, the first code and the M dependent codes are spliced into a whole to obtain the second code. The second code contains the component style information of the rendering target component and the logic code for implementing various component functions. The content of the second code is complete, but there may be syntax errors, redundant code and other problems during the splicing process. It may even be unable to stably respond to external input, and it may be difficult to process and output the input data as expected. In order to ensure the availability, stability and accuracy of the second code, the second code needs to be verified.
[0056] Figure 4 Schematic diagram of the verification process of the second code according to the embodiment of the present disclosure. Figure 4 , showing the multi-round verification process of the second code to determine the validity of the second code.
[0057] First, the second code is input into the grammar processing model. The grammar processing model has the ability to identify grammatical errors in component code and the ability to perform grammatical modification on the code according to the modification method. The grammar processing model can be a large language model. The grammar processing model performs grammar verification on the second code and generates verification results and verification suggestions. The verification results include verification pass and verification fail. The verification suggestions include the location of the incorrect grammar and the cause of the error, such as the problem of repeated references in the second line of code. If the grammar verification fails, then the modification method for the second code is determined according to the verification suggestions of the grammar processing model. In other words, the intelligent agent running this method can determine whether the verification results and verification suggestions of the grammar processing model are accurate and reasonable. If the verification suggestions are accurate, then the modification method is determined according to the verification suggestions, such as deleting the repeated code in the second line of code. Then, this modification method is fed back to the grammar processing model, and the model is controlled to modify the second code according to the modification method. The grammar processing model outputs a modified second code, and the grammar processing model is controlled again to perform grammar verification to obtain the verification results and verification suggestions. Until the second code obtained is a grammatically correct second code. The grammar processing model may include two sub-language models, such as a grammar checking model and a grammar correction model.
[0058] Furthermore, the grammatically correct second code is synchronized to the simulation data model. At the same time, the grammatically correct second code is analyzed to determine its input structure. If the component rendered by the second code is a table, the input structure can be the specific value of the field attribute, etc. Then, the simulation data model is controlled to generate corresponding input data according to the input structure. For example, in the personnel information table, the field attributes are name, age, and gender, so the specific value can be "Zhang Mou-22 years old-female". If the second code renders the component's submit button, the input structure can be a trigger operation for the button, and the specific value can be a click instruction, etc. The simulation data model can be a large language model, which has the ability to output simulation data according to the input structure, and for the same input structure, multiple simulation data can be output to simulate the input conditions of various real scenarios. For example, if the input structure displays the field attributes of name, age, and gender, the specific value can also be "Zhao-24 years old-1234", where gender should be "male" or "female", and "1234" is obviously not a description of gender. However, there may be incorrect input in actual user input, so this kind of simulated data also meets the requirements to verify the component's performance on abnormal data.
[0059] Furthermore, the modified second code with correct syntax is rendered to obtain the component to be verified. Then, a plurality of simulation data are input into the component to be verified to verify the performance of the component to be verified in actual application.
[0060] Perform input verification on the component to be verified, write the simulated data into the component to be verified, and make sure that the component to be verified can generate a correct response to the input simulated data. Still taking the personnel information table as the component to be verified, after inputting the simulated data "Zhang-22 years old-female", determine whether the value of the name attribute is "Zhang", whether the value of the age attribute is "22 years old", and whether the value of the gender attribute is "female". If all are yes, it means that the display of normal simulated data is accurate. After inputting the simulated data "Zhao-24 years old-1234", determine whether the value of the name attribute is "Zhao", whether the value of the age attribute is "24 years old", and whether the value of the gender attribute is "wrongly filled in"; if the value of the gender attribute is filled in as "1234", it means that the component does not have the ability to identify incorrect input. Alternatively, the value of the gender attribute is in a garbled state, or even the personnel information table is in a garbled state, which means that the component cannot operate normally under abnormal input data, and the processing logic of abnormal input data is chaotic. Of course, the feedback for abnormal input data does not necessarily have to be "wrongly filled in", but can also be other expressions that can correctly feedback the error problem, all of which can reflect the normal operation of the component under various simulated data. Similarly, if the simulated data is "Yang Mou", when the component to be verified is operating normally, the value of the name attribute is filled in as "Yang Mou", the values of the gender attribute and the age attribute should be blank, or "not filled in", "empty" and other expressions that can correctly feedback the problem. If garbled characters appear, it means that the component cannot operate normally in the scenario of incomplete input, and the processing logic of incomplete input data is chaotic.
[0061] Figure 5 1 is a schematic diagram of a display when the component to be verified is operating normally according to an embodiment of the present disclosure. Figure 5 , showing the situation that the component to be verified is a personnel information table. In this component, the input structure includes "name", "age" and "gender", among which the "age" attribute has a "sort" function, and the "gender" attribute has a "filter" function. The sorting function and the filtering function depend on the dependencies with sorting function logic and the dependencies with filtering function logic respectively. For the second code of the component to be verified, the logic code of these two dependencies is included. Therefore, when calling the sorting and filtering functions, the sorting and filtering can be realized by running the sorting function code and the filtering function code in the second code, so that the component has the ability to run independently after leaving the code base. Then, when the second code is in a normal running state, the name column records "Zhang" and "Zhao", the age column records "22 years old" and "24 years old", and the gender column records "female" and "wrongly filled in", etc. It can be seen that the feedback of the normal running component to abnormal data is in the form of "wrongly filled in", which can remind the user to make changes instead of directly presenting abnormal data or garbled characters.
[0062] After the first verification result indicates that the component to be verified can run normally, it means that the input verification has passed. Then, the output verification is performed to observe whether the processing result of the component to be verified on the input data according to the component function meets the expectations, that is, whether the processing result is consistent with the expected result.
[0063] Figure 6 is a schematic diagram showing when the processing result of the component to be verified according to the embodiment of the present disclosure is consistent with the expected result. Figure 6 As shown, in the age column of the personnel information table, there is a "sort" function. After clicking the reverse order of the sort function, observe whether the simulated data in the table is sorted in reverse order of age. For example, Zhao is 24 years old and Zhang is 22 years old. Then the older Zhao should be ranked before the younger Zhang. If so, it means that it is consistent with the expected result. If not, it means that it is inconsistent with the expected result. Figure 5 and Figure 6 In the personnel information table, the simulated data can be more, and the present disclosure only lists two sets of simulated data as an illustration. Similarly, the component to be verified can also be in other forms such as buttons and input boxes, which are not limited here.
[0064] If the second verification result shows that the output result of the component to be verified matches the expected result, then the second code is valid; if the first verification result shows that it cannot run normally, or the second verification result shows that it does not match, then the second code is invalid. For invalid second codes, they can be corrected according to the invalid reasons.
[0065] In some implementations, the large language model is also controlled to simplify the second code that has passed multiple rounds of verification, remove redundant code fragments, streamline the code logic structure, and other operations, which are not limited here.
[0066] Furthermore, the effective second code can be used as the target code so that it can be independently and accurately applied to the training scenario of the large model. There is no limitation on the specific application scenario of the target code.
[0067] The code generation method locates the first code and the dependent code in the code base according to the code features and dependency identifiers, and then obtains the second code spliced by the above two, realizing an automated independent code generation process, overcoming the problem of manually determining the dependency relationship and the inflexibility of the search logic. And through multiple rounds of verification of the second code, the availability and accuracy of the target code finally put into use are guaranteed, avoiding the interference of the error code.
[0068] Figure 7 is a schematic block diagram of the structure of a code generation device according to an embodiment of the present disclosure. Figure 7 As shown, the present disclosure provides a code generation device 700, including: a search module 710, used to find a first code of a target component in a code library according to a code feature of the target component, the first code records the component feature of the target component and a dependency identifier of the component feature, and the dependency identifier is used to mark the dependency code that can realize the component feature; a splicing module 720, used to splice the first code and the dependency code with the dependency identifier into a second code; a verification module 730, used to determine the validity of the second code; and a determination module 740, used to, when the validity is valid, use the second code as the target code, and the target code can obtain the target component with the component feature after rendering.
[0069] In some embodiments, the execution steps of the search module 710 are: searching for multiple candidate codes with code features in the code library, the code features include a first feature and a second feature, the first feature represents the target code framework on which the target component depends, and the second feature is a grammatical feature of the component code; and performing feature review and analysis on the multiple candidate codes to determine the first code with the code features.
[0070] In some embodiments, the execution steps of the verification module 730 are: performing syntax check on the second code to obtain a check result and a check suggestion; and if the check result is failed, adjusting the syntax of the second code according to the check suggestion to obtain a grammatically correct second code.
[0071] In some embodiments, the execution steps of the verification module 730 are: determining the input structure of the target component in the second code, the input structure represents the data category that the target component needs to obtain from the outside world; calling the simulation data model to generate multiple sets of simulation data according to the input structure, the simulation data is the simulation input content of the input structure; using the simulation data to perform functional verification on the second code to obtain a verification result, the functional verification includes input verification and output verification, the input verification is used to determine the running state of the second code after receiving the simulation data, and the output verification is used to determine whether the processing results of the second code on the simulation data are consistent with the expected results; and determining the validity of the second code based on the verification result.
[0072] Specifically, when performing functional verification, the execution steps of the verification module 730 are: rendering the second code to obtain the component to be verified; determining the first verification result of the component to be verified based on the feedback of the component to be verified on the input simulation data, the first verification result representing the operating state of the component to be verified after receiving the simulation data; when the first verification result is normal operation, controlling the component to be verified to process the simulation data, comparing the processing result of the component to be verified with the expected result, and obtaining the second verification result, the second verification result representing the consistency between the processing result and the expected result.
[0073] Specifically, when the first verification result is abnormal operation, the second code is determined to be invalid; when the second verification result is inconsistent, the second code is determined to be invalid; or when the second verification result is consistent, the second code is determined to be valid.
[0074] In some implementations, the further step includes: determining a code library corresponding to a target code framework among a plurality of candidate code libraries, the code library recording code created via the target code framework, the target code framework being a code framework on which creation of a target component depends.
[0075] The code generating device 700 may be in the form of computer software, and the above modules may be in the form of software modules.
[0076] The various modules of the code generation device 700 are arranged to implement the various steps of the code generation method. The execution principles and steps thereof can be referred to above and will not be described in detail.
[0077] The execution subject of the code generation method in the specific implementation manner of the present disclosure may be a mobile phone, a computer or other electronic device.
[0078] Therefore, based on any of the above embodiments, the present disclosure further provides an electronic device, which can execute the code generation method of any of the embodiments described above in the present disclosure.
[0079] Figure 8 It is a schematic block diagram of the structure of an electronic device according to an embodiment of the present disclosure.
[0080] like Figure 8 As shown, the hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnected buses and bridges, depending on the specific application and overall design constraints of the hardware. The bus 1100 connects various circuits including one or more processors 1200, memory 1300 and / or hardware modules together. The bus 1100 can also connect various other circuits 1400 such as peripherals, voltage regulators, power management circuits, external antennas, etc.
[0081] The bus 1100 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the figure only uses one connecting line, but does not mean that there is only one bus or one type of bus.
[0082] The present disclosure also provides a readable storage medium, in which a computer program is stored, and the computer program is used to implement the above method when executed by a processor. "Readable storage medium" can be any device that can contain, store, communicate, propagate or transmit a program for use with an instruction execution system, device or equipment or in combination with these instruction execution systems, devices or equipment. More specific examples of readable storage media include the following: an electrical connection portion (electronic device) with one or more wirings, a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.
[0083] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed, the process or function of the present disclosure is executed in whole or in part.
[0084] The computer program or instructions may be stored in a readable storage medium or transmitted from one readable storage medium to another readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The readable storage medium may be any available medium that can be accessed or a data storage device such as a server, data center, etc. that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid state drive. The computer readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.
[0085] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0086] The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0087] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0088] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0089] In the description of this specification, the description with reference to the terms "one embodiment / method", "some embodiments / methods", "example", "specific example", or "some examples" etc. means that the specific features, structures, or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, or characteristics described may be combined in any one or more embodiments / methods or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments / methods or examples described in this specification and features of different embodiments / methods or examples, unless they are contradictory.
[0090] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0091] Those skilled in the art should understand that the above embodiments are only for the purpose of clearly illustrating the present disclosure, and are not intended to limit the scope of the present disclosure. For those skilled in the art, other changes or modifications may be made based on the above disclosure, and these changes or modifications are still within the scope of the present disclosure.< / button> < / h1>
Claims
1. A code generation method, characterized in that: include: According to the code features of the target component, find the first code of the target component in the code library, the code features include a first feature and a second feature, the first feature represents the target code framework on which the target component depends, the second feature is a grammatical feature of the component code, the first code records the component features of the target component and the dependency identifier of the component features, the dependency identifier is used to mark the dependency code that can realize the component features; splicing the first code and the dependent code having the dependent identifier into a second code; Determine the validity of the second code, wherein the validity includes valid and invalid, and the validity is used to measure the grammatical state and functional state of the second code; as well as When the effectiveness is valid, the second code is used as the target code, and the target code can obtain the target component with component characteristics after rendering.
2. The code generation method according to claim 1, characterized in that: Finding the first code of the target component in a code library according to the code feature of the target component includes: Searching the code library for a plurality of candidate codes having the code features; and A feature review and analysis is performed on the multiple candidate codes to determine a first code having the code feature.
3. The code generation method according to claim 1, characterized in that: Determining the validity of the second code includes: Performing syntax checking on the second code to obtain a checking result and a checking suggestion; if the checking result is a failure, adjusting the syntax of the second code according to the checking suggestion to obtain a grammatically correct second code; and Functional verification is performed on the grammatically correct second code to obtain the validity of the second code.
4. The code generation method according to claim 3, characterized in that: Functionally verifying the grammatically correct second code to obtain the validity of the second code includes: Determine an input structure of the target component in a grammatically correct second code, wherein the input structure indicates a data category that the target component needs to obtain from the outside world; Calling a simulation data model to generate multiple sets of simulation data according to the input structure, wherein the simulation data is the simulation input content of the input structure; Performing functional verification on the grammatically correct second code using the simulation data to obtain a verification result, wherein the functional verification includes input verification and output verification, wherein the input verification is used to determine the running state of the second code after receiving the simulation data, and the output verification is used to determine whether the processing result of the second code on the simulation data matches the expected result; and The validity of the second code is determined according to the verification result.
5. The code generation method according to claim 4, characterized in that: Performing functional verification on the second code using the simulation data includes: Render the second code to obtain the component to be verified; Determine a first verification result of the component to be verified according to feedback of the component to be verified on the input simulation data, wherein the first verification result represents the operating state of the component to be verified after receiving the simulation data; When the first verification result is normal operation, the component to be verified is controlled to process the simulation data, and the processing result of the component to be verified is compared with the expected result to obtain a second verification result, wherein the second verification result represents the consistency between the processing result and the expected result.
6. The code generation method according to claim 5, characterized in that: Determining the validity of the second code according to the verification result includes: In the case where the first verification result is abnormal operation, determining that the second code is invalid; If the second verification result is inconsistent, determining that the second code is invalid; or When the second verification result is consistent, it is determined that the second code is valid.
7. The code generation method according to claim 1, characterized in that: Before finding the first code of the target component in the code base, including: A code library corresponding to a target code framework is determined among a plurality of candidate code libraries, wherein the code library records code created via the target code framework, and the target code framework is a code framework on which the target component is dependently created.
8. An electronic device, characterized in that: include: A memory storing execution instructions; as well as A processor, wherein the processor executes the execution instruction stored in the memory, so that the processor executes the code generation method according to any one of claims 1 to 7.
9. A readable storage medium, characterized in that: The readable storage medium stores execution instructions, which are used to implement the code generation method according to any one of claims 1 to 7 when executed by a processor.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the code generation method according to any one of claims 1 to 7 is implemented.