Construction method and equipment of C + + code knowledge base and medium

By building detailed compilation configuration files and parsing engines, generating compilation units and filtering abstract syntax trees, the problem of incomplete or inaccurate C++ code knowledge base in the existing technology is solved, and accurate processing and efficient data storage of complex C++ projects are achieved.

CN119918641AActive Publication Date: 2025-05-02SHANDONG HUAYUN 3D TECH CO LTD

Patent Information

Application Number
CN202510413991.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-03
Publication Date
2025-05-02
Estimated Expiration
2045-04-03

AI Technical Summary

Technical Problem

It is difficult for the existing technology to build a comprehensive and intelligent C++ code knowledge base, especially when dealing with complex C++ syntax features, it is prone to incomplete parsing or misjudgment, resulting in incomplete or inaccurate knowledge base information.

Method used

By building a compilation configuration file containing detailed compilation parameters, parsing file elements based on the preset script parsing engine, generating compilation units, and obtaining abstract syntax trees for node filtering, storing them to semantic mapping tables and relational databases, achieving two-stage persistence processing.

Benefits of technology

It realizes accurate processing of complex C++ projects, avoids parsing errors, enhances data processing efficiency, reduces unnecessary computing and storage overhead, and supports dynamic maintenance and continuous expansion of the knowledge base.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119918641A_ABST
    Figure CN119918641A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a construction method and device of a C + + code knowledge base and a medium, relates to the technical field of knowledge maps, and is used for solving the problem that information of an existing knowledge base is incomplete and inaccurate. The method comprises the steps that a compiling configuration file containing detailed compiling parameters is constructed according to a C + + project configuration file; analyzing file elements of the compiling configuration file based on a preset script analysis engine, preprocessing the C + + project source file to obtain a processed C + + project file, and generating a compiling unit based on the file elements; obtaining dependency information of the C + + project file based on a compiling unit, obtaining an abstract syntax tree of the C + + project file for node filtering, and mapping and storing the filtered nodes and the dependency information into a corresponding semantic mapping table to realize first persistence processing; and determining the incidence relation of the C + + project file based on each semantic mapping table, storing each incidence relation in a preset relation database, and realizing second persistence processing to obtain a C + + code knowledge base.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of knowledge graph technology, and in particular to a method, device and medium for constructing a C++ code knowledge base. Background Art

[0002] As a high-performance programming language widely used in system-level and complex application development, C++ usually has a large and complex code structure, including a large number of advanced syntax features such as template programming, macro definitions, and multiple inheritance. As the scale of software projects continues to expand, the amount of code is growing exponentially. In order to help developers quickly understand the structure of existing codes, quickly locate key code segments, and understand the relationship between codes, it is particularly important to build a comprehensive and intelligent C++ code knowledge base.

[0003] However, most traditional code analysis tools currently rely mainly on regular expressions or simple text matching methods. When dealing with complex syntax features of C++, they are prone to incomplete parsing or misjudgment, resulting in incomplete or inaccurate information in the constructed knowledge base. In addition, most existing code documentation and knowledge management systems rely on manual maintenance and inefficient update mechanisms, making it difficult to reflect the latest status of the code base in a timely manner. In addition, when faced with rapid iterations and large-scale codes, the maintenance cost is high, data redundancy or omissions are prone to occur, and it is difficult to achieve high-quality and comprehensive data support. Summary of the invention

[0004] In order to solve the above technical problems, one or more embodiments of this specification provide a method, device and medium for constructing a C++ code knowledge base.

[0005] One or more embodiments of this specification adopt the following technical solutions: One or more embodiments of this specification provide a method for constructing a C++ code knowledge base, the method comprising: Build a compilation configuration file containing detailed compilation parameters according to the C++ project configuration file of the C++ project source file; Based on the preset script parsing engine, the file element corresponding to the compilation configuration file is parsed and obtained, and the C++ project source file is preprocessed to obtain a processed C++ project file, so as to generate a compilation unit corresponding to the C++ project file based on the file element; Obtaining dependency information of the C++ project file based on the compilation unit, and performing node filtering based on an abstract syntax tree of the C++ project file obtained by the compilation unit, so as to map and store the filtered nodes and the dependency information into a corresponding semantic mapping table, thereby implementing a first persistence process; Based on each of the semantic mapping tables, the association relationships of the C++ project files are determined, so that each of the association relationships is stored in a preset relationship database, a second persistence process is implemented, and the preset relationship database is used as a C++ code knowledge base.

