Code calling visualization control method and system based on AST

By calling visual control methods based on AST to analyze and visualize the dependencies between software units, the problem of insufficient accuracy and high complexity of traditional analysis methods is solved, and the accuracy and efficiency of software development are improved.

CN118626070APending Publication Date: 2024-09-10BEIJING LINGWEI JUNRONG TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410518919.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-28
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

Traditional dependency analysis methods have problems such as insufficient accuracy, high computational complexity, and difficulty in ensuring coverage, which results in limited decision-making quality and efficiency in the software development process.

Method used

The AST-based code call visual control method builds an abstract syntax tree by parsing the source code, analyzes the dependencies between code units, including calling relationships, data dependencies and inheritance relationships, and displays them visually.

Benefits of technology

It improves the accuracy and efficiency of dependency analysis, helps developers better understand and maintain code, supports code reconstruction, automated test generation, code search and other fields, and improves the quality and efficiency of software development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626070A
    Figure CN118626070A
Patent Text Reader

Abstract

The invention provides a code calling visualization control method and system based on AST. The AST-based code calling visualization control method comprises the following steps: constructing an abstract syntax tree by analyzing source code files corresponding to different code units, and representing a code structure and grammar through the abstract syntax tree; performing code analysis on different code units to obtain a dependency relationship among the different code units; traversing the abstract syntax trees corresponding to the different code units respectively, and obtaining a dependency relationship between codes contained in the code units according to information data contained in the abstract syntax trees; and visually displaying the dependency relationship among the different code units and the dependency relationship among the codes contained in the code units. The system comprises modules corresponding to the steps of the method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention proposes a code call visualization control method and system based on AST, belonging to the technical field of software analysis and static code analysis. Background Art

[0002] In the process of software development, understanding the dependencies between software units is crucial for code refactoring, performance optimization, modular design, etc. Traditional dependency analysis methods are usually based on static analysis or dynamic analysis techniques, but the above methods have some limitations, such as low accuracy and high computational complexity.

[0003] At the same time, traditional dependencies not only affect the structure and quality of the code, but are also directly related to the maintainability, scalability and performance of the software. In order to effectively refactor the code, improve system performance and implement modular design, it is necessary to clearly understand the interactions between various software units. However, traditional dependency analysis methods, whether based on static code review or dynamic runtime monitoring, have some difficult-to-overcome problems. Static analysis may lead to insufficient accuracy due to the complexity of the code, while dynamic analysis may face problems such as high computational complexity and difficulty in ensuring coverage. The above limitations make it difficult to accurately capture dependencies, thereby affecting the decision-making quality and efficiency in the software development process. Therefore, exploring more accurate and efficient dependency analysis methods has become an urgent need in the field of software development. Summary of the invention

[0004] The present invention provides a code call visualization control method and system based on AST. The dependency analysis technology based on AST of the present invention can more accurately capture the dependencies between software units by directly parsing the grammatical structure of the code, thereby improving the accuracy and efficiency of the analysis. By analyzing AST, the calling relationship, data dependency, inheritance relationship, etc. between software units can be identified, thereby helping developers to better understand and maintain the code. In addition, the dependency analysis technology based on AST can also be applied to code reconstruction, automated test generation, code search and other fields, providing more possibilities and conveniences for the software development process. In order to solve the problems existing in the above-mentioned prior art, the technical solutions adopted are as follows:

[0005] The code call visualization control method based on AST includes:

[0006] Constructing an abstract syntax tree by parsing source code files corresponding to different code units, and representing the code structure and syntax through the abstract syntax tree;

[0007] Perform code analysis on different code units to obtain dependency relationships between the different code units;

[0008] Traversing the abstract syntax trees corresponding to the different code units, and acquiring the dependency relationship between the codes contained in the code units themselves according to the information data contained in the abstract syntax trees;

[0009] The dependencies between the different code units and the dependencies between the codes contained in the code units themselves are visually displayed.

[0010] Furthermore, an abstract syntax tree is constructed by parsing the source code files corresponding to different code zones, including:

[0011] Retrieving different code units and source code files corresponding to the code units;

[0012] Performing code parsing using a lexical analysis method on the source code file corresponding to each code unit to obtain lexical units contained in the source code file of the code unit;

[0013] Decomposing the lexical units according to preset grammatical rules using a grammatical analyzer to obtain expressions, statements and / or functions contained in each lexical unit;

[0014] Taking the expressions, statements and / or functions contained in the lexical unit as nodes;

[0015] A tree structure corresponding to each lexical unit is constructed using the nodes, and an abstract syntax tree corresponding to the code unit is generated using the tree structure.

[0016] Furthermore, code analysis is performed on different code units to obtain dependencies between the different code units, including:

[0017] Retrieving different code units and abstract syntax trees corresponding to the code units;

[0018] Traverse the abstract syntax tree corresponding to each code unit;

[0019] Record the calling relationship, inheritance relationship and inclusion relationship contained in the abstract syntax tree corresponding to each code unit;

[0020] Using a graph data structure to represent the calling relationship, inheritance relationship and inclusion relationship as dependencies, and constructing a dependency graph including the calling relationship, inheritance relationship and inclusion relationship corresponding to each code unit;

[0021] The dependency graph corresponding to each code unit is traversed using the depth-first search method to identify the direct and indirect dependencies between each code unit.

[0022] Further, performing code analysis on different code units to obtain dependency relationships between the different code units also includes:

[0023] Real-time monitoring of the number of calls between every two code units during the running of the code units;

[0024] Real-time monitoring of the number of logic types contained in the dependency relationship between every two code units during the running of the code units;

[0025] Real-time monitoring of the modification of one code unit in each of two code units, and synchronization of the modification information of the corresponding code modification of the other code unit with which the code unit has a dependency relationship; wherein the modification information includes the number of modifications and the coverage of the modified code;

[0026] The code modification impact value corresponding to each code unit is obtained by using the modification times and the modified code coverage; wherein the code modification impact value is obtained by the following formula:

[0027]

[0028] Wherein, Q represents the code modification impact value corresponding to each code unit; n represents the number of modifications that the other code unit performs synchronously when a code modification occurs in one of the two code units; P i represents the modified code coverage rate of another code unit when it is modified for the i-th time; λ represents the numerical adjustment coefficient; wherein the numerical adjustment coefficient is obtained by the following formula:

[0029]

[0030] Where m represents the total number of code modifications in one of every two code units; k represents the number of code lines contained in the other code unit; f i Indicates the number of modified positions in the i-th line of code; B i represents the code modification coverage when the i-th line of code is modified; w i Indicates the ratio of the number of logical types contained in the i-th line of code of every two code units to the total number of logical types contained in the other code unit when a code modification occurs in one of the other two code units;

[0031] The dependency strength value between every two code units is obtained by using the code modification impact value corresponding to each code unit in combination with the number of calls between every two code units corresponding to the code unit and the number of logic types contained in the dependency relationship between every two code units, wherein the dependency strength value is obtained by the following formula:

[0032]

[0033] Where W represents the dependency strength value between every two code units; r represents the number of calls between every two code units when a code unit is grouped with another code unit; R represents the number of logical types contained in the dependency relationship between every two code units; M represents the total number of all logical types contained in every two code units; N i Indicates the number of logical operations executed by the code unit during the i-th call;

