Code generation method and device, user equipment and storage medium

By obtaining and filling the definition language and meta description information in the interface definition language IDL file, cross-language call code is generated, which solves the problem of syntax errors and data type mismatch in interface calls of different programming languages, and improves development efficiency.

CN120215894APending Publication Date: 2025-06-27BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311800772.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-25
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

During the interface call process of cross-programming languages, due to differences in syntax and data types of different programming languages, direct call may lead to syntax errors or mismatch of data types, resulting in inefficient development and cannot meet the needs of large-scale cross-language calling code development in a short period of time.

Method used

By obtaining the definition language and meta description information in the interface definition language IDL file and populating it into the code generation template, cross-language call code is generated, thereby realizing interface calls between different programming languages.

Benefits of technology

It improves the efficiency of generating cross-language calling code, reduces the workload of developers, and meets the needs of large-scale cross-language calling code development in a short period of time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120215894A_ABST
    Figure CN120215894A_ABST
Patent Text Reader

Abstract

The invention relates to a code generation method and device, user equipment and a storage medium. An interface definition language (IDL) file is obtained, the IDL file comprises a definition language used for describing interface information corresponding to the first interface code and meta description information used for describing calling related to a second interface code, the first interface code adopts a first programming language, and the second interface code adopts a second programming language; the first programming language and the second programming language are different types of programming languages. And a code generation module is obtained, and the code generation module is used for generating a cross-language calling code for the second interface code. And extracting a definition language and meta description information from the IDL file, and filling the definition language and meta description information into a corresponding code region in the code generation template to generate a cross-language calling code corresponding to the second interface code. Therefore, the efficiency of automatically generating the cross-language call code is improved, and the requirement for large-scale cross-language call code development in a short time is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a user equipment, and a storage medium for generating code. Background Art

[0002] With the development of computer technologies, people's lives have become increasingly dependent on computer technologies. To meet various needs, various programming languages have emerged. In the process of program development, there are often situations of cross-departmental collaborative development. Since different departments use different programming languages, there are many scenarios of interface calls across programming languages in the process of collaborative development.

[0003] Due to differences in grammar, data types, compilers, or interpreters between different programming languages, direct calls may lead to problems such as syntax errors or data type mismatches.

[0004] To achieve interface calls across programming languages, developers need to master two different programming languages at the same time and write cross-language call code according to the programming languages of these two interface codes.

[0005] However, the efficiency of manually modifying interface code is low and cannot meet the requirements of large-scale cross-language call code development in a short time. Summary of the Invention

[0006] The present disclosure provides a method, an apparatus, a user equipment, and a storage medium for generating code to solve the deficiencies in the related technologies.

[0007] According to a first aspect of an embodiment of the present disclosure, a method for generating code is proposed, including:

[0008] Obtain an Interface Definition Language (IDL) file, where the IDL file contains a definition language for describing interface information corresponding to a first interface code and meta-description information related to the call of a second interface code. The first interface code uses a first programming language, the second interface code uses a second programming language, and the first programming language and the second programming language are different types of programming languages;

[0009] Obtain a code generation template, where the code generation module is used to generate cross-language call code for the second interface code;

[0010] Extract the definition language and the meta-description information from the IDL file, and fill the definition language and the meta-description information into a code area in the code generation template corresponding to the second interface code to generate cross-language call code corresponding to the second interface code, so that the first interface code can call the second interface code through the cross-language call code.

[0011] Optionally, the cross - language call code is glue code for implementing cross - language calls for the second interface code.

[0012] Optionally, before filling the definition language and the meta - description information into the code area of the code generation template corresponding to the second interface code to generate cross - language call code corresponding to the second interface code, the method further includes:

[0013] Parsing the IDL file to obtain an abstract syntax tree corresponding to the IDL file;

[0014] Filling the definition language and the meta - description information into the code area of the code generation template corresponding to the second interface code to generate cross - language call code corresponding to the second interface code includes:

[0015] Based on the abstract syntax tree corresponding to the IDL file, generating a syntax structure corresponding to the abstract syntax tree in the code generation template, filling the definition language and the meta - description information into the corresponding code area in the code generation template, and filling the definition language and the meta - description information into the syntax structure corresponding to the abstract syntax tree to generate cross - language call code corresponding to the second interface code.

[0016] Optionally, parsing the IDL file to obtain an abstract syntax tree corresponding to the IDL file includes:

[0017] Splitting the definition language and the meta - description information included in the IDL file to obtain at least one lexical unit;

[0018] Performing syntax analysis on each of the at least one lexical unit, and further using the at least one lexical unit as nodes based on the syntax analysis result to construct an abstract syntax tree corresponding to the IDL file.

[0019] Optionally, filling the definition language and the meta - description information into the code area of the code generation template corresponding to the second interface code to generate cross - language call code corresponding to the second interface code includes:

[0020] Filling the definition language and the meta - description information into the corresponding code area in the code generation template to generate interface generation code corresponding to the second interface code;

[0021] Obtain the framework code for constructing the basic framework structure and core functions of the executable program, and fill the interface generation code into the framework code to generate cross-language call code corresponding to the second interface code.

[0022] Optionally, the method further includes:

[0023] Obtain the IDL file corresponding to the third interface, where the IDL file corresponding to the third interface contains meta-description information for describing the call related to the third interface code;

[0024] Obtain the code generation template for the cross-language call code corresponding to the third interface code for forwarding call information to the second interface code, where the programming language used for the third interface code is the same as the programming language used for the second interface code;

[0025] Fill the definition language and the meta-description information for describing the call related to the third interface code into the corresponding code area in the code generation template corresponding to the third interface code to generate cross-language call code corresponding to the third interface code, so that the first interface code can call the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

[0026] Optionally, the first interface code is the interface code corresponding to the application interface included in the application installed in the operating system carried by the electronic device; the second interface code is the interface code corresponding to the application interface included in the system function in the operating system carried by the electronic device.

[0027] Optionally, the electronic device includes: an embedded device.

[0028] According to the second aspect of the embodiments of the present disclosure, a code generation device is proposed, and the device includes:

[0029] A first acquisition module for acquiring an Interface Definition Language (IDL) file, where the IDL file contains a definition language for describing interface information corresponding to the first interface code and meta-description information for describing the call related to the second interface code, the first interface code uses a first programming language, the second interface code uses a second programming language, and the first programming language and the second programming language are different types of programming languages;

[0030] A second acquisition module for acquiring a code generation template, and the code generation module is used to generate cross-language call code for the second interface code;

[0031] A generation module, configured to extract the definition language and the meta-description information from the IDL file, and fill the definition language and the meta-description information into corresponding code areas in the code generation template, to generate cross-language call code corresponding to the second interface code, so that the first interface code can call the second interface code through the cross-language call code.

[0032] Optionally, the cross-language call code is glue code for implementing cross-language call for the second interface code.

[0033] Optionally, the device further includes:

[0034] A parsing module, configured to parse the IDL file to obtain an abstract syntax tree corresponding to the IDL file;

[0035] The generation module includes:

[0036] A filling module, configured to generate a syntax structure corresponding to the abstract syntax tree in the code generation template based on the abstract syntax tree corresponding to the IDL file, fill the definition language and the meta-description information into corresponding code areas in the code generation template, and fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree, to generate cross-language call code corresponding to the second interface code.

[0037] Optionally, the parsing module includes:

[0038] A splitting module, configured to split the definition language and meta-description information included in the IDL file to obtain at least one lexical unit;

[0039] A construction module, configured to perform syntax analysis on each of the at least one lexical unit, and further use the at least one lexical unit as a node based on the syntax analysis result to construct an abstract syntax tree corresponding to the IDL file.

[0040] Optionally, the generation module includes:

[0041] A first filling module, configured to fill the definition language and the meta-description information into corresponding code areas in the code generation template to generate interface generation code corresponding to the second interface code;

[0042] A second filling module, configured to obtain framework code for constructing a basic framework structure and core functions of an executable program, and fill the interface generation code into the framework code to generate cross-language call code corresponding to the second interface code 。

[0043] Optionally, the device further includes:

[0044] A first acquisition module, configured to acquire an IDL file corresponding to the third interface, where the IDL file corresponding to the third interface contains meta-description information for describing the invocation of the code of the third interface;

[0045] A second acquisition module, configured to acquire a code generation template of a cross-language call code corresponding to the third interface code for forwarding call information to the second interface code, where the programming language used by the third interface code is the same as the programming language used by the second interface code;

[0046] A forwarding module, configured to fill the definition language and the meta-description information for describing the invocation of the code of the third interface into a corresponding code area in the code generation template corresponding to the third interface code, generate a cross-language call code corresponding to the third interface code, so that the first interface code invokes the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

[0047] Optionally, the first interface code is an interface code corresponding to an application interface included in an application installed in an operating system carried by an electronic device; the second interface code is an interface code corresponding to an application interface included in a system function in an operating system carried by the electronic device.

[0048] Optionally, the electronic device includes: an embedded device.

[0049] According to a third aspect of the embodiments of the present disclosure, a user device is provided, including:

[0050] A processor;

[0051] A memory for storing processor-executable instructions;

[0052] Wherein, the processor is configured to implement the method for generating code as described above.

[0053] According to a fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, it is used to implement the method for generating code as described above.

[0054] The technical solutions provided by the embodiments of the present disclosure can at least include the following beneficial effects:

[0055] According to an embodiment of the present disclosure, an IDL file is obtained. The IDL file contains a definition language for describing interface information corresponding to a first interface code and a meta-description information for describing the call related to a second interface code. The first interface code is in a first programming language, and the second interface code is in a second programming language. The first programming language and the second programming language are different types of programming languages. Also, a code generation template is obtained. Then, the definition language and the meta-description information in the IDL file are filled into the code area in the code generation template to automatically generate cross-language call code. Thus, the efficiency of generating cross-language call code is improved, and the requirement for large-scale cross-language call code development in a short time is met. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] To more clearly illustrate the technical solutions in the embodiments of the present disclosure, the following briefly introduces the accompanying drawings required for the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present disclosure. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0057] Figure 1 is a schematic flowchart of a method for generating code according to an embodiment of the present disclosure.