[0006] Optionally, in one or more embodiments of the present specification, after implementing the second persistence process and using the preset relational database as a C++ code knowledge base, the method further includes: Scan each file of the current C++ project file to generate a current feature value corresponding to each file according to the file content and position of each file; Comparing the current feature value with the file feature value stored in the semantic mapping table to obtain a comparison result; wherein the semantic mapping table includes: a file table, a definition table, a structure table and a symbol table; If it is determined based on the comparison result that there is an update, a corresponding update characteristic value is obtained, and an impact file corresponding to the update characteristic value is determined; Acquire dependency information corresponding to the impact file based on the file table, and establish a dependency tree of the impact file; According to the dependency tree, associated files associated with the impact file are identified to delete the contents of the impact file and the associated files in the semantic mapping table, and based on the project configuration file corresponding to the updated feature value, local knowledge bases of the impact file and the associated files are reconstructed.

[0007] Optionally, in one or more embodiments of the present specification, after implementing the second persistence process and using the preset relational database as a C++ code knowledge base, the method further includes: Receive current query request information, and query the relationship type and specific index corresponding to the current query request information in the preset relationship database based on the preset multi-dimensional query interface; wherein the query request information includes: function name, class name, file name; The semantic mapping tables are queried based on the specific index to obtain detailed data corresponding to the current query request information.

[0008] Optionally, in one or more embodiments of the present specification, a compilation configuration file containing detailed compilation parameters is constructed according to a C++ project configuration file of a C++ project source file, specifically including: Parsing a C++ project configuration file of the C++ project source file to obtain compilation parameters of the C++ project configuration file; Completing the compilation parameters of the C++ project configuration file based on preset compilation parameter default values ​​to obtain completed detailed compilation parameters; The detailed compilation parameters are stored based on a preset format to obtain a compilation configuration file containing the detailed compilation parameters.

[0009] Optionally, in one or more embodiments of the present specification, parsing and obtaining the file element corresponding to the compilation configuration file based on a preset script parsing engine, and preprocessing the C++ project source file to obtain the processed C++ project file specifically includes: Reading the compilation configuration file based on a preset script parsing engine to parse the compilation configuration file to obtain initial file elements corresponding to the compilation configuration file; wherein each file element includes: a working directory, a compilation command and a compilation file; Filtering the compile commands in the initial file element to obtain filtered compile commands and file elements; wherein the filtered compile commands have preprocessor options and language standard related commands; The C++ project source file is subjected to standardization processing to convert the encoding of the C++ project source file into the same character encoding format, to obtain a processed C++ project file, and to cache the processed C++ project file into a memory.

[0010] Optionally, in one or more embodiments of the present specification, generating a compilation unit corresponding to the C++ project file based on the file element specifically includes: The working directory, the compile command and the compile file are used as parsing parameters to construct a corresponding code parsing environment according to the parsing parameters; In the code parsing environment, the grammar parsing library is called based on the preset script parsing engine to complete the grammar structure and context semantic information corresponding to the compiled file according to the same-directory dependency information of the working directory and other directory dependency information of the compile command; Based on the completed grammatical structure and contextual semantic information, a compilation unit corresponding to the C++ project file is generated.

[0011] Optionally, in one or more embodiments of the present specification, obtaining dependency information of the C++ project file based on the compilation unit, and performing node filtering based on the abstract syntax tree of the C++ project file obtained by the compilation unit, so as to map and store the filtered nodes and the dependency information into a corresponding semantic mapping table, and implement the first persistence processing, specifically including: Determine whether the C++ project file includes a header file based on the compilation unit; If yes, extract the header file list directly referenced by the C++ project file, and recursively analyze the header file list to complete the dependency information; If not, obtaining an abstract syntax tree of the C++ project file to traverse the abstract syntax tree to complete the dependency information; A unique feature code is generated for each abstract syntax tree node, and duplicate nodes are filtered based on the feature code to store the completed dependency information and the filtered node mapping in the corresponding semantic mapping table to achieve the first persistence processing.

[0012] Optionally, in one or more embodiments of the present specification, a unique feature code is generated for each abstract syntax tree node, and duplicate nodes are filtered based on the feature code to map the completed dependency information with the filtered nodes and store them in a corresponding semantic mapping table to implement the first persistence processing, which specifically includes: Performing a hash operation based on the component elements and file positions corresponding to each node in the abstract syntax tree to generate a unique feature code for each node of the abstract syntax tree; Determine whether there is a duplicate node in the abstract syntax tree based on the feature code, and if so, do not store the duplicate node; If not, the abstract syntax tree nodes are classified based on type, and the completed dependency information and the abstract syntax tree nodes are stored in a corresponding semantic mapping table based on a preset field rule.

[0013] One or more embodiments of this specification provide a device for constructing a C++ code knowledge base, the device comprising: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to: execute any of the above-mentioned methods.

[0014] One or more embodiments of the present specification provide a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured to execute any of the above-described methods.

