Programming language conversion method and device, equipment and storage medium

By obtaining the logical architecture information of the initial language code and using a large language model to generate target language code, the problem of low automation of existing programming language conversion is solved, efficient and accurate programming language conversion is achieved, and manual intervention is reduced.

CN118940721APending Publication Date: 2024-11-12SUNGROW POWER SUPPLY CO LTD
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202410925034.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

The existing programming language conversion methods are low in automation, rely on manual intervention, lack adaptability, and require redefining rules or templates.

Method used

By obtaining the logical architecture information of the initial language code, the initial code module is generated using the preset large language model, and the target language code module is generated based on these modules, and finally integrated into the target language code to achieve highly automated programming language conversion.

Benefits of technology

It improves the accuracy and efficiency of programming language conversion, reduces the dependence on manual definition rules and templates, reduces the degree of manual intervention, and realizes a flexible and efficient conversion process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118940721A_ABST
    Figure CN118940721A_ABST
Patent Text Reader

Abstract

The invention discloses a programming language conversion method and device, equipment and a storage medium. The method comprises the following steps: acquiring an initial language code, and generating logic architecture information of the initial language code; processing the logic architecture information and the initial language code by utilizing a preset large language model to generate an initial code module of the initial language code, and generating a target code module of a target language code according to the initial code module by utilizing the preset large language model; and integrating the target code module by utilizing the preset large language model to obtain a target language code. According to the technical scheme, grammar and semanteme of various programming languages are learned and understood through the large language model technology, high automation of programming language conversion is achieved, equivalent target language codes are automatically generated, the conversion accuracy is improved, dependence on manually defined rules and templates is reduced, and the conversion efficiency is improved. And the conversion process is more flexible and efficient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a programming language conversion method, device, equipment and storage medium. Background Art

[0002] With the development of information technology, programming language conversion (also known as code migration or language translation) is a common requirement in the process of software development. This requirement may be caused by a variety of reasons, including but not limited to technology stack updates, platform compatibility or performance optimization. Programming languages ​​are emerging in an endless stream, and efficient conversion between different programming languages ​​has become an important requirement.

[0003] At present, the main methods of existing programming language conversion include: manual conversion, rule-based conversion, and code generation and template matching conversion. Manual conversion specifically includes: developers manually convert source language code into equivalent target language code based on their understanding of the source language and target language. Rule-based conversion specifically includes: converting source language code into equivalent target language code by pre-defining a series of conversion rules. Template matching conversion specifically includes: generating equivalent target language code based on the structure and semantics of the source language code by defining a series of code templates.

[0004] However, the above traditional conversion methods have problems such as low automation, reliance on manual intervention, often requiring redefinition of rules or templates, and lack of adaptability. Summary of the invention

[0005] The present invention provides a programming language conversion method, device, equipment and storage medium to solve the problems of low automation and lack of adaptability of conventional code conversion methods.

[0006] In a first aspect, the present invention provides a programming language conversion method, comprising:

[0007] Acquire an initial language code and generate logical architecture information of the initial language code;

[0008] Processing the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and generating a target code module of the target language code based on the initial code module using the preset large language model;

[0009] The target code module is integrated with the preset large language model to obtain the target language code.

[0010] In a second aspect, the present invention provides a programming language conversion device, comprising:

[0011] A logical architecture determination module, used to obtain an initial language code and generate logical architecture information of the initial language code;

[0012] a target code module generating module, configured to process the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and to generate a target code module of the target language code according to the initial code module using the preset large language model;

[0013] The target language code generation module is used to integrate the target code module with the preset large language model to obtain the target language code.

[0014] In a third aspect, the present invention provides an electronic device, the electronic device comprising:

[0015] at least one processor;

[0016] and a memory communicatively coupled to the at least one processor;

[0017] The memory stores a computer program executable by at least one processor, and the computer program is executed by at least one processor so that the at least one processor can execute the programming language conversion method of the first aspect.

[0018] In a fourth aspect, the present invention provides a computer-readable storage medium storing computer instructions, which are used to enable a processor to implement the programming language conversion method of the first aspect when executed.

[0019] The programming language conversion scheme provided by the present invention obtains the initial language code, generates the logical architecture information of the initial language code, processes the logical architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, generates a target code module of the target language code based on the initial code module using the preset large language model, and integrates the target code module using the preset large language model to obtain the target language code. By adopting the above technical scheme, by analyzing the calling relationship and logical architecture of the source language code, using the large language model technology to learn and understand the syntax and semantics of various programming languages, gradually constructing an abstract representation of the source language code according to the logical architecture, and generating equivalent code of the target language accordingly, a high degree of automation of programming language conversion is achieved, and equivalent target language code is automatically generated, which not only improves the accuracy of conversion, but also reduces the dependence on manually defined rules and templates, making the conversion process more flexible and efficient, greatly reducing the degree of manual intervention, and achieving efficient conversion.

