Code conversion method, device, equipment, medium and program product of collection type

By introducing an automatic conversion mechanism of abstract syntax trees into PL/SQL and automatically inserting condition judgment logic using target operators, the problem of redundant condition judgments in collection type code is solved, improving development efficiency and code quality.

CN122387451APending Publication Date: 2026-07-14CETC JINCANG (BEIJING) TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CETC JINCANG (BEIJING) TECH CO LTD
Filing Date
2026-04-02
Publication Date
2026-07-14

Smart Images

  • Figure CN122387451A_ABST
    Figure CN122387451A_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a collection type code conversion method, device, equipment, medium and program product. The method comprises: obtaining source code carrying a target operator, the target operator being an extended operator added in a code segment calling a collection type; parsing the source code into an abstract syntax tree, wherein the abstract syntax tree comprises a node corresponding to the target operator; replacing the node corresponding to the target operator in the abstract syntax tree with a conditional statement sub-tree to obtain a target abstract syntax tree; the conditional statement sub-tree being a sub-tree structure obtained by parsing a code block for implementing a conditional judgment logic of the collection type; and compiling the target abstract syntax tree into executable code. The method automatically converts the node corresponding to the extended operator in the abstract syntax tree during compilation, automatically inserts the conditional judgment logic in the executable code, and does not need to increase a corresponding code segment in the source code, thereby improving the development efficiency and readability of the source code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database development technology, and in particular to a method, apparatus, device, medium, and program product for converting collection types into code. Background Technology

[0002] PL / SQL (Procedural Language / Structured Query Language), as the core programming language of Oracle and its compatible databases, is widely used in implementing complex business logic. Collection types are a core tool in PL / SQL for organizing and manipulating multi-valued data, including nested tables, mutable arrays, and associative arrays. Collection types allow developers to store a set of related data in a structured manner and to quickly access or modify collection variables within a collection type using indexes or keys.

[0003] However, there are current security vulnerabilities in the use of collection types. For example, accessing an uninitialized collection variable will cause a system error. To avoid such vulnerabilities, developers often need to manually write numerous conditional statements during the coding phase to ensure that collection variables in the collection type are accessible or operable before being accessed or manipulated. Writing these conditional statements not only consumes a significant amount of development time and is inefficient, but is also easily overlooked, leading to runtime exceptions and affecting system stability. Furthermore, the presence of numerous conditional statements in the code results in redundancy, weakens the code's expressiveness, and reduces its readability and maintainability. Summary of the Invention

[0004] The code conversion method, apparatus, device, medium, and program product for collection types provided in this application can automatically insert condition judgment logic into executable code by using an abstract syntax tree for automatic conversion of target operators during source code compilation. This eliminates the need for developers to manually write redundant and repetitive condition judgment code, greatly improving development efficiency. At the same time, the separation of core business logic and condition judgment logic significantly improves the readability of the source code.

[0005] In a first aspect, embodiments of this application provide a code conversion method for a collection type, comprising: obtaining source code carrying a target operator, wherein the target operator is an extended operator added in a code segment that calls the collection type; parsing the source code into an abstract syntax tree, wherein the abstract syntax tree includes nodes corresponding to the target operator; replacing the nodes corresponding to the target operator in the abstract syntax tree with conditional statement subtrees to obtain a target abstract syntax tree; wherein the conditional statement subtree is a subtree structure obtained by parsing code blocks used to implement conditional judgment logic for the collection type; and compiling the target abstract syntax tree into executable code.

[0006] In one possible implementation, the node corresponding to the target operator in the abstract syntax tree is replaced with a conditional statement subtree to obtain the target abstract syntax tree. This includes: traversing the abstract syntax tree and identifying the node corresponding to the target operator; determining the corresponding conditional statement subtree based on the context information of the node and the target operator; and replacing the node corresponding to the target operator with the conditional statement subtree to obtain the target abstract syntax tree.

[0007] In one possible implementation, determining the corresponding conditional statement subtree based on the node's context information and the target operator includes: determining the conditional statement subtree template corresponding to the target operator under the call type based on the call type and the target operator in the node's context information; and filling the conditional statement subtree template based on the call target in the context information to obtain the conditional statement subtree.

