Multi-language program structure unified modeling method and system based on semantic reservation

By constructing a unified structured semantic graph and a multilingual unified type system, the problems of semantic loss and boundary discontinuity in cross-language analysis are solved, enabling in-depth unified modeling and vulnerability detection of heterogeneous code, thus improving analysis accuracy and efficiency.

CN121996247APending Publication Date: 2026-05-08HANGZHOU DBAPPSECURITY CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU DBAPPSECURITY CO LTD
Filing Date
2026-01-20
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing program structure modeling and static analysis methods cannot effectively understand cross-language call relationships, resulting in analysis blind spots. Furthermore, the semantic loss of intermediate representations and the inaccurate modeling of external function interfaces make it impossible to detect complex vulnerabilities.

Method used

By constructing a unified structured semantic graph (SSG) and a multilingual unified type system (MLUTS), we can achieve deep unified modeling of heterogeneous code such as Java, Rust, C/C++, and Go, preserve cross-language semantics, construct FFI descriptors, generate bridging edges, and form a complete program structure model.

Benefits of technology

It enables the recovery of cross-language call graphs and provides insight into underlying details, allowing for the detection of complex vulnerabilities such as memory leaks, dangling pointers, and concurrent deadlocks. This improves the accuracy and efficiency of analysis and provides high scalability and adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121996247A_ABST
    Figure CN121996247A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-language program structure unified modeling method and system based on semantic preservation, and relates to the technical field of program analysis and network security. The method comprises the following steps: receiving source codes of multiple programming languages, generating a corresponding native abstract syntax tree by utilizing a front-end analyzer configured with a declarative mapping framework DSMF, and converting the native abstract syntax tree AST into initial nodes and edges of a unified structured semantic graph SSG according to a predefined mapping rule; receiving type information of multiple programming languages, mapping the type information into a unified quintuple semantic vector by using a multi-language unified type system (MLUTS), and annotating the semantic vector to a corresponding node of a structured semantic graph (SSG) as an attribute. According to the method, a unified model containing control flow, data flow and program semantics can be constructed, static vulnerability detection and deep stain analysis in a cross-language environment are effectively supported, and the coverage rate and accuracy of analysis are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of program analysis and network security technology, specifically to a unified modeling method and system for multilingual program structures based on semantic preservation. Background Technology

[0002] With the rapid development of the software industry, modern large-scale software systems are becoming increasingly complex, and multi-language hybrid programming has become the mainstream development paradigm. For example, high-concurrency business logic is built using Java or Go, while high-performance low-level modules written in C / C++ or Rust are called via JNI or CGo. While this heterogeneous architecture improves development efficiency and system performance, it also poses serious challenges to software quality assurance and security testing. Existing program structure modeling and static analysis methods mainly suffer from the following shortcomings: 1. The "Language Silo" Effect: Traditional static analysis tools (such as FindBugs, Checkstyle, etc.) are usually designed for a single language and cannot understand cross-language call relationships. When the analysis process reaches the language boundary (such as Java calling a C function), the analysis is often forced to stop, resulting in a broken call graph and creating blind spots in the analysis.

