Code processing methods, devices, electronic devices, and storage media based on large models
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-17
- Publication Date
- 2026-08-14
AI Technical Summary
[0002]随着业务的快速迭代与功能不断扩展,代码规模也持续膨胀,大量历史代码因缺乏有效治理而长期滞留,导致无用代码、冗余逻辑等不断堆积,使得维度成本不断升高
[0007]根据本申请的另一方面,提供了一种存储有计算机指令的非瞬时计算机可读存储介质,其中,所述计算机指令用于使所述计算机执行根据上述实施例所述的方法。
Smart Images

Figure CN122569935A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to the field of artificial intelligence such as deep learning and large models, specifically to a code processing method, apparatus, electronic device and storage medium based on a large model. Background Technology
[0002] As business rapidly iterates and functions continue to expand, the code size also continues to grow. A large amount of historical code remains unmanaged for a long time, resulting in the accumulation of useless code and redundant logic, which in turn increases the dimensional cost. Summary of the Invention
[0003] This application provides a code processing method, apparatus, electronic device, and storage medium based on a large model. The specific solution is as follows:
[0004] According to one aspect of this application, a code processing method based on a large model is provided, comprising: In response to receiving a code processing instruction associated with a target software project input by a user, the function index library corresponding to the target software project is obtained; wherein, the function index library is used to provide structured access to function-related information in the target software project; The code processing instructions are parsed to determine the code processing flow to be executed; By leveraging the code semantic understanding capabilities of the large model and combining it with the function index library, the code processing flow is executed on the source files of the target software project to generate processed source files.
[0005] According to another aspect of this application, a code processing apparatus based on a large model is provided, comprising: The acquisition module is used to acquire the function index library corresponding to the target software project in response to the code processing instructions associated with the target software project input by the user; wherein, the function index library is used to provide structured access to function-related information in the target software project; The determination module is used to parse the code processing instructions and determine the code processing flow to be executed; The execution module is used to leverage the code semantic understanding capabilities of the large model, combined with the function index library, to execute the code processing flow on the source files of the target software project, and generate processed source files.
[0006] According to another aspect of this application, an electronic device is provided, comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method described in the above embodiments.
[0007] According to another aspect of this application, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to perform the method described in the above embodiments.
[0008] According to another aspect of this application, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the method described in the above embodiments.
[0009] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description
[0010] The accompanying drawings are provided for a better understanding of this solution and do not constitute a limitation of this application. Wherein: Figure 1 A flowchart illustrating a code processing method based on a large model provided in an embodiment of this application; Figure 2 A flowchart illustrating a code processing method based on a large model, provided in another embodiment of this application; Figure 3 A flowchart illustrating a code processing method based on a large model, provided in another embodiment of this application; Figure 4 A schematic diagram of a code processing procedure based on a large model is provided for an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a code processing device based on a large model provided in an embodiment of this application; Figure 6 This is a block diagram of an electronic device used to implement the code processing method based on a large model according to the embodiments of this application. Detailed Implementation
[0011] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0012] It should be noted that the acquisition, storage, use, and processing of data in this application comply with the relevant provisions of national laws and regulations and do not violate public order and good morals.
[0013] The following description, with reference to the accompanying drawings, outlines a code processing method, apparatus, electronic device, and storage medium based on a large model according to embodiments of this application.
[0014] In some embodiments, static analysis tools are typically used to slim down the project code. However, this method can only identify some unused classes, methods, properties, etc., and the code inspection is limited and unreliable, which will affect the accuracy and reliability of code slimming.
[0015] Based on this, this application provides a code processing method based on a large model. Figure 1 This is a flowchart illustrating a code processing method based on a large model provided in an embodiment of this application.
[0016] The code processing method based on a large model according to the embodiments of this application can be executed by the code processing device based on a large model according to the embodiments of this application, which can be configured in an electronic device.
[0017] Among them, electronic devices can be any device with computing capabilities, such as personal computers, mobile terminals, servers, etc. Mobile terminals can be hardware devices with various operating systems, touch screens and / or displays, such as in-vehicle devices, mobile phones, tablets, personal digital assistants, wearable devices, etc.
[0018] like Figure 1 As shown, this code processing method based on a large model includes: Step 101: In response to the code processing instructions associated with the target software project received from the user input, obtain the function index library corresponding to the target software project.
[0019] In this application, the code processing instructions associated with the target software project can be used to instruct code processing on the entire target software project or a portion of the source files within the target software project.
[0020] For example, code processing here may include, but is not limited to, at least one of the following types: code improvement (such as code optimization), code cleanup (such as removal of useless functions), extraction of shared code, etc.
[0021] For example, users can input code processing instructions associated with the target software project in the front-end interface (such as the AI assistant interface).
[0022] For example, the code processing instructions may include, but are not limited to, the identifier of the target software project, the identifier of the source file, and the type of code processing. The type of code processing may be one or more, without limitation.
[0023] As an example, if a code processing instruction includes the name of the target software project but does not specify any particular source file, it can be assumed that the code processing instruction instructs the entire target software project to be processed.
[0024] As an example, if a code processing instruction contains the name of the target software project and the file name of a source file within that target software project, it can be assumed that the code processing instruction instructs code processing on that source file.
[0025] In this application, the function index library can be used to provide structured access to function-related information in the target software project.
[0026] In some embodiments, the function index library may include structured function metadata such as function names, functional descriptions, and call relationships. For example, call relationships may include upper-level calls, lower-level calls, etc., where upper-level calls refer to which functions call a function, and lower-level calls refer to which functions a function calls.
[0027] For example, a function index library can be constructed by parsing all source files in the target software project to obtain the dependencies between functions.
[0028] It should be noted that the function index library can be built in real time after obtaining code processing instructions, or it can be built in advance; there is no limitation on this.
[0029] As an example, if the entire target software project is processed for the first time, a function index library can be built after the code processing instructions.
[0030] As an example, after processing the entire target software project code, if a code processing instruction is received, the existing function index library can be retrieved.
[0031] Step 102: Parse the code processing instructions to determine the code processing flow to be executed.
[0032] In this application, code processing instructions can be parsed to obtain the object to be processed, the type of code processing, etc., and the code processing flow to be executed can be determined based on the object to be processed, the type of code processing, etc.
[0033] For example, a code processing flow can be used to indicate the logic of code processing.
[0034] For example, the code processing flow to be executed may include, but is not limited to, at least one of the following: useless function deletion flow, shared code extraction flow, code quality enhancement flow, etc.
[0035] Among them, the useless function removal process is the processing flow for deleting useless functions, the shared code extraction process is the processing flow for extracting shared code, and the code quality enhancement process is the processing flow for improving code.
[0036] For example, if the object to be processed is the target software project and the processing type is not specified, the code processing flow to be executed may include the process of deleting useless functions, the process of extracting shared code, the process of enhancing code quality, etc.
[0037] For example, if the type of code processing is the deletion of useless functions, then the processing flow of the code to be executed is the deletion flow of useless functions.
[0038] Step 103: Utilize the code semantic understanding capabilities of the large model and combine it with the function index library to execute the code processing flow on the source files of the target software project and generate the processed source files.
[0039] In this application, the function index library can be traversed, and for each function in the function index library, the code semantic understanding capability of the large model can be used to execute the code processing flow on the source file of the target software project, thereby slimming down or optimizing the source file and generating the processed source file.
[0040] For example, this large model can be trained on a massive corpus of code, and the code semantic understanding ability can understand the functional intent of the code, the implicit relationships of calls, the code's reusability potential, and the code's simplification opportunities.
[0041] For example, the large model can be a large language model, or other large models with code semantic understanding capabilities, without limitation.
[0042] For example, understanding the functional intent of code means being able to determine whether a piece of code is a general utility function, core business logic, or auxiliary script; understanding the implicit relationships of calls means being able to identify which implementations a method name might point to through string concatenation; understanding the reusability potential of code means being able to identify and merge code snippets with similar structures or semantics; understanding the simplification opportunities of code means being able to identify redundant, complex, or poorly readable logic and suggest more concise and clear equivalents, such as rewriting complex conditional logic into a more concise form.
[0043] In some embodiments, "code processing" can be described as "code optimization," "code slimming," etc. For example, "proxy processing method" can be described as "code slimming method." This application does not limit the name of "code processing."
[0044] In this embodiment, after receiving the user's code processing instructions for the target software project, the function index library corresponding to the code processing instructions is obtained, and then the code processing instructions are parsed to determine the specific processing flow. By combining the code semantic understanding capability of the large model with the function index library, precise and context-aware code processing is performed on the source file. This makes the code processing not only based on the surface syntax, but also incorporates a deep understanding of the functions, which can significantly improve the accuracy, reliability, context consistency and processing efficiency of code processing.
[0045] Figure 2 This is a flowchart illustrating a code processing method based on a large model, provided as another embodiment of this application.
[0046] like Figure 2 As shown, this code processing method based on a large model includes: Step 201: In response to the code processing instructions associated with the target software project received from the user input, obtain the function index library corresponding to the target software project.
[0047] In this application, step 201 can be implemented in any of the embodiments of this application, so it will not be described in detail here.
[0048] Step 202: Parse the code processing instructions to determine the code processing flow to be executed.
[0049] In this application, step 202 can be implemented in any of the embodiments of this application, so it will not be described in detail here.
[0050] Step 203: Obtain the capability units in the large model that correspond to the code processing flow.
[0051] In this application, a capability unit can be a functional module of a larger model used to execute code processing flows. For example, a capability unit can be obtained by encapsulating the processing logic of the code processing flow.
[0052] For example, the processing logic of different code processing flows can be pre-encapsulated to obtain corresponding capability units. Then, after determining the code processing flow to be executed, the capability unit corresponding to the code processing flow can be obtained so as to execute the code processing flow through the capability unit.
[0053] Step 204: Invoke the capability unit, combine it with the function index library, execute the code processing flow on the source file, and generate the processed source file.
[0054] In some embodiments, if the code processing flow includes a useless function deletion process, the capability unit corresponding to the useless function deletion process in the large model can be called to traverse the function index library. For any function in the function index library, based on the call information of any function in the function index library, it is determined whether the function is a useless function. If it is a useless function, the function and the redundant code associated with it are deleted. If it is not a useless function, the function is retained, thereby achieving precise deletion of useless functions.
[0055] In some embodiments, if the code processing flow includes a shared code extraction flow, the shared code can be extracted by calling the capability unit corresponding to the shared code extraction flow, traversing the function index library, and executing the shared code extraction flow for any function in the function index library.
[0056] For example, the source file to which any function in the function index belongs can be determined. If a target function with a duplicate code block exists in the source file, the shared code part between the function and the target function can be extracted to generate a shared function. In the current function and the target function, the shared code part is replaced with a call to the shared function to generate the processed source file.
[0057] For example, reusable units can be extracted, abstracted, and parameterized from repetitive code blocks, that is, common code parts can be generated.
[0058] Therefore, based on the powerful semantic understanding capabilities of the large model, by calling the capability units in the large model corresponding to the common code extraction process, traversing the function index library and analyzing the code similarity in the source files of each function, if function pairs with duplicate code blocks are found, a common function with strong generalization and reasonable interface is intelligently abstracted, and the redundant code in the original function is replaced with a call to the common function. Thus, the common code extraction driven by the large model has stronger context awareness, intent understanding and code generation consistency, which can effectively eliminate the redundancy caused by code duplication. It can not only significantly improve the cohesion and maintainability of the code, but also reduce the risk of defects caused by inconsistencies in multiple modifications, while reducing the code size. It can achieve an intelligent leap from "discovering duplication" to "high-quality reuse".
[0059] In some embodiments, if the code processing flow includes a code quality enhancement flow, code optimization can be achieved by calling the capability unit corresponding to the code quality enhancement flow, traversing the function index library, and executing the code quality enhancement flow for any function in the function index library.
[0060] For example, the capability unit corresponding to the code quality enhancement process can be invoked to perform code quality detection on any function in the function index library, obtain the quality detection result, and perform code improvement processing on any function based on the quality detection result to obtain the processed source file.
[0061] For example, code quality inspection may include, but is not limited to, one or more of the following: detection of residual debugging code, detection of comment standardization, detection of code improvement points, etc.
[0062] Among them, debugging residual code detection can be used to detect debugging code such as logging code in functions, comment standardization detection can be used to detect whether comments in functions are standard, and code improvement point detection can be used to detect code improvement points in functions.
[0063] For example, if the quality inspection results determine that a function has issues such as residual debugging code or non-standard comments, the residual debugging code in the function can be deleted and the non-standard comments can be modified to standard comments.
[0064] For example, if the quality inspection results determine that a function has code improvement points, the function can be rewritten based on those improvement points.
[0065] It should be noted that code improvement processing can include one or more of the following: handling debugging remnants, modifying comments, and rewriting code; there is no limitation on this.
[0066] In some embodiments, "code modification point detection point" can be described as "code optimization point detection" or other names. This application does not limit the name of "code modification point detection point".
[0067] In some embodiments, "code improvement processing" may be described as "code optimization processing" or other names, and this application does not limit the name of "code improvement processing".
[0068] Therefore, based on the powerful semantic understanding capabilities of the large model, by calling the capability units in the large model corresponding to the code quality enhancement process, code quality detection is performed on each function in the function index library. By utilizing the semantic understanding, contextual reasoning, and programming paradigm learning capabilities of the large model, not only can the quality problems of functions be accurately identified, but the standardization, readability, and maintainability of the code can also be effectively improved.
[0069] It should be noted that if the code processing flow to be executed includes a useless function deletion process, a shared code extraction process, and a code quality enhancement process, these three processes can be executed in parallel, or they can be executed in a certain execution order. This application does not limit this.
[0070] In this embodiment, capability units that match the code processing flow to be executed are dynamically obtained from a large model and called in conjunction with a function index library to perform context-aware intelligent code processing on the source file. This method of executing code processing based on capability units of a large model can overcome the limitations of static rules or template-driven tools and realize the transformation from "mechanical modification" to "intent-driven intelligent evolution". Under the premise of ensuring the correctness of function functions, it can significantly improve the simplicity, reusability and maintainability of code.
[0071] Figure 3 This is a flowchart illustrating a code processing method based on a large model, provided as another embodiment of this application.
[0072] like Figure 3 As shown, this code processing method based on a large model includes: Step 301: In response to the code processing instructions associated with the target software project received from the user input, obtain the function index library corresponding to the target software project.
[0073] Step 302: Parse the code processing instructions to determine the code processing flow to be executed.
[0074] In this application, steps 301-302 can be implemented in any of the embodiments of this application, so they will not be described in detail here.
[0075] Step 303: Obtain the capability unit in the large model corresponding to the useless function deletion process.
[0076] In this application, if the code processing flow includes a useless function deletion process, the capability unit corresponding to the useless function deletion process can be obtained from the capability units corresponding to each code processing flow. The capability unit corresponding to the useless function deletion process can be used to implement the judgment and deletion of useless functions.
[0077] Step 304: Invoke the capability unit, traverse the function index library, identify and remove useless functions and their associated redundant code in the source file, and generate the processed source file.
[0078] In this application, the processing unit corresponding to the useless function deletion process can be invoked to traverse the function index library, obtain the call information of any function in the function index library, and based on the call information, identify and remove useless functions and their associated redundant code in the source file to generate the processed source file.
[0079] For example, the call information for any function may include, but is not limited to, upper-level call information and lower-level call information. For example, upper-level call information may include information about the upper-level function that called this function, such as the name and function of the upper-level function. For example, lower-level call information may include information about the lower-level function called by this function, such as the name and function of the lower-level function.
[0080] For example, redundant code associated with a useless function may include the code of a function that is only called by the useless function.
[0081] In large-scale engineering refactoring, there is often a scenario where an old function needs to be taken offline, but the code for that function is intertwined with common code, and existing tools cannot support deleting only all the code for that function while retaining the common code shared by other functions.
[0082] Based on this, for example, the following method can be used to identify and remove useless functions and their associated redundant code in the source file based on the call information: The capability unit corresponding to the function deletion process can be called. When it is determined that any function has no upper-level call based on the call information, dynamic call detection is performed on any function to obtain the dynamic call detection result. If the dynamic call detection result indicates that any function has no dynamic call, it is determined that any function is a useless function, and the function and the lower-level functions that are only called by the function are deleted recursively.
[0083] For example, if it is determined from the upper-level call information in the call information that any function has no upper-level call, then dynamic call detection is performed on any function.
[0084] For example, dynamic call detection for any function can refer to determining whether any function may be called in a non-static, non-direct way during program runtime, such as through reflection, string concatenation, callback registration, plugin mechanisms, event-driven methods, etc.
[0085] As an example, dynamic call detection can be performed through string analysis, configuration parsing, and program dependency tracing.
[0086] For example, after determining that any function is a useless function, you can recursively trace all functions called by that function, identify which of the called functions are unique to that function (called only by this path) and which are publicly shared (called by other paths), automatically generate a list of code that can be safely deleted (i.e., the unique part) and a list of code that should be retained (i.e., the shared part), automatically update all relevant references for that function and the functions that are only called by that function, perform compilation verification, and automatically roll back if it fails.
[0087] Therefore, by calling the capability unit corresponding to the useless function deletion process, and combining static call analysis and dynamic call detection, functions without any upper-level or dynamic calls can be accurately identified, and the function and its lower-level dependent functions that are only called by it can be accurately and safely deleted. By explicitly introducing dynamic call detection, the risk of functional loss due to missed dynamic calls can be effectively avoided. Furthermore, by recursively cleaning up unclaimed dependency chains, code residue can be avoided, thereby improving the accuracy of code deletion, effectively eliminating redundant code, and significantly improving the thoroughness of code simplification and overall maintainability.
[0088] Optionally, after deleting any function and recursively deleting all lower-level functions called only by that function, the function and its lower-level calling functions are removed from the function index library, and the function index in the function index library is updated, thereby updating the function index library and realizing real-time updating of the function index library.
[0089] Optionally, if any function in the function index library is called from an upper level, that function is retained.
[0090] Optionally, if any of these functions are dynamically called, the function is retained, and the function index is updated. For example, the information that any of these functions are dynamically called is updated in the function index.
[0091] Therefore, by dynamically identifying the actual call relationships of functions and deciding whether to retain functions in the function index library accordingly, and updating the function index library in real time when dynamic calls are detected to improve accuracy, this function lifecycle management strategy based on call context awareness can effectively avoid the problem of accidentally deleting useful functions or retaining useless functions. Thus, while ensuring the integrity of program functions, it can significantly improve the accuracy of code simplification and the timeliness of the function index library.
[0092] In this embodiment, by calling the capability unit corresponding to the useless function deletion process in the large model, the function index library is traversed and the calling information of each function is obtained. Based on the calling information, useless functions are accurately identified and these useless functions and their associated redundant code are safely removed, generating a simplified source file. The useless functions are deleted through the capability unit driven by the large model, which improves the accuracy of useless function deletion and achieves a higher degree of automation and code slimming effect.
[0093] In some embodiments of this application, the function index library corresponding to the target software project in the above embodiments can be constructed using the following method: a large model can be used to parse the source file, obtain the parsing results, and generate a call graph to represent the call dependency relationship between functions in the target software project based on the parsing results, and then establish a function index library based on the dependency relationship between functions in the call graph.
[0094] As an example, if you are processing the code of a target software project for the first time, you can first use the above method to parse the source files using a large model, generate a call graph, and then build a function index library based on the call graph.
[0095] For example, a call graph can include static calls (i.e., direct function calls), dynamic calls (such as calls via strings, protocols, etc.), implicit calls, reflection calls, etc.
[0096] For example, based on the dependencies between functions in the call graph, the upper-level call information and lower-level call information of each function in the target software project are determined, and a function index library is established based on the upper-level call information and lower-level call information of each function.
[0097] In this embodiment, a large model is used to parse the source files of the target software project, which can efficiently and accurately obtain the parsing results such as function definitions and call information. The call graph generated based on this information can intuitively and in detail represent the call dependencies between all functions in the software project, making the interactions and dependencies between functions clear at a glance. Finally, the function index library established by analyzing the dependencies in the call graph can not only greatly improve the efficiency of function location and understanding, but also provide strong support for code maintenance and updates, simplify the complexity of finding dependencies between functions, and thus improve the overall efficiency of software development and maintenance.
[0098] To facilitate understanding of the above embodiments, taking code reduction for the entire software project as an example, the following will combine... Figure 4 To explain, Figure 4 This is a schematic diagram of a code processing procedure based on a large model, provided as an embodiment of this application.
[0099] like Figure 4 As shown, all source files in the software project are parsed, a call graph is constructed based on the parsing results, and a function index library is built based on the call graph. Then, processing flows 1, 2, and 3 are executed based on the function index library. Processing flow 1 is used for code quality optimization, processing flow 2 for extracting shared code, and processing flow 3 for deleting useless functions. These three processing flows correspond to the code quality enhancement flow, shared code extraction flow, and useless function deletion flow mentioned above, respectively.
[0100] Processing flow 1: Traverse each function in the function index library. This can detect debugging code such as logger code, check for standardization, and detect code optimization points (i.e., the code improvement point detection mentioned above). Then, based on the detection results, perform code optimization and determine if there are any unprocessed functions. If so, continue with processing flow 1 until all functions have been traversed.
[0101] Processing Flow 2: Traverse each function in the function library, analyze the functions within the source file containing the function, and determine if there are duplicate code blocks. That is, determine if there is a code block in the source file that is identical to the function. If a duplicate code block exists, provide the shared part as a shared function, replace the call with the shared function, and then update the function index library. Specifically, this can involve updating the function index library as a single data entry for the shared function and its call information, and updating the indexes of other functions. Afterward, determine if there are any unprocessed functions. If so, continue with Processing Flow 2 until all functions have been traversed.
[0102] Processing Flow 3: Traverse each function in the function library, analyze the function call information, and determine if there are any upper-level calls. If there are no upper-level calls, analyze dynamic calls and determine if there are any dynamic calls. If there are no dynamic calls, determine that the function is useless and delete it, and recursively delete the lower-level functions that are only called by it. If a function has upper-level calls, keep the function. If a function has dynamic calls, keep the function and update the function index library. After processing Flow 2 is completed for a function, determine if there are any unprocessed functions. If so, continue executing Processing Flow 2 until all functions have been traversed.
[0103] For all three processing steps described above, after traversing all functions in the function index library, a code optimization report can be generated. This optimization report can record the processing operations performed on each function, the reasons for those operations, etc.
[0104] It should be noted that the above three processing flows can be executed in parallel, or they can be executed in a certain order. This application does not limit this.
[0105] In one embodiment of this application, a code intelligent slimming method can be implemented using a large language model as the code understanding engine, call graph analysis as the basis, and an agent as the automated execution subject.
[0106] The agent can detect useless code such as logger code in each function, rewrite it as standard comments, and optimize code writing. The agent can also detect mergeable call code in a single file, separating common parts from the original functions to create shared functions. Furthermore, the agent can detect the calling functions of each function, including direct and dynamic calls, determine if they are useless functions and delete them, and remove the code that was called by the agent from the lower-level functions it calls.
[0107] 1. Large language models endow code with semantic understanding capabilities. Trained on massive amounts of code corpora, large language models can understand: (1) The functional intent of the code (e.g., whether this method is a utility function or business logic); (2) Implicit relationships in the call (e.g., which implementations the method name might point to through string concatenation); (3) The potential for code reuse (e.g., these two code segments have similar logic and can be merged); (4) Opportunities to simplify the code (e.g., this complex conditional logic can be rewritten in a more concise form).
[0108] The leap has moved from "syntactic analysis" to "semantic understanding".
[0109] 2. Utilize graph analysis to enhance language model reasoning and achieve secure deletion.
[0110] The complete call graph of the project includes: (1) static calls (direct function calls); (2) dynamic calls (via strings, selectors, protocols); (3) implicit calls; and (4) reflection calls.
[0111] The call graph can be input into a large language model, which then infers which call paths are executable, which have no reachable paths, and which, although not directly referenced, may be accessed dynamically. This enables high-confidence identification of useless code.
[0112] 3. Precise execution of "function-level dependency deletion" To address the requirement of "removing code that is only called by a certain entry function", the following method can be used: Step 1 is dependency tracing: Starting from the target function, recursively trace all functions, methods, or properties it calls; Step 2 is attribution analysis: Identify which parts of the called code are unique to this function (only called by this path) and which are publicly shared (called by other paths). Step 3 is boundary delineation: automatically generating a "list of codes that can be safely deleted" (unique part) and a "list of codes that need to be retained" (shared part); Step 4 is automated deletion: Perform the deletion operation and automatically update all related references; Step 5 is verification and rollback: compilation verification, automatic rollback if it fails. This achieves "surgical precision deletion".
[0113] 4. Intelligent identification and execution of "code reuse optimization" The agent automatically scans the project and identifies three types of reuse opportunities: (1) Completely duplicated code: Identical code snippets are automatically extracted into common functions; (2) Logically similar code: similar structure, different parameters, generate generic functions or implement configuration; (3) Responsibility cohesion code: Multiple scattered codes for the same responsibility are merged into a single module.
[0114] This enables "discovery equals extraction, and identification equals reconstruction".
[0115] 5. Intelligent code simplification and rewriting Based on the understanding of code using a large language model, it executes automatically: (1) Decomposing excessively long functions: Decompose them into multiple smaller functions according to their responsibilities; (2) Simplify complex conditions: rewrite nested if-else statements into guard statements or strategy patterns; (3) Repetitive pattern abstraction: Abstract the repetitive control structure into a higher-order function.
[0116] 6. API (Application Programming Interface) Modernization: Rewriting outdated API calls with new syntax. This achieves continuous optimization with "unchanged logic and better code".
[0117] The code processing method based on large models in this application embodiment can be applied in the following application scenarios: 1. Periodic slimming down in long-term iterative software engineering After a certain period of iteration in software engineering, the amount of code continues to expand. Regularly executing the code processing method of the embodiments of this application can systematically clean up useless code, merge duplicate code, simplify complex code, and control the increase of project entropy.
[0118] 2. Cleanup after major features are taken offline When a feature (such as "Old Homepage" or "Offline Activity Module") is discontinued, the related code needs to be deleted. This application supports automatically deleting all code called only by that feature, starting from the feature's entry function, avoiding omissions during manual traversal.
[0119] 3. Basic cleanup before modular / component-based transformation Before splitting a monolithic project into a modular architecture, run this application to clean up useless code and extract common code, reducing the difficulty of splitting and ensuring clear module boundaries.
[0120] 4. Code review assistance and quality access control.
[0121] It can automatically check: (1) whether new duplicate code has been introduced; (2) whether there is complex logic that can be simplified; and (3) whether any useless code (uncalled functions) has been added.
[0122] Therefore, code slimming is shifted to the coding stage.
[0123] 5. Modernization of legacy systems For legacy software projects that lack documentation and are difficult to fully understand, this application automatically understands the code structure, identifies useless parts, and generates cleanup plans, reducing the risk of refactoring.
[0124] To implement the above embodiments, this application also proposes a code processing device based on a large model. Figure 5 This is a schematic diagram of the structure of a code processing device based on a large model provided in an embodiment of this application.
[0125] like Figure 5 As shown, the code processing device 500 based on a large model includes: The acquisition module 510 is used to acquire the function index library corresponding to the target software project in response to the code processing instructions associated with the target software project input by the user; wherein, the function index library is used to provide structured access to function-related information in the target software project; The determination module 520 is used to parse the code processing instructions and determine the code processing flow to be executed; The execution module 530 is used to utilize the code semantic understanding capability of the large model, combined with the function index library, to execute the code processing flow on the source files of the target software project and generate processed source files.
[0126] Optionally, the execution module 530 is used for: Obtain the capability units in the large model that correspond to the code processing flow; The capability unit is invoked, and in conjunction with the function index library, the code processing flow is executed on the source file to generate the processed source file.
[0127] Optionally, the code processing flow includes a useless function deletion process, and the execution module 530 is used for: The capability unit is invoked to traverse the function index library, and for any function in the function index library, the call information of that function is obtained from the function index library; Based on the call information, useless functions and their associated redundant code in the source file are identified and removed, and the processed source file is generated.
[0128] Optionally, the execution module 530 is used for: Invoke the capability unit, and in response to determining that any function has no upper-level call based on the call information, perform dynamic call detection on any function and obtain the dynamic call detection result; In response to the dynamic call detection result indicating that any function has no dynamic calls, delete any function and recursively delete any lower-level functions that are only called by any function.
[0129] Optionally, the device may further include: The retention module is used to retain any function in response to an upper-level call to any of the functions; The update module is also configured to, in response to the existence of dynamic calls to any of the functions, retain any of the functions and update the function index library.
[0130] Optionally, the code processing flow includes a common code extraction flow, and the execution module 530 is used for: The capability unit is invoked to traverse the function index library and determine the source file to which any function in the function index library belongs; In response to the existence of a target function in the source file that has a duplicate code block with any of the functions, the common code portion between the function and the target function is extracted to generate a common function; In the current function and the target function, the shared code portion is replaced with a call to the shared function, thereby generating the processed source file.
[0131] Optionally, the code processing flow includes a code quality enhancement flow, and the execution module 530 is used for: The capability unit is invoked to traverse the function index library and perform code quality detection on any function in the function index library to obtain the quality detection result: wherein, the code quality detection includes at least one of the following: debugging residual code detection, comment standardization detection, and code improvement point detection; Based on the quality inspection results, code improvement processing is performed on any of the functions to obtain the processed source file.
[0132] Optionally, the device may further include: The parsing module is used to parse the source file using the large model and obtain the parsing results; An execution module is used to generate a call graph that characterizes the call dependencies between functions in the target software project, based on the parsing results. A building module is used to establish the function index library based on the dependencies between functions in the call graph.
[0133] It should be noted that the explanation of the aforementioned code processing method embodiment based on large models also applies to the code processing device based on large models in this embodiment, so it will not be repeated here.
[0134] In this embodiment, after receiving the user's code processing instructions for the target software project, the function index library corresponding to the code processing instructions is obtained, and then the code processing instructions are parsed to determine the specific processing flow. By combining the code semantic understanding capability of the large model with the function index library, precise and context-aware code processing is performed on the source file. This makes the code processing not only based on the surface syntax, but also incorporates a deep understanding of the functions, which can significantly improve the accuracy, reliability, context consistency and processing efficiency of code processing.
[0135] According to embodiments of this application, this application also provides an electronic device, a readable storage medium, and a computer program product.
[0136] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.
[0137] like Figure 6 As shown, device 600 includes a computing unit 601, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 602 or a computer program loaded from storage unit 608 into RAM (Random Access Memory) 603. RAM 603 may also store various programs and data required for the operation of device 600. The computing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. I / O (Input / Output) interface 605 is also connected to bus 604.
[0138] Multiple components in device 600 are connected to I / O interface 605, including: input unit 606, such as keyboard, mouse, etc.; output unit 607, such as various types of monitors, speakers, etc.; storage unit 608, such as disk, optical disk, etc.; and communication unit 609, such as network card, modem, wireless transceiver, etc. Communication unit 609 allows device 600 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0139] The computing unit 601 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as large-model-based code processing methods. For example, in some embodiments, the large-model-based code processing method can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed on device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the large-model-based code processing method described above can be performed. Alternatively, in other embodiments, computing unit 601 may be configured to perform code processing methods based on large models by any other suitable means (e.g., by means of firmware).
[0140] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System-on-Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0141] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0142] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0143] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0144] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include LANs (Local Area Networks), WANs (Wide Area Networks), the Internet, and blockchain networks.
[0145] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is established by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem, addressing the shortcomings of traditional physical hosts and VPS (Virtual Private Server) services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.
[0146] According to embodiments of this application, this application also provides a computer program product that, when an instruction processor in the computer program product is executed, performs the code processing method based on a large model proposed in the above embodiments of this application.
[0147] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.
[0148] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A code processing method based on a large model, comprising: In response to receiving a code processing instruction associated with a target software project input by a user, the function index library corresponding to the target software project is obtained; wherein, the function index library is used to provide structured access to function-related information in the target software project; The code processing instructions are parsed to determine the code processing flow to be executed; By leveraging the code semantic understanding capabilities of the large model and combining it with the function index library, the code processing flow is executed on the source files of the target software project to generate processed source files.
2. The method as described in claim 1, wherein, The process of utilizing the code semantic understanding capabilities of the large model, combined with the function index library, to execute the code processing flow on the source files of the target software project and generate processed source files includes: Obtain the capability units in the large model that correspond to the code processing flow; The capability unit is invoked, and in conjunction with the function index library, the code processing flow is executed on the source file to generate the processed source file.
3. The method as described in claim 2, wherein, The code processing flow includes a useless function deletion process. The process involves calling the capability unit, combining it with the function index library, and executing the code processing flow on the source file to generate the processed source file, including: The capability unit is invoked to traverse the function index library, and for any function in the function index library, the call information of that function is obtained from the function index library; Based on the call information, useless functions and their associated redundant code in the source file are identified and removed, and the processed source file is generated.
4. The method of claim 3, wherein, The step of identifying and removing useless functions and their associated redundant code in the source file based on the call information includes: Invoke the capability unit, and in response to determining that any function has no upper-level call based on the call information, perform dynamic call detection on any function and obtain the dynamic call detection result; In response to the dynamic call detection result indicating that any function has no dynamic calls, delete any function and recursively delete any lower-level functions that are only called by any function.
5. The method of claim 4, further comprising: In response to any of the functions being called from an upper level, the function is retained. In response to any of the functions being dynamically called, the function is retained and the function index is updated.
6. The method of claim 2, wherein, The code processing flow includes a shared code extraction flow, wherein calling the capability unit, in conjunction with the function index library, executes the code processing flow on the source file to generate the processed source file, including: The capability unit is invoked to traverse the function index library and determine the source file to which any function in the function index library belongs; In response to the existence of a target function in the source file that has a duplicate code block with any of the functions, the common code portion between the function and the target function is extracted to generate a common function; In the current function and the target function, the shared code portion is replaced with a call to the shared function, thereby generating the processed source file.
7. The method of claim 2, wherein, The code processing flow includes a code quality enhancement process, wherein calling the capability unit, in conjunction with the function index library, executes the code processing flow on the source file to generate the processed source file, including: The capability unit is invoked to traverse the function index library and perform code quality detection on any function in the function index library to obtain the quality detection result: wherein, the code quality detection includes at least one of the following: debugging residual code detection, comment standardization detection, and code improvement point detection; Based on the quality inspection results, code improvement processing is performed on any of the functions to obtain the processed source file.
8. The method according to any one of claims 1-7, wherein, The function index library is constructed using the following method: The large model is used to parse the source file and obtain the parsing results; Based on the analysis results, a call graph is generated to characterize the call dependencies between functions in the target software project; Based on the dependencies between functions in the call graph, the function index library is established.
9. A code processing device based on a large model, comprising: The acquisition module is used to acquire the function index library corresponding to the target software project in response to the code processing instructions associated with the target software project input by the user; wherein, the function index library is used to provide structured access to function-related information in the target software project; The determination module is used to parse the code processing instructions and determine the code processing flow to be executed; The execution module is used to leverage the code semantic understanding capabilities of the large model, combined with the function index library, to execute the code processing flow on the source files of the target software project, and generate processed source files.
10. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-8.
11. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-8.
12. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1-8.