[0015] At least one of the above technical solutions adopted in the embodiments of this specification can achieve the following beneficial effects: By using the C++ project configuration file to build a compilation configuration file with detailed compilation parameters, the project compilation environment information can be fully retained, parsing errors caused by lack of compilation parameters can be avoided, and the processing capabilities of complex C++ projects can be enhanced. Based on the compilation unit, the abstract syntax tree is obtained and nodes are filtered. In conjunction with the node feature code caching mechanism based on the abstract syntax tree, the problem of duplicate nodes caused by dependent files is effectively solved, data processing efficiency is improved, and unnecessary computing and storage overhead are reduced. A two-stage persistence strategy is adopted. First, the filtered nodes and dependency information are mapped and stored in the semantic mapping table, and then the association relationship is stored in the preset relationship database, and the node information and relationship information are stored separately. This not only ensures data integrity, but also provides a flexible query and update mechanism, supports the dynamic maintenance and continuous expansion of the knowledge base, and can meet the needs of the continuous evolution of large-scale projects. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art description. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. In the drawings: Figure 1 A schematic diagram of a method for constructing a C++ code knowledge base provided in an embodiment of this specification; Figure 2 A schematic diagram of the overall architecture of a C++ code knowledge base provided in an embodiment of this specification; Figure 3 A schematic diagram of a C++ code knowledge base semantic mapping table set provided in an embodiment of this specification; Figure 4 A schematic diagram of a query process of a C++ code knowledge base provided in an embodiment of this specification; Figure 5 A schematic diagram of a query process after a C++ code knowledge base is reconstructed according to an embodiment of this specification; Figure 6 A schematic diagram of the structure of a C++ code knowledge base construction device provided in an embodiment of this specification; Figure 7 A schematic diagram of the structure of a non-volatile storage provided in an embodiment of this specification. DETAILED DESCRIPTION

[0017] The embodiments of this specification provide a method, device and medium for constructing a C++ code knowledge base.

[0018] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.

[0019] like Figure 1 As shown, the present specification embodiment provides a method flow chart of a method for constructing a C++ code knowledge base. Figure 1 It can be seen that in one or more embodiments of this specification, a method for constructing a C++ code knowledge base includes the following steps: S101: Constructing a compilation configuration file including detailed compilation parameters according to a C++ project configuration file of a C++ project source file.

[0020] When processing C++ code that contains a lot of advanced syntax features such as template programming, macro definitions, and multiple inheritance, the correct compilation parameters can allow the compiler to accurately understand the code structure and semantics. Therefore, in order to ensure accurate processing of complex C++ projects, in the embodiments of this specification, a compilation configuration file containing detailed compilation parameters will be constructed based on the C++ project configuration file of the C++ project source file. Specifically, in one or more embodiments of this specification, a compilation configuration file containing detailed compilation parameters is constructed based on the C++ project configuration file of the C++ project source file, specifically including: In order to provide complex compilation parameters of C++ projects for subsequent steps, the C++ project configuration file of the C++ project source file will be parsed to obtain the compilation parameters of the C++ project configuration file. Then, the compilation parameters of the C++ project configuration file are completed based on the preset compilation parameter default values ​​to obtain the completed detailed compilation parameters. The detailed compilation parameters are stored based on the preset format to obtain a compilation configuration file containing detailed compilation parameters. By parsing and obtaining the compilation parameters and completing them with the default values, the integrity and accuracy of the compilation parameters can be guaranteed, the compilation failure caused by missing or incorrect parameters can be reduced, and the stability of the compilation process can be improved. In addition, the completion mechanism of the preset compilation parameter default values ​​makes the project more adaptable when facing different development environments or configuration file differences. Even if there are missing parameters in the configuration file, the project can still be compiled based on the default values, reducing the risk of the project failing to compile due to incomplete configuration files, and facilitating the deployment and operation of the project in different environments. And the detailed compilation parameters are stored in the preset format to generate a compilation configuration file, making the compilation configuration management more standardized and unified.

[0021] S102: parsing and obtaining the file elements corresponding to the compilation configuration file based on a preset script parsing engine, and preprocessing the C++ project source file to obtain a processed C++ project file, so as to generate a compilation unit corresponding to the C++ project file based on the file elements.

[0022] like Figure 2 As shown, after the compilation configuration file containing detailed compilation parameters is obtained by preprocessing based on step S101, the compilation configuration file is parsed by the preset script parsing engine to obtain the file elements therein, such as the working directory, the compilation command, the compilation file, etc. These elements are the basis for subsequent compilation and processing. They specify the working environment of the compiler, the compilation parameters used, and the source files to be compiled. Then, the C++ project source file is preprocessed to eliminate some special instructions and macro definitions in the code, making it easier for the compiler to understand. Then, based on the parsed file elements and the preprocessed C++ project file, the corresponding compilation unit is generated.

