Code variable analysis method and device, electronic equipment and storage medium

By receiving analysis information, determining the reference relationship of code variables, obtaining all reference code files and analyzing it, the problem of inaccurate and incomplete code variable analysis in traditional methods is solved, and a higher quality code variable analysis is achieved.

CN120540701APending Publication Date: 2025-08-26BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510646198.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-19
Publication Date
2025-08-26

AI Technical Summary

Technical Problem

Traditional code variable analysis methods rely on a single code file and cannot provide complete context information of code variables throughout the program, resulting in inaccurate and comprehensive analysis results, affecting the code quality and usage experience.

Method used

By receiving analysis information, determine the reference relationship of the code variables to be analyzed, and obtain all reference code files based on this information. Use static analysis tools and LSP server to generate an abstract syntax tree, extract variable addresses and paths, generate a list of reference files, and perform code variable analysis.

Benefits of technology

It provides complete context information of code variables throughout the program, improves the accuracy and comprehensiveness of the analysis results, ensures the quality of the code, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120540701A_ABST
    Figure CN120540701A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code variable analysis method and device, electronic equipment and a storage medium. The code variable analysis method comprises the steps that analysis information is received; wherein the analysis information is used for tracking related data information of the reference relationship of the variables to be analyzed; determining all reference code files having a reference relationship with the to-be-analyzed code variable based on the analysis information; and performing code variable analysis on the to-be-analyzed code variable according to the reference code file to obtain a code variable analysis result. According to the technical scheme, all the reference code files having the reference relationship with the to-be-analyzed code variable can be determined based on the analysis information, the complete context information of the code variable in the whole program can be provided by analyzing the multiple reference code files, the data size related to the code variable is effectively increased, and the user experience is improved. Compared with a traditional method, the code variables are analyzed on the basis of the reference code file, the accuracy and comprehensiveness of the analysis result are improved, the code quality is ensured, and then the use experience feeling is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer data processing technology, and in particular to a code variable analysis method, device, electronic device, and storage medium. Background Art

[0002] During program development, code variable analysis is a critical step in ensuring code quality, maintainability, and performance optimization. However, traditional code variable analysis methods often rely on the contents of a single code file as the basis for analysis. This approach, which relies solely on a single code file for code variable analysis, often fails to provide the complete context of the code variable within the entire program. This can lead to omissions of relevant information, resulting in inaccurate and incomplete analysis results, making it impossible to ensure code quality and significantly impacting the user experience. Summary of the Invention

[0003] In view of this, in order to effectively alleviate the technical problem of inaccurate and incomplete analysis results brought about by relying on a single code file for code variable analysis in traditional methods, the embodiments of the present application provide a code variable analysis method, device, electronic device and storage medium.

[0004] In a first aspect, an embodiment of the present application provides a code variable analysis method, the method comprising:

[0005] Receiving analysis information; wherein the analysis information is relevant data information for tracking reference relationships of variables to be analyzed;

[0006] Determine all reference code files having a reference relationship with the code variable to be analyzed based on the analysis information;

[0007] Code variable analysis is performed on the code variables to be analyzed according to the reference code file to obtain code variable analysis results.

[0008] Optionally, as in the aforementioned method, the analysis information includes the variable name of the code variable to be analyzed, the code repository address, the variable definition file path and the code variable problem content.

[0009] Optionally, as in the aforementioned method, determining all referenced code files having a reference relationship with the code variable to be analyzed based on the analysis information includes:

[0010] Determine the variable definition file according to the code warehouse address and the variable definition file path;

[0011] Obtain a reference file list based on the variable definition file and the variable name;

[0012] All reference code files having a reference relationship with the code variable to be analyzed are determined according to the reference file list.

[0013] Optionally, as in the aforementioned method, determining the variable definition file according to the code repository address and the variable definition file path includes:

[0014] Accessing a code repository based on the code repository address; wherein the code repository stores all code files and the file paths corresponding to each of the code files;

[0015] Searching the code repository for a first target file path that matches the variable definition file path;

[0016] The code file corresponding to the first target file path is determined as a variable definition file.

[0017] Optionally, as in the aforementioned method, obtaining a reference file list based on the variable definition file and the variable name includes:

[0018] Converting the variable definition file into an abstract syntax tree using a static analysis tool; wherein the abstract syntax tree includes a plurality of tree nodes, each of which represents a syntax structure in the variable definition file;

