Code checking method and device, computer-readable storage medium, and terminal

By converting code into a data structure with object storage layers and using a binary tree to check logical relationships, the method addresses the inefficiencies of existing code checking methods, improving accuracy and efficiency in verifying business process logic.

CN115454445BActive Publication Date: 2025-07-15GUOTAI JUNAN SECURITIES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211192484.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-28
Publication Date
2025-07-15
Estimated Expiration
2042-09-28

AI Technical Summary

Technical Problem

Existing code inspection methods cannot automatically check the correctness of the logical relationship between each object to be checked in the code, and the accuracy and efficiency of the inspection are insufficient.

Method used

By determining the program to be converted, it includes multiple business objects and object calculations, and converts it into a preset multi-layer object storage layer data structure, matching the object to be checked and the business objects in the data structure one by one, and determining whether the logical relationship is correct based on the matching result.

Benefits of technology

It realizes automatic checking of the correctness of business processes in the code, improves the accuracy and efficiency of code inspection, and adapts to changes in different business processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115454445B_ABST
    Figure CN115454445B_ABST
Patent Text Reader

Abstract

A code checking method, apparatus, computer-readable storage medium, and terminal. The method includes: determining a program to be converted, where the program to be converted includes multiple business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object; converting the program to be converted into a preset data structure; extracting objects to be checked according to the code to be checked, successively matching each object to be checked with at least a part of the business objects stored in the data structure, then determining the matching result of each object to be checked and the matched business object, and marking the matching result in the data structure; in the marked data structure, determining whether the logical relationship indicated by each object calculation is correct according to the matching result of each business object. The above solution can automatically check the logical correctness of the business process included in the code, improving the accuracy and efficiency of code checking.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of computer technologies, and in particular, to a code inspection method and apparatus, a computer-readable storage medium, and a terminal. Background Art

[0002] In software development, for a specific business, coding needs to be carried out according to the specified process. Usually, the method of code review is adopted to ensure the correctness and completeness of the business. However, the review work requires the participants to deeply understand the relevant business scenarios, and the work efficiency is negatively correlated with the amount of business code to be inspected. Over-reliance on manual inspection makes it difficult to ensure the correctness and timeliness of the code review results. Therefore, it is extremely necessary to study how to achieve automatic code inspection.

[0003] Currently, two main methods are adopted for code inspection:

[0004] The first method realizes automatic code inspection through a static inspection tool. This type of static inspection tool usually adopts two working principles: (1) Inspection based on an Abstract Syntax Tree (AST): The front-end compiler preprocesses the source code, performs semantic and syntactic analysis to generate the corresponding abstract syntax tree, and saves the corresponding source code detailed information, such as object types and names (such as functions, structures, classes, variables, etc.), operation operations, associated header files, etc. in the AST. After obtaining the abstract syntax tree corresponding to the source code, such inspection tools can accurately locate information such as variables and functions in the source code, and can compare the syntax specifications or preset rules with the source code by means of exhaustive search, regular matching, pattern recognition, etc. to determine the correctness of the code. (2) Inspection based on Intermediate Representation (IR): The AST can be converted into an intermediate representation form IR that is closer to the target code after type checking and normalization. After the compiler analyzes and optimizes the work based on the IR, the IR is converted into assembly language for execution. This type of inspection is independent of the input language type, and usually checks for vulnerabilities and defects in the source code based on the control flow graph in combination with predefined rules and preset analysis algorithms.

[0005] The second method often relies on manual review, and checks whether each object to be inspected in the code and the business process in the code are correct by exhausting the code to be inspected.

[0006] However, in the above prior art, using a static inspection tool for automatic code inspection generally focuses on syntactic-level analysis and inspection. For example, it checks the variable assignment, whether the variable name is accurate, whether the storage space value exceeds the limit, etc., but it cannot check the logical correctness of the business processes included in the business code. Therefore, it is difficult to ensure the effectiveness and accuracy of the inspection. In addition, although the method of exhaustive manual review of the code to be inspected can check whether the business processes in the code are correct, due to the differences in variable definitions, function calls, and logical sequences included in the business code in different businesses, its characteristics such as timeliness, independence, and complexity make the efficiency of manual review and exhaustive code inspection low and the cost high.

[0007] Therefore, there is an urgent need to provide a code inspection method that can automatically check the logical correctness of the business processes included in the code and improve the accuracy and efficiency of code inspection. Summary of the Invention

[0008] The technical problem solved by the embodiments of the present invention is that the existing code inspection methods cannot automatically check the logical relationship correctness between each object to be inspected in the code, and the accuracy and efficiency of the inspection are insufficient.

[0009] To solve the above technical problem, an embodiment of the present invention provides a code inspection method, including the following steps: determining a program to be converted, the program to be converted includes multiple business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object; converting the program to be converted into a preset data structure, the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the business objects and / or object calculations, and each object calculation is used to indicate the logical relationship of one or more business objects in the object storage layer to which the object calculation belongs; extracting the objects to be inspected according to the code to be inspected, matching each object to be inspected with at least a part of the business objects stored in the data structure one by one, then determining the matching result of each object to be inspected and the matched business object, and marking the matching result in the data structure; in the marked data structure, determining whether the logical relationship indicated by each object calculation is correct according to the matching result of each business object.

[0010] Optionally, the method further includes: starting from the top-level object storage layer of the data structure, determining whether the code to be inspected passes the inspection according to at least a part of each object calculation.

[0011] Optionally, the determination of the program to be converted includes: selecting a service template, where the service template contains multiple service elements, and there is a preset service logic relationship between each service element, and there is a preset corresponding relationship between the service element and the service object; determining the logical relationship between the service objects corresponding to each service element according to the service logic relationship between the service elements; and determining the program to be converted based on the logical relationship between each service object, the service object, and the object calculation.

[0012] Optionally, converting the program to be converted into a preset data structure includes: extracting service objects and object calculations in the program to be converted; determining the root node of the data structure, where the root node is used to store the first service object in the program to be converted; and layer by layer adding child nodes to the current node in the extraction order, and each newly added child node is used to store the next service object or object calculation of the current service object or object calculation.

[0013] Optionally, the preset data structure is a binary tree, and each newly added child node is located in a preset first direction of the current node; the method further includes: if the newly added child node is used to store an object calculation and the object calculation is used to indicate a preset logical relationship, determining the service object associated with the object calculation; and rotating the subtree between the previous service object associated with the object calculation and the object calculation to the subtree in the second direction of the object calculation.

[0014] Optionally, the preset logical relationship is selected from: logical "AND" relationship and logical "OR" relationship.

[0015] Optionally, the step of successively matching the object to be inspected with at least a part of the service objects stored in the data structure includes: successively matching the object to be inspected with the first node stored in the data structure in the extraction order until the matching is successful or all the objects to be inspected are traversed; if the matching with the first node is successful, for each object to be inspected starting from the currently successfully matched object to be inspected in the order of each object to be inspected, matching with the second-direction child node of the currently successfully matched node; whenever the matching fails, first select the first-direction child node of the parent node of the currently failed-matched node for matching, and when the continuous matching fails, successively select the parent nodes from bottom to top and perform matching when the selected parent node has a first-direction child node until the matching is successful or the parent node of the currently matched node is the root node.

[0016] Optionally, the step of successively matching the object to be inspected with at least a part of the service objects stored in the data structure further includes: when the parent node of the currently matched node is the root node and the matching fails, if the currently matched node is a service object, then successively match the next object to be inspected with the currently matched node; or, if the currently matched node is an object calculation, then successively match the next object to be detected with the right child node of the currently matched node, until the matching is successful or all the objects to be inspected are traversed.

[0017] Optionally, the step of successively matching the object to be inspected with at least a part of the service objects stored in the data structure further includes: whenever the matching is successful, use the depth-first traversal algorithm to determine the next node to be matched, and match it with the next object to be inspected of the currently successfully matched object to be inspected.

