Code scanning method, device, equipment, storage medium and program product

By constructing a simulated array object of the source code in static scanning, it solves the efficiency and accuracy problems of developers when retrieving array sub-objects, and achieves safe and efficient source code inspection.

CN114527991BActive Publication Date: 2024-10-11TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210133517.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-09
Publication Date
2024-10-11
Estimated Expiration
2042-02-09

AI Technical Summary

Technical Problem

In an integrated development environment, it is difficult for developers to effectively retrieve and match array sub-objects in the source code. It is easy to ignore the different hierarchical structures of arrays, resulting in the inability to obtain the object or the value corresponding to the object.

Method used

By obtaining the identification sequence in the source code, the type of each identification is determined, and a simulated array object is constructed based on the dictionary structure conversion rules, avoiding code execution and directly constructing the simulated array object in static scanning.

Benefits of technology

It improves the efficiency and security of source code inspection, ensures accurate conversion of array objects and acquisition of values, and avoids the generation of dirty data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114527991B_ABST
    Figure CN114527991B_ABST
Patent Text Reader

Abstract

The present application provides a code scanning method, device, equipment and computer-readable storage medium; it relates to the field of computer and data processing technology, and the method includes: obtaining an identification sequence corresponding to each line of code in the source code, wherein each identification sequence includes multiple identifications, and each identification sequence corresponds to an array object in the source code; performing the following processing on each identification sequence: determining the identification type of each identification in the identification sequence, and performing dictionary structure conversion on each identification based on the dictionary structure conversion rule corresponding to the identification type; and determining a simulation array object corresponding to the array object one by one based on the conversion result. Through the present application, it is possible to safely and accurately generate a simulation array object corresponding to the array object in the source code, thereby improving the efficiency of developers in checking the source code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to computer technology, and in particular to a code scanning method, device, equipment, storage medium and program product. Background Art

[0002] In an integrated development environment (IDE), developers can obtain the definition lines and usage lines of variable parameters in the source code. However, to retrieve sub-objects of arrays in the source code, developers need to match the array structure by themselves. In code review, when matching array structures, it is easy to ignore the differences in array hierarchical structures, resulting in the failure to obtain objects (for example, keys, array objects) and the corresponding values ​​of objects (for example, the key value corresponding to the key, the value in the array object). Summary of the invention

[0003] The embodiments of the present application provide a code scanning method, device, electronic device, computer-readable storage medium and computer program product, which can safely and accurately generate simulated array objects corresponding to array objects in source code, thereby improving the efficiency of developers in checking source code.

[0004] The technical solution of the embodiment of the present application is implemented as follows:

[0005] The present application provides a code scanning method, including:

[0006] Obtaining identification sequences corresponding to each line of code in the source code, wherein each identification sequence includes a plurality of identifications, and each identification sequence corresponds to an array object in the source code;

[0007] The following processing is performed on each of the identification sequences:

[0008] determining the identifier type of each identifier in the identifier sequence, and

[0009] Based on the dictionary structure conversion rule corresponding to the identifier type, performing dictionary structure conversion on each identifier;

[0010] Based on the conversion result, a simulation array object corresponding one-to-one to the array object is determined.

[0011] An embodiment of the present application provides a code scanning device, including:

[0012] A data acquisition module, used to obtain an identification sequence corresponding to each line of code in the source code, wherein each identification sequence includes a plurality of identifications, and each identification sequence corresponds to an array object in the source code;

[0013] The data conversion module is used to perform the following processing on each of the identification sequences: determine the identification type of each of the identifications in the identification sequence, and perform dictionary structure conversion on each of the identifications based on the dictionary structure conversion rule corresponding to the identification type; and determine a simulation array object that corresponds one-to-one to the array object based on the conversion result.

[0014] An embodiment of the present application provides an electronic device, the electronic device comprising:

[0015] A memory for storing executable instructions;

[0016] The processor is used to implement the code scanning method described in the embodiment of the present application when executing the executable instructions stored in the memory.

[0017] An embodiment of the present application provides a computer-readable storage medium storing executable instructions, which, when executed by a processor, implements the code scanning method described in the embodiment of the present application.

[0018] An embodiment of the present application provides a computer program product, including a computer program or instructions, which, when executed by a processor, implements the code scanning method described in the embodiment of the present application.

[0019] The embodiments of the present application have the following beneficial effects:

[0020] In static scanning, the array objects corresponding to the identification sequence of the source code are converted into simulated array objects with a dictionary storage structure. The simulated array objects based on the dictionary storage structure facilitate obtaining object values ​​in the array objects. In addition, there is no need to execute code to construct simulated array objects in static scanning, which avoids the generation of dirty data, improves the efficiency and security of constructing simulated arrays, and facilitates developers to efficiently check source code based on simulated array objects. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is a schematic diagram of an application scenario of the code scanning method provided in an embodiment of the present application;

[0022] Figure 2 is a schematic diagram of the structure of an electronic device for scanning a code provided in an embodiment of the present application;

[0023] Figure 3A It is a flowchart of a code scanning method provided in an embodiment of the present application;

[0024] Figure 3B It is a flowchart of a code scanning method provided in an embodiment of the present application;

[0025] Figure 3CIt is a flowchart of a code scanning method provided in an embodiment of the present application;

[0026] Figure 3D It is a flowchart of a code scanning method provided in an embodiment of the present application;

[0027] Figure 3E It is a flowchart of a code scanning method provided in an embodiment of the present application;

[0028] Figure 4 is a schematic diagram of the hierarchical relationship of array objects provided in an embodiment of the present application;

[0029] Figure 5 It is a flowchart of a code scanning method provided in an embodiment of the present application;

[0030] Figure 6 It is a flowchart of the code scanning method provided in the embodiment of the present application. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0032] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0033] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.

[0034] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0035] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0036] 1) Line objects are objects separated by statement units in the syntax of the server-side programming language (PHP, Professional Hypertext Preprocessor). Line objects can be an array that occupies multiple lines of definition, for example: the array object ['key1'=>'value1', 'key2'=>'value2'] can be regarded as a line object. Line objects can also be variable declarations, for example: multiple variable declarations in a line (a code block separated by a carriage return in the code), each variable declaration can be a separate line object.

[0037] 2) Token sequence, which is the code segmentation result obtained by using the core module (Pygments) open source tool in the static scanning tool (Ulink, USB interface emulator). The token sequence includes extracted keywords, distinguishing comments, string text and other types of tokens.

[0038] 3) Array object, a data structure in the server-side programming language, can be a one-dimensional array or a multi-dimensional array. It usually appears in the form of a key-value pair consisting of Key and Value, such as: ['key1'=>'value1', 'key2'=>'value2'], which is a two-dimensional array, including two key-value pairs. In the embodiments of the present application, for the convenience of distinction and explanation, Key is called keyword or key, and the Value corresponding to Key is called key value or value, and the keyword and key value constitute a key-value pair.

[0039] 4) Simulated array object: In static scanning tools, the object is simulated based on the array object. The simulated array object provides interfaces such as writing and querying, and the main data is stored in the dictionary storage structure. Dictionary array, also known as simulated array object, is a dictionary storage structure in Python. It is similar to the array object of the server-side programming language and usually appears in unordered key-value pairs (key-value pairs include keywords and key values ​​corresponding to keywords), such as: ArrayObj{'key1':'value1','key2':'value2'}.

[0040] 5) Parameter Get function, which is used to get the value corresponding to a keyword in an array object. Multiple keywords can be passed in to implement deep-level value retrieval of a multi-dimensional array. There can be multiple key values, and a set of all possible key values ​​is returned.

[0041] 6) Parameter setting (Set) function, which is used to set the corresponding value of the key in the array object. It can be used to pass in multiple keys to implement deep-level assignment of multi-dimensional arrays. When assigning a key, there can be multiple values. For example, there is a key-value pair key: [value1] in the simulated array object. A value set [value2, value3, value4] is written to the simulated array object through the parameter setting function, and the written key-value pair key: [value1, value2, value3, value4] is obtained.

[0042] The embodiments of the present application provide a code scanning method, a code scanning device, an electronic device for scanning a code, a computer-readable storage medium, and a computer program product, which can convert an array object in an identification sequence of a line object in a source code into a simulated array object of a dictionary structure, thereby facilitating the acquisition of values ​​of objects at different levels in a corresponding array object based on the simulated element group object.