[0023] Specifically, in one or more embodiments of the present specification, parsing and obtaining the file element corresponding to the compilation configuration file based on the preset script parsing engine, and preprocessing the C++ project source file to obtain the processed C++ project file specifically includes the following process: First, the compilation configuration file is read based on the preset script parsing engine to parse the compilation configuration file to obtain the initial file element corresponding to the compilation configuration file; wherein each file element includes: a working directory, a compilation command and a compilation file. Then the compilation command in the initial file element is screened to obtain the filtered compilation command and file element; wherein the filtered compilation command has preprocessor options and language standard related commands. That is, in a certain application scenario, the script parsing engine is used to read the compilation configuration file of the previous step, and then the compilation configuration file is parsed to obtain each internal element, each element containing three parts: a working directory, a compilation command, and a compilation file for subsequent use, wherein the preprocessor options and language standard related commands are retained for the compilation command. Then the C++ project source file is standardized to convert the encoding of the C++ project source file into the same character encoding format, obtain the processed C++ project file, and cache the processed C++ project file into the memory, and the subsequent normal parsing of the abstract syntax tree AST can be guaranteed based on the standardized processing process. In this process, by filtering the compilation command and retaining only the preprocessor options and language standard related commands, the compiler can focus more on key compilation instructions and reduce unnecessary interference. Standardizing C++ project source files and unifying character encoding formats can effectively solve the compatibility issues caused by different encoding formats. The screened compilation commands and standardized source files provide a good foundation for subsequent operations such as abstract syntax tree parsing.

[0024] Specifically, in one or more embodiments of the present specification, generating a compilation unit corresponding to a C++ project file based on a file element specifically includes: After the above preprocessing operation is completed, in the embodiment of this specification, the working directory, compile command and compile file of the file elements identified by the above analysis are used as parsing parameters, so as to build a corresponding code parsing environment according to the parsing parameters, so as to ensure that the grammatical structure and context information of the source code are completely preserved. Then, in the code parsing environment, the grammar parsing library will be called based on the preset script parsing engine, so as to complete the grammatical structure and context semantic information corresponding to the compile file according to the same directory dependency information provided by the working directory and other directory dependency information of the compile command. According to the completed grammatical structure and context semantic information, a compilation unit corresponding to the C++ project file covering the complete grammatical structure and context semantic information is generated.

[0025] In large C++ projects, the dependencies between codes are complex, and accurate context information is crucial for correct compilation. In the above content of this manual, by building an accurate code parsing environment and completing the grammatical structure and contextual semantic information, the compiler can understand the source code more comprehensively and accurately. This helps reduce compilation failures caused by grammatical errors, unclear dependencies, etc., and improves the success rate of compilation.

[0026] S103: Obtain dependency information of the C++ project file based on the compilation unit, and perform node filtering based on the abstract syntax tree of the C++ project file obtained by the compilation unit, so as to map the filtered nodes and the dependency information and store them in a corresponding semantic mapping table to implement the first persistence processing.

[0027] Different from the traditional single storage, the embodiments of this specification will first process the basic node information based on the first persistence processing, and then process the relationship information through the second persistence processing. In order to store the node information and relationship information separately, a flexible query and update mechanism is provided while ensuring data integrity, supporting the dynamic maintenance and continuous expansion of the knowledge base, and meeting the evolution needs of large-scale projects. Specifically, for the first persistence processing, the embodiments of this specification will obtain the dependency information of the C++ project file based on the compilation unit, and perform node filtering based on the abstract syntax tree of the C++ project file obtained by the compilation unit, so as to map the filtered nodes with the dependency information and store them in the corresponding semantic mapping table, so as to realize the first persistence processing. By filtering the nodes of the abstract syntax tree, the filtering of duplicate nodes is realized, and then: the filtered nodes are mapped with the dependency information and stored, which can accurately reflect the dependency relationship between C++ project files.

[0028] Specifically, in one or more embodiments of the present specification, dependency information of a C++ project file is obtained based on a compilation unit, and node filtering is performed based on an abstract syntax tree of the C++ project file obtained based on the compilation unit, so that the filtered nodes and dependency information are mapped and stored in a corresponding semantic mapping table, and the first persistence processing is implemented, which specifically includes the following process: First, determine whether the C++ project file contains a header file based on the compilation unit. If so, extract the list of header files directly referenced by the C++ project file, and recursively analyze the list of header files to complete the dependency information. If there is no header file, obtain the abstract syntax tree of the C++ project file, and traverse the abstract syntax tree to complete the dependency information. And generate a unique feature code for each abstract syntax tree node, filter the duplicate nodes based on the feature code, and store the completed dependency information and the filtered node mapping in the corresponding semantic mapping table to achieve the first persistence processing. That is, since the compilation configuration file may not contain complete header file information, the header file dependency network can be supplemented in the following way in a certain scenario: when processing indirect dependencies of source files, record the header file information involved; analyze the indirect dependencies of each source file and extract the dependency relationship between header files; and construct a complete header file dependency index structure progressively by traversing the dependency information of all source files. In this process, the header file dependency network is constructed by analyzing indirect dependencies instead of relying solely on the compilation configuration file. This not only captures the direct dependencies between source files, but also constructs a complete header file dependency index through indirect dependency analysis, overcoming the limitation of incomplete header file dependency analysis in traditional solutions.

