Code task processing method, code reading method, code processing method, computing device, computer-readable storage medium, and computer program product
By incorporating the context and function call information into the code processing model, detailed function description information is generated, solving the problem of insufficient context dependency in open-source code processing by intelligent coding assistants, achieving more accurate code understanding and improving development efficiency.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-09-08
- Publication Date
- 2026-04-02
AI Technical Summary
Existing intelligent coding assistants cannot fully utilize complete contextual information when processing open-source code, resulting in the generation of incorrect comments and explanations that mislead users. Furthermore, they cannot perform global analysis and struggle to provide consistent overall understanding and recommendations.
By incorporating contextual and function call information into the code processing model, detailed and context-rich function descriptions are generated. This allows the code processing model to understand the global information of the entire code repository, reducing the generation of illusions.
It improves the accuracy and learning effectiveness of code processing, helps developers quickly understand unfamiliar coding languages and projects, and improves development efficiency.
Smart Images

Figure CN2025119577_02042026_PF_FP_ABST
Abstract
Description
Code task processing method, code reading method, code processing method, computing device, computer-readable storage medium, and computer program product
[0001] The present disclosure claims priority to Chinese Patent Application No. 202411346921.3, filed on September 25, 2024, with the Chinese Patent Office, entitled "Code task processing method, code reading method, code processing method, computing device, computer-readable storage medium, and computer program product", the entire contents of which are incorporated herein by reference. TECHNICAL FIELD
[0002] Embodiments of the present specification relate to the technical field of computer technology, and particularly relate to a code task processing method, a code reading method, a code processing method, a computing device, a computer-readable storage medium, and a computer program product. BACKGROUND
[0003] With the vigorous development of the software development industry, more and more excellent projects have emerged in the open source community. Open source repositories are not only platforms for project display, but also important resources for learning and collaboration. For developers, a large amount of open source code provides valuable learning materials. However, due to the large size and complex technology of open source projects, many new technologies are also involved, and beginners often face some difficulties when reading and understanding these codes.
[0004] Currently, code annotations and code explanations for a single function or class can be generated, however, for the case of calling other custom functions, the above scheme cannot fully utilize the complete code context information, resulting in the possibility of generating illusory annotations and explanations during code processing, i.e., generating seemingly reasonable but actually incorrect code annotations and explanation contents in the absence of sufficient context, thereby misleading users, therefore, there is an urgent need for a code task processing scheme with high accuracy. SUMMARY
[0005] In view of this, the embodiments of the present specification provide a code task processing method. One or more embodiments of the present specification also relate to a code reading method, a code processing method, a code task processing device, a code reading device, a code processing device, a computing device, a computer-readable storage medium, and a computer program product, to solve the technical defects in the prior art.
[0006] According to a first aspect of the embodiments of the present specification, a code task processing method is provided, comprising:
[0007] obtaining to-be-processed code data of a target code task;
[0008] The task processing result of the to-be-processed code data is searched from the plurality of function description information, wherein the function description information comprises first description information of a calling function, the first description information is obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis on the source code file.
[0009] According to a second aspect of an embodiment of the present specification, a code reading method is provided, comprising:
[0010] Obtaining to-be-processed code data of a code reading task;
[0011] The code reading information of the to-be-processed code data is searched from the plurality of function description information, wherein the function description information comprises first description information of a calling function, the first description information is obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis on the source code file.
[0012] According to a third aspect of an embodiment of the present specification, a code processing method is provided, comprising:
[0013] Obtaining a source code file, wherein the source code file comprises a plurality of calling functions;
[0014] Syntax analyzing the source code file to determine function call information of the plurality of calling functions respectively;
[0015] Inputting function information of the plurality of calling functions, context information of the plurality of calling functions, and the function call information of the plurality of calling functions into a code processing model to obtain first description information of the plurality of calling functions respectively.
[0016] According to a fourth aspect of an embodiment of the present specification, a code task processing apparatus is provided, comprising:
[0017] A first obtaining module configured to obtain to-be-processed code data of a target code task;
[0018] A first searching module configured to search a task processing result of the to-be-processed code data from a plurality of function description information, wherein the function description information comprises first description information of a calling function, the first description information is obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis on the source code file.
[0019] According to a fifth aspect of an embodiment of the present specification, a code reading apparatus is provided, comprising:
[0020] The second obtaining module is configured to obtain to-be-processed code data of a code reading task.
[0021] The second searching module is configured to search, from the plurality of function description information, code reading information of the to-be-processed code data, wherein the function description information comprises first description information of the calling function, and the first description information is obtained by the code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis on the source code file.
[0022] According to a sixth aspect of an embodiment of the present specification, a code processing apparatus is provided, comprising:
[0023] The third obtaining module is configured to obtain a source code file, wherein the source code file comprises a plurality of calling functions.
[0024] The parsing module is configured to perform syntax analysis on the source code file, and determine function call information of the plurality of calling functions respectively.
[0025] The input module is configured to input function information of the plurality of calling functions, context information of the plurality of calling functions, and the function call information of the plurality of calling functions into the code processing model, and obtain first description information of the plurality of calling functions respectively.
[0026] According to a seventh aspect of an embodiment of the present specification, a computing device is provided, comprising:
[0027] a memory and a processor;
[0028] The memory is configured to store computer programs / instructions, and the processor is configured to execute the computer programs / instructions, so as to implement the steps of the method provided in the first aspect or the second aspect or the third aspect.
[0029] According to an eighth aspect of an embodiment of the present specification, a computer readable storage medium is provided, which stores computer programs / instructions, and the computer programs / instructions are executed by a processor to implement the steps of the method provided in the first aspect or the second aspect or the third aspect.
[0030] According to a ninth aspect of an embodiment of the present specification, a computer program product is provided, comprising computer programs / instructions, and the computer programs / instructions are executed by a processor to implement the steps of the method provided in the first aspect or the second aspect or the third aspect.
[0031] An embodiment of the present specification provides a code task processing method, including: obtaining to-be-processed code data of a target code task; and searching for a task processing result of the to-be-processed code data from a plurality of function description information, wherein the function description information includes first description information of a calling function, the first description information being obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information being obtained based on syntax analysis on a source code file. By incorporating the context information of the calling function into the input of the code processing model, detailed and context-rich function description information can be generated for each calling function. Furthermore, by incorporating the function call information of the calling function into the input of the code processing model, the code processing model can understand the global information of the entire code repository, reduce the generation illusion of the code processing model, and further improve the accuracy of the task processing result, helping developers quickly understand unfamiliar code languages and projects, thereby improving learning effectiveness and development efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0032] FIG. 1 is an architecture diagram of a code task processing system according to an embodiment of the present specification;
[0033] FIG. 2 is an architecture diagram of another code task processing system according to an embodiment of the present specification;
[0034] FIG. 3 is a flowchart of a code task processing method according to an embodiment of the present specification;
[0035] FIG. 4 is a schematic diagram of a function call graph according to an embodiment of the present specification;
[0036] FIG. 5 is a schematic diagram of a function call tree according to an embodiment of the present specification;
[0037] FIG. 6 is a flowchart of a code reading method according to an embodiment of the present specification;
[0038] FIG. 7 is a flowchart of a code processing method according to an embodiment of the present specification;
[0039] FIG. 8 is a flowchart of a processing process of a code processing method according to an embodiment of the present specification;
[0040] FIG. 9 is a structural schematic diagram of a code task processing apparatus according to an embodiment of the present specification;
[0041] FIG. 10 is a structural schematic diagram of a code reading apparatus according to an embodiment of the present specification;
[0042] FIG. 11 is a structural schematic diagram of a code processing apparatus according to an embodiment of the present specification;
[0043] FIG. 12 is a structural block diagram of a computing device according to an embodiment of the present specification. DETAILED DESCRIPTION
[0044] In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present specification. However, the present specification can be practiced without the specific details, other than in the examples described herein. Those skilled in the art, in light of the present specification, can implement or practice the present specification without exercising the same.
[0045] The terminology used in one or more embodiments of the present specification is for the purpose of describing particular embodiments only and is not intended to be limiting of one or more embodiments of the present specification. As used in one or more embodiments of the present specification and the accompanying claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be understood by those skilled in the art that the terms "and / or," as used in one or more embodiments of the present specification, refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0046] It will be understood that, although the terms first, second, etc. can be used herein to describe various information, these terms are not intended to denote a temporal or chronological order. Rather, these terms are used solely to distinguish one from another only. For example, without departing from the scope of one or more embodiments of the present specification, first can be termed second, and similarly, second can be termed first. The term "if' as used herein, can be interpreted as meaning "when" or "in response to determining" depending on the context.
[0047] In addition, 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 for analysis, stored data, displayed data, etc.) involved in one or more embodiments of the present specification are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.
[0048] In one or more embodiments of the present specification, a large model refers to a deep learning model with a large number of model parameters, usually containing hundreds of millions, billions, tens of billions, hundreds of billions, or even tens of billions of model parameters. The large model can also be called a foundation model. Through large-scale unlabeled corpus pre-training, a pre-trained model with hundreds of millions of parameters is produced. This model can adapt to a wide range of downstream tasks and has good generalization ability. For example, large language models (LLM) and multi-modal pre-training models.
[0049] In practical applications, a large model only needs a small amount of sample data to fine-tune the pre-trained model and can be applied to different tasks. Large models can be widely used in natural language processing (NLP) and computer vision, and can be applied to tasks such as visual question answering (VQA), image captioning (IC), image generation, sentiment classification based on text, text summarization, machine translation, and other natural language processing tasks. The main application scenarios of large models include digital assistants, intelligent robots, search, online education, office software, e-commerce, intelligent design, etc.
[0050] First, the technical terms related to one or more embodiments of the present specification are explained.
[0051] Intelligent coding assistant: Through large model technology, it realizes code completion, document generation, code explanation, unit testing, code repair, etc., and improves the development efficiency, code quality and development experience of programmers.
[0052] Static code analysis: a method of analyzing code semantics and behavior without executing the program, detecting potential errors, analyzing code logic relationships, coding specification violations, and performance problems through code structure parsing.
[0053] Bottom-up traversal: a traversal method for processing tree-structured data (such as binary trees or multi-way trees). In bottom-up traversal, the bottom nodes of the tree are accessed first, and then the nodes are accessed layer by layer upwards to the root node. This method is opposite to the common top-down traversal (starting from the root node and accessing layer by layer downwards).
[0054] Function Call Graph: A function call graph is a directed graph that represents the calling relationships between functions in a program. In this graph, each node represents a function, and each directed edge represents a function calling another function. Function call graphs are widely used in program optimization, debugging, and code understanding processes, helping developers find function call paths, detect recursive calls, and analyze impact scopes.
[0055] Abstract Syntax Tree (AST): An abstract syntax tree is a tree-like data structure used to represent the structure of source code. It is mainly used in compilers and interpreters and can also be applied in scenarios such as static code analysis, code generation, and code conversion. An AST consists of a series of nodes, each representing a syntactic component of the source code, such as function calls, variable declarations, loop structures, etc.
[0056] Dictionary: A dictionary is a mutable container model that stores data in the form of key-value pairs. Each element in the dictionary contains a key and a corresponding value, where the key is an immutable type (such as a string, number, or tuple), and the value can be any data type.
[0057] Custom Class: Allows the definition of your own data types. Classes can contain attributes (i.e., data members) and methods (i.e., behaviors). Classes are the foundation of object-oriented programming and can be used in Python to achieve encapsulation, inheritance, and polymorphism.
[0058] Code Comments: Adding text explanations in the source code that will not be executed by the compiler or interpreter, but can help other developers (including future self) understand the purpose and functionality of the code.
[0059] Code Purpose: Refers to the functionality or purpose of the code, i.e., what effect the code will achieve after execution.
[0060] Code Explanation: An explanation of the code logic, used to express the purpose of the code, how it works, and why it is done this way, which helps others understand the intent of the code, especially for complex algorithms or project logic.
[0061] The product of the intelligent coding assistant class can generate code annotations and code explanations of a single function or class, which plays a positive role in improving development efficiency and facilitating code reading. However, such products also have the following shortcomings: first, insufficient context dependency: for the case of calling other custom functions, due to the inability to fully utilize complete context information, the intelligent coding assistant may have "hallucinations", that is, generate seemingly reasonable but actually incorrect content when there is insufficient context, thereby misleading the user; second, limited understanding at the repository level: current intelligent coding assistants cannot process and understand the entire code repository at once, and usually can only generate annotations and explanations for a single function or class at a time. This means that it cannot perform global analysis of the code base and it is difficult to provide a consistent overall understanding and suggestions.
[0062] To solve the above problems, an embodiment of the present specification proposes an intelligent coding assistant solution based on a code processing model, obtaining to-be-processed code data of a target code task; from a plurality of function description information, finding a task processing result of the to-be-processed code data, wherein the function description information includes first description information of a calling function, the first description information is obtained by the code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis of a source code file. By incorporating the context information of the calling function into the input of the code processing model, detailed and context-rich function description information can be generated for each calling function. Furthermore, by incorporating the function call information of the calling function into the input of the code processing model, the code processing model can understand the global information of the entire code repository, reduce the hallucinations of the code processing model, further improve the accuracy of the task processing result, and help developers quickly understand unfamiliar code languages and projects, thereby improving learning effectiveness and development efficiency.
[0063] In the present specification, a code task processing method is provided, and the present specification also relates to a code reading method, a code processing method, a code task processing device, a code reading device, a code processing device, a computing device, a computer-readable storage medium, and a computer program product, which are described in detail one by one in the following embodiments.
[0064] Referring to FIG. 1, FIG. 1 shows an architecture diagram of a code task processing system according to an embodiment of the present specification. The code task processing system can include a client 100 and a server 200.
[0065] The client 100 is configured to send to-be-processed code data of a target code task to the server 200.
[0066] The server 200 is configured to search for a task processing result of the to-be-processed code data from a plurality of function description information, wherein the function description information comprises first description information of a calling function, and the first description information is obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis on a source code file.
[0067] Optionally, the server 200 is further configured to send the task processing result of the to-be-processed code data to the client 100, and the client 100 is further configured to receive the task processing result of the to-be-processed code data sent by the server 200.
[0068] By using the scheme of the embodiments of the present specification, the first description information of the calling function is generated based on the function information, the context information, and the function call information of the calling function by using the code processing model, so that detailed and context-rich function description information is generated for each calling function, the illusion of the code processing model is reduced, and the accuracy of the task processing result is further improved.
[0069] Referring to FIG. 2, FIG. 2 shows an architecture diagram of another code task processing system according to an embodiment of the present specification. The code task processing system can include a plurality of clients 100 and a server 200. The client 100 can include an end-side device, and the server 200 can include a cloud-side device. The plurality of clients 100 can establish a communication connection through the server 200. In a code task processing scenario, the server 200 is used to provide a code task processing service between the plurality of clients 100. The plurality of clients 100 can be used as a sending end or a receiving end, and communication can be achieved through the server 200. A user can interact with the server 200 through the client 100 to receive data sent by other clients 100 or send data to other clients 100, and the like. In a code task processing scenario, a user can publish a data stream to the server 200 through the client 100. The server 200 generates a task processing result according to the data stream, and pushes the task processing result to other clients that establish a communication connection. The client 100 and the server 200 establish a connection through a network. The network provides a medium for a communication link between the client 100 and the server 200. The network can include various connection types, such as wired, wireless communication links, or optical fiber cables, and the like. The data transmitted by the client 100 can need to be processed through encoding, transcoding, compression, and the like before being published to the server 200.
[0070] The client 100 can be a browser, an application (APP), or a web application such as a HyperText Markup Language 5 (H5) application, or a light application (also known as a mini-program, a lightweight application), or a cloud application, etc. The client 100 can be developed based on a software development kit (SDK) of a corresponding service provided by the server 200, such as a real-time communication (RTC) SDK, etc. The client 100 can be deployed in an electronic device, and needs to rely on the device or some APP in the device, etc. The electronic device can have a display screen and support information browsing, etc., such as a personal mobile terminal such as a mobile phone, a tablet computer, a personal computer, etc. Various other types of applications can also be configured in the electronic device, such as human-computer dialogue applications, model training applications, text processing applications, web browser applications, shopping applications, search applications, instant messaging tools, mailbox clients, social platform software, etc.
[0071] The server 200 can include servers that provide various services, such as servers that provide communication services for multiple clients, servers that provide support for models used on clients for background training, servers that process data sent by clients, etc. It should be noted that the server 200 can be implemented as a distributed server cluster composed of multiple servers, or as a single server. The server can also be a server of a distributed system, or a server combined with a blockchain. The server can also be a cloud server of cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, etc. basic cloud computing services, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
[0072] It should be noted that the code task processing method provided in the embodiments of the present specification is generally executed by the server, but in other embodiments of the present specification, the client can also have similar functions as the server, so as to execute the code task processing method provided in the embodiments of the present specification. In other embodiments, the code task processing method provided in the embodiments of the present specification can also be executed by the client and the server together.
[0073] Referring to FIG. 3, FIG. 3 shows a flowchart of a code task processing method according to an embodiment of the present specification, which specifically includes the following steps:
[0074] Step 302: obtaining to-be-processed code data of the target code task.
[0075] It should be noted that the target code task can be a task of different types, such as a code reading task, a code comment generation task, a code explanation task, a code effect generation task, and the like. The to-be-processed code data refers to a processing object when the code task is processed. The to-be-processed code data can be a code snippet, a syntax element, or the like, and the specific selection is based on actual conditions, and the embodiments of the present specification do not make any limitation in this regard.
[0076] In actual application, there are various ways to obtain the to-be-processed code data of the target code task, and the specific selection is based on actual conditions, and the embodiments of the present specification do not make any limitation in this regard. In a possible implementation manner of the present specification, the operation of the client on the to-be-processed code data can be received, and the to-be-processed code data of the target code task is obtained in response to the operation. In another possible implementation manner of the present specification, the to-be-processed code data of the target code task can be read from other data acquisition devices or databases at a regular time.
[0077] In an optional embodiment of the present specification, the above-mentioned obtaining of the to-be-processed code data of the target code task can include the following steps:
[0078] The to-be-processed code data of the target code task is obtained in response to the operation of the client on the to-be-processed code data.
[0079] It should be noted that the client can display a source code file corresponding to the target code task, wherein the source code file includes the to-be-processed code data. The client can operate the to-be-processed code data in the source code file. After the server monitors the operation of the client on the to-be-processed code data, the to-be-processed code data of the target code task is obtained in response to the operation.
[0080] In actual application, the operation of the client on the to-be-processed code data includes any one of clicking, double-clicking, touch control, mouse hovering, sliding, long pressing, voice control, or shaking, and the specific selection is based on actual conditions, and the embodiments of the present specification do not make any limitation in this regard.
[0081] By applying the scheme of the embodiments of the present specification, the to-be-processed code data of the target code task is obtained in response to the operation of the client on the to-be-processed code data, so that the to-be-processed code data can be accurately determined, and the interactivity when the user processes the code task is improved.
[0082] Step 304: searching for the task processing result of the to-be-processed code data from the plurality of function description information, wherein the function description information comprises the first description information of the calling function, and the first description information is obtained by the code processing model based on the function information of the calling function, the context information of the calling function, and the function call information of the calling function, and the function call information is obtained based on the syntax analysis of the source code file.
[0083] It should be noted that the task processing result corresponds to the target code task, if the target code task is a code comment generation task, the code processing result is the comment information of the to-be-processed code data; if the target code task is a code interpretation task, the code processing result is the interpretation information of the to-be-processed code data.
[0084] The function description information of the plurality of functions in the source code file can be stored in the information library. When the information library stores the plurality of function description information, the function description information can be stored on the node corresponding to the function call tree. After obtaining the to-be-processed code data of the target code task, the task processing result of the to-be-processed code data can be searched from the plurality of function description information included in the information library. The plurality of functions includes calling functions and non-calling functions. The calling function refers to a function that directly or indirectly calls other functions. The calling function not only contains its own logic, but also executes more complex tasks by calling other functions. The non-calling function refers to a function that does not call any function. The non-calling function only executes the logic defined by itself, and does not depend on the calling of other functions. The function description information is used to describe the corresponding function in the form of natural language. The function description information includes at least one of function interpretation information, function role information, and function comment information. Since the function includes calling functions and non-calling functions, the function description information includes first description information of the calling function and second description information of the non-calling function. The second description information is obtained by the code processing model based on the function information of the non-calling function.
[0085] The code processing model is used for code analysis and understanding based on model input information, and outputs function description information. The code processing model can be a large model for code data, or a deep learning model obtained by supervised fine-tuning based on the function information of the sample calling function, the context information of the sample calling function, the function call information of the sample calling function, and the first description information of the sample calling function, and / or a deep learning model obtained by supervised fine-tuning based on the function information of the sample non-calling function and the second description information of the sample non-calling function.
[0086] By means of the scheme of the embodiments of the present specification, the first description information of the calling function is generated according to the function information, the context information and the function calling information of the calling function by using the code processing model, so that detailed and context-rich function description information can be generated for each calling function, the generation illusion of the code processing model is reduced, and the accuracy of the task processing result is further improved.
[0087] In actual application, there are various ways to find the task processing result of the code data to be processed from the plurality of function description information, which is specifically selected according to actual situation, and the present specification does not make any limitation on this. In one possible implementation manner of the present specification, the task processing result of the code data to be processed can be found from the plurality of function description information according to the data identifier of the code data to be processed and the information identifier carried by the plurality of function description information. In another possible implementation manner of the present specification, the similarity between the code data to be processed and each function in the code library is calculated, the function description information corresponding to the function with higher similarity is determined as the target function description information of the code data to be processed, and the task processing result of the code data to be processed is extracted from the target function description information according to the target code task.
[0088] In an optional embodiment of the present specification, the function description information carries the information identifier. The above finding the task processing result of the code data to be processed from the plurality of function description information can include the following steps:
[0089] determining the target function description information from the plurality of function description information according to the data identifier of the code data to be processed, wherein the information identifier of the target function description information is the same as the data identifier;
[0090] extracting the task processing result of the code data to be processed from the target function description information according to the target code task.
[0091] It should be noted that the information identifier is used to uniquely identify the corresponding function description information. The information identifier can be the identifier of the function corresponding to the function description information, such as the number of the function. The data identifier is used to uniquely identify the code data to be processed, and the data identifier can be the number of the code data to be processed. If the code data to be processed includes a plurality of functions, the data identifier can be an identifier sequence composed of the identifiers of the plurality of functions included.
[0092] Exemplarily, it is assumed that the data identifier of the code data to be processed is a, the function description information of the three functions included in the information library is function description information 1, function description information 2 and function description information 3 respectively, wherein the information identifier 1 carried by the function description information 1 is a, the information identifier 2 carried by the function description information 2 is b, and the information identifier 3 carried by the function description information 3 is c. When the target function description information is determined from the plurality of function description information according to the data identifier of the code data to be processed, the data identifier can be matched with the information identifier 1, the information identifier 2 and the information identifier 3 respectively, so as to determine that the data identifier is the same as the information identifier 1, and at this time, the function description information 1 is determined as the target function description information.
[0093] Further, the target function description information can include function explanation information, function action information and function annotation information. If the target code task is a code reading task, the function explanation information, the function action information and the function annotation information are determined as the task processing result of the code data to be processed. If the target code task is a code explanation task, the function explanation information is determined as the task processing result of the code data to be processed.
[0094] By using the information identifier carried by each of the plurality of function description information and the data identifier of the code data to be processed, the target function description information is determined from the plurality of function description information, so that the target function description information is more accurate. Further, according to the task type of the target code task, the task processing result of the code data to be processed is extracted from the target function description information, so that the task processing result is more in line with the target code task, and the accuracy of the task processing result is improved.
[0095] In an optional embodiment of the present specification, the function description information further includes second description information of the non-call function; before the above-mentioned searching for the task processing result of the code data to be processed from the plurality of function description information, the second description information of the non-call function can be generated by using the code processing model, and the second description information is stored in the information library, that is, before the above-mentioned searching for the task processing result of the code data to be processed from the plurality of function description information, the following steps can be further included:
[0096] The function information of the non-call function is input into the code processing model to obtain the second description information of the non-call function.
[0097] It should be noted that the function information of the non-call function refers to the attribute information of the non-call function itself, including function name, parameter list, return type and code logic in the function body, etc. The second description information of the non-call function is used to describe the explanation, action and annotation of the non-call function in the form of natural language.
[0098] In actual application, before the function information of the non-call function is input into the code processing model to obtain the second description information of the non-call function, the function information of the non-call function can be acquired, and when the function information of the non-call function is acquired, the function definition in the source code file can be directly viewed. After the second description information of the non-call function is obtained, the second description information can be stored into the information library.
[0099] By using the scheme of the embodiments of the present specification, the second description information of the non-call function is generated according to the function information of the non-call function by using the code processing model, so that the information library includes complete function description information in the source code file, and the comprehensiveness of the function description information is improved.
[0100] In an optional embodiment of the present specification, before the task processing result of searching the to-be-processed code data from the plurality of function description information is searched, the first description information of the call function can also be generated by using the code generation model, that is, before the task processing result of searching the to-be-processed code data from the plurality of function description information is searched, the following step can also be included:
[0101] Acquire the source code file, wherein the source code file includes a plurality of call functions;
[0102] Syntax analysis is performed on the source code file to determine the function call information of the call function;
[0103] According to the plurality of call functions and the function call information, a function call tree of the call function is constructed;
[0104] Hierarchical traversal is performed on the function call tree of the call function to determine the context information of the call function;
[0105] The function information of the call function, the context information of the call function, and the function call information of the call function are input into the code processing model to obtain the first description information of the call function.
[0106] It should be noted that the source code file refers to a code file used for writing a software project. The extension of the source code file includes but is not limited to ".py", ".c", ".cpp", ".js", and is selected according to the actual project, and the embodiments of the present specification do not make any limitation on this. The function information of the calling function refers to the attribute information of the calling function itself, including but not limited to function name, parameter list, return type, scope, and the like. The function information of a plurality of functions (including calling functions and non-calling functions) included in the source code file can be obtained by syntax parsing the source code file, such as a syntax structure diagram obtained by traversing syntax parsing. The function information of each function can be stored in the code library in the form of a dictionary or a custom class, so that the function information of each function can be obtained from the code library. The first description information of the calling function is used to describe the explanation, effect and annotation of the calling function in the form of natural language. The context information of the calling function refers to the function description information of the function called by the calling function. The function called by the calling function is referred to as the context of the calling function. The function call information refers to the function call relationship (such as direct call, recursive call, nested call, loop call, etc.) between the calling function and other functions when the calling function calls other functions, and the function information (such as the file, line number, name, class, parameter, etc. of the other function) of the other function.
[0107] In practical applications, there are various ways to obtain the source code file, which are selected according to actual conditions, and the embodiments of the present specification do not make any limitation on this. In a possible implementation manner of the present specification, the repository directory of the code repository can be traversed to find the source code file. In another possible implementation manner of the present specification, the source code file sent by the user through the client can be received.
[0108] Further, there are various ways to syntax parse the source code file to determine the function call information of the calling function, which are selected according to actual conditions, and the embodiments of the present specification do not make any limitation on this. In a possible implementation manner of the present specification, the syntax of the source code file can be parsed directly by using a static code analysis tool to obtain the function call information of each calling function. In another possible implementation manner of the present specification, the syntax of the source code file can be parsed to obtain a syntax structure diagram, and the function call information of each calling function can be determined based on the syntax structure diagram.
[0109] By means of the scheme of the embodiments of the present specification, the function call information of each calling function is determined by performing syntax analysis on the source code file, so that the code processing model can understand the global information of the entire source code file, reduce the generation illusion of the code processing model, and integrate the context information of the calling function in the input of the code processing model, so as to generate detailed and context-rich function description information for each calling function, help developers quickly understand unfamiliar code languages and projects, thereby improving learning effect and improving development efficiency.
[0110] In an optional embodiment of the present specification, the above syntax analysis on the source code file and determination of the function call information of the calling function can include the following steps:
[0111] Syntax analysis is performed on the source code file to obtain a syntax structure graph, wherein the syntax structure graph is constructed with syntax elements in the source code file as nodes and relationships between the syntax elements as edges;
[0112] The syntax structure graph is traversed to determine the calling function and the function call relationship of the calling function;
[0113] The function call information of the calling function is determined according to the function information and the function call relationship of the calling function.
[0114] It should be noted that the syntax structure graph can be in the form of an abstract syntax tree. The function call relationship refers to the relationship between the caller and the callee. In program design, a function is a code block that completes a specific task, which can be called by other parts of the program. When a function directly or indirectly calls another function during its execution, a function call relationship is formed. The function call relationship includes but is not limited to direct call, recursive call, nested call, and loop call, which is selected according to actual conditions, and the embodiments of the present specification do not make any limitation thereon.
[0115] In actual application, a parser corresponding to the code language (such as the AST module provided by Python) can be used to perform syntax analysis on the source code file to obtain the syntax structure graph. For example, the syntax structure graph includes calling function A and calling function B, and there is a direct call relationship between the calling function A and the calling function B, so the function call information of the calling function A is determined as: the calling function A directly calls the calling function B, the function name of the calling function B is C, and the calling function B belongs to file D.
[0116] Optionally, after performing syntax analysis on the source code file to obtain the syntax structure graph, the syntax structure graph can be traversed to extract all function definitions and class definitions, record the attribute information of each function and class, including the file, line number, name, belonging class, parameter, etc., and a data structure (such as a dictionary or a custom class) can also be defined to store these information.
[0117] By applying the scheme of the embodiments of the present specification, the structural information of the entire code library is analyzed and collected by determining the function call information of the plurality of calling functions from the syntax structure diagram, global and consistent code understanding is provided, a detailed function call graph and function call tree are constructed, the integrity and accuracy of the context are ensured, the problem of insufficient context dependency is solved, the code processing model can understand the global information of the entire source code file, and the generation illusion of the code processing model is reduced.
[0118] In an optional embodiment of the present specification, the function call tree of the calling function constructed according to the plurality of calling functions and the function call information can include the following steps:
[0119] The function call graph of the source code file is constructed with the plurality of calling functions of the source code file as nodes and the function call relationship of the calling functions as edges;
[0120] For any calling function, the function call graph is split with the calling function as the root node to obtain the function call tree of the calling function.
[0121] It should be noted that since the context information of the calling function refers to the function description information of the function called by the calling function, the function called by the calling function can be determined through the function call tree of the calling function, and the function description information of the called function is further determined as the context information, that is, the context information of the calling function is obtained based on the function call tree of the calling function, and the function call tree is split from the function call graph with the calling function as the root node.
[0122] In actual application, after the function call graph is constructed with the plurality of calling functions as nodes and the function call relationship as edges, for each specific calling function, the function call graph can be split to extract the function call tree of the calling function from the function call graph. Specifically, the function call graph can be recursively traversed: any calling function is taken as the root node, all other functions called by the calling function are recursively traversed, and the function call tree of the calling function is constructed. Optionally, for each node in the function call tree, the specific code content, file address, belonging class, and called times of the node can be stored as the function information of the node on the node. And the function information stored on the node can be dynamically adjusted, such as adding, deleting, modifying, and inquiring.
[0123] In actual application, the function information of the function, the context information of the calling function, and the function call information can be displayed and stored. When stored, the storage can be in JavaScript Object Notation (JSON) format, a relational database format, or a graph database format, which is selected according to actual conditions, and the embodiments of the present specification do not make any limitation in this regard.
[0124] By applying the scheme of the embodiments of the present specification, the function call graph is split with any calling function as a root node to obtain the function call tree of the calling function, so that the function call tree is more detailed and accurate, and the context information of the calling function is further determined according to the function call tree of the calling function, thereby improving the accuracy and comprehensiveness of the context information.
[0125] Referring to FIG. 4, FIG. 4 shows a schematic diagram of a function call graph according to an embodiment of the present specification. As shown in FIG. 4, the function call graph is constructed with 15 functions (function 1, function 2, function 3, …, function 15) as nodes and the function call relationship (solid single arrow shown in FIG. 4) between the 15 functions as edges. Referring to FIG. 5, FIG. 5 shows a schematic diagram of a function call tree according to an embodiment of the present specification. With function 4 as a root node, all other functions called by function 4 in the function call graph shown in FIG. 4 are recursively traversed to obtain the function call tree shown in FIG. 5. The function call tree includes one root node (function 4), four child nodes (function 5, function 6, function 7, and function 8), and three leaf nodes (function 9, function 10, and function 11).
[0126] In an optional embodiment of the present specification, the above step of hierarchically traversing the function call tree of the calling function to determine the context information of the calling function can include the following steps:
[0127] hierarchically traversing the function call tree of the calling function to determine the child nodes of the calling function;
[0128] in the case where the child node is a leaf node, inputting the function information of the child node into the code processing model to obtain the context information of the calling function;
[0129] in the case where the child node is a non-leaf node, inputting the function information of the child node, the function call information of the child node, and the context information of the child node into the code processing model to obtain the context information of the calling function.
[0130] It should be noted that the leaf node is a terminal node in the function call tree, and the leaf node has no child node. The non-leaf node is a node other than the leaf node in the function call tree. Taking the function call tree shown in FIG. 5 as an example, assuming that the calling function is function 4, the child nodes of function 4 are function 5 and function 6.
[0131] In actual applications, in the case that the child node of the calling function is a leaf node, it is indicated that the child node does not call other functions, and is a non-calling function. At this time, the function information of the child node can be input into the code processing model to obtain function description information of the child node, and the function description information of the child node is determined as the context information of the calling function. In the case that the child node of the calling function is a non-leaf node, it is indicated that the child node calls other functions, and is a calling function. At this time, the function information of the child node, the function call information of the child node, and the context information of the child node can be input into the code processing model to obtain the function description information of the child node, and the function description information of the child node is determined as the context information of the calling function.
[0132] It should be noted that in the case that the child node is a non-leaf node, the context information of the child node also needs to be determined, and therefore, a bottom-up hierarchical traversal method can be used to determine the context information of the non-leaf node in the function call tree. When any node is traversed, it can be ensured that all child nodes of the node have been generated and stored with generated context information.
[0133] By applying the scheme of the embodiments of the present specification, a bottom-up hierarchical traversal method is used to generate function description information of each node, and the function description information is used as the context information of the parent node, so as to generate function description information of higher quality, and to realize gradual accumulation and generation of context information, and to ensure that each function node obtains comprehensive and rich context information.
[0134] In an optional embodiment of the present specification, when processing a large-scale code library, a problem that a node (such as a main function) calls a relatively large number of child nodes (such as sub-functions) can be encountered. Excessively redundant model input data (such as function information, context information, and function call information) can easily affect the output result of the code processing model and the result generation speed. Therefore, the model input data can be trimmed, that is, before the function information of the calling function, the context information of the calling function, and the function call information of the calling function are input into the code processing model to obtain first description information of the calling function, the following steps can also be included:
[0135] According to the function information of the calling function, the context information of the calling function, and the function call information of the calling function, the input length of the model input data is determined;
[0136] In the case that the input length is greater than the preset input length, the model input data is trimmed to obtain updated model input data;
[0137] The function information of the calling function, the context information of the calling function, and the function call information of the calling function are input into the code processing model to obtain first description information of the calling function, including:
[0138] input the updated model input data into the code processing model to obtain the first description information of the calling function.
[0139] It should be noted that the preset input length is determined according to the type of the code processing model, for example, the preset input length is 4096 tokens. In the case where the input length is greater than the preset input length, it means that the model input data is too long, which will affect the output result and result generation speed of the code processing model. At this time, the model input data can be pruned to obtain updated model input data, and the input length of the updated model input data is less than or equal to the preset input length.
[0140] In actual application, the model input data can be randomly pruned, but random pruning may result in poor quality and low effectiveness of the model input data. Therefore, while controlling the overall length of the model input data within a reasonable range, it is also necessary to ensure the quality and effectiveness of the input information. Therefore, a reasonable pruning strategy and sorting algorithm can be used to effectively filter important information in the model input data.
[0141] By applying the scheme of the embodiments of the present specification, in the case where the input length is greater than the preset input length, the model input data is pruned to obtain updated model input data, and the updated model input data is input into the code processing model to obtain the first description information of the calling function, thereby ensuring the length of the model input and improving the efficiency of the model generation.
[0142] In an optional embodiment of the present specification, the above pruning of the model input data in the case where the input length is greater than the preset input length to obtain the updated model input data can include the following steps:
[0143] In the case where the input length is greater than the preset input length, the child node of the calling function is determined according to the context information and the function calling information;
[0144] The priority of the child node is determined according to a node classification strategy, wherein the node classification strategy is based on at least one of code length, code calling frequency, code function, and code position;
[0145] The context information is pruned according to the priority to obtain the updated model input data.
[0146] It should be noted that since the code length directly affects the length of the model input data, the priority of the child node can be determined by using the code length-based node classification strategy, and the priority of the child node with shorter code length is higher than that of the child node with longer code length. Since the frequently called function is generally more important, the priority of the child node can be determined by using the code call frequency-based node classification strategy, and the priority of the child node with higher code call frequency is higher than that of the child node with lower code call frequency. For example, the more descendant nodes of a certain child node, the more functions involved in the child node, the higher the core degree, and the higher the corresponding priority, so the priority of the child node can be determined according to the code location-based node classification strategy. The priority of the child node with high code function and close relationship with the current analyzed function and important code function is high according to the code function-based node classification strategy. The code function can be determined by multiple dimensions of information such as function name, code comment, document comment, etc.
[0147] Exemplarily, the child nodes with more calling times and shorter code length can be ranked in front according to the code length and calling times of the child nodes, and the model input data is pruned according to the ranking result. At the same time, when pruning, the context information of the child node with high core degree can be preferentially retained. If the context information of a single child node is too long, only the important content of the function can be considered to be retained. For example, the function header and key logic are retained, the function description information generated by the model is retained, and the internal implementation details are omitted.
[0148] Optionally, after determining the priority of the child node according to the node classification strategy, the function call information can also be pruned, or the context information and the function call information can also be pruned at the same time, and the specific pruning manner is selected according to the actual situation, which is not limited by the embodiments of the present specification.
[0149] In actual application, the function call tree can be pruned according to the node classification strategy, starting from the node with high priority, and gradually adding to the model input data until the preset input length limit is reached. If it is found that the model input data exceeds the limit, the model input data can be dynamically adjusted. For example, some information of low-priority nodes is omitted, and only the most critical information is retained.
[0150] By applying the scheme of the embodiments of the present specification, the priority of the child node is distinguished by multiple dimensions, and the context information and / or function call information are pruned based on the priority to obtain updated model input data, which can effectively filter the information of a large number of child nodes, reduce the length of the model input data, ensure the quality and effectiveness of the model input data, and improve the efficiency of the model generation and the accuracy of the results.
[0151] The code task processing method provided in the specification will be further described below in combination with the application of the code task processing method in the code reading scenario as an example, with reference to FIG. 6. FIG. 6 is a flowchart of a code reading method according to an embodiment of the specification, which specifically includes the following steps:
[0152] Step 602: Obtain the to-be-processed code data of the code reading task.
[0153] Step 604: Search for the code reading information of the to-be-processed code data from the plurality of function description information, wherein the function description information includes the first description information of the calling function, the first description information is obtained by the code processing model based on the function information of the calling function, the context information of the calling function and the function call information of the calling function, and the function call information is obtained based on the syntax analysis of the source code file.
[0154] It should be noted that the code reading task refers to a task of analyzing, understanding, annotating and explaining the code. The code reading information is used to help developers better understand, analyze and improve the code. The code reading information includes code explanation information, code function information and code annotation information. The implementation manners of steps 602 and 604 are the same as those of steps 302 and 304, and thus the specification embodiment will not be described herein again.
[0155] By using the scheme of the specification embodiment, the first description information of the calling function is generated by the code processing model based on the function information, the context information and the function call information of the calling function, so that detailed and context-rich function description information can be generated for each calling function, the illusion of the code processing model is reduced, the accuracy of the code reading information is further improved, and a high-quality code reading task processing scheme based on the code processing model is implemented.
[0156] In an optional embodiment of the specification, the code reading method can also be used for a code writing task. After the above step of searching for the code reading information of the to-be-processed code data from the plurality of function description information, the following steps can be further included:
[0157] Input the code writing prompt information and the code reading information into the code processing model to obtain the target writing code output by the code processing model.
[0158] It should be noted that the code writing prompt information is used to guide the code processing model to perform code writing based on the code reading information to output the target writing code. The target writing code refers to the code generated based on the code reading information, such as new code meeting the code reading information or code data obtained by continuing or completing the to-be-processed code data. The code processing model can be a large model in the code field and has certain code processing capability.
[0159] In actual applications, the code writing prompt information, the code reading information, and the to-be-processed code data can be input into the code processing model to obtain the target written code output by the code processing model.
[0160] By using the code processing capability of the code processing model and based on the code reading information, the code writing is performed, so that the understanding of the to-be-processed code data by the code processing model is enhanced, and the accuracy of the target written code is further improved.
[0161] Referring to FIG. 7, FIG. 7 shows a flowchart of a code processing method according to an embodiment of the present specification, which specifically includes the following steps:
[0162] In step 702, a source code file is obtained, wherein the source code file includes a plurality of calling functions.
[0163] In step 704, the source code file is parsed to determine function calling information of the plurality of calling functions.
[0164] In step 706, the function information of the plurality of calling functions, the context information of the plurality of calling functions, and the function calling information of the plurality of calling functions are input into the code processing model to obtain first description information of the plurality of calling functions, respectively.
[0165] It should be noted that steps 702 to 706 are the same as the implementation manner of “obtaining a source code file, wherein the source code file includes a plurality of calling functions; parsing the source code file to determine function calling information of the calling functions; constructing a function calling tree of the calling functions according to the plurality of calling functions and the function calling information; hierarchically traversing the function calling tree of the calling functions to determine context information of the calling functions; inputting the function information of the calling functions, the context information of the calling functions, and the function calling information of the calling functions into a code processing model to obtain first description information of the calling functions” in the code task processing method shown in FIG. 3, and thus the present specification will not be described in detail.
[0166] According to the scheme of the present specification, by parsing the source code file to determine the function calling information of each calling function, the code processing model can understand the global information of the entire source code file, reduce the generation illusion of the code processing model, and further integrate the context information of the calling functions in the input of the code processing model, so that detailed and context-rich function description information in the form of natural language can be generated for each calling function, which is no longer limited to the display of calling relationship in a simple flowchart. Therefore, even a novice developer can quickly understand the code structure and logic, the learning curve and the code reading threshold are greatly reduced, the developer can quickly understand the unfamiliar code language and project, and thus the learning effect and the development efficiency are improved.
[0167] Referring to FIG. 8, FIG. 8 shows a process flow diagram of a code processing method provided by an embodiment of the present specification. As shown in FIG. 8, the process of the code processing method includes four stages of static code analysis, function call tree construction, tree node level traversal, and reading information generation. Next, the four stages will be described in detail respectively.
[0168] Static code analysis: obtaining a source code file; performing syntax analysis on the source code file to obtain a syntax structure diagram; traversing the syntax structure diagram to determine a plurality of calling functions in the source code file and function call relationships between the plurality of calling functions; and determining function call information of the plurality of calling functions respectively according to function information of the plurality of calling functions and the function call relationships;
[0169] Function call tree construction: constructing a function call graph with the plurality of calling functions as nodes and the function call relationships between the plurality of calling functions as edges; and splitting the function call graph with the calling functions as root nodes to obtain a function call tree of the calling functions;
[0170] Tree node level traversal: traversing the function call tree of the calling functions by using a bottom-up level traversal method, determining function description information of each node in the function call tree, and determining the function description information of a current node as context information of a parent node of the current node;
[0171] Reading information generation: determining an input length of model input data according to the function information of the calling functions, the context information of the calling functions, and the function call information of the calling functions; in a case where the input length is greater than a preset input length, performing cropping on the model input data to obtain updated model input data; and inputting the updated model input data into a code processing model to obtain reading information of the calling functions, wherein the reading information includes code explanation information, code comment information, and code action information.
[0172] By applying the scheme of the embodiments of the present specification, static code analysis and a code processing model are combined, a bottom-up level traversal method is used to generate detailed and context-rich function description information for each function, the generation of model hallucinations is effectively reduced, code information of the entire code repository is generated, and developers can read conveniently.
[0173] Corresponding to the above code task processing method embodiments, the present specification also provides code task processing device embodiments. FIG. 9 shows a structural schematic diagram of a code task processing device provided by an embodiment of the present specification.
[0174] As shown in FIG. 9, the device includes:
[0175] A first obtaining module 902 configured to obtain to-be-processed code data of a target code task;
[0176] The first searching module 904 is configured to search the task processing result of the code data to be processed from a plurality of function description information, wherein the function description information comprises the first description information of the calling function, the first description information is obtained by the code processing model based on the function information of the calling function, the context information of the calling function and the function call information of the calling function, and the function call information is obtained based on the syntax analysis on the source code file.
[0177] Optionally, the function description information further comprises the second description information of the non-calling function; and the device further comprises a first processing module configured to input the function information of the non-calling function into the code processing model to obtain the second description information of the non-calling function.
[0178] Optionally, the device further comprises a fourth obtaining module configured to obtain the source code file, wherein the source code file comprises a plurality of calling functions; perform syntax analysis on the source code file to determine the function call information of the calling function; construct a function call tree of the calling function according to the plurality of calling functions and the function call information; hierarchically traverse the function call tree of the calling function to determine the context information of the calling function; and input the function information of the calling function, the context information of the calling function and the function call information of the calling function into the code processing model to obtain the first description information of the calling function.
[0179] Optionally, the fourth obtaining module is further configured to perform syntax analysis on the source code file to obtain a syntax structure graph, wherein the syntax structure graph is constructed by taking syntax elements in the source code file as nodes and taking relationships between the syntax elements as edges; traverse the syntax structure graph to determine the calling functions and the function call relationship of the calling functions; and determine the function call information of the calling functions according to the function information of the calling functions and the function call relationship.
[0180] Optionally, the fourth obtaining module is further configured to construct a function call graph of the source code file by taking a plurality of calling functions of the source code file as nodes and taking the function call relationship of the calling functions as edges; and for any calling function, take the calling function as a root node, split the function call graph to obtain the function call tree of the calling function.
[0181] Optionally, the fourth obtaining module is further configured to hierarchically traverse the function call tree of the calling function to determine the child nodes of the calling function; in a case where the child nodes are leaf nodes, input the function information of the child nodes into the code processing model to obtain the context information of the calling function; and in a case where the child nodes are non-leaf nodes, input the function information of the child nodes, the function call information of the child nodes and the context information of the child nodes into the code processing model to obtain the context information of the calling function.
[0182] Optionally, the apparatus further comprises a clipping module configured to determine an input length of the model input data according to function information of the calling function, context information of the calling function, and function call information of the calling function; clip the model input data to obtain updated model input data in a case where the input length is greater than a preset input length; and a fourth obtaining module further configured to input the updated model input data into the code processing model to obtain the first description information of the calling function.
[0183] Optionally, the clipping module is further configured to determine a child node of the calling function according to the context information and the function call information in a case where the input length is greater than the preset input length; determine a priority of the child node according to a node classification strategy, wherein the node classification strategy is based on at least one of code length, code call frequency, code function, and code location; and clip the context information according to the priority to obtain the updated model input data.
[0184] Optionally, the function description information carries an information identifier; and the first searching module 904 is further configured to determine target function description information from the plurality of function description information according to a data identifier of the to-be-processed code data, wherein the information identifier of the target function description information is the same as the data identifier; and extract a task processing result of the to-be-processed code data from the target function description information according to the target code task.
[0185] By using the scheme of the embodiment of the present specification, the first description information of the calling function is generated by the code processing model according to the function information, the context information, and the function call information of the calling function, so that detailed and context-rich function description information can be generated for each calling function, the illusion of the code processing model is reduced, and the accuracy of the task processing result is further improved.
[0186] The above is a schematic scheme of the code task processing apparatus of the embodiment. It should be noted that the technical scheme of the code task processing apparatus and the technical scheme of the code task processing method described above belong to the same concept, and the details of the technical scheme of the code task processing apparatus that are not described in detail can be referred to the description of the technical scheme of the code task processing method.
[0187] Corresponding to the code reading method embodiments described above, the present specification also provides code reading apparatus embodiments. FIG. 10 shows a structural schematic diagram of a code reading apparatus according to an embodiment of the present specification. As shown in FIG. 10, the apparatus comprises:
[0188] A second obtaining module 1002 configured to obtain to-be-processed code data of a code reading task;
[0189] The second searching module 1004 is configured to search code reading information of the code data to be processed from a plurality of function description information, wherein the function description information comprises first description information of the calling function, and the first description information is obtained by the code processing model based on function information of the calling function, context information of the calling function and function call information of the calling function, and the function call information is obtained based on syntax analysis on the source code file.
[0190] Optionally, the apparatus further comprises a second processing module configured to input the code writing prompt information and the code reading information into the code processing model to obtain target writing code output by the code processing model.
[0191] By using the scheme of the embodiment of the present specification, the first description information of the calling function is generated based on the function information, the context information and the function call information of the calling function by using the code processing model, so that detailed and context-rich function description information can be generated for each calling function, the illusion of the code processing model is reduced, the accuracy of the code reading information is further improved, and the high-quality code reading task processing scheme based on the code processing model is implemented.
[0192] The above is a schematic scheme of the code reading apparatus of the embodiment. It should be noted that the technical scheme of the code reading apparatus belongs to the same concept as the technical scheme of the code reading method described above, and the details of the technical scheme of the code reading apparatus which are not described in detail can be referred to the description of the technical scheme of the code reading method.
[0193] Corresponding to the code processing method embodiment described above, the present specification also provides a code processing apparatus embodiment, and FIG. 11 shows a structural schematic diagram of a code processing apparatus according to an embodiment of the present specification. As shown in FIG. 11, the apparatus comprises:
[0194] The third obtaining module 1102 is configured to obtain a source code file, wherein the source code file comprises a plurality of calling functions;
[0195] The parsing module 1104 is configured to perform syntax analysis on the source code file to determine function call information of the plurality of calling functions respectively;
[0196] The input module 1106 is configured to input function information of the plurality of calling functions, context information of the plurality of calling functions and the function call information of the plurality of calling functions into the code processing model to obtain first description information of the plurality of calling functions respectively.
[0197] By applying the scheme of the embodiments of the present specification, the function call information of each calling function is determined by performing syntax analysis on the source code file, so that the code processing model can understand the global information of the entire source code file, reduce the generation illusion of the code processing model, and integrate the context information of the calling function in the input of the code processing model, so as to generate detailed and context-rich function description information for each calling function, help developers quickly understand unfamiliar code languages and projects, thereby improving learning effect and improving development efficiency.
[0198] The above is a schematic scheme of a code processing device according to an embodiment of the present specification. It should be noted that the technical scheme of the code processing device belongs to the same concept as the technical scheme of the code processing method described above, and the details of the technical scheme of the code processing device that are not described in detail can be referred to the description of the technical scheme of the code processing method.
[0199] FIG. 12 shows a structural block diagram of a computing device according to an embodiment of the present specification. The components of the computing device 1200 include, but are not limited to, a memory 1210 and a processor 1220. The processor 1220 is connected to the memory 1210 through a bus 1230, and a database 1250 is used to save data.
[0200] The computing device 1200 further includes an access device 1240, which enables the computing device 1200 to communicate via one or more networks 1260. Examples of these networks include the public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 1240 can include one or more of any type of network interface (e.g., network interface card (NIC)) such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a worldwide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, etc.
[0201] In an embodiment of the present specification, the above-mentioned components of the computing device 1200 and other components not shown in FIG. 12 can also be connected to each other, for example, by a bus. It should be understood that the computing device structure block diagram shown in FIG. 12 is merely for the purpose of example, and is not a limitation on the scope of the present specification. Other components can be added or replaced by those skilled in the art as needed.
[0202] The computing device 1200 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 1200 can also be a mobile or stationary server.
[0203] The processor 1220 is configured to execute computer programs / instructions that implement the steps of the above-mentioned code task processing method or code reading method or code processing method when executed by the processor.
[0204] The above is a schematic scheme of the computing device of the present embodiment. It should be noted that the technical scheme of the computing device belongs to the same concept as the technical schemes of the above-mentioned code task processing method, code reading method and code processing method, and the details of the technical scheme of the computing device that are not described in detail can be referred to the description of the technical scheme of the above-mentioned code task processing method or code reading method or code processing method.
[0205] An embodiment of the present specification also provides a computer readable storage medium storing computer programs / instructions that implement the steps of the above-mentioned code task processing method or code reading method or code processing method when executed by the processor.
[0206] The above is a schematic scheme of the computer readable storage medium of the present embodiment. It should be noted that the technical scheme of the storage medium belongs to the same concept as the technical schemes of the above-mentioned code task processing method, code reading method and code processing method, and the details of the technical scheme of the storage medium that are not described in detail can be referred to the description of the technical scheme of the above-mentioned code task processing method or code reading method or code processing method.
[0207] An embodiment of the present specification also provides a computer program product comprising computer programs / instructions that implement the steps of the above-mentioned code task processing method or code reading method or code processing method when executed by the processor.
[0208] The above is a schematic solution of a computer program product of the embodiment. It should be noted that the technical solution of the computer program product and the technical solutions of the code task processing method, the code reading method, and the code processing method described above belong to the same concept. The technical solution of the computer program product is not described in detail, and the description of the technical solution of the code task processing method or the code reading method or the code processing method can be referred to.
[0209] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different than the order in which they are recited in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying drawings do not necessarily require the particular order shown or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous or possible.
[0210] The computer instructions include computer program code, which can be in the form of source code, object code, executable code, or some intermediate form. The computer-readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0211] It should be noted that for the foregoing method embodiments, in order to facilitate description, they are all expressed as a combination of a series of actions, but those skilled in the art should know that the embodiments of the present specification are not limited by the order of the described actions, because according to the embodiments of the present specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily all necessary for the embodiments of the present specification.
[0212] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0213] The preferred embodiments of the present specification disclosed above are only used to help explain the present specification. Alternative embodiments do not describe all the details and limit the present application to the specific embodiments described. Obviously, many modifications and variations of the embodiments of the present specification can be made in light of the content of the present specification. The present specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of the present specification, so that those skilled in the art can well understand and utilize the present specification. The present specification is limited only by the claims and their full scope and equivalents.
Claims
1. A method for processing a code task, comprising: obtaining to-be-processed code data of a target code task; finding a task processing result of the to-be-processed code data from a plurality of function description information, wherein the function description information comprises first description information of a calling function, the first description information being obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, the function call information being obtained based on syntax analysis of a source code file.
2. The method of claim 1, wherein the obtaining to-be-processed code data of a target code task comprises: in response to an operation of a client on the to-be-processed code data, obtaining to-be-processed code data of the target code task.
3. The method of claim 1, wherein the function description information further comprises second description information of a non-calling function; and the method further comprises, before the finding a task processing result of the to-be-processed code data from a plurality of function description information: inputting function information of the non-calling function into the code processing model to obtain the second description information of the non-calling function.
4. The method of claim 1, wherein the finding a task processing result of the to-be-processed code data from a plurality of function description information further comprises: obtaining a source code file, wherein the source code file comprises a plurality of calling functions; performing syntax analysis on the source code file to determine function call information of the calling functions; constructing a function call tree of the calling functions according to the plurality of calling functions and the function call information; hierarchically traversing the function call tree of the calling functions to determine context information of the calling functions; inputting function information of the calling functions, context information of the calling functions, and function call information of the calling functions into the code processing model to obtain the first description information of the calling functions.
5. The method of claim 4, wherein the performing syntax analysis on the source code file to determine function call information of the calling functions comprises: performing syntax analysis on the source code file to obtain a syntax structure graph, wherein the syntax structure graph is constructed with syntax elements in the source code file as nodes and relationships between the syntax elements as edges; traversing the syntax structure graph to determine the calling functions and function call relationships of the calling functions; determining function call information of the calling functions according to function information of the calling functions and the function call relationships.
6. The method of claim 4 or 6, wherein the constructing a function call tree of the calling functions according to the plurality of calling functions and the function call information comprises: constructing a function call graph of the source code file with the plurality of calling functions of the source code file as nodes and function call relationships of the calling functions as edges; for any calling function, taking the calling function as a root node, splitting the function call graph to obtain a function call tree of the calling function. 7. The method of any one of claims 4-6, wherein traversing the function call tree of the calling function hierarchically to determine the context information of the calling function comprises: traversing the function call tree of the calling function hierarchically to determine a child node of the calling function; in a case where the child node is a leaf node, inputting function information of the child node into the code processing model to obtain the context information of the calling function; and in a case where the child node is a non-leaf node, inputting function information of the child node, function call information of the child node, and context information of the child node into the code processing model to obtain the context information of the calling function.
8. The method of claim 7, wherein in a case where the child node of the calling function is a leaf node, function description information of the child node is obtained by inputting function information of the child node into the code processing model, and the function description information of the child node is determined as the context information of the calling function; and in a case where the child node of the calling function is a non-leaf node, function description information of the child node is obtained by inputting function information of the child node, function call information of the child node, and context information of the child node into the code processing model, and the function description information of the child node is determined as the context information of the calling function.
9. The method of any one of claims 4-7, wherein prior to inputting the function information of the calling function, the context information of the calling function, and the function call information of the calling function into the code processing model to obtain the first description information of the calling function, the method further comprises: determining an input length of model input data according to the function information of the calling function, the context information of the calling function, and the function call information of the calling function; in a case where the input length is greater than a preset input length, cropping the model input data to obtain updated model input data; and inputting the updated model input data into the code processing model to obtain the first description information of the calling function.
10. The method of claim 9, wherein in a case where the input length is greater than a preset input length, the model input data is cropped to obtain updated model input data by: determining a child node of the calling function according to the context information and the function call information; determining a priority of the child node according to a node classification strategy, wherein the node classification strategy is based on at least one of code length, code call frequency, code function, and code location; and cropping the context information according to the priority to obtain the updated model input data. 11. The method of claim 10, after determining the priority of the child node according to the node classification strategy, further comprising: trimming the function call information; or trimming the context information and the function call information.
12. The method of any one of claims 1-11, the function description information carries an information identifier; the searching, from the plurality of function description information, the task processing result of the to-be-processed code data, comprises: determining, according to a data identifier of the to-be-processed code data, a target function description information from the plurality of function description information, wherein the information identifier of the target function description information is the same as the data identifier; and extracting, according to the target code task, the task processing result of the to-be-processed code data from the target function description information.
13. The method of claim 12, the target function description information comprises function explanation information, function role information, and function annotation information; if the target code task is a code reading task, the function explanation information, the function role information, and the function annotation information are determined as the task processing result of the to-be-processed code data; if the target code task is a code explanation task, the function explanation information is determined as the task processing result of the to-be-processed code data.
14. A code reading method, comprising: obtaining to-be-processed code data of a code reading task; searching, from a plurality of function description information, code reading information of the to-be-processed code data, wherein the function description information comprises first description information of a calling function, the first description information is obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, and the function call information is obtained based on syntax analysis of a source code file.
15. The method of claim 14, after the searching, from the plurality of function description information, the code reading information of the to-be-processed code data, further comprising: inputting code writing prompt information and the code reading information into the code processing model to obtain target written code output by the code processing model.
16. A code processing method, comprising: obtaining a source code file, wherein the source code file comprises a plurality of calling functions; performing syntax analysis on the source code file to determine function call information of the plurality of calling functions respectively; inputting function information of the plurality of calling functions, context information of the plurality of calling functions, and the function call information of the plurality of calling functions into a code processing model to obtain first description information of the plurality of calling functions respectively.
17. A code task processing system, comprising a client and a server; the client is configured to send to-be-processed code data of a target code task to the server; The server is configured to search for a task processing result of the to-be-processed code data from a plurality of function description information, wherein The function description information includes first description information of a calling function, the first description information being obtained by a code processing model based on function information of the calling function, context information of the calling function, and function call information of the calling function, the function call information being obtained based on syntax analysis on a source code file. 18.A computing device, comprising: a memory and a processor; the memory is configured to store computer programs / instructions, and the processor is configured to execute the computer programs / instructions, which, when executed by the processor, implement the steps of the method in any one of claims 1 to 13 or in any one of claims 14 to 15 or in claim 16. 19.A computer readable storage medium storing computer programs / instructions, which, when executed by a processor, implement the steps of the method in any one of claims 1 to 13 or in any one of claims 14 to 15 or in claim 16. 20.A computer program product comprising computer programs / instructions, which, when executed by a processor, implement the steps of the method in any one of claims 1 to 13 or in any one of claims 14 to 15 or in claim 16.
Citation Information
Patent Citations
Code identification method and device, equipment and storage medium
CN113282293A
Source code analysis method and device, electronic equipment and storage medium
CN116303013A
SAST analysis method and device for source code, equipment and medium
CN118656824A
Automatic generation of code documentation
US20210357210A1