[0003] 2. Semantic Loss in Intermediate Representation (IR): To achieve multi-language support, some tools (such as LLVM-based analyzers) convert source code into a low-level intermediate representation (IR). However, low-level IRs like LLVM IR primarily serve compilation optimization, and their low level of abstraction results in the stripping away of semantics from the source code (such as Rust's ownership rules, Java's generic constraints, and Go's Channel mechanism) during the conversion process. Without this program semantics, security analysis tools struggle to accurately detect complex vulnerabilities such as memory leaks, dangling pointers, or concurrent deadlocks.

[0004] 3. Lack of FFI boundary modeling: Existing unified modeling methods often overlook the low-level details at the external function interface. Different languages ​​have significant differences in memory layout, byte alignment, and parameter passing conventions. If the model cannot accurately describe these differences, it cannot detect buffer overflows or data truncation vulnerabilities caused by ABI incompatibility.

[0005] To address this, the present invention proposes a unified modeling method and system for multilingual program structures based on semantic preservation. Summary of the Invention

[0006] The purpose of this invention is to provide a unified modeling method and system for multilingual program structures based on semantic preservation. By constructing a unified structured semantic graph (SSG) and a multilingual unified type system (MLUTS), it achieves deep unified modeling of heterogeneous code such as Java, Rust, C / C++, and Go, effectively solving the problems of semantic loss and boundary discontinuity in cross-language analysis.

[0007] According to a first aspect of the present invention, in order to achieve the above-mentioned objective, the present invention provides the following technical solution: a unified modeling method for multilingual program structure based on semantic preservation, comprising the following steps: It receives source code from multiple programming languages, uses a front-end parser configured with the declarative mapping framework DSMF to generate the corresponding native abstract syntax tree, and converts the native abstract syntax tree AST into the initial nodes and edges of the unified structured semantic graph SSG according to predefined mapping rules. It receives type information from multiple programming languages, uses the Multilingual Unified Type System (MLUTS) to map the type information into a unified five-tuple semantic vector, and annotates the semantic vector as an attribute to the corresponding node of the Structured Semantic Graph (SSG) to achieve semantic alignment across language types. The quintuple semantic vector explicitly describes the basic data type, ownership semantics, lifecycle constraints, memory layout characteristics, and concurrency state. Identify the external function interface (FFI) call points and definition points in the source program, calculate the memory layout fingerprint of the data structure according to the application binary interface (ABI) specification of the target runtime environment, construct the FFI descriptor, and generate bridging edges connecting different language subgraphs in SSG. Based on the initial nodes and bridging edges of the Structured Semantic Graph (SSG), control flow edges, data flow edges, and call edges are constructed to form a complete program structure model that includes the physical layer, logical layer, and semantic layer.

[0008] Furthermore, the various programming languages ​​include Java, Rust, C / C++, and Go.

[0009] Furthermore, a front-end parser configured with a declarative mapping framework is used to generate the corresponding native abstract syntax tree, and the native abstract syntax tree is converted into the initial nodes and edges of the unified structured semantic graph (SSG) according to predefined mapping rules, as follows: Rule configuration loading: The system loads a predefined declarative mapping rule library. The rule library uses YAML or JSON format and defines the static mapping relationship between the Abstract Syntax Tree (AST) node types of different programming languages ​​and the unified structured semantic graph (SSG) standard node types. Hierarchical structure mapping: The mapping engine traverses the input native AST and performs hierarchical mapping according to the rule base: For general program structures, static rules are directly applied for one-to-one or one-to-many mapping; for complex structures specific to the language, the corresponding dynamic processing logic is triggered. Dynamic semantic adaptation: For the complex structure, an embeddable script plugin is invoked, which contains logic for generating or transforming SSG subgraphs to ensure that high-level semantics of the language are preserved and accurately expressed in SSG; Attribute binding and output: While completing the node type mapping, key attributes, including identifiers and type annotations in the source node, are extracted according to the mapping rules and bound to the generated SSG node. Finally, an intermediate representation consisting of the initial SSG node and edges is output.

[0010] Furthermore, the unified structured semantic graph (SSG) is a multi-attribute directed graph, whose node types include at least: Structure definition nodes: represent the static hierarchical structure of modules, classes, functions, and interfaces; Operation execution node: represents the specific instruction behavior of declaration, assignment, invocation, and operation; Semantic anchor nodes: represent control flow turning points such as exception throwing, resource release, and asynchronous suspension.

[0011] Furthermore, the quintuple semantic vector T is defined as T = <τ base ,μ own , λ life , δ mem ,ξ sync >, where: τ base It represents the basic data structure type and is used to unify scalar and composite types in different languages; μ own Represents ownership semantic weights, used to describe the memory management ownership of variables, with values ​​including at least Owned, Borrowed, Shared, and Foreign. λ life Represents a set of lifecycle constraints, using interval logic or scope identifiers to describe the lifespan of variables; δ mem A memory layout fingerprint is used to describe the byte alignment, padding pattern, and field offset of a data structure in memory. ξ sync Represents the state of concurrent primitives, used to mark the state of synchronization locks, atomic operations, or channels.

[0012] Furthermore, the call points and definition points of the External Function Interface (FFI) in the source program are identified. Based on the Application Programming Interface (ABI) specification of the target runtime environment, the memory layout fingerprint of the data structure is calculated, an FFI descriptor is constructed, and bridging edges connecting different language subgraphs are generated in the SSG, as detailed below: Extract parameter types and return value types from cross-language calls; Based on the ABI specification of the target platform, simulate and calculate the layout of each type in memory to generate a memory layout fingerprint; Compare the memory layout fingerprints of the caller and the callee. If the fingerprints do not match, mark the memory layout risk attribute on the bridging edge. According to the calling convention, an adapter node is inserted in SSG to simulate the data flow of parameter pushing onto the stack and register passing.

[0013] Furthermore, based on the initial nodes and bridging edges of the Structured Semantic Graph (SSG), control flow edges, data flow edges, and call edges are constructed to form a complete program structure model containing physical, logical, and semantic layers, as detailed below: Control flow edge construction: Based on the sequence, branching, looping, and exception handling structure in the program, directed edges are established between operation execution nodes and semantic anchor nodes to represent the logical order and path transfer of program execution; Data flow edge construction: Based on the definition and usage relationship of variables, and combined with all semantic weights and life cycle constraint set attributes in the quintuple semantic vector, data dependency edges are established between the definition node and the usage node, supporting cross-function and cross-semantic data flow tracing; Call edge construction: Based on the function call relationship, a call edge is established between the calling node and the entry node of the called function, supporting the same representation for intra-language calls and cross-language FFI calls, and passing semantic information of parameters and return values.

[0014] According to a second aspect of the present invention, the present invention provides a unified modeling system for multilingual program structure based on semantic preservation, used to implement the unified modeling method for multilingual program structure based on semantic preservation described in the first aspect, comprising: The multi-language front-end adaptation module is used to receive source code in multiple programming languages, generate corresponding native abstract syntax trees using a front-end parser configured with the declarative mapping framework DSMF, and convert the native abstract syntax tree AST into the initial nodes and edges of the unified structured semantic graph SSG according to predefined mapping rules. The Unified Type Engine module is used to receive type information from multiple programming languages, use the Multilingual Unified Type System (MLUTS) to map the type information into a unified five-tuple semantic vector, and annotate the semantic vector as an attribute to the corresponding node of the Structured Semantic Graph (SSG) to achieve semantic alignment across language types. The quintuple semantic vector explicitly describes the basic data type, ownership semantics, lifecycle constraints, memory layout characteristics, and concurrency state. The cross-language linking module is used to identify the external function interface (FFI) call points and definition points in the source program, calculate the memory layout fingerprint of the data structure according to the application binary interface (ABI) specification of the target runtime environment, construct the FFI descriptor, and generate bridge edges in SSG that connect subgraphs of different languages. The core module for graph construction is used to build control flow edges, data flow edges, and call edges on the basis of the initial nodes and bridging edges of the structured semantic graph (SSG), forming a complete program structure model that includes the physical layer, logical layer, and semantic layer.

[0015] Furthermore, the unified type engine module incorporates the MLUTS algorithm, which includes a semantic dimensionality reducer for: Map Java / Go garbage-collected objects to "externally managed" or "shared" ownership states; Map Rust / C++ smart pointers to "exclusive" or "shared" ownership states while preserving their destructor semantics; Ensure that languages ​​with different memory management models have comparable semantic representations in SSG.

[0016] According to a third aspect of the present invention, the present invention provides a terminal device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein when the processor loads and executes the computer program, it employs the semantically preserved multilingual program structure unified modeling method described in the first aspect.

[0017] This invention has at least the following beneficial effects: 1. Complete preservation of program semantics: Through MLUTS quintuple vectors, this invention preserves Rust's ownership / borrowing semantics and C++'s pointer arithmetic semantics at the unified modeling level for the first time. This enables the model to support the detection of complex memory security vulnerabilities such as Use-After-Free and Double-Free, which is difficult to achieve with traditional low-level IR-based methods.

[0018] 2. Deep Cross-Language Perspective: This invention solves the "language island" problem through precise FFI boundary modeling. The system can not only generate bridging edges connecting different language subgraphs in SSG and restore the complete cross-language call graph, but more importantly, it can perform memory layout simulation and fingerprint comparison according to the ABI specification of the target platform. This mechanism enables the model to see through the underlying details and detect hidden risks caused by inconsistencies in memory layout, byte alignment, or parameter passing conventions, such as buffer overflows and data truncation, thus achieving deep detection capabilities for cross-language interaction vulnerabilities.

[0019] 3. High scalability and adaptability: The declarative mapping framework (DSMF) used in this invention employs an architecture that separates rule configuration from the core engine. For new programming languages, developers do not need to modify the core analysis logic of the system; they only need to write mapping rules in YAML / JSON format or pluggable scripts to adapt to the syntax structure of the new language. This design greatly reduces the complexity and cost of system expansion, enabling this invention to quickly adapt to the ever-evolving programming language ecosystem.

[0020] 4. Unified Analysis Base: The constructed SSG model simultaneously includes AST, CFG, CG, and DFG information, providing "one-stop" data structure support for upper-level taint analysis, slice analysis, and symbolic execution. Analysis tools do not need to convert and correlate between multiple intermediate representations, avoiding information loss and performance overhead caused by multi-model conversion. Thus, while ensuring analysis accuracy, the overall efficiency of the analysis process is significantly improved.

[0021] Of course, any product implementing this invention does not necessarily need to achieve all of the advantages described above at the same time. Attached Figure Description

[0022] Figure 1 This is a schematic diagram of the overall process of the method of the present invention; Figure 2 This is a diagram of the hierarchical architecture model of the Unified Structured Semantic Graph (SSG) of this invention; Figure 3 This is a schematic diagram of the five-tuple semantic vector mapping principle of the Multilingual Unified Type System (MLUTS) of this invention; Figure 4 This is a schematic diagram illustrating the working principle of the Declarative Mapping Framework (DSMF) of this invention; Figure 5 This is a schematic diagram illustrating the working principle of cross-language FLL boundary modeling in this invention. Detailed Implementation

[0023] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0024] Example 1: Please see Figures 1-5 This invention provides a technical solution: a unified modeling method for multilingual program structure based on semantic preservation, comprising the following steps: S1. Parsing and Mapping Steps: Using a front-end parser configured with a declarative mapping framework (DSMF), the source code of various programming languages ​​such as Java, Rust, C / C++, and Go is parsed to generate their respective native abstract syntax trees (ASTs). Based on predefined mapping rules, the native ASTs are then converted into the initial nodes and edges of a unified structured semantic graph (SSG), as detailed below: Rule configuration loading: The system loads a predefined declarative mapping rule library. The rule library uses YAML or JSON format and defines the static mapping relationship between the Abstract Syntax Tree (AST) node types of different programming languages ​​and the standard node types of the unified structured semantic graph (SSG). Each rule unit mainly includes fields such as source_node (specifies the node type in the source language AST, such as Java.MethodInvocation, Rust.LetStmt), target_node (specifies the standard node type in the target SSG, such as SSG.Call, SSG.Declare), and attribute_mapping (defines the attribute transformation rules from the source node to the target node, supporting the extraction or calculation of attribute values ​​through expressions). Hierarchical structure mapping: The mapping engine traverses the input native AST and performs hierarchical mapping according to the rule base: For general program structures, static rules are directly applied for one-to-one or one-to-many mapping; for complex structures specific to the language, the corresponding dynamic processing logic is triggered. Dynamic semantic adaptation: For the complex structure, an embeddable script plugin is invoked, which contains logic for generating or transforming SSG subgraphs to ensure that high-level semantics of the language are preserved and accurately expressed in SSG; Attribute binding and output: While completing the node type mapping, the key attributes, including the identifier and type annotation in the source node, are extracted according to the mapping rules and bound to the generated SSG node. Finally, the intermediate representation consisting of the initial SSG node and edges is output. DSMF reads rule definitions in YAML / JSON format, for example, mapping Java's VariableDeclaration and Go's VarSpec to Declare nodes in SSG; Furthermore, the Unified Structured Semantic Graph (SSG) is a multi-attribute directed graph whose node types include at least: Structure definition nodes: represent the static hierarchical structure of modules, classes, functions, and interfaces; Operation execution node: represents the specific instruction behavior of declaration, assignment, invocation, and operation; Semantic anchor nodes: represent control flow inflection points such as exception throwing, resource release, and asynchronous suspension; like Figure 4 As shown, DSMF allows developers to define the AST to SSG conversion logic through configuration files without modifying the core code; Configuration snippet example (pseudocode): mapping: source_node: "Java.MethodInvocation" target_node: "SSG.Call attributes: name: "$source.name" receiver: "$source.expression" children: - source: "$source.arguments" target: "SSG.Argument" For complex logic, such as the defer statement in Go, DSMF supports mounting scripts. When building CFG, the script logic will automatically insert the call node pointed to by defer before all exit nodes (Return or Panic paths) of the current function, thereby accurately restoring the resource cleanup semantics of Go in SSG. S2. Semantic Normalization Step: Using the Multilingual Unified Type System (MLUTS), the type information of each source language is mapped to a unified five-tuple semantic vector, and the semantic vector is annotated as an attribute on the corresponding node of SSG to enhance semantics; the five-tuple semantic vector explicitly describes the basic data type, ownership semantics, lifecycle constraints, memory layout characteristics, and concurrency state, as detailed below: like Figure 3 As shown, MLUTS aims to eliminate the semantic gap between different language type systems; Defined quintuple semantic vector T =<τ base ,μ own , λ life , δ mem ,ξ sync The specific meanings are as follows: τ base The basic data structure types are represented as follows: int, long, i32, int64, etc. are unified as fixed-length integer types; class and struct are unified as composite record types. μown Semantic weight representing ownership: Owned: Indicates that the user has the responsibility to release resources (e.g., C++ std::unique_ptr, Rust value type). Shared: Indicates shared ownership (such as Java object references, C++ std::shared_ptr); Borrowed: Indicates temporary borrowing (such as Rust &T, C++ references); Foreign: Indicates that it is managed by an external runtime (such as jobobject in JNI); λ life Representing a set of lifetime constraints: These are identified using abstract range or scope IDs. For example, the lifetime of a local variable is bound to its lexical scope block. δ mem A fingerprint representing the memory layout includes the record type's size, alignment, and field offset.