[0019] Traversing the tree nodes of the abstract syntax tree to find a target tree node containing the variable name;

[0020] Extracting the variable address of the code variable to be analyzed from the target tree node; wherein the variable address refers to the specific location of the code variable to be analyzed in the variable definition file;

[0021] A reference file list is obtained based on the variable address and the variable definition file path.

[0022] Optionally, as in the aforementioned method, converting the variable definition file into an abstract syntax tree using a static analysis tool includes:

[0023] Load the variable definition file from the local into the memory;

[0024] Performing lexical analysis on the variable definition file stored in the memory to obtain a lexical unit stream;

[0025] Organizing the lexical unit stream into a grammatical structure to generate a preliminary grammar tree;

[0026] Abstract processing is performed on the preliminary syntax tree to obtain an abstract syntax tree.

[0027] Optionally, as in the aforementioned method, obtaining a reference file list based on the variable address and the variable definition file path includes:

[0028] Encapsulating the variable address and the variable definition file path into an LSP (Language Server Protocol) request;

[0029] Sending the LSP request to an LSP server to trigger the LSP server to parse the LSP request to obtain the variable address and the variable definition file path; searching the code repository for all reference locations that reference the code variable to be analyzed based on the variable address and the variable definition file path; extracting the reference file path included in each reference location; and generating a reference file list based on each reference file path; wherein the reference location refers to the specific location of the code variable to be analyzed in the code file;

[0030] Obtain the reference file list sent by the LSP server.

[0031] Optionally, as in the aforementioned method, determining all reference code files having a reference relationship with the code variable to be analyzed according to the reference file list includes:

[0032] Searching the code repository for a second target file path that matches the reference file path in the reference file list;

[0033] The code file corresponding to the second target file path is determined as a reference code file having a reference relationship with the code variable to be analyzed.

[0034] Optionally, as in the aforementioned method, performing code variable analysis on the code variable to be analyzed according to the reference code file to obtain a code variable analysis result includes:

[0035] Read the reference code file to obtain the reference code file content;

[0036] The variable name, the code variable problem content and the referenced code file content are input into a code variable analysis model, and the code variable analysis model outputs a code variable analysis result; wherein, the code variable analysis model is a pre-trained large model for analyzing code variables.

[0037] In a second aspect, an embodiment of the present application provides a code variable analysis device, the device comprising:

[0038] A receiving module, configured to receive analysis information; wherein the analysis information is relevant data information for tracking reference relationships of variables to be analyzed;

[0039] a determination module, configured to determine, based on the analysis information, all reference code files having a reference relationship with the code variable to be analyzed;

[0040] The analysis module is used to perform code variable analysis on the code variables to be analyzed according to the reference code file to obtain code variable analysis results.

[0041] In a third aspect, an embodiment of the present application provides an electronic device, which includes: a processor and a memory, and the processor is used to execute a code variable analysis program stored in the memory to implement the above-mentioned code variable analysis method.

[0042] In a fourth aspect, an embodiment of the present application provides a storage medium, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned code variable analysis method.

[0043] The code variable analysis method, device, electronic device and storage medium provided in the embodiment of the present application include: receiving analysis information; wherein the analysis information is relevant data information for tracking the reference relationship of the variable to be analyzed; determining all reference code files that have a reference relationship with the code variable to be analyzed based on the analysis information; performing code variable analysis on the code variable to be analyzed according to the reference code files to obtain the code variable analysis result. In the above technical solution, all reference code files that have a reference relationship with the code variable to be analyzed can be determined based on the analysis information. By analyzing multiple reference code files, the complete context information of the code variable in the entire program can be provided, effectively amplifying the amount of data related to the code variable. Compared with the traditional method of relying on a single code file to perform code variable analysis, the present application analyzes the code variables based on the above reference code files. This application improves the accuracy and comprehensiveness of the analysis results, ensures the code quality, and thus greatly improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0046] Figure 1 A flowchart of an embodiment of a code variable analysis method provided in an embodiment of the present application;

[0047] Figure 2 A flowchart of another embodiment of a code variable analysis method provided in an embodiment of the present application;

[0048] Figure 3 A flowchart of another embodiment of a code variable analysis method provided in an embodiment of the present application;

[0049] Figure 4 A flowchart of another embodiment of a code variable analysis method provided in an embodiment of the present application;