[0043] The electronic device provided in the embodiments of the present application can be implemented as various types of user terminals such as a laptop computer, a tablet computer, a desktop computer, a set-top box, a mobile device (e.g., a mobile phone, a portable music player, a personal digital assistant, a dedicated messaging device, a portable gaming device), a vehicle-mounted terminal, etc., and can also be implemented as a server. Below, an exemplary application when the device is implemented as a server will be described.

[0044] See also Figure 1 , Figure 1 It is a schematic diagram of an application scenario of the code scanning method provided in an embodiment of the present application, involving a terminal device 401, a network 300, and a server 200. The server 200 communicates with the terminal device 401 via the network 300, and the network 300 can be a wide area network or a local area network, or a combination of the two.

[0045] The user may be a developer who writes source code. Server 200 is a code scanning tool or a server for static scanning corresponding to the platform. The user accesses the code scanning tool (the graphical front end of server 200) through terminal device 401, and sends the source code file to be detected to server 200. Server 200 obtains the identification sequence of the source code file (the identification sequence corresponds to the array object), and matches the identification sequence in the process of constructing the simulated array object. It can determine the error (bug) in the source code and feed back the error to terminal device 401, so that the developer can obtain the error in the source code.

[0046] In some embodiments, based on the constructed simulated array object, the developer can send the variable object to be retrieved to the server 200 through the terminal device 401. The server 200 searches the array object corresponding to the source code based on the variable object, and extracts the value of the variable object from the simulated array object based on the retrieved array object, and feeds back the value of the variable object to the terminal device 401.

[0047] The embodiments of the present application can be implemented through database technology. In short, a database can be regarded as an electronic file cabinet - a place to store electronic files. Users can add, query, update, delete, etc. data in the files. The so-called "database" is a collection of data that is stored together in a certain way, can be shared with multiple users, has as little redundancy as possible, and is independent of the application program.

[0048] A database management system (DBMS) is a computer software system designed for managing databases. It generally has basic functions such as storage, retrieval, security, and backup. Database management systems can be classified according to the database model they support, such as relational, XML (Extensible Markup Language); or according to the type of computer they support, such as server clusters, mobile phones; or according to the query language used, such as Structured Query Language (SQL), XQuery; or according to performance focus, such as maximum scale, maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMS can cross categories, for example, supporting multiple query languages ​​at the same time.

[0049] The embodiments of the present application can also be implemented through machine learning. Machine Learning (ML) is a multi-disciplinary cross-disciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all fields of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning by teaching.

[0050] The embodiments of the present application can also be implemented through cloud technology. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model application. It can form a resource pool, which is used on demand and is flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the high development and application of the Internet industry, as well as the promotion of search services, social networks, mobile commerce and open collaboration, each item may have its own hash code identification in the future, and all need to be transmitted to the background system for logical processing. Data of different levels will be processed separately, and all kinds of industry data require strong system backing support, which can only be achieved through cloud computing.

[0051] See also Figure 2 , Figure 2 4 is a schematic diagram of the structure of an electronic device for scanning codes provided in an embodiment of the present application. Taking the electronic device as a server as an example, it includes: at least one processor 410, a memory 450, and at least one network interface 420. The various components in the electronic device 400 are coupled together through a bus system 440. It can be understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, in Figure 2 Various buses are labeled as bus system 440 .

[0052] Processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0053] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.

[0054] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.

[0055] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.

[0056] The operating system 451 includes system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic businesses and process hardware-based tasks.

[0057] The network communication module 452 is used to reach other computing devices via one or more (wired or wireless) network interfaces 420. Exemplary network interfaces 420 include: Bluetooth, Wireless Authentication (WiFi), and Universal Serial Bus (USB).

[0058] In some embodiments, the video form generation device provided in the embodiments of the present application can be implemented in a software manner. Figure 2 The scanning device 455 of the code stored in the memory 450 is shown, which can be software in the form of a program and a plug-in, etc., including the following software modules: a data acquisition module 4551, a data conversion module 4552, these modules are logical, and therefore can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.

[0059] The code scanning method provided by the embodiment of the present application will be described in combination with the exemplary application and implementation of the terminal provided by the embodiment of the present application. Figure 3A , Figure 3A is a flowchart of a code scanning method provided in an embodiment of the present application, which will be combined with Figure 3A The steps shown are explained.

[0060] In step 301, the identification sequence corresponding to each line of code in the source code is obtained.

[0061] Here, each identification sequence (ie, token sequence) includes multiple identifications, and each identification sequence corresponds to an array object in the source code.

[0062] In some embodiments, the source code may be a source code of a server-side programming language or other languages, and correspondingly, the array object may be an array structure of a PHP language or an array structure (or linked list structure) of other languages. In the embodiments of the present application, the source code is taken as an example of the code of the server-side programming language.

[0063] For example, an array object can be a multidimensional array, which contains multiple elements. The element types include: key-value pairs, key-values, or array objects. An array object can also contain multiple levels of array objects. For details, refer to Figure 4 , Figure 4 : This is a schematic diagram of the hierarchical relationship of array objects provided in an embodiment of the present application. Array object A1 is a multi-level nested array object. Array object A1 contains multiple array objects (array object A11 to array object A1N), and N is a positive integer greater than 1. Array object A1 is the parent of array object A11 to array object A1N. Array object A11 to array object A1N can also be multi-level nested array objects. Array object A11 includes array object A111 to array object A11N, and array object A11N includes array object A11N1 to array object A11NN. There is a corresponding relationship between each array object and the array objects it includes.

[0064] For example, step 302 and step 303 may be performed simultaneously for each identification sequence.

[0065] In step 302, the identification type of each identification in the identification sequence is determined.

[0066] For example, the identifier sequence includes identifiers such as keywords, distinguishing comments, and string text. The identifier belongs to a character, and the identifier is a character that represents a specific meaning. The identifier types include: start identifier, string text, and end identifier.

[0067] The start identifier is a character or string that indicates the start of the array object among the characters corresponding to the array object. For example, the start identifier can be "$demoArray=[", "[", "array(", etc. These characters appear at the starting position in the array object.

[0068] String literals can be strings that represent elements in an array object or characters used to represent the relationship between elements, such as mapping symbols (=>), keywords (also known as Key), key values ​​(also known as Value), and separators (such as commas). For example, a string literal can be "'key1'=>'value1','key2'=>'value2'", where "'key1'=>'value1'" is a string that represents an element in an array object, key1 and key2 are keywords, "=>" is a mapping symbol used to represent the mapping relationship between keywords and key values, value1 and value2 are key values; "," is a separator used to separate different elements in an array.

[0069] The end marker is a character in the characters corresponding to the array object that indicates the end of the array object. For example, the end marker can be ")", "]", etc. These characters appear at the end position in the array object.

[0070] In some embodiments, step 302 can be implemented in the following manner: perform the following processing on each identifier in the identifier sequence: match the reference identifiers corresponding to different identifier types with the identifiers in the identifier sequence to obtain a target identifier in the reference identifier that matches the identifier in the identifier sequence; and use the identifier type corresponding to the target identifier as the identifier type corresponding to the identifier in the identifier sequence.