[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 is a flowchart of a programming language conversion method provided according to Embodiment 1 of the present invention;

[0023] Figure 2 is a flowchart of a programming language conversion method provided according to Embodiment 2 of the present invention;

[0024] Figure 3 is a schematic diagram of the structure of a programming language conversion device provided according to Embodiment 3 of the present invention;

[0025] Figure 4 It is a structural schematic diagram of an electronic device provided according to Embodiment 4 of the present invention. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In the description of the present invention, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are an "or" relationship. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0028] Embodiment 1

[0029] Figure 1 A flowchart of a programming language conversion method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of converting a programming language. The method can be executed by a programming language conversion device. The programming language conversion device can be implemented in the form of hardware and / or software. The programming language conversion device can be configured in an electronic device. The electronic device can be composed of two or more physical entities or one physical entity.

[0030] like Figure 1 As shown, the programming language conversion method provided in the first embodiment of the present invention specifically includes the following steps:

[0031] S101: Acquire an initial language code and generate logical architecture information of the initial language code.

[0032] In this embodiment, the initial language code may be analyzed in depth and a logical architecture may be established in advance, and the logical architecture information of the initial language code may include an abstract syntax tree and the like.

[0033] S102: Process the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and generate a target code module of the target language code based on the initial code module using the preset large language model. The preset large model has basic code analysis and conversion capabilities.

[0034] In this embodiment, the preset large language model can determine the characteristics of the initial language code according to the initial language code, including commonly used programming patterns, library function calls, and algorithm complexity, etc., to provide a basis for the abstract simplification of the initial language code. On this basis, the preset large language model can further analyze the main logical flow and control structure of the initial language code according to the logical architecture information, determine the code blocks that can be abstracted into modules, abstract the complex logic and details in the initial language code, and replace the specific implementation details with abstract interfaces or function calls, thereby generating an initial code module of the initial language code. Among them, the preset large language model code module division strategy can be pre-configured, such as combining related functions and classes in the initial language code into an initial code module, or dividing the code into multiple initial code modules according to business logic. Then, the preset large language model can be used to generate a target code module of the target language code according to the initial code module.

[0035] S103: Integrate the target code module using the preset large language model to obtain the target language code.

[0036] In this embodiment, the preset large language model can integrate these target code modules according to the logical architecture information to obtain target code module integration information consistent with the initial language code logical architecture, and the target language code can be obtained according to the information.

[0037] The programming language conversion method provided by the embodiment of the present invention obtains the initial language code, generates the logical architecture information of the initial language code, processes the logical architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, generates a target code module of the target language code based on the initial code module using the preset large language model, and integrates the target code module using the preset large language model to obtain the target language code. The technical solution of the embodiment of the present invention analyzes the calling relationship and logical architecture of the source language code, uses the large language model technology to learn and understand the syntax and semantics of various programming languages, gradually constructs an abstract representation of the source language code according to the logical architecture, and generates the equivalent code of the target language accordingly, thus realizing a high degree of automation of programming language conversion, automatically generating an equivalent target language code, not only improving the accuracy of conversion, but also reducing the dependence on manually defined rules and templates, making the conversion process more flexible and efficient, greatly reducing the degree of manual intervention, and realizing efficient conversion.

[0038] Optionally, before integrating the target code modules using the preset large language model to obtain the target language code, the method further includes: using the preset large language model to generate initial code nodes inside each initial code module, and generating target code nodes inside the target code module based on the initial code nodes, wherein the code of the initial code module does not include the target logic implementation code, and the code of the target code node includes the target logic implementation code.

[0039] Specifically, the code corresponding to each initial code module can be generated in advance using a preset large language model, wherein the code corresponding to the initial code module does not contain low-level logic implementation code (i.e., target logic implementation code), and only retains the name of the logic implementation code. The process of generating the initial code node inside each initial code module using the preset large language model includes the following two steps:

[0040] 1) Detailed node analysis: Analyze the initial language code in detail to understand its functions, input-output relationships, dependencies and other key features. This step provides the necessary prerequisite information for node conversion.

[0041] 2) Target language node code generation: Based on the above analysis, the preset large language model is used to automatically generate the initial code nodes and their corresponding codes within each initial code module. The code can accurately reproduce the function and logic of the target logic implementation code.

[0042] Optionally, using a preset large language model to generate an initial code node inside each initial code module includes: using the preset large language model to generate a code node to be determined inside each initial code module; using the code node to be determined inside the initial code module to generate an initial code node whose third test gap meets a third preset requirement, wherein the third test gap includes a gap between a fourth test value and a fifth test value, the fourth test value is a standard input value and a standard output value of the code node to be determined inside the initial code module determined using a preset test case, and the fifth test value is an actual input value and an actual output value of the code node to be determined inside the initial code module.

[0043] Specifically, using the preset large language model to generate the initial code nodes within each initial code module includes the following 9 steps:

[0044] 1) Detailed node analysis: Analyze the initial language code in detail to understand its functions, input-output relationships, dependencies and other key features. This step provides the necessary prerequisite information for node conversion.

[0045] 2) Target language node code generation: Based on the above analysis, the preset large language model is used to automatically generate the code nodes to be determined within each initial code module and their corresponding codes. The code can accurately reproduce the function and logic of the target logic implementation code.