[0029] Further, in one or more embodiments of the present specification, a unique feature code is generated for each abstract syntax tree node, and duplicate nodes are filtered based on the feature code to store the completed dependency information and the filtered node mapping in the corresponding semantic mapping table to implement the first persistence processing, which specifically includes: A hash operation is performed based on the components and file positions corresponding to each node in the abstract syntax tree to generate a unique feature code for each abstract syntax tree node. Then, a determination is made based on the feature code whether there are duplicate nodes in the abstract syntax tree node. If so, the duplicate nodes are not stored. If not, the abstract syntax tree nodes are classified based on type, and the completed dependency information and the abstract syntax tree nodes are stored in the corresponding file based on the preset field rules. Figure 3 The semantic mapping table shown in the figure. That is, in a certain application scenario, node signature codes will be calculated and cached for repeated node identification. Due to the information integration of dependent files, the same node may appear multiple times, and signature codes can be used to quickly remove duplicates. Then, node filtering and screening are performed. First, nodes such as standard library references that can be directly processed are filtered, definition type nodes and their location information are identified, control structure nodes such as conditional statements, loop structures, etc. are identified, and symbol reference nodes with associated relationships are identified. Then, as Figure 3 As shown, the filtered nodes are mapped and stored in the definition table, structure table, and symbol table according to the preset field rules.

[0030] S104: Determine the association relationship of the C++ project files based on the semantic mapping tables, store the association relationships in a preset relationship database, implement a second persistence process, and use the preset relationship database as a C++ code knowledge base.

[0031] In the embodiments of this specification, after the first persistence processing is implemented, in order to be able to use a two-stage persistence strategy, the node information and relationship information are stored separately, while ensuring data integrity, a flexible query and update mechanism is provided, supporting the dynamic maintenance and continuous expansion of the knowledge base, and meeting the evolution needs of large-scale projects. A second persistence processing will also be performed, that is, the association relationship of the C++ project file is determined according to each semantic mapping table, so that each association relationship is stored in a preset relationship database, the second persistence processing is implemented and the preset relationship database is used as a C++ code knowledge base. That is, the step book first reads the data previously stored in the basic table to establish data relationships: based on the file table data, the dependency relationship between files is recorded; based on the definition table data, the structure and symbols directly contained are recorded; based on the structure table data, the definitions and symbols directly contained are recorded; based on the symbol table data, the definitions, structures, and symbols referenced are recorded. Then all the association relationships established by the semantic mapping table set are stored in the relational database, which is the final code knowledge base.

[0032] Further, in one or more embodiments of this specification, after the second persistence processing is implemented and the preset relational database is used as the C++ code knowledge base, in order to solve the problem of low update efficiency and excessive data processing volume caused by existing timestamp comparison or full update, the embodiments of this specification will also be updated based on the following steps: First, scan each file of the current C++ project file to generate the current feature value corresponding to each file according to the file content and position of each file. Then, compare the current feature value with the file feature value stored in the semantic mapping table to obtain the comparison result. It should be noted that the semantic mapping table includes: file table, definition table, structure table and symbol table. If it is determined according to the comparison result that there is an update, the corresponding update feature value is obtained, and the affected file corresponding to the updated feature value is determined. Then, the dependency information corresponding to the affected file is obtained according to the file table, and a dependency tree of the affected file is established. Then, the associated files associated with the affected file are identified according to the dependency tree, so as to delete the contents of the affected file and the associated file in the semantic mapping table, and reconstruct the local knowledge base of the affected file and the associated file based on the project configuration file corresponding to the updated feature value.

[0033] That is, in a certain application scenario, Figure 4As shown in the figure, after the code is updated, the process of updating only the affected files is as follows: the system first scans all files in the project, calculates and obtains the feature value of each file. The feature value is generated with the file content and location during the knowledge base construction phase. Then, the system obtains the stored file feature value from the file table and compares it with the newly calculated feature value. If the feature value is the same, it indicates that the file has not changed and the process ends directly; if the feature value is different, continue to perform subsequent update steps; for files with changed feature values, perform the following operations: obtain direct / indirect dependency information through the file table; establish a dependency tree for affected files; identify all associated files that need to be updated; then perform batch updates on all affected files found in the relationship table to delete the original information of these contents in the corresponding table; after completing the data deletion, perform local knowledge base reconstruction and re-execute the knowledge base construction process for the affected files.