[0071] For example, if the identifier type is a start identifier, the corresponding reference identifier can be array (or [, $demoArray=[, etc.); if the identifier type is a string text, the corresponding reference identifier can be a keyword (for example: key1, key2, limit, cycle, etc.), a key value (for example: value1, value2, etc.), a mapping symbol, a separator; if the identifier type is an end identifier, the corresponding reference identifier can be a comma, etc. Assume that a string in the identifier sequence is: $array=['key1'=>'value1','key2'=>'value2'], and match each character in turn to get: "$array=[" is the start identifier; key1 and key2 are keywords; => is a mapping symbol; value1 and value2 are key values; "," is a separator; and "]" is the end identifier.

[0072] In step 303, dictionary structure conversion is performed on each identifier based on the dictionary structure conversion rule corresponding to the identifier type.

[0073] In the embodiment of the present application, the dictionary structure conversion rule is a conversion rule for converting an array object in the source code of the PHP language into a simulated array object of a dictionary structure. Different identifier types correspond to different dictionary structure conversion rules, and the dictionary structure conversion rule corresponding to the identifier is determined based on the identifier type corresponding to the identifier, and the identifier is converted based on the corresponding dictionary structure conversion rule.

[0074] In some embodiments, reference Figure 3B , Figure 3B It is a flowchart of the code scanning method provided in an embodiment of the present application; step 303 can be implemented through steps 331 to 333, which are described in detail below.

[0075] In step 331, when the identifier type of the identifier is a start identifier, the identifier is converted into a head identifier in the dictionary structure based on a dictionary structure conversion rule corresponding to the start identifier.

[0076] For example, take an array object as follows: $demoArray = ['commitStepOne' = > ['key1' = > 'value1', 'key2' = > 'value2',], 'commitStepTwo' = > ['key3' = > 'value3', 'key4' = > 'value4',],].

[0077] For example, the dictionary structure conversion rule corresponding to the start identifier includes converting the string corresponding to the start identifier into the string corresponding to the identifier (i.e., the start identifier) ​​used to represent the head of the simulated array object in the dictionary structure. For example, the string corresponding to the head identifier in the dictionary structure can be represented as "ArrayObj{". In the above array object, "$demoArray=[" is the string corresponding to the start identifier in the array object, so it is converted to "ArrayObj{".

[0078] In step 332, when the identification type of the identification is a string text, the identification is converted into a string text in the dictionary structure based on a dictionary structure conversion rule corresponding to the string text.

[0079] For example, the dictionary structure conversion rules corresponding to the string text include: converting the structure of the string corresponding to the string text into the structure corresponding to the string text in the dictionary structure. The string text includes mapping symbols, separators, keys (Key) and values ​​(Value). Different string texts correspond to different dictionary structure conversion rules. When it is determined that the identification type of the identifier is a character text string, the type corresponding to the string text is judged, and the string text is converted based on the dictionary structure conversion rules of the type corresponding to the string text. The following specifically describes the conversion of different types of string texts.

[0080] When the string literal is a mapping symbol, the mapping symbol is converted into a definition symbol (for example, a colon ":") in a dictionary structure, and characters adjacent to the mapping symbol in an identification sequence are converted into a dictionary structure, which can be achieved in the following manner: determining characters before the mapping symbol and characters after the mapping symbol from the identification sequence; converting the characters before the mapping symbol into a definition word in the dictionary structure, converting the mapping symbol into a definition symbol in the dictionary structure, and converting the characters after the mapping symbol into definition values ​​corresponding to the characters before the mapping symbol in the dictionary structure.

[0081] For example, the mapping symbol usually represents the correspondence between keywords and key values ​​in an array object. The key value can be a number, a character representing a numerical value, or an array object. For example: in the array object 'commitStepOne'=>['key1'=>'value1','key2'=>'value2',], 'commitStepOne' is the keyword, and "['key1'=>'value1','key2'=>'value2',]" after the mapping symbol is the array object and the key value corresponding to 'commitStepOne'. key1 is the keyword, and value1 is the key value corresponding to key1. key2 is the keyword, and value2 is the key value corresponding to key2. For example, the definition symbol is used to represent the correspondence between definition words and definition values ​​in the dictionary structure, simulating that the definition words in the array object correspond to the keywords in the array object, and simulating that the definition values ​​in the array object correspond to the key values ​​in the array object.

[0082] For example, the mapping symbol (=>) is converted into a definition symbol (:) in a dictionary structure, and the characters before the mapping symbol are converted into definition words in the dictionary structure, that is, the keywords are used as definition words; the identifier after the mapping symbol is converted into a definition value corresponding to the characters before the mapping symbol in the dictionary structure, that is, the key value is converted into a dictionary structure for storage, for example: 'value1' is stored as ['value1']. Then the key-value pair 'key1'=>'value1' in the array object is converted into a dictionary structure: 'key1':['value1'], where 'key1' is a definition word and ['value1'] is a definition value.

[0083] When the string text is a separator (for example: "," comma), the characters adjacent to the separator in the identification sequence are converted into a dictionary structure, which can be achieved in the following way: determine the characters adjacent to the separator from the identification sequence; when the key value in the characters adjacent to the separator is missing the corresponding keyword, perform self-increment identification (self-increment ID, that is, assign a keyword to the key value of the missing keyword) processing on the key value of the missing corresponding keyword to obtain a key-value pair, and convert the key-value pair into a defined value pair in the dictionary structure; when the character after the separator is not a keyword or a key value, skip the separator, and enter the dictionary structure conversion process based on the character after the separator; when the character after the separator is a keyword or a key value, use the separator as the separator in the dictionary structure.

[0084] Here, the key-value pair includes a key value and a self-increment keyword corresponding to the key value, and the definition-value pair includes a definition word and a definition value corresponding to the definition word.

[0085] For example, the array object can be in the form of a key-value pair or array for each element (for example: ['key1'=>'value1', 'key2'=>'value2']), or a key-value pair for each element (for example: ['value1', 'value2']), that is, the character before the separator is the key value of the missing corresponding keyword. In this case, the key value of the missing corresponding keyword can be assigned a keyword, for example: 'value1' is processed with an auto-increment identifier to obtain a key-value pair 0=>'value1', where 0 is an auto-increment keyword. After the auto-increment identifier is processed, 0=>'value1' can be converted in the way that the mapping symbol is converted into a dictionary structure.

[0086] For example, ['value1', 'value2',] is converted into a dictionary structure: ArrayObj{0:['value1'],1:['value2']}, where the comma between "'value1'" and "'value2'" is used to separate the two key values, so it is retained as a separator in the dictionary structure. The character after the comma "," after "'value2'" is the end mark ], and the end mark ] is not a keyword or key value, so the comma "," is skipped.

[0087] In step 333, when the identifier type of the identifier is an end identifier, the identifier is converted into an end identifier in the dictionary structure based on a dictionary structure conversion rule corresponding to the end identifier.

[0088] For example, the dictionary structure conversion rules corresponding to the end marker include: converting the characters corresponding to the end marker into the characters corresponding to the end marker in the dictionary structure, for example: the characters corresponding to the end marker can be ")", "]", etc., and the characters corresponding to the end marker in the dictionary structure can be "}".

[0089] In some embodiments, step 333 can be implemented in the following manner: when the identifier type of the identifier is an end identifier and there is a start identifier before the end identifier, the end identifier is converted into an end identifier in the dictionary structure; when the identifier type of the identifier is an end identifier and there is no start identifier before the end identifier, the end identifier is abnormally discarded.

[0090] For example, take the array object ['key1'=>'value1','key2'=>'value2'] as an example, where "]" is the end identifier, and the end identifier converted to the dictionary structure is "}". The above array object is converted to a simulated array object: ArrayObj{key1:['value1'],key2:['value2']}. Assume that the content of the identifier sequence is: "['key1'=>'value1','key2'=>'value2',],]", the second-to-last end identifier in the above characters has a corresponding start identifier, which is converted to the end identifier in the dictionary structure}. There is a comma (separator) between the second-to-last end identifier and the last end identifier, so the comma is skipped. The corresponding start identifier is missing before the last end identifier, and the last end identifier is discarded as an exception, so the converted simulated array object is ArrayObj{key1:['value1'],key2:['value2']}.

[0091] For example, in an array object, the end identifier and the start identifier correspond to each other. If no independent end identifier appears (the end identifier of the corresponding start identifier is missing), the end identifier of the array object and the identifier after the end identifier are converted in sequence. If the array object also has a parent array object, the end identifier of the parent array object is converted to the end identifier in the dictionary structure, so that the array object can be stored in the parent array object as a value; if an independent end identifier appears, the end identifier is abnormal, and the end identifier is abnormally discarded. The server that executes the scanning method of the code of the embodiment of the present application can send the array object corresponding to the abnormally discarded end identifier to the terminal device, so that the developer can obtain code exception information.

[0092] For example, the characters obtained by converting each identifier into a dictionary structure form a simulated array object of the dictionary structure, and each identifier corresponds to the character obtained by its conversion one by one, so the array object and the simulated array object also correspond one by one. The simulated array object of the dictionary structure and the correspondence between different array objects and simulated array objects are taken as the conversion result.

[0093] In step 304, based on the conversion result, a simulation array object corresponding one-to-one to the array object is determined.

[0094] Here, the conversion result includes: a simulated array object of a dictionary structure, and a correspondence between different array objects and the simulated array object.

[0095] For example, an array object can be a multidimensional array, that is, the array object contains multiple elements, each of which can be a key-value pair or a key value, an array object, etc. It can be traversed from the head of the identifier sequence in sequence, and each time a start identifier is matched, the start identifier is converted into a start identifier of a dictionary structure, that is, a head identifier in a simulated array object, and the conversion is performed from the outer layer to the inner layer of the array object in sequence, and the end identifier is converted from the inner layer to the outer layer to the end identifier in the dictionary structure, that is, the end identifier in the simulated array object, so that the hierarchical relationship in the simulated array object corresponds to the hierarchical relationship of the array object one by one. Based on the correspondence between different array objects and simulated array objects, the simulated array object of the dictionary structure corresponding to the array object can be determined.

