Code processing method and device, electronic equipment and computer program product

By building a program logic structure tree, checksum complexity detection, building complexity coefficients, determining the target to modify the code, solving the problem of low accuracy in code complexity evaluation, and achieving the elimination of code redundancy and logical defects and the reduction of code complexity.

CN119739609APending Publication Date: 2025-04-01INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411929334.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-25
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

In the prior art, when evaluating code complexity, there is a low evaluation accuracy rate and it is impossible to determine the complex code that needs to be optimized.

Method used

By obtaining the code to be detected, building the program logic structure tree, performing checksum complexity detection, building complexity coefficients, and determining the target modification code.

Benefits of technology

It improves the accuracy of code complexity recognition, recognizes and eliminates redundancy and logical defects in the code, reduces code complexity, and improves code operation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739609A_ABST
    Figure CN119739609A_ABST
Patent Text Reader

Abstract

The invention discloses a code processing method and device, electronic equipment and a computer program product. The method relates to the technical field of information and comprises the steps that M codes to be detected are obtained, a program logic structure tree is constructed based on each code to be detected, M program logic structure trees are obtained, and M is a positive integer; the M program logic structure trees are verified, M verification results are obtained, and each verification result is used for representing whether each to-be-detected code is abnormal or not; performing complexity detection on each to-be-detected code to obtain M pieces of complexity data; and constructing a complexity coefficient of each to-be-detected code according to the M verification results and the M complexity data, and determining a target modification code from the M to-be-detected codes according to the M complexity coefficients. Through the method and the device, the technical problem that the complex code needing to be optimized cannot be determined due to low evaluation accuracy when the code complexity is evaluated in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information technology, and in particular to a code processing method, device, electronic device and computer program product. Background Art

[0002] In the increasingly complex information technology environment, especially for large financial institutions, the stability and maintainability of software systems have become crucial factors. Software systems in the financial field often need to process large amounts of transaction data and execute complex business logic. At this time, the execution code needs to be able to complete tasks efficiently and accurately, and be easy to understand and modify. However, with the continuous iteration of business needs, the scale of applications has gradually expanded, and the complexity of the code has also increased. Under the pressure of urgent vulnerability repairs or adding new features, developers usually add or remove fields based on the original code, resulting in problems such as overly complex logic, redundant code snippets, and inefficient module design in the code. This accumulated code complexity not only makes the system difficult to understand and maintain, but also may cause any small changes to trigger a chain reaction due to subtle dependencies and redundant code paths, seriously affecting the stability of the system and the efficiency of code development, and thus seriously affecting the sustainability of the software. Therefore, it is necessary to evaluate the complexity of the code.

[0003] When evaluating and controlling the complexity of code, related technologies mainly measure the structural complexity of the program by calculating cyclomatic complexity, etc. However, although this single evaluation standard based on structural complexity can provide a measure of structural complexity, it has blind spots in the analysis of the semantics, functions and relationships between modules of the code. That is, this method easily ignores the use of complex functions, the existence of redundant code, and the problems of low cohesion and high coupling. Although these problems will not directly increase the value of cyclomatic complexity, they will significantly reduce the readability and maintainability of the code, increase the difficulty of subsequent development and debugging, and may even introduce new errors.

[0004] There is a technical problem in the related art that when evaluating code complexity, the evaluation accuracy is low, and thus the complex code that needs to be optimized cannot be determined. Currently, no effective solution has been proposed. Summary of the invention

[0005] The main purpose of the present application is to provide a code processing method, device, electronic device and computer program product to solve the technical problem in the related art that when evaluating code complexity, the evaluation accuracy is low and the complex code that needs to be optimized cannot be determined.

[0006] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a code processing method is provided. The method comprises: obtaining M codes to be detected, constructing a program logic structure tree based on each code to be detected, and obtaining M program logic structure trees, wherein M is a positive integer; respectively verifying the M program logic structure trees, and obtaining M verification results, wherein each verification result is used to characterize whether each code to be detected has an abnormality; performing complexity detection on each code to be detected, and obtaining M complexity data; constructing a complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determining a target modification code from the M codes to be detected according to the M complexity coefficients.

[0007] Furthermore, a program logic structure tree is constructed based on each code to be detected to obtain M program logic structure trees, including: for each code to be detected, the code structure of the code to be detected is determined, and the code to be detected is parsed according to the code structure to obtain a group of parsed code fields; the logic code field is extracted from the group of parsed code fields, and the branch characters in the logic code field are extracted to obtain N branch characters, wherein N is a positive integer; the logic code field is segmented according to the N branch characters to obtain segmented logic code fields; and a program logic structure tree associated with the code to be detected is generated from the segmented logic code field, wherein the program logic structure tree includes N branches, and each branch corresponds to a code field associated with a branch character.

[0008] Further, M program logic structure trees are verified respectively to obtain M verification results, including: for a program logic structure tree, obtaining the execution strategy associated with the program logic structure tree, and judging whether the execution strategy has a performance fault, and obtaining a first judgment result, wherein the performance fault includes at least one of the following: an implicit conversion fault, an index fault, and a scanning fault; obtaining a function identification tool, and using the function identification tool to judge whether the program logic structure tree calls P logic functions, wherein the logic function refers to the function compiled by the development object, and P is a positive integer; in the case where the program logic structure tree calls the logic function, obtaining L preset logic functions stored in the database, and judging whether the P logic functions match the L preset logic functions, and obtaining a second judgment result, wherein L is a positive integer; in the case where the first judgment result indicates that the execution strategy has a performance fault, obtaining the total number of faults, and in the case where the second judgment result indicates that the P logic functions match the L preset logic functions, extracting the total number of matching functions; determining the verification result of the program logic structure tree according to the total number of faults and the total number of matching functions.

[0009] Furthermore, M program logic structure trees are verified respectively to obtain M verification results, including: for a program logic structure tree, when running the code to be detected corresponding to the program logic structure tree, obtaining the number of unused variables in the program logic structure tree to obtain a first number, wherein the unused variables refer to variables that are not used when the code to be detected is run; obtaining the total number of exception capture statements associated with the program logic structure tree to obtain a second number, and obtaining the total number of exception keywords in the program logic structure tree to obtain a third number; calculating the sum of the first number, the second number and the third number to obtain a verification sum, and determining the verification result of the logic structure tree based on the verification sum.

