Code checker generation method and related system
The code development platform uses the positive and negative example code snippets and instruction information input by the user to generate a code checker, which solves the problem that developers need to be familiar with complex underlying frameworks, and achieves efficient development and improved accuracy of code checkers.
Patent Information
- Application Number
- PCT/CN2023/136047
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-07-12
- Filing Date
- 2023-12-04
- Publication Date
- 2024-10-24
AI Technical Summary
When developing a code checker, developers need to have rich development experience and familiarity with the underlying framework, which results in high development difficulty and cost. In addition, the accuracy of traditional search generation methods is low and difficult to meet user needs.
Receive positive and negative example code snippets input by users through the code development platform, obtain relevant instruction information (such as annotation information and difference information), generate candidate code checkers, narrow the search scope, focus on key parameters and types, and improve the performance of the code checker Development efficiency and accuracy.
It reduces the difficulty and cost of developing a code checker. The generated code checker can accurately and efficiently distinguish positive and negative examples, fits the user's intention, and improves development efficiency and accuracy.
Smart Images

Figure CN2023136047_24102024_PF_FP_ABST
Abstract
Description
A code checker generation method and related system
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on April 21, 2023, with application number 202310437883.1 and invention name “A code checker generation method and related system”, and claims priority to the Chinese patent application filed with the State Intellectual Property Office on July 12, 2023, with application number 202310854363.0 and invention name “A code checker generation method and related system”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of software development technology, and in particular to a code checker generation method, a code development platform, a computing device cluster, a computer-readable storage medium, and a computer program product. Background Art
[0003] In recent years, with the rise of technologies like mobile internet, cloud computing, and artificial intelligence, software has continued to expand in size and complexity, increasing the pressure on software security. Among the many security assurance technologies, static analysis can analyze the characteristics of the code itself without running the software, thereby identifying potential issues at a low cost.
[0004] A typical application of static analysis technology is code checkers. Code checkers can automatically detect potential problems (such as bugs) in the code being checked and provide feedback to developers so that these problems can be fixed before the code is actually run. Code checkers are usually built on an underlying framework, which is responsible for parsing the code being checked and storing the code in specific data structures (such as abstract syntax trees and control flow graphs). Based on data structures such as abstract syntax trees and control flow graphs, upper-level code checkers use pre-defined logic to check the code being checked and determine whether there are any errors in the code being checked.
[0005] When developing a code checker, developers not only need to be experienced code writers but also be familiar with the underlying framework the code checker is based on, the specific structure of the code being checked, and the characteristics of the programming language. Some new code checkers have designed corresponding domain-specific languages (DSLs) to assist in code checker development, eliminating the need for developers to master complex underlying frameworks. However, developing a code checker still requires a certain learning curve. Reducing the difficulty and cost of code checker development has become a key concern in the industry.
[0006] Summary of the Invention
[0007] This application provides a method for generating a code checker. This method uses indication information to narrow the search scope, thereby improving the efficiency of code checker development and reducing the difficulty and cost of code checker development. This application also provides a corresponding code development platform, computing device cluster, computer-readable storage medium, and computer program product.
[0008] In the first aspect, the present application provides a code checker generation method, which can be executed by a code development platform. The code development platform is used to generate code for the code checker. The code development platform can be a software system, which can be an independent software, such as an integrated development environment (IDE) deployed on the cloud or locally, and the software system can also be integrated into other software in the form of a plug-in, such as integrated into a code inspection engine. The software system can be deployed on a computing device cluster, and the computing device cluster executes the program code of the software system, thereby executing the code checker generation method of the present application. The code development platform can also be a hardware system with a code checker generation function, which executes the code checker generation method of the present application when the hardware system is running.
[0009] Specifically, the code development platform receives a first code snippet and a second code snippet input by a user, wherein the first code snippet is a code snippet that fails the code checker check, and the second code snippet is a code snippet that passes the code checker check, and then obtains indication information related to the first code snippet or the second code snippet, and generates code for at least one candidate code checker based on the indication information, wherein the indication information includes at least one of annotation information for the first code snippet or the second code snippet and difference information between the first code snippet and the second code snippet, and then the code development platform determines the code of the target code checker in response to the user's selection operation of the target code checker from the at least one candidate code checker.
[0010] The method supports users to input positive example code snippets and negative example code snippets, and assists in generating code for the code checker through indication information related to the positive example code snippet or the negative example code snippet (for example, annotation information for the positive and negative example code snippets or difference information of the positive and negative example code snippets). Compared with traditional search methods, this method narrows the search scope through indication information, and focuses on parameters, parameter types, etc. associated with the indication information in the positive and negative example code snippets to generate the code checker, so that the generated code checker can not only accurately and efficiently distinguish between positive and negative examples, conform to user intentions, and meet user needs, but also improve the development efficiency of the code checker and reduce the development difficulty and development cost of the code checker.
[0011] In some possible implementations, the code development platform can receive annotation information of the first code snippet or the second code snippet marked by the user through the code editing interface, and / or analyze the first code snippet and the second code snippet to obtain difference information between the first code snippet and the second code snippet.
[0012] In this method, users can annotate code snippets, and the code development platform can perform difference analysis on the code snippets, thereby obtaining indication information related to the code snippets. When generating a code checker, attention is paid to the indication information, so that the generated code checker is close to the user's intention.
[0013] In some possible implementations, the annotation information is used to annotate at least one of the following: a function name, a function parameter, and an operator in a judgment statement. This allows the code development platform to focus on content related to the function name, function parameters, or operators in the judgment statement when generating a code checker.
[0014] In some possible implementations, the code development platform may obtain annotation information in response to a user selecting or highlighting the first code snippet or the second code snippet through a code editing interface, wherein the annotation information may be used to indicate the code selected or highlighted by the user.
[0015] This method supports users to mark code snippets through the code editing interface, such as selecting or highlighting operations. In this way, users can mark the information that needs attention generated by the code checker through the interactive interface.
[0016] In some possible implementations, the code development platform can obtain the code checker syntax based on the code checker framework, then parse the code checker syntax to obtain the basic information required to generate a candidate code checker. In this way, the code development platform can generate code for at least one candidate code checker based on the instruction information and the basic information required to generate the candidate code checker, ensuring that the candidate code checker complies with the code checker framework and development specifications.
[0017] In some possible implementations, the code development platform may determine the corrected code as the code of the target code checker in response to a user's correction operation on the code of the target code checker.
[0018] In this method, the user can modify the code of the target code checker. For example, when the code of the target code checker is close to the user's requirements but does not fully meet the user's requirements, the user can modify the code of the target code checker so that the corrected code of the target code checker meets the user's requirements.
[0019] In some possible implementations, when the code of at least one candidate code checker does not meet the requirements, the code development platform may receive a code snippet newly added by the user, wherein the newly added code snippet may be used to generate the code of a new candidate code checker.
[0020] This method supports users to supplement code snippets. For example, when the codes of the candidate code checkers do not meet the user requirements and are significantly different from the user requirements, the user can instruct the code development platform to generate new candidate code checkers by adding new code snippets, thereby improving the accuracy of the generated code checkers.
[0021] In some possible implementations, the code development platform may verify the candidate code checkers based on the first code snippet and the second code snippet, and determine the code of the target code checker in response to a user selecting a candidate code checker that has passed the verification.
[0022] In this method, the code snippet can be verified using the candidate code checker, thereby ensuring that the generated code checker can correctly check the code and guaranteeing the accuracy of the code checker.
[0023] In some possible implementations, the code development platform can be logically divided into three layers: a framework layer, a code development layer, and a user layer. The framework layer can be used to analyze code snippets and code checker syntax, obtain the necessary elements for generating the code checker, and provide verification capabilities. The code development layer can use the information provided by the framework layer to generate the specific logic of the code checker. The user layer can display the code of the code checker to users, and users can also provide positive and negative example code snippets and annotation information through the user layer to indicate the generation direction of the code checker.
[0024] In a second aspect, the present application provides a code development platform, which is used to generate code for a code checker, and the code development platform includes:
[0025] An interactive module is configured to receive a first code snippet and a second code snippet input by a user, wherein the first code snippet is a code snippet that fails the code checker, and the second code snippet is a code snippet that passes the code checker;
[0026] an acquisition module, configured to acquire indication information related to the first code snippet or the second code snippet, the indication information comprising at least one of the following: annotation information of the first code snippet or the second code snippet, and difference information between the first code snippet and the second code snippet;
[0027] a generating module, configured to generate code of at least one candidate code checker according to the indication information;
[0028] The determining module is configured to determine a code of the target code checker in response to the user selecting the target code checker from the at least one candidate code checker.
[0029] In some possible implementations, the acquisition module is specifically configured to:
[0030] receiving annotation information of the first code snippet or the second code snippet by the user through a code editing interface; and / or,
[0031] The first code snippet and the second code snippet are analyzed to obtain difference information between the first code snippet and the second code snippet.
[0032] In some possible implementations, the annotation information is used to annotate at least one of the following:
[0033] Function names, function parameters, and operators in judgment statements.
[0034] In some possible implementations, the acquisition module is specifically configured to:
[0035] In response to the user selecting or highlighting the first code snippet or the second code snippet through the code editing interface, the annotation information is acquired, where the annotation information is used to indicate the code selected or highlighted by the user.
[0036] In some possible implementations, the determining module is specifically configured to:
[0037] In response to the user's correction operation on the code of the target code checker, the corrected code is determined as the code of the target code checker.
[0038] In some possible implementations, when the code of the at least one candidate code checker does not meet the requirements, the interaction module is further configured to:
[0039] A code snippet newly added by the user is received, where the newly added code snippet is used to generate code for a new candidate code checker.
[0040] In some possible implementations, the code development platform further includes:
[0041] a verification module, configured to verify the candidate code checker based on the first code snippet and the second code snippet;
[0042] The determining module is specifically configured to:
[0043] In response to the user selecting a candidate code checker that has passed verification, the code of the target code checker is determined.
[0044] In a third aspect, the present application provides a computing device cluster. The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is configured to execute instructions stored in the at least one memory, so that the computing device or computing device cluster performs the code checker generation method described in the first aspect or any implementation of the first aspect.
[0045] In a fourth aspect, the present application provides a computer-readable storage medium storing instructions, wherein the instructions instruct a computing device or a computing device cluster to execute the code checker generation method described in the first aspect or any one of the implementations of the first aspect.
[0046] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computing device or a computing device cluster, enables the computing device or computing device cluster to execute the code checker generation method described in the first aspect or any one of the implementations of the first aspect.
[0047] Based on the implementation methods provided in the above aspects, this application can also be further combined to provide more implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical methods of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments.
[0049] FIG1 is a flow chart of a method for generating a code checker based on search provided by an embodiment of the present application;
[0050] FIG2 is a schematic diagram of the architecture of a code development platform provided in an embodiment of the present application;
[0051] FIG3 is a flow chart of a method for generating a code checker according to an embodiment of the present application;
[0052] FIG4 is a schematic diagram of an application scenario of a code checker generation method provided by an embodiment of the present application;
[0053] FIG5 is a schematic diagram of a code editing interface provided in an embodiment of the present application;
[0054] FIG6 is a schematic diagram of a code checker code provided in an embodiment of the present application;
[0055] FIG7 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0056] FIG8 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;
[0057] FIG9 is a schematic diagram of the structure of another computing device cluster provided in an embodiment of the present application;
[0058] FIG10 is a schematic diagram of the structure of another computer cluster provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] The terms "first" and "second" in the embodiments of this application are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of technical features indicated. Therefore, features specified as "first" or "second" may explicitly or implicitly include one or more of the features.
[0060] First, some technical terms involved in the embodiments of this application are introduced.
[0061] Static analysis, also known as static code analysis or static program analysis, verifies code compliance, security, reliability, maintainability, and other criteria without running the code. Static analysis helps identify code defects and improve code quality, making it widely used in software testing.
[0062] A typical application of static analysis technology is a code checker (also referred to as a checker). Specifically, a code checker is usually built on an underlying framework that parses the code under test (for example, the source code of the software under test) and stores the code in a specific data structure (for example, an abstract syntax tree or a control flow graph). In this way, the upper-level code checker can use pre-set logic based on the above data structure to check the code under test, determine whether the code under test has errors or problems, and provide feedback to the developer so that the errors or problems can be fixed before the code is actually run.
[0063] Considering that developing a code checker requires developers to have rich development experience, and at the same time, they also need to be familiar with the underlying framework on which the code checker is based, the specific structure of the checked code, and the characteristics of the programming language, the code checker can be developed using a domain specific language (DSL). Among them, a domain specific language refers to a computer language for a specific application field. For example, a domain specific language may include Hyper Text Markup Language (HTML) for displaying web pages. For another example, a domain specific language may include Maven for compilation configuration. In this way, developers do not need to be proficient in complex underlying frameworks, but still require a certain learning cost to develop code checkers.
[0064] According to software engineering standards, software testing is required after software development is completed. When testing software with a code checker, the test input can be a project that includes source files and other auxiliary information. The source files can be written in the language to be tested and can include erroneous code snippets. These erroneous code snippets can be specially annotated to facilitate testing and test result verification by the code checker. Other auxiliary information can include compilation configuration scripts, project configuration information, and more.
[0065] Software testing can be used to verify the functional correctness of code checkers. Furthermore, it can also be used to identify check scenarios (for example, identifying code that is particularly prone to errors or problems), thereby facilitating developers to write corresponding code checkers based on the check scenarios identified in software testing. In other words, test cases facilitate the generation of code checkers.
[0066] Generating code based on the input and output of test cases (also known as examples) falls under the purview of code generation. Code generation refers to the use of auxiliary information or input information (such as a set of expected input and output examples provided by the user) to automatically or semi-automatically generate executable code.
[0067] Code generation techniques typically generate corresponding code based on a search. This process involves traversing all possible code to perform the search, pruning to eliminate code that doesn't meet the requirements to accelerate the search, and finally finding code that meets all input-output examples. During code generation, users can continuously add input-output examples or manually modify the generated code to better meet their needs.
[0068] The aforementioned search-based code generation technology can be applied to spreadsheet software to generate code for processing data. Specifically, users can place the data to be processed and the desired results corresponding to a portion of the data to be processed in cells. The search-based code generation generates the corresponding data processing code. This generates the corresponding data processing results for the remaining data that does not produce the desired results.
[0069] Search-based code generation technology can also be used to generate code checkers. Referring to the flowchart of a search-based code checker generation method shown in FIG1 , on the one hand, by a user writing positive and negative example code snippets, a positive example code snippet and a negative example code snippet can be obtained, for example, positive example code snippet 1 to positive example code snippet n and negative example code snippet 1 to negative example code snippet n. On the other hand, based on the syntax of the code checker, a code checker can be generated based on a search to obtain a candidate code checker. Next, the candidate code checker is tested based on the positive and negative example code snippets. If the candidate code checker does not meet all the positive and negative example code snippets, the process returns to the step of generating the code checker based on the search. If the candidate code checker meets all the positive and negative example code snippets, it is determined whether the candidate code checker meets the user's expectations. If the candidate code checker meets the user's expectations, the candidate code checker can be used as the final code checker. If the candidate code checker does not meet the user's expectations, the user can choose whether to manually modify the code checker. If the user does not manually modify the code checker, the positive and negative example code snippets can be added. If the user manually modifies the code modifier, the code checker can be obtained based on the modified content.
[0070] There are many candidate code checkers obtained through search that can successfully check positive and negative examples in the code. The accuracy of the candidate code checkers searched in the early stage is low, and it is difficult to meet user needs. Users are required to continuously supplement code positive and negative example snippets, or users manually modify the code checker, which increases the difficulty and cost of developing the code checker.
[0071] In view of this, the present application provides a code checker generation method. The method can be executed by a code development platform, which is used to generate the code of the code checker. The code development platform can be a software system, which can be an independent software, such as an integrated development environment (IDE) deployed on the cloud or locally, and the software system can also be integrated into other software in the form of a plug-in, such as integrated into a code inspection engine. The software system can be deployed on a computing device cluster, and the computing device cluster executes the program code of the software system, thereby executing the code checker generation method of the present application. The code development platform can also be a hardware system with a code checker generation function, which executes the code checker generation method of the present application when the hardware system is running.
[0072] Specifically, the code development platform receives a first code snippet and a second code snippet input by a user, wherein the first code snippet is a code snippet that fails the code checker check, and the second code snippet is a code snippet that passes the code checker check, and then obtains indication information related to the first code snippet or the second code snippet, and generates code for at least one candidate code checker based on the indication information, wherein the indication information includes at least one of annotation information for the first code snippet or the second code snippet and difference information between the first code snippet and the second code snippet, and then the code development platform determines the code of the target code checker in response to the user's selection operation of the target code checker from the at least one candidate code checker.
[0073] The method supports users to input positive example code snippets and negative example code snippets, and assists in generating code for the code checker through indication information related to the positive example code snippet or the negative example code snippet (for example, annotation information for the positive and negative example code snippets or difference information of the positive and negative example code snippets). Compared with traditional search methods, this method narrows the search scope through indication information, and focuses on parameters, parameter types, etc. associated with the indication information in the positive and negative example code snippets to generate the code checker, so that the generated code checker can not only accurately and efficiently distinguish between positive and negative examples, conform to user intentions, and meet user needs, but also improve the development efficiency of the code checker and reduce the development difficulty and development cost of the code checker.
[0074] In order to make the technical solution of the present application clearer and easier to understand, the system architecture of the present application is introduced below with reference to the accompanying drawings.
[0075] 2 , the code development platform 20 includes an interaction module 202, an acquisition module 204, a generation module 206, and a determination module 208. The functions of each module are described below.
[0076] The interaction module 202 is configured to receive a first code snippet and a second code snippet input by a user. The first code snippet is a code snippet that fails a code checker check, and the second code snippet is a code snippet that passes a code checker check. The first code snippet and the second code snippet may also be collectively referred to as positive and negative example code snippets. The interaction module 202 may receive the code snippet input by the user through a code editing interface in an interaction interface. The interaction interface may be a graphical user interface (GUI) or a command user interface (CUI).
[0077] The acquisition module 204 is configured to acquire indication information related to the first code snippet or the second code snippet. In some embodiments, the indication information may include annotation information for the first code snippet or the second code snippet, and the annotation information may be acquired in response to a user selection or highlighting operation. In other embodiments, the indication information may include difference information between the first code snippet and the second code snippet, and the difference information may be acquired by analyzing the first code snippet and the second code snippet.
[0078] The generation module 206 is configured to generate code for at least one candidate code checker based on the instruction information. In some possible implementations, the code development platform 20 may further include a parsing module 205, which is configured to parse the code checker syntax to obtain basic information required to generate the code checker, including but not limited to syntax descriptions, syntax conventions, and syntax structures. For example, the parsing module 205 may obtain the code checker syntax based on the framework of the code checker to be generated. In this way, the generation module 206 can generate code for at least one candidate code checker, provided that the code complies with the framework and development specifications of the code checker.
[0079] The determination module 208 is configured to determine the code of the target code checker in response to a user selecting a target code checker from at least one candidate code checker. In some embodiments, the determination module 208 may determine the corrected code as the code of the target code checker in response to a user correcting the code of the target code checker. In other embodiments, the code development platform 20 may further include a verification module 209 configured to verify at least one candidate code checker. The determination module 208 may determine the code of the target code checker in response to a user selecting a candidate code checker that has passed verification.
[0080] The code development platform 20 of the embodiment of the present application can be logically divided into three layers, including a framework layer, a code development layer and a user layer from bottom to top. The framework layer includes the above-mentioned parsing module 205 and the verification module 209, which is the basis for the generation of the code checker. The framework layer obtains various necessary elements for generating the code checker by analyzing the positive and negative example code snippets and the code checker syntax. The framework layer also provides verification capabilities to ensure that the generated code checker can correctly check the positive and negative example code snippets. The code development layer includes the above-mentioned acquisition module 204, generation module 206 and determination module 208. The code development layer uses the information provided by the framework layer to generate the specific logic of the code checker, and displays the code of the code checker to the user through the user layer. The user can also provide positive and negative example code snippets and annotation information through the user layer to indicate the generation direction of the code checker.
[0081] Based on the above-mentioned code development platform 20 provided in the embodiment of the present application, the embodiment of the present application also provides a code checker generation method. The code checker generation of the embodiment of the present application is described in detail below with reference to the accompanying drawings.
[0082] Referring to the flowchart of the code checker generation method shown in FIG3 , the method includes the following steps:
[0083] S302: The code development platform 20 receives a first code snippet and a second code snippet input by a user.
[0084] The code development platform 20 can be used to generate code for a code checker, a functional module that detects potential problems in input code based on checking rules. Given that a code checker can detect potential problems or errors in code, the code development platform 20 can receive a first code snippet and a second code snippet input by a user, thereby subsequently identifying the user's code checker generation requirements based on these code snippets and generating code for the code checker.
[0085] Among them, the first code snippet can be a code snippet that fails the code checker, for example, a code snippet that outputs a warning message after being input into the code checker. In other words, the first code snippet is a code snippet that contains an error and the code checker should detect the error. Therefore, the first code snippet can also be called a positive example code snippet.
[0086] Similarly, the second code snippet can be a code snippet that passes the code checker check, for example, a code snippet that, after being input into the code checker, the code checker outputs normal code information. In other words, the second code snippet is a code snippet that does not contain errors and the code checker should not detect errors. Therefore, the second code snippet can also be called a counterexample code snippet. The first code snippet and the second code snippet can also be collectively referred to as positive and negative example code snippets.
[0087] In specific implementation, the code development platform 20 can present a code editing interface to the user, which can be a GUI or a CUI. The user can input positive example code snippets and negative example code snippets through the GUI or CUI, and the code development platform 20 can receive the above positive example code snippets and negative example code snippets.
[0088] It should be noted that the embodiments of the present application do not limit the types of programming languages that the generated code checker can recognize. In other words, the code checker generated using the method in the embodiments of the present application can be used to check code written in general programming languages, including but not limited to C, C++, Java, SQL, etc. Therefore, the embodiments of the present application do not limit the types of programming languages of the first code snippet and the second code snippet. The first code snippet and the second code snippet can be code snippets written in general programming languages.
[0089] S304: The code development platform 20 obtains indication information related to the first code segment or the second code segment.
[0090] The indication information can be used to indicate information that the code checker needs to pay attention to during generation. Specifically, the indication information can include at least one of annotation information for the first code snippet or the second code snippet, and difference information between the first code snippet and the second code snippet.
[0091] The code development platform 20 can receive annotation information of the first code snippet or the second code snippet from the user through the code editing interface. The annotation information can be used to indicate the portion that the user has instructed the code development platform 20 to focus on. The annotation information can be used to annotate at least one of a function name, a function parameter, and an operator in a judgment statement.
[0092] When the annotation information is used to annotate a function name, it indicates that the user instructs the code development platform 20 to pay attention to the function name appearing in the code, for example, the user's requirement is to generate a code checker for matching a specific function name. When the annotation information is used to annotate a function parameter, it indicates that the user instructs the code development platform 20 to pay attention to the function parameter appearing in the code, for example, the user's requirement is to generate a code checker for matching a specific function type. When the annotation information is used to annotate an operator in a judgment statement, it indicates that the user instructs the code development platform 20 to pay attention to the operator in the judgment statement, for example, the user's requirement is to generate a code checker for checking whether the operator in the judgment statement is correct (such as whether the "==" in the "if a==b" statement is correct).
[0093] In a specific implementation, the code development platform 20 can obtain annotation information in response to a user selecting or highlighting the first or second code snippet through the code editing interface. This annotation information can be used to indicate the code selected or highlighted by the user. In this way, the code development platform 20 supports users in annotating code snippets by selecting or highlighting them, thereby focusing on this annotation information during the code checker generation process, so that the generated code checker is closer to the user's intention.
[0094] In other embodiments, the code development platform 20 can analyze the first code snippet and the second code snippet to obtain difference information between the first code snippet and the second code snippet. The difference information is used to represent the difference between the first code snippet and the second code snippet. In this way, the code development platform 20 can focus on this difference information when generating a code checker, enabling the generated code checker to efficiently distinguish between positive and negative examples, thereby improving the code checker's checking speed.
[0095] S306: The code development platform 20 generates code for at least one candidate code checker according to the instruction information.
[0096] Specifically, the code development platform 20 may first obtain the code checker grammar based on the code checker framework, and then parse the code checker grammar to obtain basic information required to generate candidate code checkers, such as grammatical description, grammatical rules, grammatical structure, etc.
[0097] In this way, the code development platform 20 can generate the code of at least one candidate code checker based on the instruction information and the basic information required to generate the candidate code checker, ensuring that the candidate code checker complies with the framework and development specifications of the code checker.
[0098] S308 : The code development platform 20 determines the code of the target code checker in response to the user's selection of the target code checker from the at least one candidate code checker.
[0099] Specifically, the code development platform 20 can present the code of at least one candidate code checker to the user, for example, by presenting the code of at least one candidate code checker to the user through a code editing interface. In this way, the user can select a target code checker that meets his or her needs from the candidate code checkers, thereby determining the code of the target code checker.
[0100] In some embodiments, the code development platform 20 can, in response to a user's correction operation on the target code checker's code, determine the corrected code as the target code checker's code. In other words, the code development platform 20 supports the user's modification of the target code checker's code. For example, when the target code checker's code is close to the user's requirements but does not fully meet the user's requirements, the user can modify the target code checker's code so that the modified target code checker's code meets the user's requirements.
[0101] In other embodiments, when the code of at least one candidate code checker does not meet the requirements, the code development platform 20 can receive a new code snippet added by the user. The newly added code snippet is used to generate the code of a new candidate code checker. In other words, the code development platform supports users to supplement the code snippet. For example, when the codes of the candidate code checkers do not meet the user's requirements, and the gap with the user's requirements is large, and it is difficult to modify the code of the candidate code checker through a small correction, the user can add a new code snippet. In this way, the code development platform 20 can generate the code of the new candidate code checker based on the newly added code snippet, and then calibrate the code of the code checker through the code snippet supplemented by the user, thereby improving the accuracy of the generated code checker.
[0102] It should be noted that users can also mark newly added code snippets. The specific process is similar to the introduction in the previous article and will not be repeated here.
[0103] In some other possible implementations, the code development platform 20 can also verify the candidate code checker based on the first code snippet and the second code snippet. In this way, the code development platform 20 can determine the code of the target code checker in response to the user's selection operation of the verified candidate code checker.
[0104] In specific implementation, the code development platform 20 can input the first code snippet and the second code snippet into the candidate code checker and obtain the inspection result output by the candidate code checker. When the inspection result corresponding to the first code snippet is failure to check, and the inspection result corresponding to the second code snippet is passing to check, it indicates that the candidate code checker can correctly check the positive and negative example code snippets, and the candidate code checker passes the verification; otherwise, the candidate code checker fails the verification.
[0105] Furthermore, if the indication information related to the first code snippet or the second code snippet includes annotation information or difference information, the code development platform 20 can also further verify the candidate code checker based on the annotation information or the difference information, thereby ensuring that the code checker can provide inspection capabilities for the annotation information or the difference information.
[0106] Based on the above description, the code checker generation method provided in the embodiment of the present application receives positive code snippets and negative code snippets input by the user, obtains indication information related to the positive code snippet or the negative code snippet, and then uses the indication information to generate the code of at least one candidate code checker, and then determines the code of the code checker.
[0107] This method assists in generating code for a code checker through indication information related to positive example code snippets or negative example code snippets (for example, annotation information for positive and negative example code snippets or difference information for positive and negative example code snippets), thereby effectively narrowing the search scope and making the generated code checker more accurate and more in line with user intentions. Compared with traditional search-based code generation methods, this method can reduce the number of times users modify the code or supplement the code snippets for the generated code checker, thereby improving the development efficiency of the code checker.
[0108] Next, the code checker generation method of this application is introduced in conjunction with a specific application scenario.
[0109] Referring to the application scenario diagram of a code checker generation method shown in Figure 4, the code development platform 20 can receive positive and negative example code snippets written and annotated by users, such as positive example code snippet 1 to positive example code snippet n and negative example code snippet 1 to negative example code snippet n. Then, the code development platform 20 can obtain annotation information based on the annotations in the positive and negative example code snippets, and perform difference analysis on the positive and negative example code snippets to obtain difference information.
[0110] Furthermore, the code development platform 20 can generate a candidate code checker based on the code checker syntax, the acquired annotation information and the difference information, and perform test result verification on the candidate code checker based on the positive and negative example code snippets. When the candidate code checker fails the verification, the code development platform 20 can return to the step of generating the code checker. When the candidate code checker passes the verification, the code development platform 20 can further determine whether the candidate code checker meets the user's expectations. When the candidate code checker meets the user's expectations, the code development platform 20 can respond to the user's selection of the target code checker in the candidate code checker and determine the code of the target code checker. When the candidate code checker does not meet the user's expectations, the user can choose whether to manually modify the code checker. If the user does not correct the candidate code checker, the code development platform 20 can receive the positive and negative example code snippets supplemented by the user and continue to generate the code of the candidate code checker. If the user manually modifies the code modifier, the code development platform 20 can obtain the target code checker based on the modified content.
[0111] In some possible implementations, the code development platform 20 can receive positive and negative example code snippets input by the user through a code editing interface and present the generated candidate code checker codes to the user. Referring to FIG5 , a schematic diagram of a code editing interface is shown. The code editing interface 50 includes a code snippet input area 52 and a candidate code checker code presentation area 54.
[0112] Specifically, the user can input the positive example code snippet and the negative example code snippet through the multiple code input boxes in the code snippet input area 52. In some embodiments, the multiple code input boxes can be used to input the positive example code snippet and the negative example code snippet respectively. For example, the user can trigger the "+" in the code input box to input the positive example code snippet or the negative example code snippet, or the user can drag and drop the positive example code snippet or the negative example code snippet into the code input box.
[0113] At the same time, users can also annotate the input positive example code snippet or counterexample code snippet through the code input box, for example, by selecting or highlighting the input positive example code snippet or counterexample code snippet. Furthermore, the code input box can also display the difference information between the positive example code snippet and the counterexample code snippet to the user. In this way, the code input box can display the annotated information or difference information to the user in different display methods, for example, using different colors, different fonts, and different backgrounds to display the annotated information or difference information to the user.
[0114] The candidate code checker code presentation area 54 can present the generated code of at least one candidate code checker to the user. For example, the candidate code checker code presentation area 54 can include multiple code display boxes, each of which is used to display the code of the generated candidate code checker. In this way, the user can select at least one candidate code checker or correct the code of the selected candidate code checker to determine the code of the target code checker.
[0115] It should be noted that the code editing interface 50 can be an interactive interface on the IDE side or an interactive interface on the web page side, and the embodiment of the present application does not limit this.
[0116] For ease of understanding, the following example illustrates the process of generating a code checker. As shown in Figure 6, the user's requirement is to generate a code checker for matching function declaration nodes of a specific form. When the user only inputs the counterexample code snippet 1 and the positive example code snippet 1, and does not annotate the positive and negative example code snippets, the code checker code generated by the code development platform 20 is code checker code 1, which is used to match functions named "calculate". Obviously, the above code checker does not match the user's requirement.
[0117] Furthermore, the user annotates "String" in counterexample code snippet 1. The code development platform 20 uses the annotated counterexample code snippet 1 and the positive example code snippet 1 to generate a code checker code 2, which is used to match functions whose first parameter is of type "String". At this point, the code checker still does not match the user's requirements. However, compared to the unannotated code checker code 1, the generated code checker is more in line with the user's intention because it incorporates the annotation information.
[0118] Furthermore, the user adds positive example code snippet 2. The code development platform 20 uses the annotated negative example code snippet 1, positive example code snippet 1, and positive example code snippet 2 to generate a code checker code, code checker code 3. This code checker is used to match functions whose first parameter is a "String" type and has only one parameter. At this point, the code checker matches the user's needs, achieving efficient code checker generation.
[0119] Based on the code checker generation method of the aforementioned embodiment, the present application embodiment further provides a code development platform 20 as described above. The code development platform 20 is introduced below with reference to the accompanying drawings.
[0120] 2 , the code development platform 20 is used to generate code for a code checker. The code development platform 20 includes:
[0121] Interaction module 202, configured to receive a first code snippet and a second code snippet input by a user, wherein the first code snippet is a code snippet that fails the code checker, and the second code snippet is a code snippet that passes the code checker;
[0122] An acquisition module 204 is configured to acquire indication information related to the first code snippet or the second code snippet, wherein the indication information includes at least one of the following: annotation information of the first code snippet or the second code snippet, and difference information between the first code snippet and the second code snippet;
[0123] A generating module 206, configured to generate code of at least one candidate code checker according to the indication information;
[0124] The determination module 208 is configured to determine the code of the target code checker in response to a user selecting a target code checker from at least one candidate code checker.
[0125] The interaction module 202, acquisition module 204, generation module 206, and determination module 208 described above can be implemented as hardware modules or software modules. Specifically, the interaction module 202, acquisition module 204, generation module 206, and determination module 208 can be implemented as a computing device or a computing engine on the computing device. The following description will use the acquisition module 204 as an example.
[0126] When implemented via software, acquisition module 204 can be an application or application module, such as a computing engine, running on a computing device or computing device cluster. This application can be provided to users as a virtualized service. Virtualized services may include virtual machine (VM) services, bare metal server (BMS) services, and container services. VM services can be services that use virtualization technology to create a virtual machine (VM) resource pool on multiple physical hosts (such as computing devices) to provide users with VMs on demand. BMS services can be services that create a virtual BMS resource pool on multiple physical hosts to provide users with BMSs on demand. Container services can be services that create a virtual container resource pool on multiple physical hosts to provide users with containers on demand. A VM is a simulated virtual computer, or logically a single computer. BMS is a scalable, high-performance computing service with computing performance comparable to traditional physical machines and secure physical isolation. Containers are a kernel virtualization technology that provides lightweight virtualization to isolate user space, processes, and resources. It should be understood that the VM service, BMS service and container service in the above-mentioned virtualization services are merely specific examples. In actual applications, the virtualization service may also be other lightweight or heavyweight virtualization services, which are not specifically limited here.
[0127] When implemented in hardware, the acquisition module 204 may include at least one computing device, such as a server. Alternatively, the construction module 224 may be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0128] In some possible implementations, the acquisition module 204 is specifically configured to:
[0129] Receiving annotation information of the first code snippet or the second code snippet from a user through a code editing interface; and / or,
[0130] The first code segment and the second code segment are analyzed to obtain difference information between the first code segment and the second code segment.
[0131] In some possible implementations, the annotation information is used to annotate at least one of the following:
[0132] Function names, function parameters, and operators in judgment statements.
[0133] In some possible implementations, the acquisition module 204 is specifically configured to:
[0134] In response to a user selecting or highlighting the first code snippet or the second code snippet through the code editing interface, annotation information is acquired, wherein the annotation information is used to indicate the code selected or highlighted by the user.
[0135] In some possible implementations, the determining module 208 is specifically configured to:
[0136] In response to a correction operation of the code of the target code checker by the user, the corrected code is determined as the code of the target code checker.
[0137] In some possible implementations, when the code of at least one candidate code checker does not meet the requirements, the interaction module 202 is further configured to:
[0138] A code snippet newly added by a user is received, wherein the newly added code snippet is used to generate code for a new candidate code checker.
[0139] In some possible implementations, the code development platform 20 further includes:
[0140] A verification module 209, configured to verify the candidate code checker based on the first code snippet and the second code snippet;
[0141] The determination module 208 is specifically configured to:
[0142] In response to a user selecting a candidate code checker that has passed verification, a code of a target code checker is determined.
[0143] This application also provides a computing device 700. As shown in Figure 7, computing device 700 includes a bus 702, a processor 704, a memory 706, and a communication interface 708. Processor 704, memory 706, and communication interface 708 communicate with each other via bus 702. Computing device 700 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in computing device 700.
[0144] Bus 702 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, among others. Buses may be classified as address buses, data buses, control buses, and the like. For ease of illustration, FIG7 illustrates a single bus line, but this does not imply a single bus or type of bus. Bus 702 may include a path for transmitting information between various components of computing device 700 (e.g., memory 706, processor 704, and communication interface 708).
[0145] The processor 704 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0146] The memory 706 may include a volatile memory, such as a random access memory (RAM). The memory 706 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD). The memory 706 stores executable program code, and the processor 704 executes the executable program code to implement the aforementioned code checker generation method. Specifically, the memory 706 stores instructions for the code development platform 20 to execute the code checker generation method.
[0147] The communication interface 708 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 700 and other devices or a communication network.
[0148] Embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0149] As shown in Figure 8, the computing device cluster includes at least one computing device 700. The memory 706 of one or more computing devices 700 in the computing device cluster may store instructions for executing the code checker generation method on the same code development platform 20.
[0150] In some possible implementations, one or more computing devices 700 in the computing device cluster may also be used to execute some of the instructions of the code development platform 20 for executing the code checker generation method. In other words, the combination of one or more computing devices 700 may jointly execute the instructions of the code development platform 20 for executing the code checker generation method.
[0151] It should be noted that the memories 706 in different computing devices 700 in the computing device cluster may store different instructions for executing part of the functions of the code development platform 20 .
[0152] FIG9 illustrates a possible implementation. As shown in FIG9 , two computing devices 700A and 700B are connected via a communication interface 708. The memory in computing device 700A stores instructions for executing the functions of interaction module 202, acquisition module 204, generation module 206, and determination module 208. The memory in computing device 700B stores instructions for executing the functions of parsing module 205 and verification module 209. In other words, the memories 706 of computing devices 700A and 700B jointly store instructions for the code development platform 20 to execute the code checker generation method.
[0153] The connection method between the computing device clusters shown in Figure 9 can be considered to take into account the fact that the code development platform provided by this application is logically divided into a user layer, a code generation layer, and a framework layer. Therefore, it is considered that the functions implemented by the interaction module 202, the acquisition module 204, the generation module 206, and the determination module 208 are performed by the computing device 700A, and the functions implemented by the parsing module 205 and the verification module 209 are performed by the computing device 700B.
[0154] It should be understood that the functionality of the computing device 700A shown in FIG9 may also be implemented by multiple computing devices 700. Similarly, the functionality of the computing device 700B may also be implemented by multiple computing devices 700.
[0155] In some possible implementations, one or more computing devices in a computing device cluster may be connected via a network. The network may be a wide area network (WAN) or a local area network (LAN), etc. FIG. 10 illustrates a possible implementation. As shown in FIG. 10 , two computing devices 700C and 700D are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 706 in the computing device 700C stores instructions for executing the functions of the interaction module 202, the acquisition module 204, the generation module 206, and the determination module 208. Simultaneously, the memory 706 in the computing device 700D stores instructions for executing the functions of the parsing module 205 and the verification module 209.
[0156] The connection method between the computing device clusters shown in Figure 10 can be based on the fact that the code development platform provided by this application is logically divided into a user layer, a code generation layer, and a framework layer. Therefore, it is considered that the functions implemented by the interaction module 202, the acquisition module 204, the generation module 206, and the determination module 208 are performed by the computing device 700C, and the functions implemented by the parsing module 205 and the verification module 209 are performed by the computing device 700D. It should be understood that the functions of the computing device 700C shown in Figure 10 can also be performed by multiple computing devices 700. Similarly, the functions of the computing device 700D can also be performed by multiple computing devices 700.
[0157] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the above-mentioned method for generating a code checker applied to a code development platform.
[0158] The present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the code checker generation method described above.
[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A code checker generation method, It is characterized in that Applied to a code development platform, the code development platform is used to generate code for a code checker, the method comprises: Receive a first code snippet and a second code snippet input by a user, wherein the first code snippet is a code snippet that fails the code checker, and the second code snippet is a code snippet that passes the code checker; Acquire indication information related to the first code snippet or the second code snippet, where the indication information includes at least one of the following: annotation information of the first code snippet or the second code snippet, and difference information between the first code snippet and the second code snippet; generating code of at least one candidate code checker according to the indication information; In response to the user's selection of a target code checker from among the at least one candidate code checker, a code of the target code checker is determined.
2. The method according to claim 1, It is characterized in that The acquiring indication information related to the first code snippet or the second code snippet includes: receiving annotation information of the first code snippet or the second code snippet annotated by the user through a code editing interface; and / or, The first code snippet and the second code snippet are analyzed to obtain difference information between the first code snippet and the second code snippet.
3. The method according to claim 2, It is characterized in that The annotation information is used to mark at least one of the following: Function names, function parameters, and operators in judgment statements.
4. The method according to claim 2 or 3, It is characterized in that The receiving annotation information of the first code snippet or the second code snippet annotated by the user through the code editing interface includes: In response to the user selecting or highlighting the first code snippet or the second code snippet through the code editing interface, the annotation information is acquired, where the annotation information is used to indicate the code selected or highlighted by the user.
5. The method according to any one of claims 1 to 4, It is characterized in that The code for determining the target checker includes: In response to the user's correction operation on the code of the target code checker, the corrected code is determined as the code of the target code checker.
6. The method according to claim 5, It is characterized in that The method further comprises: When the code of at least one candidate code checker does not meet the requirements, a code snippet newly added by the user is received, and the newly added code snippet is used to generate a code of a new candidate code checker.
7. The method according to any one of claims 1 to 6, It is characterized in that The method further comprises: verifying the candidate code checker based on the first code snippet and the second code snippet; In response to the user selecting a target code checker from the at least one candidate code checker, determining a code of the target code checker includes: In response to the user's selection operation on a candidate code checker that has passed verification, the code of the target code checker is determined.
8. A code development platform, the code development platform is used to generate code for a code checker, the code development platform include: An interaction module is used to receive a first code snippet and a second code snippet input by a user, wherein the first code snippet is a code snippet that fails the code checker, and the second code snippet is a code snippet that passes the code checker; an acquisition module, configured to acquire indication information related to the first code snippet or the second code snippet, the indication information comprising at least one of the following: annotation information of the first code snippet or the second code snippet, and difference information between the first code snippet and the second code snippet; A generating module, configured to generate a code of at least one candidate code checker according to the indication information; The determination module is used to determine the code of the target code checker in response to the user's selection operation of the target code checker among the at least one candidate code checker.
9. The code development platform according to claim 8, It is characterized in that The acquisition module is specifically used for: receiving annotation information of the first code snippet or the second code snippet annotated by the user through a code editing interface; and / or, The first code snippet and the second code snippet are analyzed to obtain difference information between the first code snippet and the second code snippet.
10. The code development platform according to claim 9, It is characterized in that The annotation information is used to mark at least one of the following: Function names, function parameters, and operators in judgment statements.
11. The code development platform according to claim 9 or 10, It is characterized in that The acquisition module is specifically used for: In response to the user selecting or highlighting the first code snippet or the second code snippet through the code editing interface, the annotation information is acquired, where the annotation information is used to indicate the code selected or highlighted by the user.
12. The code development platform according to any one of claims 8 to 11, It is characterized in that The determination module is specifically used for: In response to the user's correction operation on the code of the target code checker, the corrected code is determined as the code of the target code checker.
13. The code development platform according to claim 12, It is characterized in that When the code of the at least one candidate code checker does not meet the requirements, the interaction module is further used to: A code snippet newly added by the user is received, where the newly added code snippet is used to generate a code of a new candidate code checker.
14. The code development platform according to any one of claims 8 to 13, It is characterized in that The code development platform also includes: a verification module, configured to verify the candidate code checker according to the first code snippet and the second code snippet; The determination module is specifically used for: In response to the user's selection operation on a candidate code checker that has passed verification, the code of the target code checker is determined.
15. A computing device cluster, It is characterized in that The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory, wherein the at least one memory stores computer-readable instructions; the at least one processor executes the computer-readable instructions so that the computing device cluster executes the method as described in any one of claims 1 to 7.
16. A computer-readable storage medium, It is characterized in that The method comprises computer-readable instructions; the computer-readable instructions are used to implement the method according to any one of claims 1 to 7.
17. A computer program product, It is characterized in that The method comprises computer-readable instructions; the computer-readable instructions are used to implement the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
System and method for generating compiler
CN101751281A
C program code standard checking device based on PRDL rule description language
CN106970819A
Automated intelligent contract code defect detection system and method
CN109063477A
Test case generation method and device
CN109213683A
Software testing automation management system and method
CN113032240A