[0050] Figure 5 A flowchart of another embodiment of a code variable analysis method provided in an embodiment of the present application;

[0051] Figure 6 A block diagram of an embodiment of a code variable analysis device provided in an embodiment of the present application;

[0052] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0053] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0054] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0055] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0056] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.

[0057] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0058] It should be understood that the size of the serial numbers of the steps in the following embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0059] To facilitate understanding of the embodiments of the present application, further explanation will be given below with reference to specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present application.

[0060] The present application embodiment provides a code variable analysis method, which is applicable to a code variable analysis system. Figure 1 , Figure 1 A flowchart of an embodiment of a code variable analysis method provided in an embodiment of the present application. Figure 1 The process shown may include the following steps:

[0061] Step 101, receiving analysis information;

[0062] Among them, analysis information is relevant data information used to track the reference relationship of the variables to be analyzed; in actual application, users can submit analysis information to the code variable analysis system through the front-end interface (such as Web (World Wide Web) form, API (Application Programming Interface) request or command line tool).

[0063] Step 102: determining all reference code files that have a reference relationship with the code variable to be analyzed based on the analysis information;

[0064] In programming, project code is usually composed of multiple loosely coupled code files. The reference relationships between code variables may be scattered in different code files, and the explicit association between code files is weak. This discreteness makes tracking variable references complicated. In this embodiment, all referenced code files that have a reference relationship with the code variable to be analyzed can be determined through the analysis information received in step 101. Through this method, even if the code files are loosely coupled, variable references can still be systematically and automatically located, providing a reliable basis for subsequent code variable analysis.

[0065] Step 103: performing code variable analysis on the code variables to be analyzed according to the referenced code file to obtain code variable analysis results.

[0066] In this embodiment, after obtaining all reference code files that have a reference relationship with the code variable to be analyzed in step 102, the code variable analysis system provides complete context information of the code variable to be analyzed in the entire program by analyzing all reference code files that reference the code variable to be analyzed. This can effectively expand the amount of data related to the code variable to be analyzed, so that the code variable analysis results can be obtained by fully analyzing the code variable to be analyzed based on the above-mentioned reference code files. This code variable analysis method can effectively expand the relevant information of the code variable to be analyzed in the program, thereby alleviating the limitations of traditional single code file analysis.

[0067] In programming, code variables cover a wide range of named entities that store data or states. In addition to API interface parameters, common variable types also include the following categories, such as local variables, global variables, function / method parameters, system-level variables, etc., which are not listed here one by one. Therefore, the above-mentioned code variable analysis system can apply the code variable analysis method proposed in this application to all code variables in programming for analysis.

[0068] Through the method in this embodiment, all reference code files that have a reference relationship with the code variable to be analyzed can be determined based on the analysis information. By analyzing multiple reference code files, complete context information of the code variable in the entire program can be provided, effectively expanding the amount of data related to the code variable. Compared with the traditional method of relying on a single code file to analyze code variables based on the above-mentioned reference code files, this application improves the accuracy and comprehensiveness of the analysis results, ensures the code quality, and thus greatly improves the user experience.

[0069] In this embodiment, the above analysis information includes the variable name of the code variable to be analyzed, the code repository address, the variable definition file path, and the code variable problem content. To ensure the reliability and accuracy of the analysis results, attention should be paid to the accuracy of the variable name of the code variable to be analyzed submitted to the code variable analysis system to avoid invalid analysis. In specific implementation, case sensitivity issues should be avoided. For example, in Python, Config and config are two independent code variables. If case is ignored during submission, the code variable analysis system cannot determine which code variable the user is analyzing, resulting in incorrect analysis. In addition, attention should also be paid to the ambiguity of model names. For example, if the variable name submitted is data, the code variable analysis system may simultaneously match irrelevant code segments such as database connection and log storage, resulting in contamination of the analysis results.

[0070] In specific implementations, in order to completely eliminate naming ambiguity and achieve accurate code variable analysis, it is not enough to submit only the variable name. The functional description of the code variable to be analyzed must also be submitted simultaneously. For example, the variable type of JavaScript / Python may not be determined until runtime, and the behavior cannot be inferred from the variable name alone. The functional description can supplement the type constraint (such as "this parameter should receive an integer HTTP (HyperText Transfer Protocol) status code"). Therefore, the above analysis information should also include the functional description.