[0096] For example: Based on the array object $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],] in the above example, we can get the simulated array object: ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1]}],'commitStepTwo':[ArrayObj{'cycle':[5],'limit':[2]}]}.

[0097] In an embodiment of the present application, a simulated array object corresponding to an array object is constructed based on an identification sequence of the source code and constructed under static scanning, which improves the accuracy and efficiency of constructing the simulated array object and is conducive to obtaining the hierarchical structure and value in the array object based on a more accurate simulated array object.

[0098] In some embodiments, reference Figure 3C , Figure 3CIt is a flowchart of the code scanning method provided by the embodiment of the present application. After step 304, when the elements in the array object are reassigned, the corresponding elements in the simulation array object can also be updated synchronously through steps 305 to 306, which are described in detail below.

[0099] In step 305, in response to the assignment operation on the array object, a new key value corresponding to the assignment operation and a key value address corresponding to the new key value are obtained.

[0100] For example, a developer can perform an assignment operation on an array object. For example, the developer performs an assignment operation through a graphical front end of a terminal device (for example, inputting a new key value and a key value address corresponding to the new key value). The terminal device sends the data corresponding to the assignment operation to a server. The server obtains the new key value and the corresponding key value address based on the corresponding data and assigns the array object.

[0101] In step 305, a parameter setting function (such as a set function) is called based on the new key value and the key value address, a target address matching the key value address in a simulated array object corresponding one-to-one to the array object is determined, and the new key value is stored in the simulated array object based on the target address.

[0102] For example, the new key value can be a key value set. When the new key value is stored in the target address corresponding to the simulation array object, the new key value is added to the key value corresponding to the target address. For example: for the simulation array object ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1]}]}, the target address is $demoArray['commitStepOne']['limit'], and the new key value is 10, then the simulation array object after reassignment can be: ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1,10]}]}, and the key value 10 is newly stored in the target address. After reassignment, if the key value corresponding to the target address in the simulation array object is obtained, the new key value 10 can be obtained.

[0103] In the embodiment of the present application, the consistency between the simulated array object and the array object is maintained by synchronously assigning a value to the simulated array object after the value in the array object is changed.

[0104] In some embodiments, reference Figure 3D , Figure 3DIt is a flowchart of the code scanning method provided by the embodiment of the present application. After step 304, the object value in the array object can also be obtained based on the simulated array object through steps 307 to 310, which are described in detail below.

[0105] In step 307, in response to the data input operation, a variable object to be retrieved corresponding to the data input operation is obtained.

[0106] For example, the data input by the data input operation may be a variable object, or a list containing multiple variable objects. Obtaining the variable object to be retrieved corresponding to the data input operation, that is, extracting the variable object or the list of variable objects from the data input by the data input operation. The variable object may be a keyword whose key value is unknown.

[0107] For example: the developer has not determined the hierarchical structure in the array object, but the developer has the need to understand the key values ​​corresponding to certain keywords in the code. The developer enters multiple keywords (forming a keyword list) on the graphical front end displayed on the terminal device (the graphical front end corresponding to the server), and the terminal device sends the keyword list as the data corresponding to the data input operation to the server. The server parses the data to obtain these keywords and uses these keywords as variable objects to be retrieved. Based on the string corresponding to the variable object to be retrieved, the array object corresponding to the variable object is retrieved in the identification sequence of the source code, and the simulated array object corresponding to the array object is determined one by one. The parameter acquisition function is used to obtain the object values ​​corresponding to the variable objects to be retrieved from the simulated array object. The object value can be a value (Value) or a value set (a set contains multiple values). The server sends these object values ​​to the terminal device so that the developer can obtain the key values ​​corresponding to the keywords.

[0108] In step 308, based on the character string of the object name of the variable object, an iterative object search is performed in the identification sequence of all array objects to determine the array object matching the variable object and the variable value corresponding to the variable object.

[0109] For example, the array object may be a multi-dimensional array nested in multiple levels, the keyword may be a keyword in a lower-level array object, and the array object actually corresponding to the variable object may be obtained by iteratively searching the array object in each level.

[0110] In some embodiments, reference Figure 3E , Figure 3E It is a flowchart of the code scanning method provided in an embodiment of the present application; step 308 can be implemented through steps 381 to 386, which are described in detail below.

[0111] In step 381, the variable object to be retrieved is used as the current object to be processed.

[0112] In step 382, ​​the current object to be processed is segmented according to the identification type corresponding to the characters in the current object to be processed to obtain the current object name and the current variable value of the current object to be processed.

[0113] Here, the current object name is the keyword or the start identifier, and the current variable value is the value.

[0114] For example, the object to be processed is represented in the form of a string. Assume that a variable object to be retrieved is $cycle, and the variable object to be retrieved is used as the current object to be processed. The string of the object to be processed is split according to the identification type corresponding to the character, and $cycle is split to obtain the object name $cycle (starting identification) and the empty value [] (that is, the value without content). The object name $cycle is used as the current object name, and the empty value [] is used as the current variable value.

[0115] In step 383, when the current variable value is different from the acquired current variable value, the current variable value is combined with the acquired current variable value to obtain the target variable value.

[0116] For example, if the current variable value is the same as the current variable value that has been obtained, the current variable and the current variable value that has been obtained are not combined, and step 384 is executed. If it is different from the current variable value that has been obtained, the target variable value is obtained and step 384 is executed. For example: the current variable value that has been obtained is an empty value [], ['cycle'], and the current variable value obtained after segmentation is an empty value []. It is repeated with the current variable value obtained before and is not combined. Assume that the current variable value obtained after segmentation is [$key], and it is combined with the current variable value that has been obtained to obtain the target variable value ['$key', 'cycle'].

[0117] In step 384, a search is performed in the identification sequences of all array objects based on the character string corresponding to the current object name to obtain a target object that matches the character string corresponding to the current object name.

[0118] For example, the current object name string is matched in the strings corresponding to the identification sequences of all array objects to obtain the target object corresponding to the current object name string. The target object can be a constant object (a constant is a quantity that will not be modified by the program when the computer program is running), a variable object (a variable is a quantity that will be modified by the program when the computer program is running), or an array object. For example: the string cycle is matched according to $cycle, and the target object corresponding to the string cycle is $array['cycle'], and the target object is a variable object.

[0119] For example, after step 384, step 385 or step 386 is executed according to the type of the target object.

[0120] In some embodiments, there may be a situation where the target object is neither a constant, a variable nor an array object. For example, the target object does not exist, the target object is an abnormal object, etc. In this case, the server can feedback abnormal information to the terminal device to inform the developer that there is an abnormal object in the array object.

[0121] In step 385, when the target object is an array object, the array object is used as the array object that matches the variable object, and the target variable value is used as the variable value corresponding to the variable object.

[0122] For example, when the target object is an array object, the corresponding simulated array object can be obtained according to the array object, so as to extract the corresponding value from the simulated array object of the dictionary structure.

[0123] In step 386, when the target object is not an array object, the target object is taken as the current object to be processed, and the step of segmenting the current object to be processed according to the identification type corresponding to the characters in the current object to be processed is executed.

[0124] For example, if the target object is not an array object, the process returns to step 382 and iterates through steps 382 to 384 until the target object is an array object.

[0125] In step 309, based on the relationship between different array objects and simulated array objects, simulated array objects corresponding one to one with the matching array objects are obtained.

[0126] For example, the simulated array object is constructed based on the identification sequence corresponding to the array object. There is a corresponding relationship between the array object and its corresponding simulated array object. After the array object is retrieved, the simulated array object of the array object can be obtained based on the corresponding relationship.

[0127] In step 310, based on the variable value corresponding to the variable object, a target value matching the variable value corresponding to the variable object is obtained from the simulation array object, and the target value is used as the object value of the variable object.

[0128] For example, assume that the retrieved array object is $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],], the variable value of the variable object is ['$key','cycle'], and the simulation array object corresponding to the array object is: ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1]}],'commitStepTwo':[ArrayObj{'cycle':[5],'limit':[2]}]}. $key is a variable, and you can use the wildcard '.*' to replace $key. Then, according to the simulation array object, you can get the object value [3,5] corresponding to $cycle.

[0129] In some embodiments, step 10 can be implemented in the following manner: using the variable value corresponding to the variable object as an index, calling a parameter acquisition function (get function) based on the index to obtain a target value matching the index from the simulation array object.