[0034] In this process, by generating file feature values ​​and comparing them with the semantic mapping table, it is possible to accurately determine whether the file has been updated and which files have been affected. This method can accurately locate the source and scope of the update, avoid unnecessary reprocessing of the entire project, and improve processing efficiency. The method of building a dependency tree clearly shows the dependencies between files, so that all files that may be affected can be fully considered when processing file updates. This helps to ensure that important associations are not missed during the update process, thereby ensuring the integrity and consistency of the project. Only the affected files and associated files are processed instead of making large-scale modifications to the entire project. This local processing method reduces the complexity and time cost of processing, and also reduces the risk of introducing new errors. Reconstructing the local knowledge base based on the updated feature values ​​and project configuration files can quickly restore the semantic information of the files and ensure the normal operation of the project. In addition, the use of the semantic mapping table helps to centrally manage various semantic information of project files, including file definitions, structures, and symbol references. When files are updated, timely deletion of outdated information and reconstruction can ensure that the semantic mapping table always reflects the latest status of the project.

[0035] Further, in one or more embodiments of the present specification, after the second persistence processing is implemented and the preset relational database is used as a C++ code knowledge base, in order to be able to query the phase shift code information based on demand, such as Figure 5 The method also includes the following steps: First, the current query request information is received, and then based on the preset multi-dimensional query interface, the relationship type and specific index corresponding to the current query request information in the preset relationship database are queried; wherein the query request information includes: function name, class name, file name. Then, based on the specific index, each semantic mapping table is queried to obtain detailed data corresponding to the current query request information. For example, the following query functions can be implemented, including but not limited to: Enter the file name to query: (1) Direct and indirect dependencies between files: ->QUERY(DIRECT_INCLUDES|INDIRECT_INCLUDES) FROM file table WHERE full_path = "target file path" (2) Definition information contained in the file: ->QUERY(REFEREE_ID|REFEREE_TYPE) FROM relationship table WHERE REFERRER_ID IN(SELECT id FROM file table WHERE full_path = "target file path") Enter the function name to query: (1) Complete definition information of the function: ->QUERY(FULL_PATH|POSITION|KIND|TYPE) FROM definition table WHERE kind = "FUNCTION_DECL" AND spelling = "target function name" (2) Function calling relationship: ->QUERY(REFERRER_ID|REFEREE_ID|RELATION) FROM relation table WHERE referee_kind = "FUNCTION_DECL" AND relation = "CALLS" AND referee_id IN (SELECT idFROM definition table WHERE spelling = "target function name") (3) The class to which the function belongs: ->QUERY(REFERRER_ID|REFERRER_KIND) FROM relation table WHERE referee_id IN(SELECT id FROM definition table WHERE spelling = "target function name") AND relation = "MEMBER_OF" (4) Function overloading information: ->QUERY(FULL_PATH|POSITION|ARGUMENTS) FROM definition table WHERE kind = "FUNCTION" AND spelling = "target function name" Enter the class name to query: (1) Complete definition and inheritance of the class: ->QUERY(FULL_PATH|POSITION|RELATION) FROM definition table, relation table WHERE kind ="CLASS_DECL" AND spelling = "target class name" AND relation IN ("INHERITS", "INHERITED_BY") (2) Class member list: ->QUERY(REFEREE_ID|REFEREE_KIND) FROM relation table WHERE referrer_id IN(SELECT id FROM definition table WHERE spelling = "target class name") AND relation = "HAS_MEMBER" (3) Where the class is used: ->QUERY(REFERRER_ID|POSITION) FROM relation table WHERE referee_id IN (SELECTid FROM definition table WHERE spelling = "target class name" AND kind = "CLASS_DECL") Enter the variable name to query: (1) Definition and type of variables: ->QUERY(FULL_PATH|POSITION|KIND|TYPE) FROM symbol table WHERE spelling = "target variable name" AND kind = "TYPE_REF|MEMBER_REF_EXPR|CALL_EXPR" (2) Where the variable is used: ->QUERY(FULL_PATH|POSITION|REF_KIND) FROM symbol table WHERE spelling = "target variable name" (3) Structure: ->QUERY(REFERRER_ID|REFERRER_KIND) FROM relation table WHERE referee_id IN(SELECT id FROM definition table WHERE spelling = "target variable name") AND relation = "CONTAINED_BY" Input structure related content query: (1) Structural scope and content: ->QUERY(FULL_PATH|POSITION) FROM structure table WHERE full_path= "directory where the structure is located" (2) Symbol reference within the structure: ->QUERY(REFEREE_ID|REFEREE_KIND) FROM relational table WHERE referee_kind IN(IF_STMT|WHILE_STMT|FOR_STMT|DO_STMT) AND relation = "CONTAINS" (3) Structural nesting relationship: ->QUERY(REFERRER_ID|REFEREE_ID) FROM relational table WHERE relation = "CONTAINS" AND referee_kind IN (IF_STMT|WHILE_STMT|FOR_STMT|DO_STMT) ANDreferrer_kind IN (IF_STMT|WHILE_STMT|FOR_STMT|DO_STMT) Combined query: (1) Function to file dependency: ->QUERY(DIRECT_INCLUDES|INDIRECT_INCLUDES) FROM document table WHERE id IN(SELECT referrer_id FROM relationship table WHERE referee_id IN (SELECT id FROM definition table WHERE spelling = "target function name")) (2) Class to structure includes: ->QUERY(REFEREE_ID|RELATION) FROM relation table WHERE referrer_id IN (SELECTid FROM definition table WHERE spelling = "target class name") AND relation = "CONTAINS" (3) Dependency impact analysis: ->QUERY(REFERRER_ID|REFEREE_ID|RELATION) FROM relation table WHERE referee_id IN (SELECT id FROM definition table WHERE spelling = "target name") AND relation IN ("CALLS") The incremental update scheme based on the above process in the embodiment of this specification significantly reduces the computational overhead of knowledge base maintenance. For large C++ projects, the update time can be shortened from the hour level of complete reconstruction to the minute level, while ensuring the consistency and integrity of the data. And the association between various types of information is uniformly managed through the relationship table, so that developers can quickly locate all relevant information from any code element, significantly improving the efficiency of code understanding and maintenance. Specifically, the parsing mechanism based on the compilation configuration file ensures that the compilation environment information of the project is fully retained, solves the parsing errors caused by the lack of compilation parameters in traditional tools, and improves the processing ability of complex C++ projects. The progressive dependency network construction method is adopted, which not only captures the direct dependency relationship between source files, but also supplements the construction of a complete header file dependency index through indirect dependency analysis, overcoming the limitation of incomplete header file dependency analysis in traditional solutions. The node feature code caching mechanism based on the abstract syntax tree effectively solves the problem of duplicate nodes caused by dependency files, improves data processing efficiency, and reduces storage overhead. And based on the multi-dimensional association system of location information and unique identification, the precise association between code elements such as definition, reference, and control structure is realized, providing a reliable data foundation for code analysis and intelligent application. Through the two-stage persistence strategy, node information and relationship information are stored separately, providing a flexible query and update mechanism while ensuring data integrity, supporting dynamic maintenance and continuous expansion of the knowledge base, and meeting the evolution needs of large-scale projects. The precise update positioning mechanism based on eigenvalue comparison and dependency tree analysis avoids the redundant processing of unmodified files in traditional solutions, and is particularly suitable for development environments with frequent iterations. The centralized query design based on the relationship table, through a unified relationship indexing mechanism, enables the system to accurately track the evolution of associations between code elements, thereby supporting advanced application scenarios such as incremental updates and change impact analysis, significantly reducing the maintenance cost and reconstruction risk of large projects.

