Code processing method and apparatus, device, and storage medium
By displaying code flowcharts in a visual area, the problem of low efficiency in displaying code logic during code development is solved, enabling accurate presentation and efficient modification of code logic.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2026-04-29
- Publication Date
- 2026-05-29
AI Technical Summary
In existing technologies, due to code complexity and differences in coding style, it is difficult to efficiently and accurately display the business logic of the source code in the code repository during the code development process. It is necessary to add comments or write code development introduction documents, resulting in low human-computer interaction efficiency.
This provides a code processing method that displays a code flowchart of the source code in a visualization area. The flowchart node types include data declaration and initialization, guard statements and parameter validation, function calls and error handling, concurrency and synchronization, result construction and return, and conditional loop nodes, clearly presenting the business logic and supporting the modification and search functions of the flowchart nodes.
This approach achieves accurate description of the source code's business logic in the code flowchart, avoiding the problem of low efficiency in human-computer interaction, laying the foundation for subsequent code block modifications, and improving the efficiency of code understanding and modification.
Smart Images

Figure CN122111498A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code processing method, apparatus, device, and storage medium. Background Technology
[0002] With the development of internet technology, applications are offering increasingly richer functions, and the complexity of their programming code is also increasing.
[0003] In related technologies, due to the complexity of the application code used in the code development process, as well as the differences in the code style of the source code and the complexity of the business logic corresponding to the source code, it is often necessary for the source code developers to add comments or write special code development documentation.
[0004] However, how to efficiently and accurately display the business logic of the source code in the code repository is an urgent problem to be solved. Summary of the Invention
[0005] This application provides a code processing method, apparatus, device, and storage medium, the technical solution of which is as follows: According to one aspect of this application, a code processing method is provided, the method comprising: Obtain the source code from the code repository, the source code including at least two functions; The code flowchart of the source code is displayed in the visualization area. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the function calls in the function call list. The node types of the process nodes include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; and conditional loop nodes.
[0006] According to another aspect of this application, a code processing apparatus is provided, the apparatus comprising: A retrieval module is used to retrieve source code from a code repository, the source code including at least two functions; The display module is used to display the code flowchart of the source code in a visualization area. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the function calls in the function call list. The node types of the process nodes include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; and conditional loop nodes.
[0007] In an optional design of this application, the conditional loop node includes at least one of a for loop node and an if conditional branch node; When nested structures exist in the source code, the connection relationships between the corresponding process nodes in the code flowchart reflect the nested structure.
[0008] In an optional design of this application, the display module is further used for: In response to the selection operation of the target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the visualization area is highlighted.
[0009] In an optional design of this application, the visualization area further includes a function search area, and the display module is further used for: In response to the search information of the target function entered in the function search area, the code flowchart of the target function is displayed in the visualization area.
[0010] In an optional design of this application, the list of functions to be called includes functions called by the code block corresponding to the process node, and the functions include at least one of functions in the target code repository corresponding to the source code and external functions.
[0011] In an optional design of this application, the logical summary is a semantic description of code blocks generated by semantic understanding of the source code; The device further includes a processing module for: The source code is divided into blocks according to business logic, resulting in at least two code blocks; Generate a logical summary for each of the at least two code blocks, and assign a node type to each code block.
[0012] In an optional design of this application, the processing module is further configured to: Input the source code, the call chain information of the source code, and the flowchart structure definition information into the large language model; Receive the code segmentation result output by the large language model, the code segmentation result including the at least two code blocks.
[0013] In an optional design of this application, the code flowchart is generated based on a function call graph, which contains the call relationships between functions in the source code.
[0014] In an optional design of this application, the function call graph is constructed based on the abstract syntax tree data and type information corresponding to the source code.
[0015] In an optional design of this application, the processing module is further configured to: Based on the abstract syntax tree data and type information, identify the function definition information in the target code repository corresponding to the source code; Based on the function definition information, a unique identifier is generated for each function in the target code repository; By traversing the function nodes in the abstract syntax tree, the calling relationships between functions in the target code repository are determined.
[0016] In an optional design of this application, the processing module is further configured to: Traverse the function call nodes in the abstract syntax tree and identify the functions called in the function call nodes; when the called function is an interface method, determine the actual structure method called by the interface method based on the pre-stored correspondence between interface variables and instantiated structures, so as to establish the calling relationship between the interface method and the structure method in the target code repository.
[0017] In an optional design of this application, the display module is further used for: In response to an operation that adds a modification request for at least one target process node in the code flowchart, the target process node is displayed in the visualization area by adding an identifier; The device further includes a processing module for: Save the association between the target process node and the modification requirement.
[0018] In an optional design of this application, the device further includes a processing module for: In response to a request to generate a code modification plan, a code modification plan is generated based on the modification requirements; The display module is also used for: The code modification plan is displayed in the dialog area of the visualization area.
[0019] In an optional design of this application, the processing module is further configured to: In response to a modification suggestion entered in the dialog area, the code modification plan is updated according to the modification suggestion.
[0020] In an optional design of this application, the processing module is further configured to: In response to the confirmation operation of the code modification, code modifications are performed on the target code repository corresponding to the source code according to the code modification plan; Obtain the code differences before and after the code modification, and display the code differences in the visualization area.
[0021] In an optional design of this application, the processing module is further configured to: The cancellation control is displayed in the visualization area; In response to the triggering operation of the cancel modification control, the target code repository is restored to its state before the code modification.
[0022] According to another aspect of this application, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one instruction, at least one program, code set or instruction set, the at least one instruction, the at least one program, the code set or instruction set being loaded and executed by the processor to implement the code processing method as described above.
[0023] According to another aspect of this application, a computer-readable storage medium is provided, wherein at least one instruction, at least one program, code set, or instruction set is stored therein, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the code processing method described above.
[0024] According to another aspect of this application, a computer program product is provided, the computer program product including computer instructions stored in a computer-readable storage medium, wherein a processor reads from the computer-readable storage medium and executes the computer instructions to implement the code processing method described above.
[0025] The beneficial effects of the technical solution provided in this application include at least the following: By displaying a code flowchart of the source code, the node types of the process nodes in the flowchart can indicate the business logic of the source code. The business logic of the source code is clearly presented in the code flowchart, avoiding the problem of low human-computer interaction efficiency when adding comments or writing code development introduction documents in related technologies. The node types of the process nodes effectively ensure the accuracy of the description of the business logic of the source code, laying the foundation for subsequent modifications to the code blocks corresponding to the process nodes. Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 This is a schematic diagram of a computer system provided in an exemplary embodiment of this application; Figure 2 This is a schematic diagram of a code processing method provided in an exemplary embodiment of this application; Figure 3 This is a first flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 4 This is a schematic diagram of a code flowchart provided in an exemplary embodiment of this application; Figure 5 This is a second flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 6 This is a third flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 7 This is a schematic diagram illustrating a unique function identifier provided in an exemplary embodiment of this application; Figure 8 This is a schematic diagram illustrating the interface call relationship provided in an exemplary embodiment of this application; Figure 9 This is a fourth flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 10 This is the fifth flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 11 This is the sixth flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 12 This is the seventh flowchart of a code processing method provided in an exemplary embodiment of this application; Figure 13 This is a user interface diagram of a code logic visualization system provided in an exemplary embodiment of this application; Figure 14 This is a schematic diagram of a code processing system provided in an exemplary embodiment of this application; Figure 15 This is a structural block diagram of a code processing apparatus provided in an exemplary embodiment of this application; Figure 16 This is a structural block diagram of a server provided in an exemplary embodiment of this application.
[0028] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0030] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0031] The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The singular forms “a,” “the,” and “the” as used in this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0032] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions. For example, the source code, modification requirements and other information involved in this application were obtained under full authorization.
[0033] It should be understood that although the terms first, second, etc., may be used in this disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, a first parameter may also be referred to as a second parameter without departing from the scope of this disclosure, and similarly, a second parameter may also be referred to as a first parameter. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0034] Figure 1 A schematic diagram of a computer system provided in one embodiment of this application is shown. This computer system can implement a system architecture that serves as a code processing method. The computer system may include: a terminal 100 and a server 200.
[0035] Terminal 100 can be an electronic device such as a mobile phone, tablet computer, or PC (Personal Computer). A client application for the target application can be installed and run on terminal 100. This target application can be a code processing application, a code development application, or other applications that provide code processing functionality, such as an intelligent agent conversation application; this application does not limit the specific application. Furthermore, this application does not limit the form of the target application, including but not limited to apps (applications), mini-programs, etc., installed on terminal 100, and it can also be in web page form.
[0036] Server 200 can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server providing cloud computing services. Server 200 can be the backend server for the aforementioned target application, used to provide backend services to the clients of the target application.
[0037] The code processing method provided in this application embodiment can be executed by a computer device, which refers to an electronic device with data computing, processing, and storage capabilities. Figure 1 Taking the implementation environment of the scheme shown as an example, the code processing method can be executed by the terminal 100 (such as by the client of the target application installed and running in the terminal 100), or by the server 200, or by the interaction and cooperation between the terminal 100 and the server 200. This application does not limit this.
[0038] Furthermore, the technical solution of this application can be combined with blockchain technology. For example, some data involved in the code processing method disclosed in this application (such as source code, the relationship between process nodes and modification requirements, etc.) can be stored on the blockchain. Terminal 100 and server 200 can communicate through a network, such as a wired or wireless network.
[0039] Figure 2 A schematic diagram of a code processing method provided in an exemplary embodiment of this application is shown.
[0040] In this embodiment, a webpage 500 provided by the code logic visualization system is used as an example. The code flowchart display area 510 displays the code flowchart corresponding to the source code. The code flowchart includes multiple flow nodes, each of which corresponds to a code block in the source code. The first flow node 512 in the code flowchart display area 510 is surrounded by a dashed line marker 514, indicating that the first flow node 512 has a modification requirement. For example, the block comment area 520 provides an input field for modification requirements. The text box 522 in the block comment area 520 is a text input box for modification requirements. The triggering operation of the first submit modification control 524 indicates that the association between the first flow node 512 and the modification requirement added in the text box 522 is saved.
[0041] The function search area 530 on webpage 500 is used to search for functions in the source code. The search box 532 provides an input field for search information. The search history information 534 contains parameter information for previously executed searches. For example, in response to entering a function name in the function search area 530, functions in the source code with the same name are highlighted in the source code display area 540 to visually emphasize the search results.
[0042] The session area 550 in webpage 500 is used to display and adjust code modification plans. In some examples, output control 556 is used to generate a code modification plan for the source code based on the modification requirements corresponding to each process node, and to display the code modification plan in session record 552. If the code modification plan does not meet expectations, modification suggestions are entered in information input box 554, indicating how to adjust the code modification plan. Furthermore, by triggering output control 556 again, the code modification plan is updated according to the modification suggestions entered in information input box 554, and the new code modification plan is displayed in session record 552. In response to the triggering operation of the second submit modification control 558, modifications are performed on the source code in source code display area 540 according to the code modification plan displayed in session record 552.
[0043] The code processing method will be described below through the following examples.
[0044] Figure 3 A first flowchart of a code processing method provided in an exemplary embodiment of this application is shown. The method can be executed by a computer device. The method includes: Step 300: Obtain the source code from the code repository.
[0045] A code repository is an electronic storage system used to implement at least one of the functions of storing, managing, version monitoring, and collaboratively maintaining source code. For example, a code repository includes, but is not limited to, repositories based on distributed version control systems, repositories based on centralized version control systems, or remote repository services provided by cloud hosting platforms. The source code in the code repository is used to implement at least one of the business logics such as login, data computation, payment, information query, information sharing, and server resource allocation. The code repository can be the direct target of code modification, and its stored source code can be obtained through cloning, pulling, or local copying. This application does not restrict the method of obtaining the source code in the code repository.
[0046] The source code is written in a programming language and is used to form a set of instructions for an executable program. The source code includes at least two functions. For example, the programming language used in the source code includes, but is not limited to, at least one of the following: C, Java, Python, Go, and JavaScript.
[0047] Step 310: Display the code flowchart of the source code in the visualization area.
[0048] The functions in the source code can be divided into at least two code blocks, that is, the source code includes at least two code blocks. Any two code blocks in the source code can be at least one of the following: consecutive, spaced apart by other information, or interleaved. This embodiment does not limit the positional relationship between code blocks.
[0049] A code flowchart contains multiple flow nodes, each corresponding to at least one code block in the source code. For example, flow nodes display descriptive information about the corresponding code block; in some examples, each flow node displays a logical summary of the code block it corresponds to and at least one of the functions called. This information can be displayed as text or as icons, etc.
[0050] Next, the process nodes will be introduced. Regarding the node types of process nodes, in one optional implementation of this application, the node types include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; and conditional loop nodes. The different node types will be described below: The code block corresponding to the node type for data declaration and initialization is used to complete at least one of the following: declaration, definition, and initial assignment of variables, constants, data structures, etc. For example, the above code block in the source code is used to achieve at least one of the following purposes: determining the initial running state of a function, determining the scope of a function, etc.
[0051] The code block corresponding to the node type of the guard statement and parameter validation is used to check the preconditions of the function, the legality or validity of the parameters, and to exit or report an error immediately if the conditions are not met. For example, the validation methods implemented by the above code block include, but are not limited to, at least one of the following: null value checking, range validation, type checking, and resource availability checking.
[0052] The code block corresponding to the function call and error handling node type is used to execute calls to other functions and further to catch errors in the call results, such as abnormal return values or error codes. This code block implements function calls synchronously or asynchronously and can also perform post-error handling such as exception retries and error logging.
[0053] The code blocks corresponding to the concurrent and synchronous node types are used to control task parallelism, resource contention, sequence coordination, or waiting for notification in multi-threaded, coroutine, or asynchronous execution environments. The code blocks corresponding to the result construction and return node types are used to assemble the data generated by the execution of the code block into a preset output format, such as at least one of the following: output object, structure, primitive value, or response message.
[0054] The code block corresponding to the node type of the conditional loop node is used to implement the control flow branching and iteration of the source code. For example, the above code block is used to implement at least one of the following functions: state machine branching, loop accumulation / filtering, condition termination judgment, nested loop control, and recursive termination condition.
[0055] In summary, the method provided in this embodiment, by displaying a code flowchart of the source code, allows the node types of the process nodes in the flowchart to indicate the business logic of the source code. The code flowchart clearly presents the business logic of the source code, avoiding the low efficiency of human-computer interaction when adding comments or writing code development documentation in related technologies. The node types of the process nodes effectively ensure the accuracy of the description of the source code's business logic, laying the foundation for subsequent modifications to the code blocks corresponding to the process nodes.
[0056] In one optional implementation of this application, the conditional loop node includes at least one of a for loop node and an if conditional branch node; when there is a nested structure in the source code, the connection relationship between the corresponding flow nodes in the code flowchart reflects the nested structure.
[0057] Figure 4This diagram illustrates a code flowchart provided in an exemplary embodiment of this application. The start node 602 indicates the beginning of the source code. The for loop node 604 indicates the presence of nested structures in the source code. The for loop node 604 determines whether to enter the loop body. If the condition for entering the loop body is met, the data initialization node 606 is executed; otherwise, no code is executed, and the process proceeds to the end node 616.
[0058] Upon entering the loop body, data initialization node 606 is used to initialize functions, result mappings, and other information; for example, storing the return result of the initialization function. If conditional branch node 608 indicates the existence of a conditional branch within the loop body, suggesting parallel data processing. If the result of the If conditional branch node 608 is the first result, the first data processing node 615 is executed, and after executing the first data processing node 615, the loop enters the termination node 616.
[0059] If the conditional branch node 608 determines the second result, the second data processing node 610, the error handling node 612, and the execution result feedback node 614 are executed to generate feedback information for the current execution loop body. Based on the feedback information generated by the execution result feedback node 614, the process returns to the for loop node 604 to determine again whether to enter the loop body.
[0060] In summary, the method provided in this embodiment, by determining the node type for process nodes, presents the processing type of code blocks in the code flowchart. When there is a nested structure in the source code, the connection relationship between the corresponding process nodes in the code flowchart is based on at least one of the conditional loop nodes, including for loop nodes and if conditional branch nodes, thus fully presenting the nested structure in the source code and ensuring the accuracy of the information in the code flowchart.
[0061] Figure 5 A second flowchart of a code processing method provided in an exemplary embodiment of this application is shown. This method can be executed by a computer device. That is, in Figure 3 Based on the illustrated embodiment, at least one of steps 342 and 344 is also included: Step 342: In response to the selection operation of the target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the visualization area is highlighted.
[0062] In this embodiment, the selection operation targeting a target process node is used as an example. However, in different examples, it is possible that the selection operation is performed on a process node other than the target process node. For example, the selection operation is used to indicate a need to view the original code of the code block corresponding to the selected target process node.
[0063] For example, the visualization area, also known as the visualization interface, is an area that displays any kind of information related to the source code in this embodiment or any of the embodiments described above. The source code display area is a functional area of the visualization area used to present the source code. It is understood that the source code display area may always exist before the selection operation, or it may be updated in response to the selection operation; this application does not limit this. It is understood that the descriptions of one or more functional areas in the visualization area in the various embodiments of this application are merely exemplary descriptions, and any area that can display the function of the functional area can be considered to belong to the aforementioned functional area; the various areas can also be separated by any of the following methods: pop-ups, dividing lines, etc.
[0064] For example, the highlighted code block is visually salient in the source code, and the code block corresponding to the target process node targeted by the selected operation is displayed in the source code by at least one of the following methods: highlighting, bolding, adding underline, enlarging the font, changing the color, etc.
[0065] Step 344: In response to the search information of the target function entered in the function search area, display the code flowchart of the target function in the visualization area.
[0066] In this step, the visualization area also includes a function search area. The function search area provides an input field for searching information. Since the source code contains a large number of functions, this input field provides a quick way to find functions within the source code.
[0067] For example, the objective function exists in one or more flow nodes in the code flow. In some examples, the flow node containing the objective function is displayed in a visually prominent manner, such as being highlighted, having a bold border, or at least one of these features. In other examples, the flow node containing the objective function is displayed in a visually centered position by adjusting the display position of the code flow chart. The visually centered position can be the center of the visualization area or the center of the functional area within the visualization area used to display the code flow chart.
[0068] Understandably, in some examples, Figure 3Steps 300 to 310 shown can be combined with any one of steps 342 and 344 in this embodiment to form a new embodiment and be implemented independently. This application does not limit this.
[0069] In summary, the method provided in this embodiment, through the selection of target process nodes and the search information of the input target function, highlights the content of interest in the source code. It provides a function to present the relationship between process nodes and search information in the visualization interface and code blocks in the source code, facilitating the rapid presentation of the corresponding display elements of code blocks in the source code within the visualization interface. This avoids the problem of not being able to quickly match display elements in the visualization interface with code blocks when the source code has diverse function types and a large amount of information, thus improving the efficiency of human-computer interaction.
[0070] In one alternative implementation of this application, the list of functions called regarding the process nodes shown in the code flowchart is as follows: The function list includes functions called by the code blocks corresponding to the process nodes. These functions include at least one of the functions within the target code repository corresponding to the source code and external functions. For example, an internal function refers to a function defined in the source code that belongs to the target code repository. Internal functions stored in the target code repository maintain version consistency with the code repository. Internal functions are functions defined by the source code during the source code development process; basic function information such as the definition, scope, and calling method of internal functions are stored in the source code or target code repository.
[0071] For example, an external function is a function called in the source code that is not defined in the target code repository. An external function can be implemented as at least one of the following: a function in the programming language's standard library, a third-party function library, or a function provided by an application programming interface. The scope, parameter definition, etc., of an external function are usually controlled by a third party or function provider and cannot be directly modified in the target code repository.
[0072] In one alternative implementation of this application, the logic summary regarding the invocation of the process nodes shown in the code flowchart is as follows: The logical summary is a semantic description of a code block generated by semantic understanding of the source code; for example, semantic understanding of the source code can be achieved by calling an Artificial Neural Network (ANN) model, or it can be obtained by querying the function description text of at least one function in the source code.
[0073] In some examples, the process of semantic understanding of source code is introduced by calling an artificial neural network model: Divide the source code into blocks according to business logic to obtain at least two code blocks.
[0074] For example, business logic is used to indicate the function of a logical block composed of one or more functions in the source code. In some examples, the code blocks are divided according to the functions' functions in the source code, grouping functions that perform similar business operations into the same code block, such as grouping functions that implement data validation or external interface calls into the same code block. In other examples, the code blocks in the source code are divided based on the logical or calling relationships between functions. Based on the calling relationships between functions, functions with upstream and downstream call dependencies are aggregated into the same code block. For example, the entry function and its directly or indirectly called functions are combined into a code block to ensure continuity in the calling sequence of functions within the code block. In still other examples, based on the information flow of the function's input and output data, functions with the same input data source or producing the same output data results, and functions whose output data has a mutual succession relationship, are grouped into the same code block, and a function call graph is used to represent the calling relationships.
[0075] For example, by dividing the source code into blocks according to business logic, the source code can be divided into at least two code parts with relatively independent functions, resulting in at least two code blocks.
[0076] In one alternative implementation of this application, the process of determining at least two code blocks can be implemented as follows: Input the source code, source code call chain information, and flowchart structure definition information into the Large Language Model (LLM). For example, LLM has the ability to perform semantic analysis of natural language, performing semantic analysis on the logical relationships between functions in the source code and the call chain information of the source code to obtain the function functions in the source code described in natural language. The large language model groups code parts that implement the same function into a code block.
[0077] For example, call chain information in source code can be obtained from comments added during source code writing, manually compiled from source code, or analyzed from source code or its runtime logs. The following section will describe methods for obtaining call chain information using a separate embodiment.
[0078] For example, the flowchart structure definition information includes, but is not limited to, the node type of the process node, the constraint information of the connection between process nodes (such as the number of inputs and outputs of a process node), and the constraint information of process nodes on functions (such as the permitted function types in the code segment corresponding to the process node of the first node type).
[0079] Receive the code block results from the LLM output, which include at least two code blocks.
[0080] For example, at least two code blocks are the segmentation results of the input source code by the large language model. It should be noted that the input to the large language model can be input during the training or fine-tuning phase of the large language model. For example, the flowchart structure definition information is fixed knowledge information and can be input into the large language model during the training phase. The model parameters of the large language model have the semantic understanding ability of the flowchart structure definition information.
[0081] Generate a logical summary for each of at least two code blocks and assign a node type to each code block.
[0082] For example, the logical summary information can be generated by a large language model invoked during source code segmentation, or it can be predicted by a new artificial neural network model invoked after at least two code blocks have been obtained; this application does not impose any restrictions on this. Similarly, the large language model obtains flowchart structure definition information, and the node type of the code block can be assigned by the large language model, or it can be determined by re-invoking the artificial neural network model to accurately describe the meaning of the code block after the source code is segmented according to business logic, or it can be determined based on the function type in the code block.
[0083] In summary, the method provided in this embodiment divides the source code into blocks according to business logic by calling a large language model, achieving code functional segmentation of the source code. Semantic analysis is performed on the logical relationships between various functions in the source code to obtain a description of the function's role in the source code in natural language. The large language model groups code sections that implement the same function into a single code block, ensuring the accuracy of the information in the code flowchart.
[0084] Figure 6 A third flowchart of a code processing method provided in an exemplary embodiment of this application is shown. This method can be executed by a computer device. This embodiment is used to describe the process of constructing a code flowchart. In some examples, various steps in this embodiment are performed before step 310. The method includes: Step 302: Construct a function call graph based on the abstract syntax tree data and type information corresponding to the source code.
[0085] For example, the Abstract Syntax Tree (AST) is obtained by parsing the source code. It can also be obtained separately from the source code; this embodiment does not limit the method of obtaining the AST. In some examples, the source code is programmed in Go, and the AST data is obtained by parsing the static repository code of the source code using a Go language parsing tool (such as the core package `go / packages` in the Go toolchain).
[0086] Abstract Syntax Trees (ABSTs) eliminate visual clutter such as spaces and comments by defining various node types (such as declarations, statements, and expressions), parsing source code into hierarchical, structured objects. Each node in an ABST records the logical function of the source code and also retains the location information of the corresponding function or code segment within the source code.
[0087] In one alternative implementation of this application, this step can be implemented as the following sub-steps: Sub-step 1: Based on the AST data and type information, identify the function definition information in the target code repository corresponding to the source code; For example, type information refers to the function type in the source code, such as that obtained through analysis of the source code by a static type checker. In the case of Go source code, the function type can be recorded in the parameter list or return value list. For example, by traversing the function declaration nodes in the AST and combining the metadata recorded in the type information, such as the function signature, receiver type, and package path, function definitions can be distinguished into internal function definitions belonging to the target code repository and external function definitions belonging to external dependencies.
[0088] Sub-step 2: Based on the function definition information, generate a unique identifier for each function in the target code repository; For example, each function's unique identifier is used to uniquely identify the function in the source code. In some instances, due to the richness of function types, the unique identifiers of different function types have different identifier formats.
[0089] Figure 7 This illustration shows a schematic diagram of a function unique identifier provided in an exemplary embodiment of this application. The function unique identifier scheme provided in this embodiment schematically illustrates four naming formats designed by the present invention to ensure that each function has a unique identifier in the call graph. The unique identifier adopts at least one of the following formats depending on the function type: See Figure 7 In (a), for package functions, the unique identifier format is: package path.function name; see also Figure 7 In (b), for non-pointer functions of a struct method, the unique identifier format is: package path.(struct name).method name; see also Figure 7 In the (c) section, for pointer functions to struct methods, the unique identifier format is: package path.(*struct name).method name; see also Figure 7 In the (d) section, for interface method functions, the unique identifier format is: package path.(interface name).method name.
[0090] The diagram illustrates that function unique identifiers have different formats for different function types. This format accurately distinguishes function definitions of different types, avoiding naming conflicts. Particularly for Go's interface methods, this approach, by including the interface name, accurately identifies the definition location of the interface method, laying the foundation for subsequent resolution of implicit interface call relationships.
[0091] Sub-step 3: By traversing the function nodes in the AST, determine the calling relationships between functions in the target code repository; For example, the source code includes multiple functions. To obtain the complete call relationships between these functions, it's necessary to traverse the function nodes in the Abstract Syntax Tree (AST) to avoid missing any function call relationships. For example, for a second function called by a first function, traversing back to the first function reveals the call relationship between them. Traversing back to the second function again reveals the same call relationship. By recording the number of times the call relationship is retrieved, the confidence level of the function call relationships is verified. For example, if the call relationship between two functions is retrieved multiple times, and the same call relationship is found from both the calling and called functions, this call relationship has high confidence and there is no risk of incorrect call relationship retrieval.
[0092] Furthermore, sub-step three can be implemented as follows: traverse the function call nodes in the AST and identify the functions called in the function call nodes; when the called function is an interface method, determine the actual structure method called by the interface method based on the pre-stored correspondence between interface variables and instantiated structures, so as to establish the calling relationship between interface methods and structure methods in the target code repository.
[0093] Figure 8 A schematic diagram illustrating the interface call relationship provided in an exemplary embodiment of this application is shown.
[0094] This embodiment provides a schematic diagram illustrating the implicit call relationship resolution of Go language interfaces. The left side shows the interface definition area, displaying the definition of the interface IFoo and its method function DoSomething(); the middle area shows the struct implementation area, illustrating how structs A, B, and C implement the interface IFoo; the right side shows the call and resolution area, demonstrating the resolution process when calling a method through interface variables. This embodiment extracts the relationship between the interface and the implementing struct by traversing struct information and records the correspondence between interface variables and instantiated structs during the resolution process, achieving accurate association between interface methods and the actually called struct methods. This resolution mechanism can cover most Go interface call scenarios, making the construction of the code call graph more complete and accurate.
[0095] Step 304: Generate a code flowchart based on the function call graph.
[0096] As described above, the function call graph uses functions in the source code as the granularity to illustrate the call patterns between functions and demonstrate their dependencies. When the source code is divided into at least two code blocks, the call relationships of functions within a code block are aggregated to obtain the call relationships between each function in that block and other functions. This further identifies the code blocks to which associated functions belong based on the call relationships, determines the call patterns between code blocks, and generates a code flowchart indicating the logical relationships between code blocks.
[0097] Figure 9 A fourth flowchart of a code processing method provided in an exemplary embodiment of this application is shown.
[0098] The programming language parsing tool 654 is invoked to parse the source code in the target code repository 652, obtaining the abstract syntax tree data 654a and type information 654b corresponding to the source code. The abstract syntax tree parses the source code into structured objects with hierarchical relationships. The abstract syntax tree data 654a indicates the logical relationships between various functions in the source code, and the type information 654b is the function type of the functions in the source code. The programming language parsing tool 654 is the core package go / packages in the Go language toolchain.
[0099] Programming language parsing tool 654 is used to determine the unique identifiers of functions in source code. (See reference...) Figure 9 To ensure that each function has a unique identifier in the function call graph, the programming language parsing tool 654 employs multiple naming formats designed for different function types. The function call graph construction module 656 determines the call relationships between functions in the target code repository by traversing the function nodes in the abstract syntax tree data, thus outputting the function call graph 656a.
[0100] Figure 10 A fifth flowchart of a code processing method provided in an exemplary embodiment of this application is shown. This method can be executed by a computer device. That is, in Figure 3 Based on the illustrated embodiment, steps 320 and 330 are also included: Step 320: In response to a modification request for at least one target process node in the code flowchart, display the target process node in the visualization area by adding an identifier.
[0101] For example, the modification request addition operation is an operation executed at the process node level. This operation provides modification requests for at least one target process node. For example, modification requests can be entered through human-computer interaction or pre-set.
[0102] For example, the "Modify Requirement Addition" operation is used to indicate a modification requirement for part or all of the code blocks in the source code. In some examples, the "Modify Requirement Addition" operation carries code instruction information, using natural language semantics to indicate the code block or process node location targeted by the modification requirement. In another example, the process node has a corresponding functional entry point, and the "Modify Requirement Addition" operation is an interactive operation for at least one process node that has a corresponding functional entry point, determining at least one target process node corresponding to the obtained modification requirement through the functional entry point.
[0103] For example, in response to a modification request addition operation, at least one target process node targeted by the modification request addition operation is marked with an identifier, the identifier style including at least one of dashed borders and star icons. In some examples, the process node is indicated as the target process node whose code content needs to be adjusted as indicated by the modification request addition operation by displaying a dashed border surrounding the process node or displaying a star icon around the process node (such as at the corner of the process node).
[0104] For example, the modification requirement to add an operation can be implemented as at least one of the following: touch operation on a touch screen (such as at least one of single click, double click, long press, etc.); trigger operation of physical buttons, physical scroll wheels, etc. of information input devices such as keyboards and mice.
[0105] Step 330: Save the association between the target process node and the modification requirements.
[0106] As described above, the modification request addition operation is executed at the process node level; correspondingly, the modification request indicated by the modification request addition operation is aimed at the code block corresponding to the process node. It can be seen that there is a relationship between the target process node and the modification request. After obtaining the modification request addition operation, the relationship between the target process node and the modification request is saved in an automatic or manually triggered interactive manner.
[0107] In some examples, saving the association in this step and displaying the target process node with an added identifier in step 320 can be performed simultaneously; for example, if the target process node is displayed with an identifier, the association between the target process node and the modification requirement is saved.
[0108] In summary, the method provided in this embodiment, through the modification request addition operation, indicates the modification method of code block-level information in the source code, and saves the association between the target process node targeted by the modification request addition operation and the modification request. This achieves accurate recording of the code block modification method, laying the foundation for subsequent modification of code blocks in the source code. Saving the association between the target process node and the modification request avoids the shortcomings of natural language in indicating the expected code location when there are diverse function types and a large amount of information in the source code. It reduces the risk of performing unexpected modifications to code that is not expected to be modified during the process of adjusting the source code based on modification requests in natural language, effectively ensuring the accuracy of the source code modification location and improving the effect of code modification based on natural language.
[0109] Figure 11 A sixth flowchart of a code processing method provided in an exemplary embodiment of this application is shown. This method can be executed by a computer device. That is, in Figure 3 Based on the illustrated embodiment, steps 352 and 354 are also included: Step 352: In response to the request to generate a code modification plan, generate a code modification plan based on the modification requirements.
[0110] As described above, the modification requirement addition operation targets at least one process node. The generation request is generated after the modification requirement is added. For example, after adding modification requirements to the various process nodes that are expected to be modified, the code modification plan generation operation instructs the generation of a code modification plan. The generation request is the request information corresponding to the code modification plan generation operation.
[0111] For example, a code modification plan describes instructions based on modification requirements in natural language, adjusting the planned modification method for code blocks.
[0112] As described above, the modification request is a suggestion to modify the target process node. During the source code modification process, the second code block corresponding to other process nodes outside the target process node will not be adjusted. However, it does not preclude adaptive adjustments to the second code block based on modifications to the first code block corresponding to the target process node. For example, the first code block in the source code includes a first function; in the second code block, the first function is referenced by recording its name. Based on the modification request, the first function in the first code block of the source code is modified by changing the first function to a second function with a different name, thus adjusting the function type of the first function. To ensure the correct reference to the first function in the second code block, the name of the function reference is adaptively adjusted without changing the logical meaning of the second code.
[0113] Step 354: Display the code modification plan in the dialog area of the visualization area.
[0114] For example, similar to the source code display area mentioned above, the dialog area may exist indefinitely before the generation request for the code modification plan is obtained, or it may be updated and displayed in response to the generation request being obtained.
[0115] For example, a code modification plan is used to indicate how a code block is planned to be modified. A code modification plan can demonstrate how a code block is planned to be modified from at least one of the goals of modifying the code block, the implementation process, and the existing defects of the code block indicated by the modification requirements.
[0116] In one implementation, the modification target indicates the technical state that the code block is expected to achieve. This could include at least one of the following: fixing code block defects, optimizing code block performance, refactoring code block structure, enhancing code block readability, adapting to interface changes involved in the code block, or improving security.
[0117] In another implementation, the process describes the specific steps for modifying the code block, the order in which different functions within the code block are modified, and their dependencies. This may include at least one of the following: modifying the functions involved in the code block, the planned algorithm or design pattern, and the code block's testing strategy.
[0118] In another implementation, the existing defects description refers to defects present in the code block specified in the modification requirement. These may include at least one of the following: logical errors, functional defects, security vulnerabilities, lack of extensibility documentation, etc.
[0119] In some examples, Figure 3 Steps 300 to 310 shown can be combined with steps 352 and 354 in this embodiment to form a new embodiment and be implemented separately. This application does not limit this.
[0120] In summary, the method provided in this embodiment, through the modification requirement addition operation, indicates the modification method of code block-level information in the source code, saves the association between the target process node targeted by the modification requirement addition operation and the modification requirement, and achieves accurate recording of the code block modification method, laying the foundation for subsequent modification of code blocks in the source code. By displaying the code modification plan, the planned modification method of the source code is presented in natural language, and the specific steps of modifying the source code are described in natural language before the source code modification is executed; this reduces the risk of performing unexpected modifications to the source code and provides a mechanism for confirming the source code modification method. The target process node selection operation and target function search information provide an interactive way to visually highlight the code blocks of interest in the source code, effectively presenting the display position of the target process node in the code flowchart in the source code. The target function search information provides a function entry point for quickly locating the function to be found when there are many functions in the source code, improving the efficiency of human-computer interaction.
[0121] Figure 12 A seventh flowchart of a code processing method provided in an exemplary embodiment of this application is shown. This method can be executed by a computer device. In some examples, the method in this embodiment can be... Figure 11 This is executed after step 354 in the corresponding embodiment. The method includes: Step 362: In response to the modification suggestions entered in the dialog area, update the code modification plan according to the modification suggestions.
[0122] In this embodiment, the modification suggestion is used to indicate the adjustment method for the code modification plan, such as recording the errata content of the code modification plan in natural language, optimizing the code modification plan, etc. For example, the dialog area can be a display area for the code modification plan, or it can be an information input entry that is different from the modification requirements of the process node.
[0123] Step 364: In response to the confirmation operation of the code modification, execute the code modification on the target code repository corresponding to the source code according to the code modification plan.
[0124] For example, the confirmation operation for code modification is used to indicate the modification method of the code block indicated by the code modification plan. If step 362 was performed before this step, the code modification plan was updated based on the modification suggestions.
[0125] In one example, the entry point for the confirmation operation differs from the entry point for the operation corresponding to the request to generate the code modification plan. In another example, in response to the operation corresponding to the request to generate the code modification plan, the entry point for the above operation switches to the entry point for the confirmation operation. The confirmation operation for code modifications is implemented in the same human-computer interaction location or using the same human-computer interaction method. For example, the confirmation operation for code modifications can be an interactive operation of the entry point provided in the dialog area, or it can be an interactive operation of the entry point in another functional area within the display area or visualization area where the code flowchart is located.
[0126] For example, the target code repository stores the code blocks corresponding to the target process nodes. For example, the target code repository also stores or caches historical versions of the target code blocks or the modifications performed. For example, code modifications made in the target code repository are executed according to the adjustment methods recorded in the code modification plan.
[0127] Step 366: Obtain the code differences before and after the code modification, and display the code differences in the visualization area.
[0128] For example, the code differences before and after the code modification can be obtained through the differences between different historical versions of the code block recorded in the target code repository; or through the recorded modifications made to the code block. This application does not limit the method of determining code differences.
[0129] For example, code differences can be displayed by showing the different code before and after the code modification, or by visually highlighting the differences between the modified source code and the original source code, or by displaying revision information on the original source code to show how to modify it to obtain the modified source code, thus realizing the display of code differences before and after the code modification; this application does not limit the way code differences are displayed.
[0130] For example, the code differences are typically displayed in the source code display area of the visualization area, but it is not excluded that they may be displayed in other locations within the visualization area.
[0131] In some examples, steps 300 to 310, 352, 354, and 362 described above can be combined to form new embodiments and implemented individually; steps 310 to 330, 352, 354, 364, and 366 described above can be combined to form new embodiments and implemented individually. It is understood that steps 362 to 366 in this embodiment can all be executed after step 354.
[0132] Step 372: Display the Cancel Modification control in the visualization area.
[0133] In this step, the code modification plan describes the changes to the code block in natural language. In response to the confirmation action, the natural language description of the changes is implemented as the actual code modification. To avoid the risk of discrepancies between the actual code modification and the user's expectations, a cancellation control is displayed in the visual area, providing an entry point for canceling modifications to the code block in the target code repository.
[0134] In some examples, the cancel modification control in this step is updated and displayed after code modifications are made to the target code repository corresponding to the source code. For instance, the cancel modification control provides an entry point for reverting the target code repository from the current version to a previous version.
[0135] Step 374: In response to the triggering operation of the cancel modification control, restore the target code repository to the state before the code modification.
[0136] For example, in response to a triggering operation of the cancel modification control, the target code repository is instructed to revert from the current version to a historical version. The target code repository caches the code blocks before the code modification, or the target code repository has version management functionality for code blocks, stores the modification methods of code blocks between different versions, or directly stores code blocks of different versions.
[0137] In some examples, other steps besides step 362 in this embodiment may also be executed after step 354, combined into new embodiments and implemented separately. This application does not limit this.
[0138] In summary, the method provided in this embodiment, through the modification requirement addition operation, indicates the modification method of code block-level information in the source code, saves the association between the target process node targeted by the modification requirement addition operation and the modification requirement, and achieves accurate recording of the code block modification method, laying the foundation for subsequent modification of the code block in the source code. By displaying the code modification plan, the planned modification method of the source code is presented in natural language, describing the specific steps of modifying the source code in natural language before execution; this reduces the risk of performing unexpected modifications to the source code and provides a method for modifying the source code. By providing an input entry for modification suggestions, the function of adjusting the planned modification method of the source code is provided, effectively ensuring the accuracy of the source code modification method and improving the effect of code modification based on natural language.
[0139] Figure 13 The diagram shows an interface of a code logic visualization system provided in an exemplary embodiment of this application.
[0140] The code logic visualization system provides a webpage 500 as an example. The code flowchart display area 510 displays the code flowchart corresponding to the source code, which includes multiple flow nodes. In response to the selection operation 500a of the first flow node 512, a highlight background 542 is added to the first code block corresponding to the first flow node 512 in the source code display area 540, making the selected code block visually prominent. Similarly, searching for the name of a flow node or function name in the search box 532 in the function search area 530 also allows the selected code portion to be highlighted in the source code display area 540.
[0141] After the selection operation 500a of the first process node 512 is obtained, the modification request entered in the block comment area 520 is added for the first process node 512, and the modification request is entered in natural language in the text box 522. In response to the first trigger operation 500b of the first submit modification control 524, indicating confirmation of the modification request for the first process node 512, a dashed line marker 514 is displayed around the first process node 512 to indicate that a modification request has been added to the first process node 512. In some examples, the dashed line marker 514 displayed around the first process node 512 also indicates that the association between the modification request and the first process node 512 is saved.
[0142] The output control 556 in the session area 550 is used to generate a code modification plan for the source code based on the modification requirements corresponding to each process node. If adjustments to the code modification plan are required, modification suggestions are entered in the information input box 554. If no adjustments to the code modification plan are required, in response to the second trigger operation 500c of the second submit modification control 558, the source code in the source code display area 540 is instructed to be modified according to the code modification plan displayed in the session record 552.
[0143] The following describes the application scenarios of the code processing methods provided in various embodiments of this application.
[0144] In one application scenario, the visualization area in the code processing method provided in this application is provided by an intelligent agent conversation application. In some examples, the intelligent agent conversation application is implemented as a webpage; the intelligent agent conversation application provides an upload entry point for code files with source code, and provides function entry points for adding and modifying requirements in the code flowchart.
[0145] Figure 14 A schematic diagram of a code processing system provided in an exemplary embodiment of this application is shown.
[0146] The client layer 750 provides a World Wide Web (Web) browser 752. In this embodiment, the Web browser 752 provides intelligent agent conversation functionality through web pages, thereby implementing the code processing methods provided in various embodiments of this application. The server layer 760 includes a front-end server 762, a back-end API server 764, and an LLM service interface 766. The front-end server 762 provides backend support for the intelligent agent conversation functionality provided in web page form, and hosts static resources of the web page, such as Hyper Text Markup Language (HTML), Cascading Style Sheets (CSS), and images. The front-end server 762 is typically used to implement the first-screen rendering of web pages, such as server-side rendering (SSR) or static sites.
[0147] Backend API server 764 provides backend support for the intelligent agent conversation functionality provided in web page format. It handles business logic related to code modifications, data access, and provides an Application Programming Interface (API) for frontend calls. Backend API server 764 receives API requests from frontend server 762 or the web page and returns data in formats such as Extensible Markup Language (XML) or JavaScript Object Notation (JSON).
[0148] Backend API server 764 calls LLM service interface 766 to segment the source code into multiple code blocks. During the segmentation process, LLM also performs semantic understanding of the source code, generating a logical summary for each code block. Backend API server 764 calls AI Agent service 768 to generate a code modification plan, for example, using modification requirements as input information to generate a code modification plan.
[0149] The backend API server 764 is also used to modify the source code in the code repository 772 of the data layer 770. In order to display the difference information before and after the source code modification, the cache 774 provided by the data layer 770 records different historical versions of the code block in the code repository 772. By comparing the different historical versions, the difference information of the code before and after the modification can be obtained.
[0150] The following describes the code processing methods: Retrieve the source code from the code repository, which contains at least two functions; A code repository is an electronic storage system used to implement at least one of the following functions: storing, managing, version monitoring, and collaboratively maintaining source code. Source code is written in a programming language and is used to form a set of instructions for an executable program; source code includes at least two functions.
[0151] The code flowchart of the source code is displayed on the web page provided by the intelligent agent conversation application. The code flowchart contains multiple process nodes. Each process node corresponds to at least one code block in the source code. Each process node is used to display the logical summary of the code block corresponding to the process node and at least one of the functions called in the list. In this embodiment, the webpage provided by the intelligent agent conversation application offers a function entry point for uploading source code as a file. The source code can be uploaded in text format or compiled machine language format. For example, the logical summary of the code block and the list of called functions can be displayed on the process node at all times, or it can be triggered to display when the process node is selected first. The node types of the process node include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; conditional loop nodes.
[0152] In one alternative implementation of this application, it further includes: In response to the selection of a target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the web page provided by the agent conversation application is highlighted.
[0153] For example, the webpage provided by the intelligent agent conversation application, also known as the visual interface, is an area that displays any kind of information related to the source code in this embodiment or any of the embodiments described above. The source code display area is a functional area of the webpage provided by the intelligent agent conversation application, used to present the source code. It is understood that the source code display area may always exist before the selection operation, or it may be updated in response to the selection operation; this application does not impose any limitations on this.
[0154] In one alternative implementation of this application, it further includes: In response to the search information for the target function entered in the function search area, the code flowchart of the target function is displayed on a web page provided by the agent conversation application.
[0155] In this step, the webpage provided by the intelligent agent conversation application also includes a function search area. This function search area provides an input field for searching information. Since the source code contains a large number of functions, this input field provides a quick way to find functions within the source code.
[0156] In one alternative implementation of this application, it further includes: In response to a modification request for at least one target process node in the code flowchart, the target process node is displayed in the web page provided by the agent conversation application by adding an identifier. In this embodiment, the intelligent agent tool application provides a functional entry point for adding or modifying process nodes. In one example, when a target process node is selected by at least one of the following methods: single click, double click, long press, etc., an information entry box for modification requests is displayed. In response to adding modification requests in the information entry box, the appearance of the target process node with modification requests changes compared to other process nodes. For example, a marker is added around the target process node to indicate that modification requests have been entered into its appearance.
[0157] Save the association between the target process node and the modification requirements.
[0158] For example, intelligent agent utility applications provide an entry point for saving association relationships in a pop-up window.
[0159] In one alternative implementation of this application, it further includes: In response to a request to generate a code modification plan, a code modification plan is generated based on the modification requirements. For example, the code modification plan describes the instructions based on the modification requirements in natural language and adjusts the planned modification method of the code block.
[0160] The code modification plan is displayed in the dialogue area of the webpage provided by the agent conversation application. The dialogue area may exist indefinitely before the generation request for the code modification plan is obtained, or it may be updated and displayed in response to the generation request being obtained.
[0161] Furthermore, it also includes: In response to modification suggestions entered in the dialog area, update the code modification plan based on the modification suggestions.
[0162] In response to the confirmation of code modifications, code modifications are executed on the target code repository corresponding to the source code according to the code modification plan; The code differences before and after the modification are obtained and displayed on a webpage provided by the intelligent agent conversation application. For example, the code differences before and after the modification can be obtained through the differences between different historical versions of the code block recorded in the target code repository; or they can be obtained through the recorded modifications made to the code block.
[0163] Display the cancel modification control on the webpage provided by the agent conversation application; In response to a triggering action on the Cancel Modification control, the target code repository is restored to its state before the code modification. In some examples, the Cancel Modification control in this step is updated and displayed after code modifications are performed on the target code repository corresponding to the source code. For example, the Cancel Modification control provides an entry point for reverting the target code repository from the current version to a previous version.
[0164] In one application scenario, the visualization area in the code processing method provided in this application is provided by a code development application. In some examples, a code processing plugin is installed in the code development application. This plugin is used to implement the code processing methods described in the various embodiments of this application. The code processing plugin is displayed in the tab area of the code development application, and the interactive area of the code processing plugin is displayed by selecting the tab corresponding to the plugin. The interactive area of the code processing plugin provides an entry point for uploading source code files, and provides entry points for adding and modifying functions in the code flowchart.
[0165] The following describes the code processing methods: Retrieve the source code from the code repository, which contains at least two functions; A code repository is an electronic storage system used to implement at least one of the following functions: storing, managing, version monitoring, and collaboratively maintaining source code. Source code is written in a programming language and is used to form a set of instructions for an executable program; source code includes at least two functions.
[0166] The code flowchart of the source code is displayed in the tab corresponding to the code processing plugin installed in the code development application. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the functions called in the list. In this embodiment, the tab corresponding to the code processing plugin installed in the code development application provides a function entry point for uploading source code as a file. The source code can be uploaded in text format or compiled machine language format. For example, the logical summary of the code block and the list of called functions can be always displayed on the process node, or it can be triggered to display when the process node is selected first. The node types of the process node include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; conditional loop nodes.
[0167] In one alternative implementation of this application, it further includes: In response to the selection of a target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the corresponding tab of the code processing plugin installed in the code development application is highlighted.
[0168] For example, the tab corresponding to the code processing plugin installed in the code development application, also known as the visual interface, is an area that displays any kind of information related to the source code in this embodiment or any of the embodiments described above. The source code display area is a functional area of the tab corresponding to the code processing plugin installed in the code development application, used to present the source code. It is understood that the source code display area may always exist before the selection operation, or it may be updated and displayed in response to the selection operation; this application does not impose any limitations on this.
[0169] In one alternative implementation of this application, it further includes: In response to the search information for the target function entered in the function search area, the code flowchart of the target function is displayed in the corresponding tab of the code processing plugin installed in the code development application.
[0170] In this step, the tab corresponding to the code processing plugin installed in the code development application also includes a function search area. The function search area provides an input field for searching information. Since the source code contains a large number of functions, this input field provides a quick way to find functions within the source code.
[0171] In one alternative implementation of this application, it further includes: In response to the addition of an operation that requires modification of at least one target flow node in the code flowchart, the target flow node is displayed with an added identifier in the tab corresponding to the code processing plugin installed in the code development application. In this embodiment, the intelligent agent conversation application provides a functional entry point for adding or modifying process nodes. In one example, when a target process node is selected by at least one of the following methods: single click, double click, long press, etc., an information entry box for modification requests is displayed. In response to adding modification requests in the information entry box, the appearance of the target process node with modification requests changes compared to other process nodes. For example, a marker is added around the target process node to indicate that modification requests have been entered into its appearance.
[0172] Save the association between the target process node and the modification requirements.
[0173] For example, the code processing plugin installed in the code development application has a function entry in the tab to save association relationships.
[0174] In one alternative implementation of this application, it further includes: In response to a request to generate a code modification plan, a code modification plan is generated based on the modification requirements. For example, the code modification plan describes the instructions based on the modification requirements in natural language and adjusts the planned modification method of the code block.
[0175] The dialog area of the tab corresponding to the code processing plugin installed in the code development application displays the code modification plan. This dialog area can either remain present until a generation request for the code modification plan is received, or it can be updated in response to a generation request being received.
[0176] Furthermore, it also includes: In response to modification suggestions entered in the dialog area, update the code modification plan based on the modification suggestions.
[0177] In response to the confirmation of code modifications, code modifications are executed on the target code repository corresponding to the source code according to the code modification plan; The code differences before and after modification are obtained and displayed in the corresponding tab of the code processing plugin installed in the code development application. For example, the code differences before and after modification can be obtained through the differences between different historical versions of the code block recorded in the target code repository; or they can be obtained through the recorded modifications made to the code block.
[0178] The option to cancel modification is displayed in the tab corresponding to the code processing plugin installed in the code development application. In response to a triggering action on the Cancel Modification control, the target code repository is restored to its state before the code modification. In some examples, the Cancel Modification control in this step is updated and displayed after code modifications are performed on the target code repository corresponding to the source code. For example, the Cancel Modification control provides an entry point for reverting the target code repository from the current version to a previous version.
[0179] In one application scenario, the visualization area in the code processing method provided in this application is provided by an intelligent agent utility application. In some examples, the intelligent agent utility application is a client installed on a computer device. The client has the function of being displayed on top of the computer device's display interface, obtaining the source code through interactive operations of selecting the source code, and displaying the code flowchart of the selected source code in a pop-up window.
[0180] Retrieve the source code from the code repository, which contains at least two functions; A code repository is an electronic storage system used to implement at least one of the following functions: storing, managing, version monitoring, and collaboratively maintaining source code. Source code is written in a programming language and is used to form a set of instructions for an executable program; source code includes at least two functions.
[0181] The code flowchart of the source code is displayed in a pop-up window provided by the intelligent agent tool application. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the functions called in the list. In this embodiment, the pop-up window provided by the intelligent agent tool application offers a function entry point for uploading source code as a file. The source code can be uploaded in text format or compiled machine language format. For example, the logical summary of the code block and the list of called functions can be always displayed on the process node, or it can be triggered to display when the process node is selected first. The node types of the process node include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; conditional loop nodes.
[0182] In one alternative implementation of this application, it further includes: In response to the selection of a target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the pop-up window provided by the intelligent agent utility application is highlighted.
[0183] For example, the pop-up window provided by the intelligent agent tool application, also known as the visual interface, is an area that displays any kind of information related to the source code in this embodiment or any of the embodiments described above. The source code display area is a functional area of the pop-up window provided by the intelligent agent tool application, used to present the source code. It is understood that the source code display area may always exist before the selection operation, or it may be updated in response to the selection operation; this application does not impose any limitations on this.
[0184] In one alternative implementation of this application, it further includes: In response to the search information for the target function entered in the function search area, the code flowchart of the target function is displayed in a pop-up window provided by the intelligent agent utility application.
[0185] In this step, the pop-up window provided by the intelligent agent utility application also includes a function search area. This function search area provides an input field for search information. Since the source code contains a large number of functions, this input field provides a quick way to find functions within the source code.
[0186] In one alternative implementation of this application, it further includes: In response to the addition of an operation that requires modification of at least one target flow node in the code flowchart, the target flow node is displayed with an added identifier in the tab corresponding to the code processing plugin installed in the code development application. In this embodiment, the intelligent agent tool application provides a functional entry point for adding or modifying process nodes. In one example, when a target process node is selected by at least one of the following methods: single click, double click, long press, etc., an information entry box for modification requests is displayed. In response to adding modification requests in the information entry box, the appearance of the target process node with modification requests changes compared to other process nodes. For example, a marker is added around the target process node to indicate that modification requests have been entered into its appearance.
[0187] Save the association between the target process node and the modification requirements.
[0188] For example, intelligent agent utility applications provide an entry point for saving association relationships in a pop-up window.
[0189] In one alternative implementation of this application, it further includes: In response to a request to generate a code modification plan, a code modification plan is generated based on the modification requirements. For example, the code modification plan describes the instructions based on the modification requirements in natural language and adjusts the planned modification method of the code block.
[0190] The code modification plan is displayed in a dialog area of a pop-up window provided by the intelligent agent utility application. This dialog area can either exist continuously before a generation request is received, or it can be updated in response to receiving a generation request.
[0191] Furthermore, it also includes: In response to modification suggestions entered in the dialog area, update the code modification plan based on the modification suggestions.
[0192] In response to the confirmation of code modifications, code modifications are executed on the target code repository corresponding to the source code according to the code modification plan; The code differences before and after the modification are obtained and displayed in a pop-up window provided by the intelligent agent utility application. For example, the code differences before and after the modification can be obtained through the differences between different historical versions of the code block recorded in the target code repository; or they can be obtained through the recorded modifications made to the code block.
[0193] Display a cancel modification control in a pop-up window provided by the intelligent agent utility application; In response to a triggering action on the Cancel Modification control, the target code repository is restored to its state before the code modification. In some examples, the Cancel Modification control in this step is updated and displayed after code modifications are performed on the target code repository corresponding to the source code. For example, the Cancel Modification control provides an entry point for reverting the target code repository from the current version to a previous version.
[0194] Those skilled in the art will understand that the above embodiments can be implemented independently, or the above embodiments can be freely combined to create new embodiments to implement the code processing method of this application.
[0195] Figure 15 A structural block diagram of a code processing apparatus provided in an exemplary embodiment of this application is shown. The apparatus includes: Module 810 is used to retrieve source code from a code repository, which includes at least two functions. The display module 820 is used to display the code flowchart of the source code in the visualization area. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the functions called in the list. The node types of the process nodes include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; and conditional loop nodes.
[0196] In an optional implementation of this embodiment, the conditional loop node includes at least one of a for loop node and an if conditional branch node; When nested structures exist in the source code, the connection relationships between the corresponding process nodes in the code flowchart reflect the nested structure.
[0197] In an optional implementation of this embodiment, the display module 820 is further configured to: In response to the selection of a target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the visualization area is highlighted.
[0198] In an optional implementation of this embodiment, the visualization area further includes a function search area, and the display module 820 is further used for: In response to the search information for the target function entered in the function search area, the code flowchart of the target function is displayed in the visualization area.
[0199] In one optional implementation of this embodiment, the list of functions called includes functions called by the code block corresponding to the process node, and the functions include at least one of functions in the target code repository corresponding to the source code and external functions.
[0200] In one optional implementation of this embodiment, the logical summary is a semantic description of code blocks generated by semantic understanding of the source code; The device also includes a processing module 830, for: Divide the source code into blocks according to business logic to obtain at least two code blocks; Generate a logical summary for each of at least two code blocks and assign a node type to each code block.
[0201] In an optional implementation of this embodiment, the processing module 830 is further configured to: Input the source code, source code call chain information, and flowchart structure definition information into the large language model; Receive the code block results from the LLM output, which include at least two code blocks.
[0202] In one optional implementation of this embodiment, the code flowchart is generated based on a function call graph, which contains the calling relationships between functions in the source code and is used to represent the calling relationships.
[0203] In one optional implementation of this embodiment, the function call graph is constructed based on the abstract syntax tree data and type information corresponding to the source code.
[0204] In an optional implementation of this embodiment, the processing module 830 is further configured to: Based on the AST data and type information, identify the function definition information in the target code repository corresponding to the source code; Based on function definition information, generate a unique identifier for each function in the target code repository; By traversing the function nodes in the AST, the calling relationships between functions in the target code repository can be determined.
[0205] In an optional implementation of this embodiment, the processing module 830 is further configured to: Traverse the function call nodes in the AST and identify the functions called in the function call nodes; when the called function is an interface method, determine the actual structure method called by the interface method based on the pre-stored correspondence between interface variables and instantiated structures, so as to establish the calling relationship between interface methods and structure methods in the target code repository.
[0206] In an optional implementation of this embodiment, the display module 820 is further configured to: In response to a modification request for at least one target process node in the code flowchart, the target process node is displayed in the visualization area by adding an identifier. The device also includes a processing module 830, for: Save the association between the target process node and the modification requirements.
[0207] In an optional implementation of this embodiment, the apparatus further includes a processing module 830, configured to: In response to a request to generate a code modification plan, a code modification plan is generated based on the modification requirements; Display module 820 is also used for: The code modification plan is displayed in the dialog area of the visualization area.
[0208] In an optional implementation of this embodiment, the processing module 830 is further configured to: In response to modification suggestions entered in the dialog area, update the code modification plan based on the modification suggestions.
[0209] In an optional implementation of this embodiment, the processing module 830 is further configured to: In response to the confirmation of code modifications, code modifications are executed on the target code repository corresponding to the source code according to the code modification plan; Get the code differences before and after the code modification, and display the code differences in the visualization area.
[0210] In an optional implementation of this embodiment, the processing module 830 is further configured to: Display the cancel modification control in the visualization area; In response to a trigger action on the unmodify control, the target code repository is restored to its state before the code was modified.
[0211] It should be noted that the device provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules according to actual needs, that is, the content structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0212] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments of the relevant method; the technical effects achieved by each module performing its operation are the same as the technical effects in the embodiments of the relevant method, and will not be elaborated here.
[0213] This application also provides a computer device, which includes: a processor and a memory, wherein the memory stores a computer program; the processor is used to execute the computer program in the memory to implement the code processing methods provided in the above method embodiments.
[0214] Alternatively, the computer device is a server. For example, Figure 16 This is a structural block diagram of a server provided in an exemplary embodiment of this application.
[0215] Typically, server 2300 includes a processor 2301 and memory 2302.
[0216] Processor 2301 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 2301 may be implemented using at least one hardware form selected from Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). Processor 2301 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 2301 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 2301 may also include an Artificial Intelligence (AI) processor, which is used to handle computational operations related to machine learning.
[0217] The memory 2302 may include one or more computer-readable storage media, which may be non-transitory. The memory 2302 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 2302 are used to store at least one instruction, which is executed by the processor 2301 to implement the code processing method provided in the method embodiments of this application.
[0218] In some embodiments, the server 2300 may optionally include an input interface 2303 and an output interface 2304. The processor 2301, memory 2302, and input interfaces 2303 and 2304 can be connected via a bus or signal lines. Various peripheral devices can be connected to the input interfaces 2303 and 2304 via a bus, signal lines, or a circuit board. The input interfaces 2303 and 2304 can be used to connect at least one input / output (I / O) related peripheral device to the processor 2301 and memory 2302. In some embodiments, the processor 2301, memory 2302, and input interfaces 2303 and 2304 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 2301, memory 2302, and input interfaces 2303 and 2304 can be implemented on separate chips or circuit boards, and this application embodiment does not limit this.
[0219] Those skilled in the art will understand that the structure shown above does not constitute a limitation on server 2300, and may include more or fewer components than shown, or combine certain components, or employ different component arrangements.
[0220] In an exemplary embodiment, a chip is also provided, the chip including programmable logic circuitry and / or program instructions, which, when the chip is run on a computer device, are used to implement the code processing method described above.
[0221] In an exemplary embodiment, a computer program product is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions to implement the code processing methods provided in the above-described method embodiments.
[0222] In an exemplary embodiment, a computer-readable storage medium is also provided, which stores a computer program that is loaded and executed by a processor to implement the code processing methods provided in the above-described method embodiments.
[0223] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0224] Those skilled in the art will recognize that the functions described in the embodiments of this application in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any medium that facilitates the transfer of a computer program from one place to another. Storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0225] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A code processing method, characterized in that, The method includes: Obtain the source code from the code repository, the source code including at least two functions; The code flowchart of the source code is displayed in the visualization area. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the function calls in the function call list. The node types of the process nodes include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; conditional loop nodes; The conditional loop node includes at least one of a for loop node and an if conditional branch node; when there is a nested structure in the source code, the connection relationship between the corresponding flow nodes in the code flowchart reflects the nested structure.
2. The method according to claim 1, characterized in that, The method further includes: In response to the selection operation of the target flow node in the code flowchart, the location of the code block corresponding to the target flow node in the source code display area of the visualization area is highlighted.
3. The method according to claim 1 or 2, characterized in that, The visualization area also includes a function search area, and the method further includes: In response to the search information of the target function entered in the function search area, the code flowchart of the target function is displayed in the visualization area.
4. The method according to claim 1 or 2, characterized in that, The list of functions to be called includes functions called by the code block corresponding to the process node, and the functions include at least one of functions in the target code repository corresponding to the source code and external functions.
5. The method according to claim 1 or 2, characterized in that, The logical summary is a semantic description of code blocks generated through semantic understanding of the source code; the method further includes: The source code is divided into blocks according to business logic, resulting in at least two code blocks; Generate a logical summary for each of the at least two code blocks, and assign a node type to each code block.
6. The method according to claim 5, characterized in that, The source code is divided into blocks according to business logic to obtain at least two code blocks, including: Input the source code, the call chain information of the source code, and the flowchart structure definition information into the large language model LLM; Receive the code block results output by the LLM, the code block results including the at least two code blocks.
7. The method according to claim 1 or 2, characterized in that, The code flowchart is generated based on a function call graph, which contains the call relationships between functions in the source code.
8. The method according to claim 7, characterized in that, The function call graph is constructed based on the abstract syntax tree (AST) data and type information corresponding to the source code.
9. The method according to claim 8, characterized in that, The method further includes: Based on the AST data and type information, identify the function definition information in the target code repository corresponding to the source code; Based on the function definition information, a unique identifier is generated for each function in the target code repository; By traversing the function nodes in the AST, the calling relationships between functions in the target code repository are determined.
10. The method according to claim 9, characterized in that, The step of determining the call relationships between functions in the target code repository by traversing the function nodes in the AST includes: Traverse the function call nodes in the AST and identify the functions called in the function call nodes; when the called function is an interface method, determine the actual structure method called by the interface method according to the pre-stored correspondence between interface variables and instantiated structures, so as to establish the calling relationship between the interface method and the structure method in the target code repository.
11. The method according to claim 1 or 2, characterized in that, The method further includes: In response to an operation that adds a modification request for at least one target process node in the code flowchart, the target process node is displayed in the visualization area by adding an identifier; Save the association between the target process node and the modification requirement.
12. The method according to claim 1 or 2, characterized in that, The method further includes: In response to a request to generate a code modification plan, a code modification plan is generated based on the modification requirements; The code modification plan is displayed in the dialog area of the visualization area.
13. The method according to claim 12, characterized in that, The method further includes: In response to a modification suggestion entered in the dialog area, the code modification plan is updated according to the modification suggestion.
14. The method according to claim 12, characterized in that, The method further includes: In response to the confirmation operation of the code modification, code modifications are performed on the target code repository corresponding to the source code according to the code modification plan; Obtain the code differences before and after the code modification, and display the code differences in the visualization area.
15. The method according to claim 14, characterized in that, The method further includes: The cancellation control is displayed in the visualization area; In response to the triggering operation of the cancel modification control, the target code repository is restored to its state before the code modification.
16. A code processing apparatus, characterized in that, The device includes: A retrieval module is used to retrieve source code from a code repository, the source code including at least two functions; The display module is used to display the code flowchart of the source code in a visualization area. The code flowchart contains multiple flow nodes. Each flow node corresponds to at least one code block in the source code. Each flow node is used to display the logical summary of the code block corresponding to the flow node and at least one of the function calls in the function call list. The node types of the process nodes include at least one of the following: data declaration and initialization; guard statements and parameter validation; function calls and error handling; concurrency and synchronization; result construction and return; entry and exit nodes; conditional loop nodes; The conditional loop node includes at least one of a for loop node and an if conditional branch node; when there is a nested structure in the source code, the connection relationship between the corresponding flow nodes in the code flowchart reflects the nested structure.
17. A computer device, characterized in that, The computer device includes: a processor and a memory, wherein the memory stores at least one program; the processor is configured to execute the at least one program in the memory to implement the code processing method as described in any one of claims 1 to 15.
18. A computer-readable storage medium, characterized in that, The readable storage medium stores executable instructions, which are loaded and executed by a processor to implement the code processing method as described in any one of claims 1 to 15.
19. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, and a processor reads and executes the computer instructions from the computer-readable storage medium to implement the code processing method as described in any one of claims 1 to 15.