[0010] Furthermore, M program logic structure trees are verified respectively to obtain M verification results, including: for a program logic structure tree, traversing the program logic structure tree, obtaining the function keyword, and obtaining the preset function keyword stored in the database; judging whether the function keyword matches the preset function keyword, and when the function keyword matches the preset function keyword, obtaining the total number of matching keywords, and when the total number of matching keywords is greater than a first preset threshold, generating a verification result indicating the existence of coupling; obtaining the total number of deadlock codes in the program logic structure tree, and when the total number of deadlock codes is greater than a second preset threshold, generating a verification result indicating the existence of deadlock.

[0011] Furthermore, complexity detection is performed on each code to be detected to obtain M complexity data including: for a code to be detected, Y preset control statements of the code to be detected are obtained, wherein the Y preset control statements include at least conditional statements, loop statements and exception handling keywords, and Y is a positive integer; a control flow graph is constructed using the Y preset control statements, Y cyclomatic complexities are calculated based on the control flow graph, and the Y cyclomatic complexities are merged to obtain first complexity data; an operation field of the code to be detected is obtained, and the operation field is processed using a preset complexity function to obtain second complexity data, wherein the operation field includes an operator and operation data, and the operation data refers to the object on which the operator acts; the first complexity data and the second complexity data are merged to obtain complexity data of the code to be detected.

[0012] Furthermore, a complexity coefficient of each code to be detected is constructed from M verification results and M complexity data, and a target modification code is determined from the M codes to be detected according to the M complexity coefficients, including: for a code to be detected, a preset weight is obtained, and the verification result and complexity data of the code to be detected are weightedly calculated using the preset weight to obtain a complexity coefficient; the M complexity coefficients are sorted in descending order to obtain a complexity queue, and the complexity coefficient with the largest value is obtained from the complexity queue, and the code to be detected associated with the complexity coefficient with the largest value is determined as the target modification code.

[0013] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a code processing device is provided. The device comprises: an acquisition unit, used to acquire M codes to be detected, construct a program logic structure tree based on each code to be detected, and obtain M program logic structure trees, wherein M is a positive integer; a verification unit, used to verify the M program logic structure trees respectively, and obtain M verification results, wherein each verification result is used to characterize whether each code to be detected has an abnormality; a detection unit, used to perform complexity detection on each code to be detected, and obtain M complexity data; a construction unit, used to construct a complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determine the target modification code from the M codes to be detected according to the M complexity coefficients.

[0014] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium including a stored executable program, wherein when the executable program is running, a processing method for controlling a device where the computer-readable storage medium is located to execute any of the above codes.

[0015] According to another aspect of an embodiment of the present invention, there is also provided an electronic device, comprising one or more processors and a memory, wherein the memory stores an executable program, and the processor is used to run the program, wherein when the one or more programs are executed by one or more processors, the one or more processors implement a processing method for any one of the above codes.

[0016] According to another aspect of an embodiment of the present invention, a computer program product is provided. The computer program product includes a computer program, wherein when the computer program is executed by a processor, any one of the above-mentioned code processing methods is implemented.

[0017] In an embodiment of the present application, a code processing method is adopted, by obtaining M codes to be detected, constructing a program logic structure tree based on each code to be detected, and obtaining M program logic structure trees, wherein M is a positive integer; the M program logic structure trees are respectively verified to obtain M verification results, wherein each verification result is used to characterize whether each code to be detected has an abnormality; a complexity test is performed on each code to be detected to obtain M complexity data; a complexity coefficient of each code to be detected is constructed from the M verification results and the M complexity data, and a target modification code is determined from the M codes to be detected according to the M complexity coefficients, and a program logic structure tree is constructed from each code to be detected, and performance verification and complexity test are performed on each program logic structure tree respectively, and then the complexity coefficient of each code is determined, and the code to be modified is determined according to multiple complexity coefficients, thereby achieving the purpose of improving the accuracy of code complexity recognition, thereby achieving the technical effect of eliminating redundancy and logical defects in the code after identifying the complex code, reducing the code complexity and improving the code running efficiency, and thus solving the technical problem that the evaluation accuracy is low when evaluating the code complexity, and then the complex code that needs to be optimized cannot be determined. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a code processing method;

[0020] Figure 2 is a flowchart of a code processing method provided according to an embodiment of the present application;

[0021] Figure 3 is a schematic diagram of a code processing device provided according to an embodiment of the present application;

[0022] Figure 4 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0023] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0025] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set up between this system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.

[0026] It should be noted that the collected information used in this application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse to use it.

[0027] Example 1

[0028] According to an embodiment of the present application, a method embodiment of code processing is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0029] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 It is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a code processing method, such as Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more ( Figure 1102a, 102b, ..., 102n are used to illustrate) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU (Microcontroller Unit) or a programmable logic device FPGA (Field-Programmable Gate Array)), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a keyboard, a cursor control device, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0030] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As involved in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0031] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the code processing method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, realizing the above-mentioned code processing method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0032] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC) and a network interface, which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0033] The display may be, for example, a touch screen liquid crystal display (LCD), which may enable a user to interact with a user interface of the computer terminal 10 (or mobile device).

[0034] Under the above operating environment, this application provides Figure 2 The processing method of the code shown. Figure 2 is a flowchart of a code processing method provided in an embodiment of the present application, such as Figure 2 As shown, the method comprises the following steps:

[0035] Step S201, obtaining M codes to be detected, constructing a program logic structure tree based on each code to be detected, and obtaining M program logic structure trees, wherein M is a positive integer.

[0036] Specifically, the code to be tested refers to the code in the financial institution that contains multiple functions or business logics. In order to perform complexity testing on these codes, a program logic structure tree can be generated based on the code to be tested, where the program logic structure tree not only includes the grammatical structure of the code, but also includes the details of the control flow and data flow, such as conditional statements (such as if-else statements), loop structures (such as for statements and while statements), function calls, variable assignments, database operations, etc. By constructing the above program logic structure tree, the logical flow of each code module can be visually clear, which is convenient for further analysis and understanding.

[0037] Step S202, respectively verify the M program logic structure trees to obtain M verification results, wherein each verification result is used to indicate whether there is an abnormality in each code to be detected.

