CN111399842A - Code compiling method and device - Google Patents

Code compiling method and device Download PDF

Info

Publication number
CN111399842A
CN111399842A CN202010163381.0A CN202010163381A CN111399842A CN 111399842 A CN111399842 A CN 111399842A CN 202010163381 A CN202010163381 A CN 202010163381A CN 111399842 A CN111399842 A CN 111399842A
Authority
CN
China
Prior art keywords
transaction
source code
tree expression
tree
compiling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010163381.0A
Other languages
Chinese (zh)
Other versions
CN111399842B (en
Inventor
艾国信
宋超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202010163381.0A priority Critical patent/CN111399842B/en
Publication of CN111399842A publication Critical patent/CN111399842A/en
Application granted granted Critical
Publication of CN111399842B publication Critical patent/CN111399842B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application provides a code compiling method and device, and belongs to the technical field of computers. In the method, a transaction source code to be compiled is obtained, wherein a non-transaction method in the transaction source code comprises preset annotation information; generating a tree expression corresponding to the transaction source code; determining the non-transaction method in the tree expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy; compiling the modified tree expression to obtain a compiled code, wherein the non-transaction method in the compiled code is subjected to proxy calling by a transaction method through the proxy object. So as to avoid the problem of data error caused by not calling non-transaction method through proxy object.

Description

Code compiling method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a code compiling method and apparatus.
Background
In a database, reading and writing operations on data are usually implemented by transactions. During the execution of a transaction, a plurality of methods belonging to different classes (which may be called transaction methods) are called in sequence, and these transaction methods are called in the program code by proxy objects (i.e. codes having proxy call functions). For example, under the spring framework, a transaction agent is implemented using an AOP method, and is typically implemented using cglib or jdk agent. Each time a transaction method is invoked, the execution status of the transaction method, such as success or failure, is recorded. And after the execution of one transaction is finished, if the execution states of all the transaction methods are successful, the execution of the transaction is finished, and the data in the current database is stored. If the transaction method with the execution state of failure exists, the transaction execution fails, and data rollback is performed, namely, the data in the database is restored to the data before the transaction is executed.
However, there may be a case where multiple methods in the same class are called each other in a transaction, and at this time, only the method executed first in the class is a transaction method, and other methods (which may be called non-transaction methods) are not called by proxy objects because they belong to the same class as the first method (i.e., the called method is not managed by a transaction). Therefore, if a certain non-transactional method fails to execute, data rollback cannot be performed, and errors occur in data in the database.
Disclosure of Invention
An object of the embodiments of the present application is to provide a code compiling method and apparatus, so as to solve the problems in the prior art that a transaction cannot be validated and data is incorrect due to the similar invocation of a non-transaction method. The specific technical scheme is as follows:
in a first aspect, a method for compiling code is provided, the method including:
acquiring a transaction source code to be compiled, wherein a non-transaction method in the transaction source code comprises preset annotation information;
generating a tree expression corresponding to the transaction source code;
determining the non-transaction method in the tree expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy;
compiling the modified tree expression to obtain a compiled code, wherein the non-transaction method in the compiled code is subjected to proxy calling by a transaction method through the proxy object.
Optionally, the generating a tree expression corresponding to the transaction source code includes:
inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
and inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, the determining, according to the annotation information, the non-transaction method in the tree expression, and adding, according to a preset modification policy, the proxy object corresponding to the non-transaction method in the tree expression includes:
determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method through an annotation processor;
and aiming at the node corresponding to each non-transaction method, adding the node corresponding to the proxy object before the target node through the annotation processor.
Optionally, the compiling the modified tree expression includes:
generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code;
and compiling the new transaction source code.
In a second aspect, there is provided a code compiling apparatus, the apparatus including:
the system comprises an acquisition module, a compiling module and a compiling module, wherein the acquisition module is used for acquiring a transaction source code to be compiled, and a non-transaction method in the transaction source code comprises preset annotation information;
the generating module is used for generating a tree expression corresponding to the transaction source code;
the determining module is used for determining the non-transaction method in the tree expression according to the annotation information, and adding the proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy;
and the compiling module is used for compiling the modified tree expression to obtain a compiled code, and the non-transaction method in the compiled code is subjected to proxy call by a transaction method through the proxy object.
Optionally, the generating module is specifically configured to:
inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
and inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, the determining module is specifically configured to:
determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method through an annotation processor;
and aiming at the node corresponding to each non-transaction method, adding the node corresponding to the proxy object before the target node through the annotation processor.
Optionally, the compiling module is specifically configured to:
generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code;
and compiling the new transaction source code.
In a third aspect, an electronic device is provided, which includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of the first aspect when executing a program stored in the memory.
In a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when executed by a processor, the computer program implements the method steps of any of the first aspects.
In a fifth aspect, there is provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the methods described above.
The embodiment of the application has the following beneficial effects:
the embodiment of the application provides a code compiling method and device, which can obtain a transaction source code to be compiled, wherein a non-transaction method in the transaction source code comprises preset annotation information. Then, a tree expression corresponding to the transaction source code is generated, a non-transaction method is determined in the tree expression according to the annotation information, a proxy object corresponding to the non-transaction method is added in the tree expression according to a preset modification strategy, then the modified tree expression is compiled to obtain a compiled code, and the non-transaction method in the compiled code is subjected to proxy calling through the proxy object by the transaction method. By the scheme, the proxy object can be automatically added aiming at the non-transaction method, so that the transaction method can perform proxy calling on the non-transaction method based on the proxy object, and the problem of data error caused by the fact that no proxy calls the non-transaction method can be avoided.
Of course, not all advantages described above need to be achieved at the same time in the practice of any one product or method of the present application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a flowchart of a code compiling method according to an embodiment of the present application;
fig. 2 is a flowchart of a method for generating a tree expression according to an embodiment of the present application;
fig. 3 is a flowchart of a method for adding a proxy object according to an embodiment of the present application;
FIG. 4 is a flowchart of an example of a code compiling method according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a code compiling apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The embodiment of the application provides a code compiling method which can be applied to electronic equipment. The electronic device may be an electronic device with a data processing function, such as an intelligent terminal, a computer, or the like.
The following will describe a code compiling method provided in the embodiments of the present application in detail with reference to specific embodiments, as shown in fig. 1, the specific steps are as follows:
step 101, obtaining a transaction source code to be compiled.
The non-transaction method in the transaction source code comprises preset annotation information.
In an embodiment of the application, an electronic device may obtain a transaction source code to be compiled, where the transaction source code may be used to execute one or more transactions. The transaction source code comprises at least one class, and each class comprises a plurality of methods. In this embodiment, there may be a case where multiple methods in the same class are mutually invoked, where a method executed first in the class is a transaction method, and a method invoked by the transaction method in the class is a non-transaction method.
In order to avoid the problem that data errors occur due to the fact that a non-transactional method is not called through a proxy object, in the non-transactional method of a transaction source code, preset annotation information is added, and the annotation information is information used for indicating that the method is the non-transactional method. The annotation information may specifically be an annotation class, for example, for each non-transactional method in the transaction source code, a self class call (self class call) class may be added to the non-transactional method to mark that the method is a non-transactional method called by a similar method.
In one example, assuming that the same type of non-transactional method B is called in transactional method A, annotation information is added to the non-transactional method B, wherein the annotation information can be processed by an annotation processor. Subsequently, if the annotation processor determines that some method contains the annotation information, the annotation processor identifies the method as a non-transactional method, and adds a code (namely, a proxy object) with a proxy call function to the non-transactional method, so as to realize proxy call of the A method to the B method.
And 102, generating a tree expression corresponding to the transaction source code.
In the embodiment of the application, the electronic device may pre-store a tree expression generation strategy, and after the electronic device obtains the transaction source code, the tree expression corresponding to the transaction source code may be generated through the preset generation strategy. The tree expression may be an AST (abstract syntax tree), and a detailed generation process will be described later. AST is a method for representing source codes, and can reflect statements contained in the source codes and structural relationships between the statements.
And 103, determining a non-transaction method in the tree expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy.
In this embodiment of the application, the electronic device may traverse the tree expression, and determine methods including annotation information (such as a SelfClassInvoke class), which are non-transaction methods, where a node corresponding to the methods is a node corresponding to the non-transaction methods. Then, the electronic device may modify the structure of the tree expression according to a preset modification policy, so as to add proxy objects corresponding to each non-transaction method in the tree expression, and a detailed description will be provided later on in a specific modification process.
And 104, compiling the modified tree-shaped expression to obtain a compiled code.
In the embodiment of the application, the electronic device can compile the modified tree expression to obtain a compiled code. Because the proxy object is added in the tree expression aiming at the non-transaction method, in the compiled code, the non-transaction method is subjected to proxy calling through the proxy object by the transaction method, namely, the calling mode of the transaction method to the non-transaction method in the same kind is changed from direct calling to proxy calling. The problem of data errors caused by the fact that a non-transaction method is not called through a proxy object is solved.
After the tree expression is modified, the annotation processor deletes annotation information in the non-transactional method for subsequent compiling.
Optionally, the specific process of compiling the modified tree expression includes: generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code; and compiling the new transaction source code.
In the embodiment of the application, after the annotation processor modifies the tree expression, a new source code (which may be called as a new transaction source code) is generated according to the modified tree expression, and then the new transaction source code is input to the lexical analysis scanner again, and a one-dimensional array corresponding to the new transaction source code is output. Then, the one-dimensional array is input to a syntax analysis analyzer, a tree expression (which may be called as a new tree expression) corresponding to the new transaction source code is output, and then semantic analysis is performed on the new tree expression. Because the annotation processor deletes the annotation information in the non-transactional method after modifying the tree expression, the annotation processor will not modify the new tree expression any more in the process of performing semantic analysis on the new tree expression. And then, inputting the new tree expression after semantic analysis into a byte code generator, outputting JVM byte codes, and finishing compiling the transaction source codes.
In the embodiment of the application, a transaction source code to be compiled can be obtained, wherein a non-transaction method in the transaction source code includes preset annotation information. Then, a tree expression corresponding to the transaction source code is generated, a non-transaction method is determined in the tree expression according to the annotation information, a proxy object corresponding to the non-transaction method is added in the tree expression according to a preset modification strategy, then the modified tree expression is compiled to obtain a compiled code, and the non-transaction method in the compiled code is subjected to proxy calling through the proxy object by the transaction method. By the scheme, the proxy object can be automatically added aiming at the non-transaction method, so that the transaction method can perform proxy calling on the non-transaction method based on the proxy object, and the problem of data error caused by the fact that no proxy calls the non-transaction method can be avoided.
Optionally, as shown in fig. 2, a specific process of generating a tree expression corresponding to a transaction source code includes the following steps:
step 201, inputting the transaction source code into the lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code.
In this embodiment, a lexical analysis scanner may be stored in the electronic device. After the electronic device obtains the transaction source code to be compiled, the transaction source code may be input into a lexical analysis scanner, and the lexical analysis scanner may split the transaction source code into a one-dimensional array. For example, if the source code is int a ═ 6, then one-dimensional array X [4] can be obtained, where X [1] is int, X [2] is a, X [3] is ═ and X [4] is 6. In this way, the lexical analysis scanner may output a one-dimensional array corresponding to the transaction source code.
And 203, inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
In the embodiment of the application, after the lexical analysis scanner outputs the one-dimensional array, the electronic device may input the one-dimensional array to the syntax analysis parser, and the syntax analysis parser may convert the received one-dimensional array into the tree expression and then output the tree expression. The process of converting the one-dimensional array into the tree expression by the syntax analysis parser belongs to the prior art, and the embodiment of the application is not limited.
Optionally, as shown in fig. 3, a specific process of adding a proxy object includes the following steps:
step 301, according to the annotation information, determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method.
In the embodiment of the present application, a technician needs to implement a customized annotation processor in advance. The annotation Processor may specifically be an Abstract Processor (i.e., an Abstract Processor) that is an annotation Processor in the java development kit jdk, such as a Transaction Proxy Processor.
The technician may add another annotation information in the annotation processor. For example, the annotation information is @ Supported AnnotationationTypes to specify that the annotation processor supports parsing annotation information (e.g., SelfClassInvoke class). In addition, it is also possible to specify the java version supported by all annotation information, that is, specify the java version of the transaction source code.
Referring to the above description, for each non-transactional method in the transaction source code, a SelfClassInvake class is added to the non-transactional method. This method, with the addition of the Self ClassInvoke identifier, will be parsed by the annotation processor. For example, if a SelfClassInvoke annotation is added to the method B, the annotation processor may parse a SelfClassInvoke class in the process of parsing the tree expression, so as to parse a method B including the SelfClass Invoke class, and then determine that the method B is a non-transactional method.
Step 302, adding a node corresponding to the proxy object before the target node for the node corresponding to each non-transaction method.
In this embodiment of the present application, when the annotation processor determines that a method includes a SelfClassInvoke class, the method is determined to be a non-transactional method, and then a node corresponding to a proxy object may be added before a target node, so as to implement adding a proxy call, for example, adding a code aopcontext.
In one example, if transaction method a calls non-transaction method B in the class, then node of method B is determined in the AST tree expression, and before the node, node corresponding to the proxy object, i.e. node containing code ((Pojo) aopcontext. currentproxy ()) is added.
For example, the pseudo code implemented is:
Figure BDA0002406569540000091
after AST is processed using the annotation processor, the class actually generated in the compilation stage is as follows (not containing the contents defining the annotation class):
Figure BDA0002406569540000092
Figure BDA0002406569540000101
then, the annotation processor deletes the content defining the annotation class and the annotation class, and outputs a new transaction source code as follows:
Figure BDA0002406569540000102
the embodiment of the application also provides an example of a code compiling method, which can be applied to electronic equipment. The electronic device may include a lexical analysis scanner, a parser, a semantic analysis module, and a bytecode generator. Wherein the semantic analysis module comprises an annotation processor. As shown in fig. 4, the specific steps of this example are as follows.
Step 1, acquiring a transaction source code to be compiled.
And 2, inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code.
And 3, inputting the one-dimensional array into a syntax analysis analyzer, and outputting the AST corresponding to the transaction source code.
And 4, performing semantic analysis on the AST.
In the semantic analysis process, the annotation processor judges whether the tree expression contains annotation information. If so, step 5 is performed, otherwise, step 8 is performed.
And 5, the annotation processor determines the method containing the annotation information as a non-transaction method, and adds a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy.
And 6, generating a transaction source code corresponding to the modified tree-shaped expression by the annotation processor, and deleting the annotation information to obtain a new transaction source code.
And 7, taking the new transaction source code as a transaction source code to be compiled, and returning to execute the step 2.
And 8, generating a transaction source code (namely the analyzed source code) corresponding to the tree expression by the annotation processor, inputting the source code into a byte code generator, outputting a JVM (Java Virtual Machine) byte code, and finishing compiling the transaction source code.
Based on the same technical concept, an embodiment of the present application further provides a code compiling apparatus, as shown in fig. 5, the apparatus includes:
an obtaining module 510, configured to obtain a transaction source code to be compiled, where a non-transaction method in the transaction source code includes preset annotation information;
a generating module 520, configured to generate a tree expression corresponding to the transaction source code;
a determining module 530, configured to determine the non-transaction method in the tree expression according to the annotation information, and add an agent object corresponding to the non-transaction method in the tree expression according to a preset modification policy;
and the compiling module 540 is configured to compile the modified tree expression to obtain a compiled code, where the non-transaction method in the compiled code is invoked by a transaction method through the proxy object.
Optionally, the generating module 520 is specifically configured to:
inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
and inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, the determining module 530 is specifically configured to:
determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method through an annotation processor;
and aiming at the node corresponding to each non-transaction method, adding the node corresponding to the proxy object before the target node through the annotation processor.
Optionally, the compiling module 540 is specifically configured to:
generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code;
and compiling the new transaction source code.
In the embodiment of the application, a transaction source code to be compiled can be obtained, wherein a non-transaction method in the transaction source code includes preset annotation information. Then, a tree expression corresponding to the transaction source code is generated, a non-transaction method is determined in the tree expression according to the annotation information, a proxy object corresponding to the non-transaction method is added in the tree expression according to a preset modification strategy, then the modified tree expression is compiled to obtain a compiled code, and the non-transaction method in the compiled code is subjected to proxy calling through the proxy object by the transaction method. By the scheme, the proxy object can be automatically added aiming at the non-transaction method, so that the transaction method can perform proxy calling on the non-transaction method based on the proxy object, and the problem of data error caused by the fact that no proxy calls the non-transaction method can be avoided.
Based on the same technical concept, an embodiment of the present invention further provides an electronic device, as shown in fig. 6, including a processor 601, a communication interface 602, a memory 603, and a communication bus 604, where the processor 601, the communication interface 602, and the memory 603 complete mutual communication through the communication bus 604,
a memory 603 for storing a computer program;
the processor 601 is configured to implement the following steps when executing the program stored in the memory 603:
acquiring a transaction source code to be compiled, wherein a non-transaction method in the transaction source code comprises preset annotation information;
generating a tree expression corresponding to the transaction source code;
determining the non-transaction method in the tree expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy;
compiling the modified tree expression to obtain a compiled code, wherein the non-transaction method in the compiled code is subjected to proxy calling by a transaction method through the proxy object.
Optionally, the generating a tree expression corresponding to the transaction source code includes:
inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
and inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, the determining, according to the annotation information, the non-transaction method in the tree expression, and adding, according to a preset modification policy, the proxy object corresponding to the non-transaction method in the tree expression includes:
determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method through an annotation processor;
and aiming at the node corresponding to each non-transaction method, adding the node corresponding to the proxy object before the target node through the annotation processor.
Optionally, the compiling the modified tree expression includes:
generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code;
and compiling the new transaction source code.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component.
In a further embodiment provided by the present invention, a computer-readable storage medium is also provided, in which a computer program is stored which, when being executed by a processor, carries out any of the above-mentioned method steps.
In a further embodiment provided by the present invention, there is also provided a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method steps of any of the above embodiments.
The computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, e.g., from one website site, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DS L)) or wireless (e.g., infrared, wireless, microwave, etc.) manner to another website site, computer, server, or data center.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method of code compilation, the method comprising:
acquiring a transaction source code to be compiled, wherein a non-transaction method in the transaction source code comprises preset annotation information;
generating a tree expression corresponding to the transaction source code;
determining the non-transaction method in the tree expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy;
compiling the modified tree expression to obtain a compiled code, wherein the non-transaction method in the compiled code is subjected to proxy calling by a transaction method through the proxy object.
2. The method of claim 1, wherein generating the tree representation corresponding to the transaction source code comprises:
inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
and inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
3. The method according to claim 1, wherein the determining the non-transaction method in the tree expression according to the annotation information, and adding the proxy object corresponding to the non-transaction method in the tree expression according to a preset modification policy includes:
determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method through an annotation processor;
and aiming at the node corresponding to each non-transaction method, adding the node corresponding to the proxy object before the target node through the annotation processor.
4. The method of claim 1, wherein compiling the modified tree expression comprises:
generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code;
and compiling the new transaction source code.
5. A code compiling apparatus characterized in that the apparatus comprises:
the system comprises an acquisition module, a compiling module and a compiling module, wherein the acquisition module is used for acquiring a transaction source code to be compiled, and a non-transaction method in the transaction source code comprises preset annotation information;
the generating module is used for generating a tree expression corresponding to the transaction source code;
the determining module is used for determining the non-transaction method in the tree expression according to the annotation information, and adding the proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy;
and the compiling module is used for compiling the modified tree expression to obtain a compiled code, and the non-transaction method in the compiled code is subjected to proxy call by a transaction method through the proxy object.
6. The apparatus of claim 5, wherein the generating module is specifically configured to:
inputting the transaction source code into a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
and inputting the one-dimensional array into a syntax analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
7. The apparatus of claim 5, wherein the determining module is specifically configured to:
determining a node containing the annotation information in the tree expression as a node corresponding to the non-transaction method through an annotation processor;
and aiming at the node corresponding to each non-transaction method, adding the node corresponding to the proxy object before the target node through the annotation processor.
8. The apparatus of claim 5, wherein the compiling module is specifically configured to:
generating a transaction source code corresponding to the modified tree-shaped expression through an annotation processor to obtain a new transaction source code;
and compiling the new transaction source code.
9. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1 to 4 when executing a program stored in the memory.
10. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 4.
CN202010163381.0A 2020-03-10 2020-03-10 Code compiling method and device Active CN111399842B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010163381.0A CN111399842B (en) 2020-03-10 2020-03-10 Code compiling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010163381.0A CN111399842B (en) 2020-03-10 2020-03-10 Code compiling method and device

