Method and device for converting source code into interface description language
By performing syntax tree analysis and model reconstruction of the source code, the anonymous data structure is converted into a named data structure, and the template engine generates an interface description language, the problems of low efficiency and poor accuracy of manual reverse conversion are solved, and the efficiency and accuracy of the automated conversion process are achieved.
Patent Information
- Application Number
- CN202311125710.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-01
- Publication Date
- 2025-03-04
AI Technical Summary
Manually converting source code to interface description language (IDL) is inefficient, poorly accurate, and has a large workload, making it difficult to avoid introducing manual errors.
By obtaining the source code to be converted, performing syntax tree analysis to obtain the first JSON model, then model reconstruction is performed on the model, converting the anonymous data structure into a named data structure, and finally using the template engine to convert the reconstructed JSON model into an interface description language.
The automated conversion process from source code to interface description language is realized, which improves the accuracy and efficiency of the conversion results. Compared with manual writing of interface description language, both quality and efficiency are greatly improved.
Smart Images

Figure CN119556931A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for converting source code to an interface description language. Background Art
[0002] Interface Description Language (IDL) is a computer language used to describe software component interfaces. IDL describes interfaces in a way that is independent of programming languages, allowing objects running on different platforms and programs written in different languages to communicate with each other. Usually, the code based on the IDL description language is written manually by the user.
[0003] On different system platforms or technology stack platforms, programmers may use different programming languages when coding or migrating platforms for unit component functions of actual program applications. In order to achieve automatic generation and dynamic switching of different programming languages, code generators are often used to automatically generate code in the corresponding programming language by parsing the IDL description language.
[0004] However, in actual projects, it is also very common to reversely interpret or abstract IDL input based on existing code. For example, in the historical software development process, IDL was not used to abstractly define software code, nor was a code engine used to automatically generate programming language code applicable to multiple platforms. At this time, if it is necessary to standardize the methodology of the development process, or switch to a new technology stack and multi-platform programming language support, then in response to new project requirements, it is necessary to study how to reversely abstract the old project code into an IDL description language. For this reverse work, if the abstract conversion work is done manually, the workload will be very large, the efficiency will be very low, and it will be difficult to avoid introducing manual errors.
[0005] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0006] The embodiments of the present application provide a method and device for converting source code into an interface description language, so as to at least solve the technical problem that manual reverse conversion of source code into an interface description language is inefficient and has poor accuracy.
[0007] According to one aspect of an embodiment of the present application, a method for converting source code to an interface description language is provided, comprising: obtaining source code to be converted; performing syntax tree parsing on the source code to obtain a first JSON model; performing model reconstruction on the first JSON model to obtain a second JSON model, wherein the model reconstruction at least comprises: converting an anonymous data structure in the first JSON model into a named data structure; and converting the second JSON model into an interface description language using a template engine.
[0008] Optionally, performing syntax tree parsing on the source code to obtain a first JSON model includes: calling a target compiler to perform syntax tree parsing on the source code to obtain the first JSON model, wherein the target compiler includes: a clang compiler, and the first JSON model includes multiple data structures corresponding to the data types defined in the source code, and the multiple data structures include at least one of the following: a data class, a data name, a data packet, a data element, and a data category.
[0009] Optionally, the first JSON model is reconstructed, including: traversing each data structure in the first JSON model, and for each data structure, traversing each data element in the data structure, if there is a data type whose data class is an anonymous data type, determining that the data structure is an anonymous data structure; determining a target name of the data type, and generating a target data structure based on the target name; and replacing the anonymous data structure with the target data structure.
[0010] Optionally, determining the target name of the data type includes: determining a globally unique target name corresponding to the data type based on context information of the data type in the first JSON model.
[0011] Optionally, according to the principle of declaration before use, all target data structures in the second JSON model used to replace the anonymous data structure are reordered.
[0012] Optionally, converting the second JSON model into an interface description language using a template engine includes: inputting the second JSON model into a target template engine to obtain an interface description language output by the target template engine, wherein the target template engine includes: a mako template engine.
[0013] Optionally, the type of source code is C++ source code.
[0014] According to another aspect of an embodiment of the present application, a source code to interface description language conversion device is also provided, including: an acquisition module for acquiring source code to be converted; a parsing module for performing syntax tree parsing on the source code to obtain a first JSON model; a reconstruction module for performing model reconstruction on the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting an anonymous data structure in the first JSON model into a named data structure; a conversion module for converting the second JSON model into an interface description language using a template engine.
[0015] According to another aspect of an embodiment of the present application, a non-volatile storage medium is also provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the above-mentioned source code to interface description language conversion method by running the computer program.
[0016] According to another aspect of an embodiment of the present application, an electronic device is further provided, comprising: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned method of converting source code to an interface description language through the computer program.
[0017] In an embodiment of the present application, firstly, the source code to be converted is obtained; then, the syntax tree of the source code is parsed to obtain a first JSON model; then, the first JSON model is model reconstructed to obtain a second JSON model, wherein the model reconstruction at least includes: converting the anonymous data structure in the first JSON model into a named data structure; finally, the second JSON model is converted into an interface description language using a template engine. This solution completely realizes the automated conversion process from source code to interface description language, and through the intermediate JSON model as a bridge, it can also realize the reconstruction operation of the source code data type, thereby improving the accuracy of the conversion result. Compared with the current manually written interface description language, the quality and efficiency are greatly improved, that is, this solution effectively solves the technical problem of low efficiency and poor accuracy in manually converting source code into interface description language. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 is a schematic diagram of the structure of an optional computer terminal according to an embodiment of the present application;
[0020] Figure 2It is a flowchart of an optional method for converting source code to interface description language according to an embodiment of the present application;
[0021] Figure 3 is a schematic diagram of an optional C++ source code according to an embodiment of the present application;
[0022] Figure 4 is a schematic diagram of a first JSON model obtained by an optional parsing according to an embodiment of the present application;
[0023] Figure 5 is a schematic diagram of another optional first JSON model according to an embodiment of the present application;
[0024] Figure 6 is a schematic diagram of a second JSON model obtained by an optional reconstruction according to an embodiment of the present application;
[0025] Figure 7 is a schematic diagram of an optional converted interface description language according to an embodiment of the present application;
[0026] Figure 8 It is a structural diagram of an optional source code to interface description language conversion device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] In order to better understand the embodiments of the present application, some nouns or terms that appear in the description of the embodiments of the present application are first translated and explained as follows:
[0030] JSON (JavaScript Object Notation) model: JSON is a lightweight data exchange format based on a subset of JavaScript that can represent structured data in text form. The JSON model is the organizational structure and representation of JSON data, which consists of key-value pairs. Each key-value pair consists of a key and a value, where the key is a string and the value can be a string, number, Boolean, array, object, or null.
[0031] clang compiler: a compiler front end for C, C++, Objective-C, and Objective-C++ programming languages, providing functions such as code analysis, static analysis, code refactoring, and IDE (Integrated Development Environment). It has the following features: 1) Fast compilation speed: clang uses incremental compilation technology based on lexical analysis to quickly generate target code; 2) Accurate diagnostic information: clang provides detailed error and warning information to help developers quickly locate and fix problems; 3) High compatibility: clang follows the relevant standards of C, C++, and Objective-C, and supports most mainstream operating systems and architectures; 4) Extensibility: clang provides a rich plug-in interface that can easily extend its functionality.
[0032] Mako template engine: Mako is a Python template engine used to combine data with template files to generate the final output. It is based on the Python language and provides flexible syntax and powerful functions to meet various complex template requirements. The structure of the Mako template engine usually includes: template files, template contexts, template rendering functions, and rendering outputs. By combining these parts, dynamic text output can be easily generated. The mako template engine has the following features: 1) Concise and clear syntax: mako uses a markup language similar to HTML, which can easily embed Python code, making template files easier to write and understand; 2) Powerful template inheritance: mako supports template inheritance. You can define a basic template and expand and modify it on this basis to achieve template reuse and modular development; 3) Dynamic content generation: mako allows the use of Python code in templates, and can perform logical judgment, loop traversal, variable assignment and other operations to dynamically generate content; 4) Support for multiple template file formats: mako supports multiple template file formats, including HTML, XML, JSON, etc., and you can choose the appropriate template file format according to your needs; 5) High performance: mako uses a compiled template method, which can compile template files into Python code, improving the execution efficiency of templates.
[0033] Example 1
[0034] According to an embodiment of the present application, a method for converting source code to an interface description language is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0035] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 The hardware structure block diagram of a computer terminal (or mobile device) for implementing a method for converting source code to an interface description language is shown. Figure 1As shown, the computer terminal 10 (or mobile device 10) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0036] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0037] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the method for converting source code to interface description language in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, realizing the vulnerability detection method of the above-mentioned application program. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0038] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0039] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0040] In the above operating environment, the embodiment of the present application provides a method for converting source code to interface description language, such as Figure 2 As shown, the method comprises the following steps:
[0041] Step S202, obtaining source code to be converted.
[0042] In an embodiment of the present application, the type of source code to be converted may be C++ source code. Figure 3 Shows a section of C++ source code to be converted. Figure 3 The conversion process of C++ source code in the embodiment of the present invention is used as an example to illustrate the process of the conversion method of the source code of the present application to the interface description language.
[0043] Step S204, parse the source code into a syntax tree to obtain a first JSON model.
[0044] As an optional implementation, when parsing the source code, the target compiler can be called to perform syntax tree parsing on the source code to obtain a first JSON model, which includes multiple data structures corresponding to the data types defined in the source code, and the multiple data structures include at least one of the following: data class (class), data name (name), data packet (package), data elements (elements), data category (category).
[0045] Among them, in order to make the conversion method of the embodiment of the present application more universal, the above-mentioned target compiler can use the clang compiler that is compatible with C, C++, Objective-C and Objective-C++ programming languages. Of course, users can also choose the corresponding compiler according to the type of source code that actually needs to be converted.
[0046] Figure 4 Shows the Figure 3 The C++ source code in the first JSON model is converted.
[0047] Step S206, reconstructing the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting the anonymous data structure in the first JSON model into a named data structure.
[0048] Taking into account the embedding problem of the standard library in the C++ source code, that is, there may be nested data types in the C++ source code and they are all anonymous, but the code engine of the interface description language generally does not support nested data. Therefore, it is necessary to flatten the nested structure in the C++ source code first, that is, it is necessary to reconstruct the first JSON model and convert the anonymous data structure into a named data structure.
[0049] As an optional implementation, the first JSON model may be reconstructed in the following manner:
[0050] First, traverse each data structure in the first JSON model. For each data structure, traverse each data element in the data structure. If there is a data type whose data class is anonymous, that is, parse out DATA-TYPE whose class is ANONYMOUS, then determine that the data structure is an anonymous data structure.
[0051] Afterwards, determine the target name of the data type. Specifically, determine a globally unique target name corresponding to the data type based on context information of the data type in the first JSON model, and then generate a target data structure based on the target name.
[0052] Finally, the original anonymous data structure is replaced by the newly generated target data structure.
[0053] Figure 5 An optional first JSON model is shown, in which the anonymous data type std::vector in the C++ language is used <pointxyzit>, which is an instance of a C++ template type. However, in the implementation of the interface description language, this type may not be supported. Therefore, the first JSON model can be reconstructed as Figure 6 The second JSON model shown, in which the anonymous data type std::vector is assigned <pointxyzit>Unique name: XWAY_VECTOR_LB_PointXYZIT_RB.
[0054] Optionally, after replacing all anonymous data structures, all target data structures used to replace anonymous data structures in the second JSON model may be reordered according to the declare-before-use principle of the C++ language to prevent dependency order errors in temporarily generated named data types.
[0055] Step S208: using a template engine to convert the second JSON model into an interface description language.
[0056] As an optional implementation, the second JSON model may be input into a target template engine to obtain an interface description language output by the target template engine, wherein the target template engine may select a Mako template engine.
[0057] Figure 7 The target template engine is shown Figure 6 The interface description language output after the second JSON model is processed.
[0058] In an embodiment of the present application, firstly, the source code to be converted is obtained; then, the syntax tree of the source code is parsed to obtain a first JSON model; then, the first JSON model is model reconstructed to obtain a second JSON model, wherein the model reconstruction at least includes: converting the anonymous data structure in the first JSON model into a named data structure; finally, the second JSON model is converted into an interface description language using a template engine. This solution completely realizes the automated conversion process from source code to interface description language, and through the intermediate JSON model as a bridge, it can also realize the reconstruction operation of the source code data type, thereby improving the accuracy of the conversion result. Compared with the current manually written interface description language, the quality and efficiency are greatly improved, that is, this solution effectively solves the technical problem of low efficiency and poor accuracy in manually converting source code into interface description language.
[0059] Example 2
[0060] According to an embodiment of the present application, a source code to interface description language conversion device for implementing the source code to interface description language conversion method in embodiment 1 is also provided, such as Figure 8 As shown, the source code to interface description language conversion device at least includes: an acquisition module 81, a parsing module 82, a reconstruction module 83 and a conversion module 84, wherein:
[0061] The acquisition module 81 is used to acquire the source code to be converted.
[0062] In an embodiment of the present application, the type of source code to be converted may be C++ source code.
[0063] The parsing module 82 is used to parse the source code into a syntax tree to obtain a first JSON model.
[0064] As an optional implementation, when parsing the source code, the target compiler can be called to perform syntax tree parsing on the source code to obtain a first JSON model, which includes multiple data structures corresponding to the data types defined in the source code, and the multiple data structures include at least one of the following: data class, data name, data packet, data element, data category.
[0065] Among them, in order to make the conversion method of the embodiment of the present application more universal, the above-mentioned target compiler can use the clang compiler that is compatible with C, C++, Objective-C and Objective-C++ programming languages. Of course, the user can also choose the corresponding compiler according to the type of source code that actually needs to be converted.
[0066] The reconstruction module 83 is used to reconstruct the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting the anonymous data structure in the first JSON model into a named data structure.
[0067] Taking into account the embedding problem of the standard library in the C++ source code, that is, there may be nested data types in the C++ source code and they are all anonymous, but the code engine of the interface description language generally does not support nested data. Therefore, it is necessary to flatten the nested structure in the C++ source code first, that is, it is necessary to reconstruct the first JSON model and convert the anonymous data structure into a named data structure.
[0068] As an optional implementation, the first JSON model may be reconstructed in the following manner:
[0069] First, traverse each data structure in the first JSON model. For each data structure, traverse each data element in the data structure. If there is a data type whose data class is anonymous, that is, parse out DATA-TYPE whose class is ANONYMOUS, then determine that the data structure is an anonymous data structure.
[0070] Afterwards, determine the target name of the data type. Specifically, determine a globally unique target name corresponding to the data type based on context information of the data type in the first JSON model, and then generate a target data structure based on the target name.
[0071] Finally, the original anonymous data structure is replaced by the newly generated target data structure.
[0072] Optionally, after replacing all anonymous data structures, all target data structures used to replace anonymous data structures in the second JSON model may be reordered according to the declare-before-use principle of the C++ language to prevent dependency order errors in temporarily generated named data types.
[0073] The conversion module 84 is used to convert the second JSON model into an interface description language using a template engine.
[0074] As an optional implementation, the second JSON model may be input into a target template engine to obtain an interface description language output by the target template engine, wherein the target template engine may select a Mako template engine.
[0075] It should be noted that the modules in the source code to interface description language conversion device in the embodiment of the present application correspond one-to-one to the implementation steps of the source code to interface description language conversion method in Example 1. Since a detailed description has been given in Example 1, some details not reflected in this embodiment can be referred to Example 1, and will not be repeated here.
[0076] Example 3
[0077] According to an embodiment of the present application, a non-volatile storage medium is also provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the method of converting source code to interface description language in Example 1 by running the computer program.
[0078] Specifically, the device where the non-volatile storage medium is located implements the following steps by running the computer program: obtaining the source code to be converted; parsing the source code through a syntax tree to obtain a first JSON model; reconstructing the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting an anonymous data structure in the first JSON model into a named data structure; and converting the second JSON model into an interface description language using a template engine.
[0079] According to an embodiment of the present application, a processor is further provided, which is used to run a computer program, wherein the method for converting source code to interface description language in Example 1 is executed when the computer program is running.
[0080] Specifically, when the computer program is running, the following steps are executed: obtaining source code to be converted; parsing the source code through a syntax tree to obtain a first JSON model; reconstructing the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting an anonymous data structure in the first JSON model into a named data structure; and converting the second JSON model into an interface description language using a template engine.
[0081] According to an embodiment of the present application, an electronic device is also provided, which includes: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the method of converting source code to interface description language in Example 1 through the computer program.
[0082] Specifically, the processor is configured to execute the following steps through a computer program: obtaining source code to be converted; performing syntax tree parsing on the source code to obtain a first JSON model; reconstructing the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting an anonymous data structure in the first JSON model into a named data structure; and converting the second JSON model into an interface description language using a template engine.
[0083] The serial numbers of the above embodiments are only for description and do not represent the advantages or disadvantages of the embodiments.
[0084] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0085] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0086] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed over multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0087] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0088] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc. Various media that can store program codes.
[0089] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.< / pointxyzit> < / pointxyzit>
Claims
1. A method for converting source code to interface description language, characterized in that: include: Get the source code to be converted; Performing syntax tree parsing on the source code to obtain a first JSON model; Reconstructing the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting an anonymous data structure in the first JSON model into a named data structure; The second JSON model is converted into an interface description language using a template engine.
2. The method according to claim 1, characterized in that Parse the source code in a syntax tree to obtain a first JSON model, including: A target compiler is called to perform syntax tree parsing on the source code to obtain the first JSON model, wherein the target compiler includes: a clang compiler, and the first JSON model includes multiple data structures corresponding to the data types defined in the source code, and the multiple data structures include at least one of the following: a data class, a data name, a data packet, a data element, and a data category.
3. The method according to claim 1, characterized in that Reconstructing the first JSON model includes: Traverse each data structure in the first JSON model, and for each of the data structures, traverse each data element in the data structure, if there is a data type whose data class is anonymous, determine that the data structure is an anonymous data structure; determine a target name for the data type, and generate a target data structure based on the target name; and replace the anonymous data structure with the target data structure.
4. The method according to claim 3, characterized in that Determine the target name of the data type, including: Determine the globally unique target name corresponding to the data type according to context information of the data type in the first JSON model.
5. The method according to claim 3, characterized in that: The method further comprises: According to the principle of declaration before use, all the target data structures in the second JSON model used to replace the anonymous data structure are reordered.
6. The method according to claim 1, characterized in that The second JSON model is converted into an interface description language using a template engine, including: The second JSON model is input into a target template engine to obtain the interface description language output by the target template engine, wherein the target template engine includes: a mako template engine.
7. The method according to any one of claims 1 to 6, characterized in that: The type of the source code is C++ source code.
8. A source code to interface description language conversion device, characterized in that: include: An acquisition module, used to acquire source code to be converted; A parsing module, used for performing syntax tree parsing on the source code to obtain a first JSON model; A reconstruction module, configured to reconstruct the first JSON model to obtain a second JSON model, wherein the model reconstruction at least includes: converting an anonymous data structure in the first JSON model into a named data structure; A conversion module is used to convert the second JSON model into an interface description language using a template engine.
9. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the method for converting source code to interface description language as described in any one of claims 1 to 7 by running the computer program.
10. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the method for converting source code to an interface description language according to any one of claims 1 to 7 through the computer program.
Citation Information
Cited By
Automatic conversion method for data structure of vehicle communication system and computing equipment
CN121187596A