Source code location method, system, medium and device

By obtaining and using the historical location and keyword information in the database records, the search scope is gradually expanded to locate the source code to be located in the source code file, which solves the database update problem caused by inaccurate code positioning and file changes in the UNIX environment, and achieves Efficient source code location.

CN112699253BActive Publication Date: 2024-10-01GUANGZHOU CAIYI TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201911012598.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-10-23
Publication Date
2024-10-01
Estimated Expiration
2039-10-23

AI Technical Summary

Technical Problem

In a UNIX environment, the source code location through the code location program is inaccurate, or the source code file has been modified, causing the database record to be updated before the source code can be located again.

Method used

By obtaining the records of the source code to be located in the database, including historical location information and keyword information, using the method of gradually expanding the search scope to find the source code to be located in the source code file based on regular matching until its location is found, and after finding it Update database records.

Benefits of technology

Without the need to update the database, accurate source code positioning is achieved, search efficiency is improved, and positioning failures caused by changes in source code files are avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112699253B_ABST
    Figure CN112699253B_ABST
Patent Text Reader

Abstract

The present invention provides a source code location method, system, medium and device, the method comprising the following steps: obtaining a record of a source code to be located in a database, the record comprising historical position information and keyword information of a source code file where the source code to be located is located; searching for the source code to be located in the source code file where the source code to be located is located by gradually expanding the search range based on the historical position information and the keyword information. The source code location method, system, medium and device of the present invention are used to facilitate source code location without updating the database when the source code location is inaccurately located by a code location program, or the source code file has been modified so that the record in the database needs to be updated before location can be performed again.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of source code location technology, and in particular to a source code location method, system, medium and device. Background Art

[0002] In the UNIX environment, when reading code, sometimes the source code location is not accurate through the code location program, or the source code file has been modified, resulting in the need to update the database record before the source code location can be performed again. Simple solutions are proposed for the above two problems.

[0003] Therefore, it is hoped that the problem of inaccurate source code location through a code location program or source code files being modified, which results in the need to update database records before source code location can be performed again, can be solved. Summary of the invention

[0004] In view of the above-mentioned shortcomings of the prior art, the purpose of the present invention is to provide a source code location method, system, medium and device, which are used to solve the problem in the prior art that source code location is inaccurate through code location program, or the source code file has been modified, resulting in the need to update the database record before source code location can be performed again.

[0005] To achieve the above-mentioned purpose and other related purposes, the present invention provides a source code locating method, comprising the following steps: obtaining a record of a source code to be located in a database, the record comprising historical position information and keyword information of a source code file where the source code to be located is located; and searching for the source code to be located in the source code file where the source code to be located is located by gradually expanding the search range based on the historical position information and the keyword information.

[0006] In one embodiment of the present invention, the method of gradually expanding the search range includes: determining the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; expanding the search for the keyword information to a first preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, expanding the search for the keyword information to a second preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, expanding the search for the keyword information to a third preset range with the historical position as the center to find the source code to be located.

[0007] In an embodiment of the present invention, the method of gradually expanding the search scope searches for keyword information of the source code to be located in the source code file based on a regular matching method.

[0008] In one embodiment of the present invention, after the source code to be located is found in the source code file, the existing location information of the source code to be located in the source code file is recorded in a database.

[0009] To achieve the above object, the present invention further provides a source code location system, comprising: a record acquisition module and a search module; the record acquisition module is used to acquire records about the source code to be located in the database, the records including historical location information and keyword information of the source code file where the source code to be located is located;

[0010] The search module is used to find the source code to be located in the source code file where the source code to be located is located by gradually expanding the search range based on the historical position information and the keyword information.

[0011] In one embodiment of the present invention, the search module is further used to: determine the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; expand the search for the keyword information to a first preset range with the historical position as the center to find the source code to be located; when the search for the keyword information in the first preset range fails to find the source code to be located, expand the search for the keyword information to a second preset range with the historical position as the center to find the source code to be located; when the search for the keyword information in the second preset range fails to find the source code to be located, expand the search for the keyword information to a third preset range with the historical position as the center to find the source code to be located.

[0012] In an embodiment of the present invention, the method of gradually expanding the search scope searches for keyword information of the source code to be located in the source code file based on a regular matching method.

[0013] In one embodiment of the present invention, a recording module is further included. The recording module is used to record the existing location information of the source code to be located in the source code file in a database after the source code to be located is found in the source code file.

[0014] To achieve the above object, the present invention further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, any of the above source code locating methods is implemented.

[0015] To achieve the above object, the present invention also provides a source code locating device, comprising: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory and is used to execute the computer program stored in the memory, so that the source code locating device executes any of the above source code locating methods.

[0016] As described above, a source code location method, system, medium and device of the present invention have the following beneficial effects: when the source code location is inaccurately located by a code location program, or the source code file has been modified so that the database record needs to be updated before the location can be located again, the source code location can be conveniently located without updating the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1a Shown is a flow chart of a source code location method in one embodiment of the present invention;

[0018] Figure 1b Shown is a flow chart of a source code location method in another embodiment of the present invention;