[0046] 3) Node code review: Manually review the code of the generated code nodes to be determined to check the code quality, accuracy and security. Ensure that the converted code is not only syntactically correct, but also logically consistent with the original language code and conforms to the best practices of the target language.

[0047] 4) Write node test cases: Write detailed test cases for each code node to be determined, covering all expected functions, exceptions, and boundary conditions. These test cases are key to verifying the functionality and performance of the node.

[0048] 5) Execute node testing: Use the automated testing framework to execute the written test cases and test the code of each code node to be determined. Record the test results in detail, including the passed and failed cases and their reasons.

[0049] 6) Analyze test results and adjust code: Based on the test results (i.e. the difference between the actual input value and the actual output value and the corresponding standard input value and standard output value), make necessary adjustments to the code of the code node to be determined. Fix the errors found, optimize performance, and ensure that the code meets the expected functional and performance requirements.

[0050] 7) Repeat the test until the requirements are met: retest the modified code nodes to be determined to ensure that all modifications can achieve the expected results and all test cases can pass successfully (that is, the third test gap meets the third preset requirements). The above process may require multiple iterations.

[0051] 8) Inter-node integration testing: After completing the testing of a single node, conduct inter-node integration testing to ensure that the interaction and data flow between the code nodes to be determined are correct in the target language. This helps to discover and solve problems that may arise during the integration process.

[0052] 9) Document the testing and tuning process: Record the generation, testing, and tuning process of the code nodes to be determined in detail, including successful cases, problems encountered, and their solutions. These documents are very important for the subsequent stages of the project and future improvements.

[0053] Optionally, the method of generating logical architecture information of the initial language code includes: preprocessing the initial language code to obtain a preprocessing result; extracting code dependencies in the preprocessing result, and generating logical architecture information based on the code dependencies, wherein the code dependencies include call relationships, data dependencies, and control dependencies, and the logical architecture information includes logical relationships between logical elements in the syntax tree of the initial language code.

[0054] Specifically, in this embodiment, the initial language code can be analyzed in depth and the logic architecture can be established in advance, which specifically includes the following 9 steps:

[0055] 1) Initial language code preprocessing: Before analysis, the initial language code is preprocessed, including removing comments, formatting code, and processing macro definitions, to ensure the accuracy of the analysis process.

[0056] 2) Syntax analysis: Use the syntax analyzer corresponding to the source language of the initial language code to generate an abstract syntax tree (AST). This step converts the initial language code into a tree structure to facilitate subsequent analysis of the structure and syntax of the code.

[0057] 3) Control flow analysis: Build a control flow graph (CFG) based on AST, analyze the execution flow of functions or program blocks, and identify control structures such as loops and branches.

[0058] 4) Data flow analysis: Use AST and data flow analysis techniques to construct a data flow diagram (DFG) to analyze the relationship between variable definition and use, as well as the flow of data in the program.

[0059] 5) Dependency extraction: Analyze AST, CFG and DFG to extract dependencies between functions or classes, including call relationships, data dependencies and control dependencies.

[0060] 6) Logical architecture information generation: Integrate the above analysis results to generate the logical architecture information of the initial language code, which includes the logical relationship between the codes.

[0061] 7) Logical architecture information verification: Use automated algorithms to verify the generated logical architecture information to ensure that it accurately reflects the logical structure of the initial language code.

[0062] 8) Documentation and comment analysis: Analyze the documentation strings and comments in the original language code, and extract the function descriptions, parameter descriptions, and return value information that may be contained to better understand the code intent.

[0063] 9) Feedback loop: If errors or inconsistencies are found during the analysis, step 1) or step 2) needs to be performed to make corrections and re-analysis.

[0064] The above steps ensure a comprehensive understanding of the initial language code and ensure the accuracy and efficiency of subsequent conversion work.

[0065] Embodiment 2

[0066] Figure 2 This is a flowchart of a programming language conversion method provided in the second embodiment of the present invention. The technical solution of the embodiment of the present invention is further optimized on the basis of the above-mentioned optional technical solutions, and provides a specific method for converting the programming language.

[0067] Optionally, the preset large language model is used to process the logical architecture information and the initial language code to generate an initial code module of the initial language code, including: inputting the logical architecture information and the initial language code into the preset large language model to obtain the to-be-determined code module of the initial language code; using the to-be-determined code module of the initial language code, generating an initial code module whose first test gap meets the first preset requirement, wherein the first test gap includes the gap between the first test value and the second test value, the first test value is the standard input value and the standard output value of the to-be-determined code module of the initial language code determined using the preset test case, and the second test value is the actual input value and the actual output value of the to-be-determined code module of the initial language code. The advantage of such a setting is that by testing the to-be-determined code module of the initial language code using the preset test case, not only the understanding and grasp of the logic of the initial language code is guaranteed, but also the conversion process is ensured to be both automated and in line with the specific needs of the developer.