[0025] ξ sync Concurrency primitive state: indicates whether the variable is protected by a mutex or whether it is an atomic type; Application example: like Figure 3 As shown, when analyzing a C++ function that passes a `std::unique_ptr(Owned)` to a C interface that only accepts raw pointers, and that pointer is not freed in the C interface, the analyzer examines the μ on the data stream edge in the SSG. own Changes in attributes can indicate that ownership has been lost but not released, thus reporting a memory leak. S3. Cross-language bridging steps: Identify external function interface (FFI) call points and definition points in the source program; calculate the memory layout fingerprint of data structures according to the application binary interface (ABI) specification of the target runtime environment; construct FFI descriptors; and generate bridging edges with semantic inspection capabilities in SSG to connect different language subgraphs, as detailed below: Extract parameter types and return value types from cross-language calls; Based on the ABI specification of the target platform, simulate and calculate the layout of each type in memory to generate a memory layout fingerprint; Compare the memory layout fingerprints of the caller and the callee. If the fingerprints do not match, mark the memory layout risk attribute on the bridging edge. According to the calling convention, an adapter node is inserted into SSG to simulate the data flow during parameter push-on and register transfer. For example, scan all functions marked as native or extern, find their corresponding implementations, and use FFI descriptors to establish cross-graph connections; Specifically, such as Figure 5 The following is a scenario for Java calling C++ JNI: 1. Java side: Method declaration: native void foo(String s), SSG generates a Call node, the type vector of parameter s is String, where the basic type τ base For String, ownership μ own Shared, memory layout δ mem Layout for JVM objects; 2. C++ side: Function definition JNIEXPORT void JNICALL Java_pkg_foo(JNIEnv env, jobobject obj, jstring s), SSG generates a FunctionDef node, where the parameter s is of type jstring, and its semantic vector contains μ own Marked as Foreign (external hosting), δ mem Marked as an opaque handle; 3. Bridging: The system identifies the correspondence between the two, constructs an FFL descriptor, maps String to jstring, and calculates the memory layout of jstring on the C++ side when constructing the bridging edge. Since jstring is essentially a transparent pointer, the system will check whether the C++ code accesses its content through APIs such as GetStringUTFChars, and insert an adapter node in SSG to simulate the implicit passing of JNIEnv. 4. Risk Detection: If C++ code directly casts the jstring address for reading (violating the JNI specification), the memory layout fingerprint comparison in SSG will fail (JVM object layout vs. C++ pointer layout). This allows potential risks to be flagged during the modeling phase. Simultaneously, the system tracks the lifecycle λ of C-style strings obtained through the API. life If no corresponding ReleaseStringUTFChars call is found, a resource leak will be reported. S4. Steps to improve the graph structure: Finally, construct control flow edges, data flow edges, and call edges on the SSG. For example, based on the mapped nodes, the system connects control flow edges according to the language's control flow rules (such as if, for, switch); and connects data flow edges according to the read and write relationships of variables, forming a complete program structure model including physical, logical, and semantic layers as shown in Figure 2. The construction of control flow edges includes: First, identifying control flow nodes and marking all nodes in the SSG that may change the program execution order, including conditional branch nodes (if, switch), loop nodes (for, while), jump nodes (break, continue, return), and exception handling nodes (throw, catch). Then, connecting edges based on language semantics: For sequential structures, adding control flow edges from the previous node to the next; for branching structures, adding edges from conditional nodes to the entry nodes of each branch, marking the condition value (true / false), and the merging point after the branch ends, pointing from the last node of each branch to the subsequent common code node; for loop structures, establishing control flow edges from the loop head node to the first node inside the loop body, from the last node of the loop body to the loop head node, and from the loop head node to the first node after the loop ends; for exception paths, adding edges from the throw node to the nearest catch or function exit. Finally, for cross-language control flow bridging, if the function call involves FFI, marking the possible cross-language boundaries of control flow on the bridging edges, and continuing to construct control flow in the target language subgraph.