[0130] For example, the simulated array object is a dictionary structure. The value corresponding to a key in the simulated array object can be obtained through the parameter acquisition function. The parameter acquisition function supports passing in multiple keys to obtain the deep-level values ​​of the multidimensional array. If there are multiple values, the parameter acquisition function can return a set consisting of all corresponding values. For example: [3,5], this is a value set with two elements.

[0131] In some embodiments, based on the value corresponding to the keyword in the array object obtained in the simulated array object, the sizes of the array objects can also be compared to determine the relationship between different array objects (for example: greater than, less than, and equal to).

[0132] In the embodiment of the present application, a simulated array object corresponding to an array object is constructed based on an identification sequence of the source code, and the simulated array object is constructed during a static scan without executing code, thereby avoiding the generation of dirty data, and performing abnormal discard processing on abnormal characters in the array object, so that structural abnormalities in the array object can be obtained, thereby improving the accuracy, security, and stability of constructing a simulated array. Based on the corresponding relationship between the array object and the simulated array object, even if the substructure of the array object is unknown, the value corresponding to the variable in the array object can be obtained through the simulated array object, which is convenient for obtaining the variable value in the array object and for judging the size between the array objects.

[0133] Below, an exemplary application of the embodiment of the present application in an actual application scenario will be described. The code scanning method provided by the embodiment of the present application can be applied in the following actual application scenarios: When developers are testing a piece of software, they usually need to check the source code of the software to determine whether there are errors in the source code. In the integrated development environment (IDE), developers can obtain the definition lines and use lines of the variable parameters in the source code, but cannot retrieve the sub-objects of the array in the source code. The developer needs to match the array structure by himself. In the code review, it is easy to ignore the different hierarchical structures of the array, and the situation where the object cannot be obtained occurs. The code scanning method provided by the embodiment of the present application can perform static scanning based on the source code provided by the developer, construct a simulated array object of the dictionary structure of the array object, and retrieve the sub-objects in the array object based on the simulated array object, thereby improving the efficiency of static scanning and facilitating the determination of errors in the source code.

[0134] For example, an array object is a data structure in PHP, which can be a one-dimensional array or a multi-dimensional array. Each element in an array object can be a key-value pair consisting of a key and a value (for example: ['key1'=>'value1', 'key2'=>'value2']), or a value (for example: ['value1', 'value2']). In the following, for the sake of distinction and explanation, the key is called a keyword and the value is called a key value. A simulated array object is an object simulated based on an array object, which provides interfaces such as writing and querying. The array corresponding to the simulated array object is stored in a dictionary storage structure, for example: {'key1':'value1', 'key2':'value2'}. A dictionary is a list commonly used for searching and sorting. Based on the keyword, the key value corresponding to the keyword can be queried.

[0135] To understand the hierarchical relationship in array objects, refer to Figure 4, Figure 4 : It is a schematic diagram of the hierarchical relationship of array objects provided in an embodiment of the present application. Array object A1 is a multi-level nested array object, and array object A1 contains multiple array objects (array object A11 to array object A1N), and N is a positive integer. Array object A1 is the parent of array object A11 to array object A1N, and array object A11 to array object A1N can also be multi-level nested array objects. Array object A11 includes array object A111 to array object A11N, and array object A11N includes array object A11N1 to array object A11NN. For simulated array objects, there is a parent pointer (Parent) between each child array object and the corresponding parent array object. The parent array object corresponding to each child array object can be retrieved based on the parent pointer. The parent pointer is also the corresponding relationship between the child array object and its parent array object. Each simulated array object also has a pointer (Line) to the row object where the simulated array object is located.

[0136] For example, the developer sends the file corresponding to the source code to the server based on the terminal device. The server can use the pygments open source tool in the Ulink static scanning tool to obtain the code segmentation results of the source code, that is, the identification sequence. If the source code is divided into row objects, each row object corresponds to an identification sequence, and the source code in each identification sequence corresponds to an array object. The array object can be a multi-dimensional array with multiple levels of nesting. Based on the array object, a simulation array object corresponding to the array object can be constructed. The following explains the construction process of the simulation array object.

[0137] refer to Figure 5 , Figure 5 is a flowchart of a code scanning method provided in an embodiment of the present application; for each identification sequence, execute Figure 5 By using the steps in , we can get the simulated array object corresponding to each identification sequence. Figure 5 Each step is executed by the server, and the server can execute multiple identification sequences at the same time. Figure 5 Steps in .

[0138] In step 501A, determine whether it is the starting keyword, if yes, execute step 502A, if no, execute step 503A.

[0139] For example, a simulated array object can be constructed based on the initialization (Int) function. The initialization function is used to construct the corresponding simulated array object based on the identification sequence of the actual array object, and can iteratively generate nested simulated multi-dimensional array objects. The identification sequence includes identifiers such as keywords, distinguishing comments, and string text. Scan each character in the identification sequence of the code starting from the first line, and convert each character into a character in the simulated array object based on the identification type matched by each character, until the last line in the identification sequence of the code. Identification types include starting keywords (also known as starting identifiers), ending identifiers (symbols), and string texts. The starting keyword is, for example: array(or [, etc.

[0140] For ease of explanation, let's take an example of a PHP array object as follows:

[0141] $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],];