[0008] In one possible implementation, the target operator includes a safe navigation operator; the safe navigation operator is an extended operator added to the code segment used to access or manipulate the collection type; and a conditional statement subtree used to return a default value or execute silently when the collection variable in the collection type has an invalid value, and to access or manipulate the collection type when the collection variable in the collection type has a valid value.

[0009] In one possible implementation, the target operator includes a safe subscript operator; the safe subscript operator is an extended operator added to the code segment used to access or manipulate the target set variable in the set type; and a conditional statement subtree used to return a default value or execute silently when the set variable in the set type is invalid or the subscript element of the target set variable is not in a valid range, and to perform relevant access or operations on the target set element in the set type when the set variable in the set type is valid and the subscript element of the target set variable is in a valid range.

[0010] In one possible implementation, parsing the source code into an abstract syntax tree includes: performing syntactic and semantic analysis on the source code, creating the syntactic structure in the source code as a first node; when a target operator is identified, creating a second node corresponding to the target operator; and based on syntactic rules, structurally combining the first node and the second node to generate an abstract syntax tree.

[0011] Secondly, embodiments of this application provide a code conversion apparatus for a collection type, comprising: an acquisition module for acquiring source code carrying a target operator, wherein the target operator is an extended operator added in a code segment calling the collection type; a parsing module for parsing the source code into an abstract syntax tree, wherein the abstract syntax tree includes nodes corresponding to the target operator; a replacement module for replacing the nodes corresponding to the target operator in the abstract syntax tree with conditional statement subtrees to obtain a target abstract syntax tree; wherein the conditional statement subtree is a subtree structure obtained by parsing code blocks used to implement conditional judgment logic for the collection type; and a post-processing module for compiling the target abstract syntax tree into executable code.

[0012] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor;

[0013] The memory stores the instructions that the computer executes;

[0014] The processor executes computer execution instructions stored in memory, causing the processor to perform the method provided in the first aspect above.

[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method provided in the first aspect above.

[0016] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the method provided in the first aspect above.

[0017] The code conversion method, apparatus, device, medium, and program product for set types provided in this application add extended target operators to the code segments that call set types in the source code. These concise target operators express the intent for secure access, eliminating the need to manually write redundant conditional logic code segments. This improves the efficiency of source code writing, reduces redundancy, and enhances readability and maintainability. During source code compilation and parsing into an abstract syntax tree, the target operator is set as a node in the abstract syntax tree, and this node is replaced with a syntax subtree containing conditional logic. The resulting executable code then includes complete conditional logic, ensuring runtime security. Attached Figure Description

[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0019] Figure 1 A flowchart illustrating a code conversion method for a collection type provided in an embodiment of this application;

[0020] Figure 2 A flowchart illustrating another code conversion method for a collection type provided in this application embodiment;

[0021] Figure 3 A flowchart illustrating another code conversion method for a collection type provided in this application embodiment;

[0022] Figure 4 A schematic diagram of the structure of a code conversion device for a collection type provided in an embodiment of this application;

[0023] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0024] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0026] This application is primarily applied to PL / SQL development scenarios in database management systems, especially those involving complex business logic related to collection types. Collection types are data types in PL / SQL used to store collection variables, including associative arrays, mutable arrays, and nested tables. Collection types allow developers to store a set of related data in a structured manner, forming collection variables, and to quickly access or modify these variables using indexes or keys. During database operation, it is often necessary to frequently manipulate collection variables within collection types. For example, collection types can be used to perform batch operations on multiple records (such as order lists or user information collections), thereby reducing the interaction overhead between the database and the application. Furthermore, collection types can be dynamically expanded or contracted based on database operation conditions to adapt to flexible business needs.

[0027] In development scenarios, developers need to rely on the built-in collection methods provided by the database and procedural programming paradigms to design business operation logic, i.e., code blocks, for collection types to implement operations such as querying, modifying, and comparing collection types. However, built-in collection methods only provide basic operational capabilities and have significant limitations in terms of security. For example, operating on uninitialized collection variables in a collection type may cause runtime exceptions.

[0028] To address these issues, current solutions rely on developers writing lengthy, explicit defensive conditional statements to ensure that collection variables are accessible or operable before any operation is performed on the collection type. For example, before operating on a collection variable within a collection type, the program checks if the variable has been initialized; if initialized, the operation is performed; otherwise, the operation is aborted.