[0026] Data flow edge construction: Directed data flow edges are constructed based on the definition and usage relationships of variables, combined with the read / write attributes of nodes in SSG and the semantic vectors of 5-tuples. First, the definition and usage of variables are analyzed, traversing the declaration and assignment nodes in SSG to record the usage points of variables. Next, data dependency edges are established, adding data flow edges from each definition point to all reachable usage points. If the variable ownership is Borrowed, it is necessary to additionally check whether the lifecycles overlap. If the variable involves concurrency, it needs to be synchronously marked on the data flow edge to support concurrency analysis. Finally, cross-function data flow tracing is performed, passing parameters and return values ​​through call edges. For global variables and static variables, cross-function data flow links are established.

[0027] Constructing Call Edges: Based on function / method call relationships, directed call edges are constructed, including intra-language calls and cross-language FFI calls. First, call nodes are identified, and all call nodes (e.g., Call, MethodInvocation) are marked in the SSG, recording the target function identifier. Next, the target function definition is parsed, and a matching function definition node is searched within the same language subgraph. If it's a cross-language call, it's bridged to the corresponding function in the target language subgraph via an FFI descriptor. Finally, call edges and context passing are established, adding call edges from the call node to the target function's entry node and passing data flow edges for parameters and return values.

[0028] Example 2: This embodiment provides a unified modeling system for multilingual program structures based on semantic preservation, used to implement the unified modeling method for multilingual program structures based on semantic preservation described in Embodiment 1, including: The multi-language front-end adaptation module is used to receive source code in multiple programming languages, generate corresponding native abstract syntax trees using a front-end parser configured with the declarative mapping framework DSMF, and convert the native abstract syntax tree AST into the initial nodes and edges of the unified structured semantic graph SSG according to predefined mapping rules. The Unified Type Engine module is used to receive type information from multiple programming languages, use the Multilingual Unified Type System (MLUTS) to map the type information into a unified five-tuple semantic vector, and annotate the semantic vector as an attribute to the corresponding node of the Structured Semantic Graph (SSG) to achieve semantic alignment across language types. The quintuple semantic vector explicitly describes the basic data type, ownership semantics, lifecycle constraints, memory layout characteristics, and concurrency state. The cross-language linking module is used to identify the external function interface (FFI) call points and definition points in the source program, calculate the memory layout fingerprint of the data structure according to the application binary interface (ABI) specification of the target runtime environment, construct the FFI descriptor, and generate bridge edges in SSG that connect subgraphs of different languages. The core module for graph construction is used to build control flow edges, data flow edges, and call edges on the basis of the initial nodes and bridging edges of the structured semantic graph (SSG), forming a complete program structure model that includes the physical layer, logical layer, and semantic layer.