[0018] Optionally, the step of using the depth-first traversal algorithm to determine the next node to be matched and match it with the next object to be inspected of the currently successfully matched object to be inspected whenever the matching is successful includes: whenever the matching is successful, successively select the second-direction child nodes of the currently successfully matched node from top to bottom to match with the next object to be inspected; whenever reaching a leaf node, if the matching with the reached leaf node is successful, then determine the parent node with an unmatched first-direction child node from bottom to top, and then match the next object to be inspected with the unmatched first-direction child node, and when the subsequent matching is successful, successively select the second-direction child nodes of the currently successfully matched node from top to bottom to match with the next object to be inspected, until reaching the last leaf node in the first direction of the binary tree or all the objects to be inspected are traversed.

[0019] Optionally, the step of selecting the second-direction child node of the currently successfully matched node to match with the next object to be inspected includes: determining whether the currently successfully matched node has a second-direction child node; if the determination result is yes, then use the second-direction child node of the currently successfully matched node to match with the next object to be inspected.

[0020] Optionally, the method further includes: if the determination result is no, then use the first-direction child node of the currently successfully matched node to match with the next object to be inspected.

[0021] Optionally, the first direction is the right direction, the child node in the first direction is the right child node, the second direction is the left direction, and the child node in the second direction is the left child node.

[0022] Optionally, each business object and object calculation has its own check tag; marking the matching result in the data structure includes: assigning check tags to the check tags of each business object according to the matching result; wherein, the check tags of each business object have a consistent initial tag value.

[0023] Optionally, determining whether the logical relationship indicated by each object calculation is correct according to the matching results of each business object includes: determining the tag values of the check tags of the object calculations associated with each business object according to the tag values of the check tags of each business object; according to the determined tag values of the check tags of each object calculation, determining whether the logical relationship indicated by each object calculation is correct.

[0024] Optionally, determining the tag values of the check tags of the object calculations associated with each business object according to the tag values of the check tags of each business object includes: traversing each object calculation layer by layer from bottom to top, and determining the tag values of the check tags of the object calculation according to the logical relationship indicated by the object calculation and the tag values of the check tags of the child nodes of the object calculation.

[0025] Optionally, the check tag of the business object with a successful match is assigned the value true, and the check tag of the business object with a failed match is assigned the value false; determining the tag values of the check tags of the object calculations associated with each business object according to the tag values of the check tags of each business object includes: if the object calculation indicates a logical "AND" relationship, determining whether the tag values of the check tags of the child nodes of the object calculation are all true, if so, determining the tag value of the check tag of the object calculation is true, otherwise determining the tag value of the check tag of the object calculation is false; if the object calculation indicates a logical "OR" relationship, determining whether the tag values of the check tags of the child nodes of the object calculation are all false, if so, determining the tag value of the check tag of the object calculation is false, otherwise determining the tag value of the check tag of the object calculation is true; if the object calculation indicates a logical "NOT" relationship, determining whether the tag values of the check tags of the child nodes of the object calculation are all false, if so, determining the tag value of the check tag of the object calculation is true, otherwise determining the tag value of the check tag of the object calculation is false.

[0026] Optionally, the data structure is a binary tree; starting from the top object storage layer of the data structure, determining whether the code to be checked passes the check according to at least a part of each object calculation includes: if there is any path from the root node to the leaf node in the binary tree, and the tag values of the check tags of each object calculation on the path are all true, determining that the code to be checked passes the check.

[0027] Optionally, extracting the object to be inspected from the code to be inspected includes: performing compilation processing on the code to be inspected to obtain an abstract syntax tree, where the order of each node in the abstract syntax tree is the same as the order of each object to be inspected in the code to be inspected; determining each object to be inspected according to each node in the abstract syntax tree.

[0028] Optionally, sequentially matching the object to be inspected with at least a part of the business objects stored in the data structure includes: performing matching using a regular matching algorithm or a string comparison method.

[0029] Optionally, the business object includes type information and name information, and the type information of the business object is selected from: function Method, structure Struct, variable Variable, class Class, and object Object.

[0030] Optionally, the logical relationship between business objects in the program to be converted is selected from: logical "AND" relationship, logical "OR" relationship, and logical "NOT" relationship.

[0031] An embodiment of the present invention further provides a code inspection device, including: a program to be converted determination module, configured to determine a program to be converted, where the program to be converted includes multiple business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object; a data structure conversion module, configured to convert the program to be converted into a preset data structure, where the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the business object and / or object calculation, and each object calculation is used to indicate the logical relationship of one or more business objects in the object storage layer to which the object calculation belongs; a matching module, configured to extract the object to be inspected according to the code to be inspected, sequentially match the object to be inspected with at least a part of the business objects stored in the data structure, then determine the matching result of each object to be inspected and the matched business object, and mark the matching result in the data structure; a logical relationship inspection module, configured to determine whether the logical relationship indicated by each object calculation is correct according to the matching result of each business object in the marked data structure.

[0032] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is run by a processor, the steps of the above code inspection method are executed.

[0033] An embodiment of the present invention further provides a terminal, including a memory and a processor, where a computer program capable of running on the processor is stored on the memory, and when the processor runs the computer program, the steps of the above code inspection method are executed.

[0034] Compared with the prior art, the technical solution of the embodiment of the present invention has the following beneficial effects:

[0035] In the embodiment of the present invention, a program to be converted is determined, the program to be converted includes a plurality of business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object; the program to be converted is converted into a preset data structure, the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the business object and / or object calculation, and each object calculation is used to indicate the logical relationship of one or more business objects in the object storage layer to which the object calculation belongs; according to the code to be inspected, the objects to be inspected are extracted, and each of the objects to be inspected is matched with at least a part of the business objects stored in the data structure, and then the matching results of each object to be inspected and the matched business objects are determined, and the matching results are marked in the data structure; in the marked data structure, according to the matching results of each business object, it is determined whether the logical relationship indicated by each object calculation is correct.

[0036] In the prior art, the code inspection method is generally limited to the inspection at the syntax level, and it is impossible to inspect the logical correctness of the business processes included in the code, and the effectiveness and accuracy of the inspection results are insufficient; in addition, the existing inspection methods often rely on the method of exhausting the names of the objects to be inspected, and the inspection efficiency is low. Compared with the foregoing prior art, the embodiment of the present invention first determines a program to be converted that includes a plurality of business objects (corresponding to the objects to be inspected in the code) and at least one object calculation; then uses a preset data structure to store each business object and object calculation in the program to be converted; and then uses a plurality of objects to be inspected extracted from the code to be inspected to match at least a part of the business objects stored in the data structure, and determines whether the logical relationship indicated by each object calculation is correct according to the matching results. Among them, each object calculation is used to indicate the logical relationship of one or more business objects belonging to the object calculation. Thus, the embodiment of the present invention can automatically inspect the logical correctness (the logical correctness of the business processes included in the code) between each object to be inspected in the code to be inspected, and improve the accuracy and efficiency of code inspection.

[0037] Further, the determination of the program to be converted includes: selecting a service template, where the service template contains multiple service elements, and there is a preset service logic relationship between each service element, and there is a preset corresponding relationship between the service element and the service object; determining the logical relationship between the service objects corresponding to each service element according to the service logic relationship between the service elements; and determining the program to be converted based on the logical relationship between each service object, the service object, and the object calculation. Since a specific business process often follows a general process such as a business initialization stage, a business processing stage, and a business ending stage. Although the complexity and scenarios of the business are different, within each process stage or across process stages, information transfer and feedback are carried out on one or more service elements.

[0038] In the embodiment of the present invention, these "service elements" with similar functions but different types and names are abstracted into "service objects", and the information exchange and logical relationship between "service objects" are abstracted into "object calculation". Thus, according to the service implementation requirements of the business department, the business process is abstracted into a set of "service objects" that interact through "object calculation" to obtain the program to be converted, and code inspection is performed based on the program to be converted. In this way, not only can the logical correctness of the code developed by the R & D department according to the service implementation requirements be accurately inspected, but also the business process changes can be quickly adapted, improving the efficiency of code inspection.

[0039] Further, the preset data structure can be a binary tree, that is, converting the program to be converted into a binary tree. Specifically, by following the extraction order of each service object and object calculation, each layer of nodes of the binary tree is used to store each service object and object calculation, and the parent node is used to represent the low-order bit, and the child node is used to represent the high-order bit. In the embodiment of the present invention, since each service object and object calculation in the program to be converted has syntactic orderliness, and the binary tree structure can store the program to be converted simply and unambiguously without adding additional information (such as line numbers, parentheses, square brackets, curly brackets, etc.) and storage space to describe the priority relationship between each service object and object calculation in the expression. This is because the positional relationship between the parent node and the child node in the binary tree and the positional relationship between each child node in the same layer can itself represent the sequence or context relationship between service objects. Therefore, converting the program to be converted into a binary tree can reduce the storage and analysis complexity of the program to be converted and save storage space.

