Source code information retrieval method, device, electronic device, storage medium and product

By establishing an abstract syntax tree and a basic element tree and building a cache pool, real-time synchronous retrieval of source code files is realized, and the problem of delay in analyzing source code in the existing technology is solved, and information acquisition efficiency is improved.

CN114880357BActive Publication Date: 2024-12-24BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202210577393.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-25
Publication Date
2024-12-24
Estimated Expiration
2042-05-25

AI Technical Summary

Technical Problem

The existing programming platform, especially flutter technology, is not yet mature, resulting in insufficient development auxiliary tools. When analyzing source code files, it is necessary to communicate through server-client machines, which has delay problems and cannot meet scenarios with high real-time response requirements.

Method used

By establishing an abstract syntax tree and a basic element tree, using the analyzer analyzer component for lexical and semantic analysis, building an expression cache pool and a basic element cache pool, real-time synchronous retrieval of source files.

Benefits of technology

It reduces latency and improves the efficiency of source code information acquisition, and is suitable for real-time and non-blocking application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114880357B_ABST
    Figure CN114880357B_ABST
Patent Text Reader

Abstract

The present disclosure provides a source code information retrieval method, device, electronic device, storage medium and product, which relate to the field of programming technology, and in particular to the field of source file information technology. The specific implementation scheme is: obtaining all character information of the source code file, the abstract syntax corresponding to the character information is represented by the structure of an abstract syntax tree, and the basic elements corresponding to the character information are represented by the structure of a basic element tree; constructing an expression cache pool based on the characteristics of the abstract syntax tree, and constructing a basic element cache pool based on the characteristics of the basic element tree; in response to a retrieval instruction, the source code information of the source code file is retrieved in the expression cache pool and the basic element cache pool. Obtaining source code information through the present disclosure can reduce the delay in information acquisition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of programming technology, in particular to the field of source file information technology, and specifically to a source code information retrieval method, device, electronic device, storage medium and product. Background Art

[0002] With the rapid development of programming technology, various problems have been converged, and it has a good development prospect. And some new programming platforms have gradually emerged.

[0003] In the early stages of the development of some programming platform technologies, there is still little technical accumulation in many areas, and many development auxiliary tools need to be supplemented. Summary of the invention

[0004] The present invention provides a source code information retrieval method, device, electronic device, storage medium and product.

[0005] According to a first aspect of the present disclosure, there is provided an information acquisition method, the method comprising:

[0006] Acquire all source code information of a source code file, wherein the abstract syntax corresponding to the source code information is represented by an abstract syntax tree structure, and the basic elements corresponding to the source code information are represented by a basic element tree structure; construct an expression cache pool based on the characteristics of the abstract syntax tree, and construct a basic element cache pool based on the characteristics of the basic element tree; and in response to a retrieval instruction, retrieve character information of the source code file in the expression cache pool and the basic element cache pool.

[0007] According to a second aspect of the present disclosure, there is provided an information acquisition device, the device comprising:

[0008] An acquisition module is used to acquire all source code information of a source code file, wherein the abstract syntax corresponding to the source code information is represented by the structure of an abstract syntax tree, and the basic elements corresponding to the source code information are represented by the structure of a basic element tree; a construction module is used to construct an expression cache pool based on the characteristics of the abstract syntax tree, and to construct a basic element cache pool based on the characteristics of the basic element tree; a retrieval module is used to retrieve the source code information of the source code file in the expression cache pool and the basic element cache pool in response to a retrieval instruction.

[0009] According to a third aspect of the present disclosure, there is provided an electronic device, including:

[0010] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in the first aspect.

[0011] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method according to the first aspect.

[0012] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to the first aspect.

[0013] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0015] Figure 1 A schematic diagram of a flow chart of a source code information retrieval method provided by an embodiment of the present disclosure is shown;

[0016] Figure 2 A schematic diagram of a flow chart of a method for constructing an expression cache pool provided by an embodiment of the present disclosure is shown;

[0017] Figure 3 A schematic diagram of a process for constructing a basic element cache pool provided by an embodiment of the present disclosure is shown;

[0018] Figure 4 A schematic diagram of a flow chart of a source code information retrieval method provided by an embodiment of the present disclosure is shown;