[0029] Furthermore, the unified type engine module incorporates the MLUTS algorithm, which includes a semantic dimensionality reducer for: Map Java / Go garbage-collected objects to "externally managed" or "shared" ownership states; Map Rust / C++ smart pointers to "exclusive" or "shared" ownership states while preserving their destructor semantics; Ensure that languages ​​with different memory management models have comparable semantic representations in SSG.

[0030] Example 3: This embodiment provides a terminal device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The memory stores the computer program capable of running on the processor. When the processor loads and executes the computer program, it adopts the semantically preserved multilingual program structure unified modeling method described in Embodiment 1.

[0031] It should be noted that the terminal device can be a computer device such as a desktop computer, a laptop computer, or a cloud server, and the terminal device includes, but is not limited to, a processor and a memory. For example, the terminal device may also include input / output devices, network access devices, and buses.

[0032] Furthermore, the processor can be a central processing unit (CPU). Of course, depending on the actual use, other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. can also be used. The general-purpose processor can be a microprocessor or any conventional processor, etc., and this application does not limit it in this regard.

[0033] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0034] For those skilled in the art, the specific meaning of the above terms in this invention can be understood according to the specific circumstances. When an element is referred to as being "assembled on," "mounted on," "fixed to," or "set on" another element, it may be directly on the other element or there may be an intermediate element present. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be an intermediate element present. The terms "vertical," "horizontal," "upper," "lower," "left," "right," and similar expressions used herein are for illustrative purposes only and do not represent the only possible embodiments.

