Target file construction method and device, and storage medium

By obtaining the identification information and function declaration parameters of the Objective-C header file, the target file is constructed, which solves the problem of slow compilation speed caused by bridging header files and achieves fast and accurate file conversion.

CN115757287BActive Publication Date: 2026-01-27TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111032798.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-03
Publication Date
2026-01-27
Estimated Expiration
2041-09-03

AI Technical Summary

Technical Problem

The compilation speed is too slow when creating bridging header files during the process of converting Objective-C header files into object files.

Method used

By obtaining the header files of the preset language, the identification information of the target file is determined, the target keywords and function declaration parameters in the header file are obtained, and the target file is constructed, thus avoiding the creation of bridging header files.

Benefits of technology

It enables the rapid and accurate conversion of header files in the default language into files in the target language without creating a bridging header file, thus improving compilation speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115757287B_ABST
    Figure CN115757287B_ABST
Patent Text Reader

Abstract

The application discloses a target file construction method and device and a storage medium, which can be applied to various scenes such as cloud technology, AI, intelligent transportation and vehicle-mounted devices, and the method comprises the following steps: obtaining a header file in a preset language; determining the identification information of a target file based on the identification information of the header file; the target file is a file in a target language; if the header file does not include a class declaration keyword, obtaining a target keyword in the header file; if the target keyword is a function declaration, obtaining the name of a first function corresponding to the function declaration and a first parameter; determining the name of a second function in the target file based on the name of the first function; determining a second parameter of the second function matched with the first parameter; and constructing the target file based on the identification information of the target file, the name of the second function and the second parameter. The application realizes the quick and accurate conversion of the header file in the preset language into the file in the target language.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus and storage medium for constructing an object file. Background Technology

[0002] In related technologies, a bridging header file needs to be created during the process of converting Objective-C header files into object files; if a large number of Objective-C header files are imported into the bridging header file, the compilation speed will be too slow.

[0003] Therefore, it is necessary to provide a method, apparatus, and storage medium for constructing target files, which can quickly and accurately convert header files of a preset language into files of the target language without creating a bridging header file. Summary of the Invention

[0004] This application provides a method, apparatus, and storage medium for constructing target files, which can quickly and accurately convert header files of a preset language into files of the target language without creating a bridging header file.

[0005] On the one hand, this application provides a method for constructing an object file, the method comprising:

[0006] Retrieve the header file for the preset language;

[0007] Based on the identification information of the header file, the identification information of the target file is determined; the target file is a file in the target language.

[0008] If the header file does not include a class declaration keyword, obtain the target keyword from the header file;

[0009] If the target keyword is a function declaration, obtain the name and first parameter of the first function corresponding to the function declaration;

[0010] Based on the name of the first function, determine the name of the second function in the target file;

[0011] Determine the second parameter of the second function that matches the first parameter;

[0012] The target file is constructed based on the identification information of the target file, the name of the second function, and the second parameter.

[0013] On the other hand, an apparatus for constructing an object file is provided, the apparatus comprising:

[0014] The header file retrieval module is used to retrieve header files for the preset language;

[0015] The identification information determination module is used to determine the identification information of the target file based on the identification information of the header file; the target file is a file in the target language.

[0016] The target keyword acquisition module is used to acquire the target keyword in the header file if the header file does not contain a class declaration keyword.

[0017] The first parameter acquisition module is used to acquire the name of the first function corresponding to the function declaration and the first parameter if the target keyword is a function declaration;

[0018] The second function name determination module is used to determine the name of the second function in the target file based on the name of the first function;

[0019] The second parameter determination module is used to determine the second parameter of the second function that matches the first parameter;

[0020] The target file construction module is used to construct the target file based on the identification information of the target file, the name of the second function, and the second parameter.

[0021] On the other hand, a target file construction device is provided, the device including a processor and a memory, the memory storing at least one instruction or at least one program segment, the at least one instruction or the at least one program segment being loaded and executed by the processor to implement the target file construction method as described above.

[0022] On the other hand, a computer storage medium is provided that stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the method for constructing the target file as described above.

[0023] On the other hand, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, executes the computer instructions, and causes the computer device to perform the method for constructing the object file as described above.

[0024] The method, apparatus, and storage medium for constructing the target file provided in this application have the following technical advantages:

[0025] In this application, when converting a header file of a preset language into a file of a target language, for header files that do not include class declaration keywords, the target keyword is obtained; if the target keyword is a function declaration, the name and first parameter of the first function corresponding to the function declaration are obtained; and the name and second parameter of the second function in the target file are determined; finally, based on the identification information of the target file, the name of the second function, and the second parameter, the target file is constructed, thereby quickly constructing the target file and realizing the rapid and accurate conversion of a header file of a preset language into a file of a target language without creating a bridging header file. Attached Figure Description

[0026] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This is a schematic diagram of a target file construction system provided in an embodiment of this application;

[0028] Figure 2 This is a flowchart illustrating a method for constructing an object file according to an embodiment of this application;