[0019] Figure 5 A schematic diagram of the structure of a source code information retrieval device provided by an embodiment of the present disclosure is shown;

[0020] Figure 6 It is a block diagram of an electronic device used to implement the source code information retrieval method of the embodiment of the present disclosure. DETAILED DESCRIPTION

[0021] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0022] With the rapid development of programming technology, various problems have been converged and have good development prospects. Some new programming platforms have gradually emerged. For example, the cross-platform technology of the user interface toolkit (flutter). Compared with mature programming technology, flutter technology is still in the early stage of growth, and there is still little technical accumulation in many aspects, and many development auxiliary tools need to be supplemented.

[0023] In the related technology, the Dart source code file information of the Flutter technology is analyzed by using the analysis (analysis_server) service in the development tool (dart sdk) to analyze the source code, and then the C / S communication method is used to access the analysis_server service to obtain the information of the source code file.

[0024] However, using the analysis_server service in the dart sdk to analyze the source code requires additional maintenance of the analysis_server service. In addition, the client-server (C / S) communication method has a delay problem and is not suitable for scenarios with high real-time response requirements. In addition, the C / S communication implementation method is used for coding, which cannot meet some application scenarios that require real-time data acquisition.

[0025] In response to the technical problems existing in the above-mentioned related technologies, the present disclosure provides an information acquisition method and device. For the source code file, a corresponding abstract syntax tree and basic element tree are established. According to the characteristics of the established abstract syntax tree and basic element tree, the analyzer component is used to perform lexical and semantic analysis on the source code to construct a compilation unit. Then, each node of the abstract syntax tree and the basic element tree in the compilation unit is traversed to collect information, the information is classified, and added to the corresponding cache pool to provide a variety of synchronous information retrieval methods to the outside. In particular, for some application scenarios that obtain source code information in real time and non-blocking operation, such as abstract syntax tree (AST) compilation, real-time analysis of class types in source code, etc., the method provided by the present disclosure can reduce latency.

[0026] The embodiments of the present disclosure are described using a dart source code file as an example, but are not limited to dart source code files. The concepts provided by the present disclosure can be applied to any other coding platform.

[0027] Figure 1 A schematic diagram of a source code information retrieval method provided by an embodiment of the present disclosure is shown. Figure 1 As shown in , the method may include:

[0028] In step S110, all source code information of the source code file is obtained.

[0029] In the disclosed embodiment, before acquiring the source code information, the source code file may be subjected to lexical analysis and semantic analysis to determine all the source code information included in the source code file. The abstract syntax corresponding to the source code information is represented by an abstract syntax tree structure, and the basic elements corresponding to the source code information are represented by a basic element tree structure.

[0030] In the present disclosure, a file including an abstract syntax tree and a base element tree may be referred to as a compilation unit.

[0031] In step S120, an expression buffer pool is constructed based on the characteristics of the abstract syntax tree, and a basic element buffer pool is constructed based on the characteristics of the basic element tree.

[0032] In an embodiment of the present disclosure, the feature of the abstract syntax tree may be an expression in a source code file, and each node of the abstract syntax tree corresponds to an expression. In this disclosure, for the sake of distinction, the expression in the source code file is referred to as a node expression. Based on the feature of the abstract syntax tree, an expression cache pool is constructed for storing expressions in the source code file.

[0033] In the present disclosure, a node in the basic element tree corresponds to an atomic element, and a basic element cache pool is constructed based on the atomic element.

[0034] In step S130, in response to the search instruction, character information of the source code file is searched in the expression buffer pool and the basic element buffer pool.

[0035] In the disclosed embodiment, based on the expression cache pool, the character information of the node expression in the source code file is cached, and based on the basic element cache pool, the character information of the basic element in the source code file is cached. Based on the character information stored in the expression cache pool and the basic element cache pool, the character information of the required source code file is retrieved according to the retrieval instruction.

[0036] Through the information acquisition method provided by the embodiment of the present disclosure, a corresponding cache pool can be constructed based on the compilation unit of the source code file, and the information of the source code file can be cached in the corresponding cache pool. The required source code file information is obtained from the information cached in the cache pool, which can improve the efficiency of obtaining the information of the source code file.