[0058] Figure 2 is a schematic diagram of an IDL file according to an embodiment of the present disclosure.

[0059] Figure 3 is a schematic structural diagram of a generated code according to an embodiment of the present disclosure.

[0060] Figure 4 is based on Figure 1 shown in the embodiment and is a schematic flowchart of another method for generating code.

[0061] Figure 5 is a schematic diagram of a code generation template according to an embodiment of the present disclosure.

[0062] Figure 6 is based on Figure 1 shown in the embodiment and is a schematic flowchart of another method for generating code.

[0063] Figure 7 is based on Figure 1 shown in the embodiment and is a schematic flowchart of another method for generating code.

[0064] Figure 8 is based on Figure 1 shown in the embodiment and is a schematic flowchart of another method for generating code.

[0065] Figure 9 It is a schematic diagram of an executable program shown according to an embodiment of the present disclosure.

[0066] Figure 10 It is a schematic block diagram of a device for generating code shown according to an embodiment of the present disclosure.

[0067] Figure 11 It is based on Figure 10 shown in the embodiment, and is a schematic block diagram of another device for generating code.

[0068] Figure 12 It is based on Figure 10 shown in the embodiment, and is a schematic block diagram of another device for generating code.

[0069] Figure 13 It is based on Figure 10 shown in the embodiment, and is a schematic block diagram of another device for generating code.

[0070] Figure 14 It is based on Figure 10 shown in the embodiment, and is a schematic block diagram of another device for generating code.

[0071] Figure 15 It is a schematic block diagram of a device for generating code shown according to an embodiment of the present disclosure. Detailed implementation manners

[0072] Next, the technical solutions in the embodiments of the present disclosure will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.

[0073] Due to differences in aspects such as syntax, data types, compilers or interpreters between different programming languages, direct calls may cause problems such as syntax errors or data type mismatches.

[0074] To achieve cross - programming - language interface calls, it is necessary for developers to master two different programming languages at the same time and write cross - language call code according to the programming languages of these two interface codes.

[0075] However, the efficiency of manually modifying interface code is low and cannot meet the requirements for large - scale cross - language call code development in a short time.

[0076] Please refer to Figure 1 ,Figure 1 It is a schematic flowchart of a method for generating code shown according to an embodiment of the present disclosure. As Figure 1 shown, the method for generating code may include the following steps:

[0077] In step 102, an Interface Definition Language (IDL) file is obtained. The IDL file contains a definition language for describing interface information corresponding to a first interface code and meta-description information for describing the call related to a second interface code. The first interface code uses a first programming language, and the second interface code uses a second programming language. The first programming language and the second programming language are different types of programming languages.

[0078] In a possible implementation manner, the method for generating code may be applied to an electronic device, and the electronic device may include: an embedded device with an embedded system. The embedded device may be a mobile phone, a tablet personal computer, a laptop computer, a personal digital assistant (PDA), a mobile internet device (MID), or a wearable device, such as a watch, a bracelet, etc. For the sake of convenience of description, hereinafter, only the embedded device is used as the execution subject to describe the method for generating code provided in this specification.

[0079] In a possible implementation manner, the embedded device may obtain an Interface Definition Language (IDL) file. The IDL file contains a definition language for describing interface information corresponding to a first interface code and meta-description information for describing the call related to a second interface code. The first interface code uses a first programming language, and the second interface code uses a second programming language. The categories of the first programming language and the second programming language mentioned here may include: JavaScript, TypeScript, C++, C, Python, etc. Among them, the first programming language and the second programming language are different types of programming languages.

[0080] For example, the first programming language is JavaScript, and the second programming language is C. For another example, the first programming language is JavaScript, and the second programming language is C++. The present disclosure does not limit the categories of the first programming language and the second programming language.

[0081] Interface Description Language (IDL) can be an interface description specification independent of programming languages for describing application interfaces and is the basis for cross - programming - language development. IDL describes interfaces through a neutral language, enabling applications written in different programming languages to communicate through cross - language call codes.

[0082] Furthermore, the definition language defines the method names, parameters, return values, etc. of the interface information corresponding to the first interface code. The meta - description information is in a JSON - like format, consisting of key - value pairs (key / value), using curly braces to represent objects and square brackets to represent arrays. The meta - description information defines the parameters, attributes, etc. related to the invocation of the second interface code. And the meta - description information can be customized and extended according to business requirements.

[0083] Please refer to Figure 2 , Figure 2 which is a schematic diagram of an IDL file shown according to an embodiment of the present disclosure.

[0084] As Figure 2 shown, "module" can be used to define the module name and module version. "interface Widget" can be used to define an interface named Widget. "set" and "get" specify the setting method and getting method of attributes. "property" can be used to define attributes. "Int" can refer to an integer attribute. "String" can refer to a string attribute. "tag" can be used to define the tag of the interface. "interface Label extends Widget" can be used to define an interface named Label, and the interface named Label inherits from the interface named Widget. Among them, the interface named Widget can contain a definition language for describing the interface information corresponding to the first interface code. The interface named Label can contain meta - description information related to the invocation of the second interface code.

