Program call graph-based code generation method and device, electronic equipment and storage medium

By building a program call diagram in multiple code files and selecting code files related to the current code, the problem of completion accuracy and comprehensiveness in the existing information completion method is solved, and more efficient information completion is achieved.

CN119440482APending Publication Date: 2025-02-14BEIJING GUIXIN TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411250045.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

The existing information completion methods mainly rely on the content in the current file, resulting in the limitation of the accuracy and comprehensiveness of the completion.

Method used

By building a program call diagram, select and call code files related to the current code from multiple code files to determine the subsequent code content of the current code.

Benefits of technology

It improves the accuracy and comprehensiveness of information completion, ensures that the called code file has strong correlation with the current code, and improves the accuracy of the call.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440482A_ABST
    Figure CN119440482A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method and device based on a program call graph, electronic equipment and a storage medium, and relates to the technical field of intelligent software development. The method comprises the steps that a received input current code is responded, a code file related to the current code is selected and called from a plurality of code files by calling a relation graph, and the calling relation graph exists in a computer program; and generating subsequent code contents of the current code according to at least one code file in the code files and the current code file of the current code. By calling the relation graph, it can be ensured that the called code file has high correlation with the current code, and the calling accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of intelligent software development, and in particular to a method, device, electronic device and storage medium for generating code based on a program call graph. Background Art

[0002] With the development of deep learning and big model technology, more and more people are beginning to use big model technology to complete information, that is, to generate subsequent information based on existing information. The information here can be text or code, for example.

[0003] The current problem is that most existing information completion only completes subsequent code based on the content of the current file, which often limits the accuracy and comprehensiveness of the completion. Summary of the invention

[0004] In view of this, the purpose of the present disclosure is to propose a code generation method, device, electronic device and storage medium based on a program call graph, and the present disclosure can solve the existing problems in a targeted manner.

[0005] Based on the above-mentioned purpose, in a first aspect, the present disclosure proposes a code generation method based on a program call graph, comprising: in response to receiving a current code input, selecting and calling a code file related to the current code from multiple code files through a call relationship graph; determining the subsequent code content of the current code based on at least one code file among the code files and the current code file of the current code.

[0006] In the second aspect, a code generation device based on a program call graph is also provided, including: a calling unit, configured to select and call a code file related to the current code from multiple code files through a call relationship graph in response to receiving a current code input; a determination unit, configured to determine the subsequent code content of the current code based on at least one code file among the code files and a current code file of the current code.

[0007] According to a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect.

[0008] According to a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and the computer program is executed by a processor to implement any method described in the first aspect.

[0009] In a fifth aspect, a computer program product is also provided, including a computer program, wherein the computer program is executed by a processor to implement any method described in the first aspect.

[0010] In general, the present disclosure has at least the following beneficial effects: code files related to the current code can be generated and recommended to users as subsequent code content, thereby improving the accuracy and comprehensiveness of information completion. Through the call relationship graph, it can be ensured that the called code files have a strong correlation with the current code, thereby improving the accuracy of the call. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments disclosed in accordance with the present disclosure and should not be regarded as limiting the scope of the present disclosure.

[0012] Figure 1 A flowchart of a method for generating code based on a program call graph according to an embodiment of the present disclosure is shown;

[0013] Figure 2 Another flow chart of a method for generating code based on a program call graph according to an embodiment of the present disclosure is shown;

[0014] Figure 3 A schematic diagram of a code generation device based on a program call graph according to an embodiment of the present disclosure is shown;

[0015] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure is shown;

[0016] Figure 5 A schematic diagram of a storage medium provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0017] The present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.

[0018] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0019] Figure 1 The code generation method based on the program call graph of the present disclosure is shown. In an embodiment of the present disclosure, the method includes:

[0020] Step S101 , in response to receiving an input current code, selecting and calling a code file related to the current code from a plurality of code files through a call relationship graph, wherein the call relationship graph exists in a computer program.