[0071] The code repository address refers to the remote repository location where code files are stored, usually presented in the form of a URL (Uniform Resource Locator); the variable definition file path refers to the specific location (directory structure in the code repository) of the code file that stores variable declarations or definitions. It is used to clearly specify the storage location of the file.

[0072] Code variable problem content is the core part of code variable analysis. It is used to identify potential defects in the definition and use of code variables and provide optimization suggestions to improve the readability, security, accuracy and maintainability of the code. The specific code variable problem content refers to the specific problem description and optimization suggestions raised when analyzing code variables regarding the accuracy of their variable definitions (names, types, scopes, etc.) or the rationality of their use (such as logical correctness, necessity, performance impact, etc.), so that the code variable analysis system can clearly understand the specific analysis issues.

[0073] Based on the above, if Figure 2 As shown, as an optional implementation, as in the aforementioned method, step 102 of determining all reference code files having a reference relationship with the code variable to be analyzed based on the analysis information includes the following steps:

[0074] Step 201, determining the variable definition file according to the code repository address and the variable definition file path;

[0075] like Figure 3 As shown, as an optional implementation, the implementation process of step 201 can be implemented through the following steps:

[0076] Step 301: access the code repository based on the code repository address;

[0077] In practice, you can clone or remotely access a code repository based on its address using command-line tools, graphical tools, or the code hosting platform's website. This allows you to retrieve all code files stored in the repository, along with the file paths corresponding to each file. For local analysis, you can use git clone to download the entire repository locally. To simply read files, some tools (such as the GitHub API) support direct remote access.

[0078] Step 302: Search the code repository for a first target file path that matches the variable definition file path.

[0079] Since the file path corresponding to each code file in the code repository is unique, the variable definition file can be found from multiple code files through the variable definition file path. In specific implementation, all file paths can be recursively listed through gitls-files or the file system API, and then regular expressions or wildcard libraries (such as glob) can be used to filter out the first target file path that matches the variable definition file path.

[0080] Step 303: determine the code file corresponding to the first target file path as a variable definition file.

[0081] The code file corresponding to the first target file path found in step 302 is determined as the variable definition file for subsequent use in obtaining a reference file list. This method of directly determining the variable definition file by path matching can avoid manual search and reduce errors.

[0082] Step 202: Obtain a reference file list based on the variable definition file and the variable name;

[0083] like Figure 4 As shown, as an optional implementation, the implementation process of step 202 can be implemented through the following steps:

[0084] Step 401, using a static analysis tool to convert the variable definition file into an abstract syntax tree;

[0085] Among them, the abstract syntax tree includes multiple tree nodes, each tree node represents a syntax structure in the variable definition file; the abstract syntax tree strips away redundant symbols (such as brackets and semicolons) in the variable definition file in a tree structure, retaining only key syntax elements such as variable definitions and expressions, and represents the code logic with a hierarchical relationship of the tree, realizing accurate semantic analysis and automated processing, which is convenient for subsequent use.

[0086] The specific process of converting the variable definition file into an abstract syntax tree can be achieved through steps A1 to A4:

[0087] Step A1: Load the variable definition file from the local computer into the memory.

[0088] In actual applications, in order to speed up the loading speed, the code repository needs to be downloaded locally, and then the variable definition file stored locally is loaded into the memory to avoid network delays and reduce the overhead of repeatedly downloading the code repository.

[0089] Step A2, performing lexical analysis on the variable definition file stored in the memory to obtain a lexical unit stream;

[0090] Specifically, a lexer (lexer / scanner) can be used to scan the source code strings in the variable definition file, so as to ignore irrelevant content (such as spaces, comments) and decompose the continuous character sequence into meaningful lexical units to obtain an ordered lexical unit stream. Each lexical unit includes type and value (the value is the specific text content corresponding to the lexical unit) information. For variable definition files, since the variable definition file systematically records the complete definition information of each code variable, the types that may be identified include: keywords (such as var, let, const, etc.), identifiers (variable names), operators (=, :, etc.), separators (commas, semicolons, brackets, etc.), literals (numbers, strings, etc.), etc.

[0091] Step A3: Organize the lexical unit stream into a grammatical structure and generate a preliminary grammar tree;

[0092] This process can use a parser to receive a stream of lexical units as input, analyze the lexical unit sequence according to the grammatical rules of the language (usually described in BNF or similar forms) to construct a preliminary syntax tree (also called a concrete syntax tree or parse tree). Since the preliminary syntax tree usually contains more grammatical details and may contain redundancy, it is necessary to perform the subsequent step A4 to remove the redundancy.