[0085] In a possible implementation, the first interface code is the interface code corresponding to the application interface included in the application installed in the operating system carried by the electronic device. The second interface code is the interface code corresponding to the application interface included in the system functions of the operating system carried by the electronic device.

[0086] In step 104, obtain a code generation template, and the code generation module is used to generate cross - language call codes for the second interface code.

[0087] In a possible implementation, obtain a code generation template, and the code generation module is used to generate cross - language call codes for the second interface code.

[0088] Among them, the cross - language call code can be glue code for implementing cross - language calls for the second interface code.

[0089] In step 106, the definition language and the meta - description information are extracted from the IDL file, and the definition language and the meta - description information are filled into the code area in the code generation template corresponding to the second interface code to generate cross - language call code corresponding to the second interface code, so that the first interface code can call the second interface code through the cross - language call code.

[0090] In practical applications, the IDL file usually only contains the definition language for describing the interface information corresponding to the first interface code. That is to say, only part of the code related to the interface information corresponding to the first interface code can be automatically generated in the cross - language call code. Therefore, developers need to manually write part of the code for calling the second interface code according to the meta - description information related to the call of the second interface code.

[0091] In a possible implementation, the embedded device can extract the definition language and the meta - description information from the IDL file, and fill the definition language and the meta - description information into the code area in the code generation template corresponding to the second interface code to generate cross - language call code corresponding to the second interface code, so that the first interface code can call the second interface code through the cross - language call code.

[0092] Please refer to Figure 3 , Figure 3 which is a schematic diagram of an executable program shown according to an embodiment of the present disclosure.

[0093] As Figure 3 shown, assuming that the first programming language is JavaScript, the second programming language is C, and there is cross - language call code between the first interface code and the second interface code. The cross - language call code contains cross - language call code in C obtained from the definition language corresponding to the first interface code in JavaScript, and cross - language call code in C obtained from the meta - description information corresponding to the second interface code in C. Then, all the codes are jointly compiled to obtain an executable program, so that the first interface code can call the second interface code through the cross - language call code.

[0094] It can be seen from the above - mentioned embodiments that the embedded device can fill the definition language and the meta - description information in the IDL file into the code area in the code generation template, thereby automatically generating cross - language call code. Since there is no need to manually write part of the code for calling the second interface code, the workload of developers is greatly reduced, and the efficiency of generating cross - language call code is improved.

[0095] Please refer to Figure 4 , Figure 4 which is Figure 1 a schematic diagram of another method for generating code shown based on the embodiments illustrated. As Figure 4 shown, the method may further include:

[0096] In step 402, parse the IDL file to obtain an abstract syntax tree corresponding to the IDL file.

[0097] In a possible implementation, the embedded device may parse the IDL file to obtain an abstract syntax tree corresponding to the IDL file.

[0098] An abstract syntax tree (AST) is a tree-like representation of the abstract syntactic structure of code. Each node on the abstract syntax tree represents a structure in the source code. The reason why the syntax is "abstract" is that the syntax here does not represent every detail that appears in the real syntax.

[0099] In step 404, based on the abstract syntax tree corresponding to the IDL file, generate a syntax structure corresponding to the abstract syntax tree in the code generation template, fill the definition language and the meta-description information into the corresponding code area in the code generation template, and fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree to generate cross-language call code corresponding to the second interface code.

[0100] In a possible implementation, the embedded device may generate a syntax structure corresponding to the abstract syntax tree in the code generation template based on the abstract syntax tree corresponding to the IDL file, fill the definition language and the meta-description information into the corresponding code area in the code generation template, and fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree to generate cross-language call code corresponding to the second interface code.

[0101] As can be seen from the above embodiments, the embedded device can fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree, without manually writing the part of the code related to the syntax structure in the cross-language call code, reducing the workload of developers and improving the efficiency of generating cross-language call code.

[0102] Please refer to Figure 5 , Figure 5 which is a schematic diagram of a code generation template shown according to an embodiment of the present disclosure.

[0103] As Figure 5As shown, the area after the '$' is the code area to be filled. The subsequent content of '% for inf indoc.interfaces:' can be used to represent the syntax structure corresponding to the abstract syntax tree.

[0104] Please refer to Figure 6 , Figure 6 is based on Figure 1 Another schematic flowchart of a method for generating code is shown based on the embodiments shown. As Figure 6 shown, the method may include:

[0105] In step 602, the definition language and the meta-description information included in the IDL file are segmented to obtain at least one lexical unit.

[0106] In a possible implementation, the embedded device may segment the definition language and the meta-description information included in the IDL file to obtain at least one lexical unit.

[0107] For example, the IDL file is input into a lexical analyzer, and according to preset rules, the definition language and the meta-description information included in the IDL file are segmented to obtain at least one lexical unit. The lexical units include: keywords, identifiers, operators, delimiters, etc.

[0108] In step 604, each of the at least one lexical unit is subjected to syntax analysis, and based on the syntax analysis result, the at least one lexical unit is further used as a node to construct an abstract syntax tree corresponding to the IDL file.

[0109] In a possible implementation, the embedded device may perform syntax analysis on each of the at least one lexical unit, and based on the syntax analysis result, further use the at least one lexical unit as a node to construct an abstract syntax tree corresponding to the IDL file.