[0029] However, the above solutions require developers to write a large number of repetitive conditional statements, consuming significant development time, resulting in low development efficiency and a high risk of omissions. Such omissions could lead to runtime exceptions and affect system stability. Furthermore, core business logic is buried within repetitive conditional statements, resulting in highly redundant code. The core business logic cannot be intuitively represented in the source code, weakening its expressive power and reducing readability and maintainability.

[0030] The code transformation method for collection types provided in this application extends the target operator used to express the intent of secure access in the source code. During the compilation of the source code, the abstract syntax tree is dynamically transformed according to the target operator. This transforms the secure access logic of collection types from manually coded explicit condition judgments to implicit security check code automatically inserted at compile time. This improves the efficiency of developers in writing code, while reducing code redundancy and enhancing code readability and maintainability.

[0031] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0032] Figure 1 This is a flowchart illustrating a code conversion method for a collection type provided in an embodiment of this application. The method provided in this application can be applied to an encoder. Figure 1 As shown, the method includes:

[0033] Step S101: Obtain the source code carrying the target operator.

[0034] Source code is program code written by developers in a programming language; it is code that humans can understand. Source code is a raw text file and cannot be directly executed by a computer. Executable code is binary code compiled from source code, which can be directly run by a computer; it contains instructions that a computer can recognize.

[0035] The target operator is an extended operator added to the code segment that calls the collection type. The target operator is a unique, human-defined identifier that can be recognized by the compiler to indicate a safe access intent, that is, to instruct the program to perform conditional judgment logic before calling the collection type.

[0036] In this application, the code transformation method for the collection type further includes: defining a target operator for executing a secure access intent, so as to execute conditional judgment logic when the target operator is identified.

[0037] After defining the target operator, you can add the extended operator in the code segment that calls the collection type when writing the source code.

[0038] For example, define the operator @. as the target operator. When writing code to get the total number of collection variables in a collection type, add the target operator to the corresponding code block (var = collection_var count). The code block after adding the target operator will be var = collection_var@.count. Here, @. indicates that conditional judgment logic needs to be performed before this statement is executed.

[0039] In this step, after the source code containing the target identifier is written, it is uploaded to the compiler. The compiler then retrieves the uploaded source code containing the target operator.

[0040] This application avoids the problem of developers manually writing redundant condition judgment code by abstracting the condition judgment logic from the syntax level into an extended target operator, which improves development efficiency and does not affect the readability of the core business logic.

[0041] Step S102: Parse the source code into an abstract syntax tree.

[0042] The abstract syntax tree includes nodes corresponding to the target operators.

[0043] An Abstract Syntax Tree (AST) is a tree-like structure generated by a compiler after parsing source code. Each node represents a syntactic structure in the code, such as operators, expressions, and statements. Operators include target operators and general-purpose operators in the programming language.

[0044] In this step, the compiler parses the source code based on syntax analysis and semantic analysis, and builds a tree-like data structure in memory. Each node of the tree represents a syntax structure in the source code, which includes the target operator.

[0045] Specifically, the compiler first identifies the syntactic structures in the source code, including target operators, general operators, expressions, and statements. Each syntactic structure is then set as a node in the abstract syntax tree (AST), and the nodes are connected according to the logic in the source code to generate an AST that includes the target operators.

[0046] Step S103: Replace the nodes corresponding to the target operators in the abstract syntax tree with conditional statement subtrees to obtain the target abstract syntax tree.

[0047] The conditional statement subtree is the subtree structure obtained by parsing the code block used to implement the conditional judgment logic for collection types. The conditional statement subtree corresponds to the target operator. The code block used to implement the conditional judgment logic for collection types is an inline security check code block.

[0048] The conditional judgment logic is a pre-set judgment logic that requires security verification of the collection type before calling or operating on the collection type.

[0049] Specifically, the encoder parses the code block used to implement the conditional judgment logic for the collection type, obtaining the corresponding abstract syntax tree, i.e., the subtree structure. The code block containing the conditional judgment logic can be a pre-created code segment used to implement secure access to the collection type.