[0093] Step A4: abstract the preliminary syntax tree to obtain an abstract syntax tree.

[0094] Unify the semantic expression, remove nodes that are only used for grammatical structure but do not carry semantic information to remove unnecessary grammatical details (such as pure grammatical elements such as semicolons and brackets), retain the core elements of the code logical structure, and convert the preliminary syntax tree into a more abstract representation. This abstract processing not only retains the complete program semantics, but also avoids the interference of specific grammatical details, which is convenient for subsequent applications.

[0095] Step 402, traverse the tree nodes of the abstract syntax tree to find the target tree node containing the variable name;

[0096] Since each tree node includes the type of identifier (variable name), the target tree node can be found from multiple tree nodes of the abstract syntax tree by matching the identifier with the variable name.

[0097] Step 403: extract the variable address of the code variable to be analyzed from the target tree node;

[0098] Among them, the variable address refers to the specific position of the code variable to be analyzed in the variable definition file. In this embodiment, the row number and column number of the code variable to be analyzed in the variable definition file, that is, the variable address, can be obtained by directly accessing the position information attributes (row number and column offset) of the target tree node.

[0099] Step 404: Obtain a reference file list based on the variable address and the variable definition file path.

[0100] The specific process of obtaining the reference file list can be achieved through steps B1 to B3:

[0101] Step B1, encapsulate the variable address and variable definition file path into an LSP request;

[0102] In specific implementation, the variable definition file path needs to be converted into URI (Uniform Resource Identifier) ​​encoding format to avoid special character conflicts, and the variable address needs to be consistent with the LSP server convention (usually counting starts from 0 or 1) and then encapsulated into an LSP request for parsing by the LSP server.

[0103] Step B2: Send the LSP request to the LSP server to trigger the LSP server to parse the LSP request to obtain the variable address and variable definition file path, search the code repository for all reference locations that reference the code variable to be analyzed based on the variable address and variable definition file path, extract the reference file path included in each reference location, and generate a reference file list based on each reference file path; wherein the reference location refers to the specific location of the code variable to be analyzed in the code file;

[0104] The LSP (Language Server Protocol) server is an independent process that provides language intelligence services for development tools. Its core function is to realize code reference positioning. Therefore, the LSP server can be used to generate a reference file list. In specific implementation, after receiving the LSP request, the LSP server parses it to obtain the variable address and variable definition file path, and finds the code variable to be analyzed in the variable definition file based on the variable address and variable definition file path. After that, the LSP server needs to scan the entire code repository (including dependent files) to search for all reference locations that reference the code variable to be analyzed to ensure that no references are missed. Since the reference location includes the reference file path and the specific location (line number and column number), the LSP server summarizes the reference file paths in all reference locations to generate a reference file list.

[0105] In actual applications, in order to make messages persistent and avoid data loss, the generated reference file list can be cached and written to a message queue (such as Kafka, RabbitMQ, etc.).

[0106] Step B3: Obtain the reference file list sent by the LSP server.

[0107] The LSP server sends the generated reference file list to the code variable analysis system, so that the code variable analysis system can use the reference file list to perform subsequent step 203.

[0108] Step 203: Determine all reference code files that have a reference relationship with the code variable to be analyzed according to the reference file list.

[0109] The specific process of determining the reference code file can be achieved through steps C1 to C3:

[0110] Step C1, searching the code repository for a second target file path that matches the reference file path in the reference file list;

[0111] Similarly, you can use gitls-files or the file system API to recursively list all file paths in the code repository, and then use regular expressions or wildcard libraries (such as glob) to filter out the second target file path that matches the reference file path in the reference file list.

[0112] Step C2: determining the code file corresponding to the second target file path as a reference code file having a reference relationship with the code variable to be analyzed.

[0113] The code file corresponding to the second target file path found in step C2 is determined as a variable definition file to provide a data basis for subsequent code variable analysis.

[0114] like Figure 5 As shown, as an optional implementation, as in the aforementioned method, step 103 performs code variable analysis on the code variables to be analyzed according to the referenced code file, and obtaining the code variable analysis results includes the following steps:

[0115] Step 501: Read the reference code file to obtain the reference code file content;

[0116] The reference code file is read to read the source code in the reference code file, that is, the content of the reference code file.

