CN112667240A - Program code conversion method and related device - Google Patents

Program code conversion method and related device Download PDF

Info

Publication number
CN112667240A
CN112667240A CN202011540127.4A CN202011540127A CN112667240A CN 112667240 A CN112667240 A CN 112667240A CN 202011540127 A CN202011540127 A CN 202011540127A CN 112667240 A CN112667240 A CN 112667240A
Authority
CN
China
Prior art keywords
target
conversion
source
syntax tree
data structure
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.)
Pending
Application number
CN202011540127.4A
Other languages
Chinese (zh)
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.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management 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 Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202011540127.4A priority Critical patent/CN112667240A/en
Publication of CN112667240A publication Critical patent/CN112667240A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

The invention relates to the field of development assistance, and provides a program code conversion method and related equipment. The method can acquire a source code file according to a code conversion request, convert the source code file into a source syntax tree, acquire a conversion identifier in the source code file, acquire a conversion data structure from the source syntax tree according to the conversion identifier, determine a target type according to the code conversion request, acquire a target data structure corresponding to the conversion data structure according to the target type, process the source syntax tree according to the target data structure to acquire a target syntax tree, and convert the target syntax tree to acquire a target code file. The invention can support the conversion of the program codes with inconsistent names and types and can improve the code conversion efficiency. Furthermore, the invention also relates to blockchain techniques, in which the object code files may be stored.

Description