[0021] In this embodiment, the execution subject of the code generation method based on the program call graph can call a code file related to the current code in multiple code files in response to receiving the input current code through the call graph. For example, the current code can be the code input by the user. Through the call graph, the code file related to the code can be called. The code file is a file containing the above information.

[0022] The call relationship graph is used to find a code file having a call relationship with the current code through the current code input by the user.

[0023] Step S102: Generate subsequent code content of the current code according to at least one code file among the code files and the current code file of the current code.

[0024] In this embodiment, the execution subject may generate subsequent code content of the current code according to the current code file of the current code and at least one called code file to complete the current code.

[0025] The execution subject may determine the subsequent code content of the current code according to at least one of the code files and the current code file of the current code in various ways. For example, the execution subject may determine the subsequent code content corresponding to at least one of the code files and the current code file of the current code through a mapping relationship, and determine the subsequent code content as the subsequent code content of the current code.

[0026] The completed content can be transmitted to a display, and the subsequent code content can be displayed to the personnel, prompting the personnel to write the subsequent code content.

[0027] This embodiment can recommend code files related to the current code to the user as subsequent code content, avoiding the singleness of the recommended subsequent code content and improving the accuracy and comprehensiveness of information completion. Through the call relationship graph, it can be ensured that the called code file has a strong correlation with the current code, improving the accuracy of the call.

[0028] In some optional implementations of any embodiment of the present disclosure, determining the subsequent code content of the current code based on at least one code file among the code files and the current code file of the current code includes: inputting at least one code file among the code files and the current code file of the current code into an information completion model to obtain the subsequent code content of the current code.

[0029] In these optional implementations, the execution subject may input the at least one code file and the current code file into the information completion model, and may obtain the output of the information completion model, which is the subsequent code content of the current code.

[0030] The information completion model here can be any model that can predict subsequent code content through the above at least one code file and the current code file. For example, the model can be a natural language model.

[0031] These implementations can accurately predict the subsequent code content of the current code through the information completion model. In addition, by using the model for prediction, the accuracy and stability of information correction can be effectively improved. Models often have limited input lengths and cannot accept inputs that are too long. These implementations avoid the problem of too many files being input into the model, which will slow down the output speed of the model.

[0032] In some optional implementations of any embodiment of the present disclosure, the step of inputting at least one of the code files and the current code file of the current code into an information completion model to obtain subsequent code content of the current code includes: inputting at least one of the code files and the current code file into an information completion model to generate a first basic data unit, wherein the duration of generating the first basic data unit is less than a preset duration.

[0033] In these optional implementations, when the information completion model processes the code file, a basic data unit token is generated. If too many code files are input, it will take too long to generate the first token, and the user will have to wait for a long time, making the system unable to meet the actual needs of the user.

[0034] These implementations call code files related to the current code to find the input models of various code files related to the subsequent code content of the current code, which not only helps to improve the comprehensiveness and accuracy of the input, but also avoids the problem of users waiting too long.

[0035] In some optional implementations of any embodiment of the present disclosure, the call relationship graph is used to indicate code files related to the code file that can be called through the code file; calling the code files related to the current code in multiple code files through the call relationship graph includes: determining the current code file where the current code is located; calling the code files related to the current code file in multiple code files through the call relationship graph.

[0036] In these optional implementations, the call relationship graph indicates the code files related to the code file, that is, indicates the call relationship between the current file and the related code files. The above execution subject can call the code files related to the current code file through the call relationship graph.

[0037] These implementations can accurately and efficiently call other code files related to the current code file through a call relationship graph.

[0038] In some optional implementations of any embodiment of the present disclosure, the method further includes: determining at least one code file among the called code files in descending order of relevance to the current code file.

[0039] In these implementations, the execution subject may find a preset number of code files, such as 10 code files, as the at least one code file according to the correlation between the called code file and the current code file.

[0040] These implementations determine the code files in descending order of relevance, and can find the code files that are most relevant to the current code file, thereby improving the accuracy of the determined code files and helping to improve the accuracy of information completion.