[0117] Step 502: Input the variable name, code variable problem content and referenced code file content into the code variable analysis model, and the code variable analysis model outputs the code variable analysis result.

[0118] Since the current large models (ChatGPT, DeepSeek, Wenxinyiyan, etc.) all have code analysis functions, the above-mentioned code variable analysis model is a pre-trained large model for analyzing code variables. In traditional technology, the user only inputs the content of a single file into the code variable analysis model as the basis for analysis. Due to the lack of analysis materials, it is impossible to provide complete context information of the code variable in the entire program, resulting in insufficient analysis accuracy. In order to improve the analysis accuracy of the code variable analysis model, in this embodiment, all referenced code files associated with the code variable to be analyzed are first analyzed through static code analysis, and a more complete file call relationship is established. This is used as the context environment of the code variable analysis model for analysis to improve the accuracy of the large model code analysis.

[0119] The training process of the variable analysis model in the above code is as follows:

[0120] Step 1: Obtain a training sample set; wherein each training sample in the training sample set is composed of analysis information and a label of the corresponding code variable analysis result;

[0121] Step 2: Input the historical analysis information of each training sample into the large model to obtain the corresponding relationship between the analysis information identified by the large model and the code variable analysis results;

[0122] Step 3: Determine whether the large model has converged based on the corresponding relationship identified by the large model and the label corresponding to each sample combination;

[0123] Step 4: If the large model converges, the large model is determined as the trained code variable analysis model;

[0124] Step 5: If the large model has not converged, adjust the model parameters of the large model and return to step 2.

[0125] Based on the trained code variable analysis model, in this step 502, the variable name, code variable problem content and referenced code file content can be input into the pre-trained code variable analysis model to obtain the code variable analysis result.

[0126] The code variable analysis results are responses to specific code variable issues generated by the code variable analysis system after a systematic analysis of the code variable being analyzed. For example, the code variable being analyzed is the API parameter token. The code variable question for token is: Is the token type correct in the program? After thorough analysis by the code variable analysis system, the code variable analysis result is: The token type in the program is incorrect, and it is recommended to change the type to string.

[0127] The technical solution provided by the embodiment of the present invention has the advantages of being lightweight and having a fast processing speed. Therefore, the code variable analysis results can be obtained conveniently and quickly through the trained code variable analysis model. Moreover, the code variable analysis model can analyze multiple reference code files, fully provide complete context information of the code variables in the entire program, and effectively amplify the amount of data related to the code variables. Compared with the traditional method of relying on a single code file to perform code variable analysis, this application analyzes code variables based on the above-mentioned reference code files. This application improves the accuracy and comprehensiveness of the analysis results, ensures the code quality, and thus greatly improves the user experience.

[0128] See also Figure 6 , is a block diagram of an embodiment of a code variable analysis device provided in an embodiment of the present application. Figure 6 As shown, the device includes:

[0129] Receiving module 601, for receiving analysis information; wherein the analysis information is related data information used to track the reference relationship of the variables to be analyzed;

[0130] A determination module 602 is configured to determine, based on the analysis information, all reference code files that have a reference relationship with the code variable to be analyzed;

[0131] The analysis module 603 is configured to perform code variable analysis on the code variables to be analyzed according to the referenced code file to obtain code variable analysis results.

[0132] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0133] As an optional implementation, the analysis information includes the variable name of the code variable to be analyzed, the code repository address, the variable definition file path, and the code variable problem content.

[0134] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0135] As an optional implementation, the determining module 602 further includes:

[0136] A first determining module is used to determine the variable definition file according to the code warehouse address and the variable definition file path;

[0137] A first acquisition module is used to acquire a reference file list based on the variable definition file and the variable name;

[0138] The second determining module is configured to determine, according to the reference file list, all reference code files having a reference relationship with the code variable to be analyzed.

[0139] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0140] As an optional implementation manner, the first determining module is further configured to:

[0141] Access the code repository based on the code repository address; the code repository stores all code files and the file paths corresponding to each code file;

[0142] Find the first target file path that matches the variable definition file path from the code repository;

[0143] The code file corresponding to the first target file path is determined as the variable definition file.

[0144] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0145] As an optional implementation manner, the first acquisition module further includes:

[0146] a conversion module, configured to convert the variable definition file into an abstract syntax tree using a static analysis tool; wherein the abstract syntax tree includes a plurality of tree nodes, each tree node representing a syntax structure in the variable definition file;