[0110] For example, the at least one lexical unit is input into a syntax analyzer, and according to the grammar rules, syntax analysis is performed on each of the at least one lexical unit to determine the syntax analysis result. The syntax analysis result may refer to the type of the lexical unit, and the types include: keywords, identifiers, operators, delimiters, etc.

[0111] It should be noted that during the process of constructing the abstract syntax tree, semantic analysis of the IDL file may be performed. For example, checking for duplicate declarations of identifiers, verifying data type consistency, handling inheritance relationships, etc. The analysis result of the semantic analysis may directly modify the structure of the abstract syntax tree or add additional semantic information.

[0112] Please refer to Figure 7 , Figure 7 is based on Figure 1Schematic diagram of another method for generating code shown based on the illustrated embodiment. As Figure 7 shown, the method may further include:

[0113] In step 702, fill the definition language and the meta-description information into the corresponding code area in the code generation template to generate interface generation code corresponding to the second interface code.

[0114] In step 704, obtain framework code for constructing the basic framework structure and core functions of the executable program, and fill the interface generation code into the framework code to generate cross-language call code corresponding to the second interface code.

[0115] In practical applications, the technologies of cross-language call code used in different fields are not the same. For example, swig can encapsulate or transform interface code written in C / C++ into interface code in another programming language (such as python, java, php, ruby, etc.). IDL in the Chrome browser can convert interface code written in C++ into interface code written in JavaScript and only supports V8 (JavaScript engine). AIDL of the Android system can provide interface code written in C++ and interface code written in java for cross-process communication.

[0116] Since Chrome IDL must be within the Chrome environment and rely on the Chrome framework and engine. AIDL must be within the Android environment and rely on the Android framework and engine. Therefore, developers also need to develop framework code corresponding to the programming language used for the second interface code to generate cross-language call code corresponding to the second interface code.

[0117] In a possible implementation, the embedded device can fill the definition language and the meta-description information into the corresponding code area in the code generation template to generate interface generation code corresponding to the second interface code.

[0118] Then, the embedded device can obtain framework code for constructing the basic framework structure and core functions of the executable program, and fill the interface generation code into the framework code to generate cross-language call code corresponding to the second interface code. The programming language used for the framework code is the same as the programming language used for the second interface code.

[0119] As can be seen from the above embodiments, developers can develop framework code corresponding to the programming language used for the second interface code, thereby helping developers reduce repetitive work and further improving the efficiency of generating cross-language call code.

[0120] It should be noted that developers are divided into framework developers and interface developers. Framework developers can develop framework code and code generation templates based on the programming language adopted by the second interface code. Interface developers can develop IDL files based on the first interface code and the second interface code.

[0121] That is to say, relatively complex framework code and code generation templates are developed by professional developers, while relatively simple IDL files can be developed by non-professional developers.

[0122] Among them, only one framework code needs to be developed for one programming language, and only one code generation template needs to be developed for one system function. After the framework code and the code generation template are developed, when adding a new application interface, only one IDL file needs to be added, and there is no need to write implementation code anymore, thus realizing the automatic generation of cross-language call code.

[0123] Please refer to Figure 8 , Figure 8 which is Figure 1 a schematic diagram of another method for generating code shown based on the embodiments illustrated. As Figure 8 shown, the method may further include:

[0124] In step 802, obtain the IDL file corresponding to the third interface, and the IDL file corresponding to the third interface contains meta-description information for describing the call related to the third interface code;

[0125] In step 804, obtain the code generation template of the cross-language call code corresponding to the third interface code for forwarding call information to the second interface code, and the programming language adopted by the third interface code is the same as the programming language adopted by the second interface code.

[0126] In step 806, fill the definition language and the meta-description information for describing the call related to the third interface code into the corresponding code area in the code generation template corresponding to the third interface code to generate the cross-language call code corresponding to the third interface code, so that the first interface code can call the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

[0127] In practical applications, an embedded system in an embedded device usually has many functions. For example, Wifi control, Bluetooth control, software management, multimedia playback, etc. Developers usually use JavaScript or TypeScript to develop application software and develop functional software through C / C++. Cross-language calls are achieved by generating glue code between the two programming languages.

[0128] However, multiple independent processes can run simultaneously in an embedded system. When the interface codes of different types of programming languages are located in different processes, cross-process calls are required to achieve information exchange, resource sharing, and execution of specific tasks.

[0129] In a possible implementation, the embedded device can obtain an IDL file corresponding to a third interface. The IDL file corresponding to the third interface contains meta-description information for describing the calls related to the third interface code. Among them, the third interface code can be an interface code for message sending and message receiving. Different messages correspond to different message formats, and calls can be made according to a unified method.

[0130] Moreover, obtain a code generation template for the cross-language call code corresponding to the third interface code for forwarding call information to the second interface code. The programming language used for the third interface code is the same as the programming language used for the second interface code.

[0131] Then, the embedded device can fill the definition language and the meta-description information for describing the calls related to the third interface code into the corresponding code areas in the code generation template corresponding to the third interface code, generate the cross-language call code corresponding to the third interface code, so that the first interface code can call the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