[0041] like Figure 2 As shown, the training steps of the information completion model include: step S201, obtaining a call relationship graph between each code file in the multiple code files; step S202, selecting a code file related to the current code file of the current code, determining each code file related to the call relationship graph, and generating a training sample of the current code file from the each code file; step S203, using the training sample to train the information completion model to be trained to obtain a trained information completion model.

[0042] In these optional implementations, the model training step may include obtaining a call relationship graph, selecting a code file related to the current code file, and calling a code file list to determine each code file related to the current code file in the call relationship graph as a training sample of the current code file. In this way, the above-mentioned execution subject can use the training sample to train the information completion model to be trained to obtain a trained information completion model.

[0043] These implementations can determine the calling relationship between the current code file and other code files through a calling relationship graph, thereby obtaining training samples of the information completion model to implement training of the information completion model.

[0044] In some optional implementations of any one of the embodiments of the present disclosure, obtaining the calling relationship graph between each code file in the multiple code files includes: determining each code file in the source code project as the multiple code files; and performing static analysis on each code file in the multiple code files to obtain the calling relationship graph between the each code files.

[0045] In these optional implementations, the execution subject may select a software project with a large amount of software source code, that is, determine the various code files in the software project with the source code as multiple code files. Afterwards, the execution subject may perform static analysis on the source code files in each software project to obtain a call relationship graph between the various code files.

[0046] These implementations can access software projects with massive amounts of source code, allowing for the creation of larger data samples and helping to obtain more accurate models.

[0047] In some optional implementations of any one of the embodiments of the present disclosure, determining the relevant code files in the call relationship graph as training samples of the current code file includes: determining the relevant code files in the call relationship graph as the context of the current code file, and obtaining a training sample including the current code file and the context.

[0048] In these implementations, the execution subject may determine each code file related to the current code file in the call relationship graph as the context of the current code file, thereby obtaining a training sample including the current code file and the context.

[0049] In addition, in the process of determining the subsequent code content by the information completion model, the called code file can also be used as the context of the current file for prediction to obtain the subsequent code content of the current code.

[0050] These implementations may use various code files related to the current code file as the context of the current code file to train the information completion model.

[0051] The embodiment of the present disclosure provides a code generation device based on a program call graph, and the device is used to execute the code generation method based on a program call graph described in the above embodiment, such as Figure 3 As shown, the device includes: a calling unit 301, which is configured to select and call a code file related to the current code from multiple code files through a calling relationship graph in response to receiving an input current code, and the calling relationship graph exists in a computer program; a determining unit 302, which is configured to generate subsequent code content of the current code based on at least one code file in the code files and a current code file of the current code.

[0052] The program call graph-based code generation device provided in the above-mentioned embodiment of the present disclosure and the program call graph-based code generation method provided in the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.

[0053] The embodiment of the present disclosure also provides an electronic device corresponding to the method for generating code based on a program call graph provided in the above embodiment, so as to execute the above method for generating code based on a program call graph. The embodiment of the present disclosure is not limited.

[0054] Please refer to Figure 4 , which shows a schematic diagram of an electronic device provided by some embodiments of the present disclosure. Figure 4 As shown, the electronic device 40 includes: a processor 400, a memory 401, a bus 402 and a communication interface 403, and the processor 400, the communication interface 403 and the memory 401 are connected via the bus 402; the memory 401 stores a computer program that can be run on the processor 400, and the processor 400 executes the method provided in any of the aforementioned embodiments of the present disclosure when running the computer program.

[0055] The memory 401 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 403 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0056] The bus 402 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 401 is used to store programs, and the processor 400 executes the program after receiving an execution instruction. The code generation method based on the program call graph disclosed in any implementation of the aforementioned embodiment of the present disclosure may be applied to the processor 400, or implemented by the processor 400.

[0057] The processor 400 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 400 or the instruction in the form of software. The above processor 400 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 401, and the processor 400 reads the information in the memory 401 and completes the steps of the above method in combination with its hardware.