[0147] A search module, used for traversing the tree nodes of the abstract syntax tree and searching for a target tree node containing a variable name;

[0148] An extraction module is used to extract the variable address of the code variable to be analyzed from the target tree node; wherein the variable address refers to the specific location of the code variable to be analyzed in the variable definition file;

[0149] The second acquisition module is used to acquire a reference file list based on the variable address and the variable definition file path.

[0150] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0151] As an optional implementation, the above-mentioned conversion module is further used to:

[0152] Load the variable definition file from the local into the memory;

[0153] Performing lexical analysis on the variable definition file stored in the memory to obtain a lexical unit stream;

[0154] Organize the lexical unit stream into a grammatical structure and generate a preliminary grammar tree;

[0155] Perform abstract processing on the preliminary syntax tree to obtain an abstract syntax tree.

[0156] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0157] As an optional implementation manner, the second acquisition module is further configured to:

[0158] Encapsulate the variable address and variable definition file path into an LSP request;

[0159] Send the LSP request to the LSP server to trigger the LSP server to parse the LSP request to obtain the variable address and variable definition file path, find all reference locations of the code variables to be analyzed from the code repository based on the variable address and variable definition file path, and extract the reference file path included in each reference location.

[0160] Generate a reference file list based on each reference file path; the reference location refers to the specific location of the code variable to be analyzed in the code file;

[0161] Get the reference file list sent by the LSP server.

[0162] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0163] As an optional implementation manner, the second determining module is further configured to:

[0164] Searching the code repository for a second target file path that matches the reference file path in the reference file list;

[0165] The code file corresponding to the second target file path is determined as a reference code file having a reference relationship with the code variable to be analyzed.

[0166] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0167] As an optional implementation, the analysis module 603 is further configured to:

[0168] Read the reference code file to obtain the content of the reference code file;

[0169] The variable name, code variable problem content and referenced code file content are input into the code variable analysis model, and the code variable analysis model outputs the code variable analysis results; wherein the code variable analysis model is a pre-trained large model for analyzing code variables.

[0170] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7The electronic device 1200 shown includes: at least one processor 1201, a memory 1202, at least one network interface 1204 and another user interface 1203. The various components in the electronic device 1200 are coupled together via a bus system 1205. It is understood that the bus system 1205 is used to achieve connection and communication between these components. In addition to including a data bus, the bus system 1205 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, the bus system 1205 is not described in detail. Figure 7 Various buses are labeled as bus system 1205.

[0171] The user interface 1203 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touchpad, or a touch screen).

[0172] It is understood that the memory 1202 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDRSDRAM), enhanced synchronous DRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 1202 described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0173] In some embodiments, the memory 1202 stores the following elements, executable units, or data structures, or a subset thereof, or an extended set thereof: an operating system 12021 and application programs 12022 .

[0174] Among them, the operating system 12021 includes various system programs, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and handle hardware-based tasks. Application 12022 includes various application programs, such as media players and browsers, which are used to implement various application services. The program that implements the method of the embodiment of the present application can be included in application 12022.

[0175] In an embodiment of the present application, by calling a program or instruction stored in the memory 1202, specifically, a program or instruction stored in the application 12022, the processor 1201 is used to execute the method steps provided by each method embodiment.

[0176] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1201. Processor 1201 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in processor 1201 or by software instructions. The above processor 1201 may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software units in the decoding processor. The software units can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory 1202 , and the processor 1201 reads the information in the memory 1202 and completes the steps of the above method in combination with its hardware.

[0177] It is understood that the embodiments described herein may be implemented using hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or a combination thereof.

[0178] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.

[0179] The electronic device provided in this embodiment may be Figure 7 The electronic device shown in FIG. 1 can perform the following operations: Figure 1-5 All steps of the code variable analysis method are implemented Figure 1-5 For details on the technical effects of the code variable analysis method shown, please refer to Figure 1-5 For the sake of brevity, the relevant description will not be repeated here.

[0180] The present application also provides a storage medium (computer-readable storage medium). The storage medium stores one or more programs. The storage medium may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; and the memory may also include a combination of the aforementioned types of memory.

[0181] When one or more programs in the storage medium can be executed by one or more processors, the above-mentioned code variable analysis method can be implemented.

[0182] The processor is used to execute the code variable analysis program stored in the memory to implement the steps of the code variable analysis method.