[0050] The conditional judgment logic includes checking whether the collection variable in the collection type has been declared and initialized, i.e., whether the collection variable is in a valid state (i.e., not NULL). If it is in a valid state, a call or operation on the collection type is executed; otherwise, NULL is returned. Alternatively, it checks whether the collection variable in the collection type being operated on has an index element. The index element is used to locate elements in the collection variable. If the index element exists, a call or operation on the collection type is executed; otherwise, NULL is returned. The abstract syntax tree can execute this conditional judgment logic.

[0051] In this step, the compiler checks if a node corresponding to the target operator exists in the abstract syntax tree. If it does, the node is replaced with the conditional statement subtree corresponding to the target operator. After replacing all nodes corresponding to the target operators in the abstract syntax tree, the target abstract syntax tree is obtained. The target abstract syntax tree can execute conditional judgment logic that does not exist in the explicit source code.

[0052] It should be noted that this step is completed in memory and does not modify the source code.

[0053] In some embodiments, the method further includes: obtaining the code block of the condition judgment logic corresponding to the target operator; parsing the code block to obtain a condition statement subtree.

[0054] For example, the developer generates a code block based on conditional judgment logic and uploads it to the compiler. The compiler compiles the code block to obtain a conditional statement subtree. This conditional statement subtree enables the execution of conditional judgment logic before calling or manipulating a collection type, thereby achieving security verification of the collection type.

[0055] Optionally, the target operator supports chained composition, such as the object returned in the previous step including the collection type to be called in the next step; the node corresponding to the target operator in the abstract syntax tree is replaced with the condition statement subtree to obtain the target abstract syntax tree, including: replacing the node corresponding to the target operator with the condition statement subtree according to the order of the target operators increasing layer by layer from the outside to the inside to obtain the target abstract syntax tree.

[0056] Step S104: Compile the target abstract syntax tree into executable code.

[0057] In this step, the compiler compiles the target abstract syntax tree into executable code based on a common compilation method.

[0058] When the executable code is executed subsequently and reaches the collection type, the condition judgment logic will be executed. After the condition judgment logic passes (e.g., the collection variable is in a valid state, or there is an index element), the corresponding operation will be executed, thus realizing safe access to the collection type.

[0059] In some embodiments, during the executable code execution phase, the running status, such as whether security judgment logic is triggered or whether the operation is abnormal, can be obtained and fed back to the compiler so that the compiler can optimize the node replacement process of the abstract syntax tree.

[0060] Specifically, during executable code execution, the access status of collection variables is recorded via probes or logs. When compiling the same source code subsequently, the node replacement strategy of the abstract syntax tree is adjusted based on the historical access status. For example, if a collection variable has never been NULL during runtime, conditional judgment logic can be skipped. This approach further improves code execution efficiency through coordinated optimization of runtime status and compilation phases.

[0061] The code conversion method for collection types provided in this application adds extended target operators to the code segments that call collection types in the source code. These concise target operators express the intent for secure access, eliminating the need to manually write redundant conditional logic code segments. This improves the efficiency of source code writing, reduces redundancy, and enhances readability and maintainability. During source code compilation and parsing into an abstract syntax tree, the target operator is set as a node in the abstract syntax tree, and this node is replaced with a syntax subtree containing the conditional logic. The resulting executable code then includes complete conditional logic, ensuring runtime security.

[0062] In one possible implementation, the target operator includes a safe navigation operator; the safe navigation operator is an extended operator added to the code segment used to access or manipulate the collection type; and a conditional statement subtree used to return a default value or execute silently when the collection variable in the collection type has an invalid value, and to access or manipulate the collection type when the collection variable in the collection type has a valid value.

[0063] An invalid value indicates that the collection type is in an invalid state, i.e., a NULL state, used to identify the value of a collection variable that has been declared but not initialized.

[0064] Safety navigation operators are predefined extended operators used to express the intent to safely invoke collection types. The code segment corresponding to a safety navigation operator calls a collection type, and the invocation method is to access or manipulate the collection type. In one example, the safety navigation operator can be "@.".

[0065] For example, you can add safe navigation operators to code snippets that access or manipulate collection types. For instance, adding the target operator "@." to the code snippet containing the syntax `collection_expression method or attribute` results in a code snippet with the target operator added: `collection_expression@.method_or_attribute`. Here, `collection_expression` is the expression for the collection type; `method` is the specific operation, such as deletion; and `attribute` is the attribute of the collection type being accessed, such as the total number of collection variables.