[0036] like Figure 6 As shown, the present specification embodiment provides a schematic diagram of the structure of a C++ code knowledge base construction device, which comprises Figure 6 It can be seen that in one or more embodiments of this specification, a device for constructing a C++ code knowledge base includes: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to: execute any of the above-mentioned methods.

[0037] like Figure 7 As shown, the present specification embodiment provides a structural schematic diagram of a non-volatile storage medium, which is composed of Figure 7 It can be seen that in one or more embodiments of this specification, a non-volatile storage medium stores computer executable instructions 701, and the computer executable instructions 701 can: execute any of the methods described above.

[0038] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and non-volatile computer storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0039] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0040] The above description is only one or more embodiments of this specification and is not intended to limit this specification. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of this specification shall be included in the scope of the claims of this specification.

Claims

1. A method for constructing a C++ code knowledge base, characterized in that: The method comprises: Build a compilation configuration file containing detailed compilation parameters according to the C++ project configuration file of the C++ project source file; Based on the preset script parsing engine, the file element corresponding to the compilation configuration file is parsed and obtained, and the C++ project source file is preprocessed to obtain a processed C++ project file, so as to generate a compilation unit corresponding to the C++ project file based on the file element; Obtaining dependency information of the C++ project file based on the compilation unit, and performing node filtering based on an abstract syntax tree of the C++ project file obtained by the compilation unit, so as to map and store the filtered nodes and the dependency information into a corresponding semantic mapping table, thereby implementing a first persistence process; Based on each of the semantic mapping tables, the association relationships of the C++ project files are determined, so that each of the association relationships is stored in a preset relationship database, a second persistence process is implemented, and the preset relationship database is used as a C++ code knowledge base.

2. The method for constructing a C++ code knowledge base according to claim 1, characterized in that: After implementing the second persistence process and using the preset relational database as a C++ code knowledge base, the method further includes: Scan each file of the current C++ project file to generate a current feature value corresponding to each file according to the file content and position of each file; Comparing the current feature value with the file feature value stored in the semantic mapping table to obtain a comparison result; wherein the semantic mapping table includes: a file table, a definition table, a structure table and a symbol table; If it is determined based on the comparison result that there is an update, a corresponding update characteristic value is obtained, and an impact file corresponding to the update characteristic value is determined; Acquire dependency information corresponding to the impact file based on the file table, and establish a dependency tree of the impact file; According to the dependency tree, associated files associated with the impact file are identified to delete the contents of the impact file and the associated files in the semantic mapping table, and based on the project configuration file corresponding to the updated feature value, local knowledge bases of the impact file and the associated files are reconstructed.