[0183] Professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0184] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0185] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of this application. It should be understood that the above description is only the specific implementation methods of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this application should be included in the scope of protection of this application.

Claims

1. A code variable analysis method, characterized in that: The method comprises: Receiving analysis information; wherein the analysis information is relevant data information for tracking reference relationships of variables to be analyzed; Determine all reference code files having a reference relationship with the code variable to be analyzed based on the analysis information; Code variable analysis is performed on the code variables to be analyzed according to the reference code file to obtain code variable analysis results.

2. The method according to claim 1, characterized in that The analysis information includes the variable name of the code variable to be analyzed, the code repository address, the variable definition file path and the code variable problem content.

3. The method according to claim 2, characterized in that The determining, based on the analysis information, all reference code files having a reference relationship with the code variable to be analyzed includes: Determine the variable definition file according to the code warehouse address and the variable definition file path; Obtain a reference file list based on the variable definition file and the variable name; All reference code files having a reference relationship with the code variable to be analyzed are determined according to the reference file list.

4. The method according to claim 3, characterized in that The determining the variable definition file according to the code repository address and the variable definition file path includes: Accessing a code repository based on the code repository address; wherein the code repository stores all code files and the file paths corresponding to each of the code files; Searching the code repository for a first target file path that matches the variable definition file path; The code file corresponding to the first target file path is determined as a variable definition file.

5. The method according to claim 4, characterized in that The obtaining of a reference file list based on the variable definition file and the variable name includes: Converting the variable definition file into an abstract syntax tree using a static analysis tool; wherein the abstract syntax tree includes a plurality of tree nodes, each of which represents a syntax structure in the variable definition file; Traversing the tree nodes of the abstract syntax tree to find a target tree node containing the variable name; Extracting the variable address of the code variable to be analyzed from the target tree node; wherein the variable address refers to the specific location of the code variable to be analyzed in the variable definition file; A reference file list is obtained based on the variable address and the variable definition file path.

6. The method according to claim 5, characterized in that The step of converting the variable definition file into an abstract syntax tree using a static analysis tool includes: Load the variable definition file from the local into the memory; Performing lexical analysis on the variable definition file stored in the memory to obtain a lexical unit stream; Organizing the lexical unit stream into a grammatical structure to generate a preliminary grammar tree; Abstract processing is performed on the preliminary syntax tree to obtain an abstract syntax tree.

7. The method according to claim 5, characterized in that The obtaining of a reference file list based on the variable address and the variable definition file path includes: Encapsulate the variable address and the variable definition file path into an LSP request; Sending the LSP request to an LSP server to trigger the LSP server to parse the LSP request to obtain the variable address and the variable definition file path; searching the code repository for all reference locations that reference the code variable to be analyzed based on the variable address and the variable definition file path; extracting the reference file path included in each reference location; and generating a reference file list based on each reference file path; wherein the reference location refers to the specific location of the code variable to be analyzed in the code file; Obtain the reference file list sent by the LSP server.

8. The method according to claim 7, characterized in that The step of determining all reference code files having a reference relationship with the code variable to be analyzed according to the reference file list includes: Searching the code repository for a second target file path that matches the reference file path in the reference file list; The code file corresponding to the second target file path is determined as a reference code file having a reference relationship with the code variable to be analyzed.

9. The method according to claim 2, characterized in that The performing code variable analysis on the code variable to be analyzed according to the reference code file to obtain a code variable analysis result includes: Read the reference code file to obtain the reference code file content; The variable name, the code variable problem content and the referenced code file content are input into a code variable analysis model, and the code variable analysis model outputs a code variable analysis result; wherein, the code variable analysis model is a pre-trained large model for analyzing code variables.

10. A code variable analysis device, characterized in that: The device comprises: A receiving module, configured to receive analysis information; wherein the analysis information is relevant data information for tracking reference relationships of variables to be analyzed; a determination module, configured to determine, based on the analysis information, all reference code files having a reference relationship with the code variable to be analyzed; The analysis module is used to perform code variable analysis on the code variables to be analyzed according to the reference code file to obtain code variable analysis results.

11. An electronic device, characterized in that: include: A processor and a memory, wherein the processor is configured to execute a code variable analysis program stored in the memory to implement the code variable analysis method according to any one of claims 1 to 9.

12. A storage medium, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the code variable analysis method according to any one of claims 1 to 9.