[0038] Specifically, in order to ensure the quality and functional correctness of the code, before performing a complexity check on each program logic structure tree, it is necessary to determine whether the structure tree has code anomalies, that is, to perform semantic verification and functional inspection of the code, and then comprehensively evaluate the health of the code and promptly identify possible anomalies or potential problems. When verifying the program logic structure tree, it can be subjected to structural anomaly detection, semantic anomaly detection, functional anomaly detection, etc. Among them, structural anomaly detection can be used to identify overly complex control flow structures, such as too deep nesting, redundant loops and conditional branches; semantic anomaly detection can be used to check whether the code has semantic errors, such as unused variables, invalid function calls, incorrect data type conversions, etc.; functional anomaly detection can be used to verify whether the logic of the code meets the expected functional requirements, for example, by simulating input and output or using a unit test framework to verify the correctness of the function.

[0039] Step S203: perform complexity detection on each code to be detected to obtain M complexity data.

[0040] Specifically, in order to quantify the complexity of software code and identify code segments that may need to be optimized or refactored, thereby improving the operating efficiency of the entire software, each code to be tested can be tested for complexity, for example, through cyclomatic complexity, Halstead complexity, etc. Cyclomatic complexity calculates the cyclomatic complexity of the code by analyzing the nesting and branching of control flow statements, which can indirectly reflect the testability and potential maintenance costs of the code; Halstead complexity calculates Halstead complexity by counting the operators and operands in the code, which can evaluate the complexity and scale of the code. After completing the complexity test of each code to be tested, the corresponding complexity data can be generated, and each set of data corresponds to the specific complexity index value of a code module.

[0041] Step S204: construct the complexity coefficient of each code to be detected based on the M verification results and the M complexity data, and determine the target modified code from the M codes to be detected according to the M complexity coefficients.

[0042] Specifically, since the verification results reflect the abnormalities of the code module in terms of function, semantics and structure, and the complexity data quantifies the structural complexity of the code, after each code to be checked is checked and the complexity is calculated, each verification result can be converted into a numerical value to indicate the severity and number of the abnormality, and the numerical value and complexity data after each verification result is converted to construct a complexity coefficient, and the target modification code is determined from all the codes to be checked based on these coefficients. When selecting the target modification code, the complexity coefficients can be sorted according to the numerical value, and the code to be checked corresponding to the complexity coefficient with the highest numerical value is determined as the target modification code. It should be noted that when converting the verification results into numerical values, it can be achieved in the following way: first, a weight value is set, and the more or more serious the abnormalities represented by the verification results, the higher the corresponding numerical value is, and then the multiple complexity indicators of each code are weighted and summed, and finally a comprehensive complexity score is obtained.

[0043] It should be noted that after determining the target modification code, these codes can be modified, such as refactoring the code structure, reducing unnecessary nesting and branches, and optimizing the control flow structure; correcting the functional anomalies pointed out in the verification results, such as adding missing exception handling, optimizing database operations or function calls, etc.; eliminating redundant code, improving the cohesion of the code, reducing coupling, and improving the overall clarity of the code.

[0044] The code processing method provided in the embodiment of the present application obtains M codes to be detected, constructs a program logic structure tree based on each code to be detected, and obtains M program logic structure trees, wherein M is a positive integer; respectively checks the M program logic structure trees to obtain M check results, wherein each check result is used to characterize whether each code to be detected has an abnormality; performs complexity check on each code to be detected to obtain M complexity data; constructs the complexity coefficient of each code to be detected from the M check results and the M complexity data, and determines the target modification code from the M codes to be detected according to the M complexity coefficients, thereby solving the technical problem that the evaluation accuracy of code complexity is low in the related art, and thus the complex code that needs to be optimized cannot be determined. By constructing a program logic structure tree from each code to be detected, respectively performing performance check and complexity check on each program logic structure tree, and then determining the complexity coefficient of each code, the code that needs to be modified is determined according to multiple complexity coefficients, thereby achieving the technical effect of eliminating redundancy and logical defects in the code after identifying the complex code, reducing the code complexity and improving the code running efficiency.

[0045] Optionally, in the code processing method provided in the embodiment of the present application, a program logic structure tree is constructed based on each code to be detected, and M program logic structure trees are obtained, including: for each code to be detected, the code structure of the code to be detected is determined, and the code to be detected is parsed according to the code structure to obtain a set of parsed code fields; the logic code field is extracted from the set of parsed code fields, and the branch characters in the logic code field are extracted to obtain N branch characters, wherein N is a positive integer; the logic code field is segmented according to the N branch characters to obtain the segmented logic code field; and the program logic structure tree associated with the code to be detected is generated from the segmented logic code field, wherein the program logic structure tree includes N branches, and each branch corresponds to a code field associated with a branch character.

[0046] Specifically, when constructing the program logic structure tree of each code to be detected, it is first necessary to identify the basic structure of the code to be detected, wherein the code structure may include the syntax framework of the code, function or method definition, variable declaration, database operation command, etc. In addition, since the code to be detected can realize business logic and application functions, can call stored procedures or interact with other services, the stored procedures can also be identified. It should be noted that the stored procedures can provide high-performance data operations and enhance the security and consistency of data processing. Its basic structure is expressed as "CREATE OR REPLACE PROCEDURE stored procedure name (input parameter / output parameter) IS / AS variable definition BEGIN main logic code END exception branch", wherein "CREATE OR REPLACE PROCEDURE" represents the command to create or replace the stored procedure; "stored procedure name" defines the name of the stored procedure and the input parameters and output parameters it receives; "IS / AS" represents the keywords used to separate the declaration part and the execution part in the stored procedure language, which can define variables, constants, cursors and exceptions, etc.; "variable definition" can define the variables to be used in the stored procedure; "BEGIN main logic code END" refers to the execution part of the stored procedure.

[0047] In order to facilitate subsequent analysis, the code to be tested can be parsed according to the code structure and decomposed into a set of parsed code fields, where these fields can be function definitions, loop structures, conditional branches, database operation statements, etc. Then, the logic code fields are screened and extracted from the above parsed code fields, that is, the code fields containing control flow statements (such as if-else statements, for loop statements, switch-case statements), etc. are screened. Then, the branch characters in these fields are identified and extracted, such as if-else statements, when statements, etc., so that the logic code fields can be segmented according to the branch characters to obtain multiple independent segmented logic code fields, and each segmented logic code field corresponds to a specific logic branch, which helps to clearly display the code of each logic branch and facilitates the subsequent structure tree construction and complexity analysis.