[0066] When the target operator is a safe navigation operator, the conditional statement subtree is configured to check the validity status of the collection variables in the collection type before accessing or operating on the collection type. If the validity status is invalid, meaning the collection variable returns an invalid value, it indicates that the collection variable in the collection type has not been initialized, and direct access or operation may pose a risk of runtime exceptions. In this case, a default value, such as NULL, is returned, or silent execution is performed. If the validity status is valid, meaning the collection variable returns a valid value, it indicates that the collection variable in the collection type has been initialized. Then, the code segment where the target operator is located is executed, i.e., the access or operation on the collection type is performed.

[0067] For example, the conditional statement subtree is used to return a NULL value if collection_expression is NULL, or to silence the operation of the stored procedure; if collection_expression is not NULL, the call is executed, that is, the specific operation (method) is executed or the attribute of the collection type is accessed.

[0068] By setting up a safe navigation operator and its corresponding conditional statement subtree, a safety check is implemented before executing code segments that access or operate on collection types, thus ensuring the safety of calls to collection types of this type.

[0069] In one possible implementation, the target operator includes a safe subscript operator; the safe subscript operator is an extended operator added to the code segment used to access or manipulate the target set variable in the set type; and a conditional statement subtree used to return a default value or execute silently when the set variable in the set type is invalid or the subscript element of the target set variable is not in a valid range, and to perform relevant access or operations on the target set element in the set type when the set variable in the set type is valid and the subscript element of the target set variable is in a valid range.

[0070] The safe subscript operator is a predefined extended operator used to access or manipulate target collection variables within a collection type. The code segment corresponding to the safe subscript operator is invoked on the collection variable, and the invocation method is to access or manipulate that collection variable. In one example, the safe subscript operator can be "?()".

[0071] For example, a safe subscript operator can be added to the code segment that accesses or manipulates the target collection variable of a collection type. For instance, adding the target operator ?() to the code segment containing the syntax `collection_expression index_expression` results in the code segment with the target operator added: `(collection_expression?(index_expression))`. Here, `collection_expression` is the expression for the target collection variable in the collection type; `index_expression` is the subscript element of the target collection variable, also known as the subscript index value.

[0072] When the target operator is a safe subscript operator, the conditional statement subtree is configured to determine the validity status of the set variables in the set type and whether the subscript element of the target set variable is within a valid range before accessing or operating on the target set variable. Valid range refers to the range of valid key values. If the set variable in the set type is invalid (i.e., has an invalid value), or if the subscript element of the target set variable is not within a valid range, it indicates that accessing or operating on the target set variable would cause a system exception. In this case, a default value, such as NULL, is returned, or a silent operation is performed, rendering the operation invalid. If the associative variable in the set type is valid (i.e., has a valid value), and the subscript element of the target set variable is within a valid range, then the code segment containing the target operator is executed, i.e., the relevant access or operation is performed on the target set element in the set type.

[0073] For example, the conditional statement subtree is used to either return a NULL value or perform a silent operation if collection_expression is NULL or index_expression is not in a valid range; or perform an access or operation on the target collection variable of the collection type if collection_expression is not NULL and index_expression is in a valid range.

[0074] By setting a safe subscript operator and a corresponding conditional statement subtree, the system ensures that the set variable has been initialized before accessing or operating on a specific set variable of the set type. This also prevents program crashes due to index out-of-bounds errors, further ensuring the robustness and stability of the system.

[0075] Figure 2 This is a flowchart illustrating another code conversion method for a collection type provided in an embodiment of this application. For example... Figure 2 As shown, in this embodiment... Figure 1 Based on the embodiments, steps S102 and S103 will be described in detail. The method includes:

[0076] Step S201: Obtain the source code carrying the target operator.

[0077] The target operator is an extended operator added in the code block that calls the collection type.

[0078] Step S202: Perform syntax and semantic analysis on the source code, and create the syntax structure in the source code as the first node.

[0079] Syntax analysis and semantic analysis are techniques used to perform structured parsing of source code. Syntax analysis breaks down the source code into its smallest units, that is, it breaks down the source code into multiple syntactic structures. Semantic analysis checks the legality of the syntactic structures.

