Code processing method and related device
Through distributed storage and parallel analysis of multiple devices, the problem of the intermediate representation file occupies a lot of memory resources, and efficient storage and fast code analysis are achieved.
Patent Information
- Application Number
- CN202410166085.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-05
- Publication Date
- 2025-08-05
AI Technical Summary
In the prior art, the data volume of the intermediate representation file is large and occupies a lot of memory resources, which makes it difficult to efficiently complete code analysis.
By storing the intermediate representation file in distributed storage, each code field matches the first identification of the storage object, data is stored in the target storage object, and defect detection and analysis are performed in parallel through multiple devices to obtain code analysis results.
It realizes efficient storage and analysis of intermediate representation files, reduces memory usage, improves data access speed and efficiency, and supports efficient code analysis.
Smart Images

Figure CN120429010A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a code processing method and related devices. Background Art
[0002] With the continuous advancement of software development technology and application requirements, the amount of code in software is also increasing, reaching gigabytes (GB) or even tens of GB. Program analysis is the process of performing static or dynamic analysis on computer programs to obtain information about program behavior, performance, security, and quality. In program analysis, the code representation that can be used to convert and analyze between source code and target code is called an intermediate representation (IR). It is an abstract representation used in compilers or static analysis tools. Therefore, code analysis of the intermediate representation file facilitates the optimization of the subsequently generated target code.
[0003] However, current code inspection methods for intermediate representation files typically involve a single machine directly reading and analyzing the intermediate representation files stored in memory. However, due to the large data volume of intermediate representation files and their high memory usage, a single machine requires a lot of computing resources and time to analyze them, resulting in low access efficiency and difficulty in completing code analysis efficiently. Summary of the Invention
[0004] The embodiments of the present application provide a code processing method and related devices for implementing distributed storage of intermediate representation files, improving storage efficiency, and increasing data access speed and efficiency, thereby achieving efficient completion of code analysis.
[0005] In a first aspect, an embodiment of the present application provides a method for code processing. The method includes: obtaining an intermediate representation file corresponding to a source code file; based on each code field in the intermediate representation file and the first identifier of each storage object in a plurality of storage objects, determining the target storage object corresponding to each code field from the plurality of storage objects, each first identifier is used to identify a storage object, and there is a cross-reference relationship between the plurality of storage objects; storing the data of each code field in the target storage object corresponding to the code field, so as to store the intermediate representation file through the plurality of target storage objects; receiving a first analysis result sent by each first device in a plurality of first devices, wherein the first analysis result sent by each first device is a result obtained by the corresponding first device performing defect detection analysis on the data of the code field stored in one or more target storage objects; and obtaining a code analysis result of the intermediate representation file based on the first analysis results sent by the plurality of first devices.
[0006] In a second aspect, an embodiment of the present application provides a code processing device. The code processing device includes an acquisition unit and a processing unit. Exemplarily, it may also include a sending unit. The acquisition unit is configured to acquire an intermediate representation file corresponding to a source code file. The processing unit is configured to determine, based on each code field in the intermediate representation file and a first identifier of each storage object in a plurality of storage objects, multiple target storage objects for the intermediate representation file, each first identifier being used to identify a storage object, and a cross-reference relationship between the multiple storage objects. The processing unit is configured to store the data of each code field in the target storage object corresponding to the code field, so as to store the intermediate representation file through the multiple target storage objects. The acquisition unit is configured to receive a first analysis result sent by each first device among a plurality of first devices, wherein the first analysis result sent by each first device is a result obtained by the corresponding first device performing defect detection analysis on the data of the code fields stored in one or more target storage objects; based on the first analysis results sent by the plurality of first devices, the processing unit is configured to obtain a code analysis result for the intermediate representation file based on the first analysis results sent by the plurality of first devices.
[0007] In some optional embodiments, each storage object also includes a second identifier; based on the first identifiers and second identifiers of multiple storage objects, a cross-reference relationship is obtained, wherein, in the first storage object and the second storage object corresponding to the cross-reference relationship, the second identifier of the first storage object is the same as the first identifier of the second storage object, and the first storage object and the second storage object are two storage objects among the multiple storage objects.
[0008] In other optional embodiments, the storage object includes a data table in a database cluster, and the first identifier includes a primary key field of the data table; the processing unit is used to: match each code field in the intermediate representation file with the primary key field of each data table in multiple data tables to determine the target primary key field corresponding to each code field; determine the data table corresponding to each target primary key field as the target data table corresponding to the code field matching the target primary key field; store the data corresponding to each code field in the target data table corresponding to each corresponding code field, so that the intermediate representation file is stored in multiple target data tables.
[0009] In other optional embodiments, the processing unit is used to: extract the primary key field of each data table, each primary key field is used to identify the corresponding data table; when the first code field matches the primary key field of the first data table, determine that the primary key field of the first data table is the target primary key field corresponding to the first code field, the first code field is any code field, and the first data table is one of the multiple data tables; determine the first data table as the target data table corresponding to the first code field.
[0010] In other optional embodiments, the storage object includes a file in a file system, and the first identifier includes a file index of the file; the processing unit is used to: serialize the intermediate representation file to obtain a corresponding byte stream; match each code field in the byte stream with multiple file indexes to determine the target file index corresponding to each code field, wherein the multiple file indexes include the file index of each file in the file; determine the file corresponding to each target file index as the target file corresponding to the code field matching the target file index; store the data corresponding to each code field in the target file corresponding to each code field, so that the intermediate representation file is stored in multiple target files.
[0011] In some other optional embodiments, the processing unit is further configured to extract data corresponding to the code field from each target storage object before receiving the first analysis result sent by each of the plurality of first devices. The sending unit is configured to send the data of the one or more code fields to each of the first devices.
[0012] In some other optional implementations, the defect detection analysis includes one or more of a security check process, a defect check process, a code specification check process, and a grammar check process.
[0013] In other optional implementations, the processing unit is used to obtain a source code file, parse the source code file, and generate an abstract syntax tree; traverse the abstract syntax tree to obtain corresponding syntax elements; analyze the types of the syntax elements, and encode the corresponding syntax elements based on the types of the syntax elements to obtain encoded syntax elements; and generate an intermediate representation file corresponding to the source code file based on the encoded syntax elements.
[0014] In other optional implementations, the processing unit is used to: perform lexical analysis on the source code file to determine at least one lexical unit; perform syntactic analysis on each lexical unit to determine the corresponding grammatical element, and generate an abstract syntax tree based on the grammatical element.
[0015] In some other optional implementations, the processing unit is configured to: scan characters in a source code file to obtain a character string to be processed; and mark the character string to be processed to determine at least one lexical unit.
[0016] In some other optional implementations, the processing unit is used to: parse the sentence corresponding to each lexical unit to obtain the grammatical elements in the corresponding sentence; and generate an abstract syntax tree based on the sentence and grammatical elements corresponding to each lexical unit.
[0017] A third aspect of the present application provides a code processing device, comprising: a memory, an input / output (I / O) interface, and a memory. The memory is configured to store program instructions. A processor is configured to execute the program instructions in the memory to perform the code processing method corresponding to the embodiment of the first aspect described above.
[0018] A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores instructions. When the computer-readable storage medium is run on a computer, it enables the computer to execute the method corresponding to the implementation method of the first aspect above.
[0019] The fifth aspect of the embodiments of the present application provides a computer program product containing instructions, which, when run on a computer or processor, enables the computer or processor to execute the above-mentioned method corresponding to the implementation method of the first aspect.
[0020] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0021] In an embodiment of the present application, after obtaining an intermediate representation file corresponding to a source code file, a target storage object corresponding to each code field in the intermediate representation file and a first identifier of each storage object in a plurality of storage objects are determined from the plurality of storage objects. Each first identifier identifies a storage object, and a cross-reference relationship is stored between the plurality of storage objects. Thus, the data of each code field is stored in the target storage object corresponding to the code field, and storage processing of the intermediate representation file is completed via these multiple target storage objects. Then, a first analysis result transmitted by each of the plurality of first devices is received, and a code analysis result of the intermediate representation file is determined based on the first analysis results transmitted by these multiple first devices. The first analysis result transmitted by each first device is the result of defect detection analysis performed by the corresponding first device on the data of the code fields stored in one or more target storage objects. In other words, in this embodiment of the present application, multiple target storage objects for storing the intermediate representation file are determined by matching the code fields in the intermediate representation file with the first identifiers of the storage objects, so that the data of each code field in the intermediate representation file can be stored using a single target storage object. Furthermore, defect detection analysis of the data of these multiple code fields is performed in parallel by the multiple first devices. Through the above method, on the one hand, distributed storage of intermediate representation files is realized, storage efficiency is improved, and the memory resources occupied by intermediate representation files are reduced; on the other hand, multiple first devices can use fewer computing resources and computing time to analyze the data of code fields stored in different target storage objects in parallel, so that data access speed and efficiency can be improved, which facilitates the subsequent efficient completion of code analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application 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, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0023] Figure 1 A schematic diagram of the process in a traditional code detection method is shown;
[0024] Figure 2 A schematic diagram showing the system architecture provided by an embodiment of the present application is shown;
[0025] Figure 3 A flow chart showing a code processing method provided by an embodiment of the present application is shown;
[0026] Figure 4 Another flowchart of the code processing method provided in an embodiment of the present application is shown;
[0027] Figure 5 A schematic diagram of a database cluster provided in an embodiment of the present application is shown;
[0028] Figure 6 Another flowchart of the code processing method provided in an embodiment of the present application is shown;
[0029] Figure 7 A schematic diagram of the functional modules of the code processing device provided in an embodiment of the present application is shown;
[0030] Figure 8 A schematic diagram of the hardware structure of the code processing device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0031] The embodiments of the present application provide a code processing method and related devices for implementing distributed storage of intermediate representation files, improving storage efficiency, and increasing data access speed and efficiency, thereby achieving efficient completion of code analysis.
[0032] It is understandable that in the specific implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0033] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only 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.
[0034] The terms "first," "second," "third," "fourth," and the like (if any) in the specification and claims of the present application and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or sequential sequence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the implementation of the present application described herein can, for example, 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, e.g., a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to such processes, methods, products, or apparatus.
[0035] Figure 1 A schematic diagram of the process in a traditional code detection method is shown.
[0036] like Figure 1 As shown, in the traditional code checking method, the source code file is usually obtained first, and the source code file is parsed to generate the corresponding abstract syntax tree (AST). Subsequently, an intermediate representation file corresponding to the source code file is generated based on the abstract syntax tree, and the intermediate representation file is stored in the memory. In this way, in the subsequent analysis of the intermediate representation file, the intermediate representation file is all deployed in a stand-alone device, and then the intermediate representation file is analyzed by the stand-alone device to obtain the code analysis result of the intermediate representation file. The stand-alone device described can be understood as a single server or device, without specific limitation.
[0037] The amount of data in the intermediate representation file is large and will occupy more memory resources. Figure 1 Using a single device to directly read and analyze the intermediate representation file stored in the memory requires more computing resources and computing time, resulting in low access efficiency and difficulty in efficient code analysis.
[0038] Therefore, in order to solve the technical problems described above, an embodiment of the present application provides a method for code processing. The code processing method can be applied to various code inspection scenarios, can realize distributed storage of intermediate representation files, improve storage efficiency, and also improve data access speed and efficiency, and realize efficient completion of code analysis. For example, the code processing method provided in this application can also be applied to various scenarios such as cloud technology, artificial intelligence, smart transportation, Internet of Vehicles, assisted driving, etc., which are not specifically limited in this application.
[0039] For example, the code processing method provided in this application can be applied to Figure 2 In the system architecture shown, the system architecture includes at least a code processing device and multiple first devices. For example, the multiple first devices may include but are not limited to first device 1, first device 2, first device 3, first device 4, etc., which are not limited here.
[0040] like Figure 2 As shown, the code processing device can be Figure 1 The source code file is obtained in this way, and an intermediate representation file corresponding to the source code file is generated. After the intermediate representation file is generated, it is not necessary to store the intermediate representation file in the memory. Instead, each code field in the intermediate representation file is matched with the first identifier of each storage object to store the data of each code field in the intermediate representation file in the storage object corresponding to the matched first identifier. For example, code field 1 can be matched with first identifier 1 of storage object 1, first identifier 2 of storage object 2, first identifier 3 of storage object 3, and first identifier 4 of storage object 4 respectively to determine the storage object corresponding to code field 1.
[0041] It should be noted that each of the multiple storage objects can be identified using a corresponding first identifier, so that the corresponding storage object can be marked and located through the first identifier. In addition, the first identifier of each storage object is different. For example, taking the multiple storage objects including storage objects 1 to storage objects 4 as an example, the first identifier 1 can be used to identify storage object 1, the first identifier 2 can be used to mark storage object 2, the first identifier 3 can be used to identify storage object 3, and the first identifier 4 can be used to identify storage object 4. Each of the first identifiers 1 to 4 described is different.
[0042] In the subsequent process of analyzing the intermediate representation file, the code processing device can send the data of the code fields stored in one or more storage objects to each first device in parallel among the multiple first devices. For each first device, the data of one or more code fields can be analyzed to obtain the corresponding first analysis results. For example, taking the intermediate code file including code fields 1 to 4 as an example, the data of code field 1 can be sent to first device 1, the data of code field 2 can be sent to first device 2, and the data of code field 3 and code field 4 can be sent to first device 3. In this way, all first devices can feed back the corresponding first analysis results to the code processing device, and then the code processing device determines the code analysis result of the intermediate representation file based on all these first analysis results.
[0043] It should be noted that the code processing device mentioned above can be a server or other processing device. The multiple first devices described can be understood as devices in a cluster, such as servers or terminal devices, etc., which will not be elaborated here. The terminal devices mentioned may include but are not limited to smartphones, desktop computers, laptops, tablets, smart speakers, vehicle-mounted devices, smart watches, wearable smart devices, intelligent voice interaction devices, smart home appliances, aircraft, etc. The server described can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (context delivery networks, CDN), and basic cloud computing services such as big data and artificial intelligence platforms, etc., which are not specifically limited in this application. In addition, the code processing device mentioned can be directly or indirectly connected to each first device through wired communication or wireless communication, etc., which are not specifically limited in this application.
[0044] In addition, the storage objects mentioned above may include data tables in a database cluster, files in a file system, etc., and are not specifically limited.
[0045] For example, the code processing methods provided in the embodiments of the present application can be applied in cloud technology scenarios. The cloud technology described herein refers to a hosting technology that unifies a series of resources, such as hardware, software, and networks, within a wide area network or local area network to achieve data computing, storage, processing, and sharing. Cloud computing is a computing model that distributes computing tasks across a resource pool consisting of a large number of computers, enabling various application systems to obtain computing power, storage space, and information services as needed.
[0046] Cloud storage is a new concept that has been extended and developed from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of different types of storage devices (storage devices are also called storage nodes) in the network through application software or application interfaces to work together and provide external data storage and business access functions.
[0047] A database, in short, can be thought of as a digital filing cabinet—a place where electronic files are stored, allowing users to add, query, update, and delete data. A database is a collection of data stored in a specific way, shared by multiple users, with minimal redundancy, and independent of applications.
[0048] A database management system (DBMS) is a computer software system designed for managing databases, typically providing basic functions such as storage, retrieval, security, and backup. DBMSs can be categorized by the database model they support, such as relational or XML (Extensible Markup Language); by the type of computer they support, such as server clusters or mobile phones; by the query language they use, such as SQL (Structured Query Language) or XQuery; by performance priorities, such as maximum scale or maximum speed; or by other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, supporting multiple query languages simultaneously.
[0049] In the embodiment of the present application, cloud storage and other processing of different code fields can be achieved through cloud technology.
[0050] The following describes a code processing method provided by an embodiment of the present application in conjunction with the accompanying drawings. Figure 3 A flow chart of the code processing method provided in the embodiment of the present application is shown. Figure 3 As shown, the code processing method may include the following steps:
[0051] 301. Obtain an intermediate representation file corresponding to the source code file.
[0052] In this example, a source code file refers to an uncompiled file written in a specific programming language. This source code file can be converted into a target code file using an intermediate representation file. During analysis of the intermediate representation file, the code processing device can first obtain the source code file and parse it to obtain the intermediate representation file corresponding to the source code file.
[0053] For example, how to obtain the intermediate representation file can be understood by referring to the following method, namely:
[0054] First, after obtaining the source code file, the code processing device parses the source code file and generates an abstract syntax tree. As an illustrative description, the code processing device can perform lexical analysis on the source code file to determine at least one lexical unit. More specifically, the code processing device obtains the character string to be processed by scanning the characters in the source code file, and marks the character string to be processed to determine at least one lexical unit. In this way, after determining the lexical unit, the code processing device performs grammatical analysis on each lexical unit, determines the grammatical elements corresponding to each lexical unit, and then generates an abstract syntax tree based on the grammatical elements corresponding to all lexical units. For example, the sentence corresponding to each lexical unit can be parsed to obtain the grammatical elements in the corresponding sentence, and then an abstract syntax tree is generated based on the sentence and grammatical elements corresponding to each lexical unit.
[0055] After generating the abstract syntax tree, the code processing device traverses the abstract syntax tree to obtain corresponding syntax elements. The code processing device analyzes the types of the syntax elements and, based on the types, encodes the corresponding syntax elements to obtain encoded syntax elements. Based on the encoded syntax elements, the code processing device then generates an intermediate representation file corresponding to the source code file.
[0056] For example, after obtaining the intermediate representation file, it can be used to perform various code analyses, such as uninitialized variables, null pointer references, security vulnerability detection, etc., which are not limited in this application. In addition, through code analysis, code optimization can be implemented to improve code performance and efficiency, such as eliminating redundant code and loop unrolling.
[0057] 302. Based on each code field in the intermediate representation file and the first identifier of each storage object in the multiple storage objects, determine the target storage object corresponding to each code field from the multiple storage objects, each first identifier is used to identify a storage object, and there is a cross-reference relationship between the multiple storage objects.
[0058] In this example, each storage object in the plurality of storage objects can be identified by using a corresponding first identifier, the content of which can refer to the aforementioned Figure 2Please understand the contents shown in the figure and do not elaborate on them here.
[0059] In addition, there is a cross-reference relationship between the multiple storage objects described in this application. That is, in addition to the first identifier mentioned above, each storage object may also include a second identifier. The cross-reference relationship can be constructed through the first identifiers and second identifiers in all storage objects. In other words, in the first storage object and the second storage object corresponding to the cross-reference relationship, the second identifier of the first storage object is the same as the first identifier of the second storage object. The first storage object and the second storage object described are two storage objects among the multiple storage objects.
[0060] For example, taking multiple storage objects including storage object 1 to storage object 4 as an example, the corresponding cross-reference relationship can refer to the aforementioned Figure 2 As mentioned above, Figure 2 As shown, the storage object 1 includes the first identifier 1 and the second identifier 1; similarly, the storage object 2 includes the first identifier 2 and the second identifier 2; and, the storage object 3 includes the first identifier 3 and the second identifier 3; and the storage object 4 includes the first identifier 4 and the second identifier 4.
[0061] In addition, the second identifier 1 in storage object 1 is the same as the first identifier 1 in storage object 2, so as to construct a cross-reference relationship between storage object 1 and storage object 2. Through the second identifier 1 of storage object 1 and the corresponding cross-reference relationship, the storage object 2 associated therewith can be located. Similarly, the second identifier 2 in storage object 2 is the same as the first identifier 3 in storage object 3, so as to determine the cross-reference relationship between storage object 2 and storage object 3, and then according to the second identifier 2 of storage object 2 and the corresponding cross-reference relationship, the storage object 3 associated therewith can be located. Similarly, in the cross-reference relationship between storage object 3 and storage object 4, the second identifier 3 of storage object 3 is the same as the first identifier 4 of storage object 4, which can be understood in detail with reference to the aforementioned cross-reference relationship between storage object 1 and storage object 2, and will not be elaborated here. In addition, the second identifier 4 described is the same as the first identifier 1.
[0062] It should be noted that the above Figure 2 Only storage objects 1 to 4 are used as examples for illustration. In actual applications, other storage objects are also included, such as storage object 5, storage object 6, etc., which are not specifically limited in this application.
[0063] After obtaining the intermediate representation file, the code processing device extracts each code field from the intermediate representation file. The code fields can be used to identify the attribute types of different data in the intermediate representation file. For example, attribute types may include, but are not limited to, performance, behavior, and name, etc.
[0064] In this way, the code processing device can determine the target storage object corresponding to each code field from the plurality of storage objects based on each extracted code field and the first identifier of each storage object mentioned above. As an illustrative description, the code processing device can match each code field with the first identifier of each storage object, and then use the matching storage object as the target storage object corresponding to the corresponding code field.
[0065] For example, the extracted code fields include code field 1 to code field 2, and the aforementioned Figure 2 Taking storage objects 1 to 4 shown in the figure as an example, the code processing device matches code field 1 with first identifier 1 of storage object 1, first identifier 2 of storage object 2, first identifier 3 of storage object 3, and first identifier 4 of storage object 4. If code field 1 matches first identifier 1, storage object 1 identified by first identifier 1 can be used as a target storage object corresponding to code field 1, such as target storage object 1.
[0066] Similarly, the code processing device matches code field 2 with first identifier 1 of storage object 1, first identifier 2 of storage object 2, first identifier 3 of storage object 3, and first identifier 4 of storage object 4. If code field 2 matches first identifier 3, storage object 3 identified by first identifier 3 can be used as the target storage object corresponding to code field 2, such as target storage object 2. In this way, multiple target storage objects can be determined, such as target storage object 1 and target storage object 2.
[0067] For example, the storage objects mentioned above may include data tables in a database cluster, or files in a file system, etc., which are not limited here. For the case where the storage objects are data tables in a database cluster, please refer to the following Figure 4 For the case where the storage object is a file in the file system, please refer to the following Figure 6 The content described above can be understood without further elaboration here.
[0068] 303. Store the data of each code field in a target storage object corresponding to the code field, so as to store the intermediate representation file through multiple target storage objects.
[0069] In this example, after determining multiple target storage objects, the code processing device can store the intermediate representation file in these multiple target storage objects, such that each target storage object is used to store data corresponding to a code field in the intermediate representation file. As an illustrative example, the code processing device can store the data for each code field in the intermediate code file in the target storage object corresponding to the corresponding code field, thereby storing the intermediate representation file through these multiple target storage objects.
[0070] For example, taking the example shown in step 302 above, the target storage object corresponding to code field 1 is storage object 1, and the target storage object corresponding to code field 2 is storage object 2. At this time, the code processing device can store the data corresponding to code field 1 in storage object 1, and the data corresponding to code field 2 in storage object 2.
[0071] It should be noted that the data of the code field described may include but is not limited to the aforementioned Figure 2 The name (name), file, offset, length, argument_size, take_va_args, return_type_name, etc. shown in are not limited in this application.
[0072] 304. Receive a first analysis result sent by each first device among a plurality of first devices, wherein the first analysis result sent by each first device is a result obtained by the corresponding first device performing defect detection analysis on data of code fields stored in one or more target storage objects.
[0073] In this example, after the code processing device stores the data of each code field in the corresponding target storage object, the analysis and processing of the intermediate code file can be completed in parallel by multiple first devices.
[0074] As an illustrative example, the code processing device can extract data corresponding to a code field from each target storage object and then send the data for one or more code fields to each first device. Thus, after each first device receives the data for the corresponding code field, it can concurrently perform defect detection and analysis on the data for the code fields stored in the one or more target storage objects, thereby obtaining corresponding first analysis results. It should be noted that the data for one or more code fields can be sent to the corresponding first device via a message, instruction, or request.
[0075] For example, using the target storage object 1 and target storage object 2 mentioned in step 303, the data of code field 1 can be extracted from target storage object 1, and the data of code field 2 can be extracted from target storage object 2. Furthermore, the data of code field 1 is sent to first device 1, and the data of code field 2 is sent to first device 2. Alternatively, the data of code field 1 can be sent to device 2, and the data of code field 2 can be sent to device 1, and the specific details are not limited in this application.
[0076] It should be noted that, in actual applications, each first device may also directly obtain the data of the corresponding code field from the target storage object, and this application does not limit the acquisition method.
[0077] In some examples, each first device may analyze the data of the corresponding code field by performing defect detection analysis on the received code field data after receiving the data of one or more code fields. For example, the defect detection analysis may include, but is not limited to, one or more of a security check, a defect check, a code standard check, and a syntax check, which are not specifically limited in this application.
[0078] As an illustrative example, how each first device implements defect detection and analysis for a corresponding code field can be understood as follows: Each first device can perform control flow analysis and data flow analysis on the data in the corresponding code field based on preset defect analysis rules to determine target defects in the data in the corresponding code field. Each first device then determines the target defects it has determined as the first analysis result for the data in the corresponding code field.
[0079] It should be noted that in this application, it is sufficient to send the data in the intermediate representation file (i.e., the data of one or more code fields) to different first devices in a distributed manner. Which first device receives it can be determined based on the device processing capability of the first device and the size of the data of the code field. For example, the data of the code field with a larger data volume can be processed by the first device with a stronger device processing capability, and the data of the code field with a smaller data volume can be processed by the first device with a smaller device processing capability, without specific limitation. Alternatively, it can also be determined based on the priority of the code field data and the device processing capability of the first device. For example, the data of the code field with a higher priority can be processed by the first device with a stronger device processing capability, and the data of the code field with a lower priority can be processed by the first device with a smaller device processing capability, without specific limitation.
[0080] In this way, after each first device obtains a first analysis result, it can send its first analysis result to the code processing device via a message, instruction, or other means. Thus, the code processing device can receive the first analysis results sent by these multiple first devices. For example, the code processing device can receive the first analysis result related to the data in code field 1 sent by device 1, and the first analysis result related to the data in code field 2 sent by device 2.
[0081] 305. Obtain a code analysis result of the intermediate representation file based on the first analysis results sent by the multiple first devices.
[0082] In this example, after receiving the first analysis results sent by the multiple first devices, the code processing device can merge the multiple first analysis results to obtain a code analysis result for the intermediate representation file. This code analysis result can be used to understand and locate whether there are code defects in the intermediate representation file, facilitating subsequent location and analysis of the cause of the defect.
[0083] Exemplarily, after receiving the first analysis results sent by each of the multiple first devices, the code processing device can selectively reload the data of the code field corresponding to each first analysis result into memory based on the first analysis result. For example, based on the performance analysis value, resource usage value, and other values in each first analysis result, the data of the code field corresponding to the first analysis result with the larger value can be reloaded into memory. Thus, after reloading the data into memory, the code processing device can further perform defect detection analysis on the reloaded code field data. By performing these multiple rounds of code field data analysis, the accuracy of defect analysis can be improved.
[0084] In an embodiment of the present application, the data of each code field is stored in a different storage object, and the data of one or more code fields are distributed to different first devices, and then the data of the corresponding code fields are analyzed in parallel by multiple first devices, so that each first device only needs to process part of the data, thereby reducing the computing resources and computing time required in the traditional solution that relies only on a single device to process the code analysis task of the intermediate code file, thereby improving the analysis speed and reducing the memory usage requirement.
[0085] In addition, the processing method of cluster multi-machine parallel analysis adopted in this application can flexibly expand computing resources according to demand. By increasing the number of devices in the cluster, it is possible to adapt to the growing data scale and analysis needs, maintain efficient performance, and further improve the speed and processing power of the analysis. In addition, in cluster multi-machine parallel analysis, if a device breaks down or fails, other devices in the cluster can still continue to perform analysis tasks, and the security and reliability of the data can be guaranteed through backup and redundancy mechanisms, thereby improving the fault tolerance of the system. In addition, through cluster multi-machine parallel analysis, the computing resources in the cluster can be fully utilized, so that devices that may have been idle can also participate in the analysis tasks for intermediate code files, giving full play to the overall computing power of the cluster and improving resource utilization efficiency.
[0086] In some examples, the storage objects mentioned above include data tables in a database cluster, or they may also include files in a file system. The storage methods of a database cluster and a file system are different. The following will describe the case where the storage objects include data tables in a database cluster and the storage objects include files in a file system based on different embodiments. For the above two cases, refer to the following respectively. Figure 4 and Figure 6 The details are as follows:
[0087] Case 1: The storage object includes a data table in the database cluster
[0088] For example, Figure 4 Another flow chart of data processing provided by the embodiment of the present application is shown. Figure 4 As shown, the code processing method includes at least the following steps:
[0089] 401. Obtain an intermediate representation file corresponding to the source code file.
[0090] In this example, the source code files and intermediate representation files described can refer to the aforementioned Figure 3 The contents described in step 301 can be understood for simplicity and will not be elaborated here.
[0091] 402. Match each code field in the intermediate representation file with the primary key field of each data table in the multiple data tables to determine the target primary key field corresponding to each code field.
[0092] In this example, when the storage object is a data table in a database cluster, the corresponding first identifier may include a primary key field of the data table. In other words, the primary key field may be used to uniquely identify the corresponding data table.
[0093] In addition, there is also the aforementioned Figure 3The cross-reference relationship mentioned in step 302 is described in detail below. That is, in addition to the primary key fields mentioned above, each data table in the database cluster may also include foreign key fields. Using the primary key fields and foreign key fields in all data tables, a cross-reference relationship between the data tables can be constructed. In other words, in the first and second data tables corresponding to the cross-reference relationship, the foreign key field of the first data table is the same as the primary key field of the second data table. The first and second data tables described are two data tables in a plurality of data tables.
[0094] For example, taking data tables 1 to 4 in the data table cluster as an example, their corresponding cross-reference relationships can be referred to Figure 5 The schematic diagram shown is for easy understanding. Figure 5 For example, in Data Table 1, there is a primary key field 1 (e.g., id) and a foreign key field 1 (e.g., func_id). Similarly, in Data Table 2, there is a primary key field 2 (e.g., func_id) and a foreign key field 2 (e.g., callsite_id). In Data Table 3, primary key field 3 may be, for example, callsite_id, and foreign key field 3 may be callee_id. And in Data Table 4, primary key field 4 may be, for example, callee_id, and foreign key field 4 may be id. Thus, Data Tables 1 to 4 can be linked using the aforementioned foreign key fields, such as func_id, callsite_id, callee_id, and id.
[0095] Thus, after obtaining the intermediate representation file, each code field in the intermediate representation file is extracted. Further, the code processing device can match each extracted code field with the primary key field of each data table, thereby determining the target primary key field corresponding to each code field.
[0096] As a schematic description, in the process of determining the target primary key field corresponding to each code field, any code field (i.e., the first code field mentioned later) can be used as an example for illustration. For example, for each data table, the primary key field of each data table is extracted, and each primary key field is used to identify the corresponding data table. In this way, in the process of determining the target primary key field corresponding to the first code field, the first code field can be matched with the primary key field of each data table, and when the first code field matches the primary key field of the first data table, the primary key field of the first data table is determined to be the target primary key field corresponding to the first code field.
[0097] It should be noted that the first data table described here is the data table in which the primary key field matches the first code field among the multiple data tables. Furthermore, the matching process for determining the corresponding target primary key field for other code fields can also be understood by referring to the matching process for the first code field and is not further described here.
[0098] 403. Determine the data table corresponding to each target primary key field as the target data table corresponding to the code field matching the target primary key field.
[0099] In this example, after determining the target primary key field corresponding to each code field, the code processing device may determine the data table corresponding to the target primary key field as the target data table corresponding to the code field matching the target primary key field.
[0100] For example, the extracted code fields include code field 1 to code field 2, Figure 5 Taking data tables 1 to 4 shown in the figure as an example, the code processing device matches code field 1 with primary key field 1 of data table 1, primary key field 2 of data table 2, primary key field 3 of data table 3, and primary key field 4 of data table 4. If code field 1 matches primary key field 1, data table 1 identified by primary key field 1 can be used as a target data table corresponding to code field 1, such as target data table 1. Similarly, the code processing device matches code field 2 with primary key field 1 of data table 1, primary key field 2 of data table 2, primary key field 3 of data table 3, and primary key field 4 of data table 4. If code field 2 matches primary key field 3, data table 3 identified by primary key field 3 can be used as a target data table corresponding to code field 2, such as target data table 2. In this way, multiple target data tables can be determined, such as target data table 1 and target data table 2.
[0101] 404. Store the data corresponding to each code field into the target data table corresponding to each code field, so that the intermediate representation file is stored in multiple target data tables.
[0102] In this example, after determining multiple target data tables, the code processing device can store the intermediate representation file in these multiple target data tables, such that each target data table is used to store data corresponding to a code field in the intermediate representation file. As an illustrative example, the code processing device can store the data for each code field in the intermediate code file in the target data table corresponding to the corresponding code field, thereby storing the intermediate representation file through these multiple target data tables.
[0103] For example, taking the example shown in step 403 above, the target data table corresponding to code field 1 is data table 1, and the target data table corresponding to code field 2 is data table 2. At this time, the code processing device can store the data corresponding to code field 1 in data table 1, and the data corresponding to code field 2 in data table 2.
[0104] 405. Receive a first analysis result sent by each first device among a plurality of first devices, wherein the first analysis result sent by each first device is a result obtained by the corresponding first device performing defect detection analysis on data of code fields stored in one or more target storage objects.
[0105] 406. Obtain a code analysis result of the intermediate representation file based on the first analysis results sent by the multiple first devices.
[0106] It should be noted that the contents of steps 405 to 406 described here can refer to the aforementioned Figure 3 The contents described in step 304 to step 305 can be understood for reference only and will not be described in detail here.
[0107] It should be noted that the database cluster mentioned above may include but is not limited to relational database clusters such as MySQL and POSTGRESQL, and is not limited in this application. Through the above method, the computing power of the database cluster and the advantages of distributed computing are fully utilized, the intermediate representation files are uniformly transferred to different data tables in the database cluster, and the data of some code fields are analyzed in parallel by different first devices in the database cluster, thereby reducing memory usage and reducing the complexity of subsequent analysis of the intermediate representation files, improving code analysis efficiency and computing efficiency, and being applicable to scenarios where larger-scale data is processed. In addition, the capacity, quantity, and performance of the database cluster in this application can be allocated on demand according to actual analysis needs. In other words, by uniformly storing the intermediate representation files generated by the abstract syntax tree in the database cluster, the pressure of the original single-machine memory storage is distributed to the entire database cluster, avoiding the out of memory (OOM) phenomenon caused by excessive memory usage of a single machine.
[0108] Case 2: Storage objects include files in the file system
[0109] For example, Figure 6 Another flow chart of data processing provided by the embodiment of the present application is shown. Figure 6 As shown, the code processing method includes at least the following steps:
[0110] 601. Obtain an intermediate representation file corresponding to the source code file.
[0111] In this example, the source code files and intermediate representation files described can refer to the aforementioned Figure 3 The contents described in step 301 can be understood for simplicity and will not be elaborated here.
[0112] 602. Serialize the intermediate representation file to obtain a corresponding byte stream.
[0113] In this example, the serialization process described here can be understood as the process of converting the intermediate representation file into a transmittable byte stream. After obtaining the intermediate representation file, the intermediate representation file can also be serialized to obtain the corresponding byte stream. For example, sometimes a byte stream can also be referred to as a byte sequence, which is not limited here.
[0114] 603. Match each code field in the byte stream with a plurality of file indexes to determine a target file index corresponding to each code field, wherein the plurality of file indexes include a file index of each file in the file.
[0115] In this example, when the storage object is a file in a file system, the first identifier may include a file index of the file. That is, the file index may be used to uniquely identify the corresponding file.
[0116] Furthermore, between each file in the file system there exists the aforementioned Figure 3 The cross-reference relationship mentioned in step 302. That is to say, in addition to the file index mentioned above, each file in the file system may also include an external index. Through the file indexes and external indexes in all files, a cross-reference relationship between files can be constructed. In other words, in the first file and the second file corresponding to the cross-reference relationship, the external index of the first file is the same as the file index of the second file. The first file and the second file described are two files in a plurality of files. For details, please refer to the aforementioned Figure 5 The primary key fields and foreign key fields described in the previous section are understood and will not be described here.
[0117] In this way, after obtaining the intermediate representation file, each code field in the intermediate representation file is extracted. Furthermore, the code processing device can match each extracted code field with the file index of each file respectively, and then determine the target file index corresponding to each code field. As a schematic description, in the process of the target file index corresponding to each code field, any code field (that is, the first code field mentioned later) can be used as an example for illustration. Exemplarily, for each file, the file index of each file is extracted, and each file index is used to identify the corresponding file. In this way, in the process of determining the target file index corresponding to the first code field, the first code field can be matched with the file index of each file, and when the first code field matches the file index of the first file, the file index of the first file is determined to be the target file index corresponding to the first code field.
[0118] It should be noted that the first file described is the file whose file index matches the first code field among the multiple files. Furthermore, the matching process for determining the corresponding target file index for other code fields can also be understood by referring to the matching process for the first code field and will not be elaborated here.
[0119] 604. Determine the file corresponding to each target file index as the target file corresponding to the code field matching the target file index.
[0120] In this example, after determining the target file index corresponding to each code field, the code processing device may determine the file corresponding to the target file index as the target file corresponding to the code field matching the target file index.
[0121] For example, assuming the extracted code field includes code field 3 and multiple files include files 1 to 4, the code processing device matches code field 3 with file index 1 of file 1, file index 2 of file 2, file index 3 of file 3, and file index 4 of file 4. If code field 1 matches file index 2, file 2 identified by file index 2 can be used as a target file corresponding to code field 3.
[0122] 605. Store the data corresponding to each code field into the target file corresponding to each code field, so that the intermediate representation file is stored in multiple target files.
[0123] In this example, after determining multiple target files, the code processing device can store the intermediate representation file in these multiple target files, such that each target file is used to store data corresponding to a code field in the intermediate representation file. As an illustrative example, the code processing device can store the data for each code field in the intermediate code file in the target file corresponding to the corresponding code field, thereby storing the intermediate representation file across these multiple target files.
[0124] For example, taking the example shown in step 604 above, the target file corresponding to code field 3 is file 2. At this time, the code processing device can store the data corresponding to code field 3 in file 2.
[0125] 606. Receive a first analysis result sent by each first device among a plurality of first devices, wherein the first analysis result sent by each first device is a result obtained by the corresponding first device performing defect detection analysis on data of code fields stored in one or more target storage objects.
[0126] 607. Obtain a code analysis result of the intermediate representation file based on the first analysis results sent by the multiple first devices.
[0127] It should be noted that the contents of steps 606 to 607 described here can refer to the aforementioned Figure 3 The contents described in step 304 to step 305 can be understood for reference only and will not be described in detail here.
[0128] In the above manner, the intermediate representation file is serialized into a byte stream and stored in the file system. An index structure is constructed using the file index and external index for each of the multiple files to achieve fast data access. This not only improves storage efficiency and data access speed, but also enhances flexibility and scalability, and reduces costs. Furthermore, the combination of serialized intermediate representation files and index structures improves data access efficiency while saving storage space, reducing the complexity and cost of database management.
[0129] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. It can be understood that in order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. The embodiment of the present application can divide the functional modules of the device according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0130] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0131] The following describes in detail the code processing device in the embodiment of the present application. Figure 7 This is a schematic diagram of an embodiment of the code processing device provided in the embodiment of this application. Figure 7 As shown, the code processing device may include an acquisition unit 701 and a processing unit 702. Optionally, it may further include a sending unit 703.
[0132] The acquisition unit 701 is used to acquire the intermediate representation file corresponding to the source code file. Figure 3 The contents described in step 301 can be understood for simplicity and will not be elaborated here.
[0133] The processing unit 702 is configured to determine multiple target storage objects of the intermediate representation file in the multiple storage objects based on each code field in the intermediate representation file and the first identifier of each storage object in the multiple storage objects, wherein each first identifier is used to identify a storage object, and there is a cross-reference relationship between the multiple storage objects. Figure 3 The contents described in step 302 can be understood for simplicity and will not be elaborated here.
[0134] The processing unit 702 is configured to store the data of each code field into a target storage object corresponding to the code field, so as to store the intermediate representation file through multiple target storage objects. Figure 3 The contents described in step 303 can be understood for simplicity and will not be elaborated here.
[0135] The acquisition unit 701 is configured to receive a first analysis result sent by each of the plurality of first devices, wherein the first analysis result sent by each first device is a result obtained by the corresponding first device performing defect detection analysis on the data of the code field stored in one or more target storage objects. Figure 3 The contents described in step 304 can be understood for simplicity and will not be elaborated here.
[0136] The processing unit 702 is configured to obtain a code analysis result of the intermediate representation file based on the first analysis results sent by the plurality of first devices. Figure 3 The contents described in step 305 can be understood for reference only and will not be elaborated here.
[0137] In some optional embodiments, each storage object also includes a second identifier; based on the first identifiers and second identifiers of multiple storage objects, a cross-reference relationship is obtained, wherein, in the first storage object and the second storage object corresponding to the cross-reference relationship, the second identifier of the first storage object is the same as the first identifier of the second storage object, and the first storage object and the second storage object are two storage objects among the multiple storage objects.
[0138] In other optional embodiments, the storage object includes a data table in a database cluster, and the first identifier includes a primary key field of the data table; the processing unit 702 is used to: match each code field in the intermediate representation file with the primary key field of each data table in multiple data tables to determine the target primary key field corresponding to each code field; determine the data table corresponding to each target primary key field as the target data table corresponding to the code field matching the target primary key field; store the data corresponding to each code field in the target data table corresponding to each code field, so that the intermediate representation file is stored in multiple target data tables.
[0139] In other optional embodiments, the processing unit 702 is used to: extract the primary key field of each data table, each primary key field is used to identify the corresponding data table; when the first code field matches the primary key field of the first data table, determine that the primary key field of the first data table is the target primary key field corresponding to the first code field, the first code field is any code field, and the first data table is one of the multiple data tables; determine the first data table as the target data table corresponding to the first code field.
[0140] In other optional embodiments, the storage object includes a file in a file system, and the first identifier includes a file index of the file; the processing unit 702 is used to: serialize the intermediate representation file to obtain a corresponding byte stream; match each code field in the byte stream with multiple file indexes to determine the target file index corresponding to each code field, wherein the multiple file indexes include the file index of each file in the file; determine the file corresponding to each target file index as the target file corresponding to the code field matching the target file index; store the data corresponding to each code field in the target file corresponding to each code field, so that the intermediate representation file is stored in multiple target files.
[0141] In other optional implementations, the processing unit 702 is further configured to extract data corresponding to the code field from each target storage object before receiving the first analysis result sent by each of the plurality of first devices. The sending unit 703 is configured to send the data of the one or more code fields to each first device.
[0142] In some other optional implementations, the defect detection analysis includes one or more of a security check process, a defect check process, a code specification check process, and a grammar check process.
[0143] In other optional implementations, the processing unit 702 is used to obtain a source code file, parse the source code file, and generate an abstract syntax tree; traverse the abstract syntax tree to obtain corresponding syntax elements; analyze the types of the syntax elements, and encode the corresponding syntax elements based on the types of the syntax elements to obtain encoded syntax elements; and generate an intermediate representation file corresponding to the source code file based on the encoded syntax elements.
[0144] In other optional implementations, the processing unit 702 is used to: perform lexical analysis on the source code file to determine at least one lexical unit; perform syntactic analysis on each lexical unit to determine the corresponding grammatical element, and generate an abstract syntax tree based on the grammatical element.
[0145] In some other optional implementations, the processing unit 702 is configured to: scan characters in a source code file to obtain a character string to be processed; and mark the character string to be processed to determine at least one lexical unit.
[0146] In some other optional implementations, the processing unit 702 is configured to: parse the sentence corresponding to each lexical unit to obtain the grammatical elements in the corresponding sentence; and generate an abstract syntax tree based on the sentence and grammatical elements corresponding to each lexical unit.
[0147] The above describes the code processing device in the embodiment of the present application from the perspective of modular functional entities, and the following describes the code processing device in the embodiment of the present application from the perspective of hardware processing. Figure 8 Schematic diagram of the structure of the code processing device provided in the embodiment of the present application. The code processing device may have relatively large differences due to different configurations or performances, and may include but is not limited to the aforementioned code analysis device, the first device, etc.
[0148] like Figure 8 As shown, the code processing device 300 may include one or more central processing units (CPUs) 322 (for example, one or more processors) and a memory 332, and one or more storage media 330 (for example, one or more mass storage devices) for storing applications 342 or data 344. The memory 332 and the storage medium 330 may be temporary storage or permanent storage. The program stored in the storage medium 330 may include one or more modules (not shown in the figure), each of which may include a series of instruction operations in the code processing device. Furthermore, the central processing unit 322 may be configured to communicate with the storage medium 330 and execute a series of instruction operations in the storage medium 330 on the code processing device 300. Exemplarily, the central processing unit 322 is used to execute the application 342 stored in the storage medium 330, thereby implementing the code processing method provided in the above-mentioned embodiment of the present application.
[0149] The code processing device 300 may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input and output interfaces 358, and / or one or more operating systems 341, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0150] For example, Figure 8 The central processing unit 322 in the memory 332 can call the computer execution instructions stored in the memory 332 to make the code processing device execute the following Figures 3 to 6 The method in the corresponding method embodiment.
[0151] Specifically, Figure 7 The function / implementation process of the processing unit 702 can be achieved by Figure 8 The central processing unit 322 in the memory 332 calls the computer execution instructions stored in the memory 332 to achieve this. Figure 7 The functions / implementation processes of the acquisition unit 701 and the sending unit 703 can be achieved by Figure 8 It is implemented by the input and output interface 358 in.
[0152] The steps performed by the code processing device in the above embodiment can be based on the Figure 8 The structure of the code processing device shown is implemented.
[0153] A computer-readable storage medium is also provided in an embodiment of the present application, on which a computer program or instruction is stored. When the computer program or instruction is executed by a processor, the steps of the method described in the above embodiments are implemented.
[0154] A computer program product is also provided in an embodiment of the present application, including a computer program or instructions, which, when executed by a processor, implements the steps of the methods described in the above embodiments.
[0155] In the above embodiments, all or part of the embodiments may be implemented through software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. Those skilled in the art will clearly understand that for ease and brevity of description, the specific operating processes of the systems, devices, and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0156] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0157] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0158] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0159] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0160] The computer program product includes one or more computer instructions. When the computer is loaded and executed on the computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instruction can be transmitted from a website, a computer, a server or a data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode to another website, a computer, a server or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or a data center that includes one or more available media integrations. Available media can be magnetic media, (such as floppy disk, hard disk, tape), optical media (such as DVD) or semiconductor media (such as SSD)) etc.
[0161] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A code processing method, characterized in that: include: Get the intermediate representation file corresponding to the source code file; determining, based on each code field in the intermediate representation file and a first identifier of each storage object in a plurality of storage objects, a target storage object corresponding to each code field from the plurality of storage objects, each first identifier being used to identify a storage object, and a cross-reference relationship existing between the plurality of storage objects; storing the data of each code field into a target storage object corresponding to the code field, so as to store the intermediate representation file through the multiple target storage objects; receiving a first analysis result sent by each of the plurality of first devices, wherein the first analysis result sent by each of the first devices is a result obtained by the corresponding first device performing defect detection analysis on data of code fields stored in one or more target storage objects; A code analysis result of the intermediate representation file is obtained based on the first analysis results sent by the multiple first devices.
2. The method according to claim 1, characterized in that Each of the storage objects further includes a second identifier; and a cross-reference relationship exists between the plurality of storage objects, including: Based on the first identifier and the second identifier of the multiple storage objects, the cross-reference relationship is obtained, wherein, in the first storage object and the second storage object corresponding to the cross-reference relationship, the second identifier of the first storage object is the same as the first identifier of the second storage object, and the first storage object and the second storage object are two storage objects among the multiple storage objects.
3. The method according to any one of claims 1 to 2, characterized in that The storage object includes a data table in a database cluster, and the first identifier includes a primary key field of the data table; based on each code field in the intermediate representation file and the first identifier of each storage object in a plurality of storage objects, determining a target storage object corresponding to each code field from the plurality of storage objects includes: Matching each of the code fields in the intermediate representation file with the primary key field of each of the data tables to determine a target primary key field corresponding to each of the code fields; Determine the data table corresponding to each target primary key field as the target data table corresponding to the code field matching the target primary key field; Storing the data of each code field into the target storage object corresponding to the code field includes: The data corresponding to each code field is stored in the target data table corresponding to each code field, so that the intermediate representation file is stored in multiple target data tables.
4. The method according to claim 3, characterized in that Matching each code field in the intermediate representation file with the primary key field of each data table in the plurality of data tables to determine a target primary key field corresponding to each code field includes: Extracting a primary key field from each data table, where each primary key field is used to identify the corresponding data table; When the first code field matches the primary key field of the first data table, determining that the primary key field of the first data table is a target primary key field corresponding to the first code field, the first code field is any one of the code fields, and the first data table is one of the multiple data tables; Determining the data table corresponding to each target primary key field as the target data table corresponding to the code field matching the target primary key field includes: The first data table is determined as the target data table corresponding to the first code field.
5. The method according to any one of claims 1 to 2, characterized in that The storage object includes a file in a file system, and the first identifier includes a file index of the file; based on each code field in the intermediate representation file and the first identifier of each storage object in the plurality of storage objects, determining a target storage object corresponding to each code field from the plurality of storage objects includes: Serializing the intermediate representation file to obtain a corresponding byte stream; Matching each code field in the byte stream with a plurality of file indexes to determine a target file index corresponding to each code field, wherein the plurality of file indexes include a file index of each file in the files; Determine the file corresponding to each target file index as the target file corresponding to the code field matching the target file index; Storing the data of each code field into the target storage object corresponding to the code field includes: The data corresponding to each code field is stored in a target file corresponding to each code field, so that the intermediate representation file is stored in a plurality of target files.
6. The method according to any one of claims 1 to 2, characterized in that Before receiving the first analysis result sent by each of the plurality of first devices, the method further includes: Extracting data corresponding to the code field from each of the target storage objects; The data of one or more code fields are sent to each of the first devices.
7. The method according to any one of claims 1 to 2, characterized in that The defect detection analysis includes one or more of a security check process, a defect check process, a code specification check process, and a grammar check process.
8. The method according to any one of claims 1 to 2, characterized in that Get the intermediate representation file corresponding to the source code file, including: Obtaining the source code file, parsing the source code file, and generating an abstract syntax tree; Traversing the abstract syntax tree to obtain corresponding syntax elements; Analyzing the type of the syntax element, and encoding the corresponding syntax element based on the type of the syntax element to obtain an encoded syntax element; Based on the encoded syntax elements, an intermediate representation file corresponding to the source code file is generated.
9. The method according to claim 8, characterized in that Parsing the source code file to generate an abstract syntax tree includes: Performing lexical analysis on the source code file to determine at least one lexical unit; Perform grammatical analysis on each of the lexical units to determine corresponding grammatical elements, and generate the abstract syntax tree based on the grammatical elements.
10. The method according to claim 9, characterized in that Performing lexical analysis on the source code file to determine at least one lexical unit includes: Scan characters in the source code file to obtain a character string to be processed; The character string to be processed is marked to determine at least one lexical unit.
11. The method according to claim 9, characterized in that Performing grammatical parsing on each of the lexical units, determining corresponding grammatical elements, and generating the abstract syntax tree based on the grammatical elements, including: Parsing the sentence corresponding to each lexical unit to obtain the grammatical elements in the sentence; The abstract syntax tree is generated based on the sentence corresponding to each lexical unit and the grammatical element.
12. A code processing device, characterized in that: include: An acquisition unit, used for acquiring an intermediate representation file corresponding to a source code file; a processing unit, configured to determine, based on each code field in the intermediate representation file and a first identifier of each storage object in the plurality of storage objects, a plurality of target storage objects in the intermediate representation file, each first identifier being used to identify one of the storage objects, and a cross-reference relationship between the plurality of storage objects; The processing unit is configured to store the data of each code field into a target storage object corresponding to the code field, so as to store the intermediate representation file through the multiple target storage objects; The acquiring unit is configured to receive a first analysis result sent by each of the plurality of first devices, wherein the first analysis result sent by each of the first devices is a result obtained by the corresponding first device performing defect detection analysis on data of code fields stored in one or more target storage objects; The processing unit is configured to obtain a code analysis result of the intermediate representation file based on the first analysis results sent by the multiple first devices.
13. A code processing device, characterized in that: include: An input / output interface, a processor, and a memory, wherein program instructions are stored in the memory; The processor is configured to execute program instructions stored in the memory to perform the method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium comprises instructions, which, when executed on a computer device, cause the computer device to perform the method according to any one of claims 1 to 11.
15. A computer program product, characterized in that The computer program product comprises instructions, which, when executed on a computer device, cause the computer device to perform the method according to any one of claims 1 to 11.