Publications (2)

Publication Number Publication Date
CN111399842A true CN111399842A (en) 2020-07-10
CN111399842B CN111399842B (en) 2023-09-05

Family

ID=71436140

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010163381.0A Active CN111399842B (en) 2020-03-10 2020-03-10 Code compiling method and device

Country Status (1)

Country Link
CN (1) CN111399842B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112346778A (en) * 2020-10-28 2021-02-09 常州微亿智造科技有限公司 Optimization method for automatically generating byte codes during compiling of Java program

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160224322A1 (en) * 2015-01-29 2016-08-04 AppDynamics Inc. Dynamic agent delivery
CN110457869A (en) * 2019-07-23 2019-11-15 Oppo广东移动通信有限公司 Program compiles encryption method, device, storage medium and electronic equipment

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160224322A1 (en) * 2015-01-29 2016-08-04 AppDynamics Inc. Dynamic agent delivery
CN110457869A (en) * 2019-07-23 2019-11-15 Oppo广东移动通信有限公司 Program compiles encryption method, device, storage medium and electronic equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112346778A (en) * 2020-10-28 2021-02-09 常州微亿智造科技有限公司 Optimization method for automatically generating byte codes during compiling of Java program
CN112346778B (en) * 2020-10-28 2022-02-08 常州微亿智造科技有限公司 Optimization method for automatically generating byte codes during compiling of Java program