[0048] Furthermore, a program logic structure tree associated with the code to be detected can be generated from the segmented logic code field, wherein the program logic structure tree, as a graphical representation, can visualize the control flow structure of the code, each branch character corresponds to a branch in the structure tree, and each branch is associated with the code field associated with the character, and the program logic structure tree not only clearly displays the logic flow of the code, but also intuitively presents the nested and loop structure of the code. This embodiment processes the code to be detected and then constructs a program logic structure tree, making the structure and logic flow of the code intuitive, and then can accurately locate abnormal branches in the code, such as redundant if-else structures, complex loop nesting, missing exception handling, etc., through detailed code field segmentation and logic structure analysis, to provide guidance for subsequent repair work.

[0049] Optionally, in the code processing method provided in the embodiment of the present application, M program logic structure trees are verified respectively to obtain M verification results, including: for a program logic structure tree, obtaining the execution strategy associated with the program logic structure tree, and judging whether the execution strategy has a performance fault, and obtaining a first judgment result, wherein the performance fault includes at least one of the following: an implicit conversion fault, an index fault, and a scanning fault; obtaining a function identification tool, and using the function identification tool to judge whether the program logic structure tree calls P logic functions, wherein the logic function refers to the function compiled by the development object, and P is a positive integer; in the case where the program logic structure tree calls the logic function, obtaining L preset logic functions stored in the database, and judging whether the P logic functions match the L preset logic functions, and obtaining a second judgment result, wherein L is a positive integer; in the case where the first judgment result indicates that the execution strategy has a performance fault, obtaining the total number of faults, and in the case where the second judgment result indicates that the P logic functions match the L preset logic functions, extracting the total number of matching functions; determining the verification result of the program logic structure tree according to the total number of faults and the total number of matching functions.

[0050] Specifically, after obtaining the program logic structure tree corresponding to each code to be detected, the execution strategy corresponding to the program logic structure tree can be first obtained through the EXPLAIN keyword, wherein the execution strategy can include query statements, function calls, etc. in the code to be detected. Then, the above execution strategy is judged for performance failures, for example, whether there is an implicit conversion failure, that is, whether there is an implicit type conversion in the query statement, which performance failure is likely to reduce data processing efficiency and increase the computational burden at runtime; whether there is an index failure, whether there is an index missing, index redundancy or index mismatch, which performance failure is likely to reduce the query speed, for example, whether the query statement effectively uses the database index when querying; whether there is a scan failure, that is, whether the query statement performs a full table scan or an inefficient table scan. Through the above inspection, a first judgment result can be generated, that is, an evaluation report on whether the execution strategy has the above performance failure.

[0051] Furthermore, a function identification tool can be used to check whether the program logic structure tree calls the logic function compiled by the development object. If there is a call to the logic function, it is necessary to obtain multiple preset logic functions from the database storage, and determine whether the logic function matches the preset logic function, and then obtain the second judgment result, that is, determine whether there is an available function with the same effect in the database, where the preset logic function refers to a logic function that is similar in function to the logic function called in the code, but has better performance or is more in line with coding standards.

[0052] When the first judgment result indicates that there is a performance failure in the execution strategy, it is necessary to count the total number of all performance failures (i.e., the total number of failures). At the same time, if the second judgment result indicates that one or more logic functions match one or more preset logic functions in the database, it is also necessary to count the total number of matching functions. Finally, a verification result for evaluating the code performance status and the efficiency of the use of logic functions is generated based on the total number of failures and the total number of matching functions. This embodiment performs performance failure verification based on the execution strategy and uses logic functions for matching verification to obtain verification results, which can significantly improve the performance and logical clarity of the code and lay the foundation for the subsequent selection of target code modification.

[0053] Optionally, in the code processing method provided in the embodiment of the present application, M program logic structure trees are checked separately to obtain M verification results, including: for a program logic structure tree, when running the code to be checked corresponding to the program logic structure tree, obtaining the number of unused variables in the program logic structure tree to obtain a first number, wherein the unused variables refer to variables that are not used when the code to be checked is run; obtaining the total number of exception capture statements associated with the program logic structure tree to obtain a second number, and obtaining the total number of exception keywords in the program logic structure tree to obtain a third number; calculating the sum of the first number, the second number and the third number to obtain a verification sum, and determining the verification result of the logic structure tree based on the verification sum.

[0054] Specifically, while verifying the program logic result tree, you can also verify the usage of variables, exception capture statements, and the use of exception keywords in the code, and then comprehensively evaluate the health of the code. First, on the basis of static analysis, run the code to be tested through unit testing, integration testing, etc., and obtain the usage of variables in the code and the mechanism of exception capture and processing. For example, since unused variables will not only increase the redundancy of the code, but also increase the compilation time and memory consumption, it is necessary to obtain the total number of unused variables during the code running process to obtain the first number; the exception capture statement (such as the absence of the EXCEPTION branch in the code to be tested) is a key structure in the code for handling potential runtime errors. At this time, you can also analyze the program logic structure tree to count the total number of exception capture statements and the number of times the exception keywords (such as the EXCEPTION keyword, RAISE keyword, etc.) in the code are used, so as to obtain the second and third numbers.

[0055] Then the number of unused variables (first number), the total number of exception capture statements (second number) and the total number of exception keywords (third number) are summarized to obtain a checksum that characterizes potential code problems, and finally the checksum can be used to determine the check result of the program logic structure tree. This embodiment obtains multiple parameters that affect the operation of the code, and can determine the check result based on these data, thereby identifying the blind spots of exception handling in the code, ensuring that all possible exceptions are properly captured and handled, and improving the stability of the code.

[0056] Optionally, in the code processing method provided in the embodiment of the present application, M program logic structure trees are checked respectively to obtain M verification results, including: for a program logic structure tree, traversing the program logic structure tree, obtaining function keywords, and obtaining preset function keywords stored in the database; determining whether the function keyword matches the preset function keyword, and when the function keyword matches the preset function keyword, obtaining the total number of matching keywords, and when the total number of matching keywords is greater than a first preset threshold, generating a verification result indicating the existence of coupling; obtaining the total number of deadlock codes in the program logic structure tree, and when the total number of deadlock codes is greater than a second preset threshold, generating a verification result indicating the existence of deadlock.