[0029] Figure 3 This is a flowchart illustrating a method for obtaining the name and first parameter of the first function corresponding to the above function declaration, provided in an embodiment of this application.

[0030] Figure 4 This is a flowchart illustrating another method for constructing an object file provided in an embodiment of this application;

[0031] Figure 5 This is a flowchart illustrating a method for constructing the target file based on the identification information of the target file, the name of the second function, and the second parameter, according to an embodiment of this application.

[0032] Figure 6 This is a flowchart illustrating a method for constructing the target file based on the identification information and configuration information of the target file, as provided in an embodiment of this application.

[0033] Figure 7 This is a flowchart illustrating the method for loading target services provided in an embodiment of this application;

[0034] Figure 8 This is a schematic diagram of the data configuration class in the OC header file provided in an embodiment of this application;

[0035] Figure 9 This is a schematic diagram of the data configuration class for a Swift file provided in an embodiment of this application;

[0036] Figure 10 This is a diagram of the editing engineering system display interface provided in the embodiments of this application;

[0037] Figure 11 This is a flowchart illustrating a file conversion method corresponding to a pop-up window during video playback, as provided in an embodiment of this application.

[0038] Figure 12 This is a diagram illustrating how Swift projects can call Objective-C header files using existing technology.

[0039] Figure 13 This is a schematic diagram of the structure of a target file construction apparatus provided in an embodiment of this application;

[0040] Figure 14 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation

[0041] Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and networks within a wide area network or local area network to achieve data computing, storage, processing, and sharing.

[0042] Cloud technology is a collective term for network technologies, information technologies, integration technologies, management platform technologies, and application technologies applied to the cloud computing business model. It can form resource pools, providing flexible and convenient on-demand access. Cloud computing technology will become a crucial support. Backend services of technical network systems require substantial computing and storage resources, such as video websites, image websites, and many portal websites. With the rapid development and application of the internet industry, every item may have its own identification mark in the future, requiring transmission to backend systems for logical processing. Data at different levels will be processed separately, and various industry data will all require robust system support, which can only be achieved through cloud computing.

[0043] Cloud storage is a new concept that extends and develops from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as a storage system) refers to a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of storage devices of various types (storage devices are also called storage nodes) in the network to work together through application software or application interfaces to provide data storage and business access functions to the outside world.

[0044] Currently, the storage method in storage systems is as follows: Logical volumes are created, and during creation, physical storage space is allocated to each logical volume. This physical storage space may consist of a single storage device or the disks of several storage devices. Clients store data on a logical volume, which means storing the data on the file system. The file system divides the data into many parts, each part being an object. Each object contains not only the data but also additional information such as a data identifier (ID, IDentity). The file system writes each object to the physical storage space of that logical volume, and it records the storage location information of each object. Therefore, when a client requests access to data, the file system can allow the client to access the data based on the storage location information of each object.

[0045] The process of allocating physical storage space for a logical volume in a storage system is as follows: Based on the capacity estimate of the objects stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the grouping of Redundant Array of Independent Disks (RAID), the physical storage space is pre-divided into strips. A logical volume can be understood as a strip, thus allocating physical storage space to the logical volume. In this embodiment, target files converted from header files of a preset language can be stored in the cloud.

[0046] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0047] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0048] Please see Figure 1 , Figure 1 This is a schematic diagram of a target file construction system provided in an embodiment of this application, such as... Figure 1 As shown, the system for building this target file can include at least server 01 and client 02.

[0049] Specifically, in the embodiments of this specification, server 01 may include a standalone server, a distributed server, or a server cluster composed of multiple servers. It may also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Server 01 may include a network communication unit, a processor, and a memory, etc. Specifically, server 01 can be used to construct target files in a target language based on header files of a preset language.

[0050] Specifically, in the embodiments of this specification, the client 02 may include physical devices such as smartphones, desktop computers, tablets, laptops, digital assistants, smart wearable devices, smart speakers, in-vehicle terminals, and smart TVs. It may also include software running on the physical device, such as web pages provided to users by service providers, or applications provided to users by such service providers. Specifically, the client 02 can be used to quickly and accurately display business modules in a preset language within an application in the target language, according to user needs.

[0051] The following describes a method for constructing the object file according to this application. Figure 2 This is a flowchart illustrating a method for constructing an object file according to an embodiment of this application. This specification provides the operational steps of the method described in the embodiments or flowcharts, but based on conventional or non-inventive labor, more or fewer operational steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual system or server product execution, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown in the attached drawings... Figure 2 As shown, the method may include:

[0052] S201: Obtain the header file for the default language.

[0053] Specifically, in this application embodiment, the header file for the preset language can be an Objective-C header file; some applications involve mixed programming techniques using Objective-C and Swift languages; where Objective-C stands for Objective-C, usually written as ObjC or OC, and less commonly Objective-C or Obj-C, is an object-oriented programming language that extends C. It is mainly used on Mac OS X (the proprietary operating system for Macintosh computers) and GNUstep (an open software initiative implementing the OpenStep interface, aiming to provide a cross-platform object-oriented programming development environment), two systems that use the OpenStep standard. Swift is a new development language released by Apple at the 2014 WWDC Apple Developer Conference, which can run together with Objective-C on macOS and iOS platforms, and is used to build applications based on Apple platforms.