[0040] In addition, since there are logical relationships among the various business objects of the program to be converted, the embodiments of the present invention use the parent node in the binary tree to store the object calculation for indicating the logical relationship, and the child node stores the business object associated with the object calculation. Combining the flexible and rich generation methods, traversal methods, and relatively fast traversal speed of the binary tree, it can be quickly applied to different application scenarios of code inspection, improving the efficiency of code inspection.

[0041] Furthermore, during the process of generating the binary tree, a rotation (rotate) operation (left rotation or right rotation) is also adopted. For example, if each newly added child node is used to store an object calculation and the object calculation is used to indicate a preset logical relationship (such as a logical "AND" relationship or a logical "OR" relationship), then the business object associated with the object calculation is determined; then the subtree between the previous business object associated with the object calculation and the object calculation is rotated into the subtree in the second direction of the object calculation. In this way, when the parent node in the binary tree stores the object calculation, the left and right child nodes store the two business objects associated with the object calculation. Thus, it helps to make the order of traversing each node in the binary tree consistent with the word order of the program to be converted and the code to be inspected in the subsequent matching step. And, it helps to quickly and accurately determine whether the logical relationship indicated by the object calculation stored in the parent node to which the left and right child nodes belong is correct according to the matching results of the business objects stored in the left and right child nodes in the subsequent step of determining the inspection result, improving the accuracy and efficiency of code inspection.

[0042] Furthermore, during the process of successively matching the object to be inspected with at least a part of the business objects stored in the data structure, whenever a matching failure occurs, first select the first-direction child node of the parent node of the currently failed matching node for matching, and when the continuous matching still fails, successively select the parent nodes from bottom to top one by one, and perform matching when the selected parent node has a first-direction child node, until the matching is successful or the parent node of the currently matched node is the root node. In the embodiments of the present invention, a traversal scheme with a limited depth is adopted. Whenever a matching failure occurs, instead of continuing to match with the next-layer nodes of the failed matching node, start from the layer of the currently failed matching node, successively select the parent nodes from bottom to top one by one, and perform matching when the selected parent node has a first-direction child node. Thereby, it helps to improve the matching efficiency, especially in the scenario where the depth of the binary tree is very deep, and can effectively reduce the operation overhead.

[0043] Further, determining the tag value of the check tag associated with each business object based on the tag value of the check tag of each business object includes: traversing each object calculation layer by layer from bottom to top, and determining the tag value of the check tag of the object calculation according to the logical relationship indicated by the object calculation and the tag value of the check tag of the child node of the object calculation. The embodiment of the present invention adopts a layer-by-layer traversal method from bottom to top, and determines the tag value of the check tag of the object calculation according to the logical relationship indicated by each object calculation and the tag value of the check tag of the child node of the object calculation. Thereby, the tags of each object calculation in the binary tree can be determined quickly and accurately, improving the accuracy and efficiency of code inspection. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 is a flowchart of a code inspection method in an embodiment of the present invention;

[0045] Figure 2 is Figure 1 a flowchart of a specific implementation manner of step S11 in

[0046] Figure 3 is Figure 1 a flowchart of a specific implementation manner of step S12 in

[0047] Figure 4 is a schematic diagram of the process of converting a program to be converted into a binary tree in an embodiment of the present invention;

[0048] Figure 5 is Figure 1 a flowchart of a specific implementation manner of step S13 in

[0049] Figure 6 is Figure 4 a schematic diagram of the process of matching the binary tree generated in

[0050] Figure 7 is Figure 1 a flowchart of a specific implementation manner of step S14 in

[0051] Figure 8 is a schematic diagram of the structure of a code inspection device in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0052] As described in the background art, in software development, it is extremely necessary to study how to implement automatic code inspection.

[0053] In the prior art, two main methods are mainly used for code inspection:

[0054] The first method realizes the automatic inspection of code through static inspection tools. Such static inspection tools usually adopt two working principles: (1) Inspection based on Abstract Syntax Tree (AST): The front end of the compiler preprocesses the source code, performs semantic and syntactic analysis to generate the corresponding abstract syntax tree, and saves the corresponding detailed source code information, such as object types and names (such as functions, structures, classes, variables, etc.), operation operations, associated header files, etc. in the AST. After obtaining the abstract syntax tree corresponding to the source code, such inspection tools can accurately locate information such as variables and functions in the source code, and can compare the syntax specifications or preset rules with the source code by means of exhaustive enumeration, regular matching, pattern recognition, etc. to judge the correctness of the code. (2) Inspection based on Intermediate Representation (IR): After type checking and standardization, the AST can be converted into an intermediate representation form IR that is closer to the target code. After the compiler analyzes and optimizes based on IR, it converts IR into assembly language for execution. Such inspection is independent of the input language type and usually checks for vulnerabilities and defects in the source code based on the control flow graph combined with predefined rules and preset analysis algorithms.

[0055] The second method often relies on manual review. By exhaustively checking the code to be inspected, each object to be inspected in the code and the business processes in the code are checked.

[0056] The inventors of the present invention have found through research that using static inspection tools for automatic code inspection generally tends to analyze and check at the syntax level. For example, it checks whether the variable assignment, variable name is accurate, whether the storage space value exceeds the limit, etc., but it cannot check the logical correctness of the business processes included in the business code. Therefore, it is difficult to ensure the effectiveness and accuracy of the inspection. In addition, although the method of exhaustively checking the code to be inspected for manual review can check whether the business processes in the code are correct, due to the differences in variable definitions, function calls, and logical sequences included in the business code in different businesses, its characteristics such as timeliness, independence, and complexity make the efficiency of code inspection by manual review and exhaustive enumeration low and the cost high.

[0057] To solve the above technical problems, an embodiment of the present invention provides a code inspection method, which specifically includes: determining a program to be converted, where the program to be converted includes multiple business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object; converting the program to be converted into a preset data structure, the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the business objects and / or object calculations, and each object calculation is used to indicate the logical relationship of one or more business objects in the object storage layer to which the object calculation belongs; extracting the objects to be inspected according to the code to be inspected, matching each object to be inspected with at least a part of the business objects stored in the data structure one by one, then determining the matching results of each object to be inspected and the matched business objects, and marking the matching results in the data structure; in the marked data structure, determining whether the logical relationships indicated by each object calculation are correct according to the matching results of each business object.

[0058] As described above, in the embodiment of the present invention, by adopting a data structure including multiple layers of object storage layers, not only each business object in the program to be converted is stored, but also one or more object calculations used to indicate the logical relationship between each business object are stored; then, multiple objects to be inspected extracted from the code to be inspected are matched with at least a part of the business objects stored in the data structure, and according to the matching results, it is determined whether the logical relationships indicated by each object calculation are correct. Thus, it is possible to automatically check the logical relationships between each object to be inspected in the code to be inspected (or the logical correctness of the business process included in the code to be inspected), improving the accuracy and efficiency of code inspection.

[0059] To make the above objects, features, and beneficial effects of the present invention more obvious and understandable, the following specifically describes the specific embodiments of the present invention with reference to the accompanying drawings.

[0060] Refer to Figure 1 , Figure 1 is a flowchart of a code inspection method in an embodiment of the present invention. The method may include steps S11 to S14:

[0061] Step S11: Determine a program to be converted, where the program to be converted includes multiple business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object;

[0062] Step S12: Convert the program to be converted into a preset data structure, the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the business objects and / or object calculations, and each object calculation is used to indicate the logical relationship of one or more business objects in the object storage layer to which the object calculation belongs;

[0063] Step S13: Extract the objects to be inspected according to the code to be inspected, match each object to be inspected with at least a part of the business objects stored in the data structure one by one, then determine the matching results of each object to be inspected and the matched business objects, and mark the matching results in the data structure;

[0064] Step S14: In the marked data structure, determine whether the logical relationships indicated by the calculations of each object are correct according to the matching results of each business object.