Program code conversion method and related device
Technical Field
The present invention relates to the field of development assistance technologies, and in particular, to a program code conversion method and related devices.
Background
When the service method is called, the processing flow spans the multilayer structure, and when the entry types of the inner layer and the outer layer in the multilayer structure are different, for example, the entry type of the outer layer is a data transmission object, and the entry type of the inner layer is an entity object, the source file needs to be converted to be called.
In order to realize the calling of the source file, a Bean tool is usually adopted to transcode the source file, however, the Bean tool does not support the conversion of program codes with inconsistent names and types, and the selma tool needs to write a corresponding interface for each object, which causes the low efficiency of source file transcoding.
Disclosure of Invention
In view of the above, it is desirable to provide a program code conversion method and related apparatus, which can support the conversion of program codes with inconsistent names and types and can improve the code conversion efficiency.
In one aspect, the present invention provides a program code conversion method, including:
when a code conversion request is received, acquiring a source code file according to the code conversion request;
converting the source code file into a source syntax tree, and acquiring a conversion identifier in the source code file;
acquiring a conversion data structure from the source syntax tree according to the conversion identifier;
determining a target type according to the code conversion request, and acquiring a target data structure corresponding to the conversion data structure according to the target type;
processing the source syntax tree according to the target data structure to obtain a target syntax tree;
and converting the target syntax tree to obtain a target code file.
According to a preferred embodiment of the present invention, the obtaining a source code file according to the transcoding request includes:
analyzing the message of the code conversion request to obtain message information carried by the message;
acquiring a first preset label, wherein the first preset label is used for indicating a position;
acquiring information corresponding to the first preset label from the message information as a storage position;
determining a trigger terminal of the transcoding request;
and acquiring the information stored in the storage position from the trigger terminal as the source code file.
According to a preferred embodiment of the present invention, the determining a target type according to the transcoding request comprises:
removing the storage position from the message information to obtain data information;
acquiring a second preset label, wherein the second preset label is used for indicating the type;
and acquiring information corresponding to the second preset label from the data information as the target type.
According to a preferred embodiment of the present invention, said converting said source code file into a source syntax tree comprises:
calling a preset function to read the source code file to obtain a plurality of characters;
comparing the characters with preset characters to obtain a plurality of mark sequences;
carrying out syntactic analysis on the plurality of marking sequences to obtain a plurality of code structures;
determining sequence positions of the plurality of marker sequences in the source code file;
and splicing the plurality of code structures according to the sequence positions to obtain the source syntax tree.
According to a preferred embodiment of the present invention, the obtaining of the target data structure corresponding to the conversion data structure according to the target type includes:
determining a source type to which the source code file belongs;
determining a mapping table according to the source type and the target type;
acquiring a conversion field in the conversion data structure, and acquiring a target field corresponding to the conversion field from the mapping table;
and replacing the conversion field in the conversion data structure by using the target field to obtain the target data structure.
According to a preferred embodiment of the present invention, said processing said source syntax tree according to said target data structure to obtain a target syntax tree comprises:
determining a structure position of the transformation data structure in the source syntax tree;
and writing the target data structure into the structure position to obtain the target syntax tree.
According to the preferred embodiment of the present invention, the converting the target syntax tree to obtain the target code file includes:
splitting the target syntax tree into a plurality of nodes;
parallel decompiling the nodes to obtain node codes corresponding to the nodes;
determining node positions of the plurality of nodes in the target syntax tree;
and splicing the node codes according to the node positions to obtain the target code file.
In another aspect, the present invention further provides a program code conversion apparatus, including:
the system comprises an acquisition unit, a conversion unit and a conversion unit, wherein the acquisition unit is used for acquiring a source code file according to a code conversion request when the code conversion request is received;
the conversion unit is used for converting the source code file into a source syntax tree and acquiring a conversion identifier in the source code file;
the obtaining unit is further configured to obtain a conversion data structure from the source syntax tree according to the conversion identifier;
the obtaining unit is further configured to determine a target type according to the transcoding request, and obtain a target data structure corresponding to the converted data structure according to the target type;
the processing unit is used for processing the source syntax tree according to the target data structure to obtain a target syntax tree;
the conversion unit is further configured to convert the target syntax tree to obtain a target code file.
In another aspect, the present invention further provides an electronic device, including:
a memory storing computer readable instructions; and
a processor executing computer readable instructions stored in the memory to implement the program code conversion method.
In another aspect, the present invention also provides a computer-readable storage medium having computer-readable instructions stored therein, which are executed by a processor in an electronic device to implement the program code conversion method.
It can be seen from the above technical solutions that, when a code conversion request is received, the present invention can obtain a source code file according to the code conversion request, can accurately obtain a code file to be code converted through the code conversion request, convert the source code file into a source syntax tree, and obtain a conversion identifier in the source code file, obtain a conversion data structure from the source syntax tree according to the conversion identifier, obtain the conversion data structure from the source syntax tree, because each node code on the source syntax tree has a syntax structure, can quickly obtain the conversion data structure from the source syntax tree through the conversion identifier, determine a target type according to the code conversion request, and obtain a target data structure corresponding to the conversion data structure according to the target type, processing the source syntax tree according to the target data structure to obtain a target syntax tree, replacing the conversion data structure on the source syntax tree through the target data structure, and since the target syntax tree does not need to be reconstructed, rapidly generating the target syntax tree and converting the target syntax tree to obtain a target code file, the conversion data structure is determined, and then the conversion data structure is converted into the target data structure, so that the source syntax tree generated by the source code file is modified by using the target data structure, the target syntax tree can be obtained, and then the target syntax tree is converted, and a target code file corresponding to the target type can be generated. A bridge between the converted data result and the target data result can be established, and further the conversion of program codes with inconsistent names and types can be supported.
Drawings
FIG. 1 is a flow chart of the preferred embodiment of the program code conversion method of the present invention.
FIG. 2 is a flow diagram of one embodiment of the present invention for converting source code into a source syntax tree.
FIG. 3 is a functional block diagram of a preferred embodiment of the program code conversion apparatus according to the present invention.
FIG. 4 is a schematic structural diagram of an electronic device implementing the program code conversion method according to the preferred embodiment of the invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
FIG. 1 is a flow chart of the preferred embodiment of the program code conversion method of the present invention. The order of the steps in the flow chart may be changed and some steps may be omitted according to different needs.
The program code conversion method is applied to one or more electronic devices, which are devices capable of automatically performing numerical calculation and/or information processing according to computer readable instructions set or stored in advance, and the hardware thereof includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The electronic device may be any electronic product capable of performing human-computer interaction with a user, for example, a Personal computer, a tablet computer, a smart phone, a Personal Digital Assistant (PDA), a game machine, an interactive Internet Protocol Television (IPTV), a smart wearable device, and the like.
The electronic device may include a network device and/or a user device. Wherein the network device includes, but is not limited to, a single network electronic device, an electronic device group consisting of a plurality of network electronic devices, or a Cloud Computing (Cloud Computing) based Cloud consisting of a large number of hosts or network electronic devices.
The network in which the electronic device is located includes, but is not limited to: the internet, a wide area Network, a metropolitan area Network, a local area Network, a Virtual Private Network (VPN), and the like.
S10, when a code conversion request is received, the source code file is obtained according to the code conversion request.
In at least one embodiment of the present invention, the transcoding request may be triggered by a user or during a service invocation method. The transcoding request carries a trigger address, a destination address, a storage location, etc.
The source code file refers to program codes needing code conversion.
In at least one embodiment of the present invention, the electronic device obtaining a source code file according to the transcoding request includes:
analyzing the message of the code conversion request to obtain message information carried by the message;
acquiring a first preset label, wherein the first preset label is used for indicating a position;
acquiring information corresponding to the first preset label from the message information as a storage position;
determining a trigger terminal of the transcoding request;
and acquiring the information stored in the storage position from the trigger terminal as the source code file.
Wherein, the message information includes a storage location, etc. The storage location refers to an arbitrary path on the trigger terminal.
The first preset tag may be obtained from a tag library.
The triggering terminal is a terminal which triggers the code conversion request to generate, and the source code file is stored on the triggering terminal.
Through the embodiment, the whole code conversion request does not need to be analyzed, so that the acquisition efficiency of the message information can be improved, the storage position can be accurately determined by utilizing the mapping relation between the label of the indication position and the position, and in addition, the trigger terminal and the storage position can uniquely determine a file, so that the source code file can be accurately determined.
S11, converting the source code file into a source syntax tree, and acquiring a conversion identifier in the source code file.
In at least one embodiment of the invention, the source syntax tree is an abstract representation of the syntax structure in the source code file, the source syntax tree represents the syntax structure of the source code file in a tree form, and each node on the source syntax tree represents a structure in the source syntax tree.
The translation identifier is used to indicate a syntax structure that needs to be transcoded. The conversion identifier is set in the source code file in advance.
In at least one embodiment of the invention, prior to converting the source code file to a source syntax tree, the method further comprises:
detecting whether the grammar in the source code file is correct;
if the source code file has a grammar error, determining a target structure with the grammar error from the source code file;
optimizing the target structure.
Through the implementation mode, the grammar error in the source code file can be avoided, the grammar error in the converted target code file can be further avoided, and the conversion accuracy of the target code file is improved.
Referring to FIG. 2, FIG. 2 is a flow diagram of one embodiment of the present invention for converting source code into a source syntax tree. In at least one embodiment of the invention, the electronic device converting the source code file into a source syntax tree includes:
and S110, calling a preset function to read the source code file to obtain a plurality of characters.
The preset function may be a next () method.
The characters refer to characters read from the source code file.
And S111, comparing the characters with preset characters to obtain a plurality of mark sequences.
The preset character refers to a predefined function, and the like, for example, the preset character is select.
Further, each marker sequence refers to each line of code in the source code file.
And S112, carrying out syntactic analysis on the plurality of marking sequences to obtain a plurality of code structures.
The code structure refers to a grammatical relationship in the source code file.
S113, determining the sequence positions of the plurality of mark sequences in the source code file.
The sequence position refers to a specific position of the plurality of marker sequences in the source code file.
S114, splicing the code structures according to the sequence positions to obtain the source syntax tree.
The method comprises the steps of reading characters in the source code file one by one, and carrying out syntactic analysis on the plurality of mark sequences, so that the plurality of code structures can be accurately obtained, and further, the source syntactic tree can be accurately generated through sequence positions of the plurality of mark sequences in the source code file.
S12, obtaining a conversion data structure from the source syntax tree according to the conversion identification.
In at least one embodiment of the present invention, the translation data structure refers to a syntax structure that requires transcoding.
In at least one embodiment of the present invention, the electronic device obtaining the transformation data structure from the source syntax tree according to the transformation identifier comprises:
traversing the source syntax tree according to the conversion identifier;
and determining the traversed code structure containing the conversion identification as the conversion data structure.
And the conversion data structure can be accurately determined from the source syntax tree through the conversion identifier.
S13, determining a target type according to the code conversion request, and acquiring a target data structure corresponding to the conversion data structure according to the target type.
In at least one embodiment of the present invention, the target type refers to a type to which the code is converted.
The target data structure refers to a syntax structure corresponding to both the target type and the transformation data structure.
In at least one embodiment of the invention, the electronic device determining the target type from the transcoding request comprises:
removing the storage position from the message information to obtain data information;
acquiring a second preset label, wherein the second preset label is used for indicating the type;
and acquiring information corresponding to the second preset label from the data information as the target type.
By removing the storage position in the message information, data information without other interference information can be obtained, the target type can be quickly obtained from the data information, and in addition, the target type can be accurately determined from the code conversion request through the mapping relation between the second preset label and the type.
In at least one embodiment of the present invention, the obtaining, by the electronic device according to the target type, a target data structure corresponding to the conversion data structure includes:
determining a source type to which the source code file belongs;
determining a mapping table according to the source type and the target type;
acquiring a conversion field in the conversion data structure, and acquiring a target field corresponding to the conversion field from the mapping table;
and replacing the conversion field in the conversion data structure by using the target field to obtain the target data structure.
The source type refers to a code type to which the source code file belongs, and the source type may be a JAVA type.
The target type refers to a converted code type, and the target type may be a C language type.
The mapping table stores the mapping relation between the field corresponding to the source type and the field corresponding to the target type.
According to the embodiment, the obtained target field is used for replacing the conversion field in the conversion data structure, the structure does not need to be reassembled, and therefore the generation efficiency of the target data structure can be improved.
And S14, processing the source syntax tree according to the target data structure to obtain a target syntax tree.
In at least one embodiment of the present invention, the target syntax tree refers to a syntax tree corresponding to the target type.
In at least one embodiment of the present invention, the processing, by the electronic device, the source syntax tree according to the target data structure to obtain a target syntax tree includes:
determining a structure position of the transformation data structure in the source syntax tree;
and writing the target data structure into the structure position to obtain the target syntax tree.
With the above embodiment, since it is not necessary to reconstruct the entire target syntax tree, the generation efficiency of the target syntax tree can be improved.
And S15, converting the target syntax tree to obtain a target code file.
It is emphasized that the object code file may also be stored in a node of a block chain in order to further ensure the privacy and security of the object code file.
In at least one embodiment of the present invention, the object code file refers to a program code obtained by performing code conversion, and the object code file refers to a program code corresponding to the object type.
In at least one embodiment of the present invention, the converting, by the electronic device, the target syntax tree to obtain the target code file includes:
splitting the target syntax tree into a plurality of nodes;
parallel decompiling the nodes to obtain node codes corresponding to the nodes;
determining node positions of the plurality of nodes in the target syntax tree;
and splicing the node codes according to the node positions to obtain the target code file.
By splitting the target syntax tree into the plurality of nodes, the plurality of nodes can be decompiled in a parallel mode, and therefore the generation efficiency of the target code file can be improved.
In at least one embodiment of the invention, after obtaining the object code file, the method further comprises:
acquiring a request number of the code conversion request;
generating prompt information according to the request number and the target code file;
encrypting the prompt message by adopting a symmetric encryption algorithm to obtain a ciphertext;
and sending the ciphertext to the trigger terminal.
Through the implementation mode, the prompt message can be sent to the trigger terminal in time, and then a user is informed of receiving the target code file in time.
It can be seen from the above technical solutions that, when a code conversion request is received, the present invention can obtain a source code file according to the code conversion request, can accurately obtain a code file to be code converted through the code conversion request, convert the source code file into a source syntax tree, and obtain a conversion identifier in the source code file, obtain a conversion data structure from the source syntax tree according to the conversion identifier, obtain the conversion data structure from the source syntax tree, because each node code on the source syntax tree has a syntax structure, can quickly obtain the conversion data structure from the source syntax tree through the conversion identifier, determine a target type according to the code conversion request, and obtain a target data structure corresponding to the conversion data structure according to the target type, processing the source syntax tree according to the target data structure to obtain a target syntax tree, replacing the conversion data structure on the source syntax tree through the target data structure, and since the target syntax tree does not need to be reconstructed, rapidly generating the target syntax tree and converting the target syntax tree to obtain a target code file, the conversion data structure is determined, and then the conversion data structure is converted into the target data structure, so that the source syntax tree generated by the source code file is modified by using the target data structure, the target syntax tree can be obtained, and then the target syntax tree is converted, and a target code file corresponding to the target type can be generated. A bridge between the converted data result and the target data result can be established, and further the conversion of program codes with inconsistent names and types can be supported.
FIG. 3 is a functional block diagram of a preferred embodiment of the program code conversion apparatus according to the present invention. The program code conversion apparatus 11 includes an acquisition unit 110, a conversion unit 111, a processing unit 112, a generation unit 113, an encryption unit 114, and a transmission unit 115. The module/unit referred to herein is a series of computer readable instruction segments that can be accessed by the processor 13 and perform a fixed function and that are stored in the memory 12. In the present embodiment, the functions of the modules/units will be described in detail in the following embodiments.
When a transcoding request is received, the obtaining unit 110 obtains a source code file according to the transcoding request.
In at least one embodiment of the present invention, the obtaining unit 110 obtains the source code file according to the transcoding request includes:
analyzing the message of the code conversion request to obtain message information carried by the message;
acquiring a first preset label, wherein the first preset label is used for indicating a position;
acquiring information corresponding to the first preset label from the message information as a storage position;
determining a trigger terminal of the transcoding request;
and acquiring the information stored in the storage position from the trigger terminal as the source code file.
Through the embodiment, the whole code conversion request does not need to be analyzed, so that the acquisition efficiency of the message information can be improved, the storage position can be accurately determined by utilizing the mapping relation between the label of the indication position and the position, and in addition, the trigger terminal and the storage position can uniquely determine a file, so that the source code file can be accurately determined.
The conversion unit 111 converts the source code file into a source syntax tree and obtains a conversion identifier in the source code file.
In at least one embodiment of the present invention, the converting unit 111 converts the source code file into a source syntax tree including:
calling a preset function to read the source code file to obtain a plurality of characters;
comparing the characters with preset characters to obtain a plurality of mark sequences;
carrying out syntactic analysis on the plurality of marking sequences to obtain a plurality of code structures;
determining sequence positions of the plurality of marker sequences in the source code file;
and splicing the plurality of code structures according to the sequence positions to obtain the source syntax tree.
The method comprises the steps of reading characters in the source code file one by one, and carrying out syntactic analysis on the plurality of mark sequences, so that the plurality of code structures can be accurately obtained, and further, the source syntactic tree can be accurately generated through sequence positions of the plurality of mark sequences in the source code file.
The retrieving unit 110 retrieves a translation data structure from the source syntax tree based on the translation identifier.
In at least one embodiment of the present invention, the obtaining unit 110 obtains the transformation data structure from the source syntax tree according to the transformation identifier includes:
traversing the source syntax tree according to the conversion identifier;
and determining the traversed code structure containing the conversion identification as the conversion data structure.
And the conversion data structure can be accurately determined from the source syntax tree through the conversion identifier.
The obtaining unit 110 determines a target type according to the transcoding request, and obtains a target data structure corresponding to the converted data structure according to the target type.
In at least one embodiment of the present invention, the obtaining unit 110 determining the target type according to the transcoding request includes:
removing the storage position from the message information to obtain data information;
acquiring a second preset label, wherein the second preset label is used for indicating the type;
and acquiring information corresponding to the second preset label from the data information as the target type.
By removing the storage position in the message information, data information without other interference information can be obtained, the target type can be quickly obtained from the data information, and in addition, the target type can be accurately determined from the code conversion request through the mapping relation between the second preset label and the type.
In at least one embodiment of the present invention, the obtaining unit 110 obtains the target data structure corresponding to the conversion data structure according to the target type includes:
determining a source type to which the source code file belongs;
determining a mapping table according to the source type and the target type;
acquiring a conversion field in the conversion data structure, and acquiring a target field corresponding to the conversion field from the mapping table;
and replacing the conversion field in the conversion data structure by using the target field to obtain the target data structure.
According to the embodiment, the obtained target field is used for replacing the conversion field in the conversion data structure, the structure does not need to be reassembled, and therefore the generation efficiency of the target data structure can be improved.
The processing unit 112 processes the source syntax tree according to the target data structure to obtain a target syntax tree.
In at least one embodiment of the present invention, the processing unit 112 processes the source syntax tree according to the target data structure to obtain a target syntax tree, including:
determining a structure position of the transformation data structure in the source syntax tree;
and writing the target data structure into the structure position to obtain the target syntax tree.
With the above embodiment, since it is not necessary to reconstruct the entire target syntax tree, the generation efficiency of the target syntax tree can be improved.
The conversion unit 111 converts the target syntax tree to obtain a target code file.
In at least one embodiment of the present invention, the converting unit 111 converts the target syntax tree to obtain the target code file includes:
splitting the target syntax tree into a plurality of nodes;
parallel decompiling the nodes to obtain node codes corresponding to the nodes;
determining node positions of the plurality of nodes in the target syntax tree;
and splicing the node codes according to the node positions to obtain the target code file.
By splitting the target syntax tree into the plurality of nodes, the plurality of nodes can be decompiled in a parallel mode, and therefore the generation efficiency of the target code file can be improved.
In at least one embodiment of the present invention, after obtaining the target code file, the obtaining unit 110 obtains the request number of the transcoding request;
the generating unit 113 generates prompt information according to the request number and the target code file;
the encryption unit 114 encrypts the prompt message by using a symmetric encryption algorithm to obtain a ciphertext;
the sending unit 115 sends the ciphertext to the trigger terminal.
Through the implementation mode, the prompt message can be sent to the trigger terminal in time, and then a user is informed of receiving the target code file in time.
It can be seen from the above technical solutions that, when a code conversion request is received, the present invention can obtain a source code file according to the code conversion request, can accurately obtain a code file to be code converted through the code conversion request, convert the source code file into a source syntax tree, and obtain a conversion identifier in the source code file, obtain a conversion data structure from the source syntax tree according to the conversion identifier, obtain the conversion data structure from the source syntax tree, because each node code on the source syntax tree has a syntax structure, can quickly obtain the conversion data structure from the source syntax tree through the conversion identifier, determine a target type according to the code conversion request, and obtain a target data structure corresponding to the conversion data structure according to the target type, processing the source syntax tree according to the target data structure to obtain a target syntax tree, replacing the conversion data structure on the source syntax tree through the target data structure, and since the target syntax tree does not need to be reconstructed, rapidly generating the target syntax tree and converting the target syntax tree to obtain a target code file, the conversion data structure is determined, and then the conversion data structure is converted into the target data structure, so that the source syntax tree generated by the source code file is modified by using the target data structure, the target syntax tree can be obtained, and then the target syntax tree is converted, and a target code file corresponding to the target type can be generated. A bridge between the converted data result and the target data result can be established, and further the conversion of program codes with inconsistent names and types can be supported.
Fig. 4 is a schematic structural diagram of an electronic device implementing the program code conversion method according to the preferred embodiment of the present invention.
In one embodiment of the present invention, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and computer readable instructions, such as a program code conversion program, stored in the memory 12 and executable on the processor 13.
It will be appreciated by a person skilled in the art that the schematic diagram is only an example of the electronic device 1 and does not constitute a limitation of the electronic device 1, and that it may comprise more or less components than shown, or some components may be combined, or different components, e.g. the electronic device 1 may further comprise an input output device, a network access device, a bus, etc.
The Processor 13 may be a Central Processing Unit (CPU), other general purpose Processor, 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, etc. The processor 13 is an operation core and a control center of the electronic device 1, and is connected to each part of the whole electronic device 1 by various interfaces and lines, and executes an operating system of the electronic device 1 and various installed application programs, program codes, and the like.
Illustratively, the computer readable instructions may be partitioned into one or more modules/units that are stored in the memory 12 and executed by the processor 13 to implement the present invention. The one or more modules/units may be a series of computer readable instruction segments capable of performing specific functions, which are used for describing the execution process of the computer readable instructions in the electronic device 1. For example, the computer readable instructions may be divided into an acquisition unit 110, a conversion unit 111, a processing unit 112, a generation unit 113, an encryption unit 114, and a transmission unit 115.
The memory 12 may be used for storing the computer readable instructions and/or modules, and the processor 13 implements various functions of the electronic device 1 by executing or executing the computer readable instructions and/or modules stored in the memory 12 and invoking data stored in the memory 12. The memory 12 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to use of the electronic device, and the like. The memory 12 may include non-volatile and volatile memories, such as: a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other storage device.
The memory 12 may be an external memory and/or an internal memory of the electronic device 1. Further, the memory 12 may be a memory having a physical form, such as a memory stick, a TF Card (Trans-flash Card), or the like.
The integrated modules/units of the electronic device 1 may be stored in a computer-readable storage medium if they are implemented in the form of software functional units and sold or used as separate products. Based on such understanding, all or part of the flow of the method according to the above embodiments may be implemented by hardware that is configured to be instructed by computer readable instructions, which may be stored in a computer readable storage medium, and when the computer readable instructions are executed by a processor, the steps of the method embodiments may be implemented.
Wherein the computer readable instructions comprise computer readable instruction code which may be in source code form, object code form, an executable file or some intermediate form, and the like. The computer-readable medium may include: any entity or device capable of carrying said computer readable instruction code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM).
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
In conjunction with fig. 1, the memory 12 in the electronic device 1 stores computer readable instructions to implement a program code conversion method, and the processor 13 can execute the computer readable instructions to implement:
when a code conversion request is received, acquiring a source code file according to the code conversion request;
converting the source code file into a source syntax tree, and acquiring a conversion identifier in the source code file;
acquiring a conversion data structure from the source syntax tree according to the conversion identifier;
determining a target type according to the code conversion request, and acquiring a target data structure corresponding to the conversion data structure according to the target type;
processing the source syntax tree according to the target data structure to obtain a target syntax tree;
and converting the target syntax tree to obtain a target code file.
Specifically, the processor 13 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the computer readable instructions, which is not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The computer readable storage medium has computer readable instructions stored thereon, wherein the computer readable instructions when executed by the processor 13 are configured to implement the steps of:
when a code conversion request is received, acquiring a source code file according to the code conversion request;
converting the source code file into a source syntax tree, and acquiring a conversion identifier in the source code file;
acquiring a conversion data structure from the source syntax tree according to the conversion identifier;
determining a target type according to the code conversion request, and acquiring a target data structure corresponding to the conversion data structure according to the target type;
processing the source syntax tree according to the target data structure to obtain a target syntax tree;
and converting the target syntax tree to obtain a target code file.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. The plurality of units or devices may also be implemented by one unit or device through software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (10)