[0037] In the disclosed embodiment, if a new source code file is retrieved, the runtime environment is initialized based on the project path of the source code file, and the cache pool of the source code file information can be cleaned up. Thus, the source code file is obtained, and the analyzer component is subjected to lexical analysis and semantic analysis to obtain an abstract syntax tree for representing the abstract syntax of the source code file and a basic element tree for representing the basic elements of the source code file.

[0038] Figure 2A schematic diagram of a flow chart of a method for constructing an expression cache pool provided by an embodiment of the present disclosure is shown, Figure 2 As shown in , the method may include:

[0039] In step S210, a first node of the abstract syntax tree is obtained, and the first node is traversed to determine a node expression of the first node.

[0040] In the embodiment of the present disclosure, the abstract syntax tree includes multiple nodes. For the convenience of description, the present disclosure refers to the nodes included in the abstract syntax tree as first nodes, and the expression corresponding to each first node of the abstract syntax tree as a node expression.

[0041] In the present disclosure, all first nodes of the abstract syntax tree are obtained, and the node expression corresponding to each first node is determined. For example, the dart syntax includes multiple different expressions, and each node in the abstract syntax tree of the dart source code file corresponds to an expression.

[0042] In step S220, the first offset of the specified character in the node expression is determined, and the first offset is used as the first key for storing the node expression.

[0043] In an embodiment of the present disclosure, in the process of constructing an abstract syntax tree, the first offset of a specified character in a node expression corresponding to a first node can be determined. Furthermore, the first offset can be used as a unique identifier of the node expression, thereby using the first offset as a first key for storing the node expression. Based on the first key of each node expression, an expression cache pool for storing node expressions is constructed. It should be noted that, in order to facilitate distinction, the present disclosure refers to the key for storing node expressions as the first key, and the offset of the specified character in the node expression as the first offset.

[0044] In step S230, based on the first key, the character information of the node expression is cached to build an expression cache pool.

[0045] In the disclosed embodiment, each first key corresponds to a node expression, and character information of the corresponding node expression is cached according to the first key to construct an expression cache pool. The expression cache pool is used to store character information of the node expression in the source code file.

[0046] An implementation of determining the first offset in the present disclosure is as follows.

[0047] In one embodiment of the present disclosure, if the node expression is a single node expression, that is, the node expression includes one expression, the offset of the specified character in the expression is determined as the first offset of the node expression, wherein the specified character may be the first character in the single node expression.

[0048] In another embodiment of the present disclosure, if the node expression is a combined expression, all expressions included in the combined expression are obtained, and the offset of the specified character of each expression is determined. The logical relationship between multiple offsets is determined to determine the first offset corresponding to the node expression. For example, if the offsets of the specified characters of all expressions in the combined expression have the same offset, each expression can be distinguished by chain storage, and the first offset of the node expression can be determined.

[0049] In the embodiment of the present disclosure, based on the first key of the expression cache pool, the first node of the abstract syntax tree can be traversed, the character information of the node expression can be collected, and the character information of the node expression can be cached. The character information of the cached node expression can also be stored in the node expression.

[0050] Figure 3 A schematic diagram of a basic element cache pool construction method provided by an embodiment of the present disclosure is shown. Figure 3 As shown in , the method may include:

[0051] In step S310, a second node of the basic element tree is obtained, and the second node is traversed to determine the basic element corresponding to the second node.

[0052] In the disclosed embodiments, such as the above embodiments, the basic element tree is constructed based on the basic elements in the corresponding syntax of the source code file. Taking dart syntax as an example, the atomic elements included in dart syntax may include at least one of library, top level function, top level variable, class, method, field, constructor, and method invocation. The basic element tree is constructed based on all atomic elements in dart, including various atomic elements in the source code.

[0053] For the convenience of distinction, the present disclosure refers to the nodes included in the basic element tree as second nodes. The basic element corresponding to each second node is determined by traversing the second nodes and collecting information of each second node.

[0054] In step S320, the second offset of the designated character in the basic element is used as a second key for storing the basic element information.