[0065] In the specific implementation of step S11: The business object may include type information and name information. Among them, the type information can be used to indicate the type of the business object. Different business objects can belong to the same type, and the number of types of business objects is limited. The identification information can be used to indicate the name of the business object. The identification information of different business objects can be the same. Among them, the type information can also be regarded as the "key" of the business object, and the name information can also be regarded as the "value" of the business object. Therefore, for each business object, it can be considered as a key-value pair composed of a "key" and a "value".

[0066] As a non-limiting example: The type information of the business object can be selected from one or more of function Method, structure Struct, variable Variable, class Class, and object Object. In the specific implementation, the type information of the business object is related to the programming language used in the code to be inspected. Therefore, for different computer programming languages, the type information of the business object can also be selected from other different business object types, and the embodiments of the present invention do not limit this.

[0067] For example, a certain business object is a student structure, which can be expressed as Struct name = student. Then the type information of this business object is the structure Struct, and the identification information is student. A certain business object is an update function, which can be expressed as Method name = update. Then the type information of this business object is the function (method) Method, and the identification information is update.

[0068] As a non-limiting example, the logical relationship between the business objects in the program to be converted can be selected from any one of the logical "AND" relationship (logical AND relationship), logical "OR" relationship (logical OR relationship), and logical "NOT" relationship (logical NOT relationship).

[0069] In the above embodiment, the object calculation corresponding to the logical "AND" relationship can be represented by "AND", the object calculation corresponding to the logical "OR" relationship can be represented by "OR", and the object calculation corresponding to the logical "NOT" relationship can be represented by "NOT".

[0070] In specific implementations, according to different requirements for business implementation, the logical relationships between various business objects can also be other types of logical relationships. For example, progressive relationships between business objects (a further relationship between two or more business objects), call relationships (scenarios where a business object calls relevant functions or other variables as a variable), control relationships (control commands for business objects, such as continue, exit, forced return commands), etc. The embodiments of the present invention do not limit the types of logical relationships between business objects.

[0071] The object calculation is used to indicate the logical relationships between various business objects. Specifically, business objects are associated with other business objects through object calculation. For a single business object, object calculation indicates the self-originating actions of the business object; while for object calculation between multiple business objects, it indicates the mutual relationships between multiple business objects.

[0072] Refer to Figure 2 , Figure 2 is Figure 1 a flowchart of a specific implementation manner of step S11 in

[0073] In step S21, a business template is selected. The business template contains multiple business elements, and among them, there are preset business logical relationships between the business elements, and there is a preset corresponding relationship between the business elements and the business objects.

[0074] In specific implementations, the business template can be determined according to the business implementation requirements proposed by the business department. For example, if the business department proposes a business requirement that "it is not allowed to modify the customer account number and fund amount fields of the fund information and update the modification result to the database", then in this business requirement, the business elements mainly include "fund information", "customer account number", "fund amount", "update operation", etc. The logical relationships between the business elements can be preset according to this business implementation requirement. The corresponding relationship between the business elements and the business objects can be determined according to a pre-defined mapping relationship table.

[0075] In step S22, according to the business logical relationships between the business elements, the logical relationships between the business objects corresponding to the respective business elements are determined.

[0076] In specific implementations, R & D personnel can manually analyze the business logic relationships between the business elements and determine the logical relationships between the business objects corresponding to each business element; they can also determine the logical relationships between the business objects corresponding to each business element based on historical R & D records; or they can use other appropriate methods to determine the logical relationships between the business objects corresponding to each business element. The embodiments of the present invention do not limit this.

[0077] In step S23, the to-be-converted program is determined based on the logical relationships between the business objects, the business objects, and the object calculations.

[0078] It can be understood that in the to-be-converted program, business objects can establish connections with other business objects through object calculations. Each business object is independent of each other, and each business object can appear alone, while object calculations often cannot appear alone as they rely on business objects. The same object calculation can appear repeatedly and can affect the same business object. The beginning of the to-be-converted program is usually a business object, and object calculations are usually not placed at the end of the to-be-converted program. The to-be-converted program is sensitive to the arrangement order between business objects and object calculations. When extracting business objects and object calculations from the to-be-converted program, the extraction order is consistent with the arrangement order between the business objects and object calculations.

[0079] It can be understood that since a specific business process generally follows a rough process such as a business initialization stage, a business processing stage, and a business end stage. Although the complexity and scenarios of the business are different, within each process stage or across process stages, information is transmitted and feedback is provided for one or more business elements.

[0080] In the embodiments of the present invention, "business elements" with similar functions but different types and names are abstracted into "business objects", and the information exchange and logical relationships between "business objects" are abstracted into "object calculations". Thus, according to the business implementation requirements of the business department, the business process is abstracted into a group of "business objects" that interact through "object calculations" to obtain the to-be-converted program, and code inspection is performed based on the to-be-converted program. In this way, not only can the logical correctness of the code developed by the R & D department according to the business implementation requirements be accurately inspected, but also the business process changes can be quickly adapted, improving the efficiency of code inspection.

[0081] Continue to refer to Figure 1, in the specific implementation of step S12: Each layer object storage layer of the data structure may contain only one or more business objects, or only one or more object calculations, or may contain both business objects and object calculations. Each object calculation has one or more business objects that belong to (or are associated with) the object calculation.

[0082] For example, for each "AND" (used to indicate a logical AND relationship) or "OR" (used to indicate a logical OR relationship) object calculation, two business objects can be associated, or the two associated business objects belong to the "AND" or "OR" object calculation. For each "NOT" (used to indicate a logical NOT relationship) object calculation, one or more business objects can be associated, or the one or more associated business objects belong to the "NOT" object calculation.

[0083] Refer to Figure 3 , Figure 3 is Figure 1 a flowchart of a specific implementation manner of step S12 in . Converting the program to be converted into a preset data structure in step S12 may include steps S31 to S33:

[0084] In step S31, business objects and object calculations are extracted from the program to be converted.

[0085] Among them, the order of extracting the business objects and object calculations is the same as the order of the business objects and object calculations in the program to be converted.

[0086] In step S32, the root node of the data structure is determined, and the root node is used to store the first business object in the program to be converted.

[0087] In step S33, according to the extraction order, child nodes are added layer by layer to the current node, and each newly added child node is used to store the next business object or object calculation after the current business object or object calculation.

[0088] In the process of converting the program to be converted into the data structure as described above, the end conditions may include but are not limited to: until all the extracted business objects and object calculations are traversed, the number of added layers reaches a preset number of layers, the generated duration reaches a preset duration, etc.

[0089] In the embodiment of the present invention, since the syntax of each business object and object calculation in the program to be converted has an order, the binary tree structure can store the program to be converted simply and unambiguously without adding additional information (such as line numbers, parentheses, square brackets, curly brackets, etc.) and storage space to describe the priority relationship between each business object and object calculation in the expression. This is because the positional relationship between the parent node and the child node in the binary tree and the positional relationship between each child node at the same level can itself represent the sequence or context relationship between business objects (for example, the parent node represents the lower order bit and the child node represents the higher order bit). Thereby, the storage and analysis complexity of the program to be converted can be reduced and the storage space can be saved. In addition, there is a logical relationship between each business object of the program to be converted. By using the parent node in the binary tree to store the object calculation for indicating the logical relationship, and the child node to store the business object associated with the object calculation, and combining the flexible and rich generation methods, traversal methods and relatively fast traversal speed of the binary tree, it can be quickly applied to different application scenarios of code inspection, and the efficiency of code inspection can be improved.

[0090] Further, the preset data structure is a binary tree, and each newly added child node is located in the preset first direction of the current node; the method further includes: if the newly added child node is used to store an object calculation and the object calculation is used to indicate a preset logical relationship, determining the business object associated with the object calculation; rotating the subtree between the previous business object associated with the object calculation and the object calculation to the subtree in the second direction of the object calculation.

[0091] Wherein, the preset logical relationship is selected from: logical "AND" relationship and logical "OR" relationship.

[0092] As a non-limiting embodiment, the preset first direction is the right direction, that is, each newly added child node is the right child node of the current node. For a certain newly added right child node, if the right child node is used to store the object calculation of "AND", the business object associated with the "AND" is determined, and the subtree (or single node) between the previous business object associated with the "AND" (including the previous business object associated with the "AND") and the object calculation (excluding the object calculation) is rotated counterclockwise to the left subtree (or left child node) of the object calculation.