3. The method for constructing a C++ code knowledge base according to claim 1, characterized in that: After the second persistence processing is implemented and the preset relational database is used as a C++ code knowledge base, the method further includes: Receive current query request information, and query the relationship type and specific index corresponding to the current query request information in the preset relationship database based on the preset multi-dimensional query interface; wherein the query request information includes: function name, class name, file name; The semantic mapping tables are queried based on the specific index to obtain detailed data corresponding to the current query request information.

4. The method for constructing a C++ code knowledge base according to claim 1, characterized in that: According to the C++ project configuration file of the C++ project source file, a compilation configuration file containing detailed compilation parameters is constructed, including: Parsing a C++ project configuration file of the C++ project source file to obtain compilation parameters of the C++ project configuration file; Completing the compilation parameters of the C++ project configuration file based on preset compilation parameter default values ​​to obtain completed detailed compilation parameters; The detailed compilation parameters are stored based on a preset format to obtain a compilation configuration file containing the detailed compilation parameters.

5. The method for constructing a C++ code knowledge base according to claim 1, characterized in that: Based on the preset script parsing engine, the file element corresponding to the compilation configuration file is parsed and obtained, and the C++ project source file is preprocessed to obtain the processed C++ project file, which specifically includes: Reading the compilation configuration file based on a preset script parsing engine to parse the compilation configuration file to obtain initial file elements corresponding to the compilation configuration file; wherein each file element includes: a working directory, a compilation command and a compilation file; Filtering the compile commands in the initial file element to obtain filtered compile commands and file elements; wherein the filtered compile commands have preprocessor options and language standard related commands; The C++ project source file is subjected to standardization processing to convert the encoding of the C++ project source file into the same character encoding format, to obtain a processed C++ project file, and to cache the processed C++ project file into a memory.

6. A method for constructing a C++ code knowledge base according to claim 5, characterized in that: Generating a compilation unit corresponding to the C++ project file based on the file element specifically includes: The working directory, the compile command and the compile file are used as parsing parameters to construct a corresponding code parsing environment according to the parsing parameters; In the code parsing environment, the grammar parsing library is called based on the preset script parsing engine to complete the grammar structure and context semantic information corresponding to the compiled file according to the same-directory dependency information of the working directory and other directory dependency information of the compile command; Based on the completed grammatical structure and contextual semantic information, a compilation unit corresponding to the C++ project file is generated.

7. The method for constructing a C++ code knowledge base according to claim 1, characterized in that: Obtaining dependency information of the C++ project file based on the compilation unit, and performing node filtering based on the abstract syntax tree of the C++ project file obtained by the compilation unit, so as to map and store the filtered nodes and the dependency information into a corresponding semantic mapping table, and implement the first persistence processing, specifically including: Determine whether the C++ project file includes a header file based on the compilation unit; If yes, extract the header file list directly referenced by the C++ project file, and recursively analyze the header file list to complete the dependency information; If not, obtaining an abstract syntax tree of the C++ project file to traverse the abstract syntax tree to complete the dependency information; A unique feature code is generated for each abstract syntax tree node, and duplicate nodes are filtered based on the feature code to store the completed dependency information and the filtered node mapping in the corresponding semantic mapping table to achieve the first persistence processing.

8. A method for constructing a C++ code knowledge base according to claim 7, characterized in that: Generate a unique feature code for each abstract syntax tree node, filter duplicate nodes based on the feature code, and store the completed dependency information and filtered node mappings in the corresponding semantic mapping table to implement the first persistence processing, which specifically includes: Performing a hash operation based on the component elements and file positions corresponding to each node in the abstract syntax tree to generate a unique feature code for each node of the abstract syntax tree; Determine whether there is a duplicate node in the abstract syntax tree based on the feature code, and if so, do not store the duplicate node; If not, the abstract syntax tree nodes are classified based on type, and the completed dependency information and the abstract syntax tree nodes are stored in a corresponding semantic mapping table based on a preset field rule.

9. A device for constructing a C++ code knowledge base, characterized in that: The device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can: execute any of the methods described in claims 1-8.

10. A non-volatile storage medium storing computer executable instructions, characterized in that: The computer executable instructions can: execute the method described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Knowledge graph construction method and device, electronic equipment and readable storage medium

    CN111914098A

  • Code conversion method and device for pre-compiler, medium, and equipment

    CN114035805A

  • Code searching method, device and equipment

    CN114625844A

  • Code index generation method, device and equipment and computer storage medium

    CN115114287A

  • Knowledge graph construction and query method and device, equipment, storage medium and product

    CN115827487A

Cited By

  • Code library increment updating method, system and equipment based on AI programming and medium

    CN121807353A