[0057] Specifically, when checking the program logic structure tree separately, it is also possible to extract functional keywords representing specific functions or operations in the code by traversing the program logic structure tree. For example, functional keywords may include data query keywords, data update keywords, function call keywords, etc. At the same time, a preset functional keyword list for matching and analyzing the functional keywords of the actual code can be obtained from the database, wherein the list contains multiple standard functional keywords.

[0058] Furthermore, the extracted function keywords are compared with the preset function keywords to determine whether there is a match. If the function keywords match the preset keywords, it indicates that similar functions or operations are shared between the codes, that is, there may be a high coupling problem between the code modules, especially when the total number of matching keywords exceeds the first preset threshold, a verification result of "coupling exists" can be generated.

[0059] In addition, when traversing the program logic structure tree, it is also possible to check whether there is code in the code that may cause deadlock. For example, the deadlock code may include concurrent control instructions (such as locking or transaction management), circularly dependent resource requests, incorrect locking order, etc. After obtaining the total number of deadlock codes, if the number exceeds the second preset threshold, it indicates that there is a deadlock risk, and a verification result of "deadlock exists" can be generated, and then the coupling degree of the code and the potential deadlock risk are comprehensively evaluated according to the above two verification methods. This embodiment can determine the complexity of the code based on the verification results by judging whether there are coupling problems and deadlock risks in the program logic structure tree, and then provide data support for selecting target modification codes.

[0060] Optionally, in the code processing method provided in the embodiment of the present application, a complexity check is performed on each code to be detected to obtain M complexity data including: for a code to be detected, Y preset control statements of the code to be detected are obtained, wherein the Y preset control statements include at least conditional statements, loop statements and exception handling keywords, and Y is a positive integer; a control flow graph is constructed using the Y preset control statements, Y cyclomatic complexities are calculated based on the control flow graph, and the Y cyclomatic complexities are merged to obtain first complexity data; an operation field of the code to be detected is obtained, and the operation field is processed using a preset complexity function to obtain second complexity data, wherein the operation field includes an operator and operation data, and the operation data refers to the object on which the operator acts; the first complexity data and the second complexity data are merged to obtain complexity data of the code to be detected.

[0061] Specifically, in order to comprehensively and accurately quantify the structural complexity and data processing complexity of the code, first, the preset control statements that can reflect the logical complexity and control flow structure of each code to be detected can be obtained, wherein the preset control statements can include conditional statements (such as if-else statements, switch-case statements), loop statements (such as for statements, while statements) and exception handling keywords (such as try statements, catch statements, throw statements). Then, the above preset control statements are used to construct a control flow graph that can clearly display the execution logic and structure of the code, wherein the control flow graph can visualize the path and branches of code execution, wherein each node represents a basic block in the code (that is, a series of continuous statements, in which there is no control transfer), and the edges between nodes represent the transfer direction of the control flow.

[0062] After obtaining the control flow graph, the cyclomatic complexity of each control statement can be calculated based on the control flow graph: cyclomatic complexity (V) = EN + 2P, where E represents the number of edges in the control flow graph, N represents the number of nodes in the control flow graph, and P represents the number of connected components of the control flow graph. After calculating the cyclomatic complexity of all control statements, these cyclomatic complexities are merged to obtain the first complexity data reflecting the complexity of the code control flow structure. It should be noted that for conditional statements and loop statements, the cyclomatic complexity will increase accordingly with each additional nesting or branch. The larger the cyclomatic complexity value, the higher the complexity of the code, indicating that more test cases are needed to cover all possible paths, which also means that the code is more difficult to understand and maintain.

[0063] Furthermore, after calculating the cyclomatic complexity, the operation fields of the code to be detected and the operation data they act on can also be obtained, and then the operation fields and the operation data they act on are calculated through a preset complexity function, so as to obtain the Halsted complexity (that is, the second complexity data) that characterizes the logical complexity of data processing: by counting the number of different operators, the number of different operands, the total number of occurrences of operators and the total number of occurrences of operands in the code, the above data are used to calculate the lexical complexity (that is, the total number of different operators and operands) and the program length (that is, the total number of operators and operands), and then the second complexity data is calculated based on the above data, wherein the operation fields may include operators in the code (such as arithmetic operators, logical operators, bit operators, etc., and the operation data may include variables, constants, function return values, etc.

[0064] Finally, the first complexity data and the second complexity data are combined to generate complexity data for evaluating the overall complexity of the code to be detected. This embodiment calculates complexity data using two complexity calculation methods, which can promote the improvement of code quality, reduce potential errors and maintenance costs, and improve the readability, maintainability and scalability of the code.

[0065] Optionally, in the code processing method provided in the embodiment of the present application, a complexity coefficient of each code to be detected is constructed by M verification results and M complexity data, and a target modification code is determined from the M codes to be detected according to the M complexity coefficients, including: for a code to be detected, obtaining a preset weight, and using the preset weight to perform weighted calculation on the verification result and complexity data of the code to be detected to obtain a complexity coefficient; sorting the M complexity coefficients in descending order to obtain a complexity queue, and obtaining the complexity coefficient with the largest value from the complexity queue, and determining the code to be detected associated with the complexity coefficient with the largest value as the target modification code.

[0066] Specifically, in order to determine the target modification code that needs to be modified, first, a preset weight including multiple sub-weights can be obtained, each sub-weight can correspond to the verification result and complexity data, and then the verification result and complexity data are weighted calculated using the preset weights to obtain a complexity coefficient. Finally, the obtained complexity coefficients are sorted in descending order to obtain a complexity queue, and the code module corresponding to the complexity coefficient with the largest value is determined as the target modification code that most needs to be optimized. This embodiment uses the complexity coefficient to determine the target modification code, which can help the development team quickly locate the most complex and potentially problematic parts of the code, and give priority to code review, reconstruction and optimization, thereby significantly improving response speed and processing power.

[0067] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0068] Example 2

[0069] The embodiment of the present application also provides a code processing device. It should be noted that the code processing device of the embodiment of the present application can be used to execute the code processing method provided by the embodiment of the present application. The code processing device provided by the embodiment of the present application is introduced below.