[0132] Please refer to Figure 9 , Figure 9 which is a schematic diagram of an executable program shown according to an embodiment of the present disclosure.

[0133] As Figure 9As shown, assume that the first programming language is JavaScript, the second programming language is C, and there is cross-language call code between the first interface code and the third interface code. The cross-language call code includes cross-language call code in C obtained from the definition language corresponding to the first interface code in JavaScript, and cross-language call code in C obtained from the meta-description information corresponding to the third interface code in C. Then, all the codes are jointly compiled to obtain an executable program, so that the first interface code calls the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code through the message channel to complete the call to the second interface code.

[0134] As can be seen from the above embodiments, if it is determined that the two interface codes are in the same process, the first interface code calls the second interface code through the cross-language call code. If it is determined that the two interface codes are in different processes, the first interface code calls the second interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code through the message channel to complete the call to the second interface code.

[0135] Corresponding to the embodiments of the method for generating code described above, the present disclosure also provides embodiments of a device for generating code.

[0136] Please refer to Figure 10 , Figure 10 which is a schematic block diagram of a device for generating code shown according to an embodiment of the present disclosure. As Figure 10 shown, the device may include:

[0137] A first acquisition module 1002, configured to acquire an Interface Definition Language (IDL) file, where the IDL file includes a definition language for describing interface information corresponding to the first interface code and meta-description information related to the call of the second interface code. The first interface code uses a first programming language, the second interface code uses a second programming language, and the first programming language and the second programming language are different types of programming languages;

[0138] A second acquisition module 1004, configured to acquire a code generation template, where the code generation module is used to generate cross-language call code for the second interface code;

[0139] A generation module 1006, configured to extract the definition language and the meta-description information from the IDL file, and fill the definition language and the meta-description information into corresponding code areas in the code generation template to generate cross-language call code corresponding to the second interface code, so that the first interface code calls the second interface code through the cross-language call code.

[0140] Please refer to Figure 11 , Figure 11 which is Figure 10 a schematic block diagram of another code generation device shown based on the embodiment shown. As Figure 11 shown, the device may further include:

[0141] A parsing module 1102, configured to parse the IDL file to obtain an abstract syntax tree corresponding to the IDL file;

[0142] The generation module includes:

[0143] A filling module 1104, configured to generate a syntax structure corresponding to the abstract syntax tree in the code generation template based on the abstract syntax tree corresponding to the IDL file, fill the definition language and the meta-description information into the corresponding code area in the code generation template, and fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree to generate a cross-language call code corresponding to the second interface code.

[0144] Please refer to Figure 12 , Figure 12 which is Figure 10 a schematic block diagram of another code generation device shown based on the embodiment shown. As Figure 12 shown, the parsing module includes:

[0145] A splitting module 1202, configured to split the definition language and meta-description information included in the IDL file to obtain at least one lexical unit;

[0146] A construction module 1204, configured to perform syntax analysis on each of the at least one lexical unit, and further construct an abstract syntax tree corresponding to the IDL file by using the at least one lexical unit as a node based on the syntax analysis result.

[0147] Please refer to Figure 13 , Figure 13 which is Figure 10 a schematic block diagram of another code generation device shown based on the embodiment shown. As Figure 13 shown, the generation module includes:

[0148] A first filling module 1302, configured to fill the definition language and the meta-description information into the corresponding code area in the code generation template to generate an interface generation code corresponding to the second interface code;

[0149] A second filling module 1304, configured to obtain framework codes for constructing a basic framework structure and core functions of an executable program, and fill the interface generation codes into the framework codes to generate cross-language call codes corresponding to the second interface codes.

[0150] Please refer to Figure 14 , Figure 14 which is Figure 10 a schematic block diagram of another code generation device shown based on the embodiments illustrated. As Figure 14 shown, the device further includes:

[0151] A first obtaining module 1402, configured to obtain an IDL file corresponding to the third interface, where the IDL file corresponding to the third interface contains meta-description information for describing the call related to the third interface code;

[0152] A second obtaining module 1404, configured to obtain a code generation template of cross-language call codes corresponding to the third interface code for forwarding call information to the second interface code, where the third interface code uses a second programming language;

[0153] A forwarding module 1406, configured to fill the definition language and the meta-description information for describing the call related to the third interface code into corresponding code areas in the code generation template corresponding to the third interface code to generate cross-language call codes corresponding to the third interface code, so that the first interface code calls the third interface code through the cross-language call codes, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

[0154] Regarding the device in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments of the related methods, and will not be elaborated herein.

[0155] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial descriptions of the method embodiments. The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed to multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present disclosure solution. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0156] Correspondingly, the present disclosure further provides a user device, including: a processor;

[0157] A memory for storing processor-executable instructions;

[0158] Wherein, the processor is used to implement the above method for generating code.

[0159] Correspondingly, the present disclosure also provides a computer-readable storage medium, and the storage medium stores a computer program, and when the computer program is executed by a processor, the above method for generating code is implemented.

