Code change influence intelligent analysis method and system based on syntactic structure tree
By constructing a multidimensional dependency graph (SDG) and introducing the BERT model, combined with historical change data, the problems of insufficient multidimensional dependency modeling and weak semantic analysis in existing technologies for code change impact analysis are solved. This enables accurate risk assessment and management of code changes, improving software development efficiency and quality.
Patent Information
- Application Number
- CN202511039586.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-28
- Publication Date
- 2025-11-14
AI Technical Summary
Existing technologies fail to effectively model multi-dimensional dependencies such as control flow, data flow, and call flow in code change impact analysis. They lack support from historical change patterns and version evolution data, and semantic analysis has weak relevance to business, making it difficult to comprehensively assess the impact of changes and identify risk points.
We employ a syntax tree-based approach to construct a multi-dimensional dependency graph (SDG). By combining natural language processing techniques and historical change data, we analyze the multi-dimensional impact and risks of code changes through a multi-layer feature impact assessment model and a two-way impact diffusion algorithm.
It improved the accuracy and comprehensiveness of code change impact analysis, enhanced the understanding of business logic, enabled accurate prediction and efficient management of change risks, and improved software quality and stability.
Smart Images

Figure CN120950077A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer software analysis and software engineering technology, and relates to a method and system for intelligent analysis of the impact of code changes based on a syntax tree structure. Background Technology
[0002] In software development, impact analysis of code changes is a crucial but complex task, involving assessing the potential impact of one or more code changes on the entire software system. Traditional code change impact analysis methods primarily rely on Abstract Syntax Tree (AST) parsing and node extraction techniques. These methods first use tools such as ANTLR to parse the source and target code, generating an AST and extracting statement nodes, internal statement nodes, and word nodes, constructing parent-child, sibling, and other relationships between them. Next, they achieve node mapping by prioritizing mapping nodes with identical types and values in two ASTs and recursively mapping their child nodes. For unmapped nodes of the same type, iterative mapping is performed based on a similarity metric between nodes. Finally, an editing script describing the code changes is generated based on the node mapping results, including operations such as adding, deleting, and updating nodes.
[0003] However, the aforementioned existing technical solutions have obvious limitations:
[0004] Single dependency modeling: Current methods only focus on the structural differences of AST nodes and fail to explicitly model multi-dimensional dependencies such as control flow, data flow, and call flow, which limits their ability to analyze the impact of complex change propagation.
[0005] Limitations of impact assessment dimensions: Impact assessment is based on the structural characteristics of the current changes, lacks support from historical change patterns and version evolution data, and cannot effectively quantify the stability and potential risks of the changes.
[0006] Semantic analysis has weak relevance to business: traditional methods struggle to deeply understand the business logic in the code and are ineffective in identifying risk points closely related to the business.
[0007] The existing technical solutions mentioned above have not yet proposed effective solutions to problems such as the inability of dependency relationships to support multi-dimensional analysis of scenarios and the weak relevance of semantic analysis to business.
[0008] Therefore, how to provide a method and system for intelligent analysis of code change impact that can improve the comprehensiveness of code change impact assessment is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0009] In view of this, this invention proposes an intelligent analysis method and system for the impact of code changes based on a syntax structure tree. It not only focuses on the surface structural changes of the code, but also delves into multiple dimensions such as control flow, data flow, and call flow. At the same time, it utilizes natural language processing technology and historical change data to optimize risk prediction, aiming to provide stronger support for development teams and help them better understand and manage the impact of code changes.
[0010] To achieve the above objectives, the present invention adopts the following technical solution:
[0011] This invention discloses an intelligent analysis method for the impact of code changes based on a syntax structure tree, comprising the following steps:
[0012] S1: Based on the AST generated by parsing the original code and the modified code, extract the control flow, data flow, and call flow, and construct a static dependency graph (SDG) containing multi-dimensional dependencies;
[0013] S2: Construct a multi-layered feature impact assessment model, including feature calculations for the basic layer, business layer, and change annotation layer; among which,
[0014] The base layer is used to compare the differences in AST before and after code changes, and combined with the static dependency graph SDG to identify changes in control flow, data flow, and call flow, and generate a feature vector of syntax structure changes.
[0015] The business layer uses the grammatical structure change feature vector and the business domain template to match the corresponding business label for the changed AST node.
[0016] The change annotation layer is used to obtain historical code change versions, and to build cross-version dependency chains for change AST nodes based on syntax structure change feature vectors, thereby generating historical feature vectors.
[0017] S3: The multi-layer feature impact assessment model uses the feature calculation results of the basic layer, business layer and change labeling layer, combined with the multi-dimensional impact diffusion algorithm to calculate the risk value of the changed AST node, and automatically generates decision suggestions based on the risk value.
[0018] Preferably, step S1 includes:
[0019] S11: Based on the AST, label the type, position and attributes of each node, traverse all nodes in the AST and execute S12~S15;
[0020] S12: Determine whether the current node's node type belongs to a control structure. If yes, generate control flow edges based on the node's execution path and assign weights to the control flow edges; otherwise, proceed to S13.
[0021] S13: Determine whether the current node belongs to the call structure based on the node type and node attributes. If yes, generate call flow edges based on the parameter passing relationship of the node and assign weights to the call flow edges; otherwise, proceed to S14.
[0022] S14: Determine whether the current node belongs to a data structure based on the node attributes and node usage position. If so, generate a data flow edge and assign weights to the data flow edge.
[0023] S15: Based on the control flow edges, call flow edges, data flow edges and their weights in the AST, construct a static dependency graph SDG containing multi-dimensional dependencies.
[0024] Preferably, the syntax structure change feature vector in S2 is: [number of newly added nodes, number of deleted nodes, number of modified nodes, change in control flow complexity, change in call chain depth].
[0025] Preferably, the step in S2 of matching the corresponding business tag for the changed AST node using the business domain template includes:
[0026] S201: Collect comments, variable names, and function names from existing code;
[0027] S202: Use a pre-trained BERT model to semantically encode the annotations, variable names, and function names to generate code embedding vectors;
[0028] S203: Calculate the cosine similarity between the code embedding vector and the predefined business tags, and label the code embedding vectors that exceed the set similarity threshold with the corresponding business tags to generate a semantic tag set;
[0029] S204: Obtain the changed AST node based on the grammatical structure change feature vector, and match the corresponding business tag for the changed AST node in the semantic tag set through the rule engine based on the predefined business domain template.
[0030] Preferably, the step in S2 of constructing a cross-version dependency chain for the changed AST node based on the grammatical structure change feature vector and calculating the historical change frequency includes:
[0031] S211: Store historical code change version information, including package, class, and method change information, and change types, including the change types of added, modified, and deleted AST nodes in the data stream. Identify the cross-version dependency chain of the current change by matching the source code text differences between different versions and the static dependency graph SDG pattern matching.
[0032] S212: Based on the constructed cross-version dependency chain, find the historical path related to the currently changed AST node;
[0033] S213: Calculate the diffusion rate characteristics of the impact of changes to AST nodes in historical versions on the currently changed AST nodes in the current version based on the historical path;
[0034] S214: Calculate the historical change frequency characteristics of the data stream of the currently changed AST node;
[0035] S215: Generate a historical feature vector based on the influence diffusion rate feature and the historical change frequency feature of the data stream.
[0036] Preferably, the multi-dimensional influence diffusion algorithm includes a forward diffusion algorithm, used to perform the following steps:
[0037] In the static dependency graph SDG of the multidimensional dependencies, the multidimensional dependency edges of the modified AST nodes are determined, including the dependency edges of control flow edges, call flow edges and data flow edges.
[0038] Based on the feature calculation results of the basic layer, business layer, and change annotation layer, the initial risk value of the AST node is determined;
[0039] Starting from the changed AST node, the process spreads along the dependent edges, and the final risk value of each affected node is calculated by updating the initial risk value of the AST node.
[0040] Preferably, the multi-dimensional influence diffusion algorithm includes a backdiffusion algorithm, used to perform the following steps:
[0041] In the static dependency graph SDG of the multidimensional dependencies, the multidimensional dependency edges of the modified AST nodes are determined, including the dependency edges of control flow edges, call flow edges and data flow edges.
[0042] Based on the feature calculation results of the basic layer, business layer, and change annotation layer, the initial risk value of the AST node is determined;
[0043] Starting from the predefined key node, the process expands along the dependency edge, traversing to find if the changed AST node appears. If so, an impact-change path is generated, and the final risk value of each AST node on the impact-change path is updated and calculated in combination with the initial risk value of the AST node.
[0044] Preferably, S3 further includes a submission-level risk numerical assessment model for performing the following steps:
[0045] The risk value of the code block in the modified code is calculated based on the sum of the risk values of the changed AST nodes. The code block includes several AST nodes.
[0046] The risk value of a code block is calculated by weighting and aggregating the risk values according to the scope of impact. The scope of impact weights include the weights of core modules and peripheral modules, and the expression is as follows:
[0047] Submission risk value = (code block risk value * impact scope weight) / impact scope weight.
[0048] Preferably, it also includes CI / CD pipeline operation steps:
[0049] When the submitted modified code is detected, execution S1~S3 is automatically triggered;
[0050] If the submitted risk value is greater than a preset threshold, the merging of the modified code into the original code is blocked; otherwise, the modified code is automatically tested and merged into the original code after the test is passed.
[0051] This invention also provides a code change impact intelligent analysis system according to the aforementioned code change impact intelligent analysis method based on a syntax structure tree, comprising:
[0052] The Static Dependency Graph Construction Module is used to extract control flow, data flow, and call flow from the AST generated by parsing the original code and the modified code, and to construct a Static Dependency Graph (SDG) containing multi-dimensional dependencies.
[0053] The multi-layered feature impact assessment module includes:
[0054] The basic layer processing unit is used to compare the differences in AST before and after code changes, and combine the static dependency graph SDG to identify changes in control flow, data flow, and call flow, and generate a feature vector of syntax structure changes.
[0055] The business layer processing unit, based on the grammatical structure change feature vector, uses business domain templates to match corresponding business labels for the changed AST nodes;
[0056] The change annotation layer processing unit is used to obtain historical code change versions, build cross-version dependency chains for change AST nodes based on syntax structure change feature vectors, and generate historical feature vectors;
[0057] The evaluation and decision-making unit uses the feature calculation results of the basic layer, business layer and change annotation layer, combined with the multi-dimensional influence diffusion algorithm, to calculate the risk value of the changed AST node, and automatically generates decision suggestions based on the risk value.
[0058] As can be seen from the above technical solution, compared with the prior art, the beneficial effects of the present invention include:
[0059] Multi-dimensional dependency graph construction improves the accuracy of impact analysis: By explicitly modeling control flow, data flow, and call flow, a static dependency graph (SDG) containing multi-dimensional dependencies is constructed. This allows for the identification of not only the parts of the code that directly call a function that are affected by a change, but also an accurate assessment of the impact of the change on the entire data processing flow.
[0060] Semantic enhancement features enable business risk identification: By introducing BERT semantic labels and domain knowledge, a pre-trained BERT model is used to semantically encode code comments, variable names, and function names, and then cosine similarity calculation is performed with predefined business labels to identify sensitive business nodes. For example, key business logic such as "payment process" and "authorization verification" are more accurately identified, improving the accuracy of risk identification.
[0061] Historical experience features optimize risk prediction: By combining change pattern library and version evolution data, and by storing historical change patterns and matching them with current changes, as well as calculating the historical change frequency of change nodes, more accurate prediction of change risks is achieved.
[0062] The bidirectional impact diffusion algorithm improves impact coverage: It combines forward diffusion and backward tracing. Forward diffusion expands nodes in the order of control flow edges, data flow edges, and call edges, calculating the impact score of each node to comprehensively cover the direct and indirect impacts of changes. Backward tracing starts from predefined key nodes and traces all possible change nodes along dependency edges to generate an "impact-change" path, enabling responsibility attribution. This provides development teams with an efficient and accurate method for troubleshooting and resolving issues, significantly improving the efficiency of software development and maintenance.
[0063] This invention not only improves the accuracy and comprehensiveness of code change impact analysis, but also significantly enhances the ability to understand business logic and the efficiency of utilizing historical data, ultimately helping development teams better manage the risks brought about by code changes and improve software quality and stability. Attached Figure Description
[0064] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0065] Figure 1 A flowchart of the intelligent analysis method for the impact of code changes based on a syntax structure tree provided in this embodiment of the invention;
[0066] Figure 2 A flowchart for generating a static dependency graph (SDG) containing multi-dimensional dependencies is provided for embodiments of the present invention.
[0067] Figure 3 A flowchart for matching corresponding business tags to a changed AST node is provided for embodiments of the present invention;
[0068] Figure 4 A flowchart of the forward diffusion algorithm provided in an embodiment of the present invention;
[0069] Figure 5 A flowchart of the back diffusion algorithm provided in an embodiment of the present invention. Detailed Implementation
[0070] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0071] To facilitate understanding of the technical solutions for intelligent analysis methods and systems based on syntax structure trees regarding the impact of code changes, the principles of existing technologies will first be explained:
[0072] AST parsing and node extraction: Using tools such as ANTLR to parse the source code and target code, generate an abstract syntax tree (AST), extract statement nodes, internal statement nodes and word nodes, and construct parent-child, sibling and other relationships.
[0073] Equal node mapping: Prioritize mapping nodes in two ASTs that have the same type and value (such as statement nodes or internal statement nodes), and recursively map their child nodes.
[0074] Iterative mapping of similar nodes: Based on the similarity measure between nodes (such as the ancestor distance of statement nodes, the matching ratio of descendant nodes, etc.), iterative mapping is performed on unmapped similar nodes until no new mapping is generated.
[0075] Code editing script generation: Based on the node mapping results, generate editing scripts that describe code changes, such as adding, deleting, and updating nodes.
[0076] The first aspect of this invention provides a method for intelligent analysis of the impact of code changes based on a syntax structure tree, such as... Figure 1 As shown, it includes the following steps:
[0077] S1: Based on the AST generated by parsing the original code and the modified code, extract the control flow, data flow, and call flow, and construct a static dependency graph (SDG) containing multi-dimensional dependencies;
[0078] S2: Construct a multi-layered feature impact assessment model, including feature calculations for the basic layer, business layer, and change annotation layer; among which,
[0079] The base layer is used to compare the differences in AST before and after code changes, and combined with the static dependency graph SDG to identify changes in control flow, data flow, and call flow, generating a feature vector of syntax structure changes;
[0080] The business layer changes the feature vector based on the syntax structure and uses business domain templates to match the corresponding business labels for the changed AST nodes.
[0081] The change annotation layer is used to obtain historical code change versions. Based on the syntax structure change feature vector, cross-version dependency chains are built for the change AST nodes to generate historical feature vectors.
[0082] S3: The multi-layer feature impact assessment model uses the feature calculation results of the basic layer, business layer and change annotation layer, combined with the multi-dimensional impact diffusion algorithm to calculate the risk value of the change AST node, and automatically generates decision suggestions based on the risk value.
[0083] The following points need to be explained regarding the extracted control flow, data flow, and call flow:
[0084] Control flow edges: Control flow edges represent the logical order of program execution and have a direct and significant impact on program behavior. Changing the condition of an if statement may alter the execution path of the entire code block, thus significantly affecting certain operations.
[0085] Call flow edges: Call flow edges identify the logical order of function calls within a program, and can affect the interaction logic and data transfer between functions.
[0086] Data flow edges: Data flow edges mainly involve the definition and usage relationships of variables. Although changes in variables directly affect where they are used, this effect is relatively indirect. In the logic of most functions, changes to variables require processing through certain intermediate steps.
[0087] In one embodiment, such as Figure 2 As shown, the steps of S1 include:
[0088] S11: Parse the code file, generate the AST, label the type (e.g., IfStmt, MethodInvocation), position (line number, column number), and attributes (e.g., variable name, function name) of each node, traverse all nodes in the AST and execute S12~S15;
[0089] S12: Determine if the current node's node type belongs to a control structure. If so, generate control flow edges based on the node's execution path and assign weights to the control flow edges; otherwise, proceed to S13. For example, traverse the AST using depth-first search (DFS) to identify control structures such as if, for, and while, and generate control flow edges accordingly.
[0090] IfStmt node → ThenStmt node (execution path when the condition is true);
[0091] ForStmt node → BodyStmt node (loop execution path).
[0092] The control flow edge weight is set to 1.2 (indicating strong dependency).
[0093] S13: Determine whether the current node belongs to the call structure based on the node type and node attributes. If so, generate call flow edges based on the parameter passing relationship of the node and assign weights to the call flow edges; otherwise, proceed to S14. For example, parse the function call expression (such as callFunc()), generate the call edge from CallExpr node to CalleFunc node, and mark the parameter passing relationship (such as the mapping from actual parameters to formal parameters).
[0094] The flow edge weight is set to 1.1 (indicating node relationship dependency).
[0095] S14: Maintain a symbol table to track variable lifecycles. Based on the node attributes and usage position of the current node, determine whether the current node belongs to a data structure. If so, generate a data flow edge and assign weights to the data flow edge. For example, record variable definition (VarDef) and usage (VarUse) nodes: When variable x is defined in line 3 of function F and used in lines 5 and 7, generate data flow edges VarDef(x,3)→VarUse(x,5) and VarDef(x,3)→VarUse(x,7).
[0096] The weight of the data flow edge is set to 0.8 (indicating direct data dependency).
[0097] S15: Based on the corresponding control flow edges, call flow edges, data flow edges and their weights in the AST, construct a static dependency graph (SDG) containing multi-dimensional dependencies.
[0098] This embodiment constructs a static dependency graph (SDG) containing multi-dimensional dependencies by explicitly modeling control flow, data flow, and call flow.
[0099] Take a complex enterprise application as an example, which contains a large number of function calls, conditional statements, and data transfers. With existing technology, a change to a function might only reveal that the code directly calling that function is affected, but it's impossible to accurately determine the impact of the change on the entire data processing flow. However, the multi-dimensional dependency graph of this invention clearly shows that a change to a function affects the execution paths of a series of conditional statements through control flow, influences the values and transmission of related variables through data flow, and thus affects the functionality of multiple modules.
[0100] By using the CallGraph algorithm to generate call chains, the recognition rate of deep call paths (≥5 layers) has been improved from 50% to 89%. In a microservice architecture, the time taken to locate the cascading impact of a utility function deletion on 3 services and 17 interfaces has been reduced from 2 hours to 15 minutes.
[0101] In one embodiment, in S2, the types and quantities of newly added / deleted / modified nodes are identified by comparing AST differences (such as the change set generated by git diff). Adding nodes may introduce new functional modules; modifying nodes may affect the control logic syntax structure. Therefore, the change feature vector is determined as: [number of newly added nodes, number of deleted nodes, number of modified nodes, change in control flow complexity, change in call chain depth].
[0102] In this embodiment, the call chain evaluation step includes: analyzing changes in call flow edges (such as adding a call edge FuncA→FuncB or deleting FuncC→FuncD), calculating the call chain length and dependency depth, and statistically analyzing the changes in the average call chain length and the maximum call depth.
[0103] In one embodiment, step S2, which uses a business domain template to match the corresponding business tag for the changed AST node, includes:
[0104] S201: Collect comments, variable names, and function names from existing code;
[0105] S202: Use a pre-trained BERT model to perform NLP semantic encoding on annotations, variable names, and function names to generate code embedding vectors;
[0106] S203: Calculate the cosine similarity between the code embedding vector and the predefined business tags (such as "payment process" and "authorization verification"). The code embedding vectors that exceed the set similarity threshold are labeled with the corresponding business tags. For example, if the similarity exceeds the threshold of 0.6, the corresponding tag is labeled, and a semantic tag set is generated.
[0107] S204: Obtain the change AST node based on the grammatical structure change feature vector, and match the corresponding business tag for the change AST node in the semantic tag set through the rule engine based on the predefined business domain template (such as "transaction process" and "account management" in the membership system).
[0108] In this embodiment, threshold parameters are configured independently for different code units (classes / methods). For example, if the PaymentService class label changes more than 5 times within 3 months, its risk weight is automatically increased by 30%. If the change node is labeled "safe", its impact weight is increased by 30% in subsequent risk value calculations. If it belongs to the "database operation" domain, its risk level is automatically increased to medium risk in subsequent risk value calculations.
[0109] In one embodiment, LSTM or GPT series models (such as CodeGPT) can be used instead of BERT for semantic encoding to improve the semantic understanding of long code segments.
[0110] In one embodiment, the step in S2 of constructing a cross-version dependency chain for changed AST nodes based on the syntactic structure change feature vector and calculating the historical change frequency includes:
[0111] S211: Store historical code change version information, including package, class, and method change information. Change types include the types of changes such as additions, modifications, and deletions of AST nodes in the data flow. Identify the cross-version dependency chain of the current change by matching the source code text differences between different versions and matching the static dependency graph SDG pattern.
[0112] S212: Based on the constructed cross-version dependency chain, find the historical path related to the currently changed AST node;
[0113] S213: Calculate the diffusion rate characteristics of the impact of changes to AST nodes in historical versions on the currently changed AST nodes in the current version based on historical paths;
[0114] S214: Calculate the historical change frequency characteristics of the data stream of the currently changed AST node;
[0115] S215: Generate historical feature vectors based on the influence diffusion rate characteristics and the historical change frequency characteristics of data streams.
[0116] In this embodiment, step S214, which calculates the historical change frequency characteristics of the data stream of the currently changing AST node, includes one or more of the following:
[0117] Change rate based on commit count = Number of commits containing changes to this class / Total number of commits;
[0118] Change rate based on lines of code = Number of lines changed / Total number of lines in the class;
[0119] Weighted code change rate = (number of modified lines × 1 + number of new lines × 0.8 + number of deleted lines × 0.5) / total number of lines in the class + 3 (number of commits in the past 3 months > 8).
[0120] This embodiment combines a change pattern library and version evolution data, and achieves more accurate prediction of change risks by storing historical change patterns and matching them with current changes, as well as calculating the historical change frequency of change nodes.
[0121] Taking a software project that has been under development for many years as an example, some modules may have undergone frequent changes in the past, and these modules are marked as "unstable modules." When these modules change again, based on historical experience, the probability of them causing defects is relatively high. This invention, through the analysis of historical change data, can promptly identify changes to these "unstable modules" and improve their impact assessment level.
[0122] In practical applications, combining change pattern libraries and version evolution data improves defect prediction accuracy by 38% and unstable module identification accuracy by 89%. This enables development teams to focus on and test high-risk changes, improving software quality and stability.
[0123] In one embodiment, the multi-dimensional influence diffusion algorithm includes a forward diffusion algorithm for performing the following steps:
[0124] In the static dependency graph SDG with multidimensional dependencies, identify the multidimensional dependency edges of the modified AST nodes, including the dependency edges of control flow edges, call flow edges, and data flow edges;
[0125] Based on the feature calculation results of the basic layer, business layer, and change annotation layer, the initial risk value of the AST node is determined;
[0126] Starting from the changed AST node, the process spreads along the dependent edges, and the final risk value of each affected node is calculated by updating the initial risk value of the AST node.
[0127] In this embodiment, the breadth-first search (BFS) algorithm is used to calculate the influence score of a changed node in the entire dependency graph, starting from the node itself. The execution steps are as follows:
[0128] Construct the initial node set: change nodes and their direct dependencies (parent nodes, child nodes, and calling nodes in the SDG). This is because change nodes are the source of influence, and their direct dependencies are likely to be directly affected by changes to the change nodes. For example, in a function call, if the parameters of the called function (change node) change, the function that calls it (call node) is likely to be affected; if the definition of a variable (change node) changes, the nodes that use that variable (child nodes) will also be affected.
[0129] Predefined path priority: control flow (e.g., weight 1.5) > call flow (e.g., weight 1.2) > data flow (e.g., weight 0.8-1.1).
[0130] Initialize the queue and access records:
[0131] Create a queue to perform a breadth-first search and add the change starting node (changeNode) to the queue.
[0132] Create a hash table `visited` to record the final impact score of each node. Initially, add the changed node to this table and set its impact score to its base score `baseScore`.
[0133] Enter the main loop to process nodes in the queue: If the queue is not empty, repeat the following steps:
[0134] Retrieve the currently pending node, currentNode, from the queue.
[0135] Get the current impact score currentScore for this node.
[0136] Traverse all outgoing edges of the current node: For each outgoing edge of the current node (i.e., other nodes it directly affects), perform the following operations:
[0137] Get the neighboring node (i.e. the target node pointed to by the current edge).
[0138] Get the edgeWeight of the current edge, which represents the strength of the dependency between the two nodes or the proportion of the propagation influence.
[0139] Calculate the new influence score of adjacent nodes: Calculate the new influence score that adjacent nodes should receive according to the formula neighborScore=currentScore*edgeWeight.
[0140] Update the influence score of neighboring nodes and continue to spread: If a neighboring node has not been visited (i.e., is not in the visited table), or the newly calculated influence score is higher than the previously recorded one, then update the influence score of that neighboring node to the new value neighborScore.
[0141] Add adjacent nodes to the queue so that subsequent calculations can continue to spread the influence on the score starting from this node.
[0142] Termination condition: When the queue is empty, it means that all nodes that can be directly or indirectly affected through dependencies have been visited and their impact scores have been calculated, and the algorithm ends.
[0143] In one embodiment, the multidimensional influence diffusion algorithm includes a backdiffusion algorithm for performing the following steps:
[0144] In the static dependency graph SDG with multidimensional dependencies, identify the multidimensional dependency edges of the modified AST nodes, including the dependency edges of control flow edges, call flow edges, and data flow edges;
[0145] Based on the feature calculation results of the basic layer, business layer, and change annotation layer, the initial risk value of the AST node is determined;
[0146] Based on depth-first search (DFS), starting from predefined key nodes, the algorithm expands along dependency edges, traversing to find if there are any changed AST nodes. If so, an impact-change path is generated, and the final risk value of each AST node on the impact-change path is updated and calculated in combination with the initial risk value of the AST nodes.
[0147] In one embodiment, the label propagation algorithm (LPA) or PageRank algorithm can also be used to optimize the calculation of influence scores, improving the diffusion efficiency of large-scale codebases. Furthermore, a multi-layer feature influence evaluation model based on reinforcement learning (RL) can be trained to dynamically adjust edge weights and feature weights to adapt to changing patterns in different domains.
[0148] In one embodiment, the generation step of changing the flow view model is also included:
[0149] The process of invoking the flow affects the view generation steps:
[0150] The impact of function changes on the caller, callee, and upstream and downstream modules is identified by calling the flow edge (CallExpr->CalleeFunc): starting from the target node, querying content that has direct and indirect dependencies on the node (FuncA() → FuncB() → checkPermission()). A predefined recursion depth is used, with no more than 3 upstream levels and no more than 7 downstream levels, reducing performance issues caused by deep recursion.
[0151] In addition to the call flow edges, the combined impact of the data flow and the call flow also needs to be considered. Specifically, this involves generating cross-influence paths by combining the data flow and the call flow to identify composite influence paths that simultaneously involve data transfer and function calls.
[0152] Data flow: VarDef(amount, line3) → VarUse(amount, line5) → CallExpr(pay(amount), line5);
[0153] Call flow: CallExpr(pay(amount), line5) → FuncDef(pay(), line10) → CallExpr(notify(), line15);
[0154] Union path: VarDef(amount) → pay(amount) → notify().
[0155] In one embodiment, S3 further includes a submission-level risk numerical assessment model for performing the following steps:
[0156] The risk value of the code block in the modified code is calculated based on the sum of the risk values of the changed AST nodes. The code block includes several AST nodes.
[0157] The code block risk value is calculated by weighting and summing the impact scope weights. The impact scope weights include the weights of core module changes and peripheral module weights. The expression is:
[0158] Submission risk value = (code block risk value * impact scope weight) / impact scope weight.
[0159] In this embodiment, a step of visualizing the risk value of the code block is also included: the risk value of each generated code block is marked with different colors, for example, red - high risk, yellow - medium risk, and green - low risk.
[0160] In this embodiment, suggestions are automatically generated based on the risk level, such as:
[0161] High-risk recommendation: "This submission contains high-risk changes to core modules and requires codeviewing and execution of all test cases."
[0162] Medium-risk recommendation: "It is recommended to focus on testing the interface compatibility of the changed modules."
[0163] In one embodiment, the CI / CD pipeline operation steps are also included:
[0164] When the submitted modified code is detected, execution S1~S3 is automatically triggered;
[0165] Determine if the submitted risk value exceeds a preset threshold (e.g., 70 points). If so, prevent the merge of the modified code into the original code and force a manual review process. If not, automatically execute tests on the modified code and merge it into the original code after the tests pass.
[0166] The second aspect of this invention also discloses a code change impact intelligent analysis system based on a syntax tree structure-based intelligent analysis method for code change impact according to the first aspect of this invention, comprising:
[0167] The Static Dependency Graph Construction Module is used to extract control flow, data flow, and call flow from the AST generated by parsing the original code and the modified code, and to construct a Static Dependency Graph (SDG) containing multi-dimensional dependencies.
[0168] The multi-layered feature impact assessment module includes:
[0169] The basic layer processing unit is used to compare the differences in AST before and after code changes, and to identify changes in control flow, data flow and call flow by combining the static dependency graph SDG, and generate a feature vector of syntax structure changes.
[0170] The business layer processing unit, based on the grammatical structure change feature vector, uses business domain templates to match corresponding business labels for the changed AST nodes;
[0171] The change annotation layer processing unit is used to obtain historical code change versions, build cross-version dependency chains for change AST nodes based on syntax structure change feature vectors, and generate historical feature vectors;
[0172] The evaluation decision-making unit uses the feature calculation results of the basic layer, business layer and change annotation layer, combined with the multi-dimensional influence diffusion algorithm, to calculate the risk value of the changed AST node, and automatically generates decision suggestions based on the risk value.
[0173] The second aspect of the present invention is used to perform all the steps of the first aspect of the present invention.
[0174] The above provides a detailed description of the intelligent analysis method and system for code change impact based on syntax structure tree provided by the present invention. Specific examples are used in this embodiment to illustrate the principle and implementation of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core idea of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation and application scope based on the idea of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
[0175] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined in these embodiments may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for intelligent analysis of the impact of code changes based on a syntax structure tree, characterized in that, Includes the following steps: S1: Based on the AST generated by parsing the original code and the modified code, extract the control flow, data flow, and call flow, and construct a static dependency graph (SDG) containing multi-dimensional dependencies; S2: Construct a multi-layered feature impact assessment model, including feature calculations for the basic layer, business layer, and change annotation layer; among which, The base layer is used to compare the differences in AST before and after code changes, and combined with the static dependency graph SDG to identify changes in control flow, data flow, and call flow, and generate a feature vector of syntax structure changes. The business layer uses the syntactic structure change feature vector and the business domain template to match the corresponding business label for the changed AST node. The change annotation layer is used to obtain historical code change versions, and to build cross-version dependency chains for change AST nodes based on syntax structure change feature vectors, thereby generating historical feature vectors. S3: The multi-layer feature impact assessment model uses the feature calculation results of the basic layer, business layer and change labeling layer, combined with the multi-dimensional impact diffusion algorithm to calculate the risk value of the changed AST node, and automatically generates decision suggestions based on the risk value.
2. The intelligent analysis method for the impact of code changes based on a syntax structure tree, as described in claim 1, is characterized in that... The steps in S1 include: S11: Based on the AST, label the type, position and attributes of each node, traverse all nodes in the AST and execute S12~S15; S12: Determine whether the current node's node type belongs to a control structure. If yes, generate control flow edges based on the node's execution path and assign weights to the control flow edges; otherwise, proceed to S13. S13: Determine whether the current node belongs to the call structure based on the node type and node attributes. If yes, generate call flow edges based on the parameter passing relationship of the node and assign weights to the call flow edges; otherwise, proceed to S14. S14: Determine whether the current node belongs to a data structure based on the node attributes and node usage position. If so, generate a data flow edge and assign weights to the data flow edge. S15: Based on the control flow edges, call flow edges, data flow edges and their weights in the AST, construct a static dependency graph SDG containing multi-dimensional dependencies.
3. The intelligent analysis method for the impact of code changes based on a syntax structure tree as described in claim 1, characterized in that, The syntax structure change feature vector in S2 is: [number of newly added nodes, number of deleted nodes, number of modified nodes, change in control flow complexity, and change in call chain depth].
4. The intelligent analysis method for the impact of code changes based on a syntax structure tree as described in claim 1, characterized in that, The step in S2 of matching the corresponding business label for the changed AST node using the business domain template includes: S201: Collect comments, variable names, and function names from existing code; S202: Use a pre-trained BERT model to semantically encode the annotations, variable names, and function names to generate code embedding vectors; S203: Calculate the cosine similarity between the code embedding vector and the predefined business tags, and label the code embedding vectors that exceed the set similarity threshold with the corresponding business tags to generate a semantic tag set; S204: Obtain the changed AST node based on the grammatical structure change feature vector, and match the corresponding business tag for the changed AST node in the semantic tag set through the rule engine based on the predefined business domain template.
5. The intelligent analysis method for the impact of code changes based on a syntax tree structure according to claim 1, characterized in that, The steps in S2, which involve constructing a cross-version dependency chain for changed AST nodes based on syntactic structure change feature vectors and calculating historical change frequencies, include: S211: Store historical code change version information, including package, class, and method change information, and change types, including the change types of added, modified, and deleted AST nodes in the data stream. Identify the cross-version dependency chain of the current change by matching the source code text differences between different versions and the static dependency graph SDG pattern matching. S212: Based on the constructed cross-version dependency chain, find the historical path related to the currently changed AST node; S213: Calculate the diffusion rate characteristics of the impact of changes to AST nodes in historical versions on the currently changed AST nodes in the current version based on the historical path; S214: Calculate the historical change frequency characteristics of the data stream of the currently changed AST node; S215: Generate a historical feature vector based on the influence diffusion rate feature and the historical change frequency feature of the data stream.
6. The intelligent analysis method for the impact of code changes based on a syntax structure tree according to claim 1, characterized in that, The multi-dimensional influence diffusion algorithm includes a forward diffusion algorithm, which performs the following steps: In the static dependency graph SDG of the multidimensional dependencies, the multidimensional dependency edges of the modified AST nodes are determined, including the dependency edges of control flow edges, call flow edges and data flow edges. Based on the feature calculation results of the basic layer, business layer, and change annotation layer, the initial risk value of the AST node is determined; Starting from the changed AST node, the process spreads along the dependent edges, and the final risk value of each affected node is calculated by updating the initial risk value of the AST node.
7. The intelligent analysis method for the impact of code changes based on a syntax structure tree as described in claim 1, characterized in that, The multi-dimensional influence diffusion algorithm includes a back-diffusion algorithm, which performs the following steps: In the static dependency graph SDG of the multidimensional dependencies, the multidimensional dependency edges of the modified AST nodes are determined, including the dependency edges of control flow edges, call flow edges and data flow edges. Based on the feature calculation results of the basic layer, business layer, and change annotation layer, the initial risk value of the AST node is determined; Starting from the predefined key node, the process expands along the dependency edge, traversing to find if the changed AST node appears. If so, an impact-change path is generated, and the final risk value of each AST node on the impact-change path is updated and calculated in combination with the initial risk value of the AST node.
8. The intelligent analysis method for the impact of code changes based on a syntax tree structure according to claim 1, characterized in that, S3 also includes a submission-level risk numerical assessment model for performing the following steps: The risk value of the code block in the modified code is calculated based on the sum of the risk values of the changed AST nodes. The code block includes several AST nodes. The risk value of a code block is calculated by weighting and aggregating the risk values according to the scope of impact. The scope of impact weights include the weights of core modules and peripheral modules, and the expression is as follows: Submission risk value = (code block risk value * impact scope weight) / impact scope weight.
9. The intelligent analysis method for the impact of code changes based on a syntax tree structure according to claim 8, characterized in that, It also includes CI / CD pipeline operation steps: When the submitted modified code is detected, execution S1~S3 is automatically triggered; If the submitted risk value is greater than a preset threshold, the merging of the modified code into the original code is blocked; otherwise, the modified code is automatically tested and merged into the original code after the test is passed.
10. A code change impact intelligent analysis system based on a syntax tree structure-based code change impact intelligent analysis method according to any one of claims 1-9, characterized in that, include: The Static Dependency Graph Construction Module is used to extract control flow, data flow, and call flow from the AST generated by parsing the original code and the modified code, and to construct a Static Dependency Graph (SDG) containing multi-dimensional dependencies. The multi-layered feature impact assessment module includes: The basic layer processing unit is used to compare the differences in AST before and after code changes, and combine the static dependency graph SDG to identify changes in control flow, data flow, and call flow, and generate a feature vector of syntax structure changes. The business layer processing unit, based on the grammatical structure change feature vector, uses business domain templates to match corresponding business labels for the changed AST nodes; The change annotation layer processing unit is used to obtain historical code change versions, build cross-version dependency chains for change AST nodes based on syntax structure change feature vectors, and generate historical feature vectors; The evaluation and decision-making unit uses the feature calculation results of the basic layer, business layer and change annotation layer, combined with the multi-dimensional influence diffusion algorithm, to calculate the risk value of the changed AST node, and automatically generates decision suggestions based on the risk value.
Citation Information
Patent Citations
Development method and system of software development platform
CN119718278A
Multi-modal feature fusion software supply chain vulnerability intelligent positioning method
CN120068095A
Program display device, program display system, program display method, and program display program
JP2017004282A
Code change pattern mining program and code change pattern mining method
JP2022114722A
Methods, systems, apparatuses and devices for facilitating change impact analysis (CIA) using modular program dependency graphs
US20190361686A1
Cited By
Code detection method and device and storage medium
CN121411819A
Open source component risk assessment method and apparatus, and electronic device
CN121615144A
Automatic evaluation monitoring method and system based on multi-dimensional code quality
CN122219957A
Automated assessment and monitoring methods and systems based on multi-dimensional code quality
CN122219957B