[0054] This embodiment focuses on optimizations for calling Objective-C methods in a Swift project. The default header file in this embodiment is used to store configuration information that will not change within a preset timeframe. The configuration information in the Objective-C header file is generally macro definitions and global variables; for example, it can be basic configuration information for the project, including the address used for network requests, the public key of the certificate used, and a fixed URL; it can also be a singleton object class, which contains data that exists only once during program execution, such as user data, device information, and a data downloader.

[0055] S203: Based on the identification information of the above header file, determine the identification information of the target file; the above target file is a file in the target language.

[0056] In this embodiment, the target language can be Swift; correspondingly, the target file is a Swift file. Specifically, the header file's identification information can be used as the target file's identification information; the header file's identification information can be the header file's name, and the target file's identification information can be the target file's name; the header file's name can be used as the target file's name.

[0057] In this embodiment, after obtaining the header file for the preset language, the header file name (Name) can be obtained through the path suffix, which can be .h, .c, .m, etc. The target file name, i.e., the Swift file name, can be created by executing a target instruction; the target instruction can be `touch Name.swift`; the identifier information of the target file can be the same as the identifier information of the header file, meaning a Swift file name with the same name as the Objective-C header file can be created.

[0058] S205: If the above header file does not include the class declaration keyword, obtain the target keyword from the above header file.

