Method for evaluating source code using numerical array representation of source code elements
Patent Information
- Application Number
- CN202211442539.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-10
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2040-02-10
AI Technical Summary
因此,用高级语言编写的一段源代码可能难以直接使用ML模型进行处理
[0011]根据本发明构思的一些实施例,可以通过为源代码元素生成二叉抽象语法树表示并且使用该二叉AST表示来生成源代码的数值数组表示来促进对源代码的更有效评估。这类操作可以例如使用机器学习(ML)促进对源代码元素的评估,以提供漏洞预测、代码审查、代码完成、综合、修复等中的一项或多项。
Smart Images

Figure CN115935369B_ABST
Abstract
Description
[0001] This application is a divisional application of the Chinese phase of PCT international application PCT / EP2020 / 053335, entitled “Methods of Evaluating Source Code Using Numeric Array Representations of Source Code Elements”, filed on February 10, 2020 (application number 202080096065.4). Technical Field
[0002] This invention generally relates to software, and more specifically to methods and related nodes for evaluating source code. Background Technology
[0003] The use of artificial intelligence (AI) (especially machine learning (ML)) has been on the rise. AI and ML have a place in almost every aspect of life. One promising application area of AI / ML is intelligent software analysis with various objectives, such as vulnerability prediction, source code review and completion, synthesis, and remediation.
[0004] ML models are trained and developed using only numerical data in the form of arrays. For example, consider an image classification task in ML. Images are composed of pixels, which are the smallest units of an image, and each pixel has its own color, represented by numbers between 0 and 256 in a grayscale system. Therefore, from the perspective of an ML model, an image is actually viewed as a matrix containing numerical values.
[0005] On the other hand, the source code is primarily written in high-level programming languages (such as Java, Python, etc.), which include text-based keywords, words, and phrases from English (or other) natural languages. Therefore, a piece of source code written in a high-level language may be difficult to process directly using ML models. Summary of the Invention
[0006] According to some embodiments of the present invention, a method for evaluating source code of a programming language includes the following operations: Providing source code of a programming language, wherein the source code includes a plurality of source code elements. Selecting a source code element from the plurality of source code elements. Generating a plurality of tokens based on the source code element, wherein each of the plurality of tokens includes a sequence of text characters. Generating a binary abstract syntax tree (AST) representation of the source code element based on the plurality of tokens, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. Encoding each of the binary AST token nodes and binary AST empty nodes as a corresponding value. Generating a numerical array representation of the source code element based on the binary AST representation, wherein the values of the corresponding binary AST token nodes and binary AST empty nodes are mapped to positions in the numerical array representation based on their corresponding positions in the binary AST representation.
[0007] According to some other embodiments of the present invention, the source code evaluation node is adapted to perform the following operations: Provide source code of a programming language, wherein the source code includes a plurality of source code elements. Select a source code element from the plurality of source code elements. Generate a plurality of tokens based on the source code element, wherein each of the plurality of tokens includes a sequence of text characters. Generate a binary abstract syntax tree (AST) representation of the source code element based on the plurality of tokens, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. Encode each of the binary AST token nodes and binary AST empty nodes into a corresponding value. Generate a numerical array representation of the source code element based on the binary AST representation, wherein the values of the corresponding binary AST token nodes and binary AST empty nodes are mapped to positions in the numerical array representation based on their corresponding positions in the binary AST representation.
[0008] According to another embodiment of the present invention, a source code evaluation node includes processing circuitry and a memory coupled to the processing circuitry. The memory includes instructions that, when executed by the processing circuitry, cause the source code evaluation node to perform the following operations: Source code of a programming language is provided, wherein the source code includes a plurality of source code elements. A source code element is selected from the plurality of source code elements. A plurality of tokens is generated based on the source code element, wherein each of the plurality of tokens includes a sequence of text characters. A binary abstract syntax tree (AST) representation of the source code element is generated based on the plurality of tokens, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. Each of the binary AST token nodes and binary AST empty nodes is encoded as a corresponding value. A numerical array representation of the source code element is generated based on the binary AST representation, wherein the values of the corresponding binary AST token nodes and binary AST empty nodes are mapped to positions in the numerical array representation based on their corresponding positions in the binary AST representation.
[0009] According to another embodiment of the present invention, a computer program includes program code to be executed by processing circuitry of a source code evaluation node, whereby execution of the program code causes the source code evaluation node to perform the following operations: Source code of a programming language is provided, wherein the source code includes a plurality of source code elements. A source code element is selected from the plurality of source code elements. A plurality of tokens is generated based on the source code element, wherein each of the plurality of tokens includes a sequence of text characters. A binary abstract syntax tree (AST) representation of the source code element is generated based on the plurality of tokens, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. Each of the binary AST token nodes and binary AST empty nodes is encoded as a corresponding value. A numerical array representation of the source code element is generated based on the binary AST representation, wherein the values of the corresponding binary AST token nodes and binary AST empty nodes are mapped to positions in the numerical array representation based on their corresponding positions in the binary AST representation.
[0010] According to another embodiment of the present invention, a computer program product includes a non-transitory storage medium comprising program code to be executed by processing circuitry of a source code evaluation node, wherein execution of the program code causes the source code evaluation node to perform the following operations: Providing source code of a programming language, wherein the source code includes a plurality of source code elements. Selecting a source code element from the plurality of source code elements. Generating a plurality of tokens based on the source code element, wherein each of the plurality of tokens includes a sequence of text characters. Generating a binary abstract syntax tree (AST) representation of the source code element based on the plurality of tokens, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. Encoding each of the binary AST token nodes and binary AST empty nodes as a corresponding value. Generating a numerical array representation of the source code element based on the binary AST representation, wherein the values of the corresponding binary AST token nodes and binary AST empty nodes are mapped to positions in the numerical array representation based on their corresponding positions in the binary AST representation.
[0011] According to some embodiments of the present invention, more efficient evaluation of source code can be facilitated by generating binary abstract syntax tree (AST) representations for source code elements and using those ASTs to generate numerical array representations of the source code. Such operations can, for example, utilize machine learning (ML) to facilitate the evaluation of source code elements, providing one or more of the following: vulnerability prediction, code review, code completion, synthesis, and remediation. Attached Figure Description
[0012] The accompanying drawings, included to provide a further understanding of the invention and incorporated into and constituting a part of this application, illustrate certain non-limiting embodiments of the inventive concept. In the drawings:
[0013] Figure 1 This is a diagram showing an example of a non-binary AST of source code elements;
[0014] Figure 2 These are diagrams illustrating the operation of methods according to some embodiments of the concept of the present invention;
[0015] Figure 3 This is a table illustrating a segment of source code including two source code elements, representing some embodiments of the concept according to the present invention;
[0016] Figure 4A and Figure 4B This illustrates some embodiments of the concept according to the present invention. Figure 3 A table of two source code elements extracted from the source code;
[0017] Figure 5 These illustrate some embodiments based on the concept of the present invention. Figure 4A A non-binary AST graph of the source code elements;
[0018] Figure 6A This is a diagram illustrating some embodiments of a non-binary tree according to the present invention. Figure 6B It shows from Figure 6A A graph of a binary tree derived from a non-binary tree;
[0019] Figure 7A This illustrates some embodiments of the concept according to the present invention. Figure 5 Non-binary AST generation Figure 4A A binary AST graph of the source code elements;
[0020] Figure 7B This is a table illustrating some embodiments of the AST nodes encoded as numerical values according to the present invention;
[0021] Figure 8A The conversion from a binary AST to a numerical array representation according to some embodiments of the present invention is illustrated;
[0022] Figure 8B Some embodiments of the invention are shown for generating Figure 8C Numeric array representation Figure 4A Source code elements;
[0023] Figure 8C Some embodiments of the invention are shown. Figure 7A The numerical array representation of the binary AST, which is based on Figure 7B The encoding;
[0024] Figure 9 This is a table illustrating software vulnerabilities according to some embodiments of the concept proposed in this invention;
[0025] Figure 10 This is a table illustrating various aspects of a balanced subset of assessment data for different software vulnerabilities, based on some embodiments of the present invention.
[0026] Figure 11 These are graphs illustrating the performance of using a trained ML model according to some embodiments of the concept of the present invention;
[0027] Figure 12 This is a table illustrating various aspects of an imbalanced subset of assessment data for different software vulnerabilities, according to some embodiments of the present invention.
[0028] Figure 13These are graphs illustrating the performance of using a trained ML model according to some embodiments of the concept of the present invention;
[0029] Figure 14 This is a flowchart illustrating the operation of some embodiments of the concept according to the present invention;
[0030] Figure 15 This is a block diagram illustrating source code evaluation nodes according to some embodiments of the concept of the present invention;
[0031] Figure 16 This is a flowchart illustrating the operation of a source code evaluation node according to some embodiments of the present invention; Detailed Implementation
[0032] The inventive concept will now be described more fully below with reference to the accompanying drawings, which illustrate examples of embodiments of the inventive concept. However, the inventive concept can be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to make the invention thorough and complete, and to fully convey the scope of the inventive concept to those skilled in the art. It should also be noted that these embodiments are not mutually exclusive. It may be assumed by default that a component from one embodiment is present / used in another embodiment.
[0033] The following describes various embodiments of the disclosed subject matter. These embodiments are presented as illustrative examples and should not be construed as limiting the scope of the disclosed subject matter. For example, certain details of the described embodiments may be modified, omitted, or expanded without departing from the scope of the described subject matter.
[0034] Figure 15 This is a block diagram illustrating elements of a source code evaluation node configured to provide source code evaluation according to some embodiments of the present invention. As shown, the source code evaluation node may include network interface circuitry 1607 (also referred to as a network interface) configured to provide communication with other nodes. The source code evaluation node may also include processing circuitry 1603 (also referred to as a processor) coupled to the network interface circuitry, and memory circuitry 1605 (also referred to as memory) coupled to the processing circuitry. The memory circuitry 1605 may include computer-readable program code that, when executed by the processing circuitry 1603, causes the processing circuitry to perform operations according to embodiments disclosed herein. According to other embodiments, the processing circuitry 1603 may be defined to include memory, thereby eliminating the need for a separate memory circuitry.
[0035] As discussed herein, the operation of the source code evaluation node can be performed by processing circuitry 1603 and / or network interface circuitry 1607. For example, processing circuitry 1603 can control network interface circuitry 1607 to communicate with one or more other nodes. Furthermore, modules can be stored in memory 1605, and these modules can provide instructions such that when the instructions of a module are executed by processing circuitry 1603, processing circuitry 1603 performs the corresponding operation (e.g., as described below regarding...). Figure 16 (Discussion of operations).
[0036] Source code cannot be directly executed by the processor in a computer architecture. There are compilers or interpreters, which are various computer programs that process the source code and translate it into a lower-level programming language (e.g., assembly language, object code, or machine code) more suitable for execution by the instructions in the computer architecture. During the compilation of source code, several intermediate steps expose the source code elements to different processes, such as lexical analysis, parsing, and abstract syntax tree (AST) representation.
[0037] In lexical analysis, source code elements are transformed into a series of tokens by discarding any whitespace or comments. For example, in C, the following is a source code element (also known as a line of source code):
[0038] int a=5; / / This is a comment!
[0039] The following token sequence is generated.
[0040] int (keyword), a (identifier), = (operator), 5 (constant), ; (symbol).
[0041] During parsing, the tokens generated in lexical analysis are transformed into a data structure (primarily a rooted parse tree or other hierarchical structure) that provides a structural representation of the input while checking for grammatical correctness based on Context-Free Grammar (CFG) rules. This step can generate a non-binary abstract syntax tree (AST) representation of the given source code elements, which is a rooted tree-like data structure based on the tokens extracted from lexical analysis. For example, it can be like... Figure 1 The diagram shows a non-binary AST of the source code elements given above. Figure 1 The non-binary AST of the source code element "int a = 5; / / This is a comment!" is shown.
[0042] Non-binary ASTs may be a useful representation of source code elements because they include syntactic and semantic information associated with the source code elements.
[0043] Source code elements can be examined for a variety of reasons, including vulnerability detection or prediction, source code review and completion, translation into another language, synthesis, and patching. Regarding vulnerability detection, there are two main approaches that allow for some analysis of source code elements targeting potential vulnerabilities (also known as bugs). These methods include (i) static code analysis and (ii) dynamic code analysis. In static code analysis, source code elements are analyzed directly without execution, while in dynamic analysis, source code elements are executed using a specific set of inputs, and their behavior is observed against a predetermined target. Both analysis methods have open-source and commercial tools available.
[0044] On the other hand, with the emergence of artificial intelligence (AI) and machine learning (ML) technologies, there is a growing trend and research activity regarding how to leverage the advanced capabilities of AI / ML to provide intelligent software analysis. More specifically, there is significant interest in using AI / ML to automatically predict potential software vulnerabilities before they are released.
[0045] Machine learning algorithms can accept only numerical inputs for training and model development purposes. Validation and test data should also be numerical. However, source code elements are mostly written in high-level programming languages, including elements in forms unsuitable for direct processing by ML algorithms and models. Therefore, preprocessing of the source code may be necessary before feeding it into an ML model, according to some embodiments of the present invention.
[0046] Most previous studies in the literature have borrowed some methods from Natural Language Processing (NLP) techniques to process source code elements for ML applications, such as those discussed by Russell et al. in their publication “Automated Vulnerability Detection in Source Code Using Deep Representation Learning” (hereinafter referred to as reference [1]). One well-known method in this category is the Bag-of-Words (BoW), in which each word is labeled with a numerical value, and the occurrence count of each word and phrase is then counted to perform some further analysis. However, semantic information in source code elements may be lost in this approach, so these methods may not be able to represent source code elements well.
[0047] Another approach for source code processing is to use a non-binary AST representation of the source code elements, which is a tree-based data structure of the source code elements after they have been tokenized in a compiler or lexical analyzer / parser. Non-binary ASTs contain rich information about the original source code elements in terms of both semantics and syntacticity. Therefore, non-binary AST representations can be useful for ML applications. However, non-binary ASTs themselves may not be suitable for direct use by ML algorithms because they are based on tokens of source code elements.
[0048] One promising use case for software analysis using machine learning (ML) techniques is vulnerability prediction. Predicting potential vulnerabilities in source code elements can be useful, and its potential advantages will be discussed in more detail below. Traditional methods such as static code analysis and dynamic code analysis each have their advantages and disadvantages. In static code analysis tools, making target vulnerabilities formalized and defining rules to detect them may require manual engineering design. However, there may be too many false positives, and most static analysis tools may fail to detect most critical vulnerabilities. On the other hand, dynamic analysis may require running source code elements and observing their behavior to detect some vulnerabilities, and because it may be difficult to try and test all possible input sets, it can be time-consuming and / or prone to failure.
[0049] There are efforts and trends exploring how to leverage AI / ML techniques to predict potential vulnerabilities in source code elements before their release. This can be important because some vulnerabilities could lead to significant business losses. One unresolved issue in this area is how to properly represent source code elements for use by ML algorithms. This can be useful / necessary because ML algorithms may only accept numerical data for training and testing tasks. However, source code elements are simply strings, including letters, characters, numbers, operators, etc. Therefore, it may not be possible to directly input source code into ML algorithms.
[0050] According to some embodiments of the present invention, a method is provided for converting source code elements into a numerical array representation that enables intelligent analysis of the source code using machine learning techniques. In such a method, a non-binary abstract syntax tree (AST) representation of a given source code element is first obtained via a parser (it is a tree-like data structure based on extracted tokens). Then, the obtained non-binary AST is converted into a complete binary AST, where each node, except for the leaves, has two child nodes. Subsequently, the nodes in this complete binary AST structure are encoded into predefined numerical values (also called numeric keys) and auxiliary data associated with each node. Finally, depending on the position of each node in the binary AST, the resulting numerically labeled binary AST is converted into an array by mapping the nodes to immutable, consistent positions (indices) in the array.
[0051] Furthermore, the proposed method has been implemented, and experiments have been conducted to predict vulnerabilities in source code elements using ML. Initial experimental results appear promising and suggest that the proposed source code element representation method may be able to characterize some / all of the vulnerabilities considered in the experiments.
[0052] According to some embodiments of the present invention, intelligent analysis is performed directly on source code elements using data-driven technologies (e.g., AI / ML), including but not limited to vulnerability prediction, code review, code completion, synthesis, and remediation. Use cases and experimental results for vulnerability prediction are provided in this invention. For other use cases, the presence of any missing parts in the tree can be determined by examining the AST of the source code elements. If any are found, the model disclosed herein can propose which child nodes can be inserted into the missing parts. This example can also be applied to the 'code remediation' use case.
[0053] According to some embodiments of the present invention, a language-independent method is provided and can be applied to any high-level programming language.
[0054] According to some embodiments of the present invention, by paving the way for data-driven technologies (e.g., AI / ML), the need to perform specific analyses for domain experts and / or manual engineering designs is reduced or eliminated. For example, experiments have shown that vulnerability prediction can be performed even without knowing the details of the target vulnerability.
[0055] According to some embodiments of the present invention, the development of ML-based models and / or tools can be improved / optimized according to the intended objectives.
[0056] According to some embodiments of the present invention, a method for performing predictive analytics is provided.
[0057] According to some embodiments of the present invention, a numerical vector representation of a given source code element can be provided while preserving semantic information.
[0058] According to some embodiments of the present invention, automated code analysis with various objectives (e.g., vulnerability detection) can be performed. With the rise of artificial intelligence (AI), there is a trend towards using machine learning (ML) and data mining techniques to perform intelligent analysis on source code elements. For example, predicting potential software vulnerabilities in source code elements in advance using ML algorithms is an important research area. However, how to do this is unclear, and there is currently no state-of-the-art method for this purpose. The difficulties may stem from several factors, such as (i) a lack of useful and sufficiently large datasets accurately labeled with identified vulnerabilities, and (ii) a lack of efficient methods to convert source code elements into a useful data format that can be directly used to train ML models. In fact, source code elements, which are essentially composed of words and phrases in natural form, may not be suitable for direct use by ML models because only numerical data of vector or matrix structures can be used to train and develop ML algorithms. In this invention, a method is provided to translate source code elements into a useful vector structure that includes numerical values (e.g., only numerical values) (which may be suitable for direct use by ML algorithms) while preserving as much semantic and syntactic information as possible about the original source code elements. Furthermore, the proposed method can be implemented, and experiments can be conducted with the goal of vulnerability prediction on a large public dataset containing function-level source code elements labeled with known / certain vulnerability types. Therefore, the experimental results demonstrate the feasibility of the proposed method.
[0059] Figure 2 The operation of methods according to some embodiments of the present invention is illustrated, and these operations are also... Figure 14 The flowchart is shown.
[0060] Operation 1 (Source Code): In Operation 1, the source code to be processed is taken as input. The source code can be written in any high-level programming language. For example, Figure 3 This shows a sample / segment of source code written in C, which includes two source code elements.
[0061] Operation 2 (Function-Level Partitioning): In Operation 2, the source code of a program or application can be arbitrarily long in terms of the number of source code elements (also known as defined lines of source code and / or source code functions). Therefore, a good practice might be to break the source code down into function-level source code elements to improve the granularity of processing and, to some extent, reduce / limit its size. This can be done manually or automatically using a parser. Each source code element is then processed separately in the following operations. After Operation 2, the term "source code element" is used in the sense of a function-level source code element. Figure 4A and Figure 4B It shows from Figure 3 Extract two source code elements (function-level source code elements) from the original source code.
[0062] Operation 3 (Tokenization): In Operation 3, source code elements can be cleaned up first by removing unimportant parts of the source code elements (such as comments, whitespace, tabs, newlines, etc.). Figure 4A The main function of the source code is then used. The remaining elements of the source code are then converted into a series of tokens, where each token is a sequence of text characters that can be considered a unit of the programming language's syntax. This can be achieved using a lexical analyzer specifically developed for source code languages. For example, Figure 4A The tokens for the main function can be given as follows: int (keyword), main (identifier), LPAREN (delimiter), RPAREN (delimiter), = (operator), 5 (constant), ; (symbol)...
[0063] Operation 4 (Non-Binary AST Generation): In Operation 4, a non-binary AST of the source code elements is generated, which can be achieved using a parser specifically developed for source code languages. A non-binary AST contains rich information about the source code elements, including, to some extent, syntactic and semantic information. It should be noted that nodes in a non-binary AST can have any number of children, which may make it difficult / impossible to estimate in advance the number of nodes at a certain depth in the non-binary AST. This can be a problem when attempting to map the nodes of a non-binary AST to a fixed-length array. Solutions to this problem are discussed below for Operation 5. Figure 5 It shows Figure 4A The main function source code elements are non-binary ASTs. In this non-binary AST, each node is a token node corresponding to one of the tokens of the source code elements, and each token of the source code elements can be represented in the corresponding node of the non-binary AST.
[0064] Operation 5 (Convert to a Full Binary AST): Operation 5 is important for consistently distributing the elements (nodes) of a non-binary AST into a fixed-length array (as described in the following operations). In a regular non-binary AST, a node can have any number of children, while a node in a binary AST can have at most two children, often called the left and right children. Operation 5 converts a regular non-binary AST to a full binary AST, where all leaves (also called terminal nodes) have the same depth, and all internal nodes (also called non-terminal nodes) have a degree of 2 (meaning an internal node has two children). Many alternative methods may exist for converting a m-ary non-binary abstract syntax tree to a binary abstract syntax tree, and any of these methods can be used in this operation. For example, a method based on the following two rules can be used to convert a m-ary non-binary abstract syntax tree to its corresponding full binary abstract syntax tree:
[0065] 1) Assign the leftmost child node of Node-x in the m-ary non-binary abstract syntax tree to the right child node of Node-x in the corresponding complete binary abstract syntax tree, and
[0066] 2) Assign the right sibling of Node-x in the m-ary non-binary abstract syntax tree to the left child of Node-x in the corresponding complete binary abstract syntax tree.
[0067] If Node-x (e.g., a node corresponding to a non-binary AST and a binary AST token node corresponding to a token of a source code element) has no children, its right child becomes null (called a null binary AST node), and if Node-x is the rightmost child of its parent node, its left child becomes null (called a null binary AST node). Figure 6A and Figure 6B The example illustrates the conversion of a regular m-ary non-binary abstract syntax tree into a complete binary abstract syntax tree according to some embodiments. Dashed null nodes (also known as null nodes in a binary AST) are added to provide a complete binary abstract syntax tree. In such a complete binary AST, each level i includes 2... i There are 10 nodes, so each level is "complete".
[0068] As an example, it can be provided at operation 4. Figure 6A The example shown is a regular m-ary non-binary abstract syntax tree.
[0069] based on Figure 6A Given an m-ary non-binary abstract syntax tree, it is possible to perform operations at point 5, such as... Figure 6B The diagram shows the corresponding complete binary abstract syntax tree.
[0070] Figure 6B Therefore, the corresponding figure is shown. Figure 6A The sample is a regular non-binary abstract syntax tree of a complete binary abstract syntax tree.
[0071] As mentioned above, a complete binary abstract syntax tree (BAST) can grow exponentially until all leaves become null. However, this can lead to a huge number of child nodes as the depth of the BAST increases. Therefore, in some embodiments, it may be sufficient to consider a BAST with a depth that reaches a threshold, which can be determined based on performance requirements. In experimental studies, a partial BAST with a depth of 12 can adequately represent the entire BAST. By limiting the depth of the complete BAST in operation 5, the size of the complete BAST (including the total number of nodes and levels) can be fixed, independent of the size of the corresponding non-binary AST, allowing one or more tokens of source code elements to be omitted from the complete BAST, and / or allowing the number of non-binary token nodes in the non-binary AST to exceed the number of binary AST token nodes in the complete BAST.
[0072] As an example, Figure 7A yes Figure 3 , Figure 4A and Figure 4B The binary AST of the function 'main' is given in the example.
[0073] Figure 7A Therefore, it is shown Figure 5 The complete binary AST is shown in the figure.
[0074] In a binary AST, the token node (in) Figure 7A The ellipse shown (also called a binary AST token node) corresponds to the non-binary AST token node (also called a non-binary AST token node) and corresponds to the token of the source code element, and the empty node (in) Figure 7A The diagram shown is a square (also called a binary AST empty node) used to provide each level i including 2 i There are n nodes, and each node in each level (not the last level, level n) has two child nodes. In a complete binary AST of depth n, the binary AST has levels i = 0, 1, 2, ..., n (corresponding to depths 0, 1, 2, ..., n), and each level i of the binary AST includes 2 nodes. i There are n nodes, and each node at level i = 0, 1, 2, ..., n-1 has 2 child nodes at the next level. A binary AST includes... The number of nodes, and the numerical array representation (operation 7) includes nodes corresponding to the binary AST respectively. Nodes A number.
[0075] Operation 6 (Encoding as Numerical Values): In the obtained complete binary AST, nodes are named with words or text strings such as "FuncDef (function definition)", "Decl (declaration)", "TypeDecl (type declaration)", "Constant (constant)", and "ID" (corresponding to the tokens of the source code elements discussed above). These names are encoded as numerical values to allow ML algorithms to process them. Therefore, these node names can be mapped to predetermined numerical values, where each numerical value of the node name can be provided as a numeric tuple. Figure 7B The table shows an example of encoding from token name to numeric tuple.
[0076] In this encoding, the first number in the encoded numeric tuple indicates the type of token, while the second and third numbers can be used to provide auxiliary information that may exist at the node. This encoding is merely an example based on one embodiment. It should be noted that the token and the encoded numeric value may vary depending on the programming language.
[0077] Operation 7 (represented by a numerical array): Operation 7 can be the final operation. It should be noted that in a complete binary abstract syntax tree, the number of nodes that can exist at each depth (level) can be fixed. For example, level 1 can have a maximum of 2 nodes, level 2 can have a maximum of 4 nodes, level 3 can have a maximum of 8 nodes, level 4 can have a maximum of 16 nodes, and so on. The number of nodes that can exist at each level increases in powers of 2. Therefore, at depth k, a maximum of 2 nodes can exist. k This determinism allows for the creation of fixed-length numerical array representations, where element indices can be consistently assigned to nodes in a binary AST, such as... Figure 8A As shown, where Figure 8A This demonstrates how to convert a binary abstract syntax tree data structure into a numerical array representation.
[0078] Figure 4A The main function given in (reproduced as) Figure 8B ) was converted Figure 8C The numerical array representation.
[0079] Figure 8C The diagram shows a numerical array representation of the source code elements of a given function, up to a depth of 10. By choosing a depth of 10 for the binary AST (i.e., n = 10), the binary AST will have 2047 nodes, computed as follows: More generally, the number of nodes N can be calculated as:
[0080]
[0081] Where: N is the number of nodes in the binary AST, n is the depth of the binary AST, and i represents each level from 0 to n.
[0082] According to some embodiments conceived in this invention, one advantage of this numerical array representation is that each specific index (position) of the numerical array representation represents / preserves a feature (corresponding to a node in the corresponding binary AST), and these indices are always associated with the same node in the binary AST. This allows semantic information in the binary AST to be transferred to the numerical array representation, which can be a useful property for comparing binary ASTs of different source code elements and extracting patterns and hidden relationships between nodes.
[0083] According to some implementations, use cases can provide vulnerability predictions for source code.
[0084] To demonstrate the feasibility and usefulness of the proposed method for performing intelligent analysis of source code elements using ML techniques, the proposed method was implemented and experiments were conducted with the aim of predicting certain vulnerabilities in a given source code element. For this purpose, a public dataset (given as the Draper VDISC dataset in reference [1]) was used, which contains a relatively large number of function-level source code elements labeled with five different categories of vulnerabilities. The source code elements in this dataset were extracted from Debian Linux distributions, Git repositories on GitHub, and the SATE IV Juilet test suite of the NIST Samate project, and were then subjected to static tool analysis and investigated by security experts to label them for including certain predefined vulnerabilities. The following section discusses… Figure 9 The flaws in the investigation were described.
[0085] Figure 9 The types of vulnerabilities investigated in the experimental work (each involving common vulnerability enumeration or CWE) and the number of samples in each category are shown.
[0086] The method according to some embodiments is implemented using a neural network model. Two different performance evaluation tests were then performed on (i) a balanced dataset (i.e., containing the same number of positive and negative samples in both the training and test sets) and (ii) an imbalanced dataset (i.e., the dataset contains more positive samples than negative samples, or vice versa). Experimental results are presented in the following disclosure.
[0087] The following text is about Figure 10 and Figure 11 Discuss the performance evaluation of balanced datasets.
[0088] In this section, a balanced subset is extracted from the original dataset referenced above; details are provided in [the relevant section]. Figure 10 The information is provided in the text. Figure 10 It provides the number of positive and negative samples in the balanced dataset obtained by undersampling the original dataset. Figure 11 True positive rate and false positive rate of ML (neural network) implementations for testing balanced datasets according to some embodiments of the present invention are provided.
[0089] like Figure 11 As shown, the trained model performs well across all categories compared to no skill (random decision-making), even though these are initial results without adjusting hyperparameters to improve / optimize the model. These results suggest that the proposed source code representation method may be very useful in use cases for vulnerability prediction in source code.
[0090] about Figure 12 and Figure 13 Performance evaluation of imbalanced datasets is discussed.
[0091] In this section, we utilize Figure 12 The details provided are for using a subset of the original dataset. Figure 12 It provides the number of positive and negative samples in the imbalanced dataset. Figure 13 It provides accuracy callback curves for different categories tested on imbalanced datasets.
[0092] Figure 13 The precision pullback (PR) curves for different categories are shown. Potential f1 score curves also exist. When interpreting this figure, the ratio of positive to negative samples should be considered, as it determines the baseline.
[0093] According to some embodiments of the present invention, a source code representation method for machine learning applications is provided.
[0094] According to some embodiments of the present invention, a method for translating source code elements into numerical array representations is provided.
[0095] According to some embodiments of the present invention, a method is provided for preprocessing source code elements before they are fed into an ML implementation.
[0096] According to some embodiments of the present invention, a method for directly performing intelligent analysis on source code elements is provided.
[0097] According to some embodiments of the present invention, a method for providing vulnerability prediction directly from source code elements is provided.
[0098] According to some embodiments of the present invention, a method is provided that can provide automated source code analysis without the need for any domain experts or manual engineering design.
[0099] According to some embodiments of the present invention, a method is provided for encoding tokens identified in lexical analysis of source code elements into numerical values.
[0100] According to some embodiments of the present invention, a method is provided for encoding a binary AST representation of source code elements into a numerical array representation.
[0101] Reference will now be made to some embodiments based on the concept of the present invention. Figure 16 The flowchart is used to discuss the source code evaluation node 1600 (using Figure 15 The operation is implemented using a structure. For example, modules can be stored in... Figure 15 The memory 1605 contains these modules, and these modules can provide instructions such that when the instructions of the modules are executed by the processing circuit 1603, the processing circuit 1603 performs the corresponding operation of the flowchart.
[0102] At block 1701, processing circuitry 1603 provides source code for a programming language (e.g., a high-level programming language), wherein the source code includes multiple source code elements. For example, the operation of block 1701 can be as described above regarding... Figure 14 It shall be performed as discussed in Operation 1.
[0103] At block 1705, processing circuitry 1603 selects a first source code element (e.g., a function-level source code element) from the plurality of source code elements. According to some embodiments, the first source code element may include letters, characters, numbers, and operators. For example, the operation at block 1705 may be as described above regarding... Figure 14 It will be performed as discussed in Operation 2.
[0104] At box 1709, processing circuitry 1603 generates a first plurality of tokens based on a first source code element, wherein each of the first plurality of tokens comprises a sequence of text characters. According to some embodiments, the first plurality of tokens can be generated based on lexical analysis of the first source code element. For example, the operation of box 1709 can be as described above regarding... Figure 14 It shall be performed as discussed in Operation 3.
[0105] According to some embodiments, at block 1711, processing circuitry 1603 can generate a non-binary abstract syntax tree (AST) representation of the first source code element based on a first plurality of tokens of the first source code element. This non-binary AST representation can include non-binary AST token nodes, and each of the non-binary AST token nodes can be based on a corresponding one of the first plurality of tokens of the first source code element. According to such embodiments, a binary AST representation of block 1715 can be generated based on the non-binary AST representation of block 1711, and each of the binary AST token nodes can correspond to a corresponding one of the non-binary AST token nodes. In such embodiments, the number of non-binary AST token nodes can exceed the number of binary AST token nodes. For example, the operation of block 1711 can be as described above regarding... Figure 14 It will be performed as discussed in Operation 4.
[0106] At block 1715, processing circuitry 1603 generates a first binary abstract syntax tree (AST) representation of the first source code element based on a first plurality of tokens of the first source code element. The first binary AST representation includes a first plurality of binary AST nodes, each of which includes binary AST token nodes and binary AST empty nodes. Each of the binary AST token nodes in the first binary AST representation is based on a corresponding one of the first plurality of tokens of the first source code element. For example, the operation at block 1715 can be as described above regarding... Figure 14 Perform it as discussed in Operation 5.
[0107] According to some embodiments, the number of the first plurality of tokens based on the source code can exceed the number of binary AST token nodes in the first binary AST representation. For example, the binary AST representation can have a depth n, and the binary AST representation can have levels i = 0, 1, 2, ... n, where each level i of the binary AST representation can include 2 i There are nodes, and each node at level i = 0, 1, 2, ..., n-1 can have 2 child nodes at the next level. A binary AST representation can include... Each node can be represented by a numerical array, which may include nodes corresponding to a binary AST representation. Nodes There are several numerical values. Therefore, at least one of the first plurality of tokens generated based on the first source code element can be omitted from the binary AST representation.
[0108] At box 1719, processing circuitry 1603 encodes each of the binary AST token nodes and binary AST empty nodes into a corresponding value (e.g., a numeric tuple). For example, the operation of box 1719 can be as described above regarding... Figure 14 It shall be performed as discussed in Operation 6.
[0109] At block 1721, processing circuit 1603 generates a first numerical array representation of the first source code element based on the first binary AST representation, wherein the first value of the corresponding binary AST token node and binary AST empty node is mapped to the position in the first numerical array representation based on the corresponding position of the binary AST token node and binary AST empty node in the first binary AST representation. For example, the operation of block 1721 can be as described above regarding... Figure 14 It shall be performed as discussed in Operation 7.
[0110] The operations of boxes 1705, 1709, 1711, 1715, 1719, and / or 1721 can be repeated at box 1725 for each source code element of the source code. At box 1725, the processing circuit 1603 can determine whether a numerical array representation has been generated for all source code elements of the source code; if not, the operations of boxes 1705, 1709, 1711, 1715, 1719, and / or 1721 can be repeated for the next source code element of the source code, as described below.
[0111] According to some embodiments, at block 1705, processing circuitry 1603 can select a second source code element from the plurality of source code elements of the source code.
[0112] According to some embodiments, at block 1709, processing circuitry 1603 can generate a second plurality of tokens based on a second source code element, wherein each of the second plurality of tokens includes a sequence of text characters.
[0113] According to some embodiments, at block 171l, processing circuitry 1603 can generate a second non-binary abstract syntax tree (AST) representation of the second source code element based on a second plurality of tokens of the second source code element. The second non-binary AST representation may include non-binary AST token nodes, and each of the non-binary AST token nodes in the second non-binary AST representation may be based on a corresponding one of the second plurality of tokens of the second source code element.
[0114] According to some embodiments, at block 1715, processing circuitry 1603 can generate a second binary abstract syntax tree (AST) representation of the second source code element based on a second plurality of tokens of the second source code element. The second binary AST includes a second plurality of binary AST nodes, each of which includes binary AST token nodes and binary AST empty nodes. Each of the binary AST token nodes in the second binary AST is based on a corresponding one of the second plurality of tokens of the second source code element. According to such embodiments, the second binary AST representation of block 1715 can be generated based on the second non-binary AST representation of block 1711, and each of the binary AST token nodes in the second binary AST representation can correspond to a corresponding one of the non-binary AST token nodes. In such embodiments, the number of non-binary AST token nodes in the second non-binary AST representation can exceed the number of binary AST token nodes in the second binary AST representation.
[0115] According to some embodiments, at block 1719, processing circuitry 1603 can encode each of the token nodes and empty nodes of the second plurality of binary AST nodes into a corresponding value.
[0116] According to some embodiments, at block 1721, the processing circuit 1603 can generate a second numerical array representation of the second source code element based on the second binary AST representation, wherein the values of the token node and the empty node are mapped to the positions in the second numerical array representation based on the corresponding positions of the corresponding token node and the empty node in the second binary AST representation of the second plurality of binary AST nodes.
[0117] According to some embodiments at box 1725, processing circuitry 1603 can determine whether numerical array representations have been generated for all source code elements of the source code. If not, the operations of boxes 1705, 1709, 1711, 1715, 1719, and / or 1721 can be repeated at box 1725 for the next source code element. Otherwise, at box 1729, processing circuitry 1603 can evaluate the source code using a machine learning (ML) model based on one or more numerical array representations of the individual source code elements, where the ML model is based on a dataset of source code elements.
[0118] According to some embodiments, the evaluation of block 1729 may include one or more of the following: using an ML model to predict software vulnerabilities in source code, detecting vulnerabilities in source code, identifying errors in source code, and / or correcting errors in source code, wherein the ML model is based on a dataset of source code elements and is based on at least one of the following: a corresponding vulnerability corresponding to a source code element in the dataset, and / or a corresponding error corresponding to a source code element in the dataset.
[0119] According to some embodiments, the processing circuitry can use an ML model to evaluate each numerical array representation of each source code element. For example, processing circuitry 1603 can use a first numerical array representation and an ML model to evaluate a first source code element to predict software vulnerabilities in the first source code element, detect vulnerabilities in the first source code element, identify errors in the first source code element, and / or correct errors in the first source code element. Furthermore, processing circuitry 1603 can use a second numerical array representation and an ML model to evaluate a second source code element to predict software vulnerabilities in the second source code element, detect vulnerabilities in the second source code element, identify errors in the second source code element, and / or correct errors in the second source code element.
[0120] like Figure 16 As shown, a numeric array representation can be generated for all source code elements before evaluating the source code using a numeric array representation at box 1729. According to some other embodiments, each source code element can be evaluated using its corresponding numeric array representation before generating the next numeric array representation for the next source code element (e.g., moving box 1729 between boxes 1721 and 1725).
[0121] According to some embodiments, processing circuitry 1603 can generate an output indicating at least one of the following (e.g., an output to be presented on a video display): a predicted software vulnerability in the first source code element, a detected vulnerability in the first source code element, an error in the first source code element, and / or a correction to the first source code element. According to some embodiments, processing circuitry 1603 can automatically generate (without user intervention) a corrected version of the first source code element in response to evaluating the first source code element at block 1729, and processing circuitry 1603 can store the corrected version of the first source code element in memory 1605. According to some embodiments, in response to evaluating the first source code element at block 1729, processing circuitry 1603 can automatically generate (without user intervention) a corrected version of the first source code element, and processing circuitry 1603 can store a revised version of the source code including the corrected version of the first source code element in memory 1605.
[0122] From Figure 16 The various operations in the flowchart may be optional for some embodiments of the source code evaluation nodes and related methods. For example, regarding the methods of some embodiments, Figure 16 The operations in boxes 1711, 1725 and / or 1729 can be optional.
[0123] Additional explanations are provided below.
[0124] Generally, all terms used herein should be interpreted according to their ordinary meaning in the relevant art, unless explicitly given and / or implied from the context of their use. Unless otherwise expressly stated, all references to "a / an / element, device, component, apparatus, step, etc." should be interpreted as referring to at least one instance of that element, device, component, apparatus, step, etc. The steps of any method disclosed herein need not be performed in the exact order disclosed, unless a step is explicitly described as occurring after or before another step and / or implied that a step must occur after or before another step. Any feature of any embodiment disclosed herein may be applied to any other embodiment, where appropriate. Similarly, any advantage of any embodiment may be applied to any other embodiment, and vice versa. Other objects, features, and advantages of the appended embodiments will become apparent from the following description.
[0125] Some embodiments contemplated herein have been described with reference to the accompanying drawings. However, other embodiments are included within the scope of the subject matter disclosed herein, and the disclosed subject matter should not be construed as being limited to the embodiments set forth herein; rather, these embodiments are provided by way of example to convey the scope of the subject matter to those skilled in the art.
[0126] In the above description of various embodiments of the inventive concept, it should be understood that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the inventive concept. Unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which the inventive concept pertains. It will be further understood that terms such as those defined in common dictionaries should be interpreted as having the same meaning as in the context of this specification and related art, and should not be interpreted in an idealized or overly formal sense unless expressly defined herein.
[0127] When an element is referred to as “connected,” “coupled,” “responded,” or a variation thereof to another element, it may be directly connected, coupled, or responded to the other element, or there may be an intermediate element. Conversely, when an element is referred to as “directly connected,” “directly coupled,” “directly responded,” or a variation thereof to another element, there is no intermediate element. The same numbers always refer to the same element. Furthermore, “coupled,” “connected,” “responded,” or a variation thereof as used herein may include wireless coupling, connection, or response. As used herein, the singular forms “a,” “an,” and “the” are intended to also include the plural forms unless the context clearly indicates otherwise. For the sake of brevity and / or clarity, well-known functions or structures may not be described in detail. The term “and / or” (abbreviated as “ / ”) includes any and all combinations of one or more of the related listed items.
[0128] It should be understood that although the terms first, second, third, etc., may be used herein to describe various elements / operations, these elements / operations should not be limited by these terms. These terms are only used to distinguish one element / operation from another. Therefore, without departing from the teachings of the inventive concept, a first element / operation in some embodiments may be referred to as a second element / operation in other embodiments. Throughout the specification, the same element symbols or the same reference numerals denote the same or similar elements.
[0129] As used herein, the terms “comprising,” “including,” “having,” or variations thereof are open-ended and include one or more features, integers, elements, steps, components, or functions of the statement, but do not preclude the presence or addition of one or more other features, integers, elements, steps, components, functions, or groups thereof. Furthermore, as used herein, the general abbreviation “eg,” derived from the Latin phrase “exempligratia,” may be used to introduce or specify one or more general examples of the foregoing items and is not intended to limit such items. The common abbreviation “ie,” derived from the Latin phrase “id est,” may be used to specify a particular item from a more general description.
[0130] Example embodiments are described herein with reference to block diagrams and / or flowcharts of computer-implemented methods, apparatus (systems and / or devices), and / or computer program products. It should be understood that the blocks illustrated in the block diagrams and / or flowcharts, and combinations of blocks illustrated in the block diagrams and / or flowcharts, can be implemented by computer program instructions executed by one or more computer circuits. These computer program instructions can be provided to processor circuitry of general-purpose computer circuitry, special-purpose computer circuitry, and / or other programmable data processing circuitry to produce a machine, such that instructions executed via the processor of a computer and / or other programmable data processing apparatus translate and control transistors, values stored in memory locations, and other hardware components in such circuitry to implement the functions / actions specified in one or more blocks of the block diagrams and / or flowcharts, thereby creating apparatus (functions) and / or structures for implementing the functions / actions specified in the blocks of the block diagrams and / or flowcharts.
[0131] These computer program instructions may also be stored in a tangible computer-readable medium that can direct a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable medium produce an article of writing of instructions comprising functions / actions specified in one or more blocks of an execution block diagram and / or flowchart. Therefore, embodiments of the inventive concept can be embodied in hardware and / or software (including firmware, resident software, microcode, etc.) that runs on a processor such as a digital signal processor, which may be collectively referred to as a "circuit," a "module," or a variant thereof.
[0132] It should also be noted that in some alternative implementations, the functions / actions indicated in the boxes may not occur in the order shown in the flowchart. For example, depending on the functions / actions involved, two boxes shown consecutively may actually be executed substantially simultaneously, or these boxes may sometimes be executed in reverse order. Furthermore, the function of a given box in a flowchart and / or block diagram may be divided into multiple boxes, and / or the functions of two or more boxes in a flowchart and / or block diagram may be at least partially integrated. Finally, without departing from the scope of the inventive concept, other boxes may be added / inserted between the boxes shown, and / or boxes / operations may be omitted. Additionally, while some diagrams include arrows on communication paths to show the main direction of communication, it should be understood that communication may occur in the opposite direction to the depicted arrows.
[0133] Many variations and modifications can be made to the embodiments without substantially departing from the principles of the inventive concept. All such variations and modifications are intended to be included within the scope of the inventive concept. Therefore, the subject matter disclosed above is to be considered illustrative rather than restrictive, and the examples of embodiments are intended to cover all such modifications, enhancements, and other embodiments falling within the spirit and scope of the inventive concept. Thus, to the maximum extent permitted by law, the scope of the inventive concept should be determined by the broadest permissible interpretation of the invention, including examples of embodiments and their equivalents, and should not be construed as limited or restricted by the foregoing detailed description.
[0134] The following provides an explanation of the various abbreviations / acronyms used in this invention.
[0135] Abbreviation Explanation
[0136] AI (Artificial Intelligence)
[0137] Abstract Syntax Tree (AST)
[0138] Bag of Words (BoW)
[0139] CWE Common Weakness Enumeration
[0140] ML Machine Learning
[0141] NLP Natural Learning Processing
[0142] PR accuracy callback
[0143] The references are as follows.
[0144] Reference [1] Russell, Rebecca & Kim, Louis & Hamilton, Lei & Lazovich, Tomo & Harer, Jacob & Ozdemir, Onur & Ellingwood, Paul & McConley, Marc. (2018). Automated Vulnerability Detection in Source Code Using Deep Representation Learning. 757 - 762. 10.1109 / ICMLA.2018.00120.
Claims
1. A method for evaluating the source code of a programming language, the method comprising: Provide the source code of the programming language (1701), wherein the source code includes a plurality of source code elements; Select (1705) source code element from the plurality of source code elements of the source code; (1709) Multiple tokens are generated based on the source code elements, wherein each of the multiple tokens comprises a sequence of text characters; (1711) Generate a non-binary abstract syntax tree (AST) representation of the source code element based on the plurality of tokens of the source code element, wherein the non-binary AST representation includes non-binary AST token nodes, wherein each of the non-binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. (1715) Generate (1715) a binary AST representation of the source code element based on the plurality of tokens of the source code element and the non-binary AST representation, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element, and wherein each of the binary AST token nodes corresponds to a corresponding one of the non-binary AST token nodes; Each of the binary AST token nodes and the binary AST empty nodes is encoded (1719) with a corresponding value; (1721) Generate a numerical array representation of the source code element based on the binary AST representation, wherein the values of the corresponding binary AST token node and binary AST empty node are mapped to their respective positions in the numerical array representation based on their corresponding positions in the binary AST representation. as well as The source code (1729) is evaluated using a machine learning (ML) model based on the numerical array representation of the source code elements.
2. The method according to claim 1, wherein the number of non-binary AST token nodes exceeds the number of binary AST token nodes.
3. The method of claim 1, wherein each of the plurality of tokens based on the source code exceeds the number of the binary AST token nodes.
4. The method of claim 1, wherein the binary AST represents a depth n, wherein the binary AST represents a level i = 0, 1, 2, ... n, wherein each level i of the binary AST represents 2 i There are n nodes, where each node at level i = 0, 1, 2, ..., n-1 has 2 child nodes at the next level, wherein the binary AST representation includes... The number of nodes, and wherein the numerical array representation includes the nodes respectively corresponding to the binary AST representation. Each node A number.
5. The method of claim 4, wherein at least one of the plurality of tokens generated based on the source code elements is omitted from the binary AST representation.
6. The method of claim 1, wherein generating the plurality of tokens comprises generating the plurality of tokens based on lexical analysis of the source code elements.
7. The method of claim 1, wherein the source code elements include letters, characters, numbers, and operators.
8. The method of claim 1, wherein for each of the binary AST token nodes, the corresponding value comprises a numeric tuple.
9. The method of claim 1, wherein the ML model is based on a dataset of source code elements.
10. The method of claim 9, wherein the evaluation comprises at least one of: using the ML model to predict software vulnerabilities in the source code, detecting vulnerabilities in the source code, identifying errors in the source code, and / or correcting errors in the source code, wherein the ML model is based on a dataset of source code elements and is based on at least one of: vulnerabilities corresponding to source code elements of the dataset, and / or errors corresponding to source code elements of the dataset.
11. The method according to claim 9 or 10, wherein the source code element is a first source code element, wherein the plurality of tokens are a first plurality of tokens, wherein the binary AST representation is a first binary AST representation, and wherein the plurality of binary AST nodes are a first plurality of binary AST nodes, the method further comprising: Select (1705) the second source code element from the plurality of source code elements of the source code; (1709) A second plurality of tokens are generated based on the second source code element, wherein each of the second plurality of tokens comprises a sequence of text characters; (1715) A second binary abstract syntax tree (AST) representation of the second source code element is generated based on the second plurality of tokens of the second source code element, wherein the second binary AST representation includes a second plurality of binary AST nodes, the second plurality of binary AST nodes include binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes of the second binary AST representation is based on a corresponding one of the second plurality of tokens of the second source code element. Encode (1719) each of the token nodes and empty nodes of the second plurality of binary AST nodes with the corresponding value; and (1721) A second numerical array representation of the second source code element is generated based on the second binary AST representation, wherein the values of the corresponding token node and the empty node in the second binary AST representation are mapped to the positions in the second numerical array representation based on the corresponding positions of the corresponding token node and the empty node in the second binary AST representation; The evaluation of the source code includes evaluating the source code based on a first numerical array representation of the first source code element and a second numerical array representation of the second source code element.
12. A source code evaluation node (1600) including modules suitable for performing the following operations: Provide the source code of a programming language, wherein the source code includes multiple source code elements; Select a source code element from the plurality of source code elements in the source code; Multiple tokens are generated based on the source code elements, wherein each of the multiple tokens comprises a sequence of text characters; A non-binary abstract syntax tree (AST) representation of the source code element is generated based on the plurality of tokens of the source code element, wherein the non-binary AST representation includes non-binary AST token nodes, wherein each of the non-binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. An AST representation of the source code element is generated based on the plurality of tokens of the source code element and the non-binary AST representation, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element, and wherein each of the binary AST token nodes corresponds to a corresponding one of the non-binary AST token nodes. Encode each of the binary AST token nodes and binary AST empty nodes into a corresponding value; A numerical array representation of the source code elements is generated based on the binary AST representation, wherein the values of the corresponding binary AST token node and binary AST empty node are mapped to their respective positions in the numerical array representation based on their corresponding positions in the binary AST representation. as well as The source code is evaluated using a machine learning (ML) model based on the numerical array representation of the source code elements.
13. The source code evaluation node (1600) according to claim 12, wherein the number of non-binary AST token nodes exceeds the number of binary AST token nodes.
14. The source code evaluation node (1600) of claim 12, wherein each of the plurality of tokens based on the source code exceeds the number of the binary AST token nodes.
15. The source code evaluation node (1600) according to claim 12, wherein the binary AST representation has a depth n, wherein the binary AST representation has levels i = 0, 1, 2, ... n, wherein each level i of the binary AST representation includes 2 i There are n nodes, where each node in level i = 0, 1, 2, ..., n-1 has 2 child nodes in the next level, wherein the binary AST representation includes... The number of nodes, and wherein the numerical array representation includes the nodes respectively corresponding to the binary AST representation. Each node A number.
16. The source code evaluation node (1600) of claim 15, wherein at least one of the plurality of tokens generated based on the source code elements is omitted from the binary AST representation.
17. The source code evaluation node (1600) of claim 12, wherein generating the plurality of tokens includes generating the plurality of tokens based on lexical analysis of the source code elements.
18. The source code evaluation node (1600) according to claim 12, wherein the source code elements include letters, characters, numbers, and operators.
19. The source code evaluation node (1600) of claim 12, wherein for each of the binary AST token nodes, the corresponding value comprises a numeric tuple.
20. The source code evaluation node (1600) of claim 12, wherein the ML model is based on a dataset of source code elements.
21. The source code evaluation node (1600) of claim 20, wherein the evaluation includes at least one of the following: using the ML model to predict software vulnerabilities in the source code, detecting vulnerabilities in the source code, identifying errors in the source code, and / or correcting errors in the source code, wherein the ML model is based on a dataset of source code elements and is based on at least one of the following: vulnerabilities corresponding to source code elements of the dataset, and / or errors corresponding to source code elements of the dataset.
22. The source code evaluation node (1600) according to claim 20 or 21, wherein the source code element is a first source code element, wherein the plurality of tokens are a first plurality of tokens, wherein the binary AST representation is a first binary AST representation, and wherein the plurality of binary AST nodes are a first plurality of binary AST nodes, and wherein the source code evaluation node (1600) further comprises modules adapted to perform the following operations: Select a second source code element from the plurality of source code elements in the source code; A second plurality of tokens are generated based on the second source code element, wherein each of the second plurality of tokens comprises a sequence of text characters; A second binary abstract syntax tree (AST) representation of the second source code element is generated based on the second plurality of tokens of the second source code element, wherein the second binary AST representation includes a second plurality of binary AST nodes, the second plurality of binary AST nodes include binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes in the second binary AST representation is based on a corresponding one of the second plurality of tokens of the second source code element; Encode each of the token nodes and empty nodes in the second plurality of binary AST nodes into a corresponding value; and A second numerical array representation of the second source code element is generated based on the second binary AST representation, wherein the values of the corresponding token node and empty node in the second plurality of binary AST nodes are mapped to the positions in the second numerical array representation based on the corresponding positions of the corresponding token node and empty node in the second binary AST representation; The evaluation of the source code includes evaluating the source code based on a first numerical array representation of the first source code element and a second numerical array representation of the second source code element.
23. A source code evaluation node (1600), comprising: Processing circuit (1603); as well as A memory (1605) coupled to the processing circuitry, wherein the memory includes instructions that, when executed by the processing circuitry, cause the source code evaluation node (1600) to perform the following operations: Provide the source code for a programming language, wherein the source code includes multiple source code elements. Select a source code element from the plurality of source code elements in the source code. Multiple tokens are generated based on the source code elements, wherein each of the multiple tokens comprises a sequence of text characters. A non-binary abstract syntax tree (AST) representation of the source code element is generated based on the plurality of tokens of the source code element, wherein the non-binary AST representation includes non-binary AST token nodes, and each of the non-binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element. A binary AST representation of the source code element is generated based on the plurality of tokens and the non-binary AST representation, wherein the binary AST representation includes a plurality of binary AST nodes, the plurality of binary AST nodes including binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes is based on a corresponding one of the plurality of tokens of the source code element, and wherein each of the binary AST token nodes corresponds to a corresponding one of the non-binary AST token nodes. Each of the binary AST token nodes and binary AST empty nodes is encoded into a corresponding value. A numerical array representation of the source code elements is generated based on the binary AST representation, wherein the values of the corresponding binary AST token node and binary AST empty node are mapped to their respective positions in the numerical array representation based on their corresponding positions in the binary AST representation. as well as The source code is evaluated using a machine learning (ML) model based on the numerical array representation of the source code elements.
24. The source code evaluation node (1600) according to claim 23, wherein the number of non-binary AST token nodes exceeds the number of binary AST token nodes.
25. The source code evaluation node (1600) of claim 23, wherein each of the plurality of tokens based on the source code exceeds the number of the binary AST token nodes.
26. The source code evaluation node (1600) of claim 23, wherein the binary AST representation has a depth n, wherein the binary AST representation has levels i = 0, 1, 2, ... n, wherein each level i of the binary AST representation includes 2 i There are n nodes, where each node in level i = 0, 1, 2, ..., n-1 has 2 child nodes in the next level, wherein the binary AST representation includes... The number of nodes, and wherein the numerical array representation includes the nodes respectively corresponding to the binary AST representation. Each node A number.
27. The source code evaluation node (1600) of claim 26, wherein at least one of the plurality of tokens generated based on the source code elements is omitted from the binary AST.
28. The source code evaluation node (1600) of claim 23, wherein generating the plurality of tokens includes generating the plurality of tokens based on lexical analysis of the source code elements.
29. The source code evaluation node (1600) according to claim 23, wherein the source code elements include letters, characters, numbers, and operators.
30. The source code evaluation node (1600) of claim 23, wherein for each of the binary AST token nodes, the corresponding value comprises a numeric tuple.
31. The source code evaluation node (1600) of claim 23, wherein the ML model is based on a dataset of source code elements.
32. The source code evaluation node (1600) of claim 31, wherein the evaluation includes at least one of the following: using the ML model to predict software vulnerabilities in the source code, detecting vulnerabilities in the source code, identifying errors in the source code, and / or correcting errors in the source code, wherein the ML model is based on a dataset of source code elements and is based on at least one of the following: vulnerabilities corresponding to source code elements of the dataset, and / or errors corresponding to source code elements of the dataset.
33. The source code evaluation node (1600) according to claim 31 or 32, wherein the source code element is a first source code element, wherein the plurality of tokens are a first plurality of tokens, wherein the binary AST representation is a first binary AST representation, and wherein the plurality of binary AST nodes are a first plurality of binary AST nodes, and wherein the memory further includes instructions for causing the source code evaluation node (1600) to perform the following operations when executed by the processing circuitry. Select a second source code element from the plurality of source code elements in the source code; A second plurality of tokens are generated based on the second source code element, wherein each of the second plurality of tokens comprises a sequence of text characters; A second binary abstract syntax tree (AST) representation of the second source code element is generated based on the second plurality of tokens of the second source code element, wherein the second binary AST representation includes a second plurality of binary AST nodes, the second plurality of binary AST nodes include binary AST token nodes and binary AST empty nodes, wherein each of the binary AST token nodes in the second binary AST representation is based on a corresponding one of the second plurality of tokens of the second source code element; Encode each of the token nodes and empty nodes in the second plurality of binary AST nodes into a corresponding value; and A second numerical array representation of the second source code element is generated based on the second binary AST representation, wherein the values of the corresponding token node and empty node in the second plurality of binary AST nodes are mapped to the positions in the second numerical array representation based on the corresponding positions of the corresponding token node and empty node in the second binary AST representation; The evaluation of the source code includes evaluating the source code based on a first numerical array representation of the first source code element and a second numerical array representation of the second source code element.
34. A computer program product comprising a non-transitory storage medium including program code to be executed by processing circuitry (1603) of a source code evaluation node (1600), wherein execution of the program code causes the source code evaluation node (1600) to perform the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Extensible code auto-fix framework based on XML query languages
US20150082276A1
Method of creating the balanced parse tree having optimized height
US20180357052A1