[0070] According to an embodiment of the present application, a device for implementing the above code processing method is also provided. Figure 3 is a schematic diagram of a code processing device provided according to an embodiment of the present application, such as Figure 3 As shown, the device includes: an acquisition unit 30, a verification unit 31, a detection unit 32, and a construction unit 33.

[0071] The acquisition unit 30 is used to acquire M codes to be detected, construct a program logic structure tree based on each code to be detected, and obtain M program logic structure trees, where M is a positive integer;

[0072] The verification unit 31 is used to verify the M program logic structure trees respectively to obtain M verification results, wherein each verification result is used to indicate whether each code to be detected has an abnormality;

[0073] A detection unit 32, configured to perform complexity detection on each code to be detected to obtain M complexity data;

[0074] The construction unit 33 is used to construct the complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determine the target modified code from the M codes to be detected according to the M complexity coefficients.

[0075] The code processing device provided in the embodiment of the present application obtains M codes to be detected through an acquisition unit 30, constructs a program logic structure tree based on each code to be detected, and obtains M program logic structure trees, wherein M is a positive integer; the verification unit 31 verifies the M program logic structure trees respectively to obtain M verification results, wherein each verification result is used to characterize whether each code to be detected has an abnormality; the detection unit 32 performs complexity detection on each code to be detected to obtain M complexity data; the construction unit 33 constructs the complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determines the target modification code from the M codes to be detected according to the M complexity coefficients, thereby solving the technical problem that the evaluation accuracy of the code complexity is low in the related art, and thus the complex code that needs to be optimized cannot be determined. By constructing a program logic structure tree from each code to be detected, performance verification and complexity detection are performed on each program logic structure tree respectively, and then the complexity coefficient of each code is determined, and the code that needs to be modified is determined according to multiple complexity coefficients, thereby achieving the technical effect of eliminating redundancy and logical defects in the code after identifying the complex code, reducing the code complexity and improving the code running efficiency.

[0076] Optionally, in the code processing device provided in the embodiment of the present application, the acquisition unit 30 includes: a first determination module, used to determine the code structure of the code to be detected for each code to be detected, and parse the code to be detected according to the code structure to obtain a set of parsed code fields; an extraction module, used to extract the logic code field from the set of parsed code fields, and extract the branch characters in the logic code field to obtain N branch characters, wherein N is a positive integer; a segmentation module, used to segment the logic code field according to the N branch characters to obtain the segmented logic code field; a generation module, used to generate a program logic structure tree associated with the code to be detected from the segmented logic code field, wherein the program logic structure tree includes N branches, and each branch corresponds to a code field associated with a branch character.

[0077] Optionally, in the code processing device provided in the embodiment of the present application, the verification unit 31 includes: a first acquisition module, which is used to obtain the execution strategy associated with the program logic structure tree for a program logic structure tree, and determine whether the execution strategy has a performance fault, and obtain a first judgment result, wherein the performance fault includes at least one of the following: an implicit conversion fault, an index fault, and a scanning fault; a second acquisition module, which is used to obtain a function identification tool, and use the function identification tool to determine whether the program logic structure tree calls P logic functions, wherein the logic function refers to the function compiled by the development object, and P is a positive integer; a third acquisition module, which is used to obtain L preset logic functions stored in the database when the program logic structure tree calls the logic function, and determine whether the P logic functions match the L preset logic functions to obtain a second judgment result, wherein L is a positive integer; a fourth acquisition module, which is used to obtain the total number of faults when the first judgment result indicates that the execution strategy has a performance fault, and extract the total number of matching functions when the second judgment result indicates that the P logic functions match the L preset logic functions; a second determination module, which is used to determine the verification result of the program logic structure tree according to the total number of faults and the total number of matching functions.

[0078] Optionally, in the code processing device provided in the embodiment of the present application, the verification unit 31 includes: a fifth acquisition module, which is used to obtain the number of unused variables in a program logic structure tree for a program logic structure tree when running the code to be detected corresponding to the program logic structure tree, and obtain a first number, wherein the unused variables refer to variables that are not used when the code to be detected is running; a sixth acquisition module, which is used to obtain the total number of exception capture statements associated with the program logic structure tree, and obtain a second number, and obtain the total number of exception keywords in the program logic structure tree, and obtain a third number; a calculation module, which is used to calculate the sum of the first number, the second number and the third number, and obtain a checksum, and determine the verification result of the logic structure tree based on the checksum.

[0079] Optionally, in the code processing device provided in the embodiment of the present application, the verification unit 31 includes: a traversal module, which is used to traverse the program logic structure tree for a program logic structure tree, obtain the function keyword, and obtain the preset function keyword stored in the database; a judgment module, which is used to judge whether the function keyword and the preset function keyword match, and when the function keyword and the preset function keyword match, obtain the total number of matching keywords, and when the total number of matching keywords is greater than a first preset threshold, generate a verification result indicating the existence of coupling; a seventh acquisition module, which is used to obtain the total number of deadlock codes in the program logic structure tree, and when the total number of deadlock codes is greater than a second preset threshold, generate a verification result indicating the existence of deadlock.

[0080] Optionally, in the code processing device provided in the embodiment of the present application, the detection unit 32 includes: an eighth acquisition module, used to obtain Y preset control statements of a code to be detected, wherein the Y preset control statements include at least conditional statements, loop statements and exception handling keywords, and Y is a positive integer; a construction module, used to construct a control flow graph using the Y preset control statements, calculate Y cyclomatic complexities based on the control flow graph, and merge the Y cyclomatic complexities to obtain first complexity data; a ninth acquisition module, used to obtain an operation field of the code to be detected, and process the operation field using a preset complexity function to obtain second complexity data, wherein the operation field includes an operator and operation data, and the operation data refers to the object on which the operator acts; a merging module, used to merge the first complexity data and the second complexity data to obtain the complexity data of the code to be detected.

[0081] Optionally, in the code processing device provided in the embodiment of the present application, the construction unit 33 includes: a tenth acquisition module, used to obtain a preset weight for a code to be detected, and use the preset weight to perform weighted calculation on the verification result and complexity data of the code to be detected to obtain a complexity coefficient; a sorting module, used to sort the M complexity coefficients in descending order to obtain a complexity queue, and obtain the complexity coefficient with the largest value from the complexity queue, and determine the code to be detected associated with the complexity coefficient with the largest value as the target modification code.