[0058] The electronic device provided by the embodiment of the present disclosure and the code generation method based on the program call graph provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by them.

[0059] The present disclosure also provides a computer-readable storage medium corresponding to the method for generating code based on a program call graph provided in the above embodiment. Figure 5 The computer-readable storage medium shown is a CD 50 on which a computer program (ie, a program product) is stored. When the computer program is executed by a processor, the code generation method based on the program call graph provided in any of the aforementioned embodiments will be executed.

[0060] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.

[0061] The computer-readable storage medium provided by the above-mentioned embodiments of the present disclosure and the code generation method based on the program call graph provided by the embodiments of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.

[0062] It should be noted that:

[0063] In the above text, the term "comprises", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be noted that the scope of the method and device in the embodiments of the present disclosure is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0064] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present disclosure, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present disclosure.

[0065] The embodiments of the present disclosure are described above in conjunction with the accompanying drawings, which are only specific implementation modes of the present disclosure. However, the present disclosure is not limited to the above-mentioned specific implementation modes. The above-mentioned specific implementation modes are merely illustrative and not restrictive. Under the guidance of the present disclosure, ordinary technicians in this field can also make many forms without departing from the purpose of the present disclosure and the scope of protection of the claims, all of which are within the protection of the present disclosure.

Claims

1. A code generation method based on a program call graph, characterized in that: include: In response to receiving the input current code, selecting and calling a code file related to the current code from a plurality of code files through a call relationship graph, wherein the call relationship graph exists in a computer program; Generate subsequent code content of the current code according to at least one of the code files and a current code file of the current code.

2. The method according to claim 1, characterized in that The determining, based on at least one of the code files and a current code file of the current code, subsequent code content of the current code comprises: At least one of the code files and a current code file of the current code are input into an information completion model to obtain subsequent code content of the current code.

3. The method according to claim 1, characterized in that The step of inputting at least one of the code files and a current code file of the current code into an information completion model to obtain subsequent code content of the current code includes: At least one of the code files and the current code file are input into an information completion model to generate a first basic data unit, wherein a duration of generating the first basic data unit is less than a preset duration.

4. The method according to claim 1, characterized in that The call relationship graph is used to indicate code files related to the code file that can be called by the code file; The calling of the code files related to the current code in the multiple code files by calling the relationship graph includes: Determine the current code file where the current code is located; By calling the relationship graph, a code file related to the current code file is called from multiple code files.

5. The method according to claim 1, characterized in that The method further comprises: At least one code file is determined in the called code files in descending order of relevance to the current code file.

6. The method according to claim 1, characterized in that The training steps of the information completion model include: Obtain a call relationship graph between each of the multiple code files; Selecting a code file related to a current code file of a current code, determining each code file related to the call relationship graph, and generating a training sample of the current code file from each code file; The information completion model to be trained is trained using the training samples to obtain a trained information completion model.

7. The method according to claim 6, characterized in that The obtaining of a call relationship graph between each of the plurality of code files comprises: Determine code files in the source code project as the multiple code files; Static analysis is performed on each of the multiple code files to obtain a call relationship graph between the code files.

8. The method according to claim 6, characterized in that The determining of the relevant code files in the call relationship graph and generating the training sample of the current code file from the relevant code files comprises: Relevant code files in the call relationship graph are determined as contexts of the current code file, and a training sample including the current code file and the context is obtained.

9. A code generation device based on a program call graph, characterized in that: include: A calling unit, configured to select and call a code file related to the current code from a plurality of code files through a call relationship graph in response to receiving the input current code, wherein the call relationship graph exists in the computer program; The determining unit is configured to generate subsequent code content of the current code according to at least one code file among the code files and a current code file of the current code.

Citation Information

Patent Citations

  • Sample construction method, code generation method, electronic equipment and storage medium

    CN117556263A

  • Code generation method and device based on cloud service

    CN118092923A

Cited By

  • Project-level code generation method and device based on file sorting, computer equipment and storage medium

    CN121116264A