[0080] In this step, the encoder uses syntax analysis and semantic analysis to parse the source code, obtain multiple syntax structures, and create each syntax structure as a node in the abstract syntax tree.

[0081] Step S203: When the target operator is identified, create the second node corresponding to the target operator.

[0082] In this step, when the compiler recognizes a target identifier, it treats the target identifier as an independent syntactic structure and creates a second node corresponding to the target operator.

[0083] Step S204: Based on the syntax rules, the first node and the second node are structurally combined to generate an abstract syntax tree.

[0084] In this step, the encoder identifies the logical relationships between various syntactic structures in the source code based on syntactic rules, and then combines the first node and the second node in a structured manner according to the logical relationships to obtain an abstract syntax tree.

[0085] Step S205: Traverse the abstract syntax tree and identify the node corresponding to the target operator.

[0086] In this step, the encoder traverses all nodes in the abstract syntax tree and identifies the node corresponding to the target operator.

[0087] In this embodiment, the semantic analyzer of the encoder can traverse the abstract syntax tree to identify the node corresponding to the target operator.

[0088] Step S206: Determine the corresponding conditional statement subtree based on the context information of the node and the target operator.

[0089] In this step, after identifying the node corresponding to the target operator, context analysis is performed on the node to parse its context information. Then, based on the node's context information and the target operator, the corresponding conditional statement subtree is determined.

[0090] For example, the conditional statement subtrees corresponding to each target operator can be pre-defined. Based on the target operator, the conditional statement subtree corresponding to that target operator is determined; then, based on the context information, the conditional statement subtrees are adjusted, such as modifying the parameters or expressions corresponding to the nodes.

[0091] Optionally, based on the context information of the node and the target operator, the corresponding conditional statement subtree is determined, including: based on the call type and target operator in the context information of the node, determining the conditional statement subtree template corresponding to the target operator under the call type; and filling the conditional statement subtree template based on the call target in the context information to obtain the conditional statement subtree.

[0092] The call type refers to the specific operation type invoked on the collection type, including function calls (such as count), property calls, or procedure calls (such as delete, read, and write operations). The call target is the object of the specific operation, such as the collection type or a specific collection variable within the collection type. The conditional statement subtree template is a predefined conditional judgment logic structure for a specific call type and target operator.

[0093] In this step, the context information of the node can be used to extract the call type and call target. Based on the call type and target operator, the corresponding conditional statement subtree template is selected. Then, based on the call target, such as a set type or a set variable within a set type, placeholders in the conditional statement subtree template are filled with the content that needs to be filled in the template, generating a complete conditional statement subtree.

[0094] For example, the target operators include safe navigation operators and safe subscript operators. For safe navigation operators, the call type includes function calls, property calls, and procedure calls (such as delete operations). For safe subscript operators, the call type includes procedure calls, such as read or write operations. Based on the call type and target operator in the node's context information, if the target operator is a safe navigation operator and the call type is a function call or property call, then the first subtree template is determined to be a conditional statement subtree template; if the target operator is a safe navigation operator and the call type is a procedure call, then the second subtree template is determined to be a conditional statement subtree template; if the target operator is a safe subscript operator and the call type is a read operation, then the third subtree template is determined to be a conditional statement subtree template; if the target operator is a safe subscript operator and the call type is a write operation, then the fourth subtree template is determined to be a conditional statement subtree template.

[0095] The conditional logic for the first subtree template can be as follows: Check if the collection variable in the collection type has a valid value; if so, execute the function call or property call; otherwise, return NULL. The conditional logic for the second subtree template can be as follows: Check if the collection variable in the collection type has a valid value; if so, execute the procedure call; otherwise, execute silently. The conditional logic for the third subtree template can be as follows: Check if the collection variable in the collection type has a valid value and if the index element of the target collection vector is within a valid range; if so, execute the read operation and read the data corresponding to the index element; otherwise, return NULL. The conditional logic for the fourth subtree template can be as follows: Check if the collection variable in the collection type has a valid value; if so, execute the write operation; otherwise, execute silently.

[0096] By matching the call type, target operator, and conditional statement subtree template, unified management of conditional judgment logic for different calls is achieved, ensuring the correctness of the replaced conditional statement subtree. Furthermore, the conditional statement subtree obtained by populating the conditional statement subtree template can dynamically adapt to the call target, improving the flexibility of the executable code.