Also Published As

Publication number Publication date
CN111399842B (en) 2023-09-05

Similar Documents

Publication Publication Date Title
Tao et al. A reusable software component for integrated syntax and semantic validation for services computing
CN108156022B (en) Service calling method and device and electronic equipment
CN108920133B (en) Cross-language programming method and device, electronic equipment and storage medium
US9965259B2 (en) System for translating diverse programming languages
US8813049B2 (en) Type inference of partially-specified parameterized types
US20140157243A1 (en) System for Translating Diverse Programming Languages
EP2827244A1 (en) Extension mechanism for scripting language compiler
US20050004973A1 (en) Reflection-based processing of input parameters for commands
US8141035B2 (en) Method for accessing internal states of objects in object oriented programming
CN111428462A (en) Communication protocol template construction method and terminal equipment
CN110262783B (en) Interface generation method and device and terminal equipment
CN111427583A (en) Component compiling method and device, electronic equipment and computer readable storage medium
CN111427578B (en) Data conversion method, device and equipment
CN114968807A (en) Code detection method and device, electronic equipment and readable storage medium
CN110333872B (en) Application processing method, device, equipment and medium
CN113703779B (en) Cross-platform multi-language compiling method and ultra-light Internet of things virtual machine
US20080127128A1 (en) Type Validation for Applications Incorporating A Weakly-Typed Language
CN111399842B (en) Code compiling method and device
CN111352631B (en) Interface compatibility detection method and device
US10606569B2 (en) Declarative configuration elements
CN110457013B (en) Program component configuration device and method
CN116578282A (en) Code generation method, device, electronic equipment and medium
Fritzson et al. Metamodelica–a symbolic-numeric modelica language and comparison to julia
CN115022312A (en) Method and device for realizing multiple intelligent contract engines, electronic equipment and storage medium
CN113961238A (en) Object conversion method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant