Code processing method and related device
By constructing a language transfer knowledge base and a self-evolving learning code processing method, the memory management and security issues of system-level programming languages are solved, the code translation quality and efficiency of migrating from traditional programming languages to modern programming languages are improved, and the migration cost is reduced.
Patent Information
- Application Number
- PCT/CN2025/139305
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-05-07
- Filing Date
- 2025-12-02
- Publication Date
- 2026-11-12
AI Technical Summary
Existing system-level programming languages such as C/C++ have deficiencies in memory management and security, leading to numerous memory safety issues. Furthermore, the migration process from traditional programming languages to modern programming languages is costly and time-consuming, and existing automated code translation tools struggle to guarantee the quality and efficiency of code generation.
By constructing a language transfer knowledge base and utilizing a self-evolutionary learning mechanism to form a closed-loop error analysis and knowledge extraction mechanism, we can retrieve and apply translation knowledge to enhance the code translation capabilities of the language model, identify and avoid translation pitfalls such as grammatical errors and semantic biases, and improve the quality and efficiency of code translation.
Effectively identify and avoid translation pitfalls, improve code translation quality and efficiency, reduce migration costs, and ensure the accuracy and security of generated code.
Smart Images

Figure CN2025139305_12112026_PF_FP_ABST
Abstract
Description
A code processing method and related equipment
[0001] This application claims priority to Chinese Patent Application No. 202510585896.2, filed with the State Intellectual Property Office of China on May 7, 2025, entitled "A Code Processing Method and Related Equipment", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of artificial intelligence (AI) technology, and in particular to a code processing method, a code processing system, a computing device cluster, a computer-readable storage medium, and a computer program product. Background Technology
[0003] Programming languages, as core tools in software development, play a crucial role in various fields. System-level programming languages (such as C and C++) have long dominated operating systems, embedded development, and high-performance computing, widely adopted due to their efficiency and flexibility. However, these system-level programming languages have inherent flaws in memory management and security. For example, manual memory management mechanisms (such as pointer manipulation and buffer overflows) lead to numerous memory safety issues. Statistics show that approximately 70% of serious software vulnerabilities (such as Heartbleed and Shellshock) originate from memory errors in C / C++. As software complexity increases, static analysis and dynamic detection methods struggle to completely eliminate these flaws.
[0004] To address the shortcomings of system-level programming languages in areas such as memory management and security, some programming languages (such as Rust, Go, and Kotlin) have introduced stricter security mechanisms and abstraction models, significantly improving development efficiency and code quality. Taking Rust as an example, its ownership model, borrow checker, and zero-cost abstraction not only guarantee high performance but also fundamentally avoid common security issues such as null pointer exceptions and data races, making it an ideal alternative to system-level programming languages. In recent years, many critical projects such as operating system kernels and operating system drivers have gradually adopted Rust for refactoring, demonstrating the value of modern programming languages like Rust in practical applications.
[0005] However, the migration process from traditional system-level programming languages (such as C and C++) to modern programming languages (such as Rust and Go) faces significant challenges, especially for large systems, where manual migration is costly and time-consuming. This has prompted academia and industry to actively explore automated code translation tools to lower the migration barrier and improve efficiency.
[0006] Mainstream code translation methods rely on large language models (LLMs), which can be combined with retrieval-augmented generation (RAG) techniques to improve translation quality. Specifically, these methods assist the large model in generating target code by retrieving similar code snippets. However, the large model typically mechanically imitates the retrieved similar code snippets, resulting in poor code generation quality that fails to meet business requirements. Summary of the Invention
[0007] This application provides a code processing method that retrieves translation knowledge corresponding to source language code fragments from a language transfer knowledge base. This translation knowledge is then used to enhance the code conversion or translation capabilities of a language model, rather than mechanically imitating similar code fragments. This method effectively identifies and avoids translation pitfalls such as syntax errors, semantic deviations, and type mismatches, thereby improving the quality and efficiency of code translation or conversion. This application also provides a code processing system, a computing device cluster, a computer-readable storage medium, and a computer program product.
[0008] Firstly, this application provides a code processing method. This method can be applied to a code processing system. The code processing system can be a tool that implements code conversion functionality, also known as a code conversion tool. The code processing system can include a software system, which can be an independent software system or a plugin, component, functional module, or mini-program integrated into other software systems. For example, the code processing system can be integrated into various IDEs as an integrated development environment (IDE) plugin, providing developers with real-time code translation suggestions. Alternatively, the code processing system can also be a cloud service, providing services externally through an application programming interface (API). The code processing system can also include a hardware system, such as a cluster of computing devices with code conversion or translation capabilities, which executes the code processing method of this application during runtime.
[0009] Specifically, the code processing system receives source language code snippets to be converted from user input. It then retrieves translation knowledge from a language transfer knowledge base based on the source language code snippets to obtain the corresponding translation knowledge. This translation knowledge includes translation rules for converting the source language code snippets into target language code snippets. These rules can be learned by studying historically generated erroneous code snippets from the language model and their corresponding correct code snippets. The code processing system then inputs the source language code snippets and translation knowledge into the language model for inference, generating the target language code snippets and returning them to the user.
[0010] This method retrieves translation knowledge corresponding to source language code fragments from a language transfer knowledge base. This translation knowledge is then used to enhance the code conversion or translation capabilities of the language model, rather than mechanically imitating similar code fragments. This effectively identifies and avoids translation pitfalls such as syntax errors, semantic deviations, and type mismatches, thereby improving the quality and efficiency of code translation or conversion.
[0011] In some possible implementations, the code processing system can perform difference analysis on erroneous and correct code snippets to obtain the discrepancies. The system can then construct multi-dimensional prompts based on these discrepancies, with dimensions including any combination of pointer safety casting, ownership mapping, or interface semantic alignment. The system can then input these prompts into the language model for analysis, generating translation rules.
[0012] This method constructs a closed-loop error analysis and knowledge extraction mechanism through self-evolutionary learning, forming a language transfer knowledge base, which lays the foundation for subsequent code translation or code conversion capabilities based on translation knowledge and language models.
[0013] In some possible implementations, the code processing system can locate the difference region based on the syntax tree nodes of the erroneous code fragment and the correct code fragment. The system can then identify the insertion, deletion, or replacement nodes within this difference region to obtain the difference code fragment. The difference code fragment includes the code block containing the insertion, deletion, or replacement node.
[0014] This method uses syntax tree nodes to locate the difference regions, and then identifies the difference code fragments based on the insertion, deletion or replacement nodes in the difference regions, which has high accuracy.
[0015] In some possible implementations, the code processing system can generate a set of base blocks with type annotations based on erroneous and correct code snippets. The base blocks in the set include the smallest execution unit within either the erroneous or correct code snippets. The code processing system can then construct graph structures for the erroneous and correct code snippets based on the set of base blocks. These graph structures can include at least one of a control flow graph or a data dependency graph. The code processing system can compare the topologies of the graph structures to obtain the differing code snippets. These differing code snippets include the code blocks containing differing nodes or edges in the graph structures.
[0016] This method is well-suited for inter-process analysis and concurrent code scenarios, capable of capturing implicit control flow changes and data race patterns that are difficult to detect through syntax tree comparison. The difference results are output as code ranges combined with data flow labels, indicating the set of variables affected by the changes and the potential level of data race risk.
[0017] In some possible implementations, the code processing system can generate source language example code snippets and target language example code snippets corresponding to translation rules through a language model. The translation knowledge includes translation rules as well as source language example code snippets and target language example code snippets.
[0018] This method also supports generating example code snippets corresponding to translation rules, providing richer information for subsequent code translation or conversion.
[0019] In some possible implementations, the code processing system can also locate the source language code block corresponding to the differing code fragment, and then perform parameterization processing on the source language code block to obtain source language features. The source language features include a semi-structured code template obtained by replacing it with typed placeholders, and the translation knowledge includes the source language features and translation rules.
[0020] This method can abstract the source language code blocks by parameterizing the source language code blocks corresponding to the differing code fragments, thereby improving the accuracy of subsequent retrieval.
[0021] In some possible implementations, the code processing system can also receive feedback from users on target language code snippets, including corrections to the target language code snippets, and then iteratively update the translation knowledge based on the feedback.
[0022] In this method, when translation errors occur, the code processing system provides error analysis and correction capabilities. It can deeply understand and analyze errors through language models and iteratively update translation knowledge to provide targeted improvement strategies. For example, it can provide automated correction strategies for different types of errors (ownership misuse, lifecycle errors, type mismatches, etc.), avoiding the recurrence of error patterns, improving correction efficiency, and ensuring translation quality and usability. Furthermore, by continuously iteratively updating translation knowledge, it can adapt to a wider range of code conversion needs and prevent the continuous accumulation of error patterns, ensuring the long-term stability and accuracy of the system.
[0023] In some possible implementations, the translation knowledge includes source language features and the translation rules. The code processing system can parameterize source language code blocks within a source language code fragment to obtain source language features. These source language features include semi-structured code templates obtained by replacing typed placeholders. The code processing system can also retrieve translation knowledge from a language transfer knowledge base based on the source language features to obtain translation knowledge corresponding to the source language code fragment.
[0024] This method improves retrieval efficiency and accuracy by employing semi-structured source language features to retrieve a language transfer knowledge base.
[0025] In some possible implementations, the code processing system can input source language code snippets into a retrieval model to obtain the translated knowledge corresponding to the source language code snippets. The retrieval model is trained on a dual-tower neural network model using a dataset containing multiple sample data points. Each sample data point includes a source code example and a corresponding translated knowledge example.
[0026] In this method, the trained retrieval model can map new source code to the translated knowledge vector space in real time, and quickly find the most relevant translated knowledge through approximate nearest neighbor search. This method is particularly suitable for processing large-scale code bases, and the retrieval performance can be continuously optimized through continuous learning.
[0027] In some possible implementations, the code processing system can perform zero-shot or few-shot learning on the source language code fragment using a language model to obtain a first semantic representation. The code processing system can then perform zero-shot or few-shot learning on the translated knowledge in the language transfer knowledge base using the language model to obtain a second semantic representation. The code processing system then matches the first and second semantic representations to obtain the translated knowledge corresponding to the source language code fragment. And / or, the code processing system can generate a summary of the source language code fragment and, based on at least one of the algorithmic logic or data structures in the summary, perform information retrieval from the language transfer knowledge base to obtain the translated knowledge corresponding to the source language code fragment.
[0028] This method supports directly converting source code or natural language queries into a unified semantic representation for matching and retrieval, or using summaries for information retrieval, without the need for additional training of a dedicated retrieval model. Retrieval methods based on zero-shot learning, few-shot learning, or summarization can be used in combination or individually. Using them in combination leverages the powerful semantic understanding capabilities of language models while reducing retrieval complexity through code summarization.
[0029] Secondly, this application provides a code processing system. The system includes:
[0030] The translation module is used to receive source language code fragments to be converted by user input; retrieve language transfer knowledge base based on the source language code fragments to obtain translation knowledge corresponding to the source language code fragments, the translation knowledge including translation rules for converting the source language code fragments into target language code fragments, the translation rules being obtained by learning from erroneous code fragments generated in the history of the language model and the correct code fragments corresponding to the erroneous code fragments;
[0031] The translation module is further configured to input the source language code fragment and the translation knowledge into the language model for reasoning, generate the target language code fragment, and return the target language code fragment to the user.
[0032] In some possible implementations, the system further includes:
[0033] The difference analysis module is used to perform difference analysis on the erroneous code fragment and the correct code fragment to obtain the difference code fragment;
[0034] The knowledge generation module is used to construct multi-dimensional prompts based on the difference code fragments, wherein the multi-dimensional prompts include any combination of pointer safe conversion, ownership mapping, or interface semantic alignment; the prompts are input into the language model for analysis to generate the translation rules.
[0035] In some possible implementations, the difference analysis module is specifically used for:
[0036] The difference region is located based on the syntax tree nodes of the erroneous code fragment and the syntax tree nodes of the correct code fragment;
[0037] Identify the inserted node, deleted node, or replaced node in the difference region to obtain a difference code fragment, the difference code fragment including the code block where the inserted node, deleted node, or replaced node is located.
[0038] In some possible implementations, the difference analysis module is specifically used for:
[0039] A set of base blocks with type annotations is generated based on the erroneous code snippet and the correct code snippet, wherein the base blocks in the set of base blocks include the smallest execution unit in the erroneous code snippet or the correct code snippet;
[0040] Graph structures are constructed for the erroneous code fragment and the correct code fragment based on the set of base blocks, and the graph structures include at least one of control flow graphs or data dependency graphs.
[0041] By comparing the topology of the graph structure, a difference code fragment is obtained, which includes the code block containing the difference node or difference edge in the graph structure.
[0042] In some possible implementations, the knowledge generation module is also used for:
[0043] The language model generates source language example code snippets and target language example code snippets corresponding to the translation rules. The translation knowledge includes the translation rules, the source language example code snippets, and the target language example code snippets.
[0044] In some possible implementations, the knowledge generation module is also used for:
[0045] Locate the source language code block corresponding to the differing code fragment;
[0046] The source language code block is parameterized to obtain source language features, which include a semi-structured code template obtained by replacing it with typed placeholders. The translation knowledge includes the source language features and the translation rules.
[0047] In some possible implementations, the system further includes:
[0048] The knowledge update module is used to receive feedback information from the user regarding the target language code fragment, the feedback information including correction information for the target language code fragment; and to iteratively update the translation knowledge based on the feedback information.
[0049] In some possible implementations, the translation knowledge includes source language features and the translation rules, and the translation module is specifically used for:
[0050] The source language code blocks in the source language code fragment are parameterized to obtain the source language features, which include a semi-structured code template obtained by replacing typed placeholders.
[0051] Based on the source language features, a language transfer knowledge base is retrieved to obtain translation knowledge corresponding to the source language code fragment.
[0052] In some possible implementations, the translation module is specifically used for:
[0053] The source language code fragment is input into the retrieval model to obtain the translation knowledge corresponding to the source language code fragment. The retrieval model is obtained by training a dual-tower neural network model using a dataset. The dataset includes multiple sample data, and each sample data includes a source code example and a translation knowledge example corresponding to the source code example.
[0054] In some possible implementations, the translation module is specifically used for:
[0055] The language model is used to perform zero-shot or few-shot learning on the source language code fragment to obtain a first semantic representation, and the language model is used to perform zero-shot or few-shot learning on the translation knowledge in the language transfer knowledge base to obtain a second semantic representation. The first semantic representation and the second semantic representation are matched to obtain the translation knowledge corresponding to the source language code fragment; and / or,
[0056] A summary of the source language code fragment is generated, and information is retrieved from the language transfer knowledge base based on at least one of the algorithmic logic or data structures in the summary to obtain the translation knowledge corresponding to the source language code fragment.
[0057] Thirdly, this application provides a computing device cluster. The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is used to execute instructions stored in the at least one memory to cause the computing device or the computing device cluster to perform the code processing method as described in the first aspect or any implementation thereof.
[0058] Fourthly, this application provides a computer-readable storage medium storing instructions that instruct a computing device or a cluster of computing devices to execute the code processing method described in the first aspect or any implementation thereof.
[0059] Fifthly, this application provides a computer program product containing instructions that, when run on a computing device or a cluster of computing devices, causes the computing device or cluster of computing devices to execute the code processing method described in the first aspect or any implementation thereof.
[0060] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0061] To more clearly illustrate the technical methods of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly described below.
[0062] Figure 1 is a schematic diagram of the architecture of a code processing system provided in this application;
[0063] Figure 2 is a flowchart of a code processing method provided in this application;
[0064] Figure 3 is a flowchart of a translated knowledge generation method provided in this application;
[0065] Figure 4 is a schematic diagram of a prompt provided in this application;
[0066] Figure 5 is a schematic diagram of the structure of a computing device provided in this application;
[0067] Figure 6 is a schematic diagram of the structure of a computing device cluster provided in this application;
[0068] Figure 7 is a schematic diagram of the structure of a computing device cluster provided in this application;
[0069] Figure 8 is a schematic diagram of another computing device cluster provided in this application. Detailed Implementation
[0070] The terms "first" and "second" used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first" and "second" may explicitly or implicitly include one or more of that feature.
[0071] First, some technical terms involved in the embodiments of this application will be introduced.
[0072] A language model (LM) is a probability distribution model of words in a natural language. The most common data in natural language processing is text data, such as a piece of natural language text, which can be viewed as a discrete time series. Assuming a natural language text of length T contains words w1, w2, ..., wT, then in the discrete time series, wt (1 ≤ t ≤ T) can be seen as the output or label at time step t. Given a word sequence w1, w2, ..., wT of length T, the language model calculates the probability of that word sequence: P(w1, w2, ..., wT). Based on this, the language model can predict the next most likely word using the input context (e.g., several preceding words).
[0073] Language models can also be categorized by parameter size into small language models and large language models (LLMs). For ease of description, this application uses LLMs as an example. A large language model is essentially a language model composed of artificial neural networks with many parameters (typically billions of weights or more), trained on a large amount of unlabeled text using self-supervised or semi-supervised learning. Depending on the model architecture, large language models can be divided into different types. Widely used large language models in code generation include generative pre-trained transformers (GPTs).
[0074] With the continuous iteration and updating of language models, especially the evolution of large language models, language models have also begun to be applied to programming language processing. A programming language, also known as a programming design language, is a formal language used to define computer programs. Programming languages issue instructions to computing devices such as computers, enabling the devices to execute these instructions, thereby acquiring necessary data and performing appropriate actions. Programming languages can include system-level programming languages used for operating systems, embedded development, or high-performance computing, including but not limited to C or C++. These system-level programming languages are widely used due to their efficiency and flexibility. However, these languages have significant shortcomings in memory management and security. For example, manual memory management mechanisms such as pointer operations and buffer overflows in C language lead to numerous memory safety issues. Statistics show that approximately 70% of serious software vulnerabilities originate from memory errors in system-level programming languages such as C / C++. With increasing software complexity, traditional static analysis and dynamic detection methods are insufficient to completely eliminate these vulnerabilities.
[0075] To address issues such as memory safety, the industry has introduced new programming languages, including but not limited to modern languages like Rust, Go, and Kotlin. Modern programming languages, exemplified by Rust, have significantly improved development efficiency and code quality by introducing stricter safety mechanisms and abstraction models. For instance, Rust's safety mechanism can be based on an ownership model, ensuring memory safety without requiring garbage collection. Specifically, each value in Rust has an owner variable, and a value can only have one owner at a time. When the owner goes out of scope, the value is discarded, and the memory is released accordingly. Rust also supports abstraction models such as structs, enums, and traits, providing powerful abstraction capabilities while ensuring memory safety, enabling developers to write efficient and reliable code.
[0076] For code with memory management or security flaws, such as operating system kernels, browsers, and operating system driver code developed in C or C++, migration can be achieved through code conversion or code translation. Code conversion refers to the process of automatically or semi-automatically translating source code written in one programming language into another. The goal of code conversion is to achieve semantic equivalence between different programming languages, enabling the translated code to run correctly and perform the same tasks in the target language environment.
[0077] Automatic or semi-automatic code translation can be achieved using an LLM (Local Management Model). Furthermore, LLM can be combined with Retrieval-Augmented Generation (RAG) technology to improve conversion or translation quality. Let's take translating code from C++ to Rust as an example. First, a knowledge base containing C++-Rust code pairs is built, and high-quality examples are filtered through similarity matching. During the translation process, the RAG module retrieves the most similar C++ code and its Rust implementation from the knowledge base, providing this context to the LLM to generate code that better conforms to Rust syntax and style.
[0078] However, in LLM combined with RAG solutions, LLM typically mechanically mimics the retrieved similar code snippets. The quality of code retrieval is limited by the performance of similarity measurement methods or embedding models such as Code Bilingual Evaluation Understudy (CodeBLEU), making it difficult to accurately identify semantic features and translation patterns in the code. This may result in retrieving suboptimal code snippets or even code snippets containing potential errors, severely impacting the final translation results. Furthermore, the aforementioned solutions cannot perform in-depth diagnosis and analysis of errors occurring during the conversion process, leading to poor code generation quality that fails to meet business requirements.
[0079] In view of this, this application provides a code processing method. This method may include a code translation enhancement method based on self-evolutionary learning. The core of this method lies in constructing a closed-loop error analysis and knowledge extraction mechanism to form a language transfer knowledge base. Thus, during code translation or conversion, the language transfer knowledge base can be retrieved to obtain corresponding translation knowledge. By combining this translation knowledge with code translation or conversion, the accuracy of the translation results is improved, thereby enhancing the quality of the converted or generated code.
[0080] The code processing method described in this application can be applied to software migration scenarios, assisting developers in improving code conversion or translation efficiency. This code processing method can be executed by a code processing system. The code processing system can be a tool that implements code conversion functionality, also known as a code conversion tool.
[0081] The code processing system may include a software system, which can be a standalone software system or a plugin, component, functional module, or mini-program integrated into other software systems. The code processing system may also include a hardware system, such as a cluster of computing devices with code processing capabilities such as code conversion or translation, which executes the code processing method of this application during runtime. For ease of description, the following example illustrates a code processing system including a software system.
[0082] For example, a code processing system can function as an integrated development environment (IDE) plugin, integrating into various IDEs to provide developers with real-time code translation suggestions. In this scenario, developers can directly select the source language code snippets to be translated within the IDE, and the code processing system generates corresponding code conversion suggestions based on the input source language code snippets, helping developers complete code migration more quickly. Code processing systems can also emerge as features or functionalities of code editors, code conversion plugins based on large language models, or development environments, appearing with each version update. The code editor can include client-side code editors or cloud-based code editors.
[0083] For example, the code processing system can also be offered as a cloud service via an application programming interface (API). Correspondingly, other tools or services can use the code conversion functionality of this application by calling the API. In this scenario, developers can write code on local or remote servers and obtain generated code conversion suggestions by calling the API provided by this application, thereby improving the efficiency of code migration. Since the core technology of this application is independent of specific code translation models, the capabilities of the code processing system can be integrated with various tools to form a unified whole, thereby enhancing the user experience of code conversion.
[0084] In practice, the code processing system receives source language code snippets to be converted from user input. It then retrieves translation knowledge from a language transfer knowledge base based on these source language code snippets to obtain the corresponding translation knowledge. This translation knowledge includes translation rules for converting the source language code snippets into target language code snippets. These rules are learned by studying historically generated erroneous code snippets from the language model and their corresponding correct code snippets. The code processing system then inputs the source language code snippets and translation knowledge into the language model for inference, generating the target language code snippets and returning them to the user.
[0085] This method retrieves translation knowledge corresponding to source language code fragments from a language transfer knowledge base. This translation knowledge is then used to enhance the code conversion or translation capabilities of the language model, rather than mechanically imitating similar code fragments. This effectively identifies and avoids translation pitfalls such as syntax errors, semantic deviations, and type mismatches, thereby improving the quality and efficiency of code translation or conversion.
[0086] To make the technical solution of this application clearer and easier to understand, the system architecture of the code processing system of this application is described below with reference to the accompanying drawings.
[0087] Referring to Figure 1, which shows a schematic diagram of the architecture of a code processing system, the code processing system 10 includes a code conversion subsystem 100 and a knowledge management subsystem 200.
[0088] The code conversion subsystem 100 may include a translation module 102, and may further include a code analysis module 104, a testing module 106, and an error correction module 108.
[0089] The translation module 102 receives source language code fragments to be converted from user input. These source language code fragments can be code snippets from a source program. The module then retrieves knowledge from a language transfer knowledge base based on the source language code fragments to obtain the corresponding knowledge. This translation knowledge includes translation rules for converting the source language code fragments into target language code fragments. These translation rules are learned by studying historically generated erroneous code fragments from the language model and their corresponding correct code fragments.
[0090] The translation module 102 is also used to input the source language code fragment and the translated knowledge into a language model (e.g., an LLM) for inference, generate a target language code fragment, and return the target language code fragment to the user. The target language code fragment generated by the language model inference can be considered an initial version of the target language code fragment, which can be compiled and tested. If compilation and testing pass, it indicates that the initial version of the target language code fragment is a correct code fragment. If compilation or testing fails, error correction can be performed to obtain the correct code fragment. The compilation, testing, and correction processes are described below.
[0091] The code analysis module 104 is used to analyze target language code fragments and obtain analysis results. Specifically, the code analysis module 104 can perform static or dynamic analysis on the target language code fragments to obtain analysis results. Static analysis, also known as static program analysis or static code analysis, refers to the method of program analysis without running the program. Specifically, static analysis of target language code fragments can involve syntax analysis or behavioral analysis to identify abnormal syntax structures or undefined behaviors caused by erroneous encoding. In some examples, the code analysis module 104 is used to perform static analysis on target language code fragments using a compiler to obtain analysis results. Dynamic analysis, also known as dynamic program analysis or dynamic code analysis, refers to the method of program analysis while the program is running. Dynamic analysis mainly analyzes the behavior and performance of the code by monitoring the program's running state, changes in variables, and memory usage. Dynamic analysis can discover runtime problems such as memory leaks and deadlocks.
[0092] Test module 106 is used to test target language code snippets and obtain test results. The testing methods may include, but are not limited to, unit testing, integration testing, and system testing. Unit testing refers to testing the smallest testable unit in the program. The smallest testable unit includes, but is not limited to, functions and class methods. Integration testing combines multiple units for testing, checking whether the interfaces and interactions between units are normal. System testing tests the entire system (such as the program) as a whole, verifying whether the system meets the specified requirements and performance indicators.
[0093] The error repair module 108 is used to repair errors in the target language code segment when errors are detected. The error repair method can include language model-based error repair. Specifically, the error repair module 108 constructs a prompt based on the error information (such as error code, error description, and error location) of the target language code segment and inputs the prompt into the language model for repair. For example, if the code analysis module 104 detects a syntax error in the target language code segment, the error repair module 108 can repair the syntax error using an LLM (Language Modeling). Similarly, if the testing module 106 detects a semantic error in the target language code segment, the error repair module 108 can repair the semantic error using an LLM.
[0094] By inspecting and analyzing the target language code snippets, it can be ensured that the generated target language code snippets maintain semantic equivalence with the original source language code snippets in key characteristics (such as memory safety and concurrency behavior). Especially when dealing with target language-specific mechanisms (such as Rust's ownership model and lifecycle management), specialized checks can reduce superficially correct but actually security-hazardous conversion results. This semantic-level assurance allows the automated conversion results to be directly applied to the production environment, reducing additional manual review and correction work, and improving overall development efficiency and product quality.
[0095] It should be noted that the error repair module 108 can record the number of repair attempts. When the number of repair attempts reaches a preset threshold, the repair process can be stopped, and the error analysis process can begin. Through error analysis, summarization and reflection can be performed to generate potential translation rules for subsequent code translation or conversion. A detailed explanation follows.
[0096] The knowledge management subsystem 200 includes a difference analysis module 202 and a knowledge generation module 204. The difference analysis module 202 performs difference analysis on erroneous and correct code snippets to obtain the difference code snippets. The knowledge generation module 206 constructs multi-dimensional prompts based on the difference code snippets. These multi-dimensional prompts can include any combination of pointer safety conversion, ownership mapping, or interface semantic alignment. The prompts are then input into a language model for analysis to generate translation rules.
[0097] The error code snippet can be a target language code snippet that failed to be repaired. The correct code snippet can be a target language code snippet that was successfully repaired, such as a manually repaired target language code snippet. The error code snippet, the correct code snippet, and the source language code snippet can form an error triple, denoted as <source language code snippet, error code snippet, correct code snippet>. The error triple can be provided to the difference analysis module 202, which can extract the difference code snippet from the error triple through static analysis. Furthermore, the difference analysis module 202 can also extract the context. The knowledge generation module 204 can input the extracted difference code snippets into the language model for feature induction and reflection, and summarize potential translation rules. The knowledge generation module 204 can also input the context into the language model to assist the language model in generating translation rules. An example of a translation rule could be "If there is a memmove call in the source language code snippet, the target language code snippet should use slice.copy_within and ensure that the element type implements the Copy trait."
[0098] Furthermore, the knowledge generation module 204 is also used to generate source language example code snippets and target language example code snippets corresponding to the translation rules through a language model. The translation knowledge includes the translation rules, source language example code snippets, and target language example code snippets. The knowledge generation module 204 is also used to locate the source language code block corresponding to the difference code snippet, perform parameterization processing on the source language code block, and obtain source language features. The source language features include a semi-structured code template obtained by replacing typed placeholders, and the translation knowledge includes the source language features and translation rules. In some possible implementations, the translation knowledge may include source language features, difference code snippets, translation rules, and example code. The example code may include the aforementioned source language example code snippets and target language example code snippets. The translation knowledge can be represented using a quadruple, for example, <source language features, difference code snippets, translation rules, example code>. This quadruple can also be called a key insight quadruple.
[0099] In some possible implementations, the knowledge generation module 204 can also display translated knowledge to the user, such as the aforementioned four-tuple of insights, allowing the user to decide whether to include the translated knowledge in the language transfer knowledge base (or translation insights library), thus ensuring the quality and usability of the translated knowledge (such as insights). This application addresses the problem of scarce and unevenly qualityed parallel corpora in language model training by generating or updating translated knowledge based on error code snippets, rather than using it for training language models. This is achieved by generating refined and diverse transfer rules.
[0100] Furthermore, the knowledge management subsystem 200 may also include a knowledge update module. This module receives user feedback on target language code snippets, including corrections; it then iteratively updates the translation knowledge based on this feedback. This ensures enhanced retrieval performance, maintains translation quality even when dealing with marginal cases, exhibits good stability, and can adapt to diverse translation needs. It should be noted that the above knowledge update process can refer to the knowledge generation process; the functionality of the knowledge update module can also be implemented by the knowledge generation module 204, and this application does not impose any limitations on this.
[0101] In subsequent code translation tasks, the code conversion subsystem 100 extracts source language features from the input source language code fragments through static analysis and retrieves relevant insight lists from the translation insights library. The retrieved relevant insights can be dynamically embedded into the Prompt, thereby enhancing the translation capabilities of the language model and improving the accuracy and adaptability of the generated code (such as target language code fragments).
[0102] Based on the code processing system 10 shown in Figure 1, this application also provides a code processing method. The code processing method of this application will be described in detail below with reference to the accompanying drawings.
[0103] Referring to the flowchart of a code processing method shown in Figure 2, the method may include the following steps:
[0104] S202, the code processing system 10 receives the source language code fragment to be converted from user input.
[0105] Specifically, the code processing system 10 can display a source language code file to the user, who can then select a source language code snippet to be converted from the file. In response to the user's selection, the code processing system 10 determines the source language code snippet to be converted. The source language code snippet may include, but is not limited to, code snippets of functions or class methods from the source language code file.
[0106] Alternatively, the code processing system 10 can display a code editing interface to the user, receiving source language code snippets input by the user through the interface. The user can input source language code snippets via copy operation.
[0107] S204. The code processing system 10 retrieves the language transfer knowledge base based on the source language code fragment to obtain the translation knowledge corresponding to the source language code fragment.
[0108] The translation knowledge includes translation rules for converting source language code snippets into target language code snippets. These rules are learned by studying historically generated erroneous code snippets from the language model and their corresponding correct code snippets. For ease of understanding, this application also provides an example of a translation rule. For instance, a translation rule could be: "If a memmove call exists in the source language code snippet, the target language code snippet should use slice.copy_within and ensure that the element type implements the Copy trait."
[0109] Furthermore, the translated knowledge may also include at least one of the following: source language features, difference code snippets, and example code. The example code may include source language example code snippets and target language example code snippets generated by the language model that correspond to the translation rules. In some examples, the above translated knowledge can be represented as an insight quadruple, such as <source language features, difference code snippets, translation rules, example code>.
[0110] This application provides multiple search methods for retrieving translated knowledge. These are described below.
[0111] The first implementation method is a retrieval method based on source language features. Specifically, the code processing system 10 performs parameterization processing on the source language code blocks in the source language code fragment to obtain source language features. These source language features include a semi-structured code template obtained by replacing typed placeholders. Then, the code processing system 10 can retrieve the language transfer knowledge base based on the source language features to obtain the translation knowledge corresponding to the source language code fragment. This parameterization processing allows for the abstraction of the source language code fragment, and the source language features obtained through this abstraction can improve retrieval efficiency and accuracy.
[0112] The code processing system 10 can use a source language static analysis tool to parse the input source language code fragment into an Abstract Syntax Tree (AST) representation. Then, the code processing system 10 can divide the code structure according to function boundaries and logical blocks, generating independent processing units. Each independent processing unit can be a source language code block within the source language code fragment. The code processing system 10 can perform parameterization processing on the independent processing units, such as replacing the specific implementation details in the independent processing unit with typed placeholders, preserving the core code structure, and obtaining a semi-structured code template. This semi-structured code template can be used as a retrieval feature. The process of retrieval based on retrieval features is described below.
[0113] Specifically, the code processing system 10 can vectorize the retrieved features (text) and then perform a K-Nearest Neighbor (KNN) search on the language transfer knowledge base to obtain a preliminary candidate set. The language transfer knowledge base may include a Faiss-based translation insights library. The preliminary candidate set may include translation knowledge ranked k in descending order of similarity scores. k can be set empirically. In some examples, k = 10.
[0114] The second implementation method is to retrieve translated knowledge from the source language based on a retrieval model. Specifically, the code processing system 10 can train an embedding model specifically for retrieval as the retrieval model. This retrieval model can retrieve translated knowledge based on source language code fragments without extracting source language features. Specifically, the code processing system 10 can input source language code fragments into the retrieval model to obtain the translated knowledge corresponding to the source language code fragments. The retrieval model is trained using a dataset on a dual-tower neural network model. The dataset includes multiple sample data, each including source code examples and corresponding translated knowledge examples. The training process of the retrieval model is described below.
[0115] When training the retrieval model, a dataset including a large number of source code examples and corresponding translated knowledge examples can be constructed first. The translated knowledge examples can include insight descriptions corresponding to the source code examples. Then, the code processing system 10 can input samples from the dataset into a dual-tower neural network model. One tower of the dual-tower neural network model processes the source code examples in the samples, while the other tower processes the translated knowledge examples, such as natural language descriptions. The dual-tower neural network model uses contrastive learning to bring semantically related code and translated knowledge (such as insights) closer together in the embedding space, ultimately generating a joint embedding representation. The trained dual-tower neural network model can then serve as a retrieval model, capable of mapping new source language code fragments to the insight vector space in real time and quickly finding the most relevant insight through nearest neighbor search. This method is particularly suitable for processing large-scale codebases and can continuously optimize retrieval performance through ongoing learning.
[0116] The third implementation method is to perform retrieval based on the zero-shot or few-shot learning capabilities of language models (such as LLM). Specifically, the code processing system 10 can perform zero-shot or few-shot learning on the source language code fragment using a language model to obtain a first semantic representation, and perform zero-shot or few-shot learning on the translated knowledge in the language transfer knowledge base using a language model to obtain a second semantic representation. The first semantic representation and the second semantic representation are then matched to obtain the translated knowledge corresponding to the source language code fragment. In this way, the translated knowledge of the source language code fragment or natural language description can be directly converted into a unified semantic representation for matching and retrieval without the need to train a dedicated retrieval model.
[0117] The fourth implementation method is based on summary-based retrieval. Specifically, the code processing system 10 can generate a summary of the source language code fragment, and retrieve information from the language transfer knowledge base based on at least one of the algorithmic logic or data structures in the summary to obtain the translation knowledge corresponding to the source language code fragment. The code processing system 10 can automatically generate summaries using a code summary generation algorithm. Specifically, the code processing system 10 can extract core elements from the source language code fragment according to the summary generation algorithm, such as key algorithmic logic or data structures. Key algorithmic logic can be algorithmic logic ranked in the top m or above a threshold in terms of key scores, and key data structures can be data structures ranked in the top m or above a threshold in terms of key scores. In some examples, key algorithmic logic may include "using a two-pointer method to achieve interval merging," and key data structures may include "using a hash table to store intermediate results." The above core elements can form a natural language description, which can serve as a summary of the source language code fragment. The code processing system 10 can then retrieve information from the language transfer knowledge base based on this natural language description.
[0118] It should be noted that the above-mentioned implementation methods can be used individually or in combination. For example, retrieval based on zero-shot or few-shot learning capabilities of language models and summary-based retrieval can be combined. Specifically, the code processing system 10 can construct a cascaded retrieval system, first quickly filtering the candidate set through code summarization, and then performing fine ranking using LLM. This leverages the powerful semantic understanding capabilities of language models such as LLM while reducing retrieval complexity through code summarization.
[0119] S206, the code processing system 10 inputs the source language code fragments and translation knowledge into the language model for reasoning, and generates the target language code fragments.
[0120] Specifically, the code processing system 10 can embed the translated knowledge and source language code fragments into the prompt template to obtain a prompt. This prompt is then input into a language model such as LLM for inference, generating a target language code fragment. The target language code fragment generated by the language model inference can be considered an initial version of the target language code fragment. This initial version can be a correct code fragment or an incorrect code fragment.
[0121] In some possible implementations, the code processing system 10 can also compile or test the initial version. If the compilation and testing pass, it indicates that the initial version of the target language code snippet is a correct code snippet, and the code processing system 10 can execute S208. If the compilation or testing fails, the code processing system 10 can also perform error correction to obtain the correct code snippet.
[0122] Specifically, the code processing system 10 can invoke a compiler to analyze the target language code fragment, such as performing syntax analysis or behavioral analysis, to check for abnormal syntax structures or undefined behaviors caused by incorrect encoding in the target language code fragment and obtain analysis results. In some examples, the analysis results may include compilation errors in the target language code fragment, such as syntax errors, in which case compilation will fail. For compilation failures, the code processing system 10 can also perform code repair. For example, the code processing system 10 can construct a prompt based on the error information of the target language code fragment (such as error code, error description, and error location), and input the prompt into the language model for repair. The code processing system 10 can recompile the repaired target language code fragment; if compilation fails, repair can be performed again until compilation succeeds or the number of repair attempts reaches a threshold. In other examples, the analysis results may include successful compilation.
[0123] For a successfully compiled target language code snippet (which can be an initial version or a repaired version), the code processing system 10 can test the target language code snippet and obtain test results. The testing methods can include, but are not limited to, unit testing, integration testing, and system testing. Test results can include whether the test passed or failed. For a failed test, the test result can include error information. Error information can include, but is not limited to, error location and error type. For example, the error type can be a semantic error. The code processing system 10 can repair the erroneous target language code snippet using a language model. For example, the code processing system 10 can construct a prompt from the error information and the target language code snippet, and input the prompt into the language model for repair. Similarly, the code processing system 10 can test the repaired target language code snippet. If the test passes, subsequent steps can be executed; if the test fails, repair can continue until the test passes or the number of repair attempts reaches a threshold.
[0124] S208, the code processing system 10 returns a code snippet in the target language to the user.
[0125] Specifically, the code processing system 10 can display target language code snippets to the user, for example, through an interactive interface, or the code processing system 10 can return the target language code snippets to the user in the form of code files. The target language code snippets can be target code snippets generated by a language model, or repaired target language code snippets; this application does not impose any restrictions on this.
[0126] Based on the above description, this application provides a code processing method. For a source language code fragment to be converted, this method automatically retrieves translation knowledge related to the source language code fragment from a language transfer knowledge base. This translation knowledge is then used to enhance the translation or code conversion capabilities of the language model, generating an enhanced target language code fragment for user selection. Unlike related technologies that mechanically imitate similar code fragments, this method uses retrieved translation knowledge to guide the language model in generating the target language code fragment, improving the accuracy and efficiency of code conversion.
[0127] Furthermore, if the target language code snippet fails to compile or test, and the number of repair attempts reaches the repair attempt threshold but still fails, it indicates a translation or conversion failure. Data on translation failures can be recorded and included in an error translation dataset, driving the code processing system 10 to continuously learn and optimize its translation knowledge. Through this closed-loop mechanism, the code processing system 10 can continuously improve the accuracy and adaptability of its translations through iteration, thereby better addressing complex scenarios and diverse needs.
[0128] To facilitate understanding, the process of generating or iterating translated knowledge will be explained in detail below with reference to specific examples.
[0129] Referring to Figure 3, a flowchart of a translated knowledge generation process is shown, which specifically includes the following steps:
[0130] S302, the code processing system 10 performs a difference analysis on the erroneous code fragments and the correct code fragments to obtain the difference code fragments.
[0131] The erroneous code snippets can be target language code snippets generated historically by the language model that failed compilation or testing. The correct code snippets can be obtained by manually modifying the erroneous code snippets. It should be noted that correct code snippets can also be obtained through multisampling using the language model. The aforementioned erroneous and correct code snippets can constitute an error translation dataset, also known as a set of incorrect translation questions. The erroneous and correct code snippets, along with the source language code snippets, form the set of incorrect translation questions, where each sample can be represented as <source language code snippet, erroneous code snippet, correct code snippet>.
[0132] Considering that the number of target codes translated incorrectly by the language model is usually much higher than the number of target codes translated correctly, the code processing system 10 can also cluster the erroneous code fragments to obtain a set of similar errors. This set of similar errors can serve as a data source for insight reflection, which is beneficial for identifying high-frequency error patterns. Similarly, the code processing system 10 can also cluster the correct code fragments as a data source to enhance the stability of the language model's translation.
[0133] In practical implementation, the code processing system 10 can perform difference analysis on the erroneous code segments and their corresponding correct code segments in the wrong question set or similar wrong question set to obtain the difference code segments. This application provides multiple difference analysis methods. The different difference analysis methods are described below.
[0134] In some possible implementations, the code processing system 10 can locate the difference region based on the syntax tree nodes of the erroneous code segment and the correct code segment, and then identify the insertion node, deletion node, or replacement node in the difference region to obtain the difference code segment. The difference code segment includes the code block containing the insertion node, deletion node, or replacement node.
[0135] The above process can be divided into several stages, such as stage 1 and stage 2. Stage 1 mainly involves constructing a bimodal AST representation. Stage 2 involves difference detection and analysis.
[0136] In Phase 1, the code processing system 10 can use a parser (such as a Tree-Sitter) to process source language code fragments (source language code fragments corresponding to erroneous code fragments), generating a lightweight AST that preserves the complete surface syntax structure, recording the location information and code range of each syntax tree node. Then, the code processing system 10 can call the compiler frontend of the target language, such as the GCC / Clang frontend, the Java compiler, or the Python AST module, to convert the source language code fragments into intermediate representations, such as Low Level Virtual Machine Intermediate Representation (LLVM IR), Java bytecode, Python bytecode, etc., performing syntactic sugar expansion and macro processing. The syntactic sugar expansion process is usually completed automatically by the compiler, and developers generally do not need to perform it manually. Syntactic sugar allows developers to program using higher-level, more concise syntax, while the compiler converts it into low-level executable code. Next, the code processing system 10 can construct an enhanced AST containing complete semantic information based on the compiler AST (such as the AST corresponding to the intermediate representation). Each syntax tree node in the enhanced AST is labeled with its type derivation result, ownership relationship, and lifecycle parameters. The type inference result is used to indicate the node type of the syntax tree node, such as a variable or an operator. The code processing system 10 can generate fingerprints for the syntax tree nodes. For example, it can generate globally unique fingerprints based on the Secure Hash Algorithm (SHA) algorithm, and establish a one-to-one correspondence between the two types of syntax tree nodes based on the source code location information of the syntax tree nodes, thereby establishing a bidirectional mapping table between syntax nodes and semantic nodes.
[0137] In phase 2, the code processing system 10 can calculate hash values for lightweight syntax tree nodes, for example, calculating the hash value of XXH3 based on the fast hashing algorithm XXHash. Then, the code processing system 10 can use the Lowest Common Ancestor (LCA) algorithm to locate the difference region. It should be noted that LCA is only one implementation method for locating the difference region; in practical applications, other methods can also be used to locate the difference region, such as traversal. The code processing system 10 can apply the Minimum Edit Distance (TED) algorithm with pruning strategy within the difference region to accurately identify syntax tree nodes such as inserted, deleted, or replaced nodes, and obtain the difference code fragment based on these nodes. The difference code fragment can include the code block containing the inserted, deleted, or replaced node.
[0138] Furthermore, the code processing system 10 can also extract key feature nodes such as type and ownership from the enhanced AST, which includes complete semantic information, as differential code contexts, and combine them with predefined rules to fill in any missing matching cases.
[0139] In some possible implementations, the code processing system 10 can generate a set of type-labeled base blocks based on erroneous code snippets and correct code snippets. The base blocks in the set include the smallest unit of execution within either the erroneous or correct code snippet. The smallest unit of execution is typically indivisible. In some examples, the smallest unit of execution comprises a series of consecutive instructions, excluding jump instructions. The code processing system 10 can generate the set of type-labeled base blocks based on intermediate representations of the erroneous and correct code snippets. The code processing system 10 can construct graph structures for both the erroneous and correct code snippets based on the set of base blocks. The graph structures include at least one of a Control Flow Graph (CFG) or a Data Dependency Graph (DDG). The code processing system 10 can compare the topology of the graph structures to obtain differing code snippets. The differing code snippets include the code blocks containing differing nodes or edges in the graph structures.
[0140] The code processing system 10 can employ a graph isomorphism algorithm, such as the VF2 algorithm, to compare the topological structures of different graph structures and obtain different nodes and edges. Furthermore, the code processing system 10 can calculate the degree of difference through graph edit distance. If the degree of difference is greater than a set threshold, the code block containing the node and edge is marked as a difference code segment.
[0141] This approach is well-suited for inter-process analysis and concurrent code scenarios, capable of capturing implicit control flow changes and data race patterns that are difficult to detect with traditional AST comparisons. The difference results are output as code ranges combined with data flow labels, indicating the set of variables affected by the changes and the potential level of data race risk.
[0142] It should be noted that CFG or DDG are merely examples of graph structures in this application. In practical applications, the code processing system 10 can also use graph neural networks (GNNs) to extract the graph structure features of the code (such as the joint representation of control flow graph and data flow graph) to replace AST bimodal analysis and improve accuracy.
[0143] S304, the code processing system 10 constructs multi-dimensional prompts based on the differences in code fragments.
[0144] The multi-dimensional approach includes any combination of pointer-safe conversion, ownership mapping, or interface semantic alignment. The code processing system 10 takes the discrepancy code fragments obtained from the discrepancy analysis as input to construct prompts that include multiple dimensions such as pointer-safe conversion, ownership mapping, and API semantic alignment. Furthermore, the code processing system 10 can also take the discrepancy code context as input to construct prompts with multiple dimensions.
[0145] To make it easier to understand, the following is an explanation of the prompts.
[0146] Referring to Figure 4, a schematic diagram of a prompt message is shown. The prompt message 40 includes a task description 402, an error code fragment 404 in the difference code fragment, a correct code fragment 406, and a difference analysis dimension 408. In this example, the difference analysis dimension 408 may include pointer safe conversion, ownership mapping, and API semantic alignment. Furthermore, the prompt message 40 also includes an output format 409.
[0147] S306, the code processing system 10 inputs the prompt into the language model for analysis and generates translation rules.
[0148] The code processing system 10 can call the language model to perform multi-angle analysis on the differing codes and generate translation knowledge including the following elements: recommended translation rules.
[0149] S308, the code processing system 10 generates source language example code snippets and target language example code snippets corresponding to the translation rules through the language model.
[0150] Accordingly, translation knowledge includes translation rules as well as example code snippets in the source language and the target language.
[0151] S310, the code processing system 10 locates the source language code block corresponding to the difference code fragment.
[0152] Specifically, the code processing system 10 can locate the source language code block corresponding to the difference code fragment through the AST mapping relationship.
[0153] S312, the code processing system 10 performs parameterization processing on the source language code block to obtain source language features.
[0154] The code processing system 10 can use typed placeholders to replace specific implementation details in source language code blocks, preserving the core code structure and thus obtaining source language features. Source language features include semi-structured code templates obtained by replacing code blocks with typed placeholders. Correspondingly, translation knowledge includes source language features and the translation rules.
[0155] S314, the code processing system 10 obtains translation knowledge based on translation rules, difference code snippets, source language features, source language example code snippets, and target language example code snippets.
[0156] Specifically, the code processing system 10 can assemble translation rules, differing code snippets, source language features, and example code snippets of the source and target languages to obtain translation knowledge. This translation knowledge can be represented as a quadruple, such as <source language features, differing code snippets, translation rules, example code>.
[0157] It should be noted that S308 to S314 described above are optional steps in the embodiments of this application. The method of this application may also omit the above steps. For example, the code processing system 10 may use the generated translation rules as translation knowledge. In some examples, the code processing system 10 may assemble at least one of language features, difference code snippets, or example code (such as source language example code snippets and target language example code snippets) with translation rules to obtain translation knowledge.
[0158] Furthermore, based on the embodiment shown in Figure 3, when the target language code segment fails compilation or testing, the code processing system 10 can also receive feedback information from the user regarding the target language code segment. This feedback information includes correction information for the target language code segment. Accordingly, the code processing system 10 can iteratively update the translation knowledge based on the feedback information. Specifically, erroneous code segments and correct code segments can be obtained based on the feedback information. The code processing system 10 can process the erroneous code segments and correct code segments according to S302 to S314, thereby iteratively updating the translation knowledge.
[0159] In this application, the code processing system 10 generates translated knowledge through reflection, typically using an offline reflection mechanism. In some possible implementations, the code processing system 10 may also replace offline reflection with online reinforcement learning, directly optimizing the parameters of the language model through real-time feedback from developers (such as accepting / rejecting suggestions).
[0160] Based on the above description, this application provides a code processing method. This method includes introducing an error reflection learning mechanism through cross-language feature mapping. For erroneous and correct code snippets, cross-language feature mapping is performed using an abstract syntax tree to identify key mismatch regions between the erroneous and correct code snippets, extract corresponding source code features, and analyze the differences between the source and target languages in syntax, semantics, and characteristics, such as differences in pointer safety conversion, ownership mapping, and API semantic alignment. Multi-dimensional feature reflection is performed using a language model, transforming it into explicit translation knowledge (conversion strategy). Furthermore, by generating example code and abstracting source language code snippets, a searchable language transfer knowledge base is constructed. The translation knowledge, such as insights, in the language transfer knowledge base can not only guide subsequent translation tasks but also serve as reusable knowledge accumulation, significantly improving the translation capabilities of the language model.
[0161] Moreover, this method achieves a deep understanding of errors through self-evolutionary learning, continuously learning and reflecting from error transformations to provide targeted improvement strategies and generate translational knowledge. This knowledge guides the language model's translation or conversion process, enhancing its translation or conversion capabilities. On one hand, error correction prevents recurring error patterns, ensuring translation quality. On the other hand, it covers diverse code patterns and complex scenarios without requiring extensive training data (such as bilingual code), improving the universality and robustness of the translation. Furthermore, enhancing the language model's translation capabilities through translational knowledge can address the issue of unstable code quality in similarity-based retrieval technologies, preventing the impact of retrieving suboptimal or potentially erroneous code snippets on translation results.
[0162] The aforementioned solution specifically addresses the migration optimization problem of system-level programming languages. It achieves efficient and accurate code conversion by constructing an intelligent retrieval system that incorporates syntactic features, semantic rules, and corrective experience. This solution can also be extended to other code migration scenarios requiring precise semantic preservation, such as conversion from C++ to Rust, and modernization from traditional to modern languages. These areas face similar challenges, including accurately capturing semantic differences between languages, effectively reusing historical migration experience, and ensuring the security and performance of the generated code. This application's error-reflective learning through cross-language feature mapping and feature-matching-based translation knowledge enhancement conversion provide innovative solutions to these problems.
[0163] Based on the aforementioned code processing method, this application also provides a code processing system 10. The code processing system 10 provided by this application will be described below from the perspective of functional modularity.
[0164] Referring to Figure 1, which shows a schematic diagram of the structure of a code processing system 10, the code processing system 10 includes:
[0165] Translation module 102 is used to receive a source language code fragment to be converted input by the user; retrieve a language transfer knowledge base based on the source language code fragment to obtain translation knowledge corresponding to the source language code fragment, the translation knowledge including translation rules for converting the source language code fragment into a target language code fragment, the translation rules being obtained by learning from erroneous code fragments generated in the history of the language model and the correct code fragments corresponding to the erroneous code fragments;
[0166] The translation module 102 is further configured to input the source language code fragment and the translation knowledge into the language model for reasoning, generate the target language code fragment, and return the target language code fragment to the user.
[0167] The translation module 102 can be a module within the code conversion subsystem 100. For example, the translation module 102 can be implemented in hardware or software.
[0168] When implemented in software, the translation module 102 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service. Virtualization services can include virtual machine (VM) services, bare metal server (BMS) services, or container services. Specifically, a VM service can be a service that uses virtualization technology to create a pool of virtual machine (VM) resources on multiple physical hosts, providing VMs to users on demand. A BMS service is a service that uses virtualization technology to create a pool of BMS resources on multiple physical hosts, providing BMS services to users on demand. A container service is a service that uses virtualization technology to create a pool of container resources on multiple physical hosts, providing containers to users on demand. A VM is a simulated virtual computer, that is, a logical computer. A BMS is a scalable, high-performance computing service with computing performance indistinguishable from traditional physical machines, featuring secure physical isolation. A container is a kernel virtualization technology that provides lightweight virtualization to isolate user space, processes, and resources. It should be understood that the VM service, BMS service, and container service mentioned above are merely specific examples. In practical applications, virtualization services can also include other lightweight or heavyweight virtualization services, which are not specifically limited here.
[0169] When implemented in hardware, the translation module 102 may include at least one computing device, such as a server. Alternatively, the translation module 102 may be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0170] In some possible implementations, the code processing system 10 also includes:
[0171] The difference analysis module 202 is used to perform difference analysis on the erroneous code fragment and the correct code fragment to obtain the difference code fragment;
[0172] The knowledge generation module 204 is used to construct a multi-dimensional prompt based on the difference code fragment, wherein the multi-dimensional prompt includes any combination of pointer safe conversion, ownership mapping or interface semantic alignment; the prompt is input into the language model for analysis to generate the translation rule.
[0173] The difference analysis module 202 and the knowledge generation module 204 can be modules within the knowledge management subsystem 200. For example, the difference analysis module 202 and the knowledge generation module 204 can be implemented in hardware or software.
[0174] When implemented in software, the difference analysis module 202 and the knowledge generation module 204 can be applications running on a computing device. These applications can also be virtualized and provided to users as virtualization services such as VMs, BMS, or containers. When implemented in hardware, the translation module 102 can include at least one computing device, such as a server. Alternatively, the difference analysis module 202 and the knowledge generation module 204 can also be devices implemented using ASICs or PLDs.
[0175] In some possible implementations, the difference analysis module 202 is specifically used for:
[0176] The difference region is located based on the syntax tree nodes of the erroneous code fragment and the syntax tree nodes of the correct code fragment;
[0177] Identify the inserted node, deleted node, or replaced node in the difference region to obtain a difference code fragment, the difference code fragment including the code block where the inserted node, deleted node, or replaced node is located.
[0178] In some possible implementations, the difference analysis module 202 is specifically used for:
[0179] A set of base blocks with type annotations is generated based on the erroneous code snippet and the correct code snippet, wherein the base blocks in the set of base blocks include the smallest execution unit in the erroneous code snippet or the correct code snippet;
[0180] Graph structures are constructed for the erroneous code fragment and the correct code fragment based on the set of base blocks, and the graph structures include at least one of control flow graphs or data dependency graphs.
[0181] By comparing the topology of the graph structure, a difference code fragment is obtained, which includes the code block containing the difference node or difference edge in the graph structure.
[0182] In some possible implementations, the knowledge generation module 204 is further configured to:
[0183] The language model generates source language example code snippets and target language example code snippets corresponding to the translation rules. The translation knowledge includes the translation rules, the source language example code snippets, and the target language example code snippets.
[0184] In some possible implementations, the knowledge generation module 204 is further configured to:
[0185] Locate the source language code block corresponding to the differing code fragment;
[0186] The source language code block is parameterized to obtain source language features, which include a semi-structured code template obtained by replacing it with typed placeholders. The translation knowledge includes the source language features and the translation rules.
[0187] In some possible implementations, the code processing system 10 also includes:
[0188] The knowledge update module (not shown in Figure 1) is used to receive feedback information from the user on the target language code fragment, the feedback information including correction information for the target language code fragment; and to iteratively update the translation knowledge based on the feedback information.
[0189] The knowledge update module can be a module within the knowledge management subsystem 200. For example, the knowledge update module can be implemented in hardware or software.
[0190] When implemented in software, the knowledge update module can be an application running on a computing device. This application can also be virtualized and provided to users as a virtualization service such as a VM, BMS, or container. When implemented in hardware, the knowledge update module can include at least one computing device, such as a server. Alternatively, the knowledge update module can also be a device implemented using an ASIC or a PLD.
[0191] In some possible implementations, the translation knowledge includes source language features and the translation rules, and the translation module 102 is specifically used for:
[0192] The source language code blocks in the source language code fragment are parameterized to obtain the source language features, which include a semi-structured code template obtained by replacing typed placeholders.
[0193] Based on the source language features, a language transfer knowledge base is retrieved to obtain translation knowledge corresponding to the source language code fragment.
[0194] In some possible implementations, the translation module 102 is specifically used for:
[0195] The source language code fragment is input into the retrieval model to obtain the translation knowledge corresponding to the source language code fragment. The retrieval model is obtained by training a dual-tower neural network model using a dataset. The dataset includes multiple sample data, and each sample data includes a source code example and a translation knowledge example corresponding to the source code example.
[0196] In some possible implementations, the translation module 102 is specifically used for:
[0197] The language model is used to perform zero-shot or few-shot learning on the source language code fragment to obtain a first semantic representation, and the language model is used to perform zero-shot or few-shot learning on the translation knowledge in the language transfer knowledge base to obtain a second semantic representation. The first semantic representation and the second semantic representation are matched to obtain the translation knowledge corresponding to the source language code fragment; and / or,
[0198] A summary of the source language code fragment is generated, and information is retrieved from the language transfer knowledge base based on at least one of the algorithmic logic or data structures in the summary to obtain the translation knowledge corresponding to the source language code fragment.
[0199] This application also provides a computing device 500. As shown in FIG5, the computing device 500 includes: a bus 502, a processor 504, a memory 506, and a communication interface 508. The processor 504, the memory 506, and the communication interface 508 communicate with each other via the bus 502. The computing device 500 may be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 500.
[0200] Bus 502 can be 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, only one line is used in Figure 5, but this does not imply that there is only one bus or one type of bus. Bus 502 can include pathways for transmitting information between various components of computing device 500 (e.g., memory 506, processor 504, communication interface 508).
[0201] Processor 504 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0202] Memory 506 may include volatile memory, such as random access memory (RAM). Memory 506 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD). Memory 506 stores executable program code, which processor 504 executes to implement the aforementioned code processing method. Specifically, memory 506 stores instructions for the code processing system 10 to execute the code processing method. For example, memory 506 may store instructions for implementing the functions of translation module 102. Furthermore, memory 506 may also store instructions for implementing the functions of code analysis module 104, testing module 106, error repair module 108, difference analysis module 202, knowledge generation module 204, and knowledge update module.
[0203] The communication interface 508 uses transceiver modules, such as, but not limited to, network interface cards and transceivers, to enable communication between the computing device 500 and other devices or communication networks.
[0204] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0205] As shown in Figure 6, the computing device cluster includes at least one computing device 500. The memory 506 of one or more computing devices 500 in the computing device cluster may store instructions from the same code processing system 10 for executing code processing methods.
[0206] In some possible implementations, one or more computing devices 500 in the computing device cluster can also be used to execute some of the instructions of the code processing system 10 for executing code processing methods. In other words, a combination of one or more computing devices 500 can jointly execute the instructions of the code processing system 10 for executing code processing methods.
[0207] It should be noted that the memory 506 in different computing devices 500 in the computing device cluster can store different instructions for executing some functions of the code processing system 10.
[0208] Figure 7 illustrates one possible implementation. As shown in Figure 7, two computing devices 500A and 500B are connected via a communication interface 508. The memory in computing device 500A stores instructions for executing the functions of the translation module 102. The memory in computing device 500B stores instructions for executing the functions of the aforementioned difference analysis module 202 and knowledge generation module 204. Furthermore, the memory of computing device 500A may also store instructions for executing the functions of the code analysis module 104, testing module 106, and error repair module 108, and the memory of computing device 500B may also store instructions for executing the functions of the knowledge update module. In other words, the memory 506 of computing devices 500A and 500B jointly stores the instructions of the code processing system 10 for executing code processing methods.
[0209] The connection method between the computing device clusters shown in Figure 7 can be considered because the code processing method provided in this application requires a lot of resources for code translation (retrieving the language transfer knowledge base and generating target language code fragments through a language model based on the retrieved code translation knowledge). Therefore, it is considered that the functions implemented by the translation module 102 in the code conversion subsystem 100 and the modules (e.g., the difference analysis module 202 and the knowledge generation module 204) in the knowledge management subsystem 200 are respectively executed by different computing devices. For example, the functions implemented by the translation module 102 can be executed by computing device 500A, and the functions implemented by the difference analysis module 202 and the knowledge generation module 204 can be executed by computing device 500B. Furthermore, when the code processing system 10 also includes a code analysis module 104, a testing module 106, an error repair module 108, and a knowledge update module, the functions implemented by the code analysis module 104, the testing module 106, and the error repair module 108 can be executed by computing device 500A, and the functions implemented by the knowledge update module can be executed by computing device 500B.
[0210] It should be understood that the functions of computing device 500A shown in Figure 7 can also be performed by multiple computing devices 500. Similarly, the functions of computing device 500B can also be performed by multiple computing devices 500.
[0211] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 8 illustrates one possible implementation. As shown in Figure 8, two computing devices 500C and 500D are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, the memory 506 in computing device 500C stores instructions for executing the functions of the translation module 102. Simultaneously, the memory 506 in computing device 500D stores instructions for executing the functions of the aforementioned difference analysis module 202 and knowledge generation module 204. Furthermore, the memory of computing device 500C can also store instructions for executing the functions of the code analysis module 104, testing module 106, and error repair module 108, and instructions for executing the functions of the knowledge update module.
[0212] The connection method between the computing device clusters shown in Figure 8 can be considered because the code processing method provided in this application requires a large amount of resources for code translation or conversion. Therefore, the functions implemented by the translation module 102 in the code conversion subsystem 100 and the modules (e.g., the difference analysis module 202 and the knowledge generation module 204) in the knowledge management subsystem 200 are considered to be executed by different computing devices. For example, the functions implemented by the translation module 102 are executed by computing device 500C, and the functions implemented by the difference analysis module 202 and the knowledge generation module 204 are executed by computing device 500D. In addition, when the code processing system 10 also includes a code analysis module 104, a testing module 106, and an error repair module 108, the functions implemented by the code analysis module 104, the testing module 106, and the error repair module 108 can be executed by computing device 500C. When the code processing system 10 also includes a knowledge update module, the functions implemented by the knowledge update module can be executed by computing device 500D.
[0213] It should be understood that the functions of computing device 500C shown in Figure 8 can also be performed by multiple computing devices 500. Similarly, the functions of computing device 500D can also be performed by multiple computing devices 500.
[0214] This application embodiment also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the code processing method described above applied to the code processing system 10.
[0215] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute the above-described code processing method.
[0216] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of this application.
Claims
1. A code processing method, characterized in that, The method includes: Receives source language code snippets to be converted from user input; The language transfer knowledge base is retrieved based on the source language code fragment to obtain translation knowledge corresponding to the source language code fragment. The translation knowledge includes translation rules for converting the source language code fragment into a target language code fragment. The translation rules are obtained by learning from erroneous code fragments generated in the history of the language model and the correct code fragments corresponding to the erroneous code fragments. The source language code fragment and the translated knowledge are input into the language model for reasoning to generate the target language code fragment; Return the target language code snippet to the user.
2. The method according to claim 1, characterized in that, The method further includes: Perform a difference analysis on the erroneous code snippet and the correct code snippet to obtain the difference code snippet; Construct multi-dimensional prompts based on the discrepancies in the code snippets, whereby the multi-dimensional prompts include any combination of pointer-safe conversion, ownership mapping, or interface semantic alignment. The prompt is input into the language model for analysis, and the translation rule is generated.
3. The method according to claim 2, characterized in that, The step of performing a difference analysis on the erroneous code segment and the correct code segment to obtain the difference code segment includes: The difference region is located based on the syntax tree nodes of the erroneous code fragment and the syntax tree nodes of the correct code fragment; Identify the inserted node, deleted node, or replaced node in the difference region to obtain a difference code fragment, the difference code fragment including the code block where the inserted node, deleted node, or replaced node is located.
4. The method according to claim 2, characterized in that, The step of performing a difference analysis on the erroneous code segment and the correct code segment to obtain the difference code segment includes: A set of base blocks with type annotations is generated based on the erroneous code snippet and the correct code snippet, wherein the base blocks in the set of base blocks include the smallest execution unit in the erroneous code snippet or the correct code snippet; Graph structures are constructed for the erroneous code fragment and the correct code fragment based on the set of base blocks, and the graph structures include at least one of control flow graphs or data dependency graphs. By comparing the topology of the graph structure, a difference code fragment is obtained, which includes the code block containing the difference node or difference edge in the graph structure.
5. The method according to any one of claims 2 to 4, characterized in that, The method further includes: The language model generates source language example code snippets and target language example code snippets corresponding to the translation rules. The translation knowledge includes the translation rules, the source language example code snippets, and the target language example code snippets.
6. The method according to any one of claims 2 to 4, characterized in that, The method further includes: Locate the source language code block corresponding to the differing code fragment; The source language code block is parameterized to obtain source language features, which include a semi-structured code template obtained by replacing it with typed placeholders. The translation knowledge includes the source language features and the translation rules.
7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: Receive feedback from the user on the target language code snippet, the feedback including correction information for the target language code snippet; The translated knowledge is iteratively updated based on the feedback information.
8. The method according to any one of claims 1 to 7, characterized in that, The translation knowledge includes source language features and translation rules. The step of retrieving the language transfer knowledge base based on the source language code fragment to obtain the translation knowledge corresponding to the source language code fragment includes: The source language code blocks in the source language code fragment are parameterized to obtain the source language features, which include a semi-structured code template obtained by replacing typed placeholders. Based on the source language features, a language transfer knowledge base is retrieved to obtain translation knowledge corresponding to the source language code fragment.
9. The method according to any one of claims 1 to 7, characterized in that, The step of retrieving the language transfer knowledge base based on the source language code fragment to obtain the translation knowledge corresponding to the source language code fragment includes: The source language code fragment is input into the retrieval model to obtain the translation knowledge corresponding to the source language code fragment. The retrieval model is obtained by training a dual-tower neural network model using a dataset. The dataset includes multiple sample data, and each sample data includes a source code example and a translation knowledge example corresponding to the source code example.
10. The method according to any one of claims 1 to 7, characterized in that, The step of retrieving the language transfer knowledge base based on the source language code fragment to obtain the translation knowledge corresponding to the source language code fragment includes: The language model is used to perform zero-shot or few-shot learning on the source language code fragment to obtain a first semantic representation, and the language model is used to perform zero-shot or few-shot learning on the translation knowledge in the language transfer knowledge base to obtain a second semantic representation. The first semantic representation and the second semantic representation are matched to obtain the translation knowledge corresponding to the source language code fragment; and / or, A summary of the source language code fragment is generated, and information is retrieved from the language transfer knowledge base based on at least one of the algorithmic logic or data structures in the summary to obtain the translation knowledge corresponding to the source language code fragment.
11. A code processing system, characterized in that, The system includes: The translation module is used to receive source language code fragments to be converted by user input; retrieve language transfer knowledge base based on the source language code fragments to obtain translation knowledge corresponding to the source language code fragments, the translation knowledge including translation rules for converting the source language code fragments into target language code fragments, the translation rules being obtained by learning from erroneous code fragments generated in the history of the language model and the correct code fragments corresponding to the erroneous code fragments; The translation module is further configured to input the source language code fragment and the translation knowledge into the language model for reasoning, generate the target language code fragment, and return the target language code fragment to the user.
12. The system according to claim 11, characterized in that, The system also includes: The difference analysis module is used to perform difference analysis on the erroneous code fragment and the correct code fragment to obtain the difference code fragment; The knowledge generation module is used to construct multi-dimensional prompts based on the difference code fragments, wherein the multi-dimensional prompts include any combination of pointer safe conversion, ownership mapping, or interface semantic alignment; the prompts are input into the language model for analysis to generate the translation rules.
13. The system according to claim 12, characterized in that, The difference analysis module is specifically used for: The difference region is located based on the syntax tree nodes of the erroneous code fragment and the syntax tree nodes of the correct code fragment; Identify the inserted node, deleted node, or replaced node in the difference region to obtain a difference code fragment, the difference code fragment including the code block where the inserted node, deleted node, or replaced node is located.
14. The system according to claim 12, characterized in that, The difference analysis module is specifically used for: A set of base blocks with type annotations is generated based on the erroneous code snippet and the correct code snippet, wherein the base blocks in the set of base blocks include the smallest execution unit in the erroneous code snippet or the correct code snippet; Graph structures are constructed for the erroneous code fragment and the correct code fragment based on the set of base blocks, and the graph structures include at least one of control flow graphs or data dependency graphs. By comparing the topology of the graph structure, a difference code fragment is obtained, which includes the code block containing the difference node or difference edge in the graph structure.
15. The system according to any one of claims 12 to 14, characterized in that, The knowledge generation module is also used for: The language model generates source language example code snippets and target language example code snippets corresponding to the translation rules. The translation knowledge includes the translation rules, the source language example code snippets, and the target language example code snippets.
16. The system according to any one of claims 12 to 14, characterized in that, The knowledge generation module is also used for: Locate the source language code block corresponding to the differing code fragment; The source language code block is parameterized to obtain source language features, which include a semi-structured code template obtained by replacing it with typed placeholders. The translation knowledge includes the source language features and the translation rules.
17. The system according to any one of claims 11 to 16, characterized in that, The system also includes: The knowledge update module is used to receive feedback information from the user regarding the target language code fragment, the feedback information including correction information for the target language code fragment; and to iteratively update the translation knowledge based on the feedback information.
18. The system according to any one of claims 11 to 17, characterized in that, The translation knowledge includes source language features and translation rules, and the translation module is specifically used for: The source language code blocks in the source language code fragment are parameterized to obtain the source language features, which include a semi-structured code template obtained by replacing typed placeholders. Based on the source language features, a language transfer knowledge base is retrieved to obtain translation knowledge corresponding to the source language code fragment.
19. The system according to any one of claims 11 to 17, characterized in that, The translation module is specifically used for: The source language code fragment is input into the retrieval model to obtain the translation knowledge corresponding to the source language code fragment. The retrieval model is obtained by training a dual-tower neural network model using a dataset. The dataset includes multiple sample data, and each sample data includes a source code example and a translation knowledge example corresponding to the source code example.
20. The system according to any one of claims 11 to 17, characterized in that, The translation module is specifically used for: The language model is used to perform zero-shot or few-shot learning on the source language code fragment to obtain a first semantic representation, and the language model is used to perform zero-shot or few-shot learning on the translation knowledge in the language transfer knowledge base to obtain a second semantic representation. The first semantic representation and the second semantic representation are matched to obtain the translation knowledge corresponding to the source language code fragment; and / or, A summary of the source language code fragment is generated, and information is retrieved from the language transfer knowledge base based on at least one of the algorithmic logic or data structures in the summary to obtain the translation knowledge corresponding to the source language code fragment.
21. A computing device cluster, characterized in that, The computing device cluster includes at least one computing device, the at least one computing device including at least one processor and at least one memory, the at least one memory storing computer-readable instructions; the at least one processor executes the computer-readable instructions to cause the computing device cluster to perform the code processing method as described in any one of claims 1 to 10.
22. A computer-readable storage medium, characterized in that, Includes computer-readable instructions; the computer-readable instructions are used to implement the code processing method according to any one of claims 1 to 10.
23. A computer program product, characterized in that, Includes computer-readable instructions; the computer-readable instructions are used to implement the code processing method according to any one of claims 1 to 10.
