Cross-programming language function conversion method and device

By establishing a method of establishing a core data structure and generating data type relationship trees, the problem that cannot be directly called between different programming languages ​​can be solved, and cross -language function calls are realized, which improves development efficiency.

CN119336337APending Publication Date: 2025-01-21COMP NETWORK INFORMATION CENT CHINESE ACADEMY OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411360618.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

Functions cannot be called directly between different programming languages, which makes it difficult to call cross-language function.

Method used

By establishing core data structures such as a set of types to be converted, a data type table, and a template library, functions in one programming language are automatically converted into functions in another programming language, and a data type relationship tree is generated and encapsulated into target language code. .

Benefits of technology

The function calls between different programming languages ​​have been achieved, reducing repeated labor, making full use of the advantages of each language, and improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336337A_ABST
    Figure CN119336337A_ABST
Patent Text Reader

Abstract

A cross-programming language function conversion method comprises the following steps: acquiring a first data type in a first programming language, and integrating the first data type into a conversion type set; storing the first data type in a data type table, wherein the data type table comprises a basic data type table and a user-defined data type table; generating a data type relation tree based on the conversion type set; and packaging the first data type and the data corresponding to the first data type into a second programming language code based on the data type relation tree and the data type table. By means of the method, the function in one programming language can be automatically converted into the function in another programming language, and function calling is facilitated.
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 method and device for converting functions across programming languages. Background Art

[0002] With the rapid development of computer technology, various computer-related applications have emerged. Programming languages ​​are tools and foundations for realizing various medical uses, and they play an indispensable and important role. Programming languages ​​provide humans with a tool that enables programmers to accurately specify the data that computers need to use and the actions that should be taken in different application scenarios. Programming languages ​​make it possible for computers to perform tasks. From simple data processing to complex system operations, programming languages ​​are key tools for realizing these functions. Programming languages ​​have gone through different development processes from machine language, assembly language to high-level language, and their development and evolution directly reflect the development and changes in computer technology and application fields. At present, there are many high-level programming languages, such as Java, C / C++, JavaScript, Python, Ruby, PHP, Go, C#, etc. These programming languages ​​have their own characteristics and have been widely used since their creation. However, different programming languages ​​have different syntaxes, and one programming language cannot directly call the functions of another programming language if it wants to use them. Summary of the invention

[0003] In order to solve the problems existing in the prior art, the embodiments of the present application provide a method, apparatus, computing device, computer storage medium and product including a computer program for cross-programming language function conversion, which can automatically convert a function in one programming language into a function in another programming language.

[0004] In a first aspect, an embodiment of the present application provides a method for converting functions across programming languages, comprising: obtaining a first data type in a first programming language, and integrating the first data type into a conversion type set; storing the first data type in a data type table, the data type table comprising a basic data type table and a custom data type table; generating a data type relationship tree based on the conversion type set; and encapsulating the first data type and data corresponding to the first data type into a second programming language code based on the data type relationship tree and the data type table.

[0005] In some possible implementations, generating a data type relationship tree based on the conversion type set specifically includes: when the conversion type set is not empty, extracting a data type of a first programming language from the conversion type set, and determining whether the data type has been converted; when the data type has not been converted, querying the definition of the data type in the first programming language function library, extracting sub-elements contained in the definition and the data types of the sub-elements; and generating a data type relationship tree based on the data type and the data types of the elements and the sub-elements.

[0006] In some possible implementations, the determining whether the data type has been converted is specifically: querying the data type in the data type table; and if the data type is found in the data type table, confirming that the conversion has been completed.

[0007] In some possible implementations, the generating of the data type relationship tree includes: taking the data type containing the child element in the data type as the parent node, taking the data type of the child element as the child node, and constructing the data type relationship tree.

[0008] In some possible implementations, encapsulating the first data type and the data corresponding to the first data type into a second programming language code based on the data type relationship tree and the data type table specifically includes: traversing the data type relationship tree, selecting one of the parent nodes, and the child nodes of the parent node are all leaf nodes; selecting a template corresponding to the parent node in a data type template library; searching the data type table for a second data type after the data type of the element corresponding to the leaf node is converted; and generating a second programming language code for the data type corresponding to the parent node based on the template and the second data type.

[0009] In some possible implementations, the method further includes: generating an annotation corresponding to the data type of the element corresponding to the leaf node.

[0010] In some possible implementations, the method further includes: adding the comment to the second programming language code.

[0011] In some possible implementations, the method further includes: after generating the second programming language code, adding the data type corresponding to the parent node to the user-defined data type table.

[0012] In a second aspect, an embodiment of the present application provides a cross-programming language function conversion device, including: an acquisition module, used to acquire a first data type in a first programming language, and integrate the first data type into a conversion type set; storing the first data type in a data type table, the data type table including a basic data type table and a custom data type table; a processing module, used to generate a data type relationship tree based on the conversion type set; the processing module is also used to encapsulate the first data type and the data corresponding to the first data type into a second programming language code based on the data type relationship tree and the data type table.

[0013] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, comprising computer-readable instructions. When a computer reads and executes the computer-readable instructions, the computer executes the method described in any one of the first aspects.

[0014] In a fourth aspect, an embodiment of the present application provides a computing device, comprising a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the method described in any one of the first aspects is executed.

[0015] In a fifth aspect, an embodiment of the present application provides a product comprising a computer program. When the computer program product runs on a processor, the processor executes the method as described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0017] Figure 1 It is a flowchart of a method for converting functions across programming languages ​​provided in an embodiment of the present application;

[0018] Figure 2 It is a schematic diagram of a storage process of a set of data of a type to be converted provided by an embodiment of the present application;

[0019] Figure 3 is a schematic diagram of a data type relationship tree provided in an embodiment of the present application;

[0020] Figure 4 is a schematic diagram of another data type relationship tree provided in an embodiment of the present application;

[0021] Figure 5is a schematic diagram of another data type relationship tree provided in an embodiment of the present application;

[0022] Figure 6 It is a structural schematic diagram of a cross-programming language function conversion device provided by an embodiment of the present application;

[0023] Figure 7 It is a schematic diagram of the computing device structure provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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 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 are within the scope of protection of the present invention.

[0025] The term "and / or" in this article is a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The symbol " / " in this article indicates that the associated objects are in an or relationship, for example, A / B means A or B.

[0026] The terms "first" and "second" in the specification and claims herein are used to distinguish different objects rather than to describe a specific order of the objects. For example, a first response message and a second response message are used to distinguish different response messages rather than to describe a specific order of the response messages.

[0027] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0028] In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two. For example, multiple processing units refer to two or more processing units, etc.; multiple elements refer to two or more elements, etc.

[0029] To facilitate understanding of the embodiments of the present application, the following will further explain and illustrate specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present invention.

[0030] C language is one of the most commonly used and oldest programming languages ​​to date. It was created in the early 1970s. As a general-purpose computer programming language, the design goal of C language is to provide a programming language that can be compiled in a simple way, process low-level memory, generate a small amount of machine code, and can run without any operating environment support. Therefore, it is widely used. Python is an object-oriented interpreted computer programming language invented by the Dutch in 1989, and the first public release was released in 1991. Python has concise and clear syntax and rich and powerful libraries. Since C language was created earlier and has good operating efficiency, it is used in many project programming, but then Python language is adopted by more and more users due to its simple programming style. As a result, the function library originally implemented by C language needs to be called by Python language, so as to avoid the duplication of work caused by re-implementing the original function library in Python, and can also make full use of the advantages of higher operating efficiency of C language programs. However, Python language calls C language functions and needs to be encapsulated. This work can be done with the help of some ready-made frameworks, such as Cython, cffi, ctypes, pybind11, etc., which can greatly reduce the workload. However, the above encapsulation process inevitably requires the extraction and conversion of various data types in the C language function source code so that they can be understood and referenced by Python. This is the most essential and important task in the entire encapsulation process. This requires a very good understanding of both programming languages ​​and the details required for the conversion. This puts forward high requirements, making the conversion process more difficult.

[0031] At present, there are existing software frameworks such as Cython, cffi, ctypes, and pybind11 to reduce the workload of interface conversion between C / C++ and Python. However, in the actual encapsulation process, the custom data types in the C language function library need to be reconverted into the data types corresponding to the Python language, and then the function is encapsulated based on the converted data types. It can be seen that the most essential and important work in the conversion process is to convert the data types involved in the C language function interface into data types that Python can understand and reference.

[0032] In view of this, the embodiment of the present application provides a method for converting functions across programming languages, which focuses on automatically converting C language functions into Python language functions by establishing core data structures such as a set of types to be converted, a data type table, and a template library, so that the Python programming language can be called more conveniently and concisely. It is worth noting that the present application is described by taking the conversion of a C language function into a Python language function as an example, which does not constitute a limitation of the present application, and the programming language can be equivalently replaced by any programming language, such as converting a C++ language function into a Python language function, etc.

[0033] For example, Figure 1 The flowchart of a method for converting a function across programming languages ​​provided by an embodiment of the present application is shown. The method is used to convert a function in a first programming language into a function in a second programming language. Exemplarily, the first programming language is C language and the second programming language is Python language. The following description of the solution is based on C language and Python language. Figure 1 As shown, the method may include the following steps:

[0034] S11: Obtain a first data type in a first programming language, integrate the first data type into a conversion type set, and store the first data type in a data type table. The data type table includes a basic data type table and a custom data type table.

[0035] In this embodiment, in the C language function definition that needs to be encapsulated, the return value of the function and the data type of each parameter in the function are extracted to form a data type set to be converted, which is referred to as the conversion type set here. The set can be stored in a queue in the data structure. In the following operation, the main goal is to use a first-in-first-out method to convert the data types in the conversion type set to be converted into the data types corresponding to Python in turn. At the same time, the data type can also be stored in a data type table. The data type table is divided into a basic data type table and a custom data type table. The basic data type table is used to store basic data types in C language, such as int, float, etc. The data type in the basic data type is a data type with a clear type conversion method, that is, a conversion method from C language to Python language is clearly defined. Basic data types include integer, floating point, Boolean, etc. The custom data type table is used to store custom combined data types in the C language function library, such as struct, enumeration, macro definition (i.e. #define) and typedef defined in the function library. There is no clearly defined conversion method for custom data types. The data type table can also store Python data types after conversion of basic data types and Python data types after conversion of custom data types.

[0036] For example, there are two functions in the C language function library that need to be converted into Python language functions, which are defined as follows:

[0037]

[0038] The first data type includes the basic data types int and double. Int and double are integrated into a conversion type set.

[0039] In some possible embodiments, the first data type also includes a custom data type. For example, in the above example, the two structures params_s and params_t are custom data types. The two structures of the custom data types params_s and params_t in the function library are defined as follows:

[0040]

[0041]

[0042] In the params_s structure, in addition to the basic data types int and double, there is also a new custom structure params_c. Its definition is as follows:

[0043]

[0044] In this embodiment, in the add function, the data type of its return value is int, and the data types of the parameters are params_s and params_t. In the cal function, the data type of its return value is double, and the data types of the parameters are params_t, double, and double. These data types are sequentially stored in the set of types to be converted. Therefore, there may be repeated data types in the set of data types to be converted.

[0045] S12: Generate a data type relationship tree based on the conversion type set.

[0046] In the present embodiment, after the data type set to be converted is integrated, a C language data type is extracted from the type set to be converted to determine whether it is a converted data type. If it has been converted, then when the set to be converted is not empty, continue to process the next data type. If it has not been converted, it is necessary to find the definition of the data type in the C language function library, analyze and extract the sub-elements and their data types therein, build a data type relationship tree, and store the data types of all sub-elements in the type set to be converted in sequence. Circularly extract elements from the type set to be converted for processing until the type set to be converted is empty. When processing, first determine whether the data type has been converted to the data type corresponding to python. Specifically, the data type is queried and compared with the data type table. If the same type is found in the data type table, it indicates that the type conversion has been realized. At this point, the conversion process of the data type ends, and the next data type in the type set to be converted is extracted cyclically for operation. On the contrary, if the same data type is not found in the data type table, it indicates that the data type has not yet implemented the type conversion process.

[0047] In some possible embodiments, the type conversion process specifically includes: searching for a definition of the data type in a C language function library, extracting the data type of the sub-element from the definition, storing the data type of the sub-element in a conversion type set, and constructing a data type relationship tree based on the conversion type set.

[0048] For example, Figure 2 The schematic diagram of the storage process of the data set of the type to be converted is shown in FIG. Figure 2 As shown, the return value data type and parameter data type in the add function and the cal function are stored to obtain a queue, that is, Figure 2(a) in the table. Due to the first-in-first-out feature of the queue, int must be processed first. Query the data type table and find the corresponding item in the basic data type table, indicating that the data type already has a clear type conversion method and the conversion process of the data type is completed. Then query the set of types to be converted and it is not empty, then extract the next data type params_s from the set of types to be converted again. There is no corresponding item in the data type table, indicating that there is no clear type conversion method for the data type and type conversion is required. Next, find the definition of the data type in the source code of the C language function library. Extract the data types of the sub-elements in the source code of params_s, which are int, int, double, and struct params_c, respectively, and store them in the set of types to be converted in turn, and you can get the following: Figure 2 The new queue shown in (b) in the figure. Since the first element int in the queue has been processed, it is removed from the queue. The element currently being processed is params_s, so it has not been removed yet and will be removed after the processing is completed.

[0049] Next, construct a data type relationship tree. Since the logic of the code is to define first and then reference (i.e., it can be referenced only after definition), the construction of the data type relationship tree is mainly to prevent the occurrence of logical order errors of first reference and then definition. Specifically, for a composite data type (i.e., the data type contains child elements, such as struct, enumeration, etc.), the data type is used as the parent node, and the data type of the child element in the type is the child node to form a simple data type relationship tree. If there is a non-basic data type in the child node (i.e., the data type contained in the C language function itself), the child node will continue to be the new parent node, and the data type of the child element in it will be the next-level child node, and the cycle will repeat until all leaf nodes (i.e., nodes without child nodes) are basic data types. It should be noted that the data type relationship tree needs to be generated for all C language functions that need to be converted, rather than generating a data type relationship tree for a single function. Because the essence of the data type relationship tree is to record the subordinate relationship between various data types, so as to ensure that the correct declaration order between each other is maintained when defining the data type, otherwise the situation of first reference and then definition will cause the Python program to report an error.

[0050] For example, please refer to Figure 3 , with params_s as the parent node, including int, int, double, and params_c as the child nodes. This parent-child node relationship in the relationship tree mainly implies the subordinate relationship between the nodes, so as to maintain the correct order relationship when generating code later.

[0051] At this point, the processing of the element params_s has been completed, and the conversion type set is continued to be determined whether it is empty. If it is not empty, the next element params_t is processed. For example, please refer to Figure 4 After the element params_t is processed, the generated data type relationship tree is as follows Figure 4 As shown. The data type relationship tree now contains two independent trees, which means there is no association between the two trees. Therefore, when generating code later, there is no need to consider the order between the two trees.

[0052] The elements in the conversion type set are processed in sequence. When the element params_c is processed, the params_c node is changed from a leaf node to a non-leaf node. Figure 5 , Figure 5 This is a schematic diagram of the complete data type relationship tree. Figure 5 As shown, in Figure 4 Based on the above, two leaf nodes are added, namely int node and double node. The original leaf node params_c becomes a non-leaf node.

[0053] The next data type in the set of types to be converted is extracted cyclically for operation. This preprocessing process finally obtains the relationship tree of all data types for use in subsequent steps.

[0054] S13: Based on the data type relationship tree, encapsulate the first data type and its corresponding data into a second programming language code.

[0055] In this embodiment, after generating the data type relationship tree, the data type relationship tree is traversed, and the parent node whose all child nodes are leaf nodes is selected in turn, and the template corresponding to the parent node is selected from the data type template library for the parent node. At the same time, the data type table can also be queried to find the Python data type after the data type of the element corresponding to the leaf node is converted in the data type table. According to the template obtained by the query and the converted Python data type, the Python definition source code of the parent node data type is generated. The parent node and its child nodes are cut out in the data type relationship tree. Repeat the above process until all nodes have completed the integration of the definition module, and all data type conversion source codes involved have been generated. For the encapsulation of the relevant function interface, Python encapsulation code can be generated according to the adopted framework and format. The data type template library contains corresponding templates for how to convert the custom combined data type in the C language into the Python language data type. For example, for macro definitions (i.e. #define), the conversion can be achieved using the corresponding templates in the template library. Correspondingly, struct and enumeration have corresponding templates that can be used for reference.

[0056] Specifically, traverse the data type relationship tree, select the node that meets the conditions, the node is used as the parent node, and all its child nodes are leaf nodes. According to the type of the node (for example, struct, enumeration, typedef or #define, etc.), extract the corresponding template from the data type conversion template library, and according to the characteristics of different data types, query the converted data type expression from the data type table one by one according to the sub-elements in the data type, so as to generate the data type module corresponding to the Python language package. If there are still nodes in the data type relationship tree, it means that there are still data types that need to be converted, and the above process is looped until the data type relationship tree is empty. So far, all the data type conversion source codes involved have been generated. For the encapsulation of the relevant function interface, Python encapsulation code can be generated according to the adopted framework and format.

[0057] For example, please continue to refer to Figure 5 ,like Figure 5 As shown, select a node whose all child nodes are leaf nodes, params_c and params_t meet the requirements, randomly select one of them, for example, select params_c, because the data structure is a structure diagram (i.e. struct), so select the template corresponding to struct from the data type template library, and the data types of its child nodes are int and double respectively. Find the converted Python data types from the data type table, i.e. c_uint32 and c_double, and thus generate the source code of the data type params_c after conversion. The example is as follows:

[0058]

[0059] In some possible embodiments, comments corresponding to the leaf node data type can also be generated. The comments are automatically generated for the code module, first automatically including which line of which source code file in the C language function library the data type is defined, that is, the source of the data type. Then the comments and source code in the source code file corresponding to the data type are included, so that the source code after the subsequent Python encapsulation can easily locate the source and definition.

[0060] Let's take params_c node as an example. Its definition position in the C language source code is line n in abc.h. Copy the corresponding comment in the source code to the converted source code. The example is as follows:

[0061]

[0062] After generating the above source code and comments, add the data type to the custom data type table, and cut out the nodes involved from the data type relationship tree to obtain the following: Figure 4 The new relationship tree is shown. Since the relationship tree is not empty, the above process is repeated to process the two data types params_s and parmas_t and generate related codes. In this process, the data type relationship tree ensures the correct order of different data types when defining and declaring. That is, in the above example, struct params_c must be defined before struct params_s, otherwise an error will be reported because the definition of struct params_c cannot be found when structparams_s is defined.

[0063] The above process finally generates the Python source code after all data types are converted. Next, the function interface can be encapsulated. For example, the defined add code "int add(structparams_sa,structparams_tb);" can be encapsulated as the following code

[0064]

[0065] At this point, the automatic encapsulation of the function is completed, and the function can be called smoothly in the Python code.

[0066] The above is a cross-programming language function conversion method provided by the embodiment of the present application. By extracting the return value type and the type of each parameter from the C language function definition that needs to be encapsulated, a set of types to be converted is formed, and a data type relationship tree is constructed for the data in the set of types to be converted. Based on the constructed data type relationship tree, Python encapsulation code is generated. It can be seen that in this method, the data type table is a very important data structure, which can be further divided into a basic data type table and a custom data type table. Wherein the basic data type table contains the basic data types in the C language, such as int, float, etc. And what is contained in the custom data type table is the custom combined data type in the C language function library, and the custom data type that has been converted will be gradually increased during the processing. For example, various data types such as struct, enumeration, macro definition (i.e. #define) and typedef defined in the function library. The basic data type table will be created in advance, mainly including two items, namely the basic data types in the C language and the corresponding data types in python after being converted. The custom data type table is similar to this. Compared with the basic data type table, the difference between the two is that the table will gradually increase as the custom data type is converted. Through this method, a function in one programming language can be automatically converted into a function in another programming language, which facilitates cross-language function calls.

[0067] It is understandable that the size of the sequence number of each step in the above-mentioned embodiments does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, in some possible implementations, the steps in the above-mentioned embodiments can be selectively executed according to actual conditions, and can be partially executed or fully executed, which is not limited here. All or part of any feature of any embodiment of the present application can be freely and arbitrarily combined without contradiction. The combined technical solution is also within the scope of the present application.

[0068] Based on the method in the above embodiment, the embodiment of the present application also provides a cross-programming language function conversion device.

[0069] For example, Figure 6 A cross-programming language function conversion device is shown, which is deployed on a computing device. The cross-programming language function conversion device 600 includes: an acquisition module 601 and a processing module 602 .

[0070] Among them, the acquisition module 601 is used to obtain a first data type in a first programming language, integrate the first data type into a conversion type set; store the first data type in a data type table, and the data type table includes a basic data type table and a custom data type table.

[0071] The processing module 602 is used to generate a data type relationship tree based on the conversion type set.

[0072] The processing module 602 is further configured to encapsulate the first data type and data corresponding to the first data type into a second programming language code based on the data type relationship tree and the data type table.

[0073] It should be understood that the above-mentioned device is used to execute the method in the above-mentioned embodiment. The implementation principle and technical effect of the corresponding program module in the device are similar to those described in the above-mentioned method. The working process of the device can refer to the corresponding process in the above-mentioned method, which will not be repeated here.

[0074] The present application also provides a computing device 700. Figure 7 As shown, computing device 700 includes: bus 702, processor 704, memory 706 and communication interface 708. Processor 704, memory 706 and communication interface 708 communicate through bus 702. Computing device 700 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in computing device 700.

[0075] The bus 702 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 The bus 704 is represented by only one line, but does not mean that there is only one bus or one type of bus. The bus 704 may include a path for transmitting information between various components of the computing device 700 (eg, the memory 706, the processor 704, and the communication interface 708).

[0076] The processor 704 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0077] The memory 706 may include a volatile memory, such as a random access memory (RAM). The processor 704 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0078] The memory 706 stores executable program codes, and the processor 704 executes the executable program codes to respectively implement the functions of the acquisition module 601 and the processing module 602, thereby implementing all or part of the steps of the method in the above embodiment. That is, the memory 706 stores instructions for executing all or part of the steps in the method in the above embodiment.

[0079] Alternatively, the memory 706 stores executable codes, and the processor 704 executes the executable codes to respectively implement the functions of the cross-programming language function conversion device 600, thereby implementing all or part of the steps in the above-mentioned embodiment method. That is, the memory 706 stores instructions for executing all or part of the steps in the above-mentioned embodiment method.

[0080] The communication interface 708 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 700 and other devices or communication networks.

[0081] Based on the methods in the above embodiments, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the methods in the above embodiments.

[0082] Based on the methods in the above embodiments, an embodiment of the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the methods in the above embodiments.

[0083] It is understood that the processor in the embodiments of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.

[0084] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.

[0085] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.

[0086] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.

Claims

1. A method for converting functions across programming languages, characterized in that: The method comprises: Acquire a first data type in a first programming language, and integrate the first data type into a conversion type set; store the first data type in a data type table, wherein the data type table includes a basic data type table and a user-defined data type table; Based on the conversion type set, generate a data type relationship tree; Based on the data type relationship tree and the data type table, the first data type and data corresponding to the first data type are encapsulated into a second programming language code.

2. The method according to claim 1, characterized in that The generating a data type relationship tree based on the conversion type set specifically includes: When the conversion type set is not empty, extracting a data type of the first programming language from the conversion type set, and determining whether the data type has been converted; In the case where the data type has not been converted, querying the definition of the data type in the first programming language function library, and extracting sub-elements contained in the definition and the data types of the sub-elements; A data type relationship tree is generated based on the data type and the data types of the element and the sub-element.

3. The method according to claim 2, characterized in that The determining whether the data type has been converted is specifically as follows: Query the data type in the data type table; When the data type is found in the data type table, it is confirmed that the conversion has been achieved.

4. The method according to any one of claims 1 to 3, characterized in that: The generating of the data type relationship tree comprises: The data type containing the child element in the data type is taken as the parent node, and the data type of the child element is taken as the child node, so as to construct a data type relationship tree.

5. The method according to claim 1, characterized in that: The step of encapsulating the first data type and data corresponding to the first data type into a second programming language code based on the data type relationship tree and the data type table specifically includes: Traverse the data type relationship tree and select one of the parent nodes, wherein the child nodes of the parent node are all leaf nodes; Selecting a template corresponding to the parent node in a data type template library; Searching the data type table for a second data type after the data type of the element corresponding to the leaf node is converted; Based on the template and the second data type, a second programming language code of the data type corresponding to the parent node is generated.

6. The method according to claim 5, characterized in that The method also includes: generating comments corresponding to the data type of the element corresponding to the leaf node.

7. The method according to claim 6, characterized in that The method further includes adding the comment in the second programming language code.

8. The method according to any one of claims 5 to 7, characterized in that: The method further includes: after generating the second programming language code, adding the data type corresponding to the parent node to the user-defined data type table.

9. A device for converting functions across programming languages, characterized in that: The device comprises: An acquisition module is used to acquire a first data type in a first programming language, integrate the first data type into a conversion type set; store the first data type in a data type table, the data type table includes a basic data type table and a user-defined data type table; A processing module, used for generating a data type relationship tree based on the conversion type set; The processing module is further used to encapsulate the first data type and data corresponding to the first data type into a second programming language code based on the data type relationship tree and the data type table.

10. A computing device comprising a processor and a memory, wherein: The memory stores computer program instructions, and when the computer program instructions are executed by the processor, the method according to any one of the first aspects is executed.