A code checking method, device, equipment and storage medium
By obtaining the source code file, its differential information and target storage path, the target code is checked in parallel, which solves the problem of the impact of locking operations in the existing technology, and realizes efficient code inspection.
Patent Information
- Application Number
- CN202510100994.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2045-01-22
AI Technical Summary
When performing parallel inspections of multiple object codes, locking operations are required to avoid read-write conflicts, resulting in reduced efficiency; at the same time, copying source code and creating new workspaces will also increase memory footprint and file read-write operations.
By obtaining the source code file and its corresponding differential information and target storage path, the target code is checked in parallel based on each differential information and source code file to avoid modification of the source code and reduce locking operations and memory usage.
It realizes that multiple object codes are checked in parallel without modifying the source code, improving the efficiency of code checking and avoiding locking operations and additional memory usage.
Smart Images

Figure CN119556938B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program development technology, and in particular to a code checking method, device, equipment and storage medium. Background Art
[0002] During program development, when a compiler converts a source code file into a file of another programming language, it needs to read one or more source code files and other compilation intermediate products. First, the compiler performs syntax analysis on the source code file to obtain the abstract syntax tree of the corresponding programming language, parses the compilation intermediate products and obtains information, and then performs code checking or compilation to generate other compilation intermediate products or final products and provide error feedback.
[0003] In actual application, source code modification may include multiple ways, and multiple independent modifications to a source code may form multiple target codes. It is also necessary to perform parallel quality checks on multiple target codes to screen the target codes and obtain ideal target codes. However, when performing parallel checks on check files formed by multiple target codes, if the source code is modified directly, the check files need to be locked to avoid read and write conflicts between the check files, and the locking operation will affect the efficiency of the check. If the source code is copied and a new workspace is created before checking with the modified file, additional memory usage and / or file read and write operations will be generated.
[0004] Therefore the prior art still needs to be improved and enhanced. Summary of the invention
[0005] The technical problem to be solved by the present application is to provide a code checking method, device, equipment and storage medium in view of the deficiencies in the prior art.
[0006] In order to solve the above technical problems, the first aspect of the present application provides a code checking method, which is applied to a compiler. The code checking method specifically includes:
[0007] Obtaining a source code file, a plurality of differential information corresponding to the source code file, and a target storage path corresponding to each differential information, wherein the target storage path is used to store the differential information, the target code corresponding to the differential information, and the code checking result corresponding to the target code;
[0008] Based on each differential information and the source code file, the target code corresponding to each differential information is checked in parallel to obtain a code checking result.
[0009] In the code checking method, the process of obtaining the plurality of differential information corresponding to the source code file and the target storage path corresponding to each differential information specifically includes:
[0010] receiving interactive information for a portion of source code fragments in the source code file;
[0011] Based on the interactive information, a plurality of differential information corresponding to the source code file and a unique identifier corresponding to the differential information are determined, wherein the differential information is used to represent the difference between the target code and some source code fragments in the source code file, and the unique identifier is used to determine the target storage path corresponding to the differential information.
[0012] The code checking method, wherein the step of determining the plurality of differential information corresponding to the source code file based on the interactive information comprises:
[0013] Sending the interaction information to the code generator multiple times, wherein the number of times the interaction information is sent is the same as the number of the difference information;
[0014] The content generated by the code generator each time based on the interactive information is received and differential information is determined to obtain a plurality of differential information corresponding to the source code file.
[0015] The code checking method, wherein the receiving the content generated by the code generator based on the interactive information each time and determining the differential information specifically comprises:
[0016] When the interactive information includes an instruction to generate a target code and / or an instruction to generate differential information corresponding to the target code, receiving the target code and / or differential information corresponding to the target code generated by the code generator based on the interactive information each time, so as to obtain a plurality of differential information corresponding to the source code file;
[0017] The target code is a code fragment generated by the code generator that is different from some source code fragments in the source code file, and the differential information is used to indicate the difference between the target code and some source code fragments in the source code file.
[0018] The code checking method, wherein the receiving the content generated by the code generator based on the interactive information each time and determining the differential information further comprises:
[0019] When the interactive information only includes the target code generation instruction, the difference content between the source code file and each target code is analyzed to determine the difference information of each target code relative to its corresponding source code fragment.
[0020] The code checking method, wherein the receiving the content generated by the code generator based on the interactive information each time and determining the differential information comprises:
[0021] When the interaction information includes a test instruction and an instruction for generating a target code and / or an instruction for generating differential information corresponding to the target code, controlling the code generator to obtain comment information in the source code file based on the interaction information;
[0022] Receive the target code generated by the code generator based on the annotation information and / or some differential information corresponding to the target code to obtain some differential information corresponding to the source code file, wherein the target code is the test code that satisfies the test instruction.
[0023] The code checking method, wherein receiving the content generated by the code generator each time based on the interactive information and determining the differential information, further comprises:
[0024] When the interactive information includes only the test instructions and the target code generation instructions, the difference content between the source code file and each target code is analyzed to determine the difference information of each target code relative to its corresponding source code segment.
[0025] The code checking method, wherein the step of performing parallel checking on the target code corresponding to each differential information based on each differential information and the source code file to obtain the code checking result specifically includes:
[0026] Determine in parallel the target code corresponding to each differential information based on each differential information;
[0027] Each target code is checked in parallel to obtain a code checking result.
[0028] The code checking method, wherein the step of performing parallel checking on each target code to obtain a code checking result specifically comprises:
[0029] Check whether the differential information corresponds to a test task;
[0030] When there is no corresponding test task, compile the target code to obtain a compilation result of the target code, and use the compilation result of the target code as a code checking result;
[0031] When there is a corresponding test task, the target code is compiled to obtain a compilation result of the target code and a testable file corresponding to the target code is output, the testable file is tested to obtain a test result, and the compilation result and the test result are used as code inspection results.
[0032] The code checking method, wherein each differential information corresponds to a compilation thread, the compilation threads corresponding to each differential information are executed in parallel, and the target code corresponding to each differential information is checked in parallel based on each differential information and the source code file to obtain a code checking result, wherein the code checking result corresponding to each differential information is stored according to the target storage path corresponding to each differential information.
[0033] A second aspect of the present application provides a code checking device, wherein the code checking device specifically includes:
[0034] An acquisition module, used to acquire a source code file, a plurality of differential information corresponding to the source code file, and a target storage path corresponding to each differential information, wherein the target storage path is used to store the differential information, the target code corresponding to the differential information, and the code checking result corresponding to the target code;
[0035] The checking module is used to perform parallel checking on the target code corresponding to each differential information based on each differential information and the source code file to obtain a code checking result.
[0036] A third aspect of the present application provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in any of the code checking methods described above.
[0037] A fourth aspect of the present application provides a terminal device, comprising: a processor and a memory;
[0038] The memory stores a computer-readable program executable by the processor;
[0039] When the processor executes the computer-readable program, the steps in any of the above-mentioned code checking methods are implemented.
[0040] Beneficial effects: Compared with the prior art, the present application provides a code checking method, device, equipment and storage medium, the method comprising obtaining a source code file, a plurality of differential information corresponding to the source code file and a target storage path corresponding to each differential information; based on each differential information and the source code file, performing a parallel check on the target code corresponding to each differential information to obtain a code checking result. When checking the target code formed based on the source code file, the present application only needs to obtain the source code file and the differential information without making any modification to the source code file, which enables programming operations to be performed concurrently without the need for locking operations, thereby improving the efficiency of code checking. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0042] Figure 1 A flowchart of a code checking method provided in an embodiment of the present application.
[0043] Figure 2 Schematic diagram of the process of obtaining differential information.
[0044] Figure 3 It is a flowchart of the specific implementation process of step S20.
[0045] Figure 4 This is a functional block diagram of a code checking device provided in an embodiment of the present application.
[0046] Figure 5 A functional block diagram of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0047] The embodiments of the present application provide a code checking method, device, equipment and storage medium. In order to make the purpose, technical solution and effect of the present application clearer and more specific, the present application is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described here are only used to explain the present application and are not used to limit the present application.
[0048] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0049] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.
[0050] It should be understood that the sequence numbers and sizes of the steps in this embodiment do not mean the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0051] After research, it was found that in program development, when the compiler converts the source code file into a file of another programming language, it needs to read one or more source code files and other intermediate products in the compilation process. First, the compiler performs syntax analysis on the source code file to obtain the abstract syntax tree of the corresponding programming language, parses the compilation intermediate product and obtains information, and then performs code correctness check or compilation work to generate other compilation intermediate products or final products and provide error feedback, etc., and then performs subsequent compilation work, testing work, etc., which are all defined as code checking processes in this application.
[0052] In some program development scenarios (for example, development scenarios using AI to generate code, code testing or document testing scenarios, etc.), multiple independent modifications to the existing source code will be generated, and the compiler will be used to check the correctness of the modified code files. However, when performing parallel code correctness checks through the compiler, three situations may occur: First, if the source code is modified directly, the check file formed after the modification needs to be locked to avoid read and write conflicts between check files, and the locking operation will affect the efficiency of the code correctness check, which not only reduces the efficiency of source code modification, but also reduces the performance of the compiler; second, after copying the source code and creating a new workspace, the code correctness check is performed with the modified file, which will generate additional memory usage and / or file read and write operations. Third, during code testing and document testing, complete test code needs to be generated according to the test instructions to complete the code check, and document testing is usually large in number and short in content, which may result in the creation of a large number of temporary files.
[0053] In order to solve the above problems, in an embodiment of the present application, a source code file, a number of differential information corresponding to the source code file, and a target storage path corresponding to each differential information are obtained; based on each differential information and the source code file, the target code corresponding to each differential information is checked in parallel to obtain a code check result. When checking the target code formed based on the source code file, the present application only needs to obtain the source code file and the differential information, and does not need to make any modifications to the source code file, so that no read conflict will occur, and there is no need to avoid read-write conflicts by locking or backing up the source code file code, thereby improving the efficiency of code checking.
[0054] The application content is further explained below through the description of embodiments in conjunction with the accompanying drawings.
[0055] This embodiment provides a code checking method, which is applied to a compiler, such as Figure 1 As shown, the method includes:
[0056] S10, obtaining a source code file, a number of differential information corresponding to the source code file, and a target storage path corresponding to each differential information.
[0057] Specifically, the source code file is a file formed by saving the code written in assembly language or high-level language. The source code file includes a code program, which can be in any programming language (the code program can be a full code or a partial code module). For example, the code program is a C language code program, a C++ language code program, a Java code program, a Python code program, and a JavaScript code program. In other words, the source code file can be a C language source code file, a C++ language source code file, a Java source code file, a Python source code file, a JavaScript source code file, etc. Among them, the source code file can be read by the compiler based on the root directory address, or it can be sent to the compiler by an external device (for example, a controller, etc.).
[0058] The differential information is used to indicate the difference between the target code and some source code snippets in the source code file, and may include the difference content between the target code and the source code snippet in the source code file. The target code may be determined based on the differential information and the source code snippet corresponding to the differential information. For example, the target code may be formed by inserting new code into the source code snippet based on the differential information, or replacing some code in the source code snippet based on the differential information, or removing some code in the source code snippet based on the differential information, etc. Of course, in practical applications, the differential information may also include other information, such as the content of the source code snippet, the code location information corresponding to the difference content, the source code file name and the target code file name, etc.
[0059] In one implementation, if Figure 2 As shown, the process of obtaining the differential information corresponding to the source code file specifically includes:
[0060] S11, receiving interactive information for some source code fragments in the source code file;
[0061] S12. Determine, based on the interactive information, a number of differential information corresponding to the source code file and a unique identifier corresponding to the differential information.
[0062] Specifically, the interaction information is obtained from interacting with the user. Based on the interaction information, a number of differential information corresponding to the source code file can be determined. Among them, the interaction information may include the root directory address of the source code file, source code segment information, and generation instructions. The root directory address is used to read the source code file, and the source code segment information is used to determine the source code segments that form the target code and the modification methods corresponding to the source code segments. For example, the source code segment information is to insert code, replace code, etc. at the specified code line. The generation instructions include target code generation instructions and / or generation instructions for the differential information corresponding to the target code. The interaction information may also include test instructions.
[0063] The unique identifier is used to determine the target storage path corresponding to the target code. The target storage path is used to store the differential information, the target code corresponding to the differential information, and the code inspection result corresponding to the target code. Among them, the differential information can be obtained by analyzing the target code and the source code file, can also be generated by a code generator, or can be specified by the user, etc. The unique identifier can be randomly generated for the differential information, can also be generated according to a preset rule, or can be specified by the user. Among them, the unique identifiers corresponding to each differential information are different from each other, etc.
[0064] In one implementation, the determining, based on the interaction information, a number of differential information corresponding to the source code file includes:
[0065] Sending the interaction information to the code generator multiple times;
[0066] Receiving the content generated by the code generator each time based on the interaction information and determining the differential information to obtain a number of differential information corresponding to the source code file.
[0067] Specifically, the code generator interacts with the compiler to receive interactive information, and generates content for determining differential information based on the interactive information. In addition, when it is necessary to obtain some differential information, the code generator can interact multiple times to send the interactive information to the code generator multiple times. After the code generator receives the interactive information each time, it will generate content for determining differential information based on the received interactive information. Among them, when the interactive information is sent to the code generator multiple times, the interactive information can be sent to the code generator multiple times in an asynchronous manner, or the interactive information can be sent to the code generator multiple times in a synchronous manner, and when the code generator receives the content generated based on the interactive information each time and determines the differential information, the content generated by the code generator based on the interactive information obtained by multiple transmissions can be received in a synchronous manner, or the content generated by the code generator based on the interactive information obtained by multiple transmissions can be received in an asynchronous manner. Of course, whether the content generated by the code generator based on the interactive information is received in a synchronous manner or an asynchronous manner, the code check can be performed asynchronously in the subsequent code check process.
[0068] When determining a number of differential information based on the code generator, the number of differential information to be determined can be obtained first, the number of times the interactive information is sent can be determined according to the number of differential information, and then the interactive information can be sent to the code generator in an asynchronous manner. The number of times generated can be determined by interaction with the user, or a preset default number, or determined according to actual needs. In the embodiment of the present application, the number of times generated is determined by interaction with the user, so that multiple target codes can be generated for the user according to the user's needs.
[0069] The code generator can be a large language model, or a code generator that can generate multiple independent code modifications, etc. In a typical implementation of the embodiment of the present application, a large language model is used as a code generator for description, but it should be noted that the description of the embodiment of the present application does not limit the code generator to a large language model. When the interactive information is sent to the large language model, a prompt word that can be understood by the large language model can be constructed based on the interactive information, and then the prompt word is sent to the large language model multiple times. Specifically, the prompt word is used to prompt the large language model to perform a generation task. Among them, the prompt word may include a prompt instruction and a prompt content, the prompt instruction is used to inform the generation task performed by the large language model, the prompt content is the specific task content of the generation task, the prompt word can be determined based on the generation instruction in the interactive information, and the prompt content can be determined based on the source code file and source code fragment information determined by the interactive information. For example, the generation instruction in the interactive information is a target code generation instruction, the prompt instruction in the prompt word is a target code generation instruction, and the prompt content is a source code file and source code fragment information. In addition, in practical applications, the prompt word may also include several generation examples, which are used as prior knowledge for the large language model to learn.
[0070] After obtaining the prompt words generated the number of times, the prompt words generated the number of times are sent to a large language model, and the large language model responds to the prompt words generated the number of times in parallel; the prompt words generated the number of times may also be sent to multiple large language models, and the multiple large language models respond to the prompt words generated the number of times in parallel, wherein the number of the multiple large language models may be equal to the number of times of generation, and each large language model responds to one prompt word; or the number of the multiple large language models may be less than the number of times of generation, and some of the multiple large language models may respond to multiple prompt words in parallel, etc.
[0071] Further, after receiving the interactive information, the code generator will perform a generation operation based on the generation instructions in the interactive information, so that the compiler can receive the content generated by the code generator each time based on the interactive information and determine the differential information, wherein the generation instructions may include target code generation instructions and / or generation instructions for differential information corresponding to the target code, the target code generation instructions are used to generate target code that modifies the source code, and the generation instructions for differential information corresponding to the target code generate differential information corresponding to the target code. In other words, the code generator generates target code for testing, generates target code that modifies the source code, generates target code and differential information corresponding to the target code, etc. based on the generation instructions in the interactive information, that is, the content generated by the code generator may include target code and / or differential information, wherein the target code is a code fragment generated by the code generator that is different from some source code fragments in the source code file.
[0072] In one implementation, the receiving the content generated by the code generator based on the interaction information each time and determining the difference information specifically includes:
[0073] When the interactive information includes instructions for generating target code and / or instructions for generating differential information corresponding to the target code, the target code and / or differential information corresponding to the target code generated by the code generator based on the interactive information each time is received to obtain a plurality of differential information corresponding to the source code file.
[0074] Specifically, the target code generation instruction is used to indicate that the code generator is required to generate the target code for modifying the source code, and the target code corresponding differential information generation instruction is used to indicate that the code generator is required to analyze the target code and the source code fragment corresponding to the target code to obtain differential information corresponding to the target code. In other words, when the interactive information includes the target code generation instruction, the target code generated by the code generator based on the interactive information each time will be received, and when the interactive information includes the target code corresponding differential information generation instruction, the differential information corresponding to the target code generated by the code generator based on the interactive information each time will be received.
[0075] When the interactive information only includes instructions for generating differential information corresponding to the target code, the differential information corresponding to the target code generated by the code generator can be directly used as differential information corresponding to the source code file to obtain a number of differential information corresponding to the source code file, and the target code corresponding to the differential information can be restored based on each differential information and the source code file. When the interactive information only includes instructions for generating target code, only the target code generated by the code generator can be received. When the interactive information includes instructions for generating target code and instructions for generating differential information corresponding to the target code, the code generator generates both the target code and the differential information corresponding to the target code.
[0076] Based on this, the code generator generates content based on the interactive information each time and determines the difference information, and also includes:
[0077] When the interactive information only includes the target code generation instruction, the difference content between the source code file and each target code is analyzed to determine the difference information of each target code relative to its corresponding source code fragment.
[0078] Specifically, when the interactive information only includes target code generation instructions, after receiving the target code generated by the code generator, the difference content between the source code file and each target code is analyzed to determine the differential information of each target code relative to its corresponding source code fragment. That is to say, after obtaining the target code, the target code is compared with its corresponding source code fragment to determine the difference content between the target code and its corresponding source code fragment, determine the differential content and differential operation, etc., to form the differential information of the target code relative to its corresponding source code fragment.
[0079] The following are examples of interactive information including only target code generation instructions, generation instructions including both target code generation instructions and differential information corresponding to the target code, and generation instructions including only differential information corresponding to the target code.
[0080] Example 1: Example where the interactive information only includes target code generation instructions
[0081] Assume that the source code snippet in the source code file is:
[0082] int main(){
[0083] printf("%d\n",1);
[0084] return 0;
[0085] }
[0086] Then, the target code generated by the code generator based on the source code snippet is:
[0087] ```c
[0088] #include<stdio.h>
[0089] int main(){
[0090] printf("%d\n",1);
[0091] return 0;
[0092] }
[0093] ```.
[0094] After receiving the target code, the target code and the source code fragment in the source code file are analyzed to obtain differential information, which is:
[0095] ---a / ac
[0096] +++b / ac
[0097] @@-1,3+1,4@@
[0098] +#include<stdio.h>
[0099] int main(){
[0100] printf("%d\n",1);
[0101] return 0;
[0102] }.
[0103] Example 2: The interactive information includes the target code generation instruction and the generation instruction of the differential information corresponding to the target code (-diff)
[0104] Assume that the source code snippet in the source code file is:
[0105] ```c
[0106] int main(){
[0107] printf("%d\n",1);
[0108] return 0;
[0109] }
[0110] ```
[0111] The code generator can generate the target code as in Example 1, and can also generate the following differential information corresponding to the target code in Example 1, wherein the differential information can be:
[0112] ---a / ac
[0113] +++b / ac
[0114] @@-1,3+1,4@@
[0115] +#include<stdio.h>
[0116] int main(){
[0117] printf("%d\n",1);
[0118] return 0;
[0119] }.
[0120] Example 3, referring to Example 2, when the interactive information only includes the differential information generation instruction corresponding to the target code, the code generator can only output the differential information without outputting the target code. It can be understood that the compiler can restore the target code corresponding to the differential information based on each differential information and the source code file.
[0121] In another implementation, the determining, based on the interaction information, the plurality of differential information corresponding to the source code file specifically includes:
[0122] When the interactive information includes a test instruction and a target code generation instruction, or a test instruction, a target code generation instruction, and an instruction for generating differential information corresponding to the target code, controlling the code generator to obtain comment information in the source code file based on the interactive information;
[0123] Receive the target code generated by the code generator based on the annotation information and / or some differential information corresponding to the target code to obtain some differential information corresponding to the source code file, wherein the target code is the test code that satisfies the test instruction.
[0124] Specifically, the interactive information also includes a test instruction, and the test instruction is used to indicate that the differential information corresponds to a test task, and the target code generation instruction needs to generate a target code that can complete the test task. It can be understood that the source code file includes one or more comments, and each comment includes a source code snippet. When performing a test task based on the comment information in the code, the differential information can be constructed based on the source code snippet in the comment, wherein the differential information can be constructed for some comments in the source code file, or for all comments in the source code file. When constructing differential information for the source code snippet in the comment, a complete test code can be generated based on the source code snippet according to the target code generation instruction to determine the target code corresponding to the source code snippet, and the target code is a test code that satisfies the test instruction, and then the differential information is determined based on the target code.
[0125] In one embodiment, when the interactive information includes test instructions, target code generation instructions, and generation instructions for differential information corresponding to the target code, the code generator generates the target code based on the annotation information, and generates a number of differential information corresponding to the target code to obtain a number of differential information corresponding to the source code file, and the target code is a test code that satisfies the test instructions.
[0126] In one embodiment, when the interactive information includes a test instruction and an instruction to generate differential information corresponding to the target code, the code generator generates a number of differential information corresponding to the target code based on the annotation information to obtain a number of differential information corresponding to the source code file, that is, the code generator does not output the target code. It is understandable that the compiler can restore the target code based on the differential information and other preset scripts, and the target code is the test code that satisfies the test instruction.
[0127] In another embodiment, when the interactive information only includes test instructions and target code generation instructions, the code generator only generates target code, and thus it is necessary to analyze the source code fragment and the target code to obtain the difference content corresponding to the target code each time the code generator receives the content generated based on the interactive information and determines the differential information, so as to determine the differential information of each target code relative to its corresponding source code fragment.
[0128] For example, assume that the interactive information includes test instructions and target code generation, and the comments in the source code file and the source code snippets in the comments are:
[0129] / / / ```rust
[0130] / / / let result = playground::add(2,2);
[0131] / / / assert_eq!(result,4);
[0132] / / / ```
[0133] pub fn add(i:i32,j:i32)->i32{
[0134] return i+j;
[0135] }
[0136] Then, the complete test code (i.e., target code) generated by the code generator for the source code snippet is:
[0137] #[test]
[0138] fn generated_test(){
[0139] let result=playground::add(2,2);
[0140] assert_eq!(result,4);
[0141] }.
[0142] After receiving the complete test code generated by the code generator based on the interactive information, differential information is constructed with the complete test code, that is, the complete test code is stored in the target storage path corresponding to the differential information.
[0143] The above are only a few specific implementation methods for obtaining differential information. In actual applications, other methods can also be used to obtain differential information. For example, the user can directly set the differential information, or the differential information can be obtained by the above method, and then the differential information is interacted with the user, and the user's adjustment operation on the differential information is received, and the differential information adjusted by the adjustment operation is used as the obtained differential information, etc. There is no specific limitation here, as long as the differential information described in the embodiment of the present application can be obtained.
[0144] In addition, after obtaining multiple differential information based on the source code file, in order to avoid conflicts when compiling based on the differential information, a unique identifier can be randomly generated for each differential information when obtaining each differential information. The unique identifier is used to determine the target storage path corresponding to the target code, and the unique identifiers corresponding to each differential information are different. In this way, when checking the target code corresponding to the differential information, the target code and the code inspection results corresponding to the target code can be stored according to the target storage path, avoiding the problem of conflicting inspection results when the differential information is checked in parallel.
[0145] S20. Based on each differential information and the source code file, a target code corresponding to each differential information is checked in parallel to obtain a code checking result.
[0146] Specifically, after obtaining the differential information and the source code file, the compiler can restore the target code corresponding to the differential information based on the differential information and the source code file, and then perform checks on the target code in parallel (such as whether it can pass syntax checks, whether it can pass type system checks, whether it can pass unit tests, whether it can pass integration tests, etc.). The compiler can be used to check the target code corresponding to each differential information, that is, the differential information and the source code file information can be sent to the compiler, and the compiler can be controlled to check the target code corresponding to each differential information based on each differential information and the source code file to obtain a code check result.
[0147] Based on this, Figure 3 As shown, based on each differential information and the source code file, performing parallel checking on the target code corresponding to each differential information to obtain the code checking result specifically includes:
[0148] S21, determining the target code corresponding to each differential information in parallel based on each differential information;
[0149] S22. Perform parallel checking on each target code to obtain a code checking result.
[0150] Specifically, the target code is determined when the differential information is determined, such as the target code generated by a code generator, or the target code can be restored according to the differential information, for example, by merging the differential content into the source code file, etc. To this end, when the target code corresponding to each differential information is determined in parallel based on each differential information, if the target code is obtained by modifying the source code fragment, the differential information can be merged into the source code fragment corresponding to the differential information to restore the target code, and when the target code is a test code determined based on comments and source code fragments in the comments, the target code can be restored by the differential information, the source code file and other preset scripts for testing, etc.
[0151] The code check result is obtained by the compiler performing a code check on the target code corresponding to the differential information, and when there are multiple differential information, the target codes corresponding to the multiple differential information will be checked in parallel, and the target code corresponding to each differential information and the code check result corresponding to the target code will be stored according to the target storage path. Among them, the target storage path may include a target address and a target file name, the target address is the storage address of the code check result of the target code corresponding to the difference information, and the target file name is the file name used to store the code check result. In other words, after determining that the target code corresponding to each differential information and the code check result formed by checking the target code are stored in the target file at the target address, the file name of the target file is the target file name, wherein the target address and / or the target file name carry a unique identifier corresponding to the differential information, so that the compiler can determine the target address and target file name corresponding to each differential information, thereby avoiding conflicts caused by responding to code checks of multiple target codes in parallel.
[0152] Furthermore, when performing parallel code checking on the target code corresponding to each differential information, a new compiling thread may be created for each differential information, and the code checking of the target code corresponding to each differential information may be controlled by the compiling thread. Based on this, the code checking method further includes:
[0153] Create a compilation thread for each differential information;
[0154] The compiling threads corresponding to each differential information are executed in parallel, so as to perform parallel checking on the target code corresponding to each differential information based on each differential information and the source code file to obtain a code checking result.
[0155] Specifically, the compilation thread is used to control the compiler to execute the code checking process corresponding to the differential information, so as to control the compiler to restore the target code based on the differential information and the source code file, and perform code checking on the target code, wherein the compilation thread corresponds to the differential information one-to-one, and by executing the compilation thread corresponding to each differential information in parallel, a parallel code checking process for multiple target codes can be realized.
[0156] For example: Assume the source code file ac is:
[0157] int main(){
[0158] printf("%d\n",1);
[0159] return 0;
[0160] }
[0161] The differential information is represented as " / tmp / 8a0c8ac2-ebe0-434c-a45e-59f25908d0db / diff", and its content is:
[0162] ---a / ac
[0163] +++b / ac
[0164] @@-1,3+1,4@@
[0165] +#include<stdio.h>
[0166] int main(){
[0167] printf("%d\n",1);
[0168] return 0;
[0169] The unique identifier is: 8a0c8ac2-ebe0-434c-a45e-59f25908d0db;
[0170] The target storage path is: / tmp / 8a0c8ac2-ebe0-434c-a45e-59f25908d0db / ao;
[0171] Then, after obtaining the source code file, the differential information, and the target storage path corresponding to the differential information; determine the target code based on the differential information and the source code file, and perform code checking on the target code, wherein the target code and the code checking result corresponding to the target code are stored according to the target storage path, that is, the differential information can be stored in the target address / tmp / 8a0c8ac2-ebe0-434c-a45e-59f25908d0db named ao target file, wherein the target code can be:
[0172] #include<stdio.h>
[0173] int main(){
[0174] printf("%d\n",1);
[0175] return 0;
[0176] }.
[0177] Furthermore, when performing code checking on the target code, only the target code may be compiled; or the target code may be compiled first, and then the compiled target code may be tested. That is to say, the code checking result may include the compilation result, or may include the compilation result and the test result, and the result content included in the code checking result may be determined according to the inspection task corresponding to the differential information. When the interactive information includes a test instruction, the test instruction is used to indicate that the differential information corresponds to a test task, and the target code generated by the code generator based on the source code fragment in the comment and / or the differential information generated by the code generator based on the source code fragment in the comment is a test code that satisfies the test instruction. It can be understood that if the code generator only outputs differential information, the compiler can restore the target code to meet the test instruction based on each differential information and other preset scripts.
[0178] Exemplarily, the performing parallel checking on each target code to obtain the code checking result specifically includes:
[0179] Check whether the differential information corresponds to a test task;
[0180] When there is no corresponding test task, compile the target code to obtain a compilation result of the target code, and use the compilation result of the target code as a code checking result;
[0181] When there is a corresponding test task, the target code is compiled to obtain a compilation result of the target code and a testable file corresponding to the target code is output, the testable file is tested to obtain a test result, and the compilation result and the test result are used as code inspection results.
[0182] Specifically, before testing the target code, the target code needs to be compiled first. To this end, it can be determined whether the differential information corresponds to a test task. When there is no corresponding test task, only the target code is compiled to obtain the compilation result of the target code. When there is a corresponding test task, the target code is first compiled to obtain the compilation result and the testable file corresponding to each target code is output, and then the test result is obtained from the testable file. Specifically, it can be determined whether the differential information corresponds to a test task based on whether the interactive information includes a test instruction. For example, the interactive information includes a target code generation instruction and / or a generation instruction of the differential information corresponding to the target code. In the examples (Example 1, Example 2, and Example 3) where the target code and / or the differential information corresponding to the target code are generated by a code generator, there is no test task, and only the target code needs to be compiled, and the compilation result is used as the code inspection result. When the interactive information includes test instructions, in the example where the code generator generates the target code and / or the differential information corresponding to the target code, there is a corresponding test task. Then, after compiling the target code, the target code (test code) is tested to obtain the test results, and finally the compilation results and the test results are used as the code inspection results.
[0183] It should be noted that when the target code is compiled in multiple layers, if the previous layer is compiled successfully, the next layer of the compilation process will be carried out, and the compilation results of each layer will be recorded. Among them, the compilation results and intermediate files generated during the compilation process will be stored in the target storage path to prevent conflicts. In addition, after obtaining the code inspection results, the target code and the code inspection results (such as whether the compilation is successful, whether it passes the test, etc.) can also be displayed to the user, so that the user can know the target code and the code inspection results corresponding to the target code. The user can further operate the target code based on the code inspection results, for example, replace part of the source code fragments in the source code file with the target code in the compiler, add the target code, and feed the test code back to the test module.
[0184] When the target code corresponding to each differential information is checked in parallel, there is a compilation thread corresponding to each differential information, and the compilation thread corresponding to each differential information is executed in parallel. Based on each differential information and the source code file, the target code corresponding to each differential information is checked in parallel to obtain a code checking result, wherein the code checking result corresponding to each differential information is stored according to the target storage path corresponding to each differential information.
[0185] In one embodiment, when the user triggers the interactive information in the compiler, the controller obtains the interactive information and the source code file and sends it to the code generator in a request manner. When sending the request, the controller randomly generates a unique identifier for determining the target storage address to store the content output by the code generator based on the interactive information. The controller determines the differential information based on the source code file, the interactive information and the content output by the code generator and sends it to the compiler. After the compiler obtains the source code file, the differential information and the target storage path corresponding to the differential information; the target code is determined based on the differential information and the source code file, and the code check is performed on the target code in parallel, wherein the target code and the code check result corresponding to the target code are stored according to the target storage path, and the entire code check process does not modify the source code in any way, so the compilation processes can be performed concurrently without conflict. If the target code is a test code, the test code will also be compiled in parallel to complete the test, and the compilation processes will not conflict with each other. In addition, the products of all compilation processes are stored in the target storage path with a unique identifier to avoid conflicts when the compiler performs code checks in parallel.
[0186] In summary, the present embodiment provides a code checking method, the method comprising obtaining a source code file, a plurality of differential information corresponding to the source code file, and a target storage path corresponding to each differential information; based on each differential information and the source code file, performing a parallel check on the target code corresponding to each differential information to obtain a code checking result. When checking the target code formed based on the source code file, the present application only needs to obtain the source code file and the differential information, without making any modification to the source code file, which enables programming operations to be performed concurrently without the need for locking operations, thereby improving the efficiency of code checking.
[0187] Based on the above code checking method, this embodiment provides a code checking device, such as Figure 4 As shown, the code checking device specifically includes:
[0188] The acquisition module 100 is used to acquire a source code file, a plurality of differential information corresponding to the source code file, and a target storage path corresponding to each differential information, wherein the target storage path is used to store the differential information, the target code corresponding to the differential information, and the code checking result corresponding to the target code;
[0189] The checking module 200 is used to perform parallel checking on the target code corresponding to each differential information based on each differential information and the source code file to obtain a code checking result.
[0190] Based on the above code checking method, this embodiment provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in the code checking method as described in the above embodiment.
[0191] Based on the above code checking method, the present application also provides a terminal device, such as Figure 5 As shown, it includes at least one processor 20; a display screen 21; and a memory 22, and may also include a communications interface 23 and a bus 24. The processor 20, the display screen 21, the memory 22, and the communications interface 23 may communicate with each other through the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setting mode. The communications interface 23 may transmit information. The processor 20 may call the logic instructions in the memory 22 to execute the method in the above embodiment.
[0192] In addition, the logic instructions in the memory 22 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0193] The memory 22 is a computer-readable storage medium that can be configured to store software programs, computer executable programs, such as program instructions or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes functional applications and data processing by running the software programs, instructions or modules stored in the memory 22, that is, implementing the methods in the above embodiments.
[0194] The memory 22 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 22 may include a high-speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, may also be a transient storage medium.
[0195] In addition, the specific process of loading and executing the multiple instruction processors in the above-mentioned storage medium and the terminal device has been described in detail in the above-mentioned method, and will not be described one by one here.
[0196] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application 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 spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A code checking method, characterized in that: Applied to a compiler, the code checking method specifically includes: Obtaining a source code file, a plurality of differential information corresponding to the source code file, and a target storage path corresponding to each differential information, wherein the target storage path is used to store the differential information, the target code corresponding to the differential information, and the code checking result corresponding to the target code; Based on each differential information and the source code file, a target code corresponding to each differential information is checked in parallel to obtain a code checking result, wherein the source code and the differential information are input information of the compiler; The process of obtaining the plurality of differential information corresponding to the source code file and the target storage path corresponding to each differential information specifically includes: receiving interactive information for a portion of source code fragments in the source code file; Based on the interaction information, multiple interactions are performed with the code generator to determine a number of differential information corresponding to the source code file and a unique identifier corresponding to the differential information, wherein the differential information is used to represent the difference between the target code and some source code fragments in the source code file, and the unique identifier is used to determine the target storage path corresponding to the differential information.
2. The code checking method according to claim 1, characterized in that: The determining of a plurality of differential information corresponding to the source code file and a unique identifier corresponding to the differential information by performing multiple interactions with a code generator based on the interactive information includes: Sending the interaction information to the code generator multiple times, wherein the number of times the interaction information is sent is the same as the number of the difference information; The content generated by the code generator each time based on the interactive information is received and differential information is determined to obtain a plurality of differential information corresponding to the source code file.
3. The code checking method according to claim 2, characterized in that: The receiving the content generated by the code generator based on the interaction information each time and determining the difference information specifically includes: When the interactive information includes an instruction to generate a target code and / or an instruction to generate differential information corresponding to the target code, receiving the target code and / or differential information corresponding to the target code generated by the code generator based on the interactive information each time, so as to obtain a plurality of differential information corresponding to the source code file; The target code is a code fragment generated by the code generator that is different from some source code fragments in the source code file, and the differential information is used to indicate the difference between the target code and some source code fragments in the source code file.
4. The code checking method according to claim 3, characterized in that: The receiving the content generated by the code generator based on the interaction information each time and determining the difference information further includes: When the interactive information only includes the target code generation instruction, the difference content between the source code file and each target code is analyzed to determine the difference information of each target code relative to its corresponding source code fragment.
5. The code checking method according to claim 2, characterized in that: The receiving the content generated by the code generator based on the interaction information each time and determining the difference information includes: When the interaction information includes a test instruction and an instruction for generating a target code and / or an instruction for generating differential information corresponding to the target code, controlling the code generator to obtain comment information in the source code file based on the interaction information; Receive the target code generated by the code generator based on the annotation information and / or some differential information corresponding to the target code to obtain some differential information corresponding to the source code file, wherein the target code is the test code that satisfies the test instruction.
6. The code checking method according to claim 5, characterized in that: Receiving the content generated by the code generator based on the interaction information each time and determining the difference information, further comprising: When the interactive information includes only the test instructions and the target code generation instructions, the difference content between the source code file and each target code is analyzed to determine the difference information of each target code relative to its corresponding source code segment.
7. The code checking method according to claim 1, characterized in that: The step of performing parallel checking on the target code corresponding to each differential information based on each differential information and the source code file to obtain the code checking result specifically includes: Determine in parallel the target code corresponding to each differential information based on each differential information; Each target code is checked in parallel to obtain a code checking result.
8. The code checking method according to claim 7, characterized in that: The parallel checking of each target code to obtain the code checking result specifically includes: Check whether the differential information corresponds to a test task; When there is no corresponding test task, compile the target code to obtain a compilation result of the target code, and use the compilation result of the target code as a code checking result; When there is a corresponding test task, the target code is compiled to obtain a compilation result of the target code and a testable file corresponding to the target code is output, the testable file is tested to obtain a test result, and the compilation result and the test result are used as code inspection results.
9. The code checking method according to claim 7, characterized in that: Each differential information corresponds to a compilation thread, and the compilation threads corresponding to each differential information are executed in parallel. Based on each differential information and the source code file, the target code corresponding to each differential information is checked in parallel to obtain a code check result, wherein the code check result corresponding to each differential information is stored according to the target storage path corresponding to each differential information.
10. A code checking device, characterized in that: Applied to a compiler, the code checking device specifically comprises: An acquisition module, used to acquire a source code file, a plurality of differential information corresponding to the source code file, and a target storage path corresponding to each differential information, wherein the target storage path is used to store the differential information, the target code corresponding to the differential information, and the code checking result corresponding to the target code; A checking module, configured to perform parallel checking on the target code corresponding to each differential information based on each differential information and the source code file to obtain a code checking result, wherein the source code and the differential information are input information of the compiler; The process of obtaining the plurality of differential information corresponding to the source code file and the target storage path corresponding to each differential information specifically includes: receiving interactive information for a portion of source code fragments in the source code file; Based on the interaction information, multiple interactions are performed with the code generator to determine a number of differential information corresponding to the source code file and a unique identifier corresponding to the differential information, wherein the differential information is used to represent the difference between the target code and some source code fragments in the source code file, and the unique identifier is used to determine the target storage path corresponding to the differential information.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps in the code checking method according to any one of claims 1-9.
12. A terminal device, characterized in that: include: Processor and memory; The memory stores a computer-readable program executable by the processor; When the processor executes the computer-readable program, the steps in the code checking method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Multi-branch increment checking method based on artificial intelligence and related equipment
CN114924978A
Detection method, device, equipment, storage medium and computer program product
CN117632698A