[0097] Step S207: Replace the node corresponding to the target operator with the conditional statement subtree to obtain the target abstract syntax tree.

[0098] Step S208: Compile the target abstract syntax tree into executable code.

[0099] By dynamically determining the conditional statement subtree through the context information of the node corresponding to the target operator, adaptive generation of targeted security check logic is achieved. This avoids logical errors caused by contextual ambiguity, ensuring the correctness of the final generated executable code and enabling secure access to integrated types in complex scenarios. Furthermore, by dividing nodes into first and second nodes, the compiler can more stably, accurately, and efficiently generate abstract syntax trees when faced with source code carrying new operators, avoiding disruption of the compiler's original logic and significantly reducing the difficulty of modification.

[0100] Figure 3 This is a flowchart illustrating another code conversion method for collection types provided in this application. To better understand the code conversion method for collection types provided in this application, this application provides a detailed description of the code conversion method for collection types.

[0101] like Figure 3 As shown, the developer inputs source code with target operators (@. or ?()). The compiler performs syntax and semantic analysis on the source code, generating an abstract syntax tree.

[0102] The compiler checks if the target operator exists in the abstract syntax tree. If it does not exist, it continues with the normal compilation process to obtain executable code. If it exists, it performs a safe transformation process, which replaces the node corresponding to the target operator in the abstract syntax tree with the conditional statement subtree to obtain the target abstract syntax tree.

[0103] In this embodiment, the security conversion process includes: parsing the context information of the target operator and node; extracting the call type and call target (i.e., the target set variable or set type) from the context information; determining the conditional statement subtree corresponding to the equivalent inline security check code block based on the call type and call target in the context information; and finally, replacing the node corresponding to the original target operator in the abstract syntax tree with the conditional statement subtree to obtain the target abstract syntax tree.

[0104] After the replacement is completed, the subsequent compilation and optimization process is carried out to compile the target abstract syntax tree into executable code.

[0105] Executing the executable code allows for security checks on the collection type when it is called, ensuring the secure execution of the code.

[0106] Figure 4 This is a schematic diagram of the structure of a code conversion device for a collection type provided in an embodiment of this application. Figure 4 As shown, the code conversion device for collection types provided in this embodiment includes an acquisition module 401, a parsing module 402, a replacement module 403, and a post-processing module 404.

[0107] The acquisition module 401 is used to acquire the source code carrying the target operator, which is an extended operator added in the code segment that calls the collection type; the parsing module 402 is used to parse the source code into an abstract syntax tree, wherein the abstract syntax tree includes the node corresponding to the target operator; the replacement module 403 is used to replace the node corresponding to the target operator in the abstract syntax tree with a conditional statement subtree to obtain the target abstract syntax tree; the conditional statement subtree is the subtree structure obtained by parsing the code block used to implement the condition judgment logic of the collection type; the post-processing module 404 is used to compile the target abstract syntax tree into executable code.

[0108] Optionally, the replacement module 403 includes a node identification unit, a subtree determination unit, and a replacement unit, wherein:

[0109] The node identification unit is used to traverse the abstract syntax tree and identify the node corresponding to the target operator; the subtree determination unit is used to determine the corresponding conditional statement subtree based on the context information of the node and the target operator; the replacement unit is used to replace the node corresponding to the target operator with the conditional statement subtree to obtain the target abstract syntax tree.

[0110] Optional, subtree determination unit, specifically used for:

[0111] Based on the call type and target operator in the node's context information, determine the condition statement subtree template corresponding to the target operator under that call type; based on the call target in the context information, populate the condition statement subtree template to obtain the condition statement subtree.

[0112] Optionally, the target operator includes a safe navigation operator; the safe navigation operator is an extended operator added in the code segment used to access or manipulate the collection type; and a conditional statement subtree used to return a default value or execute silently when the collection variable in the collection type has an invalid value, and to access or manipulate the collection type when the collection variable in the collection type has a valid value.