[0035] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

[0036] In the description of this specification, references to terms such as "an embodiment," "example," "specific example," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this disclosure. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

Claims

1. A unified modeling method for multilingual program structure based on semantic preservation, characterized in that, Includes the following steps: It receives source code from multiple programming languages, uses a front-end parser configured with the declarative mapping framework DSMF to generate the corresponding native abstract syntax tree, and converts the native abstract syntax tree AST into the initial nodes and edges of the unified structured semantic graph SSG according to predefined mapping rules. It receives type information from multiple programming languages, uses the Multilingual Unified Type System (MLUTS) to map the type information into a unified five-tuple semantic vector, and annotates the semantic vector as an attribute to the corresponding node of the Structured Semantic Graph (SSG) to achieve semantic alignment across language types. The quintuple semantic vector explicitly describes the basic data type, ownership semantics, lifecycle constraints, memory layout characteristics, and concurrency state. Identify the external function interface (FFI) call points and definition points in the source program, calculate the memory layout fingerprint of the data structure according to the application binary interface (ABI) specification of the target runtime environment, construct the FFI descriptor, and generate bridging edges connecting different language subgraphs in SSG. Based on the initial nodes and bridging edges of the Structured Semantic Graph (SSG), control flow edges, data flow edges, and call edges are constructed to form a complete program structure model that includes the physical layer, logical layer, and semantic layer.