[0082] It should be noted that the acquisition unit 30, the verification unit 31, the detection unit 32, and the construction unit 33 correspond to steps S201 to S204 in Example 1, and the four units and the corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in the above-mentioned Example 1. It should be noted that the above-mentioned modules or units can be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n), and the above-mentioned units can also be part of the device and can be run in the computer terminal 10 provided in Example 1.

[0083] Example 3

[0084] The embodiment of the present application may provide a computer terminal, which may be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the computer terminal may also be replaced by a terminal device such as a mobile terminal or an electronic device.

[0085] Optionally, in this embodiment, the computer terminal may be located in at least one network device among a plurality of network devices of the computer network.

[0086] In this embodiment, the above-mentioned computer terminal can execute the program code of the following steps in the code processing method: obtain M codes to be detected, construct a program logic structure tree based on each code to be detected, and obtain M program logic structure trees, wherein M is a positive integer; verify the M program logic structure trees respectively to obtain M verification results, wherein each verification result is used to characterize whether there is an abnormality in each code to be detected; perform complexity detection on each code to be detected to obtain M complexity data; construct a complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determine the target modification code from the M codes to be detected according to the M complexity coefficients.

[0087] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the code processing method: construct a program logic structure tree based on each code to be detected, and obtain M program logic structure trees including: for each code to be detected, determine the code structure of the code to be detected, and parse the code to be detected according to the code structure to obtain a group of parsed code fields; extract the logic code field from the group of parsed code fields, and extract the branch characters in the logic code field to obtain N branch characters, wherein N is a positive integer; segment the logic code field according to the N branch characters to obtain the segmented logic code field; generate a program logic structure tree associated with the code to be detected from the segmented logic code field, wherein the program logic structure tree includes N branches, and each branch corresponds to a code field associated with a branch character.

[0088] Optionally, the computer terminal can execute the program code of the following steps in the code processing method: for a program logic structure tree, obtain the execution strategy associated with the program logic structure tree, and determine whether the execution strategy has a performance failure to obtain a first judgment result, wherein the performance failure includes at least one of the following: an implicit conversion failure, an index failure, and a scanning failure; obtain a function identification tool, and use the function identification tool to determine whether the program logic structure tree calls P logic functions, wherein the logic function refers to the function compiled by the development object, and P is a positive integer; in the case where the program logic structure tree calls the logic function, obtain L preset logic functions stored in the database, and determine whether the P logic functions match the L preset logic functions to obtain a second judgment result, wherein L is a positive integer; in the case where the first judgment result indicates that the execution strategy has a performance failure, obtain the total number of failures, and in the case where the second judgment result indicates that the P logic functions match the L preset logic functions, extract the total number of matching functions; determine the verification result of the program logic structure tree based on the total number of failures and the total number of matching functions.

[0089] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the code processing method: for a program logic structure tree, when running the code to be detected corresponding to the program logic structure tree, obtain the number of unused variables in the program logic structure tree to obtain a first number, wherein the unused variables refer to variables that are not used when running the code to be detected; obtain the total number of exception capture statements associated with the program logic structure tree to obtain a second number, and obtain the total number of exception keywords in the program logic structure tree to obtain a third number; calculate the sum of the first number, the second number and the third number to obtain a checksum, and determine the check result of the logic structure tree based on the checksum.

[0090] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the code processing method: for a program logic structure tree, traverse the program logic structure tree to obtain the function keyword, and obtain the preset function keyword stored in the database; determine whether the function keyword and the preset function keyword match, and when the function keyword and the preset function keyword match, obtain the total number of matching keywords, and when the total number of matching keywords is greater than a first preset threshold, generate a verification result that coupling exists; obtain the total number of deadlock codes in the program logic structure tree, and when the total number of deadlock codes is greater than a second preset threshold, generate a verification result that deadlock exists.

[0091] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the code processing method: for a code to be detected, obtain Y preset control statements of the code to be detected, wherein the Y preset control statements include at least conditional statements, loop statements and exception handling keywords, and Y is a positive integer; use the Y preset control statements to construct a control flow graph, calculate Y cyclomatic complexities based on the control flow graph, and merge the Y cyclomatic complexities to obtain first complexity data; obtain the operation field of the code to be detected, and use the preset complexity function to process the operation field to obtain second complexity data, wherein the operation field includes an operator and operation data, and the operation data refers to the object on which the operator acts; merge the first complexity data and the second complexity data to obtain the complexity data of the code to be detected.

[0092] Optionally, the above-mentioned computer terminal can execute the program code of the following steps in the code processing method: for a code to be detected, obtain a preset weight, use the preset weight to perform weighted calculation on the verification result and complexity data of the code to be detected, and obtain a complexity coefficient; sort the M complexity coefficients in descending order to obtain a complexity queue, and obtain the complexity coefficient with the largest value from the complexity queue, and determine the code to be detected associated with the complexity coefficient with the largest value as the target modification code.

[0093] Optionally, Figure 4is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 4 As shown, the electronic device may include: one or more ( Figure 4 (only one is shown) processor 402, memory 404, storage controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.

[0094] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the code processing method and device in the embodiment of the present application, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned code processing method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0095] The processor can call the information and application programs stored in the memory through the transmission device to execute the above steps in the above code processing method.

[0096] By adopting the embodiment of the present application, a solution for code processing is provided. By obtaining M codes to be detected, a program logic structure tree is constructed based on each code to be detected, and M program logic structure trees are obtained, wherein M is a positive integer; the M program logic structure trees are respectively verified to obtain M verification results, wherein each verification result is used to characterize whether each code to be detected has an abnormality; each code to be detected is subjected to complexity detection to obtain M complexity data; the complexity coefficient of each code to be detected is constructed from the M verification results and the M complexity data, and the target modification code is determined from the M codes to be detected according to the M complexity coefficients, thereby achieving the purpose of improving the accuracy of code complexity recognition, and further solving the technical problem that the evaluation accuracy is low when evaluating the code complexity, and thus the complex code that needs to be optimized cannot be determined.

[0097] It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only, and the electronic device may also be a smart phone, a tablet computer, a PDA, a mobile Internet device (MID), a PAD or other terminal device. Figure 4 The structure of the electronic device is not limited. Figure 4 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 4 Different configurations are shown.

[0098] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0099] Example 4