[0055] In the embodiments of the present disclosure, the basic elements are all different, and the second offset of the character specified by the basic element can be directly used as the second key for storing the basic element information. It should be noted that, for the sake of distinction, the present disclosure refers to the offset of the character specified in the basic element as the second offset, and the key for storing the basic element information as the second key.

[0056] In step S330, based on the second key, character information of the basic element is cached to construct a basic element pool.

[0057] In the disclosed embodiment, according to the determined second key, a basic element corresponding to the second key is determined, character information of the basic element is cached, and a basic element cache pool is constructed.

[0058] It is also possible to traverse the second node of the basic element tree based on the second key of the basic element cache pool, collect character information of the basic elements of the source code file, and cache the character information of the basic elements.

[0059] In the present disclosure, traversal of the second node of the base element tree may begin when traversing the simple identifier of the first node of the abstract syntax tree.

[0060] Figure 4 A schematic diagram of a source code information retrieval method provided by an embodiment of the present disclosure is shown. Figure 4 As shown in , the method may include:

[0061] In step S410, based on the first node of the abstract syntax tree and / or the second node of the basic element tree, multiple search paths are constructed according to the target source code information in the search instruction.

[0062] In step S420, based on at least one search path among the multiple search paths, character information of the required source code file is retrieved in the expression buffer pool and the basic element buffer pool.

[0063] In the disclosed embodiment, the target source code information to be retrieved is determined according to the search instruction, wherein the source code information may be character information of the source code file. Further, multiple search paths may be constructed based on the first node of the abstract syntax tree and / or the second node of the basic element according to the target source code information in the search instruction. The search path is a search path for searching the character information of the source code file based on the node.

[0064] In the embodiment of the present disclosure, at least one search path is determined to be used based on the existing character information, and based on the at least one search path, the character information of the required source code file is retrieved from the character information stored in the expression buffer pool and the basic element buffer pool. For example, the application scenario of the node expression information of the first node can be queried based on multiple search paths.

[0065] In the embodiment of the present disclosure, if the required character information is retrieved based on the first node, and the node expression corresponding to the first node is a node expression of a specified type, the node expression is parsed to obtain the character information of the first node. Based on the character information of the first node and the character information of the basic element of the basic element buffer pool, the required character information of the source code file is retrieved.

[0066] Among them, the node expression of the specified type can be an expression with a single string, for example, ThisExpression, SuperExpression, SimpleStringLiteral, SimpleIdentifier, SetOrMapLiteral, MethodInvocation, ListLiteral, IntegerLiteral, InstanceCreationExpression, IndexExpression, DoubleLiteral, CascadeExpression, BooleanLiteral, BinaryExpression, AssignmentExpression and other node expressions in the dart source code file.

[0067] Based on Figure 1 The same principle as shown in the method, Figure 5 A schematic diagram of the structure of a source code information retrieval device provided by an embodiment of the present disclosure is shown. Figure 5 As shown, the source code information retrieval device 500 may include:

[0068] The acquisition module 501 is used to acquire all source code information of the source code file, wherein the abstract syntax corresponding to the source code information is represented by the structure of an abstract syntax tree, and the basic elements corresponding to the source code information are represented by the structure of a basic element tree; the construction module 502 is used to construct an expression cache pool based on the characteristics of the abstract syntax tree, and to construct a basic element cache pool based on the characteristics of the basic element tree; the retrieval module 503 is used to retrieve the character information of the source code file in the expression cache pool and the basic element cache pool in response to a retrieval instruction.

[0069] In the disclosed embodiment, the acquisition module 501 is used to acquire a source code file and perform word and semantic analysis on the source code file to obtain an abstract syntax tree for representing the abstract syntax of the source code file and a basic element tree for representing the basic elements of the source code file.

[0070] In the disclosed embodiment, the construction module 502 is used to obtain the first node of the abstract syntax tree, traverse the first node, determine the node expression of the first node; and determine the first offset of the specified character in the node expression, and use the first offset as the first key for storing the node expression; based on the first key, cache the character information of the node expression and build an expression cache pool.

[0071] In the embodiment of the present disclosure, the device also includes: a cache module 504; the cache module 504 is used to traverse the first node of the abstract syntax tree based on the first key of the expression cache pool, collect character information of the node expression, and cache the character information of the node expression.