[0160] As Figure 15 shown, Figure 15 is a schematic block diagram of a device 1500 for generating code shown according to an embodiment of the present disclosure. For example, the device 1500 can be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0161] Referring to Figure 15 , the device 1500 may include one or more of the following components: a processing component 1502, a memory 1504, a power supply component 1506, a multimedia component 1508, an audio component 1510, an input / output (I / O) interface 1512, a sensor component 1514, and a communication component 1516.

[0162] The processing component 1502 generally controls the overall operation of the device 1500, such as operations associated with display, telephone call, data communication, camera operation, and recording operation. The processing component 1502 may include one or more processors 1520 to execute instructions to complete all or part of the steps of the above method. In addition, the processing component 1502 may include one or more modules to facilitate the interaction between the processing component 1502 and other components. For example, the processing component 1502 may include a multimedia module to facilitate the interaction between the multimedia component 1508 and the processing component 1502.

[0163] The memory 1504 is configured to store various types of data to support the operation of the device 1500. Examples of these data include instructions for any application or method operating on the device 1500, contact data, phone book data, messages, pictures, videos, etc. The memory 1504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disk.

[0164] The power supply component 1506 provides power for various components of the device 1500. The power supply component 1506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 1500.

[0165] The multimedia component 1508 includes a screen that provides an output interface between the device 1500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can not only sense the boundaries of the touch or swipe actions, but also detect the duration and pressure associated with the touch or swipe operation. In some embodiments, the multimedia component 1508 includes a front camera and / or a rear camera. When the device 1500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have a focal length and optical zoom capabilities.

[0166] The audio component 1510 is configured to output and / or input audio signals. For example, the audio component 1510 includes a microphone (MIC) that is configured to receive external audio signals when the device 1500 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 1504 or transmitted via the communication component 1516. In some embodiments, the audio component 1510 further includes a speaker for outputting audio signals.

[0167] The I / O interface 1512 provides an interface between the processing component 1502 and a peripheral interface module, which can be a keyboard, a click wheel, buttons, etc. These buttons can include, but are not limited to: a home button, a volume button, a power-on button, and a lock button.

[0168] The sensor assembly 1514 includes one or more sensors for providing an assessment of the status of the device 1500 in various aspects. For example, the sensor assembly 1514 can detect the on / off state of the device 1500, the relative positioning of components, such as the display and keypad of the device 1500. The sensor assembly 1514 can also detect a change in the position of the device 1500 or a component of the device 1500, the presence or absence of user contact with the device 1500, the orientation or acceleration / deceleration of the device 1500, and the temperature change of the device 1500. The sensor assembly 1514 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 1514 can also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1514 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0169] The communication component 1516 is configured to facilitate communication between the device 1500 and other devices in a wired or wireless manner. The device 1500 can access a wireless network based on communication standards, such as WiFi, 2G or 3G, 4G LTE, 5G NR, or a combination thereof. In an exemplary embodiment, the communication component 1516 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1516 further includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.

[0170] In an exemplary embodiment, the device 1500 can be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for performing the methods described in any of the above embodiments.

[0171] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as the memory 1504 including instructions, and the above instructions can be executed by the processor 1520 of the device 1500 to complete the above methods. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0172] Other embodiments of the present disclosure will be readily contemplated by those skilled in the art in view of the specification and practice of the disclosure herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include known common general knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and examples are only illustrative, and the true scope and spirit of the present disclosure are pointed out by the following claims.

[0173] It should be understood that the present disclosure is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present disclosure is only limited by the appended claims.

[0174] It should be noted that in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. The term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.

[0175] The methods and apparatuses provided in the embodiments of the present disclosure have been introduced in detail above. Specific examples are used herein to elaborate on the principles and implementation manners of the present disclosure. The description of the above embodiments is only used to help understand the method and its core idea of the present disclosure; at the same time, for those of ordinary skill in the art, according to the idea of the present disclosure, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present disclosure.

Claims

1. A method for generating code, characterized in that, Including: Obtain an Interface Definition Language (IDL) file, where the IDL file contains a definition language for describing interface information corresponding to a first interface code and meta-description information related to the invocation of a second interface code. The first interface code is in a first programming language, the second interface code is in a second programming language, and the first programming language and the second programming language are different types of programming languages; Obtain a code generation template, where the code generation module is used to generate cross-language invocation code for the second interface code; Extract the definition language and the meta-description information from the IDL file, and fill the definition language and the meta-description information into the code area in the code generation template corresponding to the second interface code to generate cross-language invocation code for the second interface code, so that the first interface code can invoke the second interface code through the cross-language invocation code.

2. The method according to claim 1, characterized in that, The cross-language invocation code is glue code for implementing cross-language invocation for the second interface code.

3. The method according to claim 1, characterized in that, Before filling the definition language and the meta-description information into the code area in the code generation template corresponding to the second interface code to generate cross-language invocation code for the second interface code, the method further includes: Parse the IDL file to obtain an abstract syntax tree corresponding to the IDL file; Filling the definition language and the meta-description information into the code area in the code generation template corresponding to the second interface code to generate cross-language invocation code for the second interface code includes: Based on the abstract syntax tree corresponding to the IDL file, generate a syntax structure corresponding to the abstract syntax tree in the code generation template, fill the definition language and the meta-description information into the corresponding code area in the code generation template, and fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree to generate cross-language invocation code for the second interface code.

4. The method according to claim 3, characterized in that, Parsing the IDL file to obtain an abstract syntax tree corresponding to the IDL file includes: Split the definition language and the meta-description information included in the IDL file to obtain at least one lexical unit; Perform syntax analysis on each of the at least one lexical unit, and further use the at least one lexical unit as a node based on the syntax analysis result to construct an abstract syntax tree corresponding to the IDL file.

5. The method according to claim 1, wherein Filling the definition language and the meta-description information into the code area in the code generation template corresponding to the second interface code to generate cross-language invocation code for the second interface code includes: Fill the definition language and the meta-description information into the corresponding code area in the code generation template to generate interface generation code for the second interface code; Obtain framework code for constructing the basic framework structure and core functions of an executable program, and fill the interface generation code into the framework code to generate cross-language call code corresponding to the second interface code.

6. The method according to claim 1, wherein The method further includes: Obtain an IDL file corresponding to a third interface, where the IDL file corresponding to the third interface contains meta-description information for describing the call related to the third interface code; Obtain a code generation template for cross-language call code corresponding to the third interface code for forwarding call information to the second interface code, where the programming language used for the third interface code is the same as the programming language used for the second interface code; Fill the definition language and the meta-description information for describing the call related to the third interface code into the corresponding code area in the code generation template corresponding to the third interface code to generate cross-language call code corresponding to the third interface code, so that the first interface code can call the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

7. The method according to claim 1, wherein The first interface code is the interface code corresponding to the application interface included in the application installed in the operating system carried by the electronic device; the second interface code is the interface code corresponding to the application interface included in the system function in the operating system carried by the electronic device.

8. The method according to claim 7, wherein The electronic device includes: an embedded device.

9. A device for generating code, characterized in that, The device includes: A first acquisition module for acquiring an Interface Definition Language (IDL) file, where the IDL file contains a definition language for describing interface information corresponding to the first interface code and meta-description information for describing the call related to the second interface code, the first interface code uses a first programming language, the second interface code uses a second programming language, and the first programming language and the second programming language are different types of programming languages; A second acquisition module for acquiring a code generation template, where the code generation module is used to generate cross-language call code for the second interface code; A generation module for extracting the definition language and the meta-description information from the IDL file, and filling the definition language and the meta-description information into the corresponding code area in the code generation template to generate cross-language call code corresponding to the second interface code, so that the first interface code can call the second interface code through the cross-language call code.

10. The device according to claim 9, wherein The cross-language call code is glue code for implementing cross-language calls for the second interface code.

11. The device according to claim 9, characterized in that, The device further includes: A parsing module for parsing the IDL file to obtain an abstract syntax tree corresponding to the IDL file; The generation module includes: A filling module, which is used to generate a syntax structure corresponding to the abstract syntax tree in the code generation template based on the abstract syntax tree corresponding to the IDL file, fill the definition language and the meta-description information into the corresponding code area in the code generation template, and fill the definition language and the meta-description information into the syntax structure corresponding to the abstract syntax tree, so as to generate cross-language call code corresponding to the second interface code.

12. The device according to claim 11, characterized in that, The parsing module includes: A splitting module, which is used to split the definition language and meta-description information included in the IDL file to obtain at least one lexical unit; A constructing module, which is used to perform syntax analysis on each of the at least one lexical unit, and further use the at least one lexical unit as a node based on the syntax analysis result to construct an abstract syntax tree corresponding to the IDL file.

13. The device according to claim 9, characterized in that, The generating module includes: A first filling module, which is used to fill the definition language and the meta-description information into the corresponding code area in the code generation template to generate interface generation code corresponding to the second interface code; A second filling module, which is used to obtain a framework code for constructing a basic framework structure and core functions of an executable program, and fill the interface generation code into the framework code to generate cross-language call code corresponding to the second interface code.

14. The device according to claim 9, characterized in that, The device further includes: A first obtaining module, which is used to obtain an IDL file corresponding to a third interface, and the IDL file corresponding to the third interface includes meta-description information for describing the call related to the third interface code; A second obtaining module, which is used to obtain a code generation template for cross-language call code corresponding to a third interface code for forwarding call information to the second interface code, and the programming language used by the third interface code is the same as the programming language used by the second interface code; A forwarding module, which is used to fill the definition language and the meta-description information for describing the call related to the third interface code into the corresponding code area in the code generation template corresponding to the third interface code to generate cross-language call code corresponding to the third interface code, so that the first interface code can call the third interface code through the cross-language call code, and the third interface code forwards the call information to the second interface code to complete the call for the second interface code.

15. The device according to claim 9, wherein, The first interface code is the interface code corresponding to the application interface included in the application installed in the operating system carried by the electronic device; the second interface code is the interface code corresponding to the application interface included in the system function in the operating system carried by the electronic device.

16. The device according to claim 15, characterized in that, The electronic device includes: an embedded device.

17. A user equipment, characterized in that, It includes: A processor; A memory for storing processor-executable instructions; Wherein, the processor is used to implement the method according to any one of claims 1 to 8.

18. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method according to any one of claims 1 to 8.