Interface file generation method and device, electronic equipment and storage medium
The compiler front-end processed source code files to generate abstract syntax trees and intermediate codes, and used the glue layer interface to translate it into interface call requests for multiple languages, which solved the problem of low efficiency in interface file development in the existing technology, and realized multilingual support and Efficient interface file generation.
Patent Information
- Application Number
- CN202310605538.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-26
- Publication Date
- 2024-11-26
AI Technical Summary
When developing Internet products, the prior art needs to expand from a software development toolkit interface file in one programming language to another language, which affects the development efficiency and convenience of interface files.
The compiler front-end processed source code files to generate abstract syntax trees and intermediate code, and used the glue layer interface to translate them into interface call requests for multiple languages, thereby generating executable files that support multilinguals.
It improves the language types supported by the software development toolkit, improves the speed and convenience of interface file generation, and enhances the adaptability and efficiency in development scenarios.
Smart Images

Figure CN119025102A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet communication technology, and in particular to an interface file generation method, device, electronic device and storage medium. Background Art
[0002] With the development of Internet communication technology, various Internet products emerge in an endless stream, and these Internet products can provide users with rich functional usage experience. When developing related Internet products, in order to conduct convenient and fast verification, a single programming language is often used for development in the early stage. For example, language A was used to develop the software development kit (SDK) in the early stage. As the business expands, the developed Internet products also need to adapt to other programming languages. For example, the use of language A to develop a software development kit also needs to adapt to language B. In related technologies, it is often necessary to open a separate link to expand the interface file of the software development kit from supporting language A to language B. This affects the development efficiency and convenience of the interface file. Therefore, it is necessary to provide a more efficient and convenient interface file generation solution. Summary of the invention
[0003] In order to solve at least one of the above-mentioned technical problems, the present application provides an interface file generation method, device, electronic device and storage medium:
[0004] According to a first aspect of the present application, a method for generating an interface file is provided, the method comprising:
[0005] In response to the received compilation instruction, determining a first source code file to be compiled according to the compilation instruction, the first source code file is used to describe a native layer interface of a software development kit, and the native layer interface supports a first class language;
[0006] Processing the first source code file using a compiler front end to obtain an abstract syntax tree, intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, wherein the second source code file is generated based on the abstract syntax tree, each of the second source code files supports a second-class language, and the glue layer interface is used to translate an interface call request using the second-class language into an interface call request using the first-class language;
[0007] The intermediate code is processed by a compiler backend to obtain a first executable file indicating the native layer interface, and the at least one second source code file is processed respectively to obtain at least one second executable file indicating the glue layer interface.
[0008] According to a second aspect of the present application, there is provided an interface file generating device, the device comprising:
[0009] A response module: used for responding to a received compilation instruction and determining a first source code file to be compiled according to the compilation instruction, wherein the first source code file is used to describe a native layer interface of a software development kit, and the native layer interface supports a first class language;
[0010] A first compiling module: used to process the first source code file by using a compiler front end, to obtain an abstract syntax tree, an intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, wherein the second source code file is generated based on the abstract syntax tree, each of the second source code files supports a second type of language, and the glue layer interface is used to translate an interface call request using the second type of language into an interface call request using the first type of language;
[0011] The second compilation module is used to process the intermediate code using the compiler backend to obtain a first executable file indicating the native layer interface, and to process the at least one second source code file respectively to obtain at least one second executable file indicating the glue layer interface.
[0012] According to the third aspect of the present application, an electronic device is provided, comprising at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the at least one processor to implement the interface file generation method as described in the first aspect.
[0013] According to the fourth aspect of the present application, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement the interface file generation method as described in the first aspect.
[0014] According to a fifth aspect of the present application, a computer program product is provided, which includes at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the interface file generation method as described in the first aspect.
[0015] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application.
[0016] Implementing this application has the following beneficial effects:
[0017] In the path of the first source code file originally compiled to indicate the native layer interface, the present application uses the compiler front end to process the first source code file to obtain the corresponding abstract syntax tree, and generates a second source code file indicating the glue layer interface based on the abstract syntax tree, and then uses the compiler back end to process the second source code file to obtain the corresponding executable file. The present application uses the glue layer interface to adapt the language translation of the received interface call request to the native layer interface, and follows the compilation path of the native layer interface source code to generate the glue layer interface source code and its corresponding executable file that supports multiple languages. This is conducive to enriching the languages supported by the software development kit and improving the speed and convenience of obtaining the executable file corresponding to the glue layer interface source code. At the same time, the executable file corresponding to the glue layer interface source code can support multiple languages, which also improves the adaptability of interface file generation in development scenarios.
[0018] Other features and aspects of the present application will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 A schematic diagram of an application environment according to an embodiment of the present application is shown;
[0021] Figure 2 A schematic diagram showing a flow chart of a method for generating an interface file according to an embodiment of the present application;
[0022] Figure 3 A schematic diagram showing a process flow of a compiler front end processing a first source code file according to an embodiment of the present application is shown;
[0023] Figure 4 A schematic diagram showing a process of obtaining a first source code file according to an embodiment of the present application is shown;
[0024] Figure 5 A flow chart of a method for generating an interface file according to an embodiment of the present application is also shown;
[0025] Figure 6 A schematic diagram showing processing items of static analysis according to an embodiment of the present application is shown;
[0026] Figure 7 A schematic diagram of optimized processing items according to an embodiment of the present application is shown;
[0027] Figure 8 A schematic diagram showing processing items of a link according to an embodiment of the present application;
[0028] Fig. 9 A code schematic diagram showing an abstract syntax tree according to an embodiment of the present application;
[0029] Fig.10 A device block diagram according to an embodiment of the present application is shown;
[0030] Fig.11 A schematic diagram of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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 making creative work are within the scope of protection of this application.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be 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 server that includes 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.
[0033] Various exemplary embodiments, features and aspects of the present application will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0034] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0035] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.
[0036] In addition, in order to better illustrate the present application, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present application can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present application.
[0037] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0038] Software Development Kit (SDK): refers to a collection of development tools used by software engineers to create application software for specific software packages, software frameworks, hardware platforms, operating systems, etc.
[0039] Application Programming Interface (API): is a computing interface that defines the interactions between multiple software intermediaries, as well as the kinds of calls or requests that can be made, how to make calls or requests, the data formats that should be used, the conventions that should be followed, etc.
[0040] Programming language: A computer language allows the programmer to define exactly what data the computer needs to work with and precisely what actions it should take in different situations.
[0041] Objective-C: is a general-purpose, high-level, object-oriented programming language.
[0042] Swift: It is an easy-to-learn and easy-to-use programming language, and it is also the first systems programming language that is as expressive and fun as a scripting language.
[0043] LLVM (Low Level Virtual Machine): Low-level virtual machine. It is a set of modular and reusable compiler and tool technologies that can be used for major programming languages.
[0044] Clang: A compilation front-end for C, C++, Objective-C, Swift, etc.
[0045] See also Figure 1 , Figure 1 A schematic diagram of an application environment according to an embodiment of the present application is shown, and the application environment may include a client 10 and a server 20. The client 10 and the server 20 may be directly or indirectly connected via wired or wireless communication. The user may send a compilation instruction to the server 20 via the client 10. In response to the received compilation instruction, the server 20 determines the first source code file to be compiled according to the compilation instruction, the first source code file is used to describe the native layer interface of the software development kit, and the native layer interface supports a first-class language; then, the first source code file is processed by the compiler front end to obtain an abstract syntax tree, an intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, the second source code file is generated based on the abstract syntax tree, each second source code file supports a second-class language, and the glue layer interface is used to translate an interface call request using the second-class language into an interface call request using the first-class language; further, the compiler back end is used to process the intermediate code to obtain a first executable file indicating the native layer interface, and at least one second source code file is processed separately to obtain at least one second executable file indicating the glue layer interface. It should be noted that Figure 1 Just an example.
[0046] The client 10 may be a physical device such as a smart phone, a computer (such as a desktop computer, a tablet computer, a laptop computer), an augmented reality (AR) / virtual reality (VR) device, a digital assistant, an intelligent voice interaction device (such as an intelligent speaker), an intelligent wearable device, an intelligent home appliance, a vehicle-mounted terminal, etc., or may be software running in a physical device, such as a computer program. The operating system of the client 10 may be an Android system (Android system), an iOS system (a mobile operating system developed by Apple), a Linux system (an operating system), a Microsoft Windows system (Microsoft Windows operating system), etc.
[0047] The server end 20 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server may include a network communication unit, a processor, a memory, etc. The server end 20 can provide background services for the corresponding client 10.
[0048] In actual applications, the user can trigger the generation of compilation instructions through the interactive interface provided by the client 10, and the client 10 responds to the compilation instructions to execute the steps for generating the interface file (i.e., the above steps of "determining the first source code file to be compiled according to the compilation instructions" to "using the compiler backend to process the intermediate code to obtain the first executable file indicating the native layer interface, and processing at least one second source code file to obtain at least one second executable file indicating the glue layer interface"). Of course, the server 20 can also respond to the compilation instructions generated by itself to execute the steps for generating the interface file.
[0049] The Internet products developed by the interface file generation scheme provided in the embodiment of the present application can be applied to cloud IOT scenarios, cloud security scenarios, etc. Among them, cloud IOT aims to connect the information perceived by sensor devices in traditional IoT and the instructions received to the Internet, truly realize networking, and realize massive data storage and calculation through cloud computing technology. Since the characteristics of IoT are that things are connected to things, and the current operating status of each "object" is perceived in real time, a large amount of data information will be generated in this process. How to summarize this information and how to filter useful information from massive information for decision support for subsequent development have become key issues affecting the development of IoT, and IoT cloud based on cloud computing and cloud storage technology has therefore become a strong support for IoT technology and applications. Cloud security refers to the general term for security software, hardware, users, institutions, and security cloud platforms based on cloud computing business model applications. Cloud security integrates emerging technologies and concepts such as parallel processing, grid computing, and unknown virus behavior judgment. Through a large number of meshed clients, the abnormal behavior of software in the network is monitored to obtain the latest information of Trojans and malicious programs on the Internet, and send it to the server for automatic analysis and processing, and then distribute the solutions for viruses and Trojans to each client.
[0050] It should be noted that for compilation instructions, source code files, etc. that are associated with user information, when the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0051] Figure 2 A flow chart of a method for generating an interface file according to an embodiment of the present application is shown as follows: Figure 2 As shown, the method includes:
[0052] S201: In response to a received compile instruction, determine a first source code file to be compiled according to the compile instruction, wherein the first source code file is used to describe a native layer interface of a software development kit, and the native layer interface supports a first class language;
[0053] In an embodiment of the present application, in response to the received compilation instruction, the server or the client determines the first source code file to be compiled according to the compilation instruction. The compilation instruction can be triggered by the user through the interactive interface provided by the client, and the client determines the first source code file to be compiled according to the compilation instruction, or the client sends the compilation instruction to the server so that the server determines the first source code file to be compiled according to the compilation instruction. The compilation instruction can also be triggered by the user through the interactive interface provided by the server, and the server determines the first source code file to be compiled according to the compilation instruction, or the server sends the compilation instruction to the client so that the client determines the first source code file to be compiled according to the compilation instruction. The compilation instruction can also be generated instantly, delayed or regularly based on the notification information indicating the first source code file, and the notification information is used to indicate that the generation of the first source code file has been completed. For example, the development of the first coded file is carried out on the server. With the completion of the first coded file, the server generates notification information, which can trigger the server to generate the compilation instruction instantly, delayed (such as the generation time of the compilation instruction is later than the preset time of the generation time of the notification information) or regularly (such as generating the compilation instruction at an hour closest to the generation time of the notification information).
[0054] The compilation instruction is intended to trigger a process for generating an executable file. The compilation instruction carries description information of the source code to be compiled. The source code to be compiled can be located by the description information of the source code to be compiled: the first source code file. The description information of the source code to be compiled can record the storage location, acquisition method, etc. of the first source code file. The description information of the source code to be compiled can also be the first source code file itself.
[0055] The server or client determines the first source code file to be compiled according to the compilation instruction. The first source code file is used to describe the native layer interface of the software development kit, and the native layer interface supports a first-class language. The native layer interface is an API provided by the kernel of the software development kit. It can be understood that in the process of developing the SDK, the first source code file is a source code representation of the native layer interface of the SDK. Due to continuous development, the first source code file can be a source code representation of the native layer interface of a certain development stage. The first class language supported by the native layer interface can be the programming language used in the early stage of developing the software development kit, and the programming language used in the early stage of developing the software development kit is often set based on the business needs at the time. In actual applications, if it is necessary to call system capabilities, the first class language generally uses Objective-C (iOS), Java (Android) and other languages. Exemplarily, when developers make the initial technology selection, in order to verify the effectiveness of their solutions and technologies more quickly, they generally only use single-platform languages (such as only using Objective-C to support the iOS platform) for rapid iterative development.
[0056] S202: Processing the first source code file using a compiler front end to obtain an abstract syntax tree, intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, wherein the second source code file is generated based on the abstract syntax tree, each of the second source code files supports a second-class language, and the glue layer interface is used to translate an interface call request using the second-class language into an interface call request using the first-class language;
[0057] In an embodiment of the present application, the server or client uses the compiler front end to process the first source code file to obtain an abstract syntax tree, intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file. The compiler front end can be Clang. The compiler front end processes the first source code file to analyze and understand the first source code file, and the language syntax of the first source code file is concerned at this stage. The abstract syntax tree, intermediate code, and second source code file are the processing products of this stage. Specifically, the compiler front end first processes the first source code file to obtain an abstract syntax tree. The compiler front end then obtains the intermediate code and the second source code file based on the abstract syntax tree. The abstract syntax tree and the intermediate code are for the native layer interface, and the second source code file is for the glue layer interface. For the glue layer interface, it is an API provided to facilitate other language calls, and it is responsible for translating other language calls into native layer interface calls. The glue layer interface is used to translate an interface call request using a second type of language into an interface call request using a first type of language. Here, at least one second source code file is generated based on the abstract syntax tree, and each second source code file supports a second type of language. Taking the example that the number of second source code files generated is two, the two second source code files are second source code file i and second source code file j, the second source code file i is generated based on the abstract syntax tree, and the second source code file j is also generated based on the abstract syntax tree. The second source code file i supports C++, and the second source code file j supports C#. The glue layer interface is used to translate interface call requests using the second type of language into interface call requests using the first type of language. If the first type of language supported by the native layer interface is Java, the glue layer interface corresponding to the second source code file i can translate the interface call request using C++ into the interface call request using Java, and the glue layer interface corresponding to the second source code file j can translate the interface call request using C# into the interface call request using Java.
[0058] In actual applications, if it is necessary to call system capabilities, the first type of language generally uses Objective-C (iOS), Java (Android) and other languages. In game development scenarios, second-type languages such as C++ (UE), C# (Unity), and JavaScript (Cocos2x) are generally used. When it is necessary to use some special system capabilities, it is necessary to translate and call the native layer interface through the glue layer interface that supports C++, C#, and JavaScript. Taking the development of game products as an example, the upper layer close to the user side can implement game services through C# (Unity), C++ (Unreal Engine), etc., and the underlying layer (as opposed to the upper layer) that provides support for this can call Google IAB / Apple IAP through the native language Java or Objective-C and encapsulate it as a payment library. Among them, Java or Objective-C are first-type languages, and C# and C++ are second-type languages.
[0059] S203: Using a compiler backend to process the intermediate code to obtain a first executable file indicating the native layer interface, and respectively processing the at least one second source code file to obtain at least one second executable file indicating the glue layer interface.
[0060] In an embodiment of the present application, the server or client uses the compiler backend to process the intermediate code to obtain a first executable file indicating a native layer interface, and processes at least one second source code file to obtain at least one second executable file indicating a glue layer interface. The compiler backend can be LLVM. The compiler backend processes the intermediate code and the second source code file separately, processes the intermediate code to obtain a first executable file indicating a native layer interface, and processes the second source code file to obtain a second executable file indicating the glue layer interface, wherein each second source code file corresponds to a second executable file. The first executable file and the second executable file are codes that can be recognized by a computer.
[0061] LLVM will perform optimization, assembly, linking, etc. during the execution of the compilation backend logic. Figure 7 ), LLVM can optimize some logic execution performance and code size. The optimization phase has strong scalability and can further optimize the code by adjusting relevant optimization strategies. The assembly phase can convert the optimized LLVM IR (intermediate code) into machine code and finally generate several binary target files. The link phase (see Figure 8 ) Link all binary target files involved in the compilation process with the static library to generate the final binary executable (machO on the iOS platform) file.
[0062] It can be understood that in the path of the first source code file that originally compiles the native layer interface, the compiler front end can first process the first source code file to obtain an abstract syntax tree, and then the compiler front end obtains the intermediate code based on the abstract syntax tree, and then the compiler back end processes the intermediate code to obtain the first executable file to complete the compilation of the first source code file. In the technical solution provided by the embodiment of the present application, in the path of the first source code file that originally compiles the native layer interface, the compiler front end is used to process the first source code file to obtain the corresponding abstract syntax tree, and based on the abstract syntax tree, a second source code file indicating the glue layer interface is generated, and then the compiler back end is used to process the second source code file to obtain the corresponding executable file.
[0063] It can be seen from the technical solution provided by the above embodiments of the present application that the embodiments of the present application utilize the glue layer interface to adapt the language translation of the received interface call request to the native layer interface, and follow the compilation path of the native layer interface source code to generate the glue layer interface source code and its corresponding executable file that supports multiple languages. This is conducive to enriching the languages supported by the software development kit, improving the speed and convenience of obtaining the executable file corresponding to the glue layer interface source code, and reducing the maintenance cost of the glue layer interface file. At the same time, the executable file corresponding to the glue layer interface source code can support multiple languages, and also improve the adaptability of interface file generation in development scenarios, thereby effectively improving the efficiency of developing cross-language SDKs.
[0064] The embodiments of the present application will be described in detail below.
[0065] As a possible implementation, the compiler front end includes a preset compiler and a plug-in of the preset compiler. Figure 3 As shown, for the aforementioned step S202, the use of the compiler front end to process the first source code file to obtain an abstract syntax tree, intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file includes:
[0066] S301: Using the preset compiler to perform lexical analysis and syntax analysis on the first source code file to obtain the abstract syntax tree;
[0067] S302: parse the abstract syntax tree using the preset compiler to obtain the intermediate code;
[0068] S303: Using the plug-in to process the abstract syntax tree based on preset rules to obtain the at least one second source code file, the preset rules include at least one sub-rule set, each of the sub-rule sets is based on one of the second-type languages.
[0069] Introducing a plug-in and using it to process the abstract syntax tree to obtain a second source code file, and obtaining the second source code file through a pluggable and easy-to-maintain plug-in is conducive to improving the convenience and flexibility of obtaining glue layer interface source code that supports different languages.
[0070] The preset compiler may be Clang. The preset compiler performs lexical analysis and grammatical analysis on the first source code file to obtain an abstract syntax tree. Lexical analysis is generally divided into the work content of the scanner module and the work content of the evaluator module. The scanner module is mainly responsible for identifying morphemes (a character sequence consisting of a class of characters) and finally confirming the type of lexical unit, and can deduce the lexical unit value according to the longest consistent principle. The evaluator module is mainly responsible for processing morphemes, generating lexical unit values, and combining them with morpheme types to finally obtain lexical units. The grammatical analysis identifies the grammatical structure of the first source code file based on the lexical analysis result, and this grammatical structure can be a tree structure, that is, an abstract syntax tree. Of course, the grammatical analysis result can be a candidate tree, and the candidate tree is semantically analyzed to obtain an abstract syntax tree. Among them, the semantic analysis focuses on eliminating semantic ambiguity. The semantic analysis can scan the grammatical analysis result as a whole, and perform rule checking to finally generate an abstract syntax tree. The grammatical analysis result can also be presented in the form of a lexical unit stream. The preset compiler parses the abstract syntax tree to obtain an intermediate code. When LLVM is used as the backend of the compiler, LLVMIR as the intermediate code can be used by LLVM as the backend of the compiler.
[0071] The plug-in may be a Clang plug-in, which is implemented based on the Clang tool. It is a modular, pluggable tool that can insert processing logic into the compilation front-end information. The plug-in processes the abstract syntax tree based on preset rules to obtain at least one second source code file. The preset rules include at least one sub-rule set, and each sub-rule set is set based on a second-class language. Exemplarily, at least one second source code file is N second source code files, so there are N second-class languages. The second source code file n is the nth second source code file among the N second source code files, and the second-class language n is the nth second-class language among the N second-class languages. If the second source code file n supports the second-class language n, the sub-rule n is set for the second-class language n. Then, the plug-in processes the abstract syntax tree based on the sub-rule n to obtain the second source code file n. A series of parsing transformations can be performed on the abstract syntax tree to obtain the second source code file. In the parsing transformation process, the plug-in focuses on establishing a translation relationship between the information in the abstract syntax tree and the two types of programming languages.
[0072] Specifically, for the aforementioned step S303, the use of the plug-in to process the abstract syntax tree based on preset rules to obtain the at least one second source code file may include the following steps: first, for each of the second-category languages, the plug-in is used to determine the sub-rule set corresponding to the second-category language, the sub-rule set including information acquisition sub-rules, information conversion sub-rules, and source code file generation sub-rules; then, the plug-in is used to obtain key information from the abstract syntax tree based on the information acquisition sub-rules; further, the plug-in is used to adapt the key information to the second-category language based on the information conversion sub-rules to obtain the conversion result; finally, the plug-in is used to establish an association between the key information and the conversion result based on the source code file generation sub-rules to obtain the second source code file corresponding to each of the second-category languages, so as to obtain the at least one second source code file.
[0073] Taking "the plug-in processes the abstract syntax tree based on sub-rule n to obtain the second source code file n" as an example, the sub-rule set includes information acquisition sub-rules, information conversion sub-rules and source code file generation sub-rules. The information acquisition sub-rule is intended to guide the acquisition of key information from the abstract syntax tree. The information conversion sub-rule is intended to define how to translate key information to adapt to the second type of language n. The source code file generation sub-rule defines the constituent elements of the second source code file n. Under the guidance of the information acquisition sub-rule, the information conversion sub-rule and the source code file generation sub-rule, the plug-in processes the abstract syntax tree to generate the second source code file. The orderly and well-founded sub-rules in the sub-rule set are conducive to ensuring the accuracy and effectiveness of the generation of the second source code file. A sub-rule set is set based on a second type of language, and a sub-rule set includes multiple sub-rules with fine granularity. The dimension of the sub-rule set and the granularity of the sub-rules therein are easy to update and maintain, have good adaptability, and are conducive to the adaptability of generating the second source code file for a specific second type of language.
[0074] The key information obtained from the abstract syntax tree can be the class name, instance variables and types defined, class variables and types, and method name, method parameters, parameter order, parameter type, etc. of each method in the abstract syntax tree. The conversion result is adapted to the conversion of the second type of language. The conversion can be performed based on the preset mapping relationship. For example, the conversion between basic types is performed based on the preset mapping relationship.
[0075] Further, for the aforementioned step of obtaining key information, the information acquisition sub-rule includes an information acquisition method and preset requirements that the information to be obtained must meet. The use of the plug-in to obtain key information from the abstract syntax tree based on the information acquisition sub-rule may include the following steps: using the plug-in to traverse all nodes of the abstract syntax tree, and in the traversal process, extracting the information that meets the preset requirements contained in each of the nodes to obtain the key information. Locating information by traversing the nodes in the tree and judging whether the located information meets the preset requirements can avoid information omissions, thereby ensuring the comprehensiveness and accuracy of the key information obtained. The traversal method can be a deep traversal. In addition, for the class name, defined instance variables and types, and class variables and types located by the nodes in the traversal tree, they can be saved in sequence through a linked list according to the sequence of the location time. For the method name, method parameters, parameter order, parameter type, etc. of each method located by the nodes in the traversal tree, they can be saved in sequence through a linked list according to the sequence of the location time. This allows for unified maintenance of key information and preparation for conversion to adapt to the second language; it also provides a basis for backtracking when errors occur in interface file generation.
[0076] In practical applications, such as Figure 5 As shown, the external system starts the compilation instruction, which triggers Clang to execute the compilation front-end logic on the first source code file, that is, the above steps S301-S302. Then, the Clang plug-in parses the abstract syntax tree generated by Clang in the process of executing the compilation front-end logic through libclang to obtain the second source code file. Furthermore, the LLVM IR generated by Clang in the process of executing the compilation front-end logic can trigger the call of LLVM to enable it to execute the compilation back-end logic. LLVM assembles and links LLVM IR and the second source code file, and finally completes the binary file generation work. The entire plug-in process is transparent to systems such as Clang and LLVM, and will not intrude or affect the original LLVM IR generation and binary file generation work, and has good controllability. The Clang plug-in works in the compilation front-end, and the storage location of the abstract syntax tree and the native layer interface is the input source of the Clang plug-in, and the second source code file is the output source of the Clang plug-in. The storage location of the native layer interface will be used as the storage location of the second source code file. A candidate source code file can be created in the storage location of the native layer interface, and the above key information and the association between the key information and the conversion result are output to the candidate source code file line by line to obtain a second source code file. If the second type of language is C++, the candidate source code file corresponding to the second type of language can be saved in the storage location in .cpp format.
[0077] The embodiment of the present application also provides a layered design for the Clang plug-in, which can divide the entire Clang plug-in into the following three core modules. 1) File module: responsible for file formatting and input and output control. The file module includes the following three sub-modules: Read file sub-module: responsible for processing the reading of language templates; Format sub-module: responsible for combining the data obtained from the abstract syntax tree with the template data, and then performing encoding processing; Write file sub-module: responsible for outputting the formatted data to the storage location of the native layer interface. 2) Core engine: responsible for analyzing the abstract syntax tree, connecting modules in series and implementing business logic. The core engine includes the following three sub-modules: Business logic processor: responsible for combining the capabilities of each module to execute the core business logic; Syntax tree parser: responsible for traversing the abstract syntax tree nodes using the capabilities of libraries such as libclang. 3) Language module: responsible for processing a specific programming language. The language module includes the following two submodules: Type conversion submodule: responsible for defining the basic type conversion rules of each language (such as Objective-C NSInteger type, corresponding to C#int type); Language template submodule: responsible for defining the coding templates of each language (such as Objective-C class definition @interface, corresponding to C#class symbol). The application of Clang plug-in is conducive to quickly generating glue layer interface source code of each language.
[0078] In addition, 1) for the aforementioned step S301, before the preset compiler is used to perform lexical analysis and syntax analysis on the first source code file to obtain the abstract syntax tree, the method may also include the following steps: when the first source code file carries a first comment, the preset compiler is used to set the comment removal option to a closed state, and the closed state is used to indicate that the second source code file carries a second comment corresponding to the first comment. Here, the comment removal option is turned off so that it can be used to generate comments for the glue layer interface later. The comments for the glue layer interface can facilitate the positioning and analysis of the second source code file and the second executable file, thereby ensuring the accuracy and easy maintenance of the interface file generation.
[0079] In practical applications, before performing lexical analysis and syntax analysis on the first source code file, the first source code file may be preprocessed. In the preprocessing stage, the preset compiler performs macro replacement on the first source code file, processes the conditional compilation logic, and finally expands the header file. The above step of turning off the optional comment removal option may be performed before expanding the header file.
[0080] 2) For the aforementioned step S302, before the abstract syntax tree is parsed by the preset compiler to obtain the intermediate code, the method may also include the following steps: for the interface indicated by the abstract syntax tree, when the structure of the interface cannot achieve conversion adapted to the second type of language, suspend compilation and / or generate an alarm notification. A fixed set of rules can be set to determine whether all interface structures can be converted to other languages normally. For structures that cannot be converted, you can consider interrupting the compilation process or using a fallback solution and performing warning prompt processing. In this way, pre-detection and optimization are performed before the abstract syntax tree is specifically applied, so that the availability of the abstract syntax tree can be judged in time, thereby ensuring the smooth generation of subsequent code files.
[0081] In practical applications, before parsing the abstract syntax tree, you can first perform static analysis on the abstract syntax tree. In the static analysis stage, the overall structure of the abstract syntax tree is analyzed and checked. For specific analysis and check items, please refer to Figure 6 The static phase is highly extensible and can be enhanced by adding different rule sets, such as the above-mentioned fixed rules and additions.
[0082] Taking a first source code file based on Objective-C as a first-class language to obtain a second source code file as an example, the following is an example of the first source code file:
[0083]
[0084] The first source code file is processed by the compiling front end to obtain an abstract syntax tree (see Fig. 9 ), and generate a second source code file based on the abstract syntax tree. The following are respectively the second source code file A with C++ as the second language and the second source code file B with C# as the second language:
[0085] 1) The second source code file A:
[0086] / / / Set up the execution process and background request environment
[0087] / / / @param process execution process
[0088] / / / @param env XX background environment
[0089] / / / @param locale XX background area
[0090] static bool SetProcess(std::string process, std::string env, std::string locale);
[0091] 2) The second source code file B:
[0092] / / / Set up the execution process and background request environment
[0093] / / / @param process execution process
[0094] / / / @param env XX background environment
[0095] / / / @param locale XX background area
[0096] 0references
[0097] static bool SetProcess(string process,string env,string locale);
[0098] The second source code file A can be used to support engines such as UE and Cocos, and the second source code file B can be used to support engines such as Unity. For the traversal and mapping involved in generating the above-mentioned second source code file A, std::string is a type that only exists in C++, and NSString* is a type that only exists in Objective-C. In the process of traversing the abstract syntax tree, the located class name, defined instance variables and types, class variables and types, and the method name, method parameters, parameter order, parameter type, etc. of each method are key information. For example, first find the class name of the current method (such as MidasIAPApi.h), and the defined class variables process, env, and locale (they are all NSString* types). Then, determine the name of each method in this class, such as the method name of a specific method is setProcess:environment:locale:, the method parameters are [process,env,locale], the parameter order is [process,env,locale], and the parameter type is [NSString*,NSString*,NSString*]. Furthermore, map the above class names to C++ class names (such as APMidasInterface.h). Also map the above defined class variable types, that is, map process, env, and locale to std::string types. Also map the above method names, method parameters, parameter order, and parameter types: for example, map the method name setProcess:environment:locale: to SetProcess; map the parameter type [NSString*, NSString*, NSString*] to [std::string,std::string,std::string]; and for the method parameters: [process, env, locale] and the parameter order [process, env, locale], since they do not change for the example method, they generally will not change. Among them, the method parameters generally will not change unless they conflict with language keywords.
[0099] As a possible implementation, Figure 4 As shown, for the aforementioned step S201, before determining the first source code file to be compiled according to the compilation instruction in response to the received compilation instruction, the method further includes:
[0100] S401: In response to a received interface update instruction, determine source code to be updated and update reference information according to the interface update instruction, wherein the update reference information is used to guide the update of the source code, and the update reference information includes update item description information and forward compatibility requirement information;
[0101] S402: Update the source code based on the update reference information to obtain the first source code file.
[0102] Provided here is an applicable business scenario for compiling with the first source code file as the starting point. Due to continuous development, the first source code file can be a source code representation of the native layer interface at a certain development stage. The first source code file can be an update result for the source code obtained in the previous development stage. Update reference information as a basis for updating the source code. Among them, the update item description information is used to indicate how to replace, delete, modify, etc. the relevant content in the source code, and indicate what new content should be added to the source code. Forward compatibility requirement information is used to indicate that the first source code file as the new version should be compatible with the source code as the old version. SDK forward compatibility (also known as upward compatibility) refers to the use of the new version of the SDK interface to include the full set of the old version of the SDK interface, that is, SDK access users can seamlessly upgrade from the old version of the SDK to the new version of the SDK, and there is no development workload.
[0103] The present application also provides an interface file generation device, such as Fig.10 As shown, the interface file generating device 100 includes:
[0104] Responding module 1001: used to respond to a received compile instruction and determine a first source code file to be compiled according to the compile instruction, wherein the first source code file is used to describe a native layer interface of a software development kit, and the native layer interface supports a first class language;
[0105] The first compiling module 1002 is used to process the first source code file by using a compiler front end, and obtain an abstract syntax tree, an intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, wherein the second source code file is generated based on the abstract syntax tree, each of the second source code files supports a second type of language, and the glue layer interface is used to translate an interface call request using the second type of language into an interface call request using the first type of language;
[0106] The second compilation module 1003 is used to process the intermediate code using the compiler backend to obtain a first executable file indicating the native layer interface, and to process the at least one second source code file respectively to obtain at least one second executable file indicating the glue layer interface.
[0107] It should be noted that the device in the device embodiment and the method embodiment are based on the same inventive concept.
[0108] In some embodiments, the functions or modules included in the device provided in the embodiments of the present application can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.
[0109] The embodiment of the present application also provides a computer-readable storage medium, wherein at least one instruction or at least one program is stored in the computer-readable storage medium, and the at least one instruction or at least one program is loaded and executed by a processor to implement the above method. The computer-readable storage medium may be a non-volatile computer-readable storage medium.
[0110] An embodiment of the present application also provides an electronic device, which includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the at least one processor to implement the above method.
[0111] The electronic device may be provided as a terminal, a server, or a device in other forms.
[0112] Fig.11 1 shows a block diagram of an electronic device according to an embodiment of the present application. For example, the electronic device 1900 can be provided as a server. Fig.11 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.
[0113] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output (I / O) interface 1958. The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.
[0114] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.
[0115] The present application may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present application.
[0116] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0117] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0118] The computer program instructions for performing the operation of the present application can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C+, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer, partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of computer-readable program instructions to personalize electronic circuits, such as programmable logic circuits, field programmable gate arrays (FPGAs) or programmable logic arrays (PLAs), the electronic circuits can execute computer-readable program instructions, thereby realizing various aspects of the present application.
[0119] Various aspects of the present application are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0120] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0121] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0122] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present application. In this regard, each square frame in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the above-mentioned module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the standard function in the square frame can also occur in a sequence different from the standard in the accompanying drawings. For example, two continuous square frames can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square frame in the block diagram and / or flow chart, and the combination of the square frames in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0123] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for generating an interface file, characterized in that: The method comprises: In response to the received compilation instruction, determining a first source code file to be compiled according to the compilation instruction, the first source code file is used to describe a native layer interface of a software development kit, and the native layer interface supports a first class language; Processing the first source code file using a compiler front end to obtain an abstract syntax tree, intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, wherein the second source code file is generated based on the abstract syntax tree, each of the second source code files supports a second-class language, and the glue layer interface is used to translate an interface call request using the second-class language into an interface call request using the first-class language; The intermediate code is processed by a compiler backend to obtain a first executable file indicating the native layer interface, and the at least one second source code file is processed respectively to obtain at least one second executable file indicating the glue layer interface.
2. The method according to claim 1, characterized in that The compiler front end includes a preset compiler and a plug-in of the preset compiler, and the using the compiler front end to process the first source code file to obtain an abstract syntax tree, intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file includes: Using the preset compiler to perform lexical analysis and syntax analysis on the first source code file to obtain the abstract syntax tree; Parsing the abstract syntax tree using the preset compiler to obtain the intermediate code; The plug-in is used to process the abstract syntax tree based on preset rules to obtain the at least one second source code file, wherein the preset rules include at least one sub-rule set, and each of the sub-rule sets is based on one of the second-type languages.
3. The method according to claim 2, characterized in that The using the plug-in to process the abstract syntax tree based on preset rules to obtain the at least one second source code file includes: For each of the second-category languages, using the plug-in, determining the sub-rule set corresponding to the second-category language, the sub-rule set including an information acquisition sub-rule, an information conversion sub-rule, and a source code file generation sub-rule; Utilize the plug-in to obtain key information from the abstract syntax tree based on the information acquisition sub-rule: Using the plug-in to convert the key information into the second language based on the information conversion sub-rule, and obtaining a conversion result; The plug-in is used to establish an association relationship between the key information and the conversion result based on the source code file generation sub-rule, and the second source code file corresponding to each of the second-type languages is obtained to obtain the at least one second source code file.
4. The method according to claim 3, characterized in that The information acquisition sub-rule includes an information acquisition method and preset requirements that the information to be acquired must meet, and the using of the plug-in to acquire key information from the abstract syntax tree based on the information acquisition sub-rule includes: The plug-in is used to traverse all nodes of the abstract syntax tree, and during the traversal process, information that meets the preset requirements and is contained in each of the nodes is extracted to obtain the key information.
5. The method according to claim 2, characterized in that: Before performing lexical analysis and grammatical analysis on the first source code file by using the preset compiler to obtain the abstract syntax tree, the method further includes: In the case where the first source code file carries a first comment, the preset compiler is used to set the comment removal option to an off state, and the off state is used to indicate that the second source code file carries a second comment corresponding to the first comment.
6. The method according to claim 2, characterized in that Before the preset compiler is used to parse the abstract syntax tree to obtain the intermediate code, the method further includes: For the interface indicated by the abstract syntax tree, if the structure of the interface cannot achieve conversion adapted to the second type of language, compiling is suspended and / or an alarm notification is generated.
7. The method according to claim 1, characterized in that Before determining the first source code file to be compiled according to the compilation instruction in response to the received compilation instruction, the method further includes: In response to the received interface update instruction, determine the source code to be updated and update reference information according to the interface update instruction, wherein the update reference information is used to guide the update of the source code, and the update reference information includes update item description information and forward compatibility requirement information; The source code is updated based on the update reference information to obtain the first source code file.
8. An interface file generating device, characterized in that: The device comprises: A response module: used for responding to a received compilation instruction and determining a first source code file to be compiled according to the compilation instruction, wherein the first source code file is used to describe a native layer interface of a software development kit, and the native layer interface supports a first class language; A first compiling module: used to process the first source code file by using a compiler front end, to obtain an abstract syntax tree, an intermediate code, and at least one second source code file indicating a glue layer interface corresponding to the first source code file, wherein the second source code file is generated based on the abstract syntax tree, each of the second source code files supports a second type of language, and the glue layer interface is used to translate an interface call request using the second type of language into an interface call request using the first type of language; The second compilation module is used to process the intermediate code using the compiler backend to obtain a first executable file indicating the native layer interface, and to process the at least one second source code file respectively to obtain at least one second executable file indicating the glue layer interface.
9. An electronic device, characterized in that: The electronic device includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the at least one processor to implement the interface file generation method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the interface file generation method according to any one of claims 1 to 7.
Citation Information
Cited By
Strategy translation and kernel protection method and system applied to container environment
CN121070380A
Cross-language interface binding method and device and electronic equipment
CN122261580A