[0059] In this embodiment, keywords in the header file (e.g., .h file) can be obtained to determine if there is a class declaration keyword, which can be @interface. If there is no class declaration keyword, separate conversions are performed for macro definitions and static variables. The target keyword can be a string, such as a macro definition keyword (e.g., #define), or a function declaration.

[0060] In this embodiment of the application, the header file may include multiple keywords; if the header file does not include a class declaration keyword, before obtaining the target keyword in the header file, the method further includes:

[0061] Iterate through each keyword in the header file until the end keyword is reached;

[0062] Determine if a class declaration keyword exists.

[0063] In this embodiment of the application, the ending keyword can be @end.

[0064] S207: If the target keyword above is a function declaration, obtain the name of the first function corresponding to the function declaration and its first parameter.

[0065] In the embodiments of this application, such as Figure 3 As shown, if the target keyword is a function declaration, the name and first parameter of the first function corresponding to the function declaration are obtained, including:

[0066] S2071: If the target keyword above is a function declaration, obtain the name of the first function corresponding to the function declaration above.

[0067] In the embodiments of this application, such as Figure 4 As shown, the above method also includes:

[0068] S401: If the above target keyword is not a function declaration, obtain the target value corresponding to the above target keyword and determine the above target keyword as the first keyword.

[0069] Specifically, in the embodiments of this application, the target keyword may include macro definition keywords and static keywords, wherein the macro definition keyword may be a string or a function; the target keyword non-function declaration includes the target keyword being a string.

[0070] In this embodiment, macro definitions can define variables or functions. If a macro definition is code, it needs to be replaced with the code implementation at compile time. For example, when initializing network requests, such as loading a page, loading a player, or downloading a video, a network request for data is initiated. If the network request is encapsulated as a macro definition or a function, the function will be replaced wherever it is used, replacing the macro with a specific application implementation. The specific implementation can be parameters, such as the App key (the unique identifier of the App), pid (the platform identifier of the App, such as the identifier of iPhone, iwatch, or iPad), and URL parameters in HTTP. When these parameters are used, they are replaced with specific values ​​during the compilation stage. Macro definitions can also define functions and methods. Similarly, they are replaced during compilation, and in the case of Swift static language, they are replaced with the implementation only during the actual execution of the program.

[0071] In this embodiment of the application, if the target keyword is not a function declaration, obtaining the target value corresponding to the target keyword and determining the target keyword as the first keyword may include:

[0072] If the target keyword is a string, obtain the target value corresponding to the string and determine the target keyword as the first keyword.

[0073] S403: Based on the second mapping information, determine the second keyword that matches the first keyword; the second mapping information represents the mapping relationship between the first keyword and the second keyword.

[0074] In this embodiment of the application, a correspondence between the first keyword of the Objective-C language and the second keyword of the Swift language can be pre-built, with a one-to-one correspondence between the first keyword and the second keyword; thereby facilitating the rapid conversion of Objective-C header files into Swift files.

[0075] S405: Construct the target file based on the identification information of the target file, the second keyword, and the target value.

[0076] Specifically, in this embodiment of the application, the correspondence between the second keyword and the target value can be stored in the target file, and the target file can be named using the identification information of the target file.

[0077] S2073: Determine the type of the first function based on the syntactic sugar in its name;

[0078] Specifically, in this embodiment, the Objective-C header file may include C functions or Objective-C functions; when declaring functions, it is necessary to determine whether it is a C function or an Objective-C function based on the syntactic sugar preceding the function name; different language conversion rules are set for different functions. Syntactic sugar, also translated as sugar-coated syntax, refers to a type of syntax added to a computer language. This syntax does not affect the functionality of the language but makes it easier for programmers to use. Generally speaking, using syntactic sugar can increase the readability of the program, thereby reducing the chance of errors in the program code.

[0079] S2075: If the above syntactic sugar includes the target character, determine that the above first function is a function of the preset language;

[0080] Specifically, in this embodiment, the type of the first function may include a function type of a preset language and a function type of the C language; wherein, the preset language may be Objective-C; the corresponding first function may be an Objective-C function or a C function. The syntactic sugar includes target characters; for example, Objective-C functions generally begin with "+" or "-", and C functions generally have a return value type. If it is a C function, the function body can be directly copied to the Swift file.

[0081] S2077: Obtain the first parameter of the first function mentioned above.

[0082] In this embodiment of the application, after determining that the first function is a function of a preset language, its corresponding first parameter is obtained; that is, the function is extracted.

[0083] In this embodiment of the application, after obtaining the first parameter of the first function, the method further includes:

[0084] Determine the type of the first parameter mentioned above.

[0085] Specifically, in the embodiments of this application, the type of the first parameter includes data type and object type. For example, the first parameter can be a basic data type, such as int, float, double, none, etc., and these types are converted according to the mapping relationship in Table 1.

[0086] In this embodiment of the application, if the first parameter is an object type, the above method further includes:

[0087] Get the object's header file;

[0088] The target file is constructed based on the identification information of the target file and the header files of the aforementioned objects.

[0089] In this embodiment, if the first parameter is an object type, such as a person, player, view, button, or image, no type conversion is performed. Instead, the object's header file is imported, indicating where the object exists and its storage location. The index relationship is then exported, which is equivalent to performing a conversion of the declaration part; that is, converting the Objective-C declaration part into the Swift declaration part.

[0090] S209: Based on the name of the first function mentioned above, determine the name of the second function in the above object file.

[0091] In this embodiment of the application, the name of the second function may be the same as the name of the first function.

[0092] S2011: Determine the second parameter of the second function that matches the first parameter.

[0093] In this embodiment of the application, the second parameter of the second function that matches the first parameter includes:

[0094] If the first parameter is a data type, the second parameter of the second function that matches the first parameter is determined based on the first mapping information; the first mapping information represents the mapping relationship between the first parameter and the second parameter.

[0095] Specifically, in this embodiment of the application, if the first parameter is a data type, it will be converted into the second parameter according to the rules in Table 1;

[0096] S2013: Based on the identification information of the target file, the name of the second function, and the second parameter, construct the target file.

[0097] In the embodiments of this application, such as Figure 5 As shown, the above method also includes:

[0098] S2012: If the above header file does not include the class declaration keyword, the first structure of the above object file is created based on the static variables in the above header file.

[0099] In this embodiment of the application, the identification information of the first structure can be determined according to the header file identification information (e.g., header file name); then the static variables in the header file are extracted, and static variables with the same static variables in the header file are created in the first structure; the data type conversion rules in the static variables are shown in Table 1.

[0100] In this embodiment of the application, a structure can include a lot of information, such as data address, image information, player information, etc. If a static variable in the OC header file is matched, the same static variable is created in the first structure of the target file, which is equivalent to a data initialization process.

[0101] Table 1

[0102] Objective-C basic data type parameter declaration Swift data type declarations intintValue var intValue:Int double doubleValue var intValue1:Double float floatValue var intValue2:Float long longValue var intValue3:Int8 short shortValue var intValue4:Int16 signed signedValue var intValue5:Int32 unsigedunsigedValue var intValue6:Int64

[0103] Accordingly, the above-mentioned target file is constructed based on the identification information of the target file, the name of the second function, and the second parameter, including:

[0104] S20131: Store the name of the second function and the second parameter in the first structure to obtain the stored first structure;

[0105] S20133: Based on the identification information of the above target file, name the first structure after storage to obtain the named structure;

[0106] S20135: Use the structure named above as the target file.

[0107] In the embodiments of this application, such as Figure 6 As shown, the above method also includes:

[0108] S601: If the above header file includes a class declaration keyword, create a second structure of the above object file based on the above class declaration keyword;

[0109] Specifically, in this embodiment of the application, the second structure for creating the target file based on the class declaration keyword may include:

[0110] Based on the above class declaration keywords, the static keywords in the above object file are determined;

[0111] Based on the static keywords mentioned above, construct the second structure of the target file.

[0112] Specifically, in the embodiments of this application, one class declaration corresponds to one second structure, and the number of corresponding second structures is equal to the number of class names corresponding to @interface, with the last keyword of creation being @end.

[0113] S603: Based on the member attribute information in the above class declaration, create the configuration information of the above target file in the above second structure;

[0114] S605: Construct the target file based on the identification and configuration information of the target file.

[0115] In this embodiment of the application, before creating the configuration information of the target file in the second structure based on the member attribute information in the class declaration, the method further includes:

[0116] The target number of members whose attribute information is obtained above;

[0117] In the second structure described above, create the target number of singleton objects;

[0118] Accordingly, the configuration information for creating the target file in the second structure based on the member attribute information in the class declaration includes:

[0119] Based on the member attribute information in the above class declaration, the configuration information of the above target file is created in the above target number of singleton objects; wherein, each singleton object corresponds to one configuration information.

[0120] Specifically, in this embodiment, when the Objective-C header file contains a class declaration, it indicates that the class is a singleton data type. In Swift, a struct with the same name needs to be created, and a singleton object is created inside the struct using the `static` keyword. Member properties corresponding to `@property` are scanned and declared identically using the `var` keyword in the Swift struct, without setting default values. If there are multiple class declarations, the same number of structs with the same name are created in the Swift file, and the conversion ends when the `@end` keyword of the last class is encountered.

[0121] In the embodiments of this application, such as Figure 7 As shown, the above method also includes:

[0122] S701: In the application of the target language, in response to the target business loading request, obtain the data class name corresponding to the above target business;

[0123] In this embodiment of the application, if the application is a video playback application, the corresponding target service can be playback service, download service, advertising pop-up service, etc.; each target service corresponds to a data class name.

[0124] S703: Determine the identification information of the target file that matches the above data class name;

[0125] In this embodiment of the application, the data class name and the identification information of the target file are mapped, and the identification information of the corresponding target file can be determined according to the data class name.

[0126] S705: Obtain the target file based on the identification information of the target file;

[0127] S707: Load the target service as described above, based on the target file.

[0128] In this embodiment, loading the target service can be displaying the page corresponding to the target service. The target file constructed using this embodiment ensures that the target service loads quickly and accurately, thereby improving the user experience.

[0129] Specifically, in this embodiment, the target file can be a configuration file, which may include configuration information that will not change within a preset time range; the configuration information may be as follows: Figure 8 The App key (a unique identifier for the App), pid (the platform identifier for the App, such as the identifier for iPhone, iWatch, or iPad), and the URL parameters in the HTTP request; custom ID (a custom ID used to identify the data initialized in the network information); gateway-related attribute names, such as request paths and HTTP URLs, are used to identify basic network functions; TCP port is the corresponding port number; and GWRkey is the public key used for encryption. A project may contain dozens to hundreds of basic information items, such as basic user configuration information (user nickname, profile picture, etc.), which are the basic data in the App; this data will not change during a single run or within a certain time frame.

[0130] In a specific implementation, such as in an XX video app, some business functions, like the playback or download module, require configuration information (playback parameters, playback duration, playback data address, and download data address). If these are fixed parameters, they would be in the Objective-C header file. However, since the technology used is mixed-language, and the application is a Swift project, it needs to be converted to a Swift configuration file. The application uses a Swift project; the Swift project is a code project written in the Swift language. For example, when playing a video, a pop-up window might appear recommending video-related advertisements or content.

[0131] In a specific embodiment, the flowchart of the file conversion method corresponding to the pop-up window during video playback is as follows: Figure 11 As shown, it includes the following steps:

[0132] S1101: Import OC header files;

[0133] S1103: Script execution, starting to scan OC header files;

[0134] S1105: Creates files based on the Swift language, with built-in structures;

[0135] S1107: Determine if the Objective-C header file includes the @interface keyword;

[0136] S1109: If the @interface keyword is included, create a content structure based on the keyword and the Swift language;

[0137] S11011: Create a static struct singleton object;

[0138] S11013: Scan member attributes in the file and create member variables of the corresponding type in the singleton object;

[0139] S11015: During the file scanning process, the scan will end when @end is encountered;

[0140] S11017: Conversion complete.

[0141] In some embodiments, the above method further includes:

[0142] S11009: If the @interface keyword is not included in the Objective-C header file, extract the macro definitions and the static keyword;

[0143] S110011: Determine if an Objective-C header file includes functions;

[0144] S110013: If an Objective-C header file includes a function, create a function with the same name in the Swift file;

[0145] S110015: Scan the parameters in the header file and perform parameter mapping according to the preset mapping relationship;

[0146] S110017: During the file scanning process, the scan will continue until the last data declaration is encountered;

[0147] S11017: Conversion complete.

[0148] In some embodiments, the above method further includes:

[0149] S1100131: If the OC header file does not include functions, jump to step S110015.

[0150] In this embodiment, the pop-up module corresponds to the OC header file. The pop-up module accesses the data information in the player through the struct name converted by Swift, such as the video being played, the video address, and the video's associated information, and then pops it up.

[0151] In a specific embodiment, such as Figure 10 As shown, Figure 10 To edit the project system's display interface diagram, you can set information such as project name, application ID, and workspace ID before importing the configuration file. Triggering the "Import Configuration File" option allows you to import files from the side folders (AA, BB, or CC). For example, you can import... Figure 8 Import the OC header files into the system to convert them into... Figure 9 The Swift file shown; the data configuration class in the Objective-C header file, such as... Figure 8 As shown, the data configuration class in the converted Swift file is as follows: Figure 9 As shown; in Objective-C header files, data is generally mainly in the form of macro definitions, while in Swift files, it is generally mainly in the form of static variables contained in structs; macro definitions can be understood as string replacement, where the compiler replaces the places where macros are used with the values ​​of the specific implementation; static variables are allocated memory during program execution and released memory when the program ends.

[0152] In Swift projects, calling Objective-C methods requires creating a bridging header file and then importing the necessary Objective-C header files into that file. In a specific example, such as... Figure 12 As shown, in a Swift project, a BridgingHeader.h file needs to be pre-built. This file includes the import keyword to import Objective-C header files. If many Objective-C header files are imported, it can cause slow compilation speed. This embodiment, however, can quickly convert header files of the preset language into files of the target language without creating a bridging header file.

[0153] As can be seen from the technical solutions provided in the embodiments of this specification above, when converting a header file of a preset language into a file of a target language, the embodiments of this specification obtain the target keyword for header files that do not include class declaration keywords; if the target keyword is a function declaration, the name and first parameter of the first function corresponding to the function declaration are obtained; and the name and second parameter of the second function in the target file are determined; finally, based on the identification information of the target file, the name of the second function, and the second parameter, the target file is constructed, thereby quickly constructing the target file and realizing the rapid and accurate conversion of a header file of a preset language into a file of a target language without creating a bridging header file.

[0154] This application also provides an apparatus for constructing target files, such as... Figure 13 As shown, the above-mentioned device includes:

[0155] The header file acquisition module 1310 is used to acquire header files for a preset language;

[0156] The identification information determination module 1320 is used to determine the identification information of the target file based on the identification information of the header file mentioned above; the target file is a file in the target language.

[0157] The target keyword acquisition module 1330 is used to acquire the target keyword in the header file if the header file does not contain a class declaration keyword.

[0158] The first parameter acquisition module 1340 is used to acquire the name of the first function corresponding to the above function declaration and the first parameter if the above target keyword is a function declaration.

[0159] The second function name determination module 1350 is used to determine the name of the second function in the above-mentioned object file based on the name of the first function mentioned above;

[0160] The second parameter determination module 1360 is used to determine the second parameter of the second function that matches the first parameter.

[0161] The target file construction module 1370 is used to construct the target file based on the identification information of the target file, the name of the second function, and the second parameter.

[0162] In some embodiments, the first parameter acquisition module includes:

[0163] The first function name acquisition unit is used to acquire the name of the first function corresponding to the above function declaration if the above target keyword is a function declaration.

[0164] The first function type determination unit is used to determine the type of the first function based on the syntactic sugar in the name of the first function.

[0165] The function determination unit is used to determine that the first function is a function of the preset language if the above syntactic sugar includes the target character;

[0166] The first parameter acquisition unit is used to acquire the first parameter of the first function mentioned above.

[0167] In some embodiments, the above-described apparatus may further include:

[0168] The first function type determination module is used to determine the type of the first parameter mentioned above.

[0169] In some embodiments, the second parameter determination module described above may include:

[0170] The second parameter determination unit is used to determine the second parameter of the second function that matches the first parameter if the first parameter is a data type, based on the first mapping information; the first mapping information represents the mapping relationship between the first parameter and the second parameter.

[0171] In some embodiments, the above-described apparatus may further include:

[0172] The first keyword acquisition module is used to acquire the target value corresponding to the target keyword and determine the target keyword as the first keyword if the target keyword is not a function declaration.

[0173] The second keyword acquisition module is used to determine a second keyword that matches the first keyword based on the second mapping information; the second mapping information represents the mapping relationship between the first keyword and the second keyword.

[0174] The construction module is used to construct the target file based on the identification information of the target file, the second keyword, and the target value.

[0175] In some embodiments, the above-described apparatus may further include:

[0176] The first structure creation module is used to create the first structure of the target file based on the static variables in the header file if the header file does not contain the class declaration keyword.

[0177] In some embodiments, the target file building module described above may include:

[0178] A storage unit is used to store the name of the second function and the second parameter in the first structure to obtain the stored first structure.

[0179] The naming unit is used to name the stored first structure based on the identification information of the target file, so as to obtain the named structure.

[0180] The target file determination unit is used to use the named structure as the target file.

[0181] In some embodiments, the above-described apparatus may further include:

[0182] The second structure creation module is used to create a second structure of the target file based on the class declaration keyword if the header file includes the class declaration keyword.

[0183] The configuration information creation module is used to create the configuration information of the target file in the second structure above, based on the member attribute information in the above class declaration.

[0184] The target file construction module is used to construct the target file based on the identification information and configuration information of the target file.

[0185] In some embodiments, the above-described apparatus may further include:

[0186] The target quantity acquisition module is used to acquire the target quantity of the above member attribute information;

[0187] The singleton object creation module is used to create the target number of singleton objects in the second structure described above.

[0188] In some embodiments, the configuration information creation module may include:

[0189] The configuration information creation unit is used to create the configuration information of the target file in the target number of singleton objects based on the member attribute information in the above class declaration; wherein, each singleton object corresponds to one configuration information.

[0190] In some embodiments, the above-described apparatus may further include:

[0191] The data class name retrieval module is used in the target language application to retrieve the data class name corresponding to the target business in response to the target business loading request.

[0192] The identification information determination module is used to determine the identification information of the target file that matches the above data class name;

[0193] The target file acquisition module is used to acquire the target file based on the identification information of the target file.

[0194] The target service loading module is used to load the target service based on the target file mentioned above.

[0195] The apparatus and method embodiments described above are based on the same inventive concept.

[0196] This application provides an apparatus for building a target file. The apparatus includes a processor and a memory. The memory stores at least one instruction or at least one program. The at least one instruction or at least one program is loaded and executed by the processor to implement the target file building method provided in the above method embodiments.

[0197] The embodiments of this application also provide a computer storage medium, which can be disposed in a terminal to store at least one instruction or at least one program related to the method of constructing a target file in the method embodiment. The at least one instruction or at least one program is loaded and executed by the processor to implement the method of constructing a target file provided in the above method embodiment.

[0198] Embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method for constructing the target file provided in the above-described method embodiments.

[0199] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0200] The memory described in the embodiments of this specification can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for the functions, etc.; the data storage area may store data created based on the use of the aforementioned device, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.