[0034] When the dependency strength value exceeds a preset strength value threshold, the dependency relationship between the two code units corresponding to the dependency strength values ​​exceeding the preset strength value threshold is marked.

[0035] Furthermore, traversing the abstract syntax trees corresponding to the different code units, and acquiring the dependency relationship between the codes contained in the code units themselves according to the information data contained in the abstract syntax trees, includes:

[0036] Use depth-first search to traverse the nodes corresponding to the abstract syntax tree corresponding to the code unit;

[0037] Identify and record the dependencies between nodes corresponding to the abstract syntax tree in real time; wherein the dependencies between the nodes include the relationship between the function caller and the called function, the location where variables are declared and used, the definition location and usage location of custom types used in the code, and the dependencies between conditional statements, loop statements, and control flow structures;

[0038] The dependency relationship is represented by using a graph data structure to form a dependency graph corresponding to the dependency relationship.

[0039] The code call visualization control system based on AST includes:

[0040] An abstract syntax tree construction module is used to construct an abstract syntax tree by parsing source code files corresponding to different code units, and to represent the code structure and syntax through the abstract syntax tree;

[0041] A first dependency relationship acquisition module, used to perform code analysis on different code units to acquire dependency relationships between the different code units;

[0042] A second dependency relationship acquisition module, used to traverse the abstract syntax trees corresponding to the different code units, and acquire the dependency relationship between the codes contained in the code unit itself according to the information data contained in the abstract syntax tree;

[0043] The visualization module is used to visualize the dependency relationships between the different code units and the dependency relationships between the codes contained in the code units themselves.

[0044] Furthermore, the abstract syntax tree construction module includes:

[0045] A source code file retrieving module, used to retrieve different code units and source code files corresponding to the code units;

[0046] A lexical unit acquisition module, used to perform code analysis using a lexical analysis method on the source code file corresponding to each code unit, and obtain the lexical units contained in the source code file of the code unit;

[0047] A lexical unit decomposition module is used to decompose the lexical units according to preset grammatical rules using a grammatical analyzer to obtain expressions, statements and / or functions contained in each lexical unit;

[0048] A node acquisition module, used to take the expression, statement and / or function contained in the lexical unit as a node;

[0049] The abstract syntax tree generation module is used to construct a tree structure corresponding to each lexical unit using the nodes, and generate an abstract syntax tree corresponding to the code unit using the tree structure.

[0050] Furthermore, the first dependency acquisition module includes:

[0051] An abstract syntax tree calling module, used to call different code units and the abstract syntax trees corresponding to the code units;

[0052] Abstract syntax tree traversal module, used to traverse the abstract syntax tree corresponding to each code unit;

[0053] An information recording module, used to record the calling relationship, inheritance relationship and inclusion relationship contained in the abstract syntax tree corresponding to each code unit;

[0054] A relationship acquisition module, used to use a graph data structure to represent the calling relationship, inheritance relationship and inclusion relationship as dependencies, and to construct a dependency graph corresponding to each code unit including the calling relationship, inheritance relationship and inclusion relationship;

[0055] The dependency acquisition execution module is used to traverse the dependency graph corresponding to each code unit using a depth-first search method to identify the direct dependency and indirect dependency between each code unit.

[0056] Furthermore, the first dependency acquisition module further includes:

[0057] The first real-time monitoring module is used to monitor the number of calls between every two code units during the running of the code units in real time;

[0058] The second real-time monitoring module is used to monitor in real time the number of logic types contained in the dependency relationship between every two code units during the running of the code units;

[0059] A third real-time monitoring module is used to monitor in real time when a code modification occurs in one of every two code units, and synchronize the modification information of the corresponding code modification with the other code unit with which it has a dependency relationship; wherein the modification information includes the number of modifications and the coverage rate of the modified code;

[0060] The code modification impact value acquisition module is used to obtain the code modification impact value corresponding to each code unit by using the modification times and the modified code coverage; wherein the code modification impact value is obtained by the following formula:

[0061]

[0062] Wherein, Q represents the code modification impact value corresponding to each code unit; n represents the number of times the other code unit performs the corresponding code modification synchronously when one of the two code units undergoes code modification; P i represents the modified code coverage rate of another code unit when it is modified for the i-th time; λ represents the numerical adjustment coefficient; wherein the numerical adjustment coefficient is obtained by the following formula:

[0063]

[0064] Where m represents the total number of code modifications in one of every two code units; k represents the number of code lines contained in the other code unit; f i Indicates the number of modified positions in the i-th line of code; B i represents the code modification coverage when the i-th line of code is modified; w i Indicates the ratio of the number of logical types contained in the i-th line of code of every two code units to the total number of logical types contained in the other code unit when a code modification occurs in one of the other two code units;

[0065] The dependency strength value acquisition module is used to obtain the dependency strength value between every two code units by using the code modification impact value corresponding to each code unit in combination with the number of calls between every two code units corresponding to the code unit and the number of logic types contained in the dependency relationship between every two code units, wherein the dependency strength value is obtained by the following formula:

[0066]

[0067] Where W represents the dependency strength value between every two code units; r represents the number of calls between every two code units when a code unit is grouped with another code unit; R represents the number of logical types contained in the dependency relationship between every two code units; M represents the total number of all logical types contained in every two code units; N i Indicates the number of logical operations executed by the code unit during the i-th call;

[0068] The dependency relationship marking module is used to mark the dependency relationship between two code units corresponding to the dependency strength values ​​exceeding the preset strength value threshold when the dependency strength value exceeds the preset strength value threshold.

[0069] Furthermore, the second dependency acquisition module includes:

[0070] A node traversal module, used to traverse the nodes corresponding to the abstract syntax tree corresponding to the code unit using a depth-first search method;

[0071] A real-time identification module is used to identify and record the dependency relationship between nodes corresponding to the abstract syntax tree in real time; wherein the dependency relationship between the nodes includes the relationship between the function caller and the called function, the location where the variable is declared and the location where it is used, the definition location and the location where the custom type is used in the code, and the dependency relationship between conditional statements, loop statements and control flow structures;

[0072] The dependency graph acquisition module is used to represent the dependency relationship using a graph data structure to form a dependency graph corresponding to the dependency relationship.

[0073] Beneficial effects of the present invention:

[0074] The AST-based code call visualization control method and system proposed by the present invention aims to automatically identify and analyze the dependencies between software units by analyzing the grammatical structure of the source code, so as to help developers better understand and master the structure and design of the software system, thereby improving the quality and efficiency of software development. The technical method of the present invention can help developers complete the following tasks:

[0075] 1. Automatically identify and analyze the calling relationship, inheritance relationship, dependency relationship, etc. in the code, and generate the corresponding dependency graph or dependency tree.

[0076] 2. Provide visualization tools to help developers understand the dependencies and structures between software units more intuitively.

[0077] 3. Support automatic detection and repair of dependency issues in the code, such as circular dependencies, deadlocks, etc., to improve the robustness and maintainability of the code.

[0078] 4. Provide dependency analysis and optimization suggestions to help developers improve the design and implementation strategies in the software development process.

[0079] The AST-based code call visualization control method and system can effectively improve the quality and efficiency of software development, reduce code maintenance costs, and promote the sustainable development of software systems.

[0080] At the same time, the AST-based code call visualization control method and system have the following advantages and positive effects:

[0081] 1. Improve accuracy: By parsing the source code and building an abstract syntax tree, the code structure and grammatical relationships can be accurately captured, thereby accurately analyzing the dependencies between software units.

[0082] 2. Comprehensiveness: AST-based technology can analyze various types of dependencies, including function calls, data dependencies, inheritance relationships, etc., to help developers fully understand the structure of the software system.

[0083] 3. Visual display: The generated dependency graph can be displayed through visualization tools, allowing developers to intuitively view and understand dependencies, making it easier to quickly locate problems and optimize code structure.

[0084] 4. Improve reusability: Understanding the dependencies between software units can provide guidance for code refactoring, helping developers perform safe and efficient refactoring operations and improving code quality.

[0085] 5. System maintenance: By analyzing dependencies, developers can better manage the complexity of software systems, quickly locate and solve problems, and improve the maintainability and scalability of the system.

[0086] 6. Code quality analysis: Dependency-based analysis can help evaluate the quality of the code, identify problems such as coupling and poor modularity, and help improve code structure and maintainability.

[0087] 7. Improve development efficiency: Better understanding and management of dependencies between software units can improve development efficiency and reduce errors and duplication of work during the development process.

[0088] In summary, the AST-based code call visualization control method and system have important advantages in the software development process. They can improve developers' understanding of the complexity of software systems and help them better manage and maintain dependencies in software systems, thereby improving software development efficiency and quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0089] Figure 1 is a flow chart of the method of the present invention;

[0090] Figure 2 The schematic diagram of the execution principle of the method of the present invention;

[0091] Figure 3 The system block diagram of the system of the present invention. DETAILED DESCRIPTION

[0092] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0093] The embodiment of the present invention proposes a code call visualization control method based on AST, such as Figure 1 and Figure 2 As shown, the AST-based code call visualization control method includes:

[0094] S1. Construct an abstract syntax tree by parsing source code files corresponding to different code units, and represent the code structure and syntax through the abstract syntax tree;

[0095] S2. Perform code analysis on different code units to obtain dependency relationships between the different code units;

[0096] S3, traversing the abstract syntax trees corresponding to the different code units, and acquiring the dependency relationship between the codes contained in the code unit itself according to the information data contained in the abstract syntax tree;

[0097] S4. Visually display the dependency relationships between the different code units and the dependency relationships between the codes contained in the code units themselves.

[0098] The working principle of the above technical solution is: the AST-based code call visualization control method and system is a method that uses the abstract syntax tree of the source code to analyze and understand the dependencies between software units. In software development, there are complex dependencies between different code units (such as functions, classes, modules, etc.). Understanding and managing the above dependencies is crucial for the maintenance and optimization of software systems. The AST-based software unit function description auxiliary generation technology mainly involves the following technical means:

[0099] Code parsing: By parsing the source code file, an abstract syntax tree is constructed to represent the code structure and syntax.

[0100] Dependency analysis: Analyze the dependencies between codes, including function calls, class associations, module references, etc.

[0101] AST traversal: traverse the abstract syntax tree and extract the required information, such as variable definitions, function declarations, dependencies, etc.

[0102] Data extraction: Extract relevant information from AST, such as function calls, variable references, etc., to assist in generating dependencies.

[0103] Dependency modeling: Model the extracted dependencies for subsequent analysis and processing.

[0104] Visual display: Visualize dependencies to help developers understand code structure and dependencies.

[0105] Specifically, build AST:

[0106] Use existing compiler or parser tools to parse the source code and generate the corresponding abstract syntax tree.

[0107] Extract call relationship:

[0108] In the generated AST, the calling relationships between functions, classes, methods, etc. in the code are extracted. This can be achieved by traversing the AST nodes and identifying grammatical structures such as function calls and method calls.

[0109] Design visual interface:

[0110] Develop a user-friendly visual interface to display the code calling relationship. The interface should clearly display the calling relationship between different code units and support interactive operations.

[0111] Data transmission and presentation:

[0112] The extracted call relationship data is transferred to the visual interface and presented appropriately. The code call relationship can be displayed in the form of charts, tree structures, etc.

[0113] Interaction:

[0114] Provide users with interactive functions, such as searching for specific functions or methods, expanding / collapsed code hierarchies, highlighting related code, etc., so that users can better understand and analyze the calling relationship between codes.

[0115] Real-time updates:

[0116] During the code editing process, the visual display of the code call relationship is updated in real time to help developers promptly understand the impact of code changes on the call relationship.

[0117] Performance optimization:

[0118] For large code bases, performance optimization needs to be considered to avoid slow loading or freezing of the visualization interface due to excessive data volume. Through the above implementation plan, the AST-based code call visualization control method and system can help the development team better understand and manage code dependencies and improve the maintainability and scalability of the software.

[0119] The effect of the above technical solution is: by constructing an abstract syntax tree (AST), the above technical solution can clearly represent the structure and syntax of the code. This enables developers to intuitively understand the composition and logic of the code and improves the readability of the code. The above technical solution can not only analyze the dependencies between different code units, but also go deep into the code unit to obtain the dependencies between the codes contained in the code unit itself. This comprehensive dependency analysis helps developers better understand the execution process and data flow of the code. By visually displaying the dependencies, the above technical solution makes complex code calls and dependencies clear at a glance. This visualization helps developers quickly locate and understand the key parts of the code, improves development efficiency and convenience of code maintenance. The visual control method based on AST can help developers find problems faster during the development process, optimize the code structure, reduce redundancy and unnecessary dependencies, and thus improve the quality and performance of the code. Since the above technical solution is based on the abstract syntax tree, it can be applied to a variety of programming languages ​​and has good versatility and scalability.

[0120] An embodiment of the present invention constructs an abstract syntax tree by parsing source code files corresponding to different code paths, including:

[0121] S101, retrieving different code units and source code files corresponding to the code units;

[0122] S102, performing code analysis on the source code file corresponding to each code unit by using a lexical analysis method, and obtaining lexical units contained in the source code file of the code unit;

[0123] S103, using a grammar analyzer to decompose the lexical units according to preset grammar rules, and obtaining expressions, statements and / or functions contained in each lexical unit;

[0124] S104, taking the expression, statement and / or function included in the lexical unit as a node;

[0125] S105: construct a tree structure corresponding to each lexical unit using the nodes, and generate an abstract syntax tree corresponding to the code unit using the tree structure.

[0126] The working principle of the above technical solution is as follows: First, the system needs to obtain different code units and their corresponding source code files. This is the initial step of building an abstract syntax tree (AST).

[0127] The system will perform lexical analysis on the source code file of each code unit. The above process mainly decomposes the source code into a series of lexical units (tokens), such as keywords, identifiers, operators, values, etc.

[0128] Next, the system uses a grammar analyzer to further decompose the above lexical units. This step will identify the structures such as expressions, statements and / or functions in the lexical units according to the preset grammar rules.

[0129] The structures such as expressions, statements and functions obtained by analysis are regarded as nodes. The above nodes are the basic elements for constructing the abstract syntax tree.

[0130] Finally, the system uses the above nodes to construct a tree structure corresponding to each lexical unit, and then generates an abstract syntax tree for the entire code unit. The above tree structure intuitively reflects the grammatical structure and hierarchical relationship of the source code.

[0131] The effect of the above technical solution is that by constructing an abstract syntax tree, the syntax structure and logical relationship of the source code can be accurately represented. This is crucial for subsequent code analysis, optimization, and conversion tasks. The abstract syntax tree provides developers with an intuitive way to understand and operate the code. The above technical solution helps to speed up the development process, reduce errors, and improve code quality.

[0132] Abstract syntax trees are widely used in many fields such as compiler design, code optimization, static code analysis, and refactoring tools. By analyzing abstract syntax trees, developers can more easily identify patterns and structures in the code, thereby more effectively maintaining and modifying the code. Abstract syntax trees provide convenience for automated tools such as code generators, optimizers, and converters. The above tools can perform precise operations and conversions based on abstract syntax trees.

[0133] In one embodiment of the present invention, code analysis is performed on different code units to obtain dependency relationships between the different code units, including:

[0134] S201, retrieving different code units and abstract syntax trees corresponding to the code units;

[0135] S202, traversing the abstract syntax tree corresponding to each code unit;

[0136] S203, recording the calling relationship, inheritance relationship and inclusion relationship contained in the abstract syntax tree corresponding to each code unit;

[0137] S204, using a graph data structure to represent the calling relationship, inheritance relationship and inclusion relationship as dependencies, and constructing a dependency graph including the calling relationship, inheritance relationship and inclusion relationship corresponding to each code unit;

[0138] S205: Use a depth-first search method to traverse the dependency graph corresponding to each code unit to identify the direct dependency relationship and indirect dependency relationship between each code unit.

[0139] The working principle of the above technical solution is: the system first obtains different code units (such as classes, functions, modules, etc.), and then generates or obtains the corresponding abstract syntax tree (AST) for each code unit. The abstract syntax tree is a tree representation of the source code, which describes the grammatical structure in the code in a tree structure, and each node represents a structure in the source code.

[0140] The system then traverses the abstract syntax tree for each unit of code, systematically checking each node in the tree to ensure that no dependency-related information is missed.

[0141] In the process of traversing the abstract syntax tree, the system will identify and record various relationships, including function call relationships (one function calls another function), inheritance relationships (one class inherits another class), and inclusion relationships (one code block includes another code block or resource). The above relationships form the basis of dependencies between code units.

[0142] The system represents the above calling relationships, inheritance relationships, and inclusion relationships using a graph data structure. In the above dependency graph, nodes represent code units, and edges represent the relationships between the above code units. In this way, complex code dependencies are converted into a visual network structure for easy analysis and understanding.

[0143] Finally, the system uses the depth-first search (DFS) algorithm to traverse the dependency graph of each code unit. DFS is an algorithm used to traverse or search a tree or graph. During the above process, the system identifies and records the direct dependencies (direct connections between two code units) and indirect dependencies (connected through one or more intermediate code units) between each code unit.

[0144] Through the above technical solutions, developers can obtain a comprehensive dependency view between code units, so as to better understand the structure of the code, optimize code design, reduce unnecessary coupling, and improve the maintainability and quality of the code.

[0145] The effect of the above technical solution is: by traversing the abstract syntax tree (AST) of each code unit and recording the call relationship, inheritance relationship and inclusion relationship therein, the technical solution can comprehensively and accurately capture various dependencies between code units. The above technical solution helps developers to fully understand the structure and interaction of the code. The above dependencies are represented by a graph data structure, and a dependency graph is constructed, so that complex code dependencies become more intuitive and visual. This is particularly helpful for understanding and analyzing large code bases. By traversing the dependency graph by a depth-first search method, the technical solution can accurately identify the direct and indirect dependencies between each code unit. This precise identification helps developers locate potential code problems, such as circular dependencies, unnecessary dependencies, etc. Understanding the dependencies between code units can help developers optimize code design, reduce unnecessary coupling, and improve the maintainability and scalability of the code. At the same time, this also provides strong support for refactoring existing code. In project management and team collaboration, understanding the dependencies between code units helps to formulate reasonable development plans and task allocations to ensure the smooth progress of the project. Through in-depth analysis of dependencies, potential errors and risks can be discovered, so that they can be corrected at an early stage and the overall quality of the software can be improved.

[0146] In summary, this technical solution provides strong support for code analysis, design, maintenance and management in the software development process through comprehensive dependency analysis, intuitive dependency representation, precise dependency identification and other means, which helps to improve the quality and efficiency of the software.

[0147] In one embodiment of the present invention, code analysis is performed on different code units to obtain dependency relationships between the different code units, and further includes:

[0148] Step 1: Real-time monitoring of the number of calls between every two code units during the running of the code units;

[0149] Step 2: Real-time monitoring of the number of logic types contained in the dependency relationship between every two code units during the running of the code units; wherein the logic types include but are not limited to conditional logic and loop logic;

[0150] Step 3: When a code modification occurs in one of two code units, the modification information of the corresponding code modification is synchronized with the other code unit with which the code unit has a dependency relationship in real time; wherein the modification information includes the number of modifications and the coverage rate of the modified code;

[0151] Step 4: Obtain the code modification impact value corresponding to each code unit using the modification times and the modified code coverage; wherein the code modification impact value is obtained by the following formula:

[0152]

[0153] Wherein, Q represents the code modification impact value corresponding to each code unit; n represents the number of modifications that the other code unit performs synchronously when a code modification occurs in one of the two code units; P i represents the modified code coverage rate of another code unit when it is modified for the i-th time; λ represents the numerical adjustment coefficient; wherein the numerical adjustment coefficient is obtained by the following formula:

[0154]

[0155] Where m represents the total number of code modifications in one of every two code units; k represents the number of code lines contained in the other code unit; f i Indicates the number of modified positions in the i-th line of code; B i represents the code modification coverage when the i-th line of code is modified; w i Indicates the ratio of the number of logical types contained in the i-th line of code of every two code units to the total number of logical types contained in the other code unit when a code modification occurs in one of the other two code units;

[0156] Step 5: Obtain a dependency strength value between every two code units by using the code modification impact value corresponding to each code unit in combination with the number of calls between every two code units corresponding to the code unit and the number of logic types contained in the dependency relationship between every two code units, wherein the dependency strength value is obtained by the following formula:

[0157]

[0158] Where W represents the dependency strength value between every two code units; r represents the number of calls between every two code units when a code unit is grouped with another code unit; R represents the number of logical types contained in the dependency relationship between every two code units; M represents the total number of all logical types contained in every two code units; N i Indicates the number of logical operations executed by the code unit during the i-th call;

[0159] Step 6: When the dependency strength value exceeds a preset strength value threshold, the dependency relationship between the two code units corresponding to the dependency strength values ​​exceeding the preset strength value threshold is marked.

[0160] The working principle of the above technical solution is to quantitatively evaluate the dependency strength between each two code units by real-time monitoring and analyzing various dynamic data between different code units, including the number of calls, the logic types in the dependency relationship, code modification information, and the impact of the modification. The specific steps are as follows:

[0161] Real-time monitoring of call counts: Track and record actual calls between code units.

[0162] Real-time monitoring of logic types: Analyze the different logic types involved in the dependencies between code units, such as conditional logic and loop logic.

[0163] Real-time monitoring of code modification information: When a code unit is modified, monitor the synchronous modification of another code unit that has a dependency on it, and record the number of modifications and the modified code coverage.

[0164] Calculate the code modification impact value: Use a formula to combine the number of modifications and the modified code coverage to quantify the impact of code modifications on dependent code units.