[0068] Optionally, using a preset large language model to generate a target code module of a target language code according to an initial code module includes: using a preset large language model to generate a code module to be determined of a target language code according to the initial code module; using the code module to be determined of the target language code to generate a target code module whose second test gap meets a second preset requirement, wherein the second test gap includes a gap between a first test value and a third test value, and the third test value is an actual input value and an actual output value of the code module to be determined of the target language code. The advantage of such a setting is that by testing the code module to be determined of the target language code using preset test cases, not only the accuracy and functional integrity of the target language code are ensured, but also the quality and stability of the code can be improved through repeated testing and optimization.

[0069] Optionally, before using the code nodes to be determined inside the initial code module to generate the initial code nodes whose third test gap meets the third preset requirement, it also includes: if the code of the code nodes to be determined inside the initial code module includes code exceeding the preset complexity, deconstructing the code exceeding the preset complexity into logic units to obtain new code nodes to be determined; wherein, using the code nodes to be determined inside the initial code module to generate the initial code nodes whose third test gap meets the third preset requirement includes: using the new code nodes to be determined inside the initial code module to generate the initial code nodes whose third test gap meets the third preset requirement. The advantage of such a setting is that by deconstructing the code exceeding the preset complexity into logic units, attention to and precise control of code details are achieved, ensuring the high accuracy and functional consistency of each node during the conversion process, thereby improving the quality and reliability of the conversion.

[0070] like Figure 2 As shown, a programming language conversion method provided by Embodiment 2 of the present invention specifically includes the following steps:

[0071] S201. Acquire an initial language code and generate logical architecture information of the initial language code.

[0072] S202: Input the logic architecture information and the initial language code into a preset large language model to obtain a code module to be determined of the initial language code.

[0073] S203: Generate an initial code module whose first test gap meets a first preset requirement by using the to-be-determined code module of the initial language code.

[0074] Among them, the first test gap includes the gap between the first test value and the second test value, the first test value is the standard input value and standard output value of the code module to be determined of the initial language code determined by using the preset test case, and the second test value is the actual input value and actual output value of the code module to be determined of the initial language code.

[0075] Specifically, since the automatic abstraction and simplification of the initial language code by the preset large language model may not be perfect, it is necessary to review the accuracy of the abstracted module to ensure that it meets the intention of the initial language code and can correctly represent the original function. A clear interface can be defined for each code module to be determined, including input parameters, output results, and dependencies between modules. Write detailed documents for each code module to be determined, explaining its functions, usage methods, and dependencies, so as to facilitate subsequent code generation and understanding. Run the code module to be determined in the initial language environment, and verify whether its functions meet expectations through preset test cases. Under the premise of keeping the overall function of the initial language code unchanged, verify the correctness and efficiency of the code module to be determined, that is, verify that the first test gap meets the first preset requirement, which involves testing and performance evaluation of the module interface to obtain the initial code module whose first test gap meets the first preset requirement.

[0076] Optionally, the code of each initial code module can be generated using the preset large language model, and the process of testing the code using the test case includes the following 8 steps:

[0077] 1) Module code generation: Use the preset large language model to automatically generate the initial language code of each initial code module. This includes specific function implementation, data structure definition and interface implementation between modules.

[0078] 2) Code review and optimization: The automatically generated module code needs to be reviewed to ensure the quality, readability and performance of the code. At this stage, the generated code can be reviewed to identify and correct possible logical errors, performance bottlenecks or areas that do not meet coding standards.

[0079] 3) Module-level test case definition: Define dedicated test cases for each generated module. These test cases should cover all major functions and boundary conditions of the initial code module to ensure that the initial code module can be executed correctly in various situations.

[0080] 4) Perform module testing: Use the automated testing framework to execute the module-level test cases defined in the previous step. Record the test results, including successful and failed test cases and their cause analysis. Pay special attention to whether the interfaces and data interactions between the initial code modules are correct.

[0081] 5) Analysis and Adjustment: Based on the results of module testing, make necessary analysis and adjustments to the initial code module code. Correct the errors and problems found to optimize the performance and stability of the initial code module. If necessary, return to the initial code module design stage for adjustment.

[0082] 6) Integration testing: After all initial code modules have passed testing, perform preliminary integration testing to check whether the interactions and data flows between the initial code modules work as expected. This helps identify and resolve issues that may arise during the integration of the initial code modules.

[0083] 7) Document test results: Record the results of initial code module testing and integration testing in detail, including test coverage, problem list and its resolution status. This will provide important information for subsequent project review and quality assurance.

[0084] 8) Feedback loop: The testing and adjustment process is an iterative process. Based on the test results and feedback from the project team, multiple iterations may be required to continuously optimize the code of the initial code module until all predetermined quality and functional requirements are met.

[0085] The advantage of this setting is that it ensures that each initial code module is not only logically consistent with the initial language code, but also can accurately implement the functions of the initial language code. This process not only takes advantage of the automation of large language model technology, but also combines the strict standards of testing to ensure high-quality programming language conversion.

[0086] S204: Generate a to-be-determined code module of the target language code according to the initial code module using a preset large language model.