2. The unified modeling method for multilingual program structure based on semantic preservation according to claim 1, characterized in that: The various programming languages ​​mentioned include Java, Rust, C / C++, and Go.

3. The unified modeling method for multilingual program structure based on semantic preservation according to claim 2, characterized in that: The corresponding native abstract syntax tree is generated using a front-end parser configured with a declarative mapping framework. Then, based on predefined mapping rules, the native abstract syntax tree is converted into the initial nodes and edges of a unified structured semantic graph (SSG), as follows: Rule configuration loading: The system loads a predefined declarative mapping rule library. The rule library uses YAML or JSON format and defines the static mapping relationship between the Abstract Syntax Tree (AST) node types of different programming languages ​​and the unified structured semantic graph (SSG) standard node types. Hierarchical structure mapping: The mapping engine traverses the input native AST and performs hierarchical mapping according to the rule base: For general program structures, static rules are directly applied for one-to-one or one-to-many mapping; for complex structures specific to the language, the corresponding dynamic processing logic is triggered. Dynamic semantic adaptation: For the complex structure, an embeddable script plugin is invoked, which contains logic for generating or transforming SSG subgraphs to ensure that high-level semantics of the language are preserved and accurately expressed in SSG; Attribute binding and output: While completing the node type mapping, key attributes, including identifiers and type annotations in the source node, are extracted according to the mapping rules and bound to the generated SSG node. Finally, an intermediate representation consisting of the initial SSG node and edges is output.

4. The unified modeling method for multilingual program structure based on semantic preservation according to claim 3, characterized in that: The unified structured semantic graph (SSG) is a multi-attribute directed graph whose node types include at least: Structure definition nodes: represent the static hierarchical structure of modules, classes, functions, and interfaces; Operation execution node: represents the specific instruction behavior of declaration, assignment, invocation, and operation; Semantic anchor nodes: represent control flow turning points such as exception throwing, resource release, and asynchronous suspension.