[0165] Calculate dependency strength value: Consider factors such as the number of calls, the number of logic types, and the impact of code modifications, and use the formula to calculate the dependency strength between every two code units.

[0166] Dependency marking: When the dependency strength exceeds the preset threshold, the corresponding dependency is marked for subsequent optimization or reconstruction

[0167] The effect of the above technical solution is: this technical solution provides real-time and dynamic code dependency analysis, which can reflect the dependency of the code during actual operation. Through specific numerical calculations, the dependency is transformed from a qualitative description to a quantitative evaluation, which more intuitively shows the degree of dependency between code units. When the dependency strength exceeds the preset threshold, it is marked, which provides a clear signal for developers, helping to promptly discover and solve potential code structure problems. Developers can optimize the code structure in a targeted manner based on the marked dependencies, reduce the dependency strength, and improve the modularity and maintainability of the code. Continuous monitoring of dependency strength can help project teams better manage code quality risks and prevent potential problems caused by excessive dependencies.

[0168] This technical solution provides strong data support and decision-making basis for code analysis, optimization and management in the software development process by real-time monitoring and quantitative evaluation of the dependencies between code units.

[0169] In one embodiment of the present invention, traversing the abstract syntax trees corresponding to the different code units, and acquiring the dependency relationship between the codes contained in the code units themselves according to the information data contained in the abstract syntax trees, includes:

[0170] S301, traversing the nodes corresponding to the abstract syntax tree corresponding to the code unit by using a depth-first search method; wherein each node included in the abstract syntax tree represents a construct in the source code (such as a function declaration, a variable declaration, a control flow statement, etc.);

[0171] S302, identifying and recording the dependency relationships between nodes corresponding to the abstract syntax tree in real time; wherein the dependency relationships between the nodes include the relationship between the function caller and the called function, the location where variables are declared and used, the definition location and use location of user-defined types used in the code, and the dependency relationships between conditional statements, loop statements, and control flow structures;

[0172] S303: Use a graph data structure to represent the dependency relationship to form a dependency graph corresponding to the dependency relationship.

[0173] The working principle of the above technical solution is as follows: First, the system uses a depth-first search method to traverse each node of the abstract syntax tree (AST) corresponding to the code unit. Each node of the AST represents a construct in the source code, such as a function declaration, a variable declaration, a control flow statement, etc. Through DFS, the system can access all nodes in the AST and ensure that no part is missed.

[0174] In the process of traversing the AST, the system identifies and records the dependencies between nodes in real time. The above dependencies include but are not limited to the relationship between function callers and called functions, the declaration location and usage location of variables, the definition location and usage location of custom types, and the dependencies between conditional statements, loop statements, and control flow structures. The above information is crucial for understanding the execution flow and logic of the code.

[0175] Finally, the system uses a graph data structure to represent the identified dependencies, forming a dependency graph. In the graph, nodes represent the various constructs in the code, and edges represent the dependencies between the constructs. This graphical representation makes complex dependencies intuitive and easy to understand.

[0176] The effect of the above technical solution is: by traversing AST and using the DFS algorithm, the technical solution can comprehensively analyze the dependencies within the code unit to ensure that no important dependency information is missed. By converting dependencies into a graphical dependency graph, developers can intuitively view and understand the dependency structure in the code, thereby improving development efficiency and code quality. Understanding the dependencies within the code helps developers find potential optimization points and refactoring opportunities, such as identifying redundant code and discovering possible performance bottlenecks. A clear dependency graph can help new development team members understand the code structure and logic more quickly, thereby improving the maintainability of the code. By analyzing and optimizing dependencies, developers can find and fix potential errors and problems in the early stages, thereby reducing later debugging time and costs.

[0177] The embodiment of the present invention proposes a code call visualization control system based on AST, such as Figure 3 As shown, the AST-based code call visualization control system includes:

[0178] An abstract syntax tree construction module is used to construct an abstract syntax tree by parsing source code files corresponding to different code units, and to represent the code structure and syntax through the abstract syntax tree;

[0179] A first dependency relationship acquisition module, used to perform code analysis on different code units to acquire dependency relationships between the different code units;

[0180] A second dependency relationship acquisition module, used to traverse the abstract syntax trees corresponding to the different code units, and acquire the dependency relationship between the codes contained in the code unit itself according to the information data contained in the abstract syntax tree;

[0181] The visualization module is used to visualize the dependency relationships between the different code units and the dependency relationships between the codes contained in the code units themselves.

[0182] The working principle of the technical solution is as follows: The AST-based code call visualization control method and system is a method that uses the abstract syntax tree of the source code to analyze and understand the dependencies between software units. In software development, there are complex dependencies between different code units (such as functions, classes, modules, etc.). Understanding and managing the above dependencies is crucial for the maintenance and optimization of software systems. The AST-based software unit function description auxiliary generation technology mainly involves the following technical means:

[0183] Code parsing: By parsing the source code file, an abstract syntax tree is constructed to represent the code structure and syntax.

[0184] Dependency analysis: Analyze the dependencies between codes, including function calls, class associations, module references, etc.

[0185] AST traversal: traverse the abstract syntax tree and extract the required information, such as variable definitions, function declarations, dependencies, etc.

[0186] Data extraction: Extract relevant information from AST, such as function calls, variable references, etc., to assist in generating dependencies.

[0187] Dependency modeling: Model the extracted dependencies for subsequent analysis and processing.

[0188] Visual display: Visualize dependencies to help developers understand code structure and dependencies.

[0189] The effect of the above technical solution is: by constructing an abstract syntax tree (AST), the above technical solution can clearly represent the structure and syntax of the code. This enables developers to intuitively understand the composition and logic of the code and improves the readability of the code. The above technical solution can not only analyze the dependencies between different code units, but also go deep into the code unit to obtain the dependencies between the codes contained in the code unit itself. This comprehensive dependency analysis helps developers better understand the execution process and data flow of the code. By visually displaying the dependencies, the above technical solution makes complex code calls and dependencies clear at a glance. This visualization helps developers quickly locate and understand the key parts of the code, improves development efficiency and convenience of code maintenance. The visual control method based on AST can help developers find problems faster during the development process, optimize the code structure, reduce redundancy and unnecessary dependencies, and thus improve the quality and performance of the code. Since the above technical solution is based on the abstract syntax tree, it can be applied to a variety of programming languages ​​and has good versatility and scalability.

[0190] In one embodiment of the present invention, the abstract syntax tree construction module includes:

[0191] A source code file retrieving module, used to retrieve different code units and source code files corresponding to the code units;

[0192] A lexical unit acquisition module, used to perform code analysis using a lexical analysis method on the source code file corresponding to each code unit, and acquire the lexical units contained in the source code file of the code unit;

[0193] A lexical unit decomposition module is used to decompose the lexical units according to preset grammatical rules using a grammatical analyzer to obtain expressions, statements and / or functions contained in each lexical unit;

[0194] A node acquisition module, used to take the expression, statement and / or function contained in the lexical unit as a node;

[0195] The abstract syntax tree generation module is used to construct a tree structure corresponding to each lexical unit using the nodes, and generate an abstract syntax tree corresponding to the code unit using the tree structure.

[0196] The working principle of the above technical solution is as follows: First, the system needs to obtain different code units and their corresponding source code files. This is the initial step of building an abstract syntax tree (AST).