[0019] Figure 1c Shown is a flow chart of a source code location method in yet another embodiment of the present invention;

[0020] Figure 2 Shown is a schematic diagram of the structure of a source code location system in one embodiment of the present invention;

[0021] Figure 3 FIG. 1 is a schematic diagram showing the structure of a source code locating device in one embodiment of the present invention.

[0022] Component number description

[0023] 21 Get record module

[0024] 22 Search Module

[0025] 31 Processor

[0026] 32 Memory DETAILED DESCRIPTION

[0027] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0028] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0029] The source code location method, system, medium and device of the present invention are used to facilitate source code location without updating the database when the source code location is inaccurately located by a code location program or the source code file has been modified so that the database record needs to be updated before location can be performed again.

[0030] like Figure 1a As shown, in one embodiment, the source code location method of the present invention includes the following steps:

[0031] Step S11, obtaining a record of the source code to be located in the database, wherein the record includes historical location information and keyword information of the source code file where the source code to be located is located.

[0032] Specifically, the source code location method is used in the present application because it is an operation performed when there is no way to directly find the source code to be located based on the original record of the source code to be located.

[0033] Specifically, the record of the source code to be located in the database is obtained through the code location program. Specifically, the code location program includes but is not limited to: vim, emacs. Vim is a well-known powerful and highly customizable text editor similar to Vi, which improves and adds many features on the basis of Vi. VIM is free software. Emacs, a well-known integrated development environment and text editor.

[0034] For example, the record of the source code to be located includes the following contents:

[0035] Code library format table

[0036]

[0037] Specifically, the record of the source code to be located in the database is the record of the file path in the code library format table, through which the historical location information and keyword information of the source code file where the source code to be located is located can be obtained. Specifically, the historical location information is the line number, and the keyword information is the file offset number.

[0038] Specifically, the historical location information can also be the specific line number information of the source code to be located in the source code file, and the keyword information includes but is not limited to the line number name, variable name, structure, and language of the source code to be located. The line number name refers to the specific line number of the source code to be located; the variable name refers to the variable name of the source code to be located. Specifically, the variable name should be able to describe the information represented by the variable. The variable name is represented by lowercase letters and separated by underscores; the structure is a data set composed of a series of data of the same type or different types, also called a structure; the language refers to the language used by the source code to be located, including but not limited to: C language, C++, java, Python.

[0039] Step S12: searching for the source code to be located in the source code file where the source code to be located is located by gradually expanding the search range based on the historical position information and the keyword information.

[0040] Specifically, the method of gradually expanding the search range includes: determining the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; expanding the search for the keyword information to a first preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, expanding the search for the keyword information to a second preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, expanding the search for the keyword information to a third preset range with the historical position as the center to find the source code to be located. Specifically, if the source code file is relatively large, when the source code to be located is not found by searching the keyword information in the third preset range, expanding the search for the keyword information to a fourth preset range with the historical position as the center to find the source code to be located. If not found, gradually expanding to a fifth preset range, a sixth preset range, and so on with the historical position as the center until the source code to be located is found. For example, Figure 1bAs shown, the historical position information of the source code to be located is used to determine the historical position of the source code to be located in the source code file; the search range is expanded to a first preset range with the historical position as the center to search the keyword information so as to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, the search range is expanded to a second preset range with the historical position as the center to search the keyword information so as to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, the search range is expanded to the entire source code file with the historical position as the center to search the keyword information so as to find the source code to be located. For another example, the historical position information of the source code to be located is used to determine the historical position of the source code to be located in the source code file; the search range is expanded to the five lines above and below the historical position as the first preset range with the historical position as the center to search the keyword information to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, the search range is expanded to the twenty lines above and below the historical position as the center to search the keyword information in the second preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, the search range is expanded to the entire file of the source code file with the historical position as the center to search the keyword information to find the source code to be located. In this way, source code location is convenient without updating the database. This method of gradually expanding the search range is step-by-step, and does not require searching the entire file of the source code file at once, which can have higher search efficiency.

[0041] Specifically, the method of gradually expanding the search scope searches for keyword information of the source code to be located in the source code file based on a regular matching method. Specifically, the regular matching is also called: regular expression, also known as regular notation, conventional notation (English: Regular Expression, often abbreviated as regex, regexp or RE in the code), a concept in computer science. Regular expressions use a single string to describe and match a series of strings that conform to a certain syntactic rule. In many text editors, regular expressions are often used to retrieve and replace text that conforms to a certain pattern.

[0042] Specifically, the keyword information of the source code to be located in the source code file is searched based on grep. Grep is used to find the string that meets the conditions in the file. Grep is used to find the file whose content contains the specified template style. If it is found that the content of a certain file meets the specified template style, grep is preset to display the column containing the template style. If no file name is specified, or the given file name is -, grep will read data from the standard input device.

[0043] Specifically, after the source code to be located is found in the source code file, the existing location information of the source code to be located in the source code file is recorded in the database. In this way, when searching for the source code to be located next time, step S11 and step S12 are no longer needed, and the source code to be located can be directly found in the source code file based on the record, that is, directly located at the correct place.