[0072] In an embodiment of the present disclosure, the construction module 502 is also used to, in response to the node expression being a single node expression, determine the first offset of the node expression based on the offset of a specified character in the single node expression; or, in response to the node expression being a combined expression, obtain the offset of a specified character in each expression in the combined expression, and determine the first offset of the node expression based on the logical relationship between each of the offsets.

[0073] In the embodiment of the present disclosure, the construction module 502 is used to obtain the second node of the basic element tree, traverse the second node, and determine the basic element corresponding to the second node; use the second offset of the character specified by the basic element as the second key to store the basic element information; based on the second key, cache the character information of the basic element to build a basic element cache pool.

[0074] In the disclosed embodiment, the cache module 504 is used to traverse the second node of the basic element tree based on the second key of the basic element cache pool, collect character information of the basic elements of the source code file, and cache the character information of the basic elements.

[0075] In the embodiment of the present disclosure, the retrieval acquisition module 503 is used to construct multiple retrieval paths based on the first node of the abstract syntax tree and / or the second node of the basic element tree, according to the target source code information in the retrieval instruction; based on at least one retrieval path among the multiple retrieval paths, retrieve the required character information of the source code file in the expression cache pool and the basic element cache pool.

[0076] In the embodiment of the present disclosure, the acquisition module 501 is also used to parse the node expression and acquire the character information of the first node in response to the retrieval path being to retrieve the character information based on the first node, and the node expression corresponding to the first node being a node expression of a specified type; and retrieve the required character information of the source code file based on the character information of the first node and the character information of the basic element of the basic element cache pool.

[0077] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0078] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0079] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0080] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0081] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0082] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as the method information acquisition method. For example, in some embodiments, the method information acquisition method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the method information acquisition method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the method information acquisition method by any other appropriate means (e.g., by means of firmware).

[0083] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0084] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0085] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0086] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0087] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0088] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0089] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0090] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A source code information retrieval method, the method comprising: Acquire all source code information of a source code file, wherein the abstract syntax corresponding to the source code information is represented by an abstract syntax tree structure, and the basic elements corresponding to the source code information are represented by a basic element tree structure; Building an expression cache pool based on the characteristics of the abstract syntax tree, and building a basic element cache pool based on the characteristics of the basic element tree; The method of constructing an expression cache pool based on the feature of the abstract syntax tree includes: obtaining a first node of the abstract syntax tree, traversing the first node, and determining a node expression of the first node; and determining a first offset of a specified character in the node expression, and using the first offset as a first key for storing the node expression; based on the first key, caching character information of the node expression, and constructing an expression cache pool; the specified character in the node expression is the first character in the node expression; In response to the retrieval instruction, source code information of the source code file is retrieved in the expression cache pool and the basic element cache pool.

2. The method according to claim 1, wherein: The acquisition of all source code information of the source code file includes: A source code file is obtained, and word and semantic analysis is performed on the source code file to obtain an abstract syntax tree for representing an abstract syntax of the source code file and a basic element tree for representing basic elements of the source code file.

3. The method according to claim 1, wherein: Determining the first offset of the specified character in the node expression includes: In response to the node expression being a single node expression, determining a first offset of the node expression based on an offset of a specified character in the single node expression; or In response to the node expression being a combined expression, the offset of a specified character in each expression in the combined expression is obtained, and based on the logical relationship between each of the offsets, the first offset of the node expression is determined.

4. The method according to claim 1, wherein: The caching of the character information of the node expression based on the first key includes: Based on the first key of the expression cache pool, the first node of the abstract syntax tree is traversed, the character information of the node expression is collected, and the character information of the node expression is cached.

5. The method according to claim 1 or 2, wherein: The step of constructing a basic element cache pool based on the characteristics of the basic element tree includes: Obtaining a second node of the basic element tree, and traversing the second node to determine a basic element corresponding to the second node; The second offset of the designated character in the basic element is used as a second key for storing basic element information; based on the second key, the character information of the basic element is cached to construct a basic element cache pool.

