CN-121996255-A - Bridging method, system, terminal and storage medium for KaihongOS cross-language interface
Abstract
The invention relates to the technical field of computer software and discloses a bridging method, a bridging system, a bridging terminal and a storage medium for a KaihongOS cross-language interface. The method comprises the steps of analyzing an interface definition file to obtain function statement information of a target interface, analyzing a native interface definition file to obtain implementation information of a native interface corresponding to the target interface, automatically generating a bridge function code conforming to a target running environment according to preset bridge rules based on the function statement information and the implementation information, and bridging a cross-language interface through the bridge function code. According to the invention, by automatically analyzing and generating codes, and improving the quality of the codes, the bridge function codes conforming to the target running environment are automatically generated, so that repeated labor and potential errors in manual writing are avoided. The preset bridging rule ensures the consistency and maintainability of codes, and can effectively reduce the technical threshold and shorten the project period.
Inventors
- ZHANG SHOUZHONG
Assignees
- 深圳开鸿数字产业发展有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20251229
Claims (10)
- 1. A bridging method for a KaihongOS cross-language interface, the bridging method for a KaihongOS cross-language interface comprising: Analyzing the interface definition file to obtain function statement information of the target interface; analyzing a native interface definition file to obtain implementation information of a native interface corresponding to the target interface; And based on the function statement information and the implementation information, automatically generating a bridging function code conforming to a target running environment according to a preset bridging rule, and bridging a cross-language interface through the bridging function code.
- 2. The bridging method for KaihongOS cross-language interfaces according to claim 1, wherein parsing the interface definition file to obtain function declaration information of the target interface includes: performing lexical analysis and grammar analysis on the interface definition file to generate an abstract grammar tree; Traversing the abstract syntax tree, identifying and extracting function declaration nodes, and obtaining initial function declaration information according to the function declaration nodes; And converting the initial function statement information into a standardized intermediate representation, and uniformly mapping the data types of the intermediate representation to obtain the function statement information, wherein the function statement information comprises a function name, a parameter list, a return type and a call type.
- 3. The bridging method for a KaihongOS cross-language interface according to claim 2, wherein the parsing the native interface definition file to obtain implementation information of a native interface corresponding to the target interface includes: Preprocessing the original interface definition file, analyzing the header file content of the preprocessed original interface definition file, and ignoring macro definition and conditional compiling instructions to obtain grammar tree information of function statement; Extracting a function signature of a native interface corresponding to the target interface from the grammar tree information, wherein the function signature comprises a function name, a return value type, a parameter type list and a parameter sequence; And according to the function signature, a mapping relation table from the native programming language type to the native application program interface type is established, and the mapping relation table is used as the implementation information of the native interface.
- 4. The bridging method for a cross-language interface of claim KaihongOS, wherein the automatically generating, based on the function declaration information and the implementation information, a bridging function code that meets a target operating environment according to a preset bridging rule, bridging the cross-language interface through the bridging function code, includes: creating a bridging function basic framework conforming to the target running environment specification according to the function name in the function statement information, wherein the basic framework comprises standardized function signatures and an error processing mechanism; Generating a parameter analysis and type conversion logic code according to a type mapping relation between the parameter types in the function declaration information and the corresponding types in the implementation information, and injecting the parameter analysis and type conversion logic code into the bridge function basic framework, wherein the parameter analysis and type conversion logic code is used for converting the parameters described by the high-level language into parameters identifiable by the native programming language; And generating a native interface calling logic and a returned result processing logic according to the calling type in the function declaration information and the realization information, and injecting the native interface calling logic and the returned result processing logic into the bridge function basic framework to obtain the bridge function code, wherein parameters used by the native interface calling logic are native language parameters processed by the parameter analysis and type conversion logic code.
- 5. The bridging method for a KaihongOS cross-language interface according to claim 4, wherein creating a bridging function basic framework that meets the target operating environment specification includes: Generating a corresponding bridging function name according to the function name of the target interface; Constructing a bridging function signature taking a specific type as a return value and taking a running environment handle and a callback information handle as input parameters; State variables for recording and checking the call state of the application program interface are declared inside the bridging function.
- 6. The bridging method for a KaihongOS cross-language interface according to claim 5, wherein generating a parameter parsing and type conversion logic code according to a type mapping relation between a parameter type in the function declaration information and a corresponding type in the implementation information includes: Generating a code segment for analyzing the number of parameters and the parameter value array from the callback information handle according to the mapping relation between the parameter types in the function declaration information and the types corresponding to the implementation information; Generating a type check code and a type conversion code for each parameter in the code segment based on a preset type mapping relation; the parameter analysis and type conversion logic code comprises the code segment, the type checking code and the type conversion code, wherein the type conversion code is used for converting parameter value representations in a high-level language running environment into variable representations in a native programming language.
- 7. The bridging method for KaihongOS's cross-language interface of claim 4 wherein generating native interface call logic and returning result processing logic comprises: when the call type is synchronous, the following operations are performed: generating codes for directly calling the native interfaces, and transmitting the codes into converted native language parameters during calling; Generating codes for converting the return value of the native interface into a bridge function return value type; When the call type is an asynchronous call, the following operations are performed: Generating code for creating an asynchronous task object; Generating an asynchronous execution function code, wherein the asynchronous execution function code comprises a call statement for a native interface; Generating a completion callback function code, wherein the completion callback function code comprises logic for processing asynchronous operation results and analyzing or rejecting asynchronous promised objects; Code is generated that submits the asynchronous task object to an execution queue.
- 8. A bridging system for a KaihongOS cross-language interface, the bridging system for a KaihongOS cross-language interface comprising: the first analysis module is used for analyzing the interface definition file and obtaining function statement information of the target interface; the second analysis module is used for analyzing the primary interface definition file and obtaining the realization information of the primary interface corresponding to the target interface; And the code generation module is used for automatically generating a bridging function code conforming to the target running environment according to a preset bridging rule based on the function statement information and the implementation information, and bridging the cross-language interface through the bridging function code.
- 9. A terminal comprising a memory, a processor and a bridging program for a KaihongOS cross-language interface stored on the memory and executable on the processor, the bridging program for a KaihongOS cross-language interface implementing the steps of the bridging method for a KaihongOS cross-language interface as claimed in any one of claims 1 to 7 when executed by the processor.
- 10. A computer readable storage medium storing a bridging program for a cross-language interface of KaihongOS, which bridging program for a cross-language interface of KaihongOS, when executed by a processor, implements the steps of the bridging method for a cross-language interface of KaihongOS as claimed in any one of claims 1 to 7.
Description
Bridging method, system, terminal and storage medium for KaihongOS cross-language interface Technical Field The present invention relates to the field of computer software technologies, and in particular, to a bridging method, a bridging system, a bridging terminal and a computer readable storage medium for a KaihongOS cross-language interface. Background In the Kai hong operating system (Kaihong Operating System, kaihongOS), a layered architecture is typically employed in which the application layer is developed using a high-level language such as JavaScript (JS) or TYPESCRIPT (type script, TS), where TYPESCRIPT may be a ark type script (ARK TYPESCRIPT, ARKTS). The system framework layer uses a native language such as C (C programming language) or C++ (C++ programming language, C++ Programming Languages) to implement core functions. The local application program interface (NATIVE API, NAPI) serves as an important bridge mechanism, so that JavaScript code of the application layer can safely and efficiently call a C or C++ interface of the system layer. Currently, writing the corresponding NAPI function for each C or c++ interface that needs to be exposed to the application layer is a highly human-dependent process. The developer must deeply understand the complex programming specification of the NAPI, and manually complete the tedious and error-prone steps of type conversion, asynchronous callback processing, memory management, and the like. This development mode has the following significant drawbacks: 1. the efficiency is low, when the system framework needs to open a large number of interfaces to the application layer, manually writing NAPI functions becomes a development bottleneck, and seriously slow the project progress. 2. The skill threshold is high, the developer is required to be proficient in both high-level language and native language, and the NAPI programming skills are mastered skillfully, so that the labor cost is increased. 3. The code quality is uneven, the coding habit and style of different developers are different, the generated NAPI codes are not uniform in style, the readability and maintainability are poor, and potential errors are easy to introduce. Accordingly, the prior art is still in need of improvement and development. Disclosure of Invention The invention mainly aims to provide a bridging method, a bridging system, a bridging terminal and a computer readable storage medium for KaihongOS cross-language interfaces, and aims to solve the problems of low development efficiency, over-high technical threshold and uneven code quality of cross-language interface bridging caused by manually programming NAPI bridging functions in the development of an operating system in the prior art. To achieve the above object, the present invention provides a bridging method for a KaihongOS cross-language interface, the bridging method for a KaihongOS cross-language interface includes the following steps: Analyzing the interface definition file to obtain function statement information of the target interface; analyzing a native interface definition file to obtain implementation information of a native interface corresponding to the target interface; And based on the function statement information and the implementation information, automatically generating a bridging function code conforming to a target running environment according to a preset bridging rule, and bridging a cross-language interface through the bridging function code. Further, the parsing the interface definition file to obtain function declaration information of the target interface includes: performing lexical analysis and grammar analysis on the interface definition file to generate an abstract grammar tree; Traversing the abstract syntax tree, identifying and extracting function declaration nodes, and obtaining initial function declaration information according to the function declaration nodes; And converting the initial function statement information into a standardized intermediate representation, and uniformly mapping the data types of the intermediate representation to obtain the function statement information, wherein the function statement information comprises a function name, a parameter list, a return type and a call type. Further, the analyzing the native interface definition file to obtain implementation information of the native interface corresponding to the target interface includes: Preprocessing the original interface definition file, analyzing the header file content of the preprocessed original interface definition file, and ignoring macro definition and conditional compiling instructions to obtain grammar tree information of function statement; Extracting a function signature of a native interface corresponding to the target interface from the grammar tree information, wherein the function signature comprises a function name, a return value type, a parameter type list and a parameter sequence; And according to