CN111399842B - Code compiling method and device - Google Patents

Code compiling method and device Download PDF

Info

Publication number
CN111399842B
CN111399842B CN202010163381.0A CN202010163381A CN111399842B CN 111399842 B CN111399842 B CN 111399842B CN 202010163381 A CN202010163381 A CN 202010163381A CN 111399842 B CN111399842 B CN 111399842B
Authority
CN
China
Prior art keywords
transaction
source code
tree
compiling
annotation
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.)
Active
Application number
CN202010163381.0A
Other languages
Chinese (zh)
Other versions
CN111399842A (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

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, transaction source codes to be compiled are acquired, wherein a non-transaction method in the transaction source codes comprises preset annotation information; generating a tree expression corresponding to the transaction source code; determining the non-transaction method in the tree-shaped expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree-shaped expression according to a preset modification strategy; compiling the modified tree expression to obtain compiled codes, wherein the non-transaction method in the compiled codes is subjected to proxy call by a transaction method through the proxy object. To avoid the problem of data errors caused by the fact that the non-transactional method is not called through the 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 databases, read and write operations on data are typically implemented by transactions. In executing a transaction, a plurality of methods belonging to different classes (which may be referred to as transaction methods) are sequentially called, and the transaction methods are called in program code through proxy objects (i.e., code with proxy calling functions). For example, under the spring framework is a transaction proxy implemented using AOP, typically implemented using cglib or jdk proxy. Each time a transaction method is called, the execution state of the transaction method, such as success or failure, is recorded. When one transaction is completed, if the execution state of all the transaction methods is successful, the transaction is completed, and the data in the current database is saved. If there is a transaction method whose execution state is failed, the transaction fails to execute, and data rollback is performed, that is, 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 call each other in a transaction, where only the first method executed in the class is a transaction method, and other methods (may be referred to as non-transaction methods) are not called by proxy objects (i.e., the called methods are not managed by the transaction) because they belong to the same class as the first method. Therefore, if a certain non-transactional method fails to execute, no data rollback is performed, resulting in errors in the data in the database.
Disclosure of Invention
The embodiment of the application aims to provide a code compiling method and device, which are used for solving the problems that transactions cannot take effect and data are wrong in the prior art due to similar calling of a non-transaction method. The specific technical scheme is as follows:
in a first aspect, there is provided a code compiling method, 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-shaped expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree-shaped expression according to a preset modification strategy;
compiling the modified tree expression to obtain compiled codes, wherein the non-transaction method in the compiled codes is subjected to proxy call by a transaction method through the proxy object.
Optionally, the generating the tree expression corresponding to the transaction source code includes:
inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
inputting the one-dimensional array to a grammar analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, 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, by an annotation processor, a node containing the annotation information in the tree expression as a node corresponding to the non-transactional method;
and adding a node corresponding to the proxy object before the target node by the annotation processor for the node corresponding to each non-transaction method.
Optionally, compiling the modified tree expression includes:
generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code;
compiling the new transaction source code.
In a second aspect, there is provided a code compiling apparatus, the apparatus comprising:
the system comprises an acquisition module, a compiling module and a compiling module, wherein the acquisition module is used for acquiring transaction source codes to be compiled, and a non-transaction method in the transaction source codes comprises preset annotation information;
the generation 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 a 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-shaped expression to obtain a compiled code, and the non-transaction method in the compiled code is invoked by the transaction method through the proxy object.
Optionally, the generating module is specifically configured to:
inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
inputting the one-dimensional array to a grammar analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, the determining module is specifically configured to:
determining, by an annotation processor, a node containing the annotation information in the tree expression as a node corresponding to the non-transactional method;
and adding a node corresponding to the proxy object before the target node by the annotation processor for the node corresponding to each non-transaction method.
Optionally, the compiling module is specifically configured to:
generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code;
compiling the new transaction source code.
In a third aspect, an electronic device is provided, including a processor, a communication interface, a memory, and a communication bus, where 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 aspects when executing a program stored on a memory.
In a fourth aspect, a computer-readable storage medium is provided, characterized in that the computer-readable storage medium has stored therein a computer program which, when executed by a processor, implements the method steps of any of the first aspects.
In a fifth aspect, there is provided a computer program product comprising 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 beneficial effects that:
the embodiment of the application provides a code compiling method and device, which can acquire transaction source codes to be compiled, wherein a non-transaction method in the transaction source codes comprises preset annotation information. Then, generating a tree expression corresponding to the transaction source code, further determining a non-transaction method in the tree expression according to annotation information, 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, and performing proxy call on the non-transaction method in the compiled code by the transaction method through the proxy object. According to the scheme, the proxy object can be automatically added for the non-transaction method, so that the transaction method can perform proxy call on the non-transaction method based on the proxy object, and the problem of data error caused by the fact that the non-transaction method is not called by a proxy can be avoided.
Of course, it is not necessary for any one product or method of practicing the application to achieve all of the advantages set forth above at the same time.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the application or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
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 proxy objects 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
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the 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, etc.
The following will describe a code compiling method according to an embodiment of the present application in detail with reference to a specific embodiment, as shown in fig. 1, the specific steps are as follows:
step 101, obtaining 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, the electronic device may obtain transaction source code to be compiled, which may be used to execute one or more transactions. The transaction source code includes at least one class, each class including a plurality of methods. In this embodiment, there may be a case where multiple methods in the same class call each other, where the first method executed in the class is a transaction method, and the method called by the transaction method in the class is a non-transaction method.
In order to avoid the problem of data errors caused by the fact that a non-transactional method is not called through a proxy object, preset annotation information is added in the non-transactional method of a transaction source code, 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 transactional source code, a SelfClassInvoke 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 class of non-transactional method B is to be invoked at transactional method a, annotation information is added for non-transactional method B, which is annotation information that the annotation processor is capable of handling. Subsequently, if the annotation processor determines that a method contains the annotation information, the annotation processor identifies the method as a non-transaction method, and adds codes (namely agent objects) with agent calling functions for the non-transaction method, so that agent calling of the A method to the B method is realized.
And 102, generating a tree expression corresponding to the transaction source code.
In the embodiment of the application, the generation strategy of the tree expression can be prestored in the electronic equipment, and the tree expression corresponding to the transaction source code can be generated through the preset generation strategy after the electronic equipment acquires the transaction source code. The tree expression concrete may be AST (abstract syntax tree ), and the concrete generation process will be described in detail later. AST is a method for representing source code, and reflects each sentence included in source code and the structural relationship between each sentence.
Step 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 the embodiment of the application, the electronic device can traverse the tree expression to determine the method containing the annotation information (such as SelfClassInvoke class), the methods are non-transaction methods, and the corresponding nodes are nodes 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 specific modification process will be described in detail later.
And 104, compiling the modified tree expression to obtain compiled codes.
In the embodiment of the application, the electronic equipment can compile the modified tree expression to obtain the compiled code. Because the proxy object is added for the non-transaction method in the tree expression, the non-transaction method is subjected to proxy call by the transaction method through the proxy object in the compiled code, namely, the call mode of the transaction method to the non-transaction method in the same class is changed from direct call to proxy call. The problem of data errors caused by the fact that the non-transaction method is not called through the proxy object is avoided.
The annotation processor deletes the annotation information in the non-transaction method after modifying the tree expression so as to carry out subsequent compiling.
Optionally, the specific process of compiling the modified tree expression is as follows: generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code; compiling the new transaction source code.
In the embodiment of the application, after modifying the tree-shaped expression, the annotation processor generates a new source code (which can be called a new transaction source code) according to the modified tree-shaped expression, and then re-inputs the new transaction source code to the lexical analysis scanner to output a one-dimensional array corresponding to the new transaction source code. Then, the one-dimensional array is input to a parse parser, a tree expression (which may be referred to 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. Since 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 during the semantic analysis of the new tree expression. Then, the new tree expression after semantic analysis is input to a byte code generator, JVM byte codes are output, and compiling of transaction source codes is completed.
In the embodiment of the application, the transaction source code to be compiled can be obtained, wherein the non-transaction method in the transaction source code contains preset annotation information. Then, generating a tree expression corresponding to the transaction source code, further determining a non-transaction method in the tree expression according to annotation information, 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, and performing proxy call on the non-transaction method in the compiled code by the transaction method through the proxy object. According to the scheme, the proxy object can be automatically added for the non-transaction method, so that the transaction method can perform proxy call on the non-transaction method based on the proxy object, and the problem of data error caused by the fact that the non-transaction method is not called by a proxy can be avoided.
Optionally, as shown in fig. 2, the specific process of generating the tree expression corresponding to the transaction source code includes the following steps:
step 201, inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code.
In the embodiment of the application, the lexical analysis scanner can be stored in the electronic equipment. After the electronic device obtains the transaction source code to be compiled, the transaction source code may be input to a lexical analysis scanner, where the lexical analysis scanner splits the transaction source code into a one-dimensional array. For example, a one-dimensional array X4 can be obtained when the source code is int a=6, where X1 is int, X2 is a, X3 is=, and X4 is 6. Thus, the lexical analysis scanner may output a one-dimensional array corresponding to the transaction source code.
Step 203, inputting the one-dimensional array to 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 a one-dimensional array, the electronic equipment can input the one-dimensional array into the syntax analysis analyzer, and the syntax analysis analyzer converts the received one-dimensional array into a tree expression and then outputs 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, the specific process of adding the proxy object includes the following steps:
in step 301, according to the annotation information, a node containing the annotation information is determined in the tree expression as a node corresponding to the non-transaction method.
In the embodiment of the application, a technician needs to realize a customized annotation processor in advance. The annotation processor concrete may be Abstract Processor (i.e., abstract processor), abstract Processor is an annotation processor in java development kit jdk, such as Transaction Proxy Processor (i.e., transaction proxy processor).
The technician may add another annotation information in the annotation processor. For example, the annotation information is @ Supported dAnnetationTypes (supporting annotation types) to specify that the annotation processor supports parsing the annotation information (such as the SelfClassInvoke class). In addition, all java versions supported by the annotation information may be specified, i.e., the java version of the transaction source code.
Referring to the above description, for each non-transactional method in the transactional source code, a SelfClassInvoke class is added to the non-transactional method. This method of adding the Self ClassInvoke identifier will be parsed by the annotation processor. For example, when a SelfClassInvoke annotation is added to the method B, the annotation processor parses the SelfClassInvoke class in the process of parsing the tree expression, so as to parse the method B including the SelfClass Invoke class, and then it can be determined that the method B is a non-transaction method.
Step 302, for each node corresponding to the non-transaction method, adding a node corresponding to the proxy object before the target node.
In the embodiment of the application, when the annotation processor determines that a method comprises a SelfClassInvoke class, the method is determined to be a non-transaction method, and then a node corresponding to a proxy object can be added in front of a target node, so that a proxy call is added, for example, an addition code AopContext.
In one example, if the transaction method a calls the non-transaction method B in the class, a node of the method B is determined in the AST tree expression, and before the node, a node corresponding to the proxy object, that is, a node containing a code ((Pojo) aopcontext. Currentproxy ()) is added.
For example, the pseudocode implemented is:
when an AST is processed using the annotation processor, the class actually generated at the compilation stage is as follows (without content defining the annotation class):
then, the annotation processor deletes the content defining the annotation class and the annotation class, and outputs new transaction source codes as follows:
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 parse 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.
And step 1, acquiring transaction source codes 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 step 3, inputting the one-dimensional array into a grammar analysis analyzer, and outputting AST corresponding to the transaction source code.
And 4, carrying out semantic analysis on the AST.
In the semantic analysis process, the annotation processor determines whether annotation information is contained in the tree expression. If so, step 5 is performed, otherwise, step 8 is performed.
And 5, determining a method containing annotation information as a non-transaction method by the annotation processor, and adding a proxy object corresponding to the non-transaction method into the tree expression according to a preset modification strategy.
And 6, generating transaction source codes corresponding to the modified tree expressions by the annotation processor, and deleting annotation information in the transaction source codes to obtain new transaction source codes.
And 7, taking the new transaction source code as the transaction source code to be compiled, and returning to the execution step 2.
And 8, generating transaction source codes (namely analyzed source codes) corresponding to the tree expressions by the annotation processor, inputting the source codes into a byte code generator, outputting JVM (Java Virtual Machine ) byte codes, and completing compiling of the transaction source codes.
Based on the same technical concept, the embodiment of the application further provides a code compiling device, as shown in fig. 5, where the device 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, according to the annotation information, the non-transaction method in the tree expression, and add, according to a preset modification policy, a proxy object corresponding to the non-transaction method in the tree expression;
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 the transaction method through the proxy object.
Optionally, the generating module 520 is specifically configured to:
inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
inputting the one-dimensional array to a grammar analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, the determining module 530 is specifically configured to:
determining, by an annotation processor, a node containing the annotation information in the tree expression as a node corresponding to the non-transactional method;
and adding a node corresponding to the proxy object before the target node by the annotation processor for the node corresponding to each non-transaction method.
Optionally, the compiling module 540 is specifically configured to:
generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code;
compiling the new transaction source code.
In the embodiment of the application, the transaction source code to be compiled can be obtained, wherein the non-transaction method in the transaction source code contains preset annotation information. Then, generating a tree expression corresponding to the transaction source code, further determining a non-transaction method in the tree expression according to annotation information, 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, and performing proxy call on the non-transaction method in the compiled code by the transaction method through the proxy object. According to the scheme, the proxy object can be automatically added for the non-transaction method, so that the transaction method can perform proxy call on the non-transaction method based on the proxy object, and the problem of data error caused by the fact that the non-transaction method is not called by a proxy can be avoided.
Based on the same technical concept, the embodiment of the present application 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 perform communication with each other through the communication bus 604,
a memory 603 for storing a computer program;
the processor 601 is configured to execute the program stored in the memory 603, and implement the following steps:
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-shaped expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree-shaped expression according to a preset modification strategy;
compiling the modified tree expression to obtain compiled codes, wherein the non-transaction method in the compiled codes is subjected to proxy call by a transaction method through the proxy object.
Optionally, the generating the tree expression corresponding to the transaction source code includes:
inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
inputting the one-dimensional array to a grammar analysis analyzer, and outputting a tree expression corresponding to the transaction source code.
Optionally, 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, by an annotation processor, a node containing the annotation information in the tree expression as a node corresponding to the non-transactional method;
and adding a node corresponding to the proxy object before the target node by the annotation processor for the node corresponding to each non-transaction method.
Optionally, compiling the modified tree expression includes:
generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code;
compiling the new transaction source code.
The communication bus mentioned above for the electronic devices may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include 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 aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processing, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In a further embodiment of the present application, a computer-readable storage medium is also provided, in which a computer program is stored which, when being executed by a processor, implements any of the above-mentioned method steps.
In a further embodiment of the present application, a computer program product comprising instructions is also provided, which when run on a computer causes the computer to perform any of the method steps of the above embodiments.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It should be noted that in this document, relational terms such as "first" and "second" and the like are 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. Moreover, 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 one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The foregoing is only a specific embodiment of the application to enable those skilled in the art to understand or practice the application. 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 application. Thus, the present application 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 (4)

1. A method of compiling code, the method comprising:
acquiring transaction source codes to be compiled, wherein a non-transaction method in the transaction source codes comprises preset annotation information, the annotation information is information for representing that the method is a non-transaction method, the annotation information is a self-class calling class, and the self-class calling class is added in each non-transaction method in the transaction source codes for marking that the non-transaction method is a non-transaction method called by a similar method;
generating a tree expression corresponding to the transaction source code;
determining the non-transaction method in the tree-shaped expression according to the annotation information, and adding a proxy object corresponding to the non-transaction method in the tree-shaped 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 call by a transaction method through the proxy object;
the method 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 comprises the following steps:
determining, by an annotation processor, a node containing the annotation information in the tree expression as a node corresponding to the non-transactional method; for each node corresponding to the non-transaction method, adding a node corresponding to the proxy object before the node by the annotation processor;
the generating the tree expression corresponding to the transaction source code comprises the following steps:
inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
inputting the one-dimensional array to a grammar analysis analyzer, and outputting a tree expression corresponding to the transaction source code;
the compiling of the modified tree expression comprises the following steps:
generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code;
compiling the new transaction source code.
2. A code compiling apparatus, the apparatus comprising:
the system comprises an acquisition module, a compiling module and a compiling module, wherein the transaction source code is used for acquiring transaction source codes to be compiled, a non-transaction method in the transaction source codes comprises preset annotation information, the annotation information is information for indicating that the method is a non-transaction method, the annotation information is a self-class calling class, and the self-class calling class is added in the non-transaction method for each non-transaction method in the transaction source codes so as to mark that the non-transaction method is a non-transaction method called by a similar method;
the generation 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 a proxy object corresponding to the non-transaction method in the tree expression according to a preset modification strategy;
the compiling module is used for compiling the modified tree-shaped expression to obtain a compiled code, and the transaction method in the compiled code is subjected to proxy call by the transaction method through the proxy object;
the determining module is specifically configured to:
determining, by an annotation processor, a node containing the annotation information in the tree expression as a node corresponding to the non-transactional method; for each node corresponding to the non-transaction method, adding a node corresponding to the proxy object before the node by the annotation processor;
the generating module is specifically configured to:
inputting the transaction source code to a lexical analysis scanner, and outputting a one-dimensional array corresponding to the transaction source code;
inputting the one-dimensional array to a grammar analysis analyzer, and outputting a tree expression corresponding to the transaction source code;
the compiling module is specifically configured to:
generating a transaction source code corresponding to the modified tree expression through the annotation processor to obtain a new transaction source code;
compiling the new transaction source code.
3. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of claim 1 when executing a program stored on a memory.
4. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored therein a computer program which, when executed by a processor, implements the method steps of claim 1.
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 CN111399842A (en) 2020-07-10
CN111399842B true 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)

Families Citing this family (1)

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

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110457869A (en) * 2019-07-23 2019-11-15 Oppo广东移动通信有限公司 Program compiles encryption method, device, storage medium and electronic equipment

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9535666B2 (en) * 2015-01-29 2017-01-03 AppDynamics, Inc. Dynamic agent delivery

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110457869A (en) * 2019-07-23 2019-11-15 Oppo广东移动通信有限公司 Program compiles encryption method, device, storage medium and electronic equipment

Also Published As

Publication number Publication date
CN111399842A (en) 2020-07-10

Similar Documents

Publication Publication Date Title
CN111428462B (en) Communication protocol template construction method and terminal equipment
KR100995199B1 (en) Reflection-based processing of input parameters for commands
US9471282B2 (en) System and method for using annotations to automatically generate a framework for a custom javaserver faces (JSF) component
US20160342413A1 (en) Verification of backward compatibility of software components
JP6524021B2 (en) Parsed header for compilation
US20040049766A1 (en) Method and apparatus for associating metadata attributes with program elements
US8141035B2 (en) Method for accessing internal states of objects in object oriented programming
CN111427583A (en) Component compiling method and device, electronic equipment and computer readable storage medium
CN114968807A (en) Code detection method and device, electronic equipment and readable storage medium
EP3974964A1 (en) Automated generation of software patches
CN111399842B (en) Code compiling method and device
CN111427578B (en) Data conversion method, device and equipment
CN111352631B (en) Interface compatibility detection method and device
US6938239B2 (en) Automatic gopher program generator
CN110457013B (en) Program component configuration device and method
CN112416612A (en) Service calling method and device, computer equipment and readable storage medium
CN116578282A (en) Code generation method, device, electronic equipment and medium
CN116755669A (en) Low code development method and tool based on DSL language operation model
CN111475150A (en) Cross-language binding method, device, equipment and storage medium
Fritzson et al. Metamodelica–a symbolic-numeric modelica language and comparison to julia
CN112711405B (en) Method, equipment and storage medium for generating add-delete-modify-check application program interface
CN111767213B (en) Database check point testing method and device, electronic equipment and storage medium
CN110737431B (en) Software development method, development platform, terminal device and storage medium
US11556455B2 (en) Automated identification of posts related to software patches
CN112328241B (en) Method and device for creating Android library module dependency relationship in application program development

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