[0087] S205 : Generate a target code module whose second test gap meets a second preset requirement by using the to-be-determined code module of the target language code.

[0088] The second test gap includes the gap between the first test value and the third test value, and the third test value is the actual input value and the actual output value of the to-be-determined code module of the target language code.

[0089] Specifically, the process of generating the target code module and its corresponding code includes the following 8 steps:

[0090] 1) Target language module code generation: Using the preset large language model, the target language code's to-be-determined code module and its corresponding code can be generated based on the initial code module. This process needs to ensure that the target code can accurately reproduce the functions and logic of the initial language code.

[0091] 2) Code quality review: The automatically generated target language code module needs to be thoroughly reviewed to verify its quality, accuracy and compliance with the programming conventions of the target language. During the review process, special attention is paid to logical deviations, performance issues and security vulnerabilities that may occur during the conversion process.

[0092] 3) Writing test cases for target language modules: Based on the functions of the initial code modules and their preset test cases, corresponding test cases can be written for the target language code modules to be determined. This includes but is not limited to unit testing, boundary testing, and error handling testing to ensure that all key functional points are covered.

[0093] 4) Execute target language module testing: Use automated testing tools to execute the written test cases and test each target language code module to be determined. Record detailed test results, including success, failure, and problems found.

[0094] 5) Analyze test results and make adjustments: Analyze the problems found in the test, find out the reasons for the failure, and make necessary adjustments and optimizations to the code of the target language’s code module to be determined. This may involve modifying code logic, optimizing performance, or enhancing security.

[0095] 6) Repeat the test: Retest the modified target language code module to verify whether the problem has been solved. This process may require multiple iterations until all target language code modules can successfully pass the test case test, and the target code module that meets the second preset requirement can be obtained.

[0096] 7) Target language code integration test: After all target language code modules have been tested individually and passed, the overall integration test is performed to verify whether the interaction and data flow between different modules are correct in the target language.

[0097] 8) Documentation and feedback: Record the code generation, testing, and adjustment process of the target language's code module in detail, including successful cases, problems encountered, and their solutions. These documents are essential for future project reviews and continuous improvements.

[0098] S206: Generate code nodes to be determined in each initial code module by using a preset large language model.

[0099] S207: If the code of the code node to be determined in the initial code module includes code exceeding a preset complexity, deconstruct the code exceeding the preset complexity into logic units to obtain a new code node to be determined.

[0100] Specifically, in the face of the challenge of directly generating complex functions, the code that exceeds the preset complexity can be deconstructed into more basic programming logic units. The specific approach includes: carefully dividing the functions in the code that exceeds the preset complexity into core logic components such as linear execution sequences, selective branch paths, and repeated execution loop frameworks, and systematically implementing independent code generation steps for these basic logic units, thereby breaking them down one by one, ensuring the feasibility and accuracy of the generation process.

[0101] S208: Generate an initial code node whose third test gap meets a third preset requirement by using the new to-be-determined code node in the initial code module.

[0102] S209: Integrate the target code module using a preset large language model to obtain a target language code.

[0103] Specifically, the process of integrating the target code module to obtain the target language code and testing the target language code includes the following six steps:

[0104] 1) Overall code integration: Integrate the target code module and its internal nodes to obtain the complete target language code. In this process, pay special attention to the docking of the interfaces between modules and the correctness of the data flow. The integration process may include: ① Bottom-up integration: Start from the lowest-level target code module and gradually integrate higher-level target code modules upward. ② Incremental integration: Integrate only one or two modules at a time and gradually build the entire system; ③ Function-based integration: Organize the integration order according to the functional modules in the target code module to ensure that each functional point can work properly during integration; ④ Interface-based integration: Pay attention to the interfaces between target code modules to ensure that they can communicate correctly.

[0105] 2) Integration testing: Perform comprehensive integration testing to verify whether the integrated target code module meets expectations in terms of functionality, performance, and user experience. This includes but is not limited to user scenario testing, performance testing, and security testing.

[0106] 3) Problem diagnosis and resolution: For problems found during integration testing, detailed diagnosis is performed to determine the root cause and appropriate measures are taken to resolve it. This may involve adjusting the code logic of the target code module, optimizing performance, or enhancing security.

[0107] 4) Regression testing: Perform regression testing on the modified target language code to ensure that the changes have not introduced new problems and that previous functionality and performance are maintained.

[0108] 5) Performance optimization: Based on the test results, the target language code is optimized for performance, including but not limited to code optimization, resource management optimization, loading time optimization, etc., to ensure that the project runs smoothly on the target platform.

[0109] 6) Documentation and manual updates: Update test documents and user manuals, including installation guides, user guides, and API documentation, to ensure that the documents accurately reflect the final status of the target language code.

[0110] The above steps not only ensure that the target language code obtained after conversion can run normally as a whole, but also improve the performance and user experience of the target language code through comprehensive quality control and optimization, ensuring that the quality of the target language code delivered is higher than or equal to the standard of the initial language code, and achieving comprehensive guarantee for the successful delivery of the target language code. It is the final stage of the entire programming language conversion process.