[0093] In an embodiment of the present invention, during the process of generating a binary tree, a rotation operation (left rotation or right rotation) is also adopted. For example, if each newly added child node is used to store an object calculation, and the object calculation is used to indicate a preset logical relationship (such as a logical "AND" relationship or a logical "OR" relationship), then the business object associated with the object calculation is determined; then, the subtree between the previous business object associated with the object calculation and the object calculation is rotated into the subtree in the second direction of the object calculation. In this way, when the parent node in the binary tree stores an object calculation, the left and right child nodes store the two business objects associated with the object calculation. Thus, it helps to make the order of traversing each node in the binary tree in the subsequent matching step consistent with the word order of the program to be converted and the code to be checked. Moreover, in the subsequent step of determining the inspection result, according to the matching results of the business objects stored in the left and right child nodes, it can quickly and accurately determine whether the logical relationship indicated by the object calculation stored in the parent node to which the left and right child nodes belong is correct, improving the accuracy and efficiency of code inspection.

[0094] Referring to Figure 4 , Figure 4 is a schematic diagram of the process of converting a program to be converted into a binary tree in an embodiment of the present invention.

[0095] As a non-limiting embodiment, the program to be converted is as follows:

[0096]

[0097]

[0098] First, in the above program to be converted, business objects and object calculations are extracted, which are: <Method regx = "true" name = "^BF">, <Object name = "class">, <Struct name = "student">, <var name="age">, <or> , <var name="name">, <Struct name="teacher">, <Varname="subject">, <and>, <Method name="Update">. Among them, the above-mentioned various business objects and the order of object calculations are consistent with the order in the program to be converted.

[0099] Then, determine the root node of the binary tree, and the root node is used to store the first business object in the program to be converted; then, in accordance with the extraction order, add a right child node layer by layer to the current node, and each newly added right child node is used to store the current business object or the next business object or object calculation after the object calculation. Therefore, for each business object and object calculation extracted from the above program to be converted, the specific process of generating a binary tree is as follows:

[0100] (1) First, determine the root node of the binary tree and use it to store <Method regx="true" name="^BF">.

[0101] In a specific implementation, each node can store only the type information and identification information in the business object, for example, only store Method and BF.

[0102] (2) Then, add right child nodes layer by layer downward from the root node, respectively used to store business objects <object name="class">, <Structname="student">, <Varname="age">.

[0103] (3) The newly added right child node at the next lower level is used to store object calculations <or>, at this time, it is not only necessary to add a new node currently <or>Continue to add a right child node in the next layer to store the next business object <var name="name">, it is also necessary to determine the object calculation <or>The associated business objects are <Varname="age"> and <Varname="name"> respectively;

[0104] Then calculate the previous business object associated with this object from <Varname="age"> to the calculation of this object <or>The child node between (i.e., business object <Va1rname="age">) is rotated counterclockwise to calculate for this object <or>The left child node of

[0105] (4) Continue to add a right child node at the next level of the business object <Varname="name"> to store the calculation of the next object <or>, at this time, same as step (3), first calculate on this object <or>Add a right child node in the next layer to store this <or>The subsequent business object <Structname="teacher"> and determine the calculation of this object <or>The previous associated business object is <Structname="student"> (this structure contains variables age and name);

[0106] Then calculate this object <or>The previous business object associated <Struct name="student"> to the calculation of this object <or>Calculate the left subtree rotation between for this object <or>The left subtree.

[0107] (5) And so on, and finally, the Figure 4 last binary tree in

[0108] Continue to refer to Figure 1 , in the specific implementation of step S13, the object to be inspected is similar to the business object, and each object to be inspected also includes at least type information and identification information. Among them, the type information can be used to indicate the type of the object to be inspected, and different objects to be inspected can belong to the same type. The identification information can be used to indicate the name of the object to be inspected, and the identification information of different objects to be inspected can be the same.

[0109] As a non-limiting example: the type information of the object to be inspected can also be selected from function Method, structure Struct, variable Variable, class Class, and object Object. In a specific implementation, the type information of the object to be inspected is related to the programming language used in the code to be inspected. Therefore, for different computer programming languages, the type information of the object to be inspected can also be selected from other different types, and the embodiments of the present invention do not limit this.

[0110] Furthermore, extracting the object to be inspected from the code to be inspected in step S13 may include: performing a compilation process on the code to be inspected to obtain an abstract syntax tree, where the order of each node in the abstract syntax tree is the same as the order of each object to be inspected in the code to be inspected; determining each object to be inspected according to each node in the abstract syntax tree.

[0111] Among them, the abstract syntax tree (AST) is an abstract representation of the syntax structure of the code to be inspected. It represents the syntax structure of a programming language in a tree-like form, and each node on the tree represents a structure in the code to be inspected. The AST tree can be obtained by analyzing and compiling the code to be inspected using a syntax analyzer. In computer science and linguistics, syntactic analysis is a process of analyzing an input text composed of a sequence of words (such as an English word sequence) according to a given formal grammar and determining its syntax structure. A syntax analyzer usually appears as a component of a compiler or interpreter, and its role is to perform syntax checks and construct a data structure composed of the input words (such as a hierarchical data structure such as an AST tree).

[0112] Among them, each node of the AST tree may contain information about each object to be inspected in the source code, mainly including the type information and identification information (or name information) of the object to be inspected. In addition, it may also include the line information, scope information, etc. to which the object to be inspected belongs.

[0113] In a specific implementation, in addition to extracting each object to be inspected based on the abstract syntax tree generated by compiling the code to be inspected, other methods may also be used to determine each object to be inspected in the code to be inspected, and the embodiments of the present invention do not limit this.

[0114] Refer to Figure 5 , Figure 5 is Figure 1 a flowchart of a specific implementation manner of step S13 in . The step of matching each object to be inspected with at least a part of the business objects stored in the data structure in step S13 may include steps S51 to S53, may also include step S54, and may also include step S55. The following explains each step.

[0115] In step S51, in accordance with the extraction order, each object to be inspected is matched with the first node stored in the data structure until the match is successful or all objects to be inspected are traversed.

[0116] In some non-limiting embodiments, a regular matching algorithm or a string comparison method may be used for matching.

[0117] In a specific implementation, for each business object, the specific matching method used may be identified in the node storing the business object.

[0118] Taking Figure 4 the to-be-converted program given in as an example, for the business object <Method regx = "true" name = "^BF">, where regx = "true" can be used to identify that the regular matching algorithm is used when matching this business object. For the business object <Struct name = "student">, which does not contain a matching method identifier, the string comparison method may be used for matching this business object.

[0119] Among them, regx is the abbreviation of Regular Expression, and can also be abbreviated as regexp or RE in the code. A regular expression is a logical formula for operating on strings (including ordinary characters, such as letters between a and z) and special characters (called "meta characters"), that is, using some predefined specific characters and combinations of these specific characters to form a "rule string", and this "rule string" can be used to express a filtering logic for strings. A regular expression is a text pattern that describes one or more strings to be matched when searching text.

[0120] In step S52, if the match with the first node is successful, in the order of each object to be inspected, for each object to be inspected starting from the currently successfully matched object to be inspected, it is matched with the second-direction child nodes of the currently successfully matched node.

[0121] It can be understood that in the specific implementation, before matching each object to be inspected starting from the currently successfully matched object to be inspected with the second-direction child nodes of the currently successfully matched node, it can also be first determined whether the currently successfully matched node has second-direction child nodes; if the currently successfully matched node only has first-direction child nodes, then the next object to be inspected of the currently successfully matched object to be inspected can be matched with the first-direction child node.

[0122] In step S53, whenever the match fails, first select the first-direction child node of the parent node of the currently failed-matched node for matching, and when the continuous match fails, select the parent nodes one by one from bottom to top, and perform matching when the selected parent node has a first-direction child node until the match is successful or the parent node of the currently matched node is the root node.

[0123] In the embodiment of the present invention, whenever the match fails, it no longer continues to match with the next-level nodes of the failed-matched node, but starts from the currently failed-matched node layer, selects the parent nodes one by one from bottom to top, and performs matching when the selected parent node has a first-direction child node. By adopting this traversal scheme with limited depth, the matching efficiency can be effectively improved (especially in the scenario where the depth of the binary tree is very deep), and the operation overhead can be reduced.

[0124] In step S54, when the parent node of the currently matched node is the root node and the match fails, then when the current node is a business object, the next object to be inspected is successively used to match with the current node, or when the current node is an object calculation, the next object to be detected is successively used to match with the right child node of the current node until the match is successful or all objects to be inspected are traversed.

[0125] In step S55, whenever a match is successful, a depth-first traversal algorithm is used to determine the next node to be matched, and it is matched with the next object to be inspected of the currently successfully matched object to be inspected.

[0126] Among them, the order of execution between step S55 and step S53 may not be distinguished.

[0127] Furthermore, step S55 may include: whenever a match is successful, the second-direction child nodes of the currently successfully matched node are selected one by one from top to bottom to be matched with the next object to be inspected; whenever a leaf node is reached, if the match with the reached leaf node is successful, the parent node with unmatched first-direction child nodes is determined from bottom to top, and then the next object to be inspected is used to match with the unmatched first-direction child node, and when the continuous match is successful, the second-direction child nodes of the currently successfully matched node are selected one by one from top to bottom to be matched with the next object to be inspected until the last leaf node in the first direction of the binary tree is reached or all objects to be inspected are traversed.

[0128] Even further, the selection of the second-direction child nodes of the currently successfully matched node to be matched with the next object to be inspected includes: determining whether the currently successfully matched node has second-direction child nodes; if the determination result is yes, the second-direction child nodes of the currently successfully matched node are used to match with the next object to be inspected.

[0129] Among them, if the determination result is no, the first-direction child nodes of the currently successfully matched node are used to match with the next object to be inspected.

[0130] In some non-limiting embodiments, the first direction is the right direction, the child nodes in the first direction are right child nodes, the second direction is the left direction, and the child nodes in the second direction are left child nodes.

[0131] Refer to Figure 6 , Figure 6 is Figure 4 a schematic diagram of the process of matching the binary tree generated in with the extracted objects to be inspected.

[0132] As a non-limiting embodiment, the process of matching each node in the binary tree with each object to be inspected extracted from the abstract syntax tree may specifically include the following steps:

[0133] (1) In the order of extraction, each object to be inspected is matched with the first node <Methodregx="true" name="^BF"> stored in the binary tree one by one until a match is successful for a certain object to be inspected with this first node.

[0134] (2) If a match is successful with <Methodregx="true" name="^BF">, then, in the order of the objects to be inspected, for each object to be inspected from the currently successfully matched object to the subsequent objects, a match is made with the left child node of the currently successfully matched node.

[0135] It can be understood that in a specific implementation, before matching each object to be inspected starting from the currently successfully matched object to be inspected with the left child node of the currently successfully matched node, it can also be first determined whether the currently successfully matched node has a left child node; if the currently successfully matched node only has a right child node, then the next object to be inspected of the currently successfully matched object to be inspected can be matched with the right child node.

[0136] Since the <Methodregx="true" name="^BF"> node only has a right child node, and the right child node stores object calculation <and>, then skip this right child node and take the next object to be inspected and <and>Match the left child node of

[0137] (3) If the object to be inspected currently being matched is the same as <and>The left child node <object name="class">If the match is successful, continue to take the next object to be inspected of the currently successfully matched object to be inspected and <object name="class">Match the left child node. Similarly, because <object name="class">Only the right child node and the calculation of the object stored in the right child node <or>, so skip the object calculation <or>, the next object to be inspected is compared with <or>Match with the left child node of <Struct name="student">.

[0138] (4) And so on. Whenever a match is successful, select the left child node (if there is only a right child node, select that right child node) of the currently successfully matched node one by one from top to bottom to match with the next object to be inspected;

[0139] Whenever reaching a leaf node, if the match with the reached leaf node is successful (the leaf node first reached in the embodiment of the present invention is <Varname="age">), then determine the parent node with an unmatched right child node from bottom to top (the parent node of <Varname="age"> is object calculation <or>, the right child node of the parent node <Varname="name"> has not been matched).

[0140] (5) Use the next object to be inspected and the parent node <or>Match the unmatched right child node with <Varname="name">.

[0141] (6) If the current object to be inspected matches the right child node <Varname="name"> successfully, then continue to determine the parent nodes with unmatched right child nodes from bottom to top. At this time, the determined parent nodes are the parent nodes of <Struct name="student"> and <Struct name="teacher"> <or>, the unmatched right child node of the parent node is <Structname="teacher">, and the next object to be inspected is matched with the unmatched right child node <Structname="teacher">.

[0142] (7) If the object to be inspected currently being matched fails to match <Struct name="teacher">, first select the right child node of the parent node of the currently failed matching node (which is still <Struct name="teacher">) for matching, and when the continuous matching fails, select the parent nodes one by one from bottom to top. The parent nodes selected in sequence are <object name="class">、 <and>, where <object name="class">Has a right child node, but the right child node is an object calculation <or>, at this time, skip this right child node and <and>Match the right child node <Methodname="Update">.

[0143] (8) If the object to be inspected currently being matched matches successfully with <Methodname="Update">, since <Method name="Update"> is the rightmost leaf node of the binary tree, the traversal of the binary tree is completed at this time, and the matching process ends;

[0144] If the object to be inspected currently being matched fails to match with <Method name="Update">, then, as in step (7), select the parent nodes one by one from bottom to top, and perform matching when the selected parent node has a right child node until the matching is successful or the parent node of the currently matched node is the root node.

[0145] In this embodiment, when the selected parent node is <Methodregx="true" name="^BF">, this parent node has a right child node <and>, at this time due to <and>Calculate segments for the object and the parent node <Methodregx="true" name="^BF"> is the root node. In this case, each next object to be inspected is successively used with <and>Match with the right child node of <Method name="Update">; until a to-be-checked object matches <Method name="Update" successfully, at which point the binary tree traversal is completed and the matching process ends, or until all to-be-checked objects have been traversed and all of them fail to match <Method name="Update", then the matching process ends.

[0146] Further, marking the matching result in the data structure in step S13 includes: assigning check tags to each business object according to the matching result; wherein, the check tags of each business object have a consistent initial tag value.

[0147] As a non-limiting embodiment, the initial tag value of the check tags of each business object can be set to false. If the match is successful, the check tag of the successfully matched business object can be assigned true. If the match fails, the tag value of the check tag of the business object that fails to match remains false unchanged.

[0148] Continue to refer to Figure 1 , in the specific implementation of step S14, it is possible to determine whether the logical relationship indicated by the calculation of each object stored in the data structure is correct according to the tag values of the check tags of each matched business object in the data structure and the initial tag values of each unmatched business object (there is a possibility that there are business objects that have not been matched).

[0149] Refer to Figure 7 , Figure 7 is Figure 1 A flowchart of a specific implementation manner of step S14 in

[0150] In step S71, determine the tag value of the check tag of the object calculation associated with each business object according to the tag value of the check tag of each business object.

[0151] Further, step S71 may include: traversing each object calculation layer by layer from bottom to top, and determining the tag value of the check tag of the object calculation according to the logical relationship indicated by the object calculation and the tag values of the check tags of the child nodes of the object calculation.

[0152] As a non - restrictive embodiment: If the object calculation indicates a logical "AND" relationship, determine whether the label values of the check labels of the child nodes calculated by the object are all true. If so, determine that the label value of the check label calculated by the object is true; otherwise, determine that the label value of the check label calculated by the object is false.

[0153] If the object calculation indicates a logical "OR" relationship, determine whether the label values of the check labels of the child nodes calculated by the object are all false. If so, determine that the label value of the check label calculated by the object is false; otherwise, determine that the label value of the check label calculated by the object is true.

[0154] If the object calculation indicates a logical "NOT" relationship, determine whether the label values of the check labels of the child nodes calculated by the object are all false. If so, determine that the label value of the check label calculated by the object is true; otherwise, determine that the label value of the check label calculated by the object is false.

[0155] In the embodiments of the present invention, by adopting a bottom - up layer - by - layer traversal method, according to the logical relationship indicated by each object calculation and the label value of the check label of the child nodes calculated by the object, the label value of the check label calculated by the object is determined. Thus, the labels of each object calculation in the binary tree can be determined quickly and accurately, improving the accuracy and efficiency of code checking.

[0156] In step S72, according to the label values of the check labels of each determined object calculation, determine whether the logical relationship indicated by each object calculation is correct.

[0157] In the above - mentioned embodiment, for each object calculation, if the label value of the check label of the object calculation is true, it can be determined that the logical relationship indicated by the object calculation is correct; if the label value of the check label of the object calculation is false, it can be determined that the logical relationship indicated by the object calculation is incorrect.

[0158] Further, after step S14, the method further includes: starting from the top - level object storage layer of the data structure, determine whether the code to be checked passes the check according to at least a part of each object calculation.

[0159] Furthermore, the data structure is a binary tree. If there is any path from the root node to the leaf node in the binary tree, and the label values of the check labels of each object calculation on this path are all true, determine that the code to be checked passes the check.

[0160] Combined with Figure 6 , in the binary tree, traverse each object layer by layer from bottom to top for calculation. According to the logical relationship indicated by the calculation of the object and the label values of the check labels of the child nodes calculated by the object, the specific process of determining the label value of the check label calculated by the object is as follows:

[0161] (1) For a node <var name="age">And node <var name="name">Parent node <or>, since the tag values of the check tags for <Varname="age"> and <Varname="name"> are both true, and since <or>Indicates a logical "OR" relationship, and at this time it can be determined that the parent node <or>The label value of the inspection label is true.

[0162] (2) For the parent nodes of the nodes <Struct name="student"> and <Struct name="teacher"> <or>, since the tag value of the check tag of <Struct name="student"> is true and the tag value of the check tag of <Struct name="teacher"> is false, and since <or>Indicates a logical "OR" relationship, and at this time, the parent node can be determined <or>The label value of the check label is true.

[0163] (3) For the node <object name="class">The parent node of <Method name="Update"> <and>, since <object name="class">The label value of the check label is true. If the label value of the check label of <Method name="Update"> is also true, and since <and>Indicates a logical "AND" relationship, and at this time, the parent node can be determined <and>The label value of the check label is true.

[0164] In summary, since there is a path from the root node <Method regx="true" name="^BF"> to the leaf node in the binary tree <var name="age">For any path of <Varname="name">, the tag values of the check tags calculated by each object on this path are all true. At this time, it can be determined that the code to be checked passes the check.

[0165] In the embodiment of the present invention, first, a to-be-converted program including multiple service objects (corresponding to the objects to be checked in the code) and at least one object calculation is determined; then, a preset data structure is used to store each service object and object calculation in the to-be-converted program (where each object calculation is used to indicate the logical relationship of one or more service objects belonging to this object calculation); then, multiple objects to be checked extracted from the code to be checked are matched with at least a part of the service objects stored in the data structure, and whether the logical relationships indicated by each object calculation are correct is determined according to the matching results. Thus, it is possible to automatically check the logical correctness (the logical correctness of the service processes included in the code) between each object to be checked in the code to be checked, improving the accuracy and efficiency of code checking.

[0166] Refer to Figure 8 , Figure 8 is a schematic structural diagram of a code checking device in an embodiment of the present invention. The code checking device may include:

[0167] A to-be-converted program determination module 81, configured to determine a to-be-converted program, where the to-be-converted program includes multiple service objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each service object;

[0168] A data structure conversion module 82, configured to convert the to-be-converted program into a preset data structure, where the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the service object and / or object calculation, and each object calculation is used to indicate the logical relationship of one or more service objects in the object storage layer to which this object calculation belongs;

[0169] A matching module 83, configured to extract objects to be checked according to the code to be checked, match each object to be checked with at least a part of the service objects stored in the data structure one by one, then determine the matching results of each object to be checked and the matched service objects, and mark the matching results in the data structure;

[0170] A logical relationship checking module 84, configured to determine whether the logical relationships indicated by each object calculation are correct according to the matching results of each service object in the marked data structure.

[0171] Regarding the principle, specific implementation and beneficial effects of this code checking device, please refer to the previous text and Figures 1 to 7 the relevant descriptions about the code checking method shown in

[0172] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the steps of the above code checking method are executed. The computer-readable storage medium may include a non-volatile memory or a non-transitory memory, and may also include an optical disc, a mechanical hard disk, a solid-state drive, etc.