[0197] The system will perform lexical analysis on the source code file of each code unit. The above process mainly decomposes the source code into a series of lexical units (tokens), such as keywords, identifiers, operators, values, etc.

[0198] Next, the system uses a grammar analyzer to further decompose the above lexical units. This step will identify the structures such as expressions, statements and / or functions in the lexical units according to the preset grammar rules.

[0199] The structures such as expressions, statements and functions obtained by analysis are regarded as nodes. The above nodes are the basic elements for constructing the abstract syntax tree.

[0200] Finally, the system uses the above nodes to construct a tree structure corresponding to each lexical unit, and then generates an abstract syntax tree for the entire code unit. The above tree structure intuitively reflects the grammatical structure and hierarchical relationship of the source code.

[0201] The effect of the above technical solution is that by constructing an abstract syntax tree, the syntax structure and logical relationship of the source code can be accurately represented. This is crucial for subsequent code analysis, optimization, and conversion tasks. The abstract syntax tree provides developers with an intuitive way to understand and operate the code. The above technical solution helps to speed up the development process, reduce errors, and improve code quality.

[0202] Abstract syntax trees are widely used in many fields such as compiler design, code optimization, static code analysis, and refactoring tools. By analyzing abstract syntax trees, developers can more easily identify patterns and structures in the code, thereby more effectively maintaining and modifying the code. Abstract syntax trees provide convenience for automated tools such as code generators, optimizers, and converters. The above tools can perform precise operations and conversions based on abstract syntax trees.

[0203] In one embodiment of the present invention, the first dependency acquisition module includes:

[0204] An abstract syntax tree calling module, used to call different code units and the abstract syntax trees corresponding to the code units;

[0205] Abstract syntax tree traversal module, used to traverse the abstract syntax tree corresponding to each code unit;

[0206] An information recording module, used to record the calling relationship, inheritance relationship and inclusion relationship contained in the abstract syntax tree corresponding to each code unit;

[0207] A relationship acquisition module, used to use a graph data structure to represent the calling relationship, inheritance relationship and inclusion relationship as dependencies, and to construct a dependency graph corresponding to each code unit including the calling relationship, inheritance relationship and inclusion relationship;

[0208] The dependency acquisition execution module is used to traverse the dependency graph corresponding to each code unit using a depth-first search method to identify the direct dependency and indirect dependency between each code unit.

[0209] The working principle of the above technical solution is: the system first obtains different code units (such as classes, functions, modules, etc.), and then generates or obtains the corresponding abstract syntax tree (AST) for each code unit. The abstract syntax tree is a tree representation of the source code, which describes the grammatical structure in the code in a tree structure, and each node represents a structure in the source code.

[0210] The system then traverses the abstract syntax tree for each unit of code, systematically checking each node in the tree to ensure that no dependency-related information is missed.

[0211] In the process of traversing the abstract syntax tree, the system will identify and record various relationships, including function call relationships (one function calls another function), inheritance relationships (one class inherits another class), and inclusion relationships (one code block includes another code block or resource). The above relationships form the basis of dependencies between code units.

[0212] The system represents the above calling relationships, inheritance relationships, and inclusion relationships using a graph data structure. In the above dependency graph, nodes represent code units, and edges represent the relationships between the above code units. In this way, complex code dependencies are converted into a visual network structure for easy analysis and understanding.

[0213] Finally, the system uses the depth-first search (DFS) algorithm to traverse the dependency graph of each code unit. DFS is an algorithm used to traverse or search a tree or graph. During the above process, the system identifies and records the direct dependencies (direct connections between two code units) and indirect dependencies (connected through one or more intermediate code units) between each code unit.

[0214] Through the above technical solutions, developers can obtain a comprehensive dependency view between code units, so as to better understand the structure of the code, optimize code design, reduce unnecessary coupling, and improve the maintainability and quality of the code.

[0215] The effect of the above technical solution is: by traversing the abstract syntax tree (AST) of each code unit and recording the call relationship, inheritance relationship and inclusion relationship therein, the technical solution can comprehensively and accurately capture various dependencies between code units. The above technical solution helps developers to fully understand the structure and interaction of the code. The above dependencies are represented by a graph data structure, and a dependency graph is constructed, so that complex code dependencies become more intuitive and visual. This is particularly helpful for understanding and analyzing large code bases. By traversing the dependency graph by a depth-first search method, the technical solution can accurately identify the direct and indirect dependencies between each code unit. This precise identification helps developers locate potential code problems, such as circular dependencies, unnecessary dependencies, etc. Understanding the dependencies between code units can help developers optimize code design, reduce unnecessary coupling, and improve the maintainability and scalability of the code. At the same time, this also provides strong support for refactoring existing code. In project management and team collaboration, understanding the dependencies between code units helps to formulate reasonable development plans and task allocations to ensure the smooth progress of the project. Through in-depth analysis of dependencies, potential errors and risks can be discovered, so that they can be corrected at an early stage and the overall quality of the software can be improved.

[0216] In summary, this technical solution provides strong support for code analysis, design, maintenance and management in the software development process through comprehensive dependency analysis, intuitive dependency representation, precise dependency identification and other means, which helps to improve the quality and efficiency of the software.

[0217] In one embodiment of the present invention, the first dependency acquisition module further includes:

[0218] The first real-time monitoring module is used to monitor the number of calls between every two code units during the running of the code units in real time;

[0219] A second real-time monitoring module is used to monitor in real time the number of logic types contained in the dependency relationship between every two code units during the operation of the code units; wherein the logic types include but are not limited to conditional logic and loop logic;

[0220] A third real-time monitoring module is used to monitor in real time when a code modification occurs in one of every two code units, and synchronize the modification information of the corresponding code modification with the other code unit with which it has a dependency relationship; wherein the modification information includes the number of modifications and the coverage rate of the modified code;

[0221] The code modification impact value acquisition module is used to obtain the code modification impact value corresponding to each code unit by using the modification times and the modified code coverage; wherein the code modification impact value is obtained by the following formula:

[0222]

[0223] Wherein, Q represents the code modification impact value corresponding to each code unit; n represents the number of modifications that the other code unit performs synchronously when a code modification occurs in one of the two code units; P i represents the modified code coverage rate of another code unit when it is modified for the i-th time; λ represents the numerical adjustment coefficient; wherein the numerical adjustment coefficient is obtained by the following formula:

[0224]

[0225] Where m represents the total number of code modifications in one of every two code units; k represents the number of code lines contained in the other code unit; f i Indicates the number of modified positions in the i-th line of code; B i represents the code modification coverage when the i-th line of code is modified; w i Indicates the ratio of the number of logical types contained in the i-th line of code of every two code units to the total number of logical types contained in the other code unit when a code modification occurs in one of the other two code units;

[0226] The dependency strength value acquisition module is used to obtain the dependency strength value between every two code units by using the code modification impact value corresponding to each code unit in combination with the number of calls between every two code units corresponding to the code unit and the number of logic types contained in the dependency relationship between every two code units, wherein the dependency strength value is obtained by the following formula:

[0227]

[0228] Where W represents the dependency strength value between every two code units; r represents the number of calls between every two code units when a code unit is grouped with another code unit; R represents the number of logical types contained in the dependency relationship between every two code units; M represents the total number of all logical types contained in every two code units; N i Indicates the number of logical operations executed by the code unit during the i-th call;