[0111] Optionally, the process of generating test cases includes the following 9 steps:

[0112] 1) Test case design: Test cases should cover the main execution paths, branch conditions, exception handling, and edge cases of the code.

[0113] 2) Test environment setup: Prepare the test environment, including installing the necessary runtime environment, dependent libraries, and tools to ensure that the test can be performed under conditions similar to the production environment.

[0114] 3) Execute test cases: Run the designed test cases in the execution environment of the initial language code and collect the running results, including standard output, error information and program status.

[0115] 4) Input / output records: For each test case, record the input data, expected output results, and actual output results. These records will be used for subsequent comparison and verification.

[0116] 5) Parameter and status recording: Insert hooks at key nodes of the initial language code to record the parameter values, return values ​​and global status of the function or module to facilitate subsequent comparison and analysis.

[0117] 6) Test result verification: Compare the expected results and actual results of the test cases to ensure the correctness and stability of the source language code. Failed test cases need to be debugged and corrected.

[0118] 7) Test coverage analysis: Analyze the coverage of the test cases for the initial language code to ensure that important code paths and functional points are fully tested. If the coverage is insufficient, more test cases need to be added.

[0119] 8) Test report generation: Write a test report summarizing the test results, coverage analysis, and any code issues found. This report will serve as an important reference document for the conversion process.

[0120] 9) Test case maintenance: As the initial language code is updated and the conversion process changes, the test cases may need to be updated and maintained accordingly to ensure that they are always valid.

[0121] Through the above steps, it is ensured that the functions and logic of the initial language code before conversion are accurately understood and recorded, providing a solid foundation for subsequent code conversion and verification. This not only helps to improve the accuracy of conversion, but also significantly reduces the workload of subsequent debugging and verification.

[0122] Optionally, the process of handling the misalignment of the code conversion process includes the following 7 steps:

[0123] 1) Error and problem classification: All errors and problems encountered during the conversion process are recorded and classified in detail. The classification criteria include: error type (such as syntax errors, logical errors, and performance issues), impact scope (such as single nodes and interactions between modules), and problem complexity.

[0124] 2) Preliminary analysis and diagnosis: Perform preliminary analysis and diagnosis on each classified error to determine the root cause of the error. This may require reviewing the original language code, the converted code, and the associated test results.

[0125] 3) Determine the handling strategy: Based on the nature and complexity of the error, determine a handling strategy for each problem. The strategy may include automatic repair, manual correction, module reconstruction, or temporary ignoring.

[0126] 4) Manual intervention and correction: For errors that require manual intervention, experienced developers are arranged to correct them. This includes: directly modifying the target language code, adjusting the conversion logic, or adding special processing logic, etc.

[0127] 5) Optimize conversion tools and processes: Based on the problems encountered and the experience of manual intervention, optimize the conversion tools and processes. This may involve updating the conversion rules, improving the training data of large language models, or adjusting the module division strategy.

[0128] 6) Re-execute conversion and testing: For codes that have been manually corrected or optimized by tools, re-execute the conversion and testing process to verify whether the problem has been resolved.

[0129] 7) Record and analyze: Record the process, measures taken and final results in detail for subsequent analysis. This helps identify weaknesses and improvement opportunities in the conversion process.

[0130] The above steps ensure that even when encountering complex problems that are difficult to handle automatically, the progress and quality of the conversion project can be maintained through effective error management and manual intervention strategies. This step reflects the importance of flexibility and adaptability in programming language conversion projects.

[0131] The programming language conversion method provided by the embodiment of the present invention not only ensures the understanding and grasp of the logic of the initial language code, but also ensures that the conversion process is both automated and meets the specific needs of the developer by testing the code modules to be determined of the initial language code with preset test cases. By using preset test cases to test the code modules to be determined of the target language code, not only the accuracy and functional integrity of the target language code are ensured, but also the quality and stability of the code can be improved through repeated testing and optimization. By deconstructing the code exceeding the preset complexity into logical units, attention to and precise control of the code details are achieved, ensuring the high accuracy and functional consistency of each node in the conversion process, thereby improving the quality and reliability of the conversion. This method not only integrates a large language model, but also incorporates the new idea of ​​"fine-grained logical structure decomposition" (that is, deconstructing codes that exceed the preset complexity into logical units). It copes with the complex challenges faced in the traditional conversion process with a high level of automation, depth of logical processing, and a more delicate level. It not only greatly improves the ability to handle complex grammar and deep semantic differences, but also enhances the reliability and consistency of the conversion output through modular design and verification strategies, greatly reduces manual intervention, improves the flexibility and expansion potential of the conversion, and lays a solid foundation for the future development of AI-assisted programming and code maintenance.

[0132] Embodiment 3

[0133] Figure 3 This is a schematic diagram of the structure of a programming language conversion device provided by Embodiment 3 of the present invention. Figure 3 As shown, the device includes: a logic architecture determination module 301, a target code module generation module 302 and a target language code generation module 303, wherein:

[0134] A logical architecture determination module, used to obtain an initial language code and generate logical architecture information of the initial language code;

[0135] a target code module generating module, configured to process the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and to generate a target code module of the target language code according to the initial code module using the preset large language model;

[0136] The target language code generation module is used to integrate the target code module with the preset large language model to obtain the target language code.

[0137] The programming language conversion device provided in the embodiment of the present invention analyzes the calling relationship and logical architecture of the source language code, uses the large language model technology to learn and understand the syntax and semantics of various programming languages, gradually constructs an abstract representation of the source language code according to the logical architecture, and generates equivalent code of the target language based on it, thereby achieving a high degree of automation of programming language conversion and automatically generating equivalent target language code, which not only improves the accuracy of the conversion, but also reduces the dependence on manually defined rules and templates, making the conversion process more flexible and efficient, greatly reducing the degree of manual intervention, and achieving efficient conversion.

[0138] Optionally, the target code module generation module includes:

[0139] an initial language code module generating unit, configured to input the logic architecture information and the initial language code into a preset large language model to obtain a code module to be determined of the initial language code;

[0140] The initial code module determination unit is used to generate an initial code module whose first test gap meets a first preset requirement by using the code module to be determined of the initial language code, wherein the first test gap includes a gap between a first test value and a second test value, the first test value is a standard input value and a standard output value of the code module to be determined of the initial language code determined by using a preset test case, and the second test value is an actual input value and an actual output value of the code module to be determined of the initial language code.

[0141] Optionally, the target code module generation module includes:

[0142] A target language code module generating unit, configured to generate a to-be-determined code module of a target language code according to the initial code module by using the preset large language model;

[0143] The target code module determination unit is used to generate a target code module whose second test gap meets the second preset requirement by using the code module to be determined of the target language code, wherein the second test gap includes the gap between the first test value and the third test value, and the third test value is the actual input value and the actual output value of the code module to be determined of the target language code.

[0144] Optionally, the device further comprises:

[0145] A target code node generation module is used to generate an initial code node inside each of the initial code modules using the preset large language model before the target code module is integrated with the preset large language model to obtain the target language code, and generate a target code node inside the target code module based on the initial code node, wherein the code of the initial code module does not include the target logic implementation code, and the code of the target code node includes the target logic implementation code.

[0146] Optionally, the using the preset large language model to generate the initial code node inside each of the initial code modules includes: using the preset large language model to generate the code node to be determined inside each of the initial code modules; using the code node to be determined inside the initial code module to generate the initial code node whose third test gap meets the third preset requirement, wherein the third test gap includes the gap between the fourth test value and the fifth test value, the fourth test value is the standard input value and standard output value of the code node to be determined inside the initial code module determined using the preset test case, and the fifth test value is the actual input value and actual output value of the code node to be determined inside the initial code module.

[0147] Optionally, the target code module generation module also includes:

[0148] A new code node generating unit is configured to, before using the code node to be determined in the initial code module to generate the initial code node whose third test gap meets the third preset requirement, deconstruct the code exceeding the preset complexity into logic units to obtain a new code node to be determined if the code of the code node to be determined in the initial code module includes code exceeding the preset complexity.

[0149] Optionally, the using the to-be-determined code nodes within the initial code module to generate the initial code nodes whose third test gaps meet the third preset requirement includes: using the new to-be-determined code nodes within the initial code module to generate the initial code nodes whose third test gaps meet the third preset requirement.

[0150] Optionally, the method of generating the logical architecture information of the initial language code includes: preprocessing the initial language code to obtain a preprocessing result; extracting code dependencies in the preprocessing result, and generating logical architecture information based on the code dependencies, wherein the code dependencies include call relationships, data dependencies, and control dependencies, and the logical architecture information includes logical relationships between logical elements in the syntax tree of the initial language code.

[0151] The programming language conversion device provided in the embodiment of the present invention can execute the programming language conversion method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0152] Embodiment 4

[0153] Figure 4 A schematic diagram of the structure of an electronic device 40 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0154] like Figure 4 As shown, the electronic device 40 includes at least one processor 41, and a memory connected to the at least one processor 41, such as a read-only memory (ROM) 42, a random access memory (RAM) 43, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 41 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 42 or the computer program loaded from the storage unit 48 to the random access memory (RAM) 43. In the RAM 43, various programs and data required for the operation of the electronic device 40 can also be stored. The processor 41, the ROM 42, and the RAM 43 are connected to each other through a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.

[0155] A number of components in the electronic device 40 are connected to the I / O interface 45, including: an input unit 46, such as a keyboard, a mouse, etc.; an output unit 47, such as various types of displays, speakers, etc.; a storage unit 48, such as a disk, an optical disk, etc.; and a communication unit 49, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 49 allows the electronic device 40 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0156] The processor 41 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 41 executes the various methods and processes described above, such as a programming language conversion method.

[0157] In some embodiments, the programming language conversion method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 48. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 40 via the ROM 42 and / or the communication unit 49. When the computer program is loaded into the RAM 43 and executed by the processor 41, one or more steps of the programming language conversion method described above may be performed. Alternatively, in other embodiments, the processor 41 may be configured to perform the programming language conversion method in any other appropriate manner (e.g., by means of firmware).