[0173] Specifically, in the embodiment of the present invention, the processor may be a central processing unit (CPU for short), and this processor may also be other general-purpose processors, digital signal processors (DSP for short), application specific integrated circuits (ASIC for short), field programmable gate arrays (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or this processor may also be any conventional processor, etc.

[0174] It should also be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of random access memory (RAM) are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchlink dynamic random access memory (SLDRAM), and direct rambus random access memory (DR RAM).

[0175] Embodiments of the present invention also provide a terminal, including a memory and a processor. A computer program capable of running on the processor is stored on the memory. When the processor runs the computer program, it executes the steps of the above code checking method. The terminal may include, but is not limited to, terminal devices such as mobile phones, computers, and tablet computers, and may also be a server, a cloud platform, etc.

[0176] It should be understood that the term "and / or" in this article is only an association relationship describing associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this article indicates that the associated objects before and after are in an "or" relationship.

[0177] In the embodiments of the present application, "a plurality of" means two or more.

[0178] In the embodiments of the present application, the descriptions such as first and second are only used for indicating and distinguishing the described objects, without any order, nor do they represent specific limitations on the number of devices in the embodiments of the present application, and cannot constitute any limitation on the embodiments of the present application.

[0179] It should be noted that the sequence numbers of the steps in this embodiment do not represent the limitation of the execution order of each step.

[0180] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention should be subject to the scope defined by the claims.< / var> < / and> < / and> < / object> < / and> < / object> < / or> < / or> < / or> < / or> < / or> < / or> < / var> < / var> < / and> < / and> < / and> < / and> < / or> < / object> < / and> < / object> < / or> < / or> < / or> < / or> < / or> < / or> < / object> < / object> < / object> < / and> < / and> < / and> < / or> < / or> < / or> < / or> < / or> < / or> < / or> < / or> < / or> < / or> < / var> < / or> < / or> < / object> < / and> < / var> < / or> < / var>

Claims

1. A code checking method, characterized in that, Including: Determine the program to be converted, where the program to be converted includes multiple business objects and at least one object calculation, and the object calculation is used to indicate the logical relationship between each business object; Convert the program to be converted into a preset data structure, where the data structure has multiple layers of object storage layers, and each layer of object storage layer is used to store the business object and / or object calculation, and each object calculation is used to indicate the logical relationship between one or more business objects in the object storage layer to which the object calculation belongs; Extract the objects to be inspected according to the code to be inspected, match each object to be inspected with at least a part of the business objects stored in the data structure one by one, then determine the matching results of each object to be inspected and the matched business objects, and mark the matching results in the data structure; In the marked data structure, determine whether the logical relationship indicated by each object calculation is correct according to the matching results of each business object; Wherein, the method further includes: starting from the top-level object storage layer of the data structure, determine whether the code to be inspected passes the inspection according to at least a part of each object calculation; Wherein, the converting the program to be converted into a preset data structure includes: Extract business objects and object calculations in the program to be converted; Determine the root node of the data structure, and the root node is used to store the first business object in the program to be converted; According to the extraction order, add child nodes layer by layer to the current node, and each newly added child node is used to store the current business object or the next business object or object calculation after the object calculation; Wherein, the preset data structure is a binary tree, and each newly added child node is located in a preset first direction of the current node; The method further includes: If the newly added child node is used to store an object calculation and the object calculation is used to indicate a preset logical relationship, determine the business object associated with the object calculation; Rotate the subtree between the previous business object associated with the object calculation and the object calculation to the subtree in the second direction of the object calculation.

2. The method according to claim 1, characterized in that The determining the program to be converted includes: Select a business template, where the business template includes multiple business elements, and there is a preset business logical relationship between each business element, and there is a preset corresponding relationship between the business element and the business object; According to the business logical relationship between the business elements, determine the logical relationship between the business objects corresponding to each business element; Based on the logical relationship between each business object, the business object and the object calculation, determine the program to be converted.

3. The method according to claim 1, characterized in that, The preset logical relationship is selected from: logical "AND" relationship and logical "OR" relationship.

4. The method according to claim 3, characterized in that, The matching each object to be inspected with at least a part of the business objects stored in the data structure one by one includes: According to the extraction order, match each object to be inspected with the first node stored in the data structure one by one until the matching is successful or all objects to be inspected are traversed; If the match with the first node is successful, in the order of the objects to be inspected, for each object to be inspected starting from the currently successfully matched object to be inspected, match it with the second-direction child nodes of the currently successfully matched node; Whenever a match fails, first select the first-direction child node of the parent node of the currently failed-matched node for matching, and when the continued match fails, select the parent nodes one by one from bottom to top, and perform matching when the selected parent node has a first-direction child node until the match is successful or the parent node of the currently matched node is the root node.

5. The method according to claim 4, characterized in that The step of successively matching the objects to be inspected with at least a part of the business objects stored in the data structure further includes: When the parent node of the currently matched node is the root node and the match fails, then when the current node is a business object, successively use the next object to be inspected to match with the current node, or when the current node is an object calculation, successively use the next object to be detected to match with the right child node of the current node until the match is successful or all the objects to be inspected are traversed.

6. The method according to claim 5, wherein, The step of successively matching the objects to be inspected with at least a part of the business objects stored in the data structure further includes: Whenever a match is successful, use the depth-first traversal algorithm to determine the next node to be matched, and match it with the next object to be inspected of the currently successfully matched object to be inspected.

7. The method according to claim 4, characterized in that, Whenever a match is successful, using the depth-first traversal algorithm to determine the next node to be matched, and matching it with the next object to be inspected of the currently successfully matched object to be inspected includes: Whenever a match is successful, successively select the second-direction child nodes of the currently successfully matched node from top to bottom to match with the next object to be inspected; Whenever reaching a leaf node, if the match with the reached leaf node is successful, determine the parent node with an unmatched first-direction child node from bottom to top, then use the next object to be inspected to match with the unmatched first-direction child node, and when the continued match is successful, successively select the second-direction child nodes of the currently successfully matched node from top to bottom to match with the next object to be inspected until reaching the last leaf node in the first direction of the binary tree or all the objects to be inspected are traversed.

8. The method according to claim 7, characterized in that The step of selecting the second-direction child node of the currently successfully matched node to match with the next object to be inspected includes: Determine whether the currently successfully matched node has a second-direction child node; If the judgment result is yes, use the second-direction child node of the currently successfully matched node to match with the next object to be inspected.

9. The method according to claim 8, wherein The method further includes: If the judgment result is no, use the first-direction child node of the currently successfully matched node to match with the next object to be inspected.

10. The method according to any one of claims 1 to 9, characterized in that, The first direction is the right direction, the child nodes in the first direction are right child nodes, the second direction is the left direction, and the child nodes in the second direction are left child nodes.

11. The method according to claim 1, characterized in that Each business object and object calculation has its own inspection label; The step of marking the match result in the data structure includes: Assign values to the inspection labels of each business object according to the match result; Among them, the check tags of each business object have consistent initial tag values.

12. The method according to claim 11, wherein The determining whether the logical relationships indicated by the calculations of each object are correct according to the matching results of each business object includes: Determining the tag values of the check tags of the object calculations associated with each business object according to the tag values of the check tags of each business object; Determining whether the logical relationships indicated by the calculations of each object are correct according to the determined tag values of the check tags of each object calculation.

13. The method according to claim 12, wherein The determining the tag values of the check tags of the object calculations associated with each business object according to the tag values of the check tags of each business object includes: Traversing each object calculation layer by layer from bottom to top, and determining the tag value of the check tag of the object calculation according to the logical relationship indicated by the object calculation and the tag values of the check tags of the child nodes of the object calculation.

14. The method according to claim 13, wherein The check tag of the business object with a successful match is assigned the value true, and the check tag of the business object with a failed match is assigned the value false; The determining the tag value of the check tag of the object calculation according to the logical relationship indicated by the object calculation and the tag values of the check tags of the child nodes of the object calculation includes: If the object calculation indicates a logical "AND" relationship, then determine whether the tag values of the check tags of the child nodes of the object calculation are all true. If so, determine that the tag value of the check tag of the object calculation is true; otherwise, determine that the tag value of the check tag of the object calculation is false; If the object calculation indicates a logical "OR" relationship, then determine whether the tag values of the check tags of the child nodes of the object calculation are all false. If so, determine that the tag value of the check tag of the object calculation is false; otherwise, determine that the tag value of the check tag of the object calculation is true; If the object calculation indicates a logical "NOT" relationship, then determine whether the tag values of the check tags of the child nodes of the object calculation are all false. If so, determine that the tag value of the check tag of the object calculation is true; otherwise, determine that the tag value of the check tag of the object calculation is false.

15. The method according to claim 14, characterized in that, The data structure is a binary tree; Starting from the top-level object storage layer of the data structure, determining whether the code to be checked passes the check according to at least a part of each object calculation includes: If there is any path from the root node to the leaf node in the binary tree, and the tag values of the check tags of each object calculation on the path are all true, then determine that the code to be checked passes the check.

16. The method according to claim 1, wherein The extracting the objects to be checked according to the code to be checked includes: Performing compilation processing on the code to be checked to obtain an abstract syntax tree, where the order of the nodes in the abstract syntax tree is the same as the order of the objects to be checked in the code to be checked; Determining each object to be checked according to the nodes in the abstract syntax tree.

17. The method according to claim 1, wherein Successively matching each object to be checked with at least a part of the business objects stored in the data structure includes: Using a regular matching algorithm or a string comparison method for matching.

18. The method according to claim 1, characterized in that, The business object contains type information and name information, and the type information of the business object is selected from: Function Method, structure Struct, variable Variable, class Class, and object Object.

19. The method according to claim 1, wherein The logical relationships between business objects in the program to be converted are selected from: Logical "AND" relationship, logical "OR" relationship, and logical "NOT" relationship.

20. A code checking device, characterized in that, Including: A program-to-be-converted determination module for determining a program to be converted, which includes multiple business objects and at least one object calculation for indicating the logical relationships between the respective business objects; A data structure conversion module for converting the program to be converted into a preset data structure, which has multiple object storage layers, and each object storage layer is used to store the business objects and / or object calculations, and each object calculation is used to indicate the logical relationships between one or more business objects in the object storage layer to which the object calculation belongs; A matching module for extracting objects to be inspected according to the code to be inspected, successively matching the objects to be inspected with at least a part of the business objects stored in the data structure, then determining the matching results of the respective objects to be inspected and the matched business objects, and marking the matching results in the data structure; A logical relationship inspection module for determining whether the logical relationships indicated by the respective object calculations are correct according to the matching results of the respective business objects in the marked data structure; Wherein, the device further includes: a module for determining whether the code to be inspected passes the inspection according to at least a part of the respective object calculations starting from the top-level object storage layer of the data structure; Wherein, the data structure conversion module includes: A sub-module for extracting business objects and object calculations in the program to be converted; A sub-module for determining the root node of the data structure, and the root node is used to store the first business object in the program to be converted; A sub-module for successively adding child nodes layer by layer in the current node according to the extraction order, and each newly added child node is used to store the current business object or the next business object or object calculation after the object calculation; Wherein, the preset data structure is a binary tree, and each newly added child node is located in a preset first direction of the current node; The device further includes: A module for determining the business objects associated with the object calculation if the newly added child node is used to store the object calculation and the object calculation is used to indicate a preset logical relationship; A module for rotating the subtree between the previous business object associated with the object calculation and the object calculation into a subtree in a second direction of the object calculation.

21. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is run by a processor, it executes the steps of the code inspection method according to any one of claims 1 to 19.

22. A terminal, comprising a memory and a processor, where a computer program capable of running on the processor is stored on the memory, characterized in that, When the processor runs the computer program, it executes the steps of the code inspection method according to any one of claims 1 to 19.

Citation Information

Patent Citations

  • Code checking method and device

    CN106371997A

  • Code specification checking method, device and system and storage medium

    CN112148581A