6. The method according to claim 5, wherein: The caching the character information of the basic element based on the second key includes: Based on the second key of the basic element cache pool, the second node of the basic element tree is traversed, character information of the basic elements of the source code file is collected, and the character information of the basic elements is cached.

7. The method according to claim 1, wherein: The step of retrieving source code information of the source code file from the expression buffer pool and the basic element buffer pool in response to the retrieval instruction includes: Based on the first node of the abstract syntax tree and / or the second node of the basic element tree, and according to the target source code information in the search instruction, construct multiple search paths; Based on at least one of the multiple search paths, the required character information of the source code file is retrieved in the expression buffer pool and the basic element buffer pool.

8. The method according to claim 7, wherein: The method further comprises: In response to the search path being to retrieve the character information based on the first node, and the node expression corresponding to the first node being a node expression of a specified type, parsing the node expression to obtain the character information of the first node; Based on the character information of the first node and the character information of the basic element of the basic element buffer pool, the required character information of the source code file is retrieved.

9. A source code information retrieval device, comprising: An acquisition module, used for acquiring all character information of a source code file, wherein the abstract syntax corresponding to the character information is represented by an abstract syntax tree structure, and the basic elements corresponding to the character information are represented by a basic element tree structure; A construction module, used to construct an expression cache pool based on the characteristics of the abstract syntax tree, and to construct a basic element cache pool based on the characteristics of the basic element tree; The construction module is used to: obtain a first node of the abstract syntax tree, traverse the first node, and determine a node expression of the first node; and determining a first offset of a specified character in the node expression, and using the first offset as a first key for storing the node expression; Based on the first key, cache the character information of the node expression to build an expression cache pool; The specified character in the node expression is the first character in the node expression; The retrieval module is used to retrieve the source code information of the source code file in the expression buffer pool and the basic element buffer pool in response to the retrieval instruction.

10. The device according to claim 9, wherein: The acquisition module is used to: A source code file is obtained, and word and semantic analysis is performed on the source code file to obtain an abstract syntax tree for representing an abstract syntax of the source code file and a basic element tree for representing basic elements of the source code file.

11. The device according to claim 9, wherein: The building blocks are also used to: In response to the node expression being a single node expression, determining a first offset of the node expression based on an offset of a specified character in the single node expression; or In response to the node expression being a combined expression, the offset of a specified character in each expression in the combined expression is obtained, and based on the logical relationship between each of the offsets, the first offset of the node expression is determined.

12. The device according to claim 9, wherein: The device further comprises: a cache module; The cache module is used to traverse the first node of the abstract syntax tree based on the first key of the expression cache pool, collect character information of the node expression, and cache the character information of the node expression.

13. The device according to claim 9 or 10, wherein: The building blocks are used to: Obtaining a second node of the basic element tree, and traversing the second node to determine a basic element corresponding to the second node; Using the second offset of the character specified by the basic element as the second key for storing basic element information; Based on the second key, the character information of the basic element is cached to build a basic element cache pool.

14. The device according to claim 12, wherein: The cache module is used to: Based on the second key of the basic element cache pool, the second node of the basic element tree is traversed, character information of the basic elements of the source code file is collected, and the character information of the basic elements is cached.

15. The device according to claim 9, wherein: The retrieval module is used to: Based on the first node of the abstract syntax tree and / or the second node of the basic element tree, and according to the target source code information in the search instruction, construct multiple search paths; Based on at least one of the multiple search paths, the required character information of the source code file is retrieved in the expression buffer pool and the basic element buffer pool.

16. The device according to claim 15, wherein: The retrieval module is used to: In response to the search path being to retrieve the character information based on the first node, and the node expression corresponding to the first node being a node expression of a specified type, parsing the node expression to obtain the character information of the first node; Based on the character information of the first node and the character information of the basic element of the basic element buffer pool, the required character information of the source code file is retrieved.

17. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.

18. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-8.

19. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Efficient novel memory index structure processing method

    CN110597805A

  • Project knowledge tree construction and retrieval method

    CN111368090A

  • Source code detection method and device based on abstract syntax tree and computer storage medium

    CN112631944A

  • Hook method and device for compiling period, equipment and storage medium

    CN112799677A

  • Structured search in source code

    US20100169871A1