[0142] Among them, characters such as [, $demoArray=[, etc. are starting keywords.

[0143] In step 502A, a new dictionary object or sub-object is created.

[0144] For example, when the judgment result of step 501A is yes, that is, if the starting keyword is matched, a new object is created based on the scanned characters. A dictionary object refers to a simulated array object stored in a dictionary structure, and a child object refers to a simulated array object with a parent simulated array object.

[0145] Assuming that the starting keywords such as Array=[, array(, etc. are matched, the newly created object is a dictionary object. If [ is matched, and the starting keywords such as Array=[, array(, etc. are included before [, the newly created object is a child object. The specific way to create a new object is to convert the starting characters (Array=[, [, array(, etc.) in the actual array into ArrayObj{.

[0146] For example, convert $demoArray=[to a dictionary structure to get ArrayObj{.

[0147] In step 503A, determine whether it is a mapping symbol. If yes, execute steps 504A and 505A. If not, execute step 506A.

[0148] For example, the mapping symbol is =>.

[0149] In step 504A, the characters preceding the mapping symbol are stored as keywords.

[0150] In step 505A, the characters following the mapping symbol are stored as key values.

[0151] For example, the character object takes the character or string as an object, and the mapping symbol is used to represent the mapping relationship between the keyword and the key value. Therefore, if the mapping symbol is scanned, the character or string before the mapping symbol is the keyword, and the character or string after the mapping symbol is the key value corresponding to the keyword. The mapping symbol is converted into a symbol in the dictionary storage structure that is used to represent the relationship between the key value and the keyword, such as the colon (:). The meaning of the colon is to define the content after the colon as the content before the colon. In the simulated array object, the character object before the colon can be used as the definition, and the character object after the colon can be used as the value content of the definition, that is, the definition value.

[0152] For example, the explanation is based on the array object in the above example. Assume that the current scan is:

[0153] 'commitStepOne'=>['cycle'=>3,'limit'=>1,].

[0154] Converted to a dictionary structure, we get 'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1]}.

[0155] In step 506A, determine whether it is a separator, if yes, execute step 507A, if no, execute step 511A.

[0156] For example, the separator symbol (,) is usually used in the code to separate different elements in an array object (for example: key-value pairs, key values, etc.).

[0157] In step 507A, it is determined whether there is a keyword before the separator. If yes, step 509 is executed. When the determination in step 507A is no, step 508A is executed.

[0158] As shown above, the type of the array object can be ['value1','value2'] or ['key1'=>'value1','key2'=>'value2'], that is, the separator can be used to separate key-value pairs or key values, and the characters before the separator are judged to determine the type of elements in the array object.

[0159] In step 508A, a self-incrementing identifier is processed and the self-incrementing identifier is used as a keyword.

[0160] For example, for an array without a keyword such as ['value1', 'value2'], it can be maintained by a self-incrementing ID, such as [0=>'value1', 1=>'value2'], where 0 is the self-incrementing keyword of the key value 'value1', and converting it into a simulated array object is: ArrayObj{0:['value1'],1:['value2']}. After step 508A, the identifiers in the identifier sequence of the code continue to be scanned.

[0161] In step 509A, the characters before the separator are stored as the key value.

[0162] In step 510A, the characters following the separator are stored as keywords.

[0163] For example, for an array of key-value pairs such as ['cycle'=>3,'limit'=>1,], it can be determined that the "3" before the separator is the key value of the keyword 'cycle', and it can be determined that the 'limit' after the separator is the keyword of the key value "1".

[0164] In some embodiments, if the character after the separator is the end symbol, the character object before the separator is the last key-value pair or key value in the array, and the separator can be skipped. For example: ['cycle'=>3, 'limit'=>1,] is converted to a dictionary storage structure of ArrayObj{'cycle':[3], 'limit':[1]}, where the separator after the key value "1" is skipped and not stored in the dictionary storage structure.

[0165] In step 511A, determine whether it is the end symbol, if so, execute step 512A, if not, execute step 501A.

[0166] For example, the end symbol is a symbol such as ), ], etc. It is used to indicate the end of the array object in the code. In step 512A, it is determined whether the start keyword is matched before the end symbol. If yes, step 514A is executed, and if not, step 513A is executed.

[0167] In step 513A, the characters are discarded as exceptions.

[0168] For example, an array object usually has a starting keyword as the head and an ending symbol as the tail, for example: array object array = [**]. Where ** refers to the element in the array object, and the ending symbol corresponds to the starting keyword. If the ending symbol is matched but the starting keyword does not exist, for example: **], the currently scanned character is an abnormal character and is discarded.

[0169] In step 514A, determine whether the current array has a parent array, if not, execute step 515A, if yes, execute step 516A.

[0170] For example, determining whether a parent array exists can be achieved in the following manner: determining whether a starting keyword is matched before the starting keyword corresponding to the current array object. If so, obtaining the relationship between the array object corresponding to the starting keyword and the current array object to determine whether a parent array exists.

[0171] In step 515A, the dictionary object is returned.

[0172] For example, if the parent array does not exist, the currently scanned character is converted to the end symbol in the dictionary structure to generate an array object. For example, the end symbol ] is converted to}.

[0173] In step 516A, the current array is stored in the parent array as a key value.

[0174] For example, if a parent array exists, the current array object is the child object, the currently scanned character is converted into the end symbol in the dictionary structure, and the child object is added to the array of the parent object by adding the end character corresponding to the parent object after the child object.

[0175] For example, based on the array object $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],] in the above example, after conversion, we can get the simulated array object: ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1]}],'commitStepTwo':[ArrayObj{'cycle':[5],'limit':[2]}]}.

[0176] In some embodiments, for a multidimensional array, when a new array start keyword is matched, a new simulated array object start keyword ArrayObj is created, and then the simulation starts based on Figure 5 The steps in the above code are used to construct inner simulated array objects inwards until the innermost simulated array object is constructed. Then, the inner simulated array object is stored as a key value in the parent simulated array object, and the process is repeated upwards until the outermost simulated array object is constructed.

[0177] In some embodiments, different from dictionaries in common computer programming languages ​​(Python), the simulated array object (ArrayObj) is a custom dictionary class with functions such as setting parameters (set), getting parameters (get), and converting to dictionaries (dict) in common computer programming languages.

[0178] In some embodiments, for the constructed simulation array object, a parameter output function (Values) can also be used to debug and output the parameter values ​​(ie, key values) corresponding to the keywords in the simulation array object.

[0179] Definitions and definition values ​​in simulated array objects, where definitions correspond to keywords in array objects and definition values ​​correspond to key values ​​in array objects. Elements in simulated array objects (definition values, pairs of definition values ​​and definitions) can be stored in the form of collections.

[0180] For ease of understanding, if the code is regarded as a collection, the collection contains multiple levels, and there is a corresponding relationship between each object in the collection and its parent object. In the case of different logical branches in the code, if different key values ​​are set or the original key values ​​are overwritten, new values ​​will be added to the value collection. For the value collection corresponding to the simulated array object, there is a corresponding relationship between each definition value pair in the collection and the simulated array object corresponding to the definition value. Based on the corresponding relationship, the actual definition of the definition value in the actual array object can be traced (the actual definition can be a variable or a function call).

[0181] In some embodiments, when the actual array object corresponding to the simulated array object is reassigned, the simulated array object can be reassigned synchronously by calling a parameter setting function (set function). The key value in the array object is an element carrying a pointer, that is, the key value carries the keyword corresponding to the key value and the row information (for example: the address corresponding to the row).

[0182] For example, the code for reassigning the actual array object $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],] is as follows: $demoArray['commitStepOne']['limit']=10. It can be seen that the newly assigned value is 10, and the address is 'limit' in the object 'commitStepOne'. The code for reassigning the simulated array object is: ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1,10]}],'commitStepTwo':[ArrayObj{'cycle':[5],'limit':[2]}]}.

[0183] For example, after the definition value corresponding to a certain address in the simulated array object is reassigned, the definition value obtained by calling the address is the newly assigned definition value. For example: the array object is $a=['key1'=>'1','key2'=>'2']; the key2 in the array object is reassigned $a['key2']='3'; the simulated array object is reassigned synchronously, and the simulated array object is ArrayObj{'key1':[1],'key2':[2,3]}. At this time, the value corresponding to key2 is obtained from the simulated array object, and 3 is obtained instead of the original 2.

[0184] For example, the definition value includes a definition line object pointer (that is, when the definition value is output, the definition value includes the definition value itself and the address corresponding to the definition value), and the definition value may not be printed out during the debugging process.

[0185] In some embodiments, based on the constructed simulated array object, the developer can obtain the key value corresponding to the keyword of the sub-object or lower-level object in the actual array object. Figure 6 , Figure 6 is a flowchart of a code scanning method provided in an embodiment of the present application, Figure 6 Each step in the process is performed by the server.

[0186] In step 601A, the object to be retrieved is obtained and the object to be retrieved is used as the current object.

[0187] For example, the object to be retrieved may be the name of a keyword uploaded by a developer, the name of an array object, or the name of an underlying array object. For example, the object to be retrieved is $cycle, and the object value of $cycle is unknown, and is assumed to be an empty value []. Step 602A is executed after step 601A.

[0188] In step 602A, the current object is cut into an object name and a dict value.

[0189] In this example, the dict value is also the object value. Taking the object $cycle as an example, the object name $cycle and the empty value [] are obtained by cutting the object $cycle. After step 602A, step 603A is executed.

[0190] In step 603A, it is determined whether the current object is a variable or a constant. If so, step 604A is executed; if not, step 607A is executed.

[0191] For example, the current object can be a variable, a constant, or an array object. A constant is a quantity that will not be modified by a computer program when the program is running, whereas a variable is a quantity that will be modified by the program when the program is running.

[0192] In step 604A, it is determined whether there is a new dict value, if yes, step 605A is executed, if no, step 606A is executed.

[0193] For example, the new dict value is a dict value different from the dict value that has been obtained. For example, if the dict value that has been obtained is empty value [], ['cycle'], the dict value obtained after segmentation is empty value [], and empty value [] has been obtained, then there is no new dict value.

[0194] In step 605A, the new dict value is added to the current dict value.

[0195] For example, if the object value [$key] is obtained and it is different from the previously obtained object value (empty value [], ['cycle']), the object values ​​are combined to obtain the current object value ['$key', 'cycle'].

[0196] In step 606A, a search is performed in the identification list based on the object name of the current object, and the searched object is used as the current object.

[0197] For example, the array object $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],];$array=$demoArray[$key];$cycle=$array['cycle'] is used for explanation. Among them, $array=$demoArray[$key];$cycle=$array['cycle'] is the application representation variable declaration.

[0198] Among them, the simulation array object corresponding to the array object $demoArray=['commitStepOne'=>['cycle'=>3,'limit'=>1,],'commitStepTwo'=>['cycle'=>5,'limit'=>2,],] is: ArrayObj{'commitStepOne':[ArrayObj{'cycle':[3],'limit':[1]}],'commitStepTwo':[ArrayObj{'cycle':[5],'limit':[2]}]}.

[0199] For example, the split based on $cycle results in an empty value [], and there is no new dict value. $cycle is a variable, and the string based on the object name $cycle is searched in the identification sequence to obtain the object $array['cycle'] that matches $cycle. The object $array['cycle'] is taken as the current object, and the current object $array['cycle'] is split to obtain the object name $array and the object value ['cycle']. The object value ['cycle'] is different from the empty value, and step 605A is executed to obtain the current object value ['cycle']. The current object is a variable based on the object name $array, and the string based on the object name $array is searched again in the identification sequence to obtain the object $demoArray[$key]. The object $demoArray[$key] is cut to obtain the object name $demoArray and the object value [$key]. The object value [$key] is different from the object value obtained previously, and the object values ​​are combined to obtain the current object value ['$key', 'cycle']. The string based on the object name $demoArray can match the simulated array object ArrayObj.