[0100] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the code processing method provided in the first embodiment.

[0101] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.

[0102] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: obtaining M codes to be detected, constructing a program logic structure tree based on each code to be detected, and obtaining M program logic structure trees, wherein M is a positive integer; verifying the M program logic structure trees respectively, and obtaining M verification results, wherein each verification result is used to characterize whether there is an abnormality in each code to be detected; performing complexity detection on each code to be detected, and obtaining M complexity data; constructing a complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determining the target modification code from the M codes to be detected according to the M complexity coefficients.

[0103] The present application also provides a computer program product which, when executed on a data processing device, is suitable for executing the program of the processing method steps of the code.

[0104] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0105] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0106] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0107] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0108] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0109] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), mobile hard disk, disk or optical disk, etc., which can store program code.

[0110] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A code processing method, characterized in that: include: Obtain M codes to be detected, and construct a program logic structure tree based on each code to be detected to obtain M program logic structure trees, where M is a positive integer; Verifying the M program logic structure trees respectively to obtain M verification results, wherein each verification result is used to indicate whether each code to be detected has an abnormality; Perform complexity detection on each code to be detected to obtain M complexity data; The complexity coefficient of each code to be detected is constructed by the M verification results and the M complexity data, and the target modified code is determined from the M codes to be detected according to the M complexity coefficients.

2. The method according to claim 1, characterized in that A program logic structure tree is constructed based on each code to be detected, and M program logic structure trees are obtained, including: For each code to be detected, determine the code structure of the code to be detected, and parse the code to be detected according to the code structure to obtain a set of parsed code fields; Extracting a logic code field from the set of parsed code fields, and extracting branch characters in the logic code field to obtain N branch characters, where N is a positive integer; Segment the logic code field according to the N branch characters to obtain segmented logic code fields; A program logic structure tree associated with the code to be detected is generated from the segmented logic code field, wherein the program logic structure tree includes N branches, and each branch corresponds to a code field associated with a branch character.

3. The method according to claim 1, characterized in that The M program logic structure trees are verified respectively, and M verification results are obtained, including: For a program logic structure tree, obtaining an execution strategy associated with the program logic structure tree, and determining whether the execution strategy has a performance failure, to obtain a first determination result, wherein the performance failure includes at least one of the following: an implicit conversion failure, an index failure, and a scan failure; Obtain a function identification tool, and use the function identification tool to determine whether the program logic structure tree calls P logic functions, wherein the logic function refers to a function compiled by the development object, and P is a positive integer; In the case where the program logic structure tree calls the logic function, obtaining L preset logic functions stored in the database, and determining whether the P logic functions match the L preset logic functions to obtain a second determination result, wherein L is a positive integer; When the first judgment result indicates that the execution strategy has the performance fault, the total number of faults is obtained; when the second judgment result indicates that the P logic functions match the L preset logic functions, the total number of matching functions is extracted; The verification result of the program logic structure tree is determined according to the total number of faults and the total number of matching functions.

4. The method according to claim 1, characterized in that: The M program logic structure trees are verified respectively, and M verification results are obtained, including: For a program logic structure tree, when running the code to be detected corresponding to the program logic structure tree, obtaining the number of unused variables in the program logic structure tree to obtain a first number, wherein the unused variables refer to variables that are not used when the code to be detected is run; Obtaining the total number of exception capture statements associated with the program logic structure tree to obtain a second number, and obtaining the total number of exception keywords in the program logic structure tree to obtain a third number; A sum of the first number, the second number, and the third number is calculated to obtain a checksum, and a check result of the logical structure tree is determined based on the checksum.

5. The method according to claim 1, characterized in that The M program logic structure trees are verified respectively, and M verification results are obtained, including: For a program logic structure tree, traverse the program logic structure tree to obtain function keywords, and obtain preset function keywords stored in the database; Determine whether the function keyword matches the preset function keyword, and if the function keyword matches the preset function keyword, obtain the total number of matching keywords, and if the total number of matching keywords is greater than a first preset threshold, generate a verification result indicating coupling exists; The total number of deadlock codes in the program logic structure tree is obtained, and when the total number of deadlock codes is greater than a second preset threshold, a verification result indicating the existence of a deadlock is generated.

6. The method according to claim 1, characterized in that Perform complexity detection on each code to be detected, and obtain M complexity data including: For a code to be detected, obtain Y preset control statements of the code to be detected, wherein the Y preset control statements at least include conditional statements, loop statements and exception handling keywords, and Y is a positive integer; constructing a control flow graph using the Y preset control statements, calculating Y cyclomatic complexities based on the control flow graph, and merging the Y cyclomatic complexities to obtain first complexity data; Obtaining an operation field of the code to be detected, and processing the operation field using a preset complexity function to obtain second complexity data, wherein the operation field includes an operator and operation data, and the operation data refers to an object on which the operator acts; The first complexity data and the second complexity data are combined to obtain the complexity data of the code to be detected.

7. The method according to claim 1, characterized in that Constructing a complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determining a target modification code from the M codes to be detected according to the M complexity coefficients includes: For a code to be detected, a preset weight is obtained, and a verification result and complexity data of the code to be detected are weightedly calculated using the preset weight to obtain a complexity coefficient; The M complexity coefficients are sorted in descending order to obtain a complexity queue, and the complexity coefficient with the largest value is obtained from the complexity queue, and the code to be detected associated with the complexity coefficient with the largest value is determined as the target modified code.

8. A code processing device, characterized in that: include: An acquisition unit is used to acquire M codes to be detected, and construct a program logic structure tree based on each code to be detected to obtain M program logic structure trees, where M is a positive integer; A verification unit, used to verify the M program logic structure trees respectively to obtain M verification results, wherein each verification result is used to indicate whether each code to be detected has an abnormality; A detection unit, used for performing complexity detection on each code to be detected to obtain M complexity data; A construction unit is used to construct a complexity coefficient of each code to be detected from the M verification results and the M complexity data, and determine a target modified code from the M codes to be detected according to the M complexity coefficients.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is run, the device where the computer-readable storage medium is located is controlled to execute the code processing method according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: A memory storing an executable program; A processor, used to run the program, wherein the program executes the code processing method described in any one of claims 1 to 7 when running.

11. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the steps of the code processing method described in any one of claims 1 to 7 are implemented.