5. The unified modeling method for multilingual program structure based on semantic preservation according to claim 4, characterized in that: The quintuple semantic vector T is defined as T = < τ base ,μ own , λ life , δ mem ,ξ sync >, where: τ base It represents the basic data structure type and is used to unify scalar and composite types in different languages; μ own Represents ownership semantic weights, used to describe the memory management ownership of variables, with values ​​including at least Owned, Borrowed, Shared, and Foreign. λ life Represents a set of lifecycle constraints, using interval logic or scope identifiers to describe the lifespan of variables; δ mem A memory layout fingerprint is used to describe the byte alignment, padding pattern, and field offset of a data structure in memory. ξ sync Represents the state of concurrent primitives, used to mark the state of synchronization locks, atomic operations, or channels.

6. The unified modeling method for multilingual program structure based on semantic preservation according to claim 5, characterized in that: Identify the external function interface (FFI) call points and definition points in the source program, calculate the memory layout fingerprint of the data structure according to the application binary interface (ABI) specification of the target runtime environment, construct the FFI descriptor, and generate bridging edges connecting different language subgraphs in SSG, as follows: Extract parameter types and return value types from cross-language calls; Based on the ABI specification of the target platform, simulate and calculate the layout of each type in memory to generate a memory layout fingerprint; Compare the memory layout fingerprints of the caller and the callee. If the fingerprints do not match, mark the memory layout risk attribute on the bridging edge. According to the calling convention, an adapter node is inserted in SSG to simulate the data flow of parameter pushing onto the stack and register passing.

7. The unified modeling method for multilingual program structure based on semantic preservation according to claim 6, characterized in that: Based on the initial nodes and bridging edges of the Structured Semantic Graph (SSG), control flow edges, data flow edges, and call edges are constructed to form a complete program structure model containing physical, logical, and semantic layers, as detailed below: Control flow edge construction: Based on the sequence, branching, looping, and exception handling structure in the program, directed edges are established between operation execution nodes and semantic anchor nodes to represent the logical order and path transfer of program execution; Data flow edge construction: Based on the definition and usage relationship of variables, and combined with all semantic weights and life cycle constraint set attributes in the quintuple semantic vector, data dependency edges are established between the definition node and the usage node, supporting cross-function and cross-semantic data flow tracing; Call edge construction: Based on the function call relationship, a call edge is established between the calling node and the entry node of the called function, supporting the same representation for intra-language calls and cross-language FFI calls, and passing semantic information of parameters and return values.

8. A unified modeling system for multilingual program structure based on semantic preservation, used to implement the unified modeling method for multilingual program structure based on semantic preservation as described in any one of claims 1 to 7, characterized in that, include: The multi-language front-end adaptation module is used to receive source code in multiple programming languages, generate corresponding native abstract syntax trees using a front-end parser configured with the declarative mapping framework DSMF, and convert the native abstract syntax tree AST into the initial nodes and edges of the unified structured semantic graph SSG according to predefined mapping rules. The Unified Type Engine module is used to receive type information from multiple programming languages, use the Multilingual Unified Type System (MLUTS) to map the type information into a unified five-tuple semantic vector, and annotate the semantic vector as an attribute to the corresponding node of the Structured Semantic Graph (SSG) to achieve semantic alignment across language types. The quintuple semantic vector explicitly describes the basic data type, ownership semantics, lifecycle constraints, memory layout characteristics, and concurrency state. The cross-language linking module is used to identify the external function interface (FFI) call points and definition points in the source program, calculate the memory layout fingerprint of the data structure according to the application binary interface (ABI) specification of the target runtime environment, construct the FFI descriptor, and generate bridge edges in SSG that connect subgraphs of different languages. The core module for graph construction is used to build control flow edges, data flow edges, and call edges on the basis of the initial nodes and bridging edges of the structured semantic graph (SSG), forming a complete program structure model that includes the physical layer, logical layer, and semantic layer.

9. The unified modeling system for multilingual program structure based on semantic preservation according to claim 8, characterized in that: The unified type engine module incorporates the MLUTS algorithm, which includes a semantic dimensionality reducer for: Map Java / Go garbage-collected objects to "externally managed" or "shared" ownership states; Map Rust / C++ smart pointers to "exclusive" or "shared" ownership states while preserving their destructor semantics; Ensure that languages ​​with different memory management models have comparable semantic representations in SSG.

10. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that, When the processor loads and executes the computer program, it employs the semantically preserved unified modeling method for multilingual program structures as described in any one of claims 1 to 7.