[0200] In step 607A, it is determined whether the current object is an array object, and if so, step 608A is executed. If not, step 609A is executed.

[0201] In step 609A, the current object is treated as an abnormal object.

[0202] For example, assuming that the current object is not an array object, it can be determined that there may be an abnormality in the substructure of the array object, and the current object is regarded as an abnormal object, that is, there is no object value corresponding to the object to be retrieved, or the array object does not contain the object to be retrieved. In this case, the server can send corresponding information to the terminal device to prompt the developer.

[0203] In step 608A, the value in the array object that matches the current dict value is obtained as the object value corresponding to the object to be retrieved.

[0204] For example, we continue to explain based on the above example. For the simulated array object ArrayObj, we can get the object value from the simulated array object through the parameter acquisition function (get function). The current object value is ['$key', 'cycle']. Based on ['$key', 'cycle'], we search in the simulated array object ArrayObj and get the object value [3,5] corresponding to $cycle.

[0205] For example, $key is a variable, and you can use the wildcard '.*' to replace $key (for example, 'p'.$i is replaced with '^p.*', 'pre'.$key.'test' is replaced with '^pre.*test$', and regular matching is used in the get method of ArrayObj to determine whether the key value is matched. Regular matching is used to match character combinations in strings).

[0206] In some embodiments, the Foreach iterator can implement iteration when the type of the traversed element in the array is known. The For iterator can implement iteration when the size of the array is known and the array is ordered. If there is an object of the Foreach iterator, all the keywords and corresponding key values ​​in the simulated array object ArrayObj are returned.

[0207] The embodiment of the present application solves the problem that there is no effective verification of array sub-objects in static code scanning, and supports multi-dimensional arrays, and reconstructs and obtains the data of array objects through functions such as get and set. Based on static retrieval, there is no need to execute code, which is more efficient and secure, and avoids the generation of dirty data. At the same time, when the array object is not a certain value (variable or function call), the simulated array object can also be constructed and regular matched normally.

[0208] The following continues to describe the exemplary structure of the code scanning device 455 provided in the embodiment of the present application implemented as a software module. In some embodiments, such as Figure 2 As shown, the software modules in the code scanning device 455 stored in the memory 440 may include: a data acquisition module 4551, used to obtain the identification sequence corresponding to each line of code in the source code, wherein each identification sequence includes multiple identifications, and each identification sequence corresponds to an array object in the source code; a data conversion module 4552, used to perform the following processing on each identification sequence: determine the identification type of each identification in the identification sequence, and perform dictionary structure conversion on each identification based on the dictionary structure conversion rule corresponding to the identification type; based on the conversion result, determine the simulation array object corresponding to the array object one by one.

[0209] In some embodiments, the data conversion module 4552 is also used to perform the following processing on each identifier in the identifier sequence: match the reference identifiers corresponding to the different identifier types with the identifiers in the identifier sequence to obtain a target identifier in the reference identifier that matches the identifier in the identifier sequence; and use the identifier type corresponding to the target identifier as the identifier type corresponding to the identifier in the identifier sequence.

[0210] In some embodiments, the identifier types include: a start identifier, a string text, and an end identifier; the data conversion module 4552 is further used to perform the following conversion on each of the identifiers:

[0211] When the identifier type of the identifier is a start identifier, the identifier is converted into a head identifier in the dictionary structure based on the dictionary structure conversion rule corresponding to the start identifier; when the identifier type of the identifier is a string text, the identifier is converted into a string text in the dictionary structure based on the dictionary structure conversion rule corresponding to the string text; when the identifier type of the identifier is an end identifier, the identifier is converted into an end identifier in the dictionary structure based on the dictionary structure conversion rule corresponding to the end identifier.

[0212] In some embodiments, the string text includes mapping symbols, separators, keywords and key values; the data conversion module 4552 is also used to convert the mapping symbol into a definition symbol in a dictionary structure when the string text is a mapping symbol, and convert the characters adjacent to the mapping symbol in the identification sequence into a dictionary structure; when the string text is a separator, the characters adjacent to the separator in the identification sequence are converted into a dictionary structure.

[0213] In some embodiments, the data conversion module 4552 is also used to determine the characters before the mapping symbol and the characters after the mapping symbol from the identifier sequence when the string text is a mapping symbol; convert the characters before the mapping symbol into a defined word in the dictionary structure, convert the mapping symbol into a defined symbol in the dictionary structure, and convert the identifier after the mapping symbol into a defined value in the dictionary structure corresponding to the characters before the mapping symbol.

[0214] In some embodiments, the data conversion module 4552 is also used to determine the characters adjacent to the separator from the identification sequence when the string text is a separator; when the key value in the character adjacent to the separator lacks the corresponding keyword, the key value of the missing corresponding keyword is processed by self-increment identification to obtain a key-value pair, and the key-value pair is converted into a definition value pair in the dictionary structure, wherein the key-value pair includes a key value and a self-increment keyword corresponding to the key value, and the definition value pair includes a definition word and a definition value corresponding to the definition word; when the character after the separator is not a keyword or a key value, the separator is skipped, and the dictionary structure conversion is performed based on the character after the separator; when the character after the separator is a keyword or a key value, the separator is used as the separator in the dictionary structure. The characters obtained by performing dictionary structure conversion on each identifier constitute a simulated array object of the dictionary structure, and the simulated array object of the dictionary structure and the correspondence between different array objects and simulated array objects are used as conversion results.

[0215] In some embodiments, the data conversion module 4552 is also used to convert the end identifier into an end identifier in the dictionary structure when the identifier type of the identifier is an end identifier and there is a start identifier before the end identifier; when the identifier type of the identifier is an end identifier and there is no start identifier before the end identifier, the end identifier is abnormally discarded.

[0216] In some embodiments, the data conversion module 4552 is also used to respond to an assignment operation on an array object, obtain a new key value corresponding to the assignment operation and a key value address corresponding to the new key value; call a parameter setting function based on the new key value and the key value address, determine a target address that matches the key value address in a simulated array object that corresponds one-to-one to the array object, and store the new key value in the simulated array object based on the target address.

[0217] In some embodiments, the conversion result includes: a simulated array object of a dictionary structure, and a corresponding relationship between different array objects and the simulated array objects; the data conversion module 4552 is also used to respond to a data input operation, obtain a variable object to be retrieved corresponding to the data input operation; based on the character string of the object name of the variable object, iteratively search for objects in the identification sequence of all array objects to determine the array object that matches the variable object and the variable value corresponding to the variable object; based on the relationship between different array objects and the simulated array objects, obtain a simulated array object that corresponds one-to-one to the matching array object; based on the variable value corresponding to the variable object, obtain a target value that matches the variable value corresponding to the variable object from the simulated array object, and use the target value as the object value of the variable object.

[0218] In some embodiments, the data conversion module 4552 is also used to take the variable object to be retrieved as the current object to be processed; split the current object to be processed according to the identification type corresponding to the characters in the current object to be processed to obtain the current object name and the current variable value of the current object to be processed, wherein the current object name is a keyword or a starting identification, and the current variable value is the key value; when the current variable value is different from the current variable value that has been obtained, combine the current variable value with the current variable value that has been obtained to obtain the target variable value; search in the identification sequence of all array objects based on the character string corresponding to the current object name to obtain the target object that matches the character string corresponding to the current object name; when the target object is an array object, take the array object as the array object that matches the variable object, and take the target variable value as the variable value corresponding to the variable object; when the target object is not an array object, take the target object as the current object to be processed, and execute the step of splitting the current object to be processed according to the identification type corresponding to the characters in the current object to be processed.

[0219] In some embodiments, the data conversion module 4552 is further used to use the variable value corresponding to the variable object as an index, and call a parameter acquisition function based on the index to obtain a target value matching the index from the simulation array object.

[0220] The embodiment of the present application provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the code scanning method described in the embodiment of the present application.

[0221] The embodiment of the present application provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the code scanning method provided by the embodiment of the present application, for example, Figure 3A The scanning method of the code is shown.

[0222] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.

[0223] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0224] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0225] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0226] In summary, through the embodiment of the present application, the identification sequence corresponding to each line of code in the source code is obtained, wherein each identification sequence includes multiple identifications, and each identification sequence corresponds to an array object in the source code; each identification sequence is processed as follows: the identification type of each identification in the identification sequence is determined, and the dictionary structure conversion rule corresponding to the identification type is used to convert each identification into a dictionary structure; based on the conversion result, the simulation array object corresponding to the array object is determined. The simulation array object corresponding to the array object in the source code can be generated safely and accurately, which is conducive to more accurately obtaining the value in the array object based on the simulation array object, thereby improving the efficiency of developers in checking the source code.