[0201] The object file construction method provided in this application can be executed on a mobile terminal, computer terminal, server, or similar computing device. Taking running on a server as an example... Figure 14 This is a hardware structure block diagram of a server for a method of constructing an object file provided in an embodiment of this application. For example... Figure 14As shown, the server 1400 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1410 (CPUs 1410 may include, but are not limited to, microprocessors such as MCUs or programmable logic devices such as FPGAs), a memory 1430 for storing data, and one or more storage media 1420 (e.g., one or more mass storage devices) for storing application programs 1423 or data 1422. The memory 1430 and storage media 1420 may be temporary or persistent storage. The program stored in the storage media 1420 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 1410 may be configured to communicate with the storage media 1420 and execute the series of instruction operations stored in the storage media 1420 on the server 1400. Server 1400 may also include one or more power supplies 1460, one or more wired or wireless network interfaces 1450, one or more input / output interfaces 1440, and / or one or more operating systems 1421, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0202] The input / output interface 1440 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 1400. In one example, the input / output interface 1440 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In one example, the input / output interface 1440 can be a radio frequency (RF) module for wireless communication with the Internet.

[0203] Those skilled in the art will understand that Figure 14 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 1400 may also include... Figure 14 The more or fewer components shown, or having the same Figure 14 The different configurations shown.

[0204] As can be seen from the embodiments of the target file construction method, apparatus, server or storage medium provided in this application, when converting a header file of a preset language into a file of a target language, for header files that do not include class declaration keywords, the target keyword is obtained; if the target keyword is a function declaration, the name of the first function corresponding to the function declaration and the first parameter are obtained; and the name of the second function and the second parameter in the target file are determined; finally, based on the identification information of the target file, the name of the second function and the second parameter, the target file is constructed, thereby quickly constructing the target file and realizing the rapid and accurate conversion of a header file of a preset language into a file of a target language without creating a bridging header file.

[0205] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0206] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, devices, and storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0207] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer storage medium, such as a read-only memory, a disk, or an optical disk.

[0208] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for constructing an object file, characterized in that, The method includes: Retrieve the header file for the preset language; Based on the identification information of the header file, the identification information of the target file is determined; the target file is a file in the target language. If the header file does not include a class declaration keyword, obtain the target keyword from the header file; If the target keyword is a function declaration, obtain the name of the first function corresponding to the function declaration; The type of the first function is determined based on the syntactic sugar in the name of the first function; If the syntactic sugar includes the target character, the first function is determined to be a function of a preset language; Obtain the first parameter of the first function; Based on the name of the first function, determine the name of the second function in the target file; Determine the second parameter of the second function that matches the first parameter; The target file is constructed based on the identification information of the target file, the name of the second function, and the second parameter.

2. The method according to claim 1, characterized in that, After obtaining the first parameter of the first function, the method further includes: Determine the type of the first parameter; Accordingly, determining the second parameter of the second function that matches the first parameter includes: If the first parameter is a data type, the second parameter of the second function that matches the first parameter is determined based on the first mapping information; the first mapping information represents the mapping relationship between the first parameter and the second parameter.

3. The method according to claim 1, characterized in that, The method further includes: If the target keyword is not a function declaration, obtain the target value corresponding to the target keyword and determine the target keyword as the first keyword; Based on the second mapping information, a second keyword matching the first keyword is determined; the second mapping information represents the mapping relationship between the first keyword and the second keyword. The target file is constructed based on the identification information of the target file, the second keyword, and the target value.

4. The method according to claim 1, characterized in that, The method further includes: If the header file does not include a class declaration keyword, the first structure of the target file is created based on the static variables in the header file; Accordingly, constructing the target file based on the identifier information of the target file, the name of the second function, and the second parameter includes: The name of the second function and the second parameter are stored in the first structure to obtain the stored first structure; Based on the identification information of the target file, the stored first structure is named to obtain the named structure. The named structure is used as the target file.

5. The method according to claim 1, characterized in that, The method further includes: If the header file includes a class declaration keyword, a second structure of the target file is created based on the class declaration keyword; Based on the member attribute information in the class declaration, the configuration information of the target file is created in the second structure; The target file is constructed based on its identification and configuration information.

6. The method according to claim 5, characterized in that, Before creating the configuration information of the target file in the second structure based on the member attribute information in the class declaration, the method further includes: The target number of members whose attribute information is obtained; In the second structure, create the target number of singleton objects; Correspondingly, the step of creating the configuration information for the target file in the second structure based on the member attribute information in the class declaration includes: Based on the member attribute information in the class declaration, configuration information for the target file is created in the target number of singleton objects; wherein, each singleton object corresponds to one set of configuration information.

7. The method according to claim 5, characterized in that, The method further includes: In the application of the target language, in response to the target service loading request, the data class name corresponding to the target service is obtained; Determine the identification information of the target file that matches the data class name; The target file is obtained based on its identification information; Load the target service based on the target file.

8. An apparatus for constructing an object file, characterized in that, The device includes: The header file retrieval module is used to retrieve header files for the preset language; The identification information determination module is used to determine the identification information of the target file based on the identification information of the header file; the target file is a file in the target language. The target keyword acquisition module is used to acquire the target keyword in the header file if the header file does not contain a class declaration keyword. The first parameter acquisition module is used to acquire the name and first parameter of the first function corresponding to the function declaration if the target keyword is a function declaration; the first parameter acquisition module includes: a first function name acquisition unit, used to acquire the name of the first function corresponding to the function declaration if the target keyword is a function declaration; a first function type determination unit, used to determine the type of the first function based on the syntactic sugar in the name of the first function; a function determination unit, used to determine that the first function is a function of a preset language if the syntactic sugar includes a target character; and a first parameter acquisition unit, used to acquire the first parameter of the first function; The second function name determination module is used to determine the name of the second function in the target file based on the name of the first function; The second parameter determination module is used to determine the second parameter of the second function that matches the first parameter; The target file construction module is used to construct the target file based on the identification information of the target file, the name of the second function, and the second parameter.

9. The apparatus according to claim 8, characterized in that, The device further includes: The first function type determination module is used to determine the type of the first parameter; The second parameter determination module includes: The second parameter determination unit is used to determine the second parameter of the second function that matches the first parameter if the first parameter is a data type, based on the first mapping information; the first mapping information represents the mapping relationship between the first parameter and the second parameter.

10. The apparatus according to claim 8, characterized in that, The device further includes: The first keyword acquisition module is used to acquire the target value corresponding to the target keyword and determine the target keyword as the first keyword if the target keyword is not a function declaration. The second keyword acquisition module is used to determine a second keyword that matches the first keyword based on the second mapping information; the second mapping information represents the mapping relationship between the first keyword and the second keyword. The construction module is used to construct the target file based on the identification information of the target file, the second keyword, and the target value.

11. The apparatus according to claim 8, characterized in that, The device further includes: The first structure creation module is used to create the first structure of the target file based on the static variables in the header file if the header file does not contain a class declaration keyword; The target file construction module includes: A storage unit is used to store the name of the second function and the second parameter in the first structure to obtain the stored first structure. The naming unit is used to name the stored first structure based on the identification information of the target file, so as to obtain the named structure; The target file determination unit is used to use the named structure as the target file.

12. The apparatus according to claim 8, characterized in that, The device further includes: The second structure creation module is used to create a second structure of the target file based on the class declaration keyword if the header file includes the class declaration keyword. The configuration information creation module is used to create the configuration information of the target file in the second structure based on the member attribute information in the class declaration; The target file construction module is used to construct the target file based on the target file's identification information and configuration information.

13. The apparatus according to claim 12, characterized in that, The device further includes: The target quantity acquisition module is used to acquire the target quantity of the member attribute information; A singleton object creation module is used to create the target number of singleton objects in the second structure; The configuration information creation module includes: The configuration information creation unit is used to create configuration information for the target file in the target number of singleton objects based on the member attribute information in the class declaration; wherein each singleton object corresponds to one configuration information.

14. The apparatus according to claim 13, characterized in that, The device further includes: The data class name acquisition module is used to acquire the data class name corresponding to the target business in response to the target business loading request in the application of the target language; The identification information determination module is used to determine the identification information of the target file that matches the data class name; The target file acquisition module is used to acquire the target file based on the identification information of the target file; The target service loading module is used to load the target service based on the target file.

15. A device for constructing object files, characterized in that, The device includes a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or at least one program being loaded and executed by the processor to implement the method for constructing an object file as described in any one of claims 1-7.

16. A computer program product, characterized in that, The computer program product includes computer instructions that are executed by a processor to implement the method for constructing an object file as described in any one of claims 1-7.

17. A computer storage medium, characterized in that, The computer storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the method for constructing the target file as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Method for realizing compiled embedded Python

    CN112346722A