[0113] Optionally, the target operator includes a safe subscript operator; the safe subscript operator is an extended operator added to the code segment used to access or manipulate the target set variable in the set type; and a conditional statement subtree used to return a default value or execute silently when the set variable in the set type is invalid or the subscript element of the target set variable is not in a valid range, and to perform relevant access or operations on the target set element in the set type when the set variable in the set type is valid and the subscript element of the target set variable is in a valid range.

[0114] Optional, parsing module 402, specifically used for:

[0115] The source code is subjected to syntactic and semantic analysis, and the syntactic structure in the source code is created as the first node; when the target operator is identified, the second node corresponding to the target operator is created; based on the syntactic rules, the first node and the second node are structurally combined to generate an abstract syntax tree.

[0116] The code conversion device for collection types provided in this embodiment can execute the methods provided in the above method embodiments. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0117] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 5 As shown, the electronic device provided in this embodiment includes at least one processor 501 and a memory 502. Optionally, the electronic device further includes a communication component 503. The processor 501, memory 502, and communication component 503 are connected via a bus.

[0118] In a specific implementation, at least one processor 501 executes computer execution instructions stored in memory 502, causing at least one processor 501 to perform the above-described method.

[0119] The specific implementation process of processor 501 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0120] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0121] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0122] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0123] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0124] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0125] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0126] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0127] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0128] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0129] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0130] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0131] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0132] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

Claims

1. A code conversion method for collection types, characterized in that, include: Obtain the source code carrying the target operator, which is an extended operator added in the code segment that calls the collection type; The source code is parsed into an abstract syntax tree, wherein the abstract syntax tree includes nodes corresponding to the target operator; The nodes corresponding to the target operators in the abstract syntax tree are replaced with conditional statement subtrees to obtain the target abstract syntax tree; the conditional statement subtree is a subtree structure obtained by parsing the code block used to implement the condition judgment logic of the set type. The target abstract syntax tree is compiled into executable code.

2. The method according to claim 1, characterized in that, The step of replacing the node corresponding to the target operator in the abstract syntax tree with a conditional statement subtree to obtain the target abstract syntax tree includes: Traverse the abstract syntax tree to identify the node corresponding to the target operator; Based on the context information of the node and the target operator, determine the corresponding conditional statement subtree; The target abstract syntax tree is obtained by replacing the node corresponding to the target operator with the conditional statement subtree.

3. The method according to claim 2, characterized in that, The step of determining the corresponding conditional statement subtree based on the context information of the node and the target operator includes: Based on the call type and the target operator in the context information of the node, determine the conditional statement subtree template corresponding to the target operator under the call type; Based on the call target in the context information, the conditional statement subtree template is filled to obtain the conditional statement subtree.

4. The method according to claim 1, characterized in that, The target operator includes a safe navigation operator; the safe navigation operator is an extended operator added in a code segment used to access or manipulate a collection type; The conditional statement subtree is used to return a default value or execute silently when the set variable in the set type is invalid, and to access or operate on the set type when the set variable in the set type is valid.

5. The method according to claim 1, characterized in that, The target operator includes a safe subscript operator; the safe subscript operator is an extended operator added in the code segment used to access or manipulate the target set variable in the set type; The conditional statement subtree is used to return a default value or execute silently when the set variable in the set type is invalid or the index element of the target set variable is not in a valid range, and to perform relevant access or operation on the target set element in the set type when the set variable in the set type is valid and the index element of the target set variable is in a valid range.

6. The method according to any one of claims 1-5, characterized in that, The step of parsing the source code into an abstract syntax tree includes: Perform syntax and semantic analysis on the source code, and create the syntactic structure in the source code as the first node; When the target operator is identified, a second node corresponding to the target operator is created; Based on grammar rules, the first node and the second node are structurally combined to generate the abstract syntax tree.

7. A code conversion device for a collection type, characterized in that, include: The acquisition module is used to acquire the source code carrying the target operator, which is an extended operator added in the code segment that calls the collection type; A parsing module is used to parse the source code into an abstract syntax tree, wherein the abstract syntax tree includes nodes corresponding to the target operator; The replacement module is used to replace the nodes corresponding to the target operators in the abstract syntax tree with conditional statement subtrees to obtain the target abstract syntax tree; the conditional statement subtree is a subtree structure obtained by parsing the code block used to implement the condition judgment logic of the set type. The post-processing module is used to compile the target abstract syntax tree into executable code.

8. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-6.

10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-6.