[0227] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims

1. A code scanning method, It is characterized in that The method comprises: Obtaining identification sequences corresponding to each line of code in the source code, wherein each identification sequence includes a plurality of identifications, and each identification sequence corresponds to an array object in the source code; The following processing is performed on each of the identification sequences: Determine the identifier type of each identifier in the identifier sequence, the identifier type including: a start identifier, a string text, and an end identifier, and The following conversion is performed on each of the identifiers: when the identifier type of the identifier is the start identifier, based on the dictionary structure conversion rule corresponding to the start identifier, the identifier is converted into a head identifier in the dictionary structure; when the identifier type of the identifier is the string text, based on the dictionary structure conversion rule corresponding to the string text, the identifier is converted into a string text in the dictionary structure; when the identifier type of the identifier is the end identifier, based on the dictionary structure conversion rule corresponding to the end identifier, the identifier is converted into an end identifier in the dictionary structure; wherein the characters obtained by performing the dictionary structure conversion on each of the identifiers constitute a simulated array object of the dictionary structure, and the simulated array object of the dictionary structure and the correspondence between different array objects and the simulated array objects are taken as conversion results; Based on the conversion result, a simulation array object corresponding one-to-one to the array object is determined.

2. The method according to claim 1, It is characterized in that The determining the identification type of each identification in the identification sequence includes: The following processing is performed on each of the identifiers in the identifier sequence: Matching the reference identifiers corresponding to the different identifier types with the identifiers in the identifier sequence to obtain target identifiers in the reference identifiers that match the identifiers in the identifier sequence; The identification type corresponding to the target identification is used as the identification type corresponding to the identification in the identification sequence.

3. The method according to claim 1, It is characterized in that The string text includes mapping symbols, separators, keywords and key values; When the identifier type of the identifier is the string text, based on the dictionary structure conversion rule corresponding to the string text, the identifier is converted into the string text in the dictionary structure, including: When the string text is the mapping symbol, converting the mapping symbol into a definition symbol in the dictionary structure, and converting characters adjacent to the mapping symbol in the identification sequence into a dictionary structure; When the string text is the separator, characters adjacent to the separator in the identification sequence are converted into a dictionary structure.

4. The method according to claim 3, It is characterized in that When the string text is a mapping symbol, converting the mapping symbol into a definition symbol in the dictionary structure, and converting characters adjacent to the mapping symbol in the identification sequence into a dictionary structure, including: When the string text is a mapping symbol, determining the character before the mapping symbol and the character after the mapping symbol from the identification sequence; The characters before the mapping symbol are converted into definition words in the dictionary structure, the mapping symbol is converted into definition symbols in the dictionary structure, and the characters after the mapping symbol are converted into definition values ​​in the dictionary structure corresponding to the characters before the mapping symbol.

5. The method according to claim 3, It is characterized in that When the string text is the separator, converting characters adjacent to the separator in the identification sequence into a dictionary structure includes: When the string text is the separator, determining characters adjacent to the separator from the identification sequence; When the key value in the characters adjacent to the separator symbol is missing the corresponding keyword, the key value missing the corresponding keyword is processed by self-increment identification to obtain a key-value pair, and the key-value pair is converted into a definition-value pair in the dictionary structure, wherein the key-value pair includes a key value and a self-increment keyword corresponding to the key value, and the definition-value pair includes a definition word and a definition value corresponding to the definition word; When the character after the separator is not a keyword or a key value, the separator is skipped, and the dictionary structure conversion process is performed based on the character after the separator; When the character after the separator is a keyword or a key value, the separator is used as a separator in the dictionary structure.

6. The method according to claim 1, It is characterized in that When the identifier type of the identifier is the end identifier, converting the identifier into an end identifier in the dictionary structure based on a dictionary structure conversion rule corresponding to the end identifier includes: When the identifier type of the identifier is the end identifier and a start identifier exists before the end identifier, converting the end identifier into an end identifier in the dictionary structure; When the identifier type of the identifier is the end identifier and there is no start identifier before the end identifier, abnormal discard processing is performed on the end identifier.

7. The method according to claim 1, It is characterized in that After determining the simulated array objects corresponding one-to-one to the array objects based on the conversion results, the method further includes: In response to an assignment operation on the array object, obtaining a new key value corresponding to the assignment operation and a key value address corresponding to the new key value; A parameter setting function is called based on the new key value and the key value address, a target address matching the key value address in the simulation array object corresponding to the array object is determined, and the new key value is stored in the simulation array object based on the target address.

8. The method according to claim 1, It is characterized in that The conversion result includes: a simulated array object of a dictionary structure, and a correspondence between different array objects and the simulated array object; After determining the simulated array objects corresponding one-to-one to the array objects based on the conversion results, the method further includes: In response to a data input operation, obtaining a variable object to be retrieved corresponding to the data input operation; Based on the character string of the object name of the variable object, iteratively search for objects in the identification sequence of all array objects to determine the array object matching the variable object and the variable value corresponding to the variable object; Based on the correspondence between the different array objects and the simulated array objects, acquiring simulated array objects that correspond one to one with the matching array objects; Based on the variable value corresponding to the variable object, a target value matching the variable value corresponding to the variable object is obtained from the simulation array object, and the target value is used as the object value of the variable object.

9. The method according to claim 8, It is characterized in that The string based on the object name of the variable object, iteratively searching for objects in the identification sequence of all array objects, comprises: Taking the variable object to be retrieved as the current object to be processed; According to the identification type corresponding to the characters in the current object to be processed, the current object to be processed is segmented to obtain the current object name and the current variable value of the current object to be processed, wherein the current object name is a keyword or a starting identification, and the current variable value is a key value; When the current variable value is different from the acquired current variable value, combining the current variable value with the acquired current variable value to obtain a target variable value; Based on the character string corresponding to the current object name, a search is performed in the identification sequence of all array objects to obtain a target object that matches the character string corresponding to the current object name; When the target object is an array object, the array object is used as an array object matching the variable object, and the target variable value is used as the variable value corresponding to the variable object; When the target object is not an array object, the target object is taken as the current object to be processed, and the step of segmenting the current object to be processed according to the identification types corresponding to the characters in the current object to be processed is performed.

10. The method according to claim 8, It is characterized in that The step of acquiring, from the simulation array object, a target value matching the variable value corresponding to the variable object based on the variable value corresponding to the variable object comprises: The variable value corresponding to the variable object is used as an index, and a parameter acquisition function is called based on the index to obtain a target value matching the index from the simulation array object.

11. A code scanning device, It is characterized in that The code scanning device comprises: A data acquisition module, used to obtain an identification sequence corresponding to each line of code in the source code, wherein each identification sequence includes a plurality of identifications, and each identification sequence corresponds to an array object in the source code; A data conversion module is used to perform the following processing on each of the identifier sequences: determine the identifier type of each identifier in the identifier sequence, the identifier types include: a start identifier, a string text and an end identifier, and perform the following conversion on each identifier: when the identifier type of the identifier is the start identifier, based on the dictionary structure conversion rule corresponding to the start identifier, convert the identifier into a head identifier in a dictionary structure; when the identifier type of the identifier is the string text, based on the dictionary structure conversion rule corresponding to the string text, convert the identifier into a string text in a dictionary structure; when the identifier type of the identifier is the end identifier, based on the dictionary structure conversion rule corresponding to the end identifier, convert the identifier into an end identifier in a dictionary structure; wherein the characters obtained by performing the dictionary structure conversion on each of the identifiers constitute a simulated array object of a dictionary structure, and the simulated array object of the dictionary structure and the correspondence between different array objects and the simulated array object are taken as conversion results; based on the conversion results, determine the simulated array object corresponding to the array object one by one.

12. An electronic device, It is characterized in that The electronic device comprises: A memory for storing executable instructions; A processor, configured to implement the code scanning method according to any one of claims 1 to 10 when executing the executable instructions stored in the memory.

13. A computer-readable storage medium storing executable instructions, It is characterized in that When the executable instructions are executed by a processor, the code scanning method according to any one of claims 1 to 10 is implemented.

14. A computer program product comprising a computer program or instructions, It is characterized in that When the computer program or instruction is executed by a processor, the code scanning method according to any one of claims 1 to 10 is implemented.