Compiler-based data processing method, device and readable storage medium
By acquiring and analyzing annotations in Objective-C source code through the compiler to generate intermediate code, the inefficiency of the Objective-C programming language annotation scheme is solved, enabling efficient development without third-party dependencies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2020-10-27
- Publication Date
- 2026-05-19
AI Technical Summary
Existing Objective-C programming language annotation schemes introduce third-party dependency frameworks and header files during use, resulting in low efficiency in component or application development.
The compiler obtains target annotations from the source code, loads annotation processing plugins for analysis and matching, generates a list of target annotations, and automatically generates intermediate code by the compiler, avoiding the introduction of third-party dependency frameworks and header files.
It improved development efficiency, simplified the code modification process, reduced the workload of writing code, and increased the automation level of development tools.
Smart Images

Figure CN114489653B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to compiler-based data processing methods, apparatus, and readable storage media. Background Technology
[0002] Existing technologies provide annotation capabilities for programming languages, allowing programs to obtain information about program elements such as classes, fields, and methods. Developers can also use annotations to track dependencies in the source code. However, existing methods for annotating programming languages such as Objective-C (an object-oriented programming language that extends C) involve introducing third-party dependency frameworks and header files, resulting in low development efficiency during component or application development. Summary of the Invention
[0003] This application provides a compiler-based data processing method, apparatus, and readable storage medium, which can improve development efficiency.
[0004] This application provides a compiler-based data processing method, including:
[0005] Retrieve target annotations from the source code;
[0006] The compiler loads the annotation processing plugin to obtain the target annotation code corresponding to the target annotation in the annotation processing plugin.
[0007] Based on the target annotation code, a target annotation list is generated to describe the data structure of the target annotation. The target annotation list is then translated to generate intermediate code corresponding to the source code.
[0008] The compiler generates the target file corresponding to the intermediate code.
[0009] This application provides a compiler-based data processing device, including:
[0010] The annotation retrieval module is used to retrieve target annotations from the source code.
[0011] The code acquisition module is used to load the annotation processing plugin through the compiler and acquire the target annotation code corresponding to the target annotation in the annotation processing plugin.
[0012] The code generation module is used to generate a target annotation list that describes the data structure of the target annotation based on the target annotation code, and to perform translation processing on the target annotation list to generate intermediate code corresponding to the source code;
[0013] The file generation module is used to generate the target file corresponding to the intermediate code through the compiler.
[0014] The code acquisition module includes:
[0015] The analysis unit is used to analyze the target annotation through the annotation processing plugin and generate an initial annotation list; the initial annotation list includes the basic description identifier of the target annotation;
[0016] The matching unit is used to search for annotation code that matches the basic description identifier in the annotation library of the annotation processing plugin, based on the initial annotation list, and use it as the target annotation code; the annotation code in the annotation library is the implementation code for the annotation.
[0017] The code generation module includes:
[0018] An update unit is used to update the initial annotation list according to the target annotation code to obtain a target annotation list; the target annotation list includes a data structure carrying detailed information of the target annotation;
[0019] The translation unit is used to translate the data structure in the target annotation list to generate the business logic of the target annotation; to instrument the business logic in the intermediate code to generate the intermediate code corresponding to the source code; the intermediate code is obtained by the compiler compiling the project code, and the project code is the code in the source code other than the target annotation.
[0020] The device further includes:
[0021] The detection module is used to call the annotation processing plugin to perform error detection on the target annotation. If the target annotation is detected to not meet the annotation protocol, the compiler is called to handle the error.
[0022] Specifically, the detection module is used to determine that the target annotation does not meet the annotation protocol when the annotation processing plugin detects that the writing format of the target annotation does not meet the writing format in the annotation protocol, or the annotation processing plugin detects that the target annotation has a spelling error, or the annotation processing plugin detects that the type of the annotation parameter in the target annotation is incorrect.
[0023] The device further includes:
[0024] The registration module is used to generate a description file based on the service information obtained from the target annotation; the service information is used to describe the open services provided by the target component; when the target component is integrated into the application project, the service information is integrated into the resource lock file according to the description file, the command line tool is called to convert the service information in the resource lock file into service code, and the service code is inserted into the application project; the business framework is called through the service code to register the open service at runtime.
[0025] The target annotation includes the interface color attribute of the target application; the interface color attribute is obtained by modifying the initial interface color attribute in the source code through the target annotation; the device further includes:
[0026] The color update module is used to obtain the target file through the linker, convert the target file into an executable program in the linker, run the executable program, and update the interface color of the target application according to the interface color attribute.
[0027] This application provides a compiler-based data processing device, including a processor and a memory;
[0028] The processor is connected to a memory, wherein the memory is used to store a computer program, and the processor is used to invoke the computer program to perform the method as described in one aspect of this application.
[0029] This application provides a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, perform the method as described in one aspect of this application.
[0030] This application can obtain target annotations from the source code, load an annotation processing plugin through the compiler, and then analyze and match the target annotations to obtain the corresponding target annotation code. Furthermore, it can generate a target annotation list based on the target annotation code, and then perform transpilation processing on the target annotation list to generate intermediate code corresponding to the source code. Finally, the compiler generates the target file corresponding to the intermediate code. Therefore, the method provided in this application can provide compiler-level annotations and automatically generate intermediate code containing annotation-based business logic without additional code support or the introduction of third-party dependency frameworks and header files, greatly improving development efficiency. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of the present invention 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 the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 This is a schematic diagram of a system architecture provided in this application;
[0033] Figure 2 This is a schematic diagram illustrating a scenario of a compiler-based data processing method provided in this application;
[0034] Figure 3 This is a flowchart illustrating a compiler-based data processing method provided in this application;
[0035] Figure 4 This is a flowchart illustrating another compiler-based data processing method provided in this application;
[0036] Figure 5 This is a flowchart illustrating the annotation information transmission process provided in this application;
[0037] Figure 6 This is a schematic diagram of the structure of a compiler-based data processing device provided in this application;
[0038] Figure 7 This is a schematic diagram of another compiler-based data processing device provided in this application. Detailed Implementation
[0039] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0040] Please see Figure 1 This is a schematic diagram of a system architecture provided in this application. For example... Figure 1As shown, the system architecture may include server 100, terminal devices 200a, 200b, and 200c. Server 100 can transmit data with terminal devices 200a, 200b, and 200c via a network. Each terminal device can install various applications (or software), such as instant messaging applications, games, video applications, and music applications. These applications can be obtained by downloading installation packages released by developers. Therefore, each terminal device can transmit data with server 100 through the corresponding application client. For example, server 100 can send application update information to each terminal device, and the terminal device can respond to user-entered update operations, downloading the latest installation package from server 100 for version updates. Terminal devices may include mobile phones, tablets, laptops, PDAs, mobile internet devices (MIDs), and wearable devices (such as smartwatches and smart bracelets).
[0041] The process involves compiling, linking, and testing the completed source code using development tools. The entire project can then be packaged into an installation package and released for users to download and use. A computer program, also known as software or simply a program, is a set of instructions that direct a computer or other information-processing device to perform each action. It is typically written in a programming language and runs on a specific target architecture. Source code refers to the original code of a program written in a particular programming language. Please refer to [link to relevant documentation] for more details. Figure 2 This is a schematic diagram illustrating a compiler-based data processing method provided in this application. Figure 2 As shown, the scene is based on Figure 1 Taking the server 100 and terminal device 200a in the corresponding embodiment as examples, in a project developing a new version of the application, the development tool can obtain the source code written by the developers. The source code may include annotations and project code. Project code refers to the code in the source code other than the annotations, for example... Figure 2In the source code shown, annotations 300a and 300b are used; annotation 300a is the same as the annotation for project code 300b. Annotations can be added to program elements in the source code. These elements can include classes, fields, methods, packages, variables, or parameters. Annotations are typically declared before program elements to describe or comment on them and associate them with that information. In traditional development, developers may need to modify a lot of code to update the application. However, with the method provided in this application, developers can simplify the code using annotations. The parameter types supported by annotations can include, but are not limited to, strings, numbers, classes, and enumerations. For example, the initial page color attribute in the source code can be modified using annotations, changing the application's interface color attribute from "white" to "gray". Furthermore, since machines cannot recognize source code written in programming languages, a compiler can be invoked to compile the source code. Specifically, annotations can be extracted from the source code, and the annotation processing plugin loaded by the compiler can be used to process these annotations, generating runtime business logic. Simultaneously, the compiler can also compile the code in the source code other than the annotations, generating intermediate code. The aforementioned business logic and intermediate code are then assembled to obtain the intermediate code corresponding to the source code. The compiler can then generate the object file corresponding to the intermediate code. This object file is a machine-readable binary file. The object file is then sent to the linker, which combines related object files and function libraries throughout the project to generate an executable program. The linker then executes the program. The operation can be referred to as "linking". The executable program is run on the development tool or other device. After the test is passed, the project can be packaged into an installation package through the development tool. The installation package can be published to the relevant network platform (such as the application store of the terminal device 200a) through the server 100. After the platform approves the application, the server 100 can obtain the update information of the application and send the update information to the terminal device 200a for display. The update information may include the application version number, a brief introduction of the optimized or added features, etc. The terminal device 200a can respond to the update operation entered by the user, such as responding to the trigger operation of the "upgrade" button, download the updated installation package through the server 100, and install it on the terminal device 200a to update the version of the application. For example, terminal device 200a has installed an updated instant messaging application A1. After opening instant messaging application A1, the executable program corresponding to instant messaging application A1 can run on the operating system to respond to the relevant operations of entering the chat page. Terminal device 200a can obtain the interface color attribute of instant messaging application A1 and display the updated chat page a2 according to the interface color attribute. It can be seen that the background color of the chat page is updated from white in the initial chat page a1 to gray in the chat page a2.
[0042] Therefore, this application can obtain annotations from the source code, load an annotation processing plugin through the compiler, process the annotations through the plugin, generate intermediate code corresponding to the source code, and then generate object files corresponding to the intermediate code through the compiler. Thus, the method provided by this application can provide compiler-level annotations and automatically generate intermediate code containing annotation-based business logic through the compiler, without requiring additional code support or the introduction of third-party dependency frameworks and header files, greatly improving development efficiency.
[0043] Please see Figure 3 This is a flowchart illustrating a compiler-based data processing method provided in this application. The method may include the following steps:
[0044] Step S101: Obtain the target annotations in the source code;
[0045] Specifically, the compiler can obtain target annotations in the source code. The source code may include target annotations and project code, where project code is the code in the source code excluding target annotations. Annotations refer to code in the source code written according to annotation protocols used to annotate program elements. In other words, annotations can be understood as special markers in the source code. These markers can be read during compilation, class loading, or runtime, and corresponding processing can be performed to allow other tools to supplement information or perform deployment. Annotation protocols are mainly used to distinguish annotations from other code, and can also identify all annotations from the source code according to the specific provisions of the annotation protocol. Therefore, the specific provisions of the annotation protocol can be set according to actual needs, such as using pre-agreed special identifiers, pre-agreed keywords, pre-agreed writing formats, pre-agreed special locations, or other pre-agreed syntax rules, etc., which are not limited here. For example, see the following partial source code written in Objective-C (Objective C or Obj-C, an object-oriented programming language extending C):
[0046] NS_ASSUME_NONNULL_BEGIN
[0047] @protocol RABasicProtocol <nsobject>
[0048] @end
[0049] __attribute__((raft(service)));
[0050] __attribute__((raft(interface=RABasicProtocol,RACustomProtocol)));
[0051] @interface RAFTBasicService:NSObject <rabasicprotocol>
[0052] __attribute__((raft(property)));
[0053] @property(nonatomic,strong)NSString*name;
[0054] __attribute__((raft(property)));
[0055] @property(nonatomic,strong)NSString*version;
[0056] __attribute__((raft(initmethod)));
[0057] -(instancetype)initWinthVersion:(NSString*)version
[0058] name:(NSString*)name;
[0059] __attribute__((raft(method)));
[0060] -(void)startup;
[0061] @end
[0062] In the source code above, an annotation is used to declare a class named RAFTBasicService, which provides a service (can be called a Service). The annotation specifies the interface implemented by this service. The source code contains multiple annotations; for example, the fourth line, `__attribute__((raft(service)))`, represents an annotation for RAFTBasicService. The source code uses the `__attribute__((...))` format to write the annotation. Annotations can be written within parentheses, and the annotation is identified by `__attribute__` and parentheses. `__attribute__` indicates the start of the annotation, and two right parentheses indicate the end. This allows for quick identification of the target annotation from the source code. Annotations can be written before the annotated element; however, `__attribute__((raft(service)))` can only appear on the class declaration, thus allowing for quick retrieval of relevant information about the annotated element. Furthermore, annotations can use keywords, such as `raft` in the example above. Annotation parameters, such as `property`, can be added as needed, reducing the amount of code writing required. Each annotation can be written in only one line of code, thus improving the efficiency of identifying annotations from the source code. Therefore, according to the above annotation protocol, annotations can be quickly and efficiently identified and extracted from the source code. In addition, annotations also support specifying initialization methods and property injection, such as `__attribute__((raft(initmethod)))` and `__attribute__((raft(property)))` in the example above.
[0063] Understandably, to make annotations more concise, specific names can be used to represent annotations in the source code. For example, `__attribute__((raft(service)))` can be simplified to the name `RAFT_SERVICE`. Annotation parameters can be added after the name when needed, such as `RAFT_FACTORYCLASS(CLS)`, where `CLS` in parentheses is the annotation parameter. The annotation scheme provided in this application supports almost all types of parameters, specifically including at least one of the following: string type, numeric type, enumeration type, character type, boolean type, class, array type, and custom language type. The definition and implementation of annotations can be determined according to actual needs, and this application does not impose any restrictions.
[0064] Step S102: Load the annotation processing plugin through the compiler and obtain the target annotation code corresponding to the target annotation in the annotation processing plugin;
[0065] Specifically, after identifying the target annotation in the source code, the compiler can load the annotation processing plugin. This plugin can be implemented independently or work in conjunction with the compiler. The annotation processing plugin analyzes the target annotation, performing lexical and syntactic analysis to generate an initial annotation list. This initial annotation list can include the basic descriptive identifiers of the target annotations; that is, it can use descriptive symbols with annotation information to represent the structure of the target annotation in the source code. Further, based on the initial annotation list, the annotation processing plugin can search its annotation library for annotation code that matches the basic descriptive identifiers. This target annotation code is then used as the target annotation code. The annotation library contains all custom annotation code, which is the implementation code for the annotation, describing its definition and specific implementation. This annotation code can be predefined in the annotation library and dynamically injected into the annotation processing plugin as a dynamic library when the plugin runs.
[0066] Step S103: Generate a target annotation list to describe the data structure of the target annotation based on the target annotation code; perform translation processing on the target annotation list to generate intermediate code corresponding to the source code;
[0067] Specifically, the annotation processing plugin can update the initial annotation list based on the target annotation code to obtain a target annotation list. This target annotation list describes the data structure of the target annotation and includes a data structure carrying detailed information about the target annotation. This detailed information can include data related to the target annotation code, such as some definitions of the target annotation. The plugin can then translate the data structure in the target annotation list to generate the business logic of the target annotation. This business logic is then instrumented in the intermediate code, assembling the business logic and the intermediate code to generate the intermediate code corresponding to the source code. The intermediate code is obtained by the compiler compiling the project code, which is the code in the source code excluding the target annotations. In this application, the intermediate code specifically refers to the final version's intermediate code. The intermediate code acts as a "bridge" between the compiler front-end and back-end, facilitating the development and portability of the compiler program and enabling code optimization. The business logic of the target annotation can be understood as a dependency injection framework, forming a complete lifecycle management code. The subsequently generated executable program will automatically run according to this business logic.
[0068] Step S104: Generate the target file corresponding to the intermediate code using the compiler.
[0069] Specifically, the compiler can optimize the intermediate code by extracting common subexpressions, optimizing loops, and removing useless code, in order to generate a more efficient target file.
[0070] This application obtains target annotations from the source code, loads an annotation processing plugin through the compiler, and then analyzes and matches the target annotations to obtain the corresponding target annotation code. Further, it generates a target annotation list based on the target annotation code and performs transpilation processing on the target annotation list to generate intermediate code corresponding to the source code. The compiler then generates the target file corresponding to the intermediate code. Therefore, the method provided in this application can improve annotation functionality and extend annotation capabilities by providing compiler-level annotations and enriching the types of supported annotation parameters. Moreover, it automatically generates intermediate code containing annotation-based business logic through the compiler without requiring additional code support or the introduction of third-party dependency frameworks and header files, greatly improving development efficiency.
[0071] Please see Figure 4 This is a flowchart illustrating another compiler-based data processing method provided in this application. The method may include the following steps:
[0072] Step S201: Obtain the target annotations in the source code;
[0073] Specifically, target annotations can be quickly identified from source code based on annotation protocols, such as... Figure 4 The source code is written in Objective-C and includes annotations and project code. Annotation 300a includes the identifier `__attribute__((...))`, the keyword `raft`, and the annotation parameter `property`. Project code 300b is a declaration written in Objective-C. Please refer to [link / reference]. Figure 5 This is a flowchart illustrating the annotation information transmission process provided in this application. For example... Figure 5 As shown, all target annotations identified in the source code can be extracted to obtain target annotation 400a, also known as User Code.
[0074] Step S202: Load the annotation processing plugin through the compiler, analyze the target annotation through the annotation processing plugin, and generate an initial annotation list; the initial annotation list includes the basic description identifier of the target annotation;
[0075] Specifically, after identifying the target annotation in the source code, the compiler can call the annotation processing plugin to work together. The annotation processing plugin can perform lexical analysis on the target annotation, converting the string-based target annotation into a stream of tokens. Tokens can be viewed as a flat array of syntactic fragments (or understood as a permutation of short strings). Then, it can perform syntactic analysis on the token stream, converting it into an initial annotation list. This initial annotation list can be in the form of an Abstract Syntax Tree (AST). During the syntactic analysis phase, the information in the tokens is used to convert them into a tree structure of an AST. Therefore, the initial annotation list can include basic descriptive identifiers of the target annotation. These basic descriptive identifiers can be short strings used only to describe the annotation information, rather than actual data structures that can be recognized and executed by the machine. For source code written in Objective-C, this application suggests using a compiler based on LLVM (Low Level Virtual Machine) and Clang to process the source code. LLVM is the foundational framework for building compilers, enabling the construction of a language executor that includes compile-time, link-time, and runtime mechanisms. Therefore, it can serve as an Objective-C compiler toolchain and also as a backend optimizer. Clang is a sub-project of the LLVM project and is a compiler frontend based on the LLVM architecture. Therefore, Clang can perform frontend optimization and abstract syntax tree generation for Objective-C, acting as a part of the LLVM toolchain ecosystem. Figure 5 As shown, the annotation processing plugin and compiler can both be implemented using LLVM and Clang. The annotation processing plugin can include an abstract syntax tree matcher 400b (Clang AST Matcher), an attribute definition library 400c (LLVM Attribute Definition), a dynamic library 400d (LLVM dylib), an annotation plugin 400e (LLVM Annotation Plugin), and a transpile 400f (LLVMTransformer). It can then call the abstract syntax tree matcher 400b in the annotation processing plugin to analyze the target annotation 400a. After completion, it generates an AST list (i.e., the initial annotation list) for the next stage of LLVM plugin analysis.
[0076] Step S203: Based on the initial annotation list, search for the annotation code that matches the basic description identifier in the annotation library of the annotation processing plugin, and use it as the target annotation code; the annotation code in the annotation library is the implementation code for the annotation;
[0077] Specifically, such as Figure 5 As shown, the attribute definition library 400c can contain annotation code for all predefined annotations. Annotation code refers to the specific definition and implementation code of an annotation. The attribute definition library 400c is dynamically injected into LLVM as a dynamic library 400d. Furthermore, the annotation plugin 400e can parse the initial annotation list (or AST list) generated in the abstract syntax tree matcher 400b using annotations defined in the attribute definition library 400c. Specifically, it can search within the attribute definition library 400c (i.e., the annotation library). When an annotation code matching the basic description identifier in the initial annotation list is detected, it is used as the target annotation code.
[0078] Optionally, custom annotation code can be written according to actual needs. For example, the definition of the annotation can be saved in a configuration file, and the self-annotation code in the configuration file can be read later through a predefined template file.
[0079] Step S204: Update the initial annotation list according to the target annotation code to obtain a target annotation list; the target annotation list includes a data structure carrying detailed information of the target annotation;
[0080] Specifically, the annotation plugin 400e can update the initial annotation list based on the target annotation code to obtain the target annotation list. At this time, the target annotation list is still in the form of an AST list, but the target annotation list includes data structures carrying detailed information of the target annotations, and these data structures can be recognized and used by machines. The detailed information of the target annotations is no longer the basic description identifier of the target annotations mentioned in step S202 above, but more detailed and specific information, such as the specific type of the target annotation, which annotation codes in the corresponding annotation library, and the program elements annotated by the target annotations.
[0081] Step S205: Translate the data structure in the target annotation list to generate the business logic of the target annotation; instrument the business logic in the intermediate code to generate the intermediate code corresponding to the source code; the intermediate code is obtained by the compiler compiling the project code, and the project code is the code in the source code other than the target annotation;
[0082] Specifically, after obtaining the target annotation list, the 400f transpiler can convert the data structures in the target annotation list into data structures that LLVM Pass can recognize, thereby generating the business logic of the target annotations. Then, LLVM Pass can be used to insert the business logic of the target annotations into the intermediate code, that is, to assemble the business logic and the intermediate code to generate the final version of the intermediate code corresponding to the source code. Figure 5 The intermediate code shown is 400g (LLVM IR). This intermediate code can be obtained by compiling the project code using a compiler. The compilation process can be completed before code instrumentation, and this application does not impose any restrictions on this. LLVM Pass is an important component of the LLVM framework; its main function is code optimization, and it also handles some code analysis.
[0083] It should be noted that the processes of steps S201-S205 above are all "implicit", that is, they are not perceived or intrusive at the user level.
[0084] Step S206: Call the annotation processing plugin to perform error detection on the target annotation. If the target annotation is detected to not meet the annotation protocol, call the compiler to perform error handling.
[0085] Specifically, the annotation processing plugin can perform error detection on the target annotation. Optionally, when the annotation processing plugin detects that the writing format of the target annotation does not meet the writing format in the annotation protocol, such as using the __attribute__((...)) rule to write the annotation, then the underscores and parentheses must be used completely, and the annotation must be placed in parentheses. Otherwise, it can be determined that the target annotation does not meet the annotation protocol.
[0086] Optionally, if the annotation processing plugin detects a misspelling in the target annotation, such as misspelling the keyword "raft" as "rafy", and there is no annotation code for "rafy" in the annotation library, then it can be determined that the target annotation does not meet the annotation protocol.
[0087] Optionally, when the annotation processing plugin detects an error in the type of the annotation parameter in the target annotation, such as using a parameter that is not a string in a target annotation that only supports string parameters, it can be determined that the target annotation does not meet the annotation protocol.
[0088] Optionally, when the annotation processing plugin detects that the target annotation is not located in the specified location, for example, different attributes can only appear in their corresponding locations, such as raft(service) can only appear on the class declaration, while raft(method) can only appear on the method, otherwise it can be determined that the target annotation does not satisfy the annotation protocol.
[0089] Furthermore, when a target annotation is detected as not conforming to the annotation protocol, the detection result from the annotation processing plugin can be sent to the compiler. Upon receiving this result, the compiler can handle the error, such as displaying error messages on the user interface. These messages can include the number of errors, the cause of the error, and the line number of the error code. In this case, compilation will fail, and the corresponding errors must be corrected before recompiling can generate the target file. It's important to note that the compiler can provide corresponding prompts based on the detection results during both the pre-compilation stage (which can be understood as the stage where the source code is still being written) and the compilation stage. Any syntax errors appearing in the project code will also be reported. In addition, if some code is detected without errors but may contain writing styles or methods that the compiler does not recommend, the compiler can also issue warnings and recommend better writing practices to the developers.
[0090] Step S207: Generate the target file corresponding to the intermediate code using the compiler;
[0091] Specifically, the compiler can optimize the intermediate code by extracting common subexpressions, optimizing loops, and removing useless code to process and transform the intermediate code, generating the target file corresponding to the intermediate code. The compilation process is the process of converting each source code instruction into appropriate machine language instructions.
[0092] It should be noted that the process described in steps S201-S207 above can be effective in both the pre-compilation and compilation stages. The pre-compilation process can be used to verify whether the target annotations are complete and correct, while the compilation process is mainly used to generate the specific intermediate code. During subsequent injection and runtime, it is a dynamic instrumentation process.
[0093] Step S208: Obtain the target file through the linker, and convert the target file into an executable program in the linker;
[0094] Specifically, although the object file contains machine language instructions, it is not yet a complete program. Therefore, the object file can be obtained by the LLVM backend linker and combined with the necessary runtime library routines to generate an executable program. The executable program (stored in the executable file) contains machine language instructions or executable code and can already run on a computer device.
[0095] Step S209: Run the executable program.
[0096] Specifically, Objective-C is a dynamic language, therefore it requires not only a compiler but also a runtime system to dynamically create classes and objects, and to perform message passing and forwarding, such as... Figure 5 The runtime system shown is 400h, i.e., the Objective-C Runtime. The executable program described above can run normally on runtime system 400h. For example, when updating the interface color of a target application, annotations can be used to modify the initial interface color attribute in its source code. The modified source code can then be processed by tools such as compilers and linkers to generate the executable program corresponding to the target application. Running this executable program on the terminal device's operating system will update the interface color of the target application according to its interface color attribute. See the above for details. Figure 2 The process of updating the background color of the chat page in the instant messaging application A1 using annotations in the corresponding embodiment will not be described in detail here.
[0097] Optionally, different approaches can be adopted based on annotations to achieve similar effects. For example, in a component governance project, developers can use annotations in Objective-C code to define open services (also known as Servives, which are essentially classes that provide open services to the component, and can be understood as the functionality provided by the component to the outside world) offered by the target component. For instance, the component can provide an address for downloading resources, and the outside world can download the required content from the webpage after obtaining the resource download address; this is an open service. In this application, some of the target component's public APIs (Application Programming Interfaces) can be defined as open services exposed to the outside world. A component can expose multiple open services for external use. After obtaining the service information from the target annotations, a description file can be automatically generated based on the service information. The service information describes the open services provided by the target component, and the description file is essentially a configuration file that can describe the interface and other information of the open services. Optionally, the description file can also be written manually by the developers. When a target component is integrated into an application project, its service information is also integrated into a resource lock file. This resource lock file can contain service information for multiple open services. Using the project's command-line tool, the service information in the resource lock file can be converted into service code (i.e., annotated business logic), and this service code is automatically inserted into the application project. This service code can then call the project's business framework, automatically registering the service during runtime of the subsequently generated executable. This method avoids the need for developers to manually write service registration code, as is done in traditional methods. The code is automatically generated via command-line tools, and the service can be directly accessed and used through the business framework without needing to worry about the service's initialization process and dependencies. This greatly expands the capabilities of annotations and improves project development efficiency. Compared to the compiler-based data processing method described above, this method is "explicit"—developers can see the service code stored in a file that is integrated into the application project, and they need to manually write commands using command-line tools to convert the service information in the resource lock file into service code. In contrast, the compiler-based data processing method is seamless and non-intrusive to developers.
[0098] This application obtains target annotations from the source code, loads an annotation processing plugin through the compiler, and then analyzes and matches the target annotations to obtain the corresponding target annotation code. Further, it generates a target annotation list based on the target annotation code, performs transpilation processing on the target annotation list, and detects errors in the source code. If no errors are found, it generates intermediate code corresponding to the source code, and then uses the compiler to generate the corresponding object file, ultimately producing an executable program. Therefore, the method provided in this application enriches the types of supported annotation parameters by providing compiler-level annotations and error correction mechanisms, thereby improving annotation functionality and expanding annotation capabilities. Furthermore, it automatically generates intermediate code containing annotation-based business logic through the compiler without requiring additional code support or the introduction of third-party dependency frameworks and header files, greatly improving development efficiency.
[0099] Please see Figure 6 This is a schematic diagram of the structure of a compiler-based data processing device provided in this application. Figure 6 As shown, the compiler-based data processing device 1 may include an annotation acquisition module 11, a code acquisition module 12, a code generation module 13, and a file generation module 14;
[0100] Annotation acquisition module 11 is used to acquire target annotations in the source code;
[0101] Code acquisition module 12 is used to load the annotation processing plugin through the compiler and acquire the target annotation code corresponding to the target annotation in the annotation processing plugin;
[0102] Code generation module 13 is used to generate a target annotation list for describing the data structure of the target annotation based on the target annotation code, perform translation processing on the target annotation list, and generate intermediate code corresponding to the source code;
[0103] The file generation module 14 is used to generate the target file corresponding to the intermediate code through the compiler.
[0104] The specific implementation of the annotation acquisition module 11 can be found in the above description. Figure 3 The corresponding step S101 in the embodiment, or as described above, can be found in the above-described embodiment. Figure 4 The specific functional implementation of step S201 in the corresponding embodiment, the code acquisition module 12, can be found above. Figure 3 The corresponding embodiment of step S102, or you can refer to the above. Figure 4 For the specific implementation of steps S202-S203 in the corresponding embodiments, the code generation module 13 can be found above. Figure 3 The corresponding step S103 in the embodiment, or as described above. Figure 4 For the specific functional implementation of steps S204-S205 in the corresponding embodiments, the file generation module 14 can be found above. Figure 3 The corresponding embodiment's step S104, or you can refer to the above. Figure 4 Step S207 in the corresponding embodiment will not be described again here.
[0105] Please see also Figure 6 The compiler-based data processing device 1 may also include a detection module 15;
[0106] The detection module 15 is used to call the annotation processing plugin to perform error detection on the target annotation. If the target annotation is detected to be inconsistent with the annotation protocol, the compiler is called to perform error processing.
[0107] The detection module 15 is specifically used to determine that the target annotation does not meet the annotation protocol when the annotation processing plugin detects that the writing format of the target annotation does not meet the writing format in the annotation protocol, or the annotation processing plugin detects that the target annotation has a spelling error, or the annotation processing plugin detects that the type of the annotation parameter in the target annotation is incorrect.
[0108] The specific functional implementation of the detection module 15 can be found in the above description. Figure 4 Step S206 in the corresponding embodiment will not be described again here.
[0109] Please see also Figure 6 The compiler-based data processing device 1 may also include a registration module 16;
[0110] Registration module 16 is used to generate a description file based on the service information obtained from the target annotation if service information is obtained from the target annotation; the service information is used to describe the open services provided by the target component; when the target component is integrated into the application project, the service information is integrated into the resource lock file according to the description file, the command line tool is called to convert the service information in the resource lock file into service code, and the service code is inserted into the application project; the business framework is called through the service code to register the open service at runtime.
[0111] The specific implementation of the registration module 16 can be found in the above description. Figure 4 Step S209 in the corresponding embodiment will not be described again here.
[0112] Please see also Figure 6 The compiler-based data processing device 1 may also include a color update module 17;
[0113] Color update module 17 is used to obtain the target file through the linker, convert the target file into an executable program in the linker, run the executable program, and update the interface color of the target application according to the interface color attribute.
[0114] The specific implementation of the color update module 17 can be found in the above description. Figure 4 Step S209 in the corresponding embodiment will not be described again here.
[0115] Please see also Figure 6 The code acquisition module 12 may include an analysis unit 121 and a matching unit 122;
[0116] Analysis unit 121 is used to analyze the target annotation through the annotation processing plugin and generate an initial annotation list; the initial annotation list includes the basic description identifier of the target annotation;
[0117] The matching unit 122 is used to search for annotation code that matches the basic description identifier in the annotation library of the annotation processing plugin according to the initial annotation list, and use it as the target annotation code; the annotation code in the annotation library is the implementation code for the annotation.
[0118] The specific functional implementation of the analysis unit 121 can be found in the above description. Figure 4 The specific functional implementation of step S202 in the corresponding embodiment, and the matching unit 122, can be found in the above description. Figure 4 Step S203 in the corresponding embodiment will not be described again here.
[0119] Please see also Figure 6 The code generation module 13 may include an update unit 131 and a translation unit 132;
[0120] The update unit 131 is used to update the initial annotation list according to the target annotation code to obtain a target annotation list; the target annotation list includes a data structure carrying detailed information of the target annotation;
[0121] The translation unit 132 is used to translate the data structure in the target annotation list to generate the business logic of the target annotation; to instrument the business logic in the intermediate code to generate the intermediate code corresponding to the source code; the intermediate code is obtained by the compiler compiling the project code, and the project code is the code in the source code other than the target annotation.
[0122] The specific implementation of the update unit 131 can be found in the above description. Figure 4 The specific functional implementation of step S204 in the corresponding embodiment, and the translation unit 132, can be found above. Figure 4 Step S205 in the corresponding embodiment will not be described again here.
[0123] This application obtains target annotations from the source code, loads an annotation processing plugin through the compiler, and then analyzes and matches the target annotations to obtain the corresponding target annotation code. Further, it generates a target annotation list based on the target annotation code, performs transpilation processing on the target annotation list, and detects errors in the source code. This generates intermediate code corresponding to the source code, and the compiler generates the corresponding object file, ultimately producing an executable program. Therefore, the method provided in this application enriches the types of supported annotation parameters by providing compiler-level annotations and error correction mechanisms, thereby improving annotation functionality and extending annotation capabilities. Furthermore, it automatically generates intermediate code containing annotation-based business logic through the compiler without requiring additional code support or the introduction of third-party dependency frameworks and header files, greatly improving development efficiency.
[0124] Please see Figure 7 This is a schematic diagram of another compiler-based data processing device provided in this application. Figure 7 As shown, the compiler-based data processing device 1000 may include a processor 1001, a network interface 1004, and a memory 1005. Furthermore, the compiler-based data processing device 1000 may also include a user interface 1003 and at least one communication bus 1002. The communication bus 1002 is used to implement communication between these components. The user interface 1003 may include a display screen and a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1004 may be high-speed RAM or non-volatile memory, such as at least one disk drive. The memory 1005 may optionally be at least one storage device located remotely from the processor 1001. Figure 7 As shown, the memory 1005, which is a computer-readable storage medium, may include an operating system, a network communication module, a user interface module, and a device control application.
[0125] In such Figure 7 In the compiler-based data processing device 1000 shown, the network interface 1004 provides network communication functionality; the user interface 1003 is mainly used to provide an input interface for the user; and the processor 1001 can be used to call the device control application stored in the memory 1005 to achieve the above. Figure 3 , Figure 4 The description of the compiler-based data processing method in any of the corresponding embodiments will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated.
[0126] It should be understood that the compiler-based data processing device 1000 described in the embodiments of the present invention can execute the foregoing text. Figure 3 , Figure 4 The description of the compiler-based data processing method in any corresponding embodiment can also be performed as described above. Figure 6 The description of the compiler-based data processing device 1 in the corresponding embodiments will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated.
[0127] Furthermore, it should be noted that this embodiment of the invention also provides a computer-readable storage medium, which stores a computer program executed by the compiler-based data processing device 1 mentioned above. The computer program includes program instructions, and when the processor executes the program instructions, it can execute the aforementioned... Figure 3 , Figure 4 The description of the compiler-based data processing method in any corresponding embodiment is already provided and will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated. For technical details not disclosed in the computer-readable storage medium embodiments related to this invention, please refer to the description of the method embodiments of this invention.
[0128] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0129] The above description discloses only preferred embodiments of the present invention and should not be construed as limiting the scope of the present invention. Therefore, equivalent variations made in accordance with the claims of the present invention are still within the scope of the present invention.< / rabasicprotocol> < / nsobject>
Claims
1. A compiler-based data processing method, characterized in that, include: Retrieve target annotations from the source code; The compiler loads the annotation processing plugin, and the annotation processing plugin analyzes the target annotation to generate an initial annotation list; The initial annotation list includes the basic description identifier of the target annotation; Based on the initial annotation list, the annotation code that matches the basic description identifier is searched in the annotation library of the annotation processing plugin and used as the target annotation code. The annotation code in the annotation library is the implementation code for the annotations; Based on the target annotation code, a target annotation list is generated to describe the data structure of the target annotation. The target annotation list is then translated to generate intermediate code corresponding to the source code. The compiler generates the target file corresponding to the intermediate code.
2. The method according to claim 1, characterized in that, The step of generating a target annotation list to describe the data structure of the target annotation based on the target annotation code, and translating the target annotation list to generate intermediate code corresponding to the source code includes: The initial annotation list is updated based on the target annotation code to obtain a target annotation list; the target annotation list includes a data structure carrying detailed information of the target annotations; The data structure in the target annotation list is translated to generate the business logic of the target annotation; The business logic is instrumented in the intermediate code to generate intermediate code corresponding to the source code; the intermediate code is obtained by the compiler compiling the project code, and the project code is the code in the source code excluding the target annotation.
3. The method according to claim 1, characterized in that, Also includes: The annotation processing plugin is invoked to perform error detection on the target annotation. If the target annotation is found to be inconsistent with the annotation protocol, the compiler is invoked to handle the error.
4. The method according to claim 3, characterized in that, The step of calling the annotation processing plugin to perform error detection on the target annotation includes: When the annotation processing plugin detects that the writing format of the target annotation does not meet the writing format in the annotation protocol, or when the annotation processing plugin detects that the target annotation has a spelling error, or when the annotation processing plugin detects that the type of the annotation parameter in the target annotation is incorrect, it determines that the target annotation does not meet the annotation protocol.
5. The method according to claim 1, characterized in that, Also includes: If service information is obtained from the target annotation, a description file is generated based on the service information; The service information is used to describe the open services provided by the target component; When the target component is integrated into the application project, the service information is integrated into the resource lock file according to the description file, the command line tool is called to convert the service information in the resource lock file into service code, and the service code is inserted into the application project; The service code calls the business framework to register the open service at runtime.
6. The method according to claim 1, characterized in that, The target annotation includes the interface color attributes of the target application; The interface color attribute is obtained by modifying the initial interface color attribute in the source code through the target annotation; the method further includes: The target file is obtained through a linker, and the target file is converted into an executable program in the linker; Run the executable program and update the interface color of the target application according to the interface color attribute.
7. A compiler-based data processing device, characterized in that, include: The annotation retrieval module is used to retrieve target annotations from the source code. The code acquisition module is used to load the annotation processing plugin through the compiler, analyze the target annotation through the annotation processing plugin, and generate an initial annotation list; the initial annotation list includes the basic description identifier of the target annotation; The code acquisition module is further configured to search for annotation code that matches the basic description identifier in the annotation library of the annotation processing plugin, based on the initial annotation list, and use it as the target annotation code; The annotation code in the annotation library is the implementation code for the annotations; The code generation module is used to generate a target annotation list that describes the data structure of the target annotation based on the target annotation code, and to perform translation processing on the target annotation list to generate intermediate code corresponding to the source code; The file generation module is used to generate the target file corresponding to the intermediate code through the compiler.
8. A compiler-based data processing device, characterized in that, include: Processor and memory; The processor is connected to a memory, wherein the memory is used to store a computer program, and the processor is used to invoke the computer program to perform the method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, perform the method as described in any one of claims 1-6.