[0229] The dependency relationship marking module is used to mark the dependency relationship between two code units corresponding to the dependency strength values ​​exceeding the preset strength value threshold when the dependency strength value exceeds the preset strength value threshold.

[0230] The working principle of the above technical solution is to quantitatively evaluate the dependency strength between each two code units by real-time monitoring and analyzing various dynamic data between different code units, including the number of calls, the logic types in the dependency relationship, code modification information, and the impact of the modification. The specific steps are as follows:

[0231] Real-time monitoring of call counts: Track and record actual calls between code units.

[0232] Real-time monitoring of logic types: Analyze the different logic types involved in the dependencies between code units, such as conditional logic and loop logic.

[0233] Real-time monitoring of code modification information: When a code unit is modified, monitor the synchronous modification of another code unit that has a dependency on it, and record the number of modifications and the modified code coverage.

[0234] Calculate the code modification impact value: Use a formula to combine the number of modifications and the modified code coverage to quantify the impact of code modifications on dependent code units.

[0235] Calculate dependency strength value: Consider factors such as the number of calls, the number of logic types, and the impact of code modifications, and use the formula to calculate the dependency strength between every two code units.

[0236] Dependency marking: When the dependency strength exceeds the preset threshold, the corresponding dependency is marked for subsequent optimization or reconstruction

[0237] The effect of the above technical solution is: this technical solution provides real-time and dynamic code dependency analysis, which can reflect the dependency of the code during actual operation. Through specific numerical calculations, the dependency is transformed from a qualitative description to a quantitative evaluation, which more intuitively shows the degree of dependency between code units. When the dependency strength exceeds the preset threshold, it is marked, which provides a clear signal for developers, helping to promptly discover and solve potential code structure problems. Developers can optimize the code structure in a targeted manner based on the marked dependencies, reduce the dependency strength, and improve the modularity and maintainability of the code. Continuous monitoring of dependency strength can help project teams better manage code quality risks and prevent potential problems caused by excessive dependencies.

[0238] This technical solution provides strong data support and decision-making basis for code analysis, optimization and management in the software development process by real-time monitoring and quantitative evaluation of the dependencies between code units.

[0239] In one embodiment of the present invention, the second dependency acquisition module includes:

[0240] The node traversal module is used to traverse the nodes corresponding to the abstract syntax tree corresponding to the code unit using a depth-first search method; wherein each node contained in the abstract syntax tree represents a construct in the source code (such as a function declaration, a variable declaration, a control flow statement, etc.;

[0241] A real-time identification module is used to identify and record the dependency relationship between nodes corresponding to the abstract syntax tree in real time; wherein the dependency relationship between the nodes includes the relationship between the function caller and the called function, the location where the variable is declared and the location where it is used, the definition location and the location where the custom type is used in the code, and the dependency relationship between conditional statements, loop statements and control flow structures;

[0242] The dependency graph acquisition module is used to represent the dependency relationship using a graph data structure to form a dependency graph corresponding to the dependency relationship.

[0243] The working principle of the above technical solution is as follows: First, the system uses a depth-first search method to traverse each node of the abstract syntax tree (AST) corresponding to the code unit. Each node of the AST represents a construct in the source code, such as a function declaration, a variable declaration, a control flow statement, etc. Through DFS, the system can access all nodes in the AST and ensure that no part is missed.

[0244] In the process of traversing the AST, the system identifies and records the dependencies between nodes in real time. The above dependencies include but are not limited to the relationship between function callers and called functions, the declaration location and usage location of variables, the definition location and usage location of custom types, and the dependencies between conditional statements, loop statements, and control flow structures. The above information is crucial for understanding the execution flow and logic of the code.

[0245] Finally, the system uses a graph data structure to represent the identified dependencies, forming a dependency graph. In the graph, nodes represent the various constructs in the code, and edges represent the dependencies between the constructs. This graphical representation makes complex dependencies intuitive and easy to understand.

[0246] The effect of the above technical solution is: by traversing AST and using the DFS algorithm, the technical solution can comprehensively analyze the dependencies within the code unit to ensure that no important dependency information is missed. By converting dependencies into a graphical dependency graph, developers can intuitively view and understand the dependency structure in the code, thereby improving development efficiency and code quality. Understanding the dependencies within the code helps developers find potential optimization points and refactoring opportunities, such as identifying redundant code and discovering possible performance bottlenecks. A clear dependency graph can help new development team members understand the code structure and logic more quickly, thereby improving the maintainability of the code. By analyzing and optimizing dependencies, developers can find and fix potential errors and problems in the early stages, thereby reducing later debugging time and costs.

[0247] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if the above-mentioned modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include the above-mentioned modifications and variations.

Claims

1. The code call visualization control method based on AST is characterized by: The AST-based code call visualization control method includes: Constructing an abstract syntax tree by parsing source code files corresponding to different code units, and representing the code structure and syntax through the abstract syntax tree; Perform code analysis on different code units to obtain dependency relationships between the different code units; Traversing the abstract syntax trees corresponding to the different code units, and acquiring the dependency relationship between the codes contained in the code units themselves according to the information data contained in the abstract syntax trees; The dependencies between the different code units and the dependencies between the codes contained in the code units themselves are visually displayed.

2. According to the AST-based code call visualization control method according to claim 1, it is characterized in that: The abstract syntax tree is constructed by parsing the source code files corresponding to different code zones, including: Retrieving different code units and source code files corresponding to the code units; Performing code parsing using a lexical analysis method on the source code file corresponding to each code unit to obtain lexical units contained in the source code file of the code unit; Decomposing the lexical units according to preset grammatical rules using a grammatical analyzer to obtain expressions, statements and / or functions contained in each lexical unit; Taking the expressions, statements and / or functions contained in the lexical unit as nodes; A tree structure corresponding to each lexical unit is constructed using the nodes, and an abstract syntax tree corresponding to the code unit is generated using the tree structure.

3. According to the AST-based code call visualization control method of claim 1, it is characterized in that: Perform code analysis on different code units to obtain dependencies between the different code units, including: Retrieving different code units and abstract syntax trees corresponding to the code units; Traverse the abstract syntax tree corresponding to each code unit; Record the calling relationship, inheritance relationship and inclusion relationship contained in the abstract syntax tree corresponding to each code unit; Using a graph data structure to represent the calling relationship, inheritance relationship and inclusion relationship as dependencies, and constructing a dependency graph corresponding to each code unit including the calling relationship, inheritance relationship and inclusion relationship; The dependency graph corresponding to each code unit is traversed using the depth-first search method to identify the direct and indirect dependencies between each code unit.

4. The AST-based code call visualization control method according to claim 1 or 2, characterized in that: Performing code analysis on different code units to obtain dependencies between the different code units also includes: Real-time monitoring of the number of calls between every two code units during the running of the code units; Real-time monitoring of the number of logic types contained in the dependency relationship between every two code units during the running of the code units; Real-time monitoring of the modification of one code unit in each of two code units, and synchronization of the modification information of the corresponding code modification of the other code unit with which the code unit has a dependency relationship; wherein the modification information includes the number of modifications and the coverage of the modified code; The code modification impact value corresponding to each code unit is obtained by using the modification times and the modified code coverage; wherein the code modification impact value is obtained by the following formula: Wherein, Q represents the code modification impact value corresponding to each code unit; n represents the number of modifications that the other code unit performs synchronously when a code modification occurs in one of the two code units; P i represents the modified code coverage rate of another code unit when it is modified for the i-th time; λ represents the numerical adjustment coefficient; wherein the numerical adjustment coefficient is obtained by the following formula: Where m represents the total number of code modifications in one of every two code units; k represents the number of code lines contained in the other code unit; f i Indicates the number of modified positions in the i-th line of code; B i represents the code modification coverage when the i-th line of code is modified; w i Indicates the ratio of the number of logical types contained in the i-th line of code of every two code units to the total number of logical types contained in the other code unit when a code modification occurs in one of the other two code units; The dependency strength value between every two code units is obtained by using the code modification impact value corresponding to each code unit in combination with the number of calls between every two code units corresponding to the code unit and the number of logic types contained in the dependency relationship between every two code units, wherein the dependency strength value is obtained by the following formula: Where W represents the dependency strength value between every two code units; r represents the number of calls between every two code units when a code unit is grouped with another code unit; R represents the number of logical types contained in the dependency relationship between every two code units; M represents the total number of all logical types contained in every two code units; N i Indicates the number of logical operations executed by the code unit during the i-th call; When the dependency strength value exceeds a preset strength value threshold, the dependency relationship between the two code units corresponding to the dependency strength values ​​exceeding the preset strength value threshold is marked.

5. According to the AST-based code call visualization control method according to claim 1, it is characterized in that: Traversing the abstract syntax trees corresponding to the different code units, and acquiring the dependency relationship between the codes contained in the code units themselves according to the information data contained in the abstract syntax trees, including: Use depth-first search to traverse the nodes corresponding to the abstract syntax tree corresponding to the code unit; Identify and record the dependencies between nodes corresponding to the abstract syntax tree in real time; wherein the dependencies between the nodes include the relationship between the function caller and the called function, the location where variables are declared and used, the definition location and usage location of custom types used in the code, and the dependencies between conditional statements, loop statements, and control flow structures; The dependency relationship is represented by using a graph data structure to form a dependency graph corresponding to the dependency relationship.

6. The code call visualization control system based on AST is characterized by: The AST-based code call visualization control system includes: An abstract syntax tree construction module is used to construct an abstract syntax tree by parsing source code files corresponding to different code units, and to represent the code structure and syntax through the abstract syntax tree; A first dependency relationship acquisition module, used to perform code analysis on different code units to acquire dependency relationships between the different code units; A second dependency relationship acquisition module, used to traverse the abstract syntax trees corresponding to the different code units, and acquire the dependency relationship between the codes contained in the code unit itself according to the information data contained in the abstract syntax tree; The visualization module is used to visualize the dependency relationships between the different code units and the dependency relationships between the codes contained in the code units themselves.

7. The AST-based code call visualization control system according to claim 6, characterized in that: The abstract syntax tree building module includes: A source code file retrieving module, used to retrieve different code units and source code files corresponding to the code units; A lexical unit acquisition module, used to perform code analysis using a lexical analysis method on the source code file corresponding to each code unit, and obtain the lexical units contained in the source code file of the code unit; A lexical unit decomposition module is used to decompose the lexical units according to preset grammatical rules using a grammatical analyzer to obtain expressions, statements and / or functions contained in each lexical unit; A node acquisition module, used to take the expression, statement and / or function contained in the lexical unit as a node; The abstract syntax tree generation module is used to construct a tree structure corresponding to each lexical unit using the nodes, and generate an abstract syntax tree corresponding to the code unit using the tree structure.

8. The AST-based code call visualization control system according to claim 6, characterized in that: The first dependency acquisition module includes: An abstract syntax tree calling module, used to call different code units and the abstract syntax trees corresponding to the code units; Abstract syntax tree traversal module, used to traverse the abstract syntax tree corresponding to each code unit; An information recording module, used to record the calling relationship, inheritance relationship and inclusion relationship contained in the abstract syntax tree corresponding to each code unit; A relationship acquisition module, used to use a graph data structure to represent the calling relationship, inheritance relationship and inclusion relationship as dependencies, and to construct a dependency graph corresponding to each code unit including the calling relationship, inheritance relationship and inclusion relationship; The dependency acquisition execution module is used to traverse the dependency graph corresponding to each code unit using a depth-first search method to identify the direct dependency and indirect dependency between each code unit.

9. The AST-based code call visualization control system according to claim 6 or 7, characterized in that: The first dependency acquisition module further includes: The first real-time monitoring module is used to monitor the number of calls between every two code units during the running of the code units in real time; The second real-time monitoring module is used to monitor in real time the number of logic types contained in the dependency relationship between every two code units during the running of the code units; A third real-time monitoring module is used to monitor in real time when a code modification occurs in one of every two code units, and synchronize the modification information of the corresponding code modification with the other code unit with which it has a dependency relationship; wherein the modification information includes the number of modifications and the coverage rate of the modified code; The code modification impact value acquisition module is used to obtain the code modification impact value corresponding to each code unit by using the modification times and the modified code coverage; wherein the code modification impact value is obtained by the following formula: Wherein, Q represents the code modification impact value corresponding to each code unit; n represents the number of modifications that the other code unit performs synchronously when a code modification occurs in one of the two code units; P i represents the modified code coverage rate of another code unit when it is modified for the i-th time; λ represents the numerical adjustment coefficient; wherein the numerical adjustment coefficient is obtained by the following formula: Where m represents the total number of code modifications in one of every two code units; k represents the number of code lines contained in the other code unit; f i Indicates the number of modified positions in the i-th line of code; B i represents the code modification coverage when the i-th line of code is modified; w i Indicates the ratio of the number of logical types contained in the i-th line of code of every two code units to the total number of logical types contained in the other code unit when a code modification occurs in one of the other two code units; The dependency strength value acquisition module is used to obtain the dependency strength value between every two code units by using the code modification impact value corresponding to each code unit in combination with the number of calls between every two code units corresponding to the code unit and the number of logic types contained in the dependency relationship between every two code units, wherein the dependency strength value is obtained by the following formula: Where W represents the dependency strength value between every two code units; r represents the number of calls between every two code units when a code unit is grouped with another code unit; R represents the number of logical types contained in the dependency relationship between every two code units; M represents the total number of all logical types contained in every two code units; N i Indicates the number of logical operations executed by the code unit during the i-th call; The dependency relationship marking module is used to mark the dependency relationship between two code units corresponding to the dependency strength values ​​exceeding the preset strength value threshold when the dependency strength value exceeds the preset strength value threshold.

10. The AST-based code call visualization control system according to claim 6, characterized in that: The second dependency acquisition module includes: A node traversal module, used to traverse the nodes corresponding to the abstract syntax tree corresponding to the code unit using a depth-first search method; A real-time identification module is used to identify and record the dependency relationship between nodes corresponding to the abstract syntax tree in real time; wherein the dependency relationship between the nodes includes the relationship between the function caller and the called function, the location where the variable is declared and the location where it is used, the definition location and the location where the custom type is used in the code, and the dependency relationship between conditional statements, loop statements and control flow structures; The dependency graph acquisition module is used to represent the dependency relationship using a graph data structure to form a dependency graph corresponding to the dependency relationship.

Citation Information

Cited By

  • PEG-based AADL code-to-graph multi-level conversion method

    CN120029667A

  • Historical engineering code analysis optimization method and device, equipment and storage medium

    CN122387506A