[0158] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0159] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0160] The computer device provided above can be used to execute the programming language conversion method provided in any of the above embodiments, and has corresponding functions and beneficial effects.

[0161] Embodiment 5

[0162] In the context of the present invention, a computer-readable storage medium may be a tangible medium, wherein the computer-executable instructions, when executed by a computer processor, are used to perform a programming language conversion method, the method comprising:

[0163] Acquire an initial language code and generate logical architecture information of the initial language code;

[0164] Processing the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and generating a target code module of the target language code based on the initial code module using the preset large language model;

[0165] The target code module is integrated with the preset large language model to obtain the target language code.

[0166] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by an instruction execution system, device or equipment or used with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0167] The computer device provided above can be used to execute the programming language conversion method provided in any of the above embodiments, and has corresponding functions and beneficial effects.

[0168] It is worth noting that in the embodiment of the above-mentioned programming language conversion device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0169] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A programming language conversion method, characterized in that: include: Acquire an initial language code and generate logical architecture information of the initial language code; Processing the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and generating a target code module of the target language code based on the initial code module using the preset large language model; The target code module is integrated with the preset large language model to obtain the target language code.

2. The method according to claim 1, characterized in that The initial code module for processing the logic architecture information and the initial language code by using a preset large language model to generate the initial language code includes: Inputting the logic architecture information and the initial language code into a preset large language model to obtain a to-be-determined code module of the initial language code; Using the code module to be determined of the initial language code, an initial code module whose first test gap meets the first preset requirement is generated, wherein the first test gap includes a gap between a first test value and a second test value, the first test value is a standard input value and a standard output value of the code module to be determined of the initial language code determined using a preset test case, and the second test value is an actual input value and an actual output value of the code module to be determined of the initial language code.

3. The method according to claim 2, characterized in that The target code module for generating the target language code according to the initial code module by using the preset large language model comprises: Generate a to-be-determined code module of a target language code according to the initial code module using the preset large language model; Using the code module to be determined in the target language code, a target code module with a second test gap that meets a second preset requirement is generated, wherein the second test gap includes a gap between the first test value and a third test value, and the third test value is an actual input value and an actual output value of the code module to be determined in the target language code.

4. The method according to any one of claims 1 to 3, characterized in that Before integrating the target code module with the preset large language model to obtain the target language code, the method further includes: The preset large language model is used to generate an initial code node inside each of the initial code modules, and a target code node inside the target code module is generated according to the initial code node, wherein the code of the initial code module does not include the target logic implementation code, and the target code node includes the target logic implementation code.

5. The method according to claim 4, characterized in that The step of using the preset large language model to generate the initial code nodes within each of the initial code modules includes: Using the preset large language model, generating a code node to be determined within each of the initial code modules; Using the code node to be determined inside the initial code module, an initial code node whose third test gap meets a third preset requirement is generated, wherein the third test gap includes a gap between a fourth test value and a fifth test value, the fourth test value is a standard input value and a standard output value of the code node to be determined inside the initial code module determined using a preset test case, and the fifth test value is an actual input value and an actual output value of the code node to be determined inside the initial code module.

6. The method according to claim 4, characterized in that Before using the to-be-determined code nodes in the initial code module to generate the initial code nodes whose third test gaps meet the third preset requirement, the method further includes: If the code of the code node to be determined in the initial code module includes code exceeding a preset complexity, deconstructing the code exceeding the preset complexity into logic units to obtain a new code node to be determined; The step of using the to-be-determined code nodes in the initial code module to generate the initial code nodes whose third test gap meets the third preset requirement includes: An initial code node whose third test gap meets a third preset requirement is generated by using the new to-be-determined code node in the initial code module.

7. The method according to claim 1, characterized in that The method of generating the logical architecture information of the initial language code includes: Preprocessing the initial language code to obtain a preprocessing result; Extract code dependencies in the preprocessing results, and generate logical architecture information based on the code dependencies, wherein the code dependencies include call relationships, data dependencies, and control dependencies, and the logical architecture information includes logical relationships between logical elements in the syntax tree of the initial language code.

8. A programming language conversion device, characterized in that: include: A logical architecture determination module, used to obtain an initial language code and generate logical architecture information of the initial language code; a target code module generating module, configured to process the logic architecture information and the initial language code using a preset large language model to generate an initial code module of the initial language code, and to generate a target code module of a target language code according to the initial code module using the preset large language model; The target language code generation module is used to integrate the target code module with the preset large language model to obtain the target language code.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the programming language conversion method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the programming language conversion method according to any one of claims 1 to 7 when executed.

Citation Information

Cited By

  • Device and method for supporting multi-language code output by low-code platform

    CN119440490A

  • Code generation method and device

    CN119781772A

  • Code conversion method and device, electronic equipment and computer readable medium

    CN120335817A

  • Method and device for code conversion, equipment, storage medium and program product

    CN122489078A