[0044] Specifically, Figure 1c As shown, the source code location method is used in the present application because there is no way to directly find the source code to be located based on the original record of the source code to be located (started when the original system code location software fails to locate). Obtain the record of the source code to be located in the database (load the code database), the record includes the historical position information and keyword information of the source code file where the source code to be located is located (read the cursor to obtain the code keyword, and search the code data according to the keyword to obtain the target file name and line number (i.e., the keyword information and the line number name of the source code to be located)). Determine the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; expand the search range to the first preset range with the historical position (this line) as the center to search for the keyword information to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, expand the search range to the second preset range with the historical position as the center to search for the keyword information to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, expand the search range to the entire file of the source code file with the historical position as the center to search for the keyword information to find the source code to be located.

[0045] like Figure 2As shown, in one embodiment, the source code location system of the present invention comprises a record acquisition module 21 and a search module 22; the record acquisition module 21 is used to acquire records about the source code to be located in a database, wherein the records include historical location information and keyword information of the source code file where the source code to be located is located; the search module 22 is used to find the source code to be located in the source code file where the source code to be located is located by gradually expanding the search range based on the historical location information and the keyword information.

[0046] The search module 22 is further used to: determine the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; search the keyword information by expanding the search range from the historical position to a first preset range to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, the search is expanded from the historical position to a second preset range to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, the search is expanded from the historical position to a third preset range to find the source code to be located.

[0047] Specifically, the method of gradually expanding the search scope searches for keyword information of the source code to be located in the source code file based on a regular matching method.

[0048] The recording module 21 is used for recording the existing position information of the source code to be located in the source code file in the database after the source code to be located is found in the source code file.

[0049] It should be noted that the structures and principles of the acquisition record module 21 and the search module 22 correspond one-to-one to the steps in the above-mentioned source code location method, so they will not be described in detail here.

[0050] It should be noted that it should be understood that the division of the various modules of the above system is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the x module can be a separately established processing element, or it can be integrated in a chip of the above device for implementation. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0051] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital singnal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0052] In one embodiment of the present invention, the present invention further includes a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, any of the above-mentioned source code locating methods is implemented.

[0053] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

[0054] like Figure 3 As shown, in one embodiment, the source code locating device of the present invention includes: a processor 31 and a memory 32; the memory 32 is used to store computer programs; the processor 31 is connected to the memory 32, and is used to execute the computer program stored in the memory 32, so that the source code locating device executes any of the source code locating methods described above.

[0055] Specifically, the memory 32 includes: ROM, RAM, disk, USB flash drive, memory card or optical disk, etc., which can store program codes.

[0056] Preferably, the processor 31 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.

[0057] In summary, the source code location method, system, medium and device of the present invention are used to facilitate source code location without updating the database when the source code location is inaccurate through the code location program or the source code file has been modified so that the database record needs to be updated before the location can be performed again. Therefore, the present invention effectively overcomes various shortcomings in the prior art and has a high industrial utilization value.

[0058] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.

Claims

1. A source code location method, characterized in that: The following steps are involved: Obtaining a record of the source code to be located in a database, wherein the record includes historical location information and keyword information of a source code file where the source code to be located is located; Based on the historical position information and the keyword information, the source code to be located is searched in the source code file where the source code to be located is located by gradually expanding the search range; The method for gradually expanding the search range includes: determining the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; expanding the search for the keyword information to a first preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, expanding the search for the keyword information to a second preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, expanding the search for the keyword information to a third preset range with the historical position as the center to find the source code to be located.

2. The source code location method according to claim 1, characterized in that: The method of gradually expanding the search scope searches for keyword information of the source code to be located in the source code file based on a regular matching method.

3. The source code location method according to claim 1, characterized in that: After the source code to be located is found in the source code file, the existing location information of the source code to be located in the source code file is recorded in a database.

4. A source code location system, characterized in that: include: Get record module and search module; The record acquisition module is used to acquire a record about the source code to be located in the database, wherein the record includes historical location information and keyword information of the source code file where the source code to be located is located; The search module is used to find the source code to be located in the source code file where the source code to be located is located by gradually expanding the search range based on the historical position information and the keyword information; The method for gradually expanding the search range includes: determining the historical position of the source code to be located in the source code file based on the historical position information of the source code to be located; expanding the search for the keyword information to a first preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the first preset range, expanding the search for the keyword information to a second preset range with the historical position as the center to find the source code to be located; when the source code to be located is not found by searching the keyword information in the second preset range, expanding the search for the keyword information to a third preset range with the historical position as the center to find the source code to be located.

5. The source code location system according to claim 4, characterized in that: The method of gradually expanding the search scope searches for keyword information of the source code to be located in the source code file based on a regular matching method.

6. The source code location system according to claim 4, characterized in that: The invention also comprises a recording module, wherein the recording module is used for recording the existing position information of the source code to be located in the source code file in the database after the source code to be located is found in the source code file.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement the source code locating method according to any one of claims 1 to 3.

8. A source code location device, characterized in that: include: Processor and memory; The memory is used to store computer programs; The processor is connected to the memory and is used to execute the computer program stored in the memory, so that the source code locating device executes the source code locating method according to any one of claims 1 to 3.