1. A program code conversion method, characterized in that the program code conversion method comprises:
when a code conversion request is received, acquiring a source code file according to the code conversion request;
converting the source code file into a source syntax tree, and acquiring a conversion identifier in the source code file;
acquiring a conversion data structure from the source syntax tree according to the conversion identifier;
determining a target type according to the code conversion request, and acquiring a target data structure corresponding to the conversion data structure according to the target type;
processing the source syntax tree according to the target data structure to obtain a target syntax tree;
and converting the target syntax tree to obtain a target code file.
2. The program code conversion method of claim 1, wherein said obtaining a source code file according to the code conversion request comprises:
analyzing the message of the code conversion request to obtain message information carried by the message;
acquiring a first preset label, wherein the first preset label is used for indicating a position;
acquiring information corresponding to the first preset label from the message information as a storage position;
determining a trigger terminal of the transcoding request;
and acquiring the information stored in the storage position from the trigger terminal as the source code file.
3. The program code conversion method of claim 2, wherein said determining a target type from said code conversion request comprises:
removing the storage position from the message information to obtain data information;
acquiring a second preset label, wherein the second preset label is used for indicating the type;
and acquiring information corresponding to the second preset label from the data information as the target type.
4. The program code conversion method of claim 1, wherein said converting the source code file into a source syntax tree comprises:
calling a preset function to read the source code file to obtain a plurality of characters;
comparing the characters with preset characters to obtain a plurality of mark sequences;
carrying out syntactic analysis on the plurality of marking sequences to obtain a plurality of code structures;
determining sequence positions of the plurality of marker sequences in the source code file;
and splicing the plurality of code structures according to the sequence positions to obtain the source syntax tree.
5. The program code conversion method of claim 1, wherein said obtaining a target data structure corresponding to the translation data structure according to the target type comprises:
determining a source type to which the source code file belongs;
determining a mapping table according to the source type and the target type;
acquiring a conversion field in the conversion data structure, and acquiring a target field corresponding to the conversion field from the mapping table;
and replacing the conversion field in the conversion data structure by using the target field to obtain the target data structure.
6. The program code conversion method of claim 1, wherein said processing said source syntax tree in accordance with said target data structure to obtain a target syntax tree comprises:
determining a structure position of the transformation data structure in the source syntax tree;
and writing the target data structure into the structure position to obtain the target syntax tree.
7. The program code conversion method of claim 1, wherein said converting said target syntax tree to obtain a target code file comprises:
splitting the target syntax tree into a plurality of nodes;
parallel decompiling the nodes to obtain node codes corresponding to the nodes;
determining node positions of the plurality of nodes in the target syntax tree;
and splicing the node codes according to the node positions to obtain the target code file.
8. A program code conversion apparatus, characterized in that the program code conversion apparatus comprises:
the system comprises an acquisition unit, a conversion unit and a conversion unit, wherein the acquisition unit is used for acquiring a source code file according to a code conversion request when the code conversion request is received;
the conversion unit is used for converting the source code file into a source syntax tree and acquiring a conversion identifier in the source code file;
the obtaining unit is further configured to obtain a conversion data structure from the source syntax tree according to the conversion identifier;
the obtaining unit is further configured to determine a target type according to the transcoding request, and obtain a target data structure corresponding to the converted data structure according to the target type;
the processing unit is used for processing the source syntax tree according to the target data structure to obtain a target syntax tree;
the conversion unit is further configured to convert the target syntax tree to obtain a target code file.
9. An electronic device, characterized in that the electronic device comprises:
a memory storing computer readable instructions; and
a processor executing computer readable instructions stored in the memory to implement the program code conversion method of any of claims 1 to 7.
10. A computer-readable storage medium characterized by: the computer readable storage medium has stored therein computer readable instructions which are executed by a processor in an electronic device to implement the program code conversion method according to any one of claims 1 to 7.
CN202011540127.4A 2020-12-23 2020-12-23 Program code conversion method and related device Pending CN112667240A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011540127.4A CN112667240A (en) 2020-12-23 2020-12-23 Program code conversion method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011540127.4A CN112667240A (en) 2020-12-23 2020-12-23 Program code conversion method and related device

Publications (1)

Publication Number Publication Date
CN112667240A true CN112667240A (en) 2021-04-16

Family

ID=75408913

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011540127.4A Pending CN112667240A (en) 2020-12-23 2020-12-23 Program code conversion method and related device

Country Status (1)

Country Link
CN (1) CN112667240A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113050953A (en) * 2021-04-21 2021-06-29 平安普惠企业管理有限公司 Method, device and storage medium for generating code based on annotation
CN113076108A (en) * 2021-06-04 2021-07-06 华控清交信息科技(北京)有限公司 Code execution method and device for code execution
CN113110847A (en) * 2021-04-29 2021-07-13 杭州以诺行汽车科技股份有限公司 Program code conversion processing method and system
CN113268243A (en) * 2021-05-11 2021-08-17 网易(杭州)网络有限公司 Memory prediction method and device, storage medium and electronic equipment
CN113791838A (en) * 2021-08-20 2021-12-14 深圳市元征科技股份有限公司 Program file calling method and device and storage medium
WO2023097750A1 (en) * 2021-11-30 2023-06-08 同程网络科技股份有限公司 Order booking method based on cross-terminal program generation system
CN116360797A (en) * 2023-06-02 2023-06-30 北京长亭科技有限公司 DSL-based security baseline creation method, system, device and medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140047538A1 (en) * 2012-08-08 2014-02-13 Coverity, Inc. Static tainting anasystem and method for taint analysis of computer program codelysis
CN106293677A (en) * 2015-06-08 2017-01-04 阿里巴巴集团控股有限公司 A kind of code conversion method and device
CN108182069A (en) * 2017-12-28 2018-06-19 深圳市创梦天地科技股份有限公司 Programming language transformation method, terminal device and computer-readable medium
CN108664546A (en) * 2018-03-26 2018-10-16 武汉船舶通信研究所(中国船舶重工集团公司第七二二研究所) Xml data structure conversion method and device
CN109933331A (en) * 2019-03-07 2019-06-25 杭州时趣信息技术有限公司 Data transfer device and associated component between a kind of client-server
CN110109681A (en) * 2019-05-08 2019-08-09 上海携程商务有限公司 The conversion method and system of code between different platform
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN111045678A (en) * 2019-11-06 2020-04-21 北京奇艺世纪科技有限公司 Method, device and equipment for executing dynamic code on page and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140047538A1 (en) * 2012-08-08 2014-02-13 Coverity, Inc. Static tainting anasystem and method for taint analysis of computer program codelysis
CN106293677A (en) * 2015-06-08 2017-01-04 阿里巴巴集团控股有限公司 A kind of code conversion method and device
CN108182069A (en) * 2017-12-28 2018-06-19 深圳市创梦天地科技股份有限公司 Programming language transformation method, terminal device and computer-readable medium
CN108664546A (en) * 2018-03-26 2018-10-16 武汉船舶通信研究所(中国船舶重工集团公司第七二二研究所) Xml data structure conversion method and device
CN109933331A (en) * 2019-03-07 2019-06-25 杭州时趣信息技术有限公司 Data transfer device and associated component between a kind of client-server
CN110109681A (en) * 2019-05-08 2019-08-09 上海携程商务有限公司 The conversion method and system of code between different platform
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN111045678A (en) * 2019-11-06 2020-04-21 北京奇艺世纪科技有限公司 Method, device and equipment for executing dynamic code on page and storage medium

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113050953A (en) * 2021-04-21 2021-06-29 平安普惠企业管理有限公司 Method, device and storage medium for generating code based on annotation
CN113110847A (en) * 2021-04-29 2021-07-13 杭州以诺行汽车科技股份有限公司 Program code conversion processing method and system
CN113110847B (en) * 2021-04-29 2024-02-13 杭州以诺行汽车科技股份有限公司 Conversion processing method and system for program codes
CN113268243A (en) * 2021-05-11 2021-08-17 网易(杭州)网络有限公司 Memory prediction method and device, storage medium and electronic equipment
CN113268243B (en) * 2021-05-11 2024-02-23 网易(杭州)网络有限公司 Memory prediction method and device, storage medium and electronic equipment
CN113076108A (en) * 2021-06-04 2021-07-06 华控清交信息科技(北京)有限公司 Code execution method and device for code execution
CN113791838A (en) * 2021-08-20 2021-12-14 深圳市元征科技股份有限公司 Program file calling method and device and storage medium
CN113791838B (en) * 2021-08-20 2024-04-23 深圳市元征科技股份有限公司 Program file calling method, device and storage medium
WO2023097750A1 (en) * 2021-11-30 2023-06-08 同程网络科技股份有限公司 Order booking method based on cross-terminal program generation system
CN116360797A (en) * 2023-06-02 2023-06-30 北京长亭科技有限公司 DSL-based security baseline creation method, system, device and medium
CN116360797B (en) * 2023-06-02 2023-10-27 北京长亭科技有限公司 DSL-based security baseline creation method, system, device and medium

Similar Documents

Publication Publication Date Title
CN112667240A (en) Program code conversion method and related device
CN111694840A (en) Data synchronization method, device, server and storage medium
CN111797351A (en) Page data management method and device, electronic equipment and medium
CN112433705A (en) Script generation method and device, electronic equipment and storage medium
CN111796809A (en) Interface document generation method and device, electronic equipment and medium
CN112948418A (en) Dynamic query method, device, equipment and storage medium
CN113283675B (en) Index data analysis method, device, equipment and storage medium
CN114035827A (en) Application program updating method, device, equipment and storage medium
CN111679975A (en) Document generation method and device, electronic equipment and medium
CN112711398A (en) Method, device and equipment for generating buried point file and storage medium
CN113536770B (en) Text analysis method, device and equipment based on artificial intelligence and storage medium
CN112947911A (en) Interface script generation method, device, equipment and storage medium
CN113918467A (en) Financial system testing method, device, equipment and storage medium
CN114116108A (en) Dynamic rendering method, device, equipment and storage medium
CN112181485B (en) Script execution method and device, electronic equipment and storage medium
CN112434062A (en) Quasi-real-time data processing method, device, server and storage medium
CN112187783A (en) Authentication method and device, electronic equipment and storage medium
CN112738175B (en) Request processing method and related equipment
CN113283677B (en) Index data processing method, device, equipment and storage medium
CN115794621A (en) Code coverage test method, device, equipment and storage medium
CN115952201A (en) Data query method, device, system and storage medium
CN113515444B (en) Test case generation method, device, computer equipment and storage medium
JP2007241461A (en) Data management device, data management method and recording medium with data management program recorded thereon
CN114360732A (en) Medical data analysis method and device, electronic equipment and storage medium
CN112685253A (en) Front-end error log collection method, device, 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