Transcoding method, apparatus, device, and storage medium

CN116954609BActive Publication Date: 2026-10-30CHINA MERCHANTS BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310947207.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-28
Publication Date
2026-10-30
Estimated Expiration
2043-07-28

AI Technical Summary

Benefits of technology

[0035]本发明公开了一种代码转换方法、装置、设备及存储介质,该方法包括:基于用户输入的目标转译路径生成对应的路径获取请求发送至待转换数据库,待转换数据库在接收路径获取请求后,反馈与路径获取请求对应的对象清单;对接收的对象清单进行遍历解析,获得各待处理对象对应的待处理源码;根据各待处理源码的文件类型,将各待处理源码转换为对应的目标代码。本发明可根据目标转译路径从待转换数据库中批量获取待处理源码,再根据各待处理源码的文件类型自动将待处理源码批量转换为目标代码,从而避免出现代码转换错误和遗漏的情况,提高代码转换的准确率。因此,本发明可以字节流的形式从待转换数据库中逐项获取待处理源码,并根据各待处理源码的文件类型对其中的代码行进行自动的代码逐行解析和代码逐行转换,同时相较于现有的人工代码转换方法,本发明的代码转换耗时减少,因此提高了代码转换效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116954609B_ABST
    Figure CN116954609B_ABST
Patent Text Reader

Abstract

The application discloses a code conversion method, device and equipment and a storage medium, and the method comprises the following steps: based on a target translation path input by a user, a corresponding path acquisition request is generated and sent to a database to be converted; after receiving the path acquisition request, the database to be converted feeds back an object list corresponding to the path acquisition request; the received object list is parsed iteratively to obtain source codes to be processed corresponding to each object to be processed; and according to the file types of the source codes to be processed, the source codes to be processed are converted into corresponding target codes. According to the application, the source codes to be processed can be batched and acquired from the database to be converted according to the target translation path, and then the source codes to be processed are automatically batched and converted into the target codes according to the file types of the source codes to be processed, so that the code conversion errors and omissions can be avoided, and the accuracy of the code conversion is improved. Compared with the existing manual code conversion method, the code conversion time of the application is reduced, and therefore the code conversion efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electronic digital data processing technology, and in particular to a code conversion method, apparatus, device, and storage medium. Background Technology

[0002] Currently, some companies' core business operations can be carried out using IBM's AS400 system. However, the AS400 system has drawbacks such as being difficult to understand, deploy, scale, and innovate, which is detrimental to business development. Therefore, companies are increasingly focusing on transforming their core business systems from AS400 systems to development platforms.

[0003] However, the current migration process of manually converting the code logic in the AS400 system into target code such as Java pseudocode (or source code) is prone to risks such as errors in code understanding and omissions, resulting in low accuracy. Furthermore, the manual code conversion process is time-consuming and inefficient. Therefore, there is an urgent need for a fast and accurate code conversion method to transform the code logic in the AS400 system into target code.

[0004] The above content is only used to help understand the technical solution of the present invention and does not represent an admission that the above content is prior art. Summary of the Invention

[0005] The main objective of this invention is to provide a code conversion method, apparatus, device, and storage medium, aiming to solve the technical problems of low efficiency and low accuracy in existing methods for converting code logic in AS400 systems into target code.

[0006] To achieve the above objectives, the present invention provides a code conversion method, the method comprising:

[0007] Based on the target translation path input by the user, a corresponding path acquisition request is generated and sent to the database to be converted. After receiving the path acquisition request, the database to be converted returns a list of objects corresponding to the path acquisition request.

[0008] The received list of objects is traversed and parsed to obtain the source code to be processed for each object.

[0009] Based on the file type of each source code to be processed, the source code to be processed is converted into the corresponding target code.

[0010] Optionally, the step of traversing and parsing the received list of objects to obtain the source code to be processed corresponding to each object includes:

[0011] The received list of objects is traversed and parsed to obtain the paths and names of all objects to be processed;

[0012] Based on the path and name of each object to be processed, a corresponding object retrieval request is generated and sent to the database to be converted. After receiving the object retrieval request, the database to be converted returns the source code to be processed corresponding to the object retrieval request in the form of a byte stream.

[0013] Receive the source code to be processed corresponding to each of the objects to be processed.

[0014] Optionally, the target code includes: an entity, and the step of converting each source code to be processed into the corresponding target code according to the file type of each source code to be processed includes:

[0015] When the file type of the source code to be processed is a PF file, determine whether the source code to be processed is a file;

[0016] If so, the source code to be processed will be converted into an entity.

[0017] Optionally, the target code includes: a data transfer object; and when the file type of the source code to be processed is the PF file, after determining whether the source code to be processed is a file, it further includes:

[0018] If not, the source code to be processed will be converted into a data transfer object.

[0019] Optionally, the target code includes: an index; the step of converting each source code to be processed into corresponding target code according to the file type of each source code to be processed further includes:

[0020] When the file type of the source code to be processed is an LF file, the source code to be processed is converted into an index.

[0021] Optionally, the target code includes: JAVA pseudocode; the step of converting each source code to be processed into the corresponding target code according to the file type of each source code to be processed further includes:

[0022] When the file type of the source code to be processed is an RPGLE program, the source code to be processed is traversed to obtain the function type and target code set of each line of code in the source code to be processed.

[0023] The target subroutine code line in the source code to be processed is determined according to the function type, and the source code to be processed is replaced according to the target code set and the target subroutine code line to obtain intermediate source code;

[0024] Based on the function type and preset mapping relationship, the intermediate source code is replaced with keywords to obtain the corresponding JAVA pseudocode.

[0025] Optionally, the step of traversing the source code to obtain the function type and target code set of each line of code in the source code when the file type of the source code to be processed is an RPGLE program includes:

[0026] When the file type of the source code to be processed is an RPGLE program, the function type of each line of code is obtained according to the header code of each line of code in the source code to be processed;

[0027] When the function type of any line of code is a preset subroutine type, obtain the code fragment corresponding to the line of code of the preset subroutine type;

[0028] All the acquired code snippets are combined into a target code set.

[0029] Furthermore, to achieve the above objectives, the present invention also proposes a code conversion device, the code conversion device comprising:

[0030] The list acquisition module is used to generate a corresponding path acquisition request based on the target translation path input by the user and send it to the database to be converted. After receiving the path acquisition request, the database to be converted will return a list of objects corresponding to the path acquisition request.

[0031] The source code acquisition module is used to traverse and parse the received list of objects to obtain the source code to be processed corresponding to each object to be processed.

[0032] The code conversion module is used to convert each source code to be processed into the corresponding target code according to the file type of each source code to be processed.

[0033] Furthermore, to achieve the above objectives, the present invention also proposes a code conversion device, the device comprising: a memory, a processor, and a code conversion program stored in the memory and executable on the processor, the code conversion program being configured to implement the steps of the code conversion method described above.

[0034] In addition, to achieve the above objectives, the present invention also proposes a storage medium storing a code conversion program, which, when executed by a processor, implements the steps of the code conversion method described above.

[0035] This invention discloses a code conversion method, apparatus, device, and storage medium. The method includes: generating a corresponding path acquisition request based on a target translation path input by a user and sending it to a database to be converted; the database, upon receiving the path acquisition request, returns a list of objects corresponding to the path acquisition request; traversing and parsing the received object list to obtain the source code to be processed corresponding to each object; and converting each source code to be processed into the corresponding target code according to the file type of each source code. This invention can batch acquire source code to be processed from the database according to the target translation path, and then automatically convert the source code to be processed into target code according to the file type of each source code, thereby avoiding code conversion errors and omissions and improving the accuracy of code conversion. Therefore, this invention can acquire source code to be processed item by item from the database in the form of a byte stream, and automatically parse and convert the code line by line according to the file type of each source code. Furthermore, compared with existing manual code conversion methods, the code conversion time of this invention is reduced, thus improving code conversion efficiency. Attached Figure Description

[0036] Figure 1 This is a schematic diagram of the structure of the code conversion device for the hardware operating environment involved in the embodiments of the present invention;

[0037] Figure 2 This is a schematic diagram of the first process of the first embodiment of the code conversion method of the present invention;

[0038] Figure 3 This is a schematic diagram of the second process of the first embodiment of the code conversion method of the present invention;

[0039] Figure 4 This is a schematic diagram of code transmission in the first embodiment of the code conversion method of the present invention;

[0040] Figure 5 This is a schematic diagram of the first process of the second embodiment of the code conversion method of the present invention;

[0041] Figure 6 This is a schematic diagram of the interface or field mapping of the second embodiment of the code conversion method of the present invention;

[0042] Figure 7 This is a schematic diagram of the second process of the second embodiment of the code conversion method of the present invention;

[0043] Figure 8 This is a structural block diagram of the first embodiment of the code conversion device of the present invention.

[0044] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0045] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0046] Reference Figure 1 , Figure 1 This is a schematic diagram of the code conversion device structure of the hardware operating environment involved in the embodiments of the present invention.

[0047] like Figure 1 As shown, the code conversion device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wireless-Fidelity (Wi-Fi) interface). The memory 1005 may be high-speed random access memory (RAM) or stable non-volatile memory (NVM), such as a disk drive. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001.

[0048] Those skilled in the art will understand that Figure 1 The structure shown does not constitute a limitation on the code conversion device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0049] like Figure 1 As shown, the memory 1005, which serves as a storage medium, may include an operating system, a data storage module, a network communication module, a user interface module, and a code conversion program.

[0050] exist Figure 1 In the code conversion device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the code conversion device of the present invention can be set in the code conversion device, and the code conversion device calls the code conversion program stored in the memory 1005 through the processor 1001 and executes the code conversion method provided in the embodiment of the present invention.

[0051] This invention provides a code conversion method, referring to... Figure 2 , Figure 2 This is a schematic diagram of the first process of the first embodiment of the code conversion method of the present invention.

[0052] In this embodiment, the code conversion method includes the following steps:

[0053] Step S10: Generate a corresponding path acquisition request based on the target translation path input by the user and send it to the database to be converted. After receiving the path acquisition request, the database to be converted will return a list of objects corresponding to the path acquisition request.

[0054] It should be noted that the executing entity of the method in this embodiment can be a computing service device with data processing, data communication, program execution, and code conversion functions, such as a tablet computer or personal computer, or other electronic devices capable of performing the same or similar functions. Here, the code conversion device (hereinafter referred to as the conversion device) is used to specifically describe the code conversion methods provided in this embodiment and the following embodiments.

[0055] It is understood that this embodiment requires converting the RPGLE language of the AS400 system into pseudocode or source code in Java (which may include the Spring Boot framework or the Mybatis framework). Each line of RPGLE language code is formatted according to a specified format. Specifically, if the first character is 'C', it indicates a code line; otherwise, it indicates text without logical meaning. The second character is '*', indicating a comment line, and a space indicates a non-comment line. Characters 7-20 represent FACTOR1 (parameter 1), the meaning of which depends on the keywords of Opcode & Ext (opcode and extended content) in characters 21-30. That is, each line of RPGLE language code can be composed of: code line / no logic + comment line / non-comment line + parameter + keyword. Based on this, this embodiment can read the RPGLE language in the AS400 system via byte stream and parse the obtained RPGLE language code line by line. By combining this with a stack data structure, automatic code translation can be achieved.

[0056] It is important to understand that the database to be converted can be the AS400 system to which the code is to be converted. Before the code conversion, the conversion device needs to connect to the AS400 system's server, which can be via TCP communication. Then, it obtains the source code of each code to be converted, specifically through the target translation path mentioned above. This target translation path can be the code library path corresponding to the code to be converted, such as the VBSISN library path, or the ISILCPGMFILE under the VBSISN library. After receiving the path acquisition request, the AS400 system can obtain the content of the corresponding Member. In the AS400 system, a Member can be a collection of records of a specific type. That is, when a PF is opened with a specified Member, only the record data belonging to that Member will be seen. Therefore, this embodiment can utilize this feature to obtain only the objects to be processed under the corresponding Member, such as tables, programs, or commands, based on the path acquisition request in the AS400 system, and generate a corresponding object list based on all the objects to be processed.

[0057] Step S20: Iterate and parse the received object list to obtain the source code to be processed corresponding to each object to be processed;

[0058] It is easy to understand that in this embodiment, the conversion device can obtain the above-mentioned object list through a pre-written integrated output interface program module. The object list only contains the names of each object to be processed, and does not contain the code of each object. Therefore, this embodiment can traverse and parse the above-mentioned object list to obtain the source code corresponding to each object to be processed item by item.

[0059] Furthermore, as one possible implementation method, such as Figure 3 As shown, Figure 3 This is a second flowchart illustrating the first embodiment of the code conversion method of the present invention. In this embodiment, step S20 includes:

[0060] Step S201: Iterate through and parse the received object list to obtain the paths and names of all objects to be processed;

[0061] Step S202: Generate corresponding object retrieval requests based on the path and name of each object to be processed and send them to the database to be converted. After receiving the object retrieval request, the database to be converted returns the source code to be processed corresponding to the object retrieval request in the form of a byte stream.

[0062] Step S203: Receive the source code to be processed corresponding to each object to be processed.

[0063] It should be noted that this embodiment can traverse and parse the above object list to obtain each object to be processed and its corresponding code path, thereby obtaining the RPGLE format source code under each code path from the AS400 system. Specifically, this embodiment can generate a corresponding object acquisition request based on the path and name of each object to be processed and send it to the AS400 system. After receiving the object acquisition request, the AS400 system can return the source code to be processed corresponding to the object acquisition request in the form of a byte stream. The conversion device can receive the source code to be processed output by the AS400 system through the above-mentioned output interface program module. Each output can represent a line of RPGLE format code. This embodiment can summarize all the output interfaces corresponding to an object acquisition request to obtain the RPGLE format source code file related to an object to be processed, that is, the source code to be processed corresponding to each of the above-mentioned objects to be processed.

[0064] Step S30: Based on the file type of each source code to be processed, convert each source code to be processed into the corresponding target code.

[0065] It should be noted that the file types of the source code to be processed mentioned above may include: PF files, LF files and / or RPGLE programs. Therefore, this embodiment can convert each source code to be processed into the corresponding target code according to the file type of each source code. In this embodiment, the target code can be JAVA-style source code or pseudo-code, thereby batch converting the code of the AS400 source code library into JAVA pseudo-code item by item, avoiding code conversion errors and omissions, and improving the accuracy of code conversion.

[0066] It is understood that the target code obtained after file type identification is as close as possible to Java-style code. However, to ensure the accuracy of the final code, in this embodiment, after converting each source code to be processed into the corresponding target code, the relevant developers can fine-tune the target code. Compared with existing code conversion methods, this application only requires a small number of personnel familiar with AS400 / RPGLE development during the migration of the core system using a code conversion device. Therefore, the code conversion time in this embodiment is reduced, thereby improving the code conversion efficiency.

[0067] It should be understood that the conversion device in this embodiment can be applied to the conversion of other AS400 / RPGLE programs, and can also be extended to other programming languages ​​and platforms besides JAVA. The specific type of the target code mentioned above is not limited in this embodiment.

[0068] In practical applications, such as Figure 4 As shown, Figure 4This is a schematic diagram of code transmission in the first embodiment of the code conversion method of the present invention. In this embodiment, the code conversion device generates a corresponding path retrieval request after receiving the target translation path input by the user, and sends it to the AS400 system via TCP communication. Upon receiving the path retrieval request, the AS400 system finds the corresponding code database path and returns a list of all objects corresponding to the path retrieval request. After receiving the object list, the code conversion device traverses and parses the received object list to obtain each object to be processed, and then translates each object one by one. Specifically, in this embodiment, a corresponding object retrieval request is generated based on the path and name of the object to be processed and sent to the AS400 system via TCP communication. Upon receiving the object retrieval request, the AS400 system finds the corresponding code path based on the name of the object to be processed and returns the source code to be processed corresponding to the object retrieval request in the form of a byte stream. After receiving the source code to be processed, the code conversion device converts each source code to be processed into the corresponding target code according to the file type of each source code. Finally, the conversion is complete when the code conversion device detects that there are no unprocessed objects to be processed, and it stops retrieving objects from the AS400 system.

[0069] This embodiment discloses a code conversion method, which includes: generating a corresponding path acquisition request based on the target translation path input by the user and sending it to the database to be converted; the database to be converted, upon receiving the path acquisition request, returns a list of objects corresponding to the path acquisition request; traversing and parsing the received object list to obtain the paths and names of all objects to be processed; generating corresponding object acquisition requests based on the paths and names of each object to be processed and sending them to the database to be converted; the database to be converted, upon receiving the object acquisition request, returns the source code to be processed corresponding to the object acquisition request in the form of a byte stream; receiving the source code to be processed corresponding to each object to be processed; and converting each source code to be processed into the corresponding target code according to the file type of each source code to be processed. Therefore, compared with existing code conversion methods, this embodiment can batch acquire source code to be processed from the database to be converted, i.e., the AS400 system, according to the target translation path, and then automatically convert the source code to be processed into target code in batches according to the file type of each source code to be processed. Therefore, this embodiment can retrieve the source code to be processed item by item from the database in the form of a byte stream, and automatically parse and convert the code line by line according to the file type of each source code, avoiding code conversion errors and omissions, and improving the accuracy of code conversion. At the same time, compared with existing manual code conversion methods, the code conversion time of this embodiment is reduced, thus improving the code conversion efficiency.

[0070] Reference Figure 5 , Figure 5 This is a flowchart illustrating the second embodiment of the code conversion method of the present invention, based on the above. Figure 2 The illustrated embodiment presents a second embodiment of the code conversion method of the present invention.

[0071] It is important to understand that in this embodiment, the conversion device can directly convert various objects to be processed under the target translation path, such as interfaces, files, and / or executable programs, into corresponding Data Transfer Objects (DTOs), Entities, and Java-based pseudocode according to preset conversion logic and relationships. Specifically, in the AS400 system, the naming convention for interfaces is: 2-digit system code + 3-digit product code + 3-digit business module + 2-digit suffix, which can be mapped to Java Data Transfer Objects. The first digit of the 2-digit suffix indicates an input interface if it is X, a bidirectional interface if it is Y, and an output interface if it is Z. The naming convention for files is: 2-digit system code + 3-digit product code + 3-digit business meaning + P, which can be mapped to Java Entities. The naming convention for executable programs is: 2-digit system code + 3-digit product code + 3-digit business module + RP, which can be mapped to Java pseudocode.

[0072] It should be understood that in this embodiment, the field or interface mapping relationship between the conversion device and the AS400 system can be pre-configured before determining the file type of the source code to be processed. For ease of understanding, let's take... Figure 6 The following example illustrates this. Figure 6 This is a schematic diagram of the interface or field mapping of the second embodiment of the code conversion method of the present invention, such as... Figure 6 As shown, the ISILCMSTP data interface of the AS400 system can be mapped to IMPORT_LETTER_CREDIT_T in JAVA; the LCM_ILC_NBR field of the AS400 system can be mapped to BIZ_NO in JAVA, etc., so as to facilitate subsequent interface conversion or variable conversion in executable programs.

[0073] Furthermore, as one possible implementation, the target code includes: an entity, the target code includes: a data transfer object, such as... Figure 5 As shown, in this embodiment, step S30 may include:

[0074] Step S301: When the file type of the source code to be processed is a PF file, determine whether the source code to be processed is a file;

[0075] Step S302: If so, convert the source code to be processed into an entity.

[0076] Step S303: If not, convert the source code to be processed into a data transfer object.

[0077] It should be noted that the aforementioned PF file (Physical File) is a special file of AS400. In this embodiment, when the file type of the source code to be processed is detected as a PF file, this embodiment can first determine whether the actual type of the obtained PF file is a file or an interface. Specifically, it can be identified according to the ninth digit of the naming convention. If the ninth digit is P, it is a file; if it is XYZ, it is an interface. After determining the actual type of the PF file, if it is a file, it can be converted into an entity; if it is an interface, it can be converted into a data transfer object, and then further code conversion is performed according to the conversion logic corresponding to the PF file.

[0078] It's important to understand that the processing logic for the PF file in this embodiment can be as follows: First, iterate through all source code to exclude useless lines and retain only valid lines. Specifically, if a line of code in the byte stream has an asterisk (*) or a space in its 7th position, it represents a comment line and can be excluded, retaining only valid lines where the 7th position is 'A'. Then, in this embodiment, iterate through the remaining source code a second time. If the 8th to 46th positions of a line of code are spaces and the 47th position onwards is 'REF', it indicates that the line of code references an external file, which can function as a data dictionary. If the 18th position of a line of code is 'R', it represents a defined data format name, and the corresponding 20th to 29th positions represent the data format name in the corresponding code of this file. If the 18th position of a line of code is a space, the corresponding 20th to 29th positions represent fields defined in the current PF file. In this case, the content of the current line number and the following consecutive lines with empty positions (8th to 46th positions) needs to be concatenated together, indicating that this field references multiple RPGLE FUNCTIONS keywords.

[0079] Understandably, if the 18th bit of the code line is a space, further analysis is needed. If the 30th bit of the code line is R, it means that the field definition references an external file. In this case, it is necessary to find the content starting from the 46th bit of the code line, find the keyword REFFLD, and identify the content referenced in the subsequent parentheses. Then, based on the application content, find the corresponding field definition in the code line where the data dictionary exists and set it as the attribute of the current field. If the 30th bit of the byte stream is empty, it means that the code line is a custom field. The length of the field can be represented by bits 31-35, the field type can be represented by bit 36 ​​(A: only single-byte characters are allowed; O: double-byte characters such as Chinese are allowed; S, P represent numeric types, etc.), and the decimal places can be represented by bits 37-38.

[0080] Furthermore, as one possible implementation method, such as Figure 5 As shown, in this embodiment, the target code includes: an index; step S30 further includes:

[0081] Step S311: When the file type of the source code to be processed is an LF file, the source code to be processed is converted into an index.

[0082] It is important to understand that when the source code to be processed is an LF file, it can be directly converted into an index by the relevant developers.

[0083] Furthermore, as one possible implementation method, such as Figure 5 As shown, in this embodiment, the target code includes: JAVA pseudocode; step S30 further includes:

[0084] Step S321: When the file type of the source code to be processed is an RPGLE program, the source code to be processed is traversed to obtain the function type and target code set of each line of code in the source code to be processed;

[0085] It's important to understand that RPGLE programs can be the aforementioned executable programs. Because RPGLE programs contain many keywords and numerous subroutines (code blocks similar to internal functions of an open platform), processing them can be quite complex. Therefore, this embodiment requires multiple traversals of a source file of type RPGLE program to achieve efficient code conversion.

[0086] Furthermore, as one possible implementation method, such as Figure 7 As shown, Figure 7 This is a schematic diagram of the fourth process of the second embodiment of the code conversion method of the present invention. In this embodiment, step S321 includes:

[0087] Step S3211: When the file type of the source code to be processed is an RPGLE program, obtain the function type of each line of code according to the header code of each line of code in the source code to be processed;

[0088] Step S3212: When the function type of any line of code is a preset subroutine type, obtain the code segment corresponding to the line of code of the preset subroutine type;

[0089] Step S3213: Combine all the acquired code snippets into a target code set.

[0090] It should be noted that each source file in an RPGLE program can contain many subroutines. In this embodiment, the source code to be processed can be traversed three times to achieve the final code conversion. During the first traversal, the conversion device can obtain the function type of each line of code based on the header code of each line and perform preliminary code conversion. The function type can include: temporary type, interface definition, file definition, subroutine and / or external subroutine call. The subroutine and / or external subroutine are the aforementioned preset subroutine types. The purpose of the first traversal is to identify constants, variables, definitions and / or functions in the RPGLE program and establish mapping relationships. Specifically, during the first pass, if a line of code is identified where the first character is F and the second character is not *, it indicates that the function type of this line of code is a file definition, and the conversion device can identify the entities involved in the current line of code. If a line of code starting with D followed by a space is identified, it indicates that this line of code is a temporary variable or temporary object, and its function type is temporary. The conversion device can preprocess this line of code by placing the identified temporary variable or temporary object at the beginning of the line of code to improve readability and increase the speed of subsequent code conversion. If a line of code starting with CSR is identified, it indicates that this line of code is a subroutine. For this type of line of code, this embodiment can also extract and parse it to obtain all the code fragments of the corresponding current subroutine. If a line of code starting with D / DEFINE is identified, it indicates that an external function has been introduced, and an external function library needs to be established to perform a mapping call conversion on subsequent lines of code. The function type of this line of code is an external subroutine call, and its corresponding external subroutine needs to be extracted and parsed to obtain all the code fragments of the corresponding external subroutine.

[0091] It is understood that, in this embodiment, the target code set described above can be constructed based on all code fragments of the current subroutine and all code fragments of the external subroutine, as well as the names of each current subroutine and external subroutine.

[0092] Step S322: Determine the target subroutine code line in the source code to be processed according to the function type, and perform code replacement on the source code to be processed according to the target code set and the target subroutine code line to obtain intermediate source code;

[0093] It is important to understand that this embodiment can perform a second traversal after the first traversal, and parse the program code fragments replaced in the first traversal line by line. The program code fragments replaced in the first traversal are generally a collection of multiple subroutines. At this time, the code lines containing subroutines or code lines that are called by external subroutines obtained in the first traversal, i.e., the target subroutines, can be replaced according to the target code set, thereby parsing the source code to be processed into a set of source code without subroutines, i.e., the intermediate source code.

[0094] Step S323: Based on the function type and preset mapping relationship, perform keyword replacement on the intermediate source code to obtain the corresponding JAVA pseudocode.

[0095] It should be noted that after obtaining the intermediate source code based on the second traversal, this embodiment can perform a third traversal and convert the intermediate source code line by line using keywords to obtain the final Java pseudocode. In practical applications, if the keyword encountered during traversal is EVAL, it indicates assignment logic. If it operates on file fields, it is directly translated into object assignment logic in BUILDER mode; if it assigns a value to a temporary variable, it is directly assigned. If the keyword encountered during traversal is SELECT, it indicates that the subsequent code is an IF-ELSE-IF-ELSE relationship, and the code in the SELECT and subsequent ENDSL keywords is translated. It should be understood that there may be nested SELECT statements within SELECTL, so we need to use the principle of stacks to convert these lines of code. During the conversion, attention should also be paid to the indentation of the code lines to maintain code cleanliness. The same applies to keywords such as IF / WHILE.

[0096] In this embodiment, when the file type of the source code to be processed is a PF file, it is determined whether the source code to be processed is a file; if yes, the source code to be processed is converted into an entity; if no, the source code to be processed is converted into a data transfer object. When the file type of the source code to be processed is an LF file, the source code to be processed is converted into an index. When the file type of the source code to be processed is an RPGLE program, the function type of each line of code is obtained according to the header code of each line of code in the source code to be processed; when the function type of any line of code is a preset subroutine type, the code fragment corresponding to the line of code of the preset subroutine type is obtained; all the obtained code fragments are combined into a target code set; the target subroutine code line in the source code to be processed is determined according to the function type, and the source code to be processed is replaced according to the target code set and the target subroutine code line to obtain intermediate source code; the intermediate source code is replaced with keywords based on the function type and the preset mapping relationship to obtain the corresponding JAVA pseudocode. This embodiment can batch convert source code in the database to be processed into JAVA pseudocode based on the file type of the source code to be processed. That is, this embodiment can perform program translation based on the original functional logic of the source code to be processed, and realize code conversion without affecting the functional logic of the source code to be processed.

[0097] Furthermore, embodiments of the present invention also propose a storage medium storing a code conversion program, wherein when the code conversion program is executed by a processor, it implements the steps of the code conversion method described above.

[0098] refer to Figure 8 , Figure 8 This is a structural block diagram of the first embodiment of the code conversion device of the present invention.

[0099] like Figure 8 As shown, the code conversion device proposed in this embodiment of the invention includes:

[0100] The list acquisition module 801 is used to generate a corresponding path acquisition request based on the target translation path input by the user and send it to the database to be converted. After receiving the path acquisition request, the database to be converted will return a list of objects corresponding to the path acquisition request.

[0101] The source code acquisition module 802 is used to traverse and parse the received object list to obtain the source code to be processed corresponding to each object to be processed.

[0102] The code conversion module 803 is used to convert each source code to be processed into the corresponding target code according to the file type of each source code to be processed.

[0103] Furthermore, as one possible implementation, the source code acquisition module 802 is also used to traverse and parse the received object list to obtain the paths and names of all objects to be processed;

[0104] The source code acquisition module 802 is also used to generate corresponding object acquisition requests based on the path and name of each object to be processed and send them to the database to be converted. After receiving the object acquisition request, the database to be converted feeds back the source code to be processed corresponding to the object acquisition request in the form of a byte stream.

[0105] The source code acquisition module 802 is also used to receive the source code to be processed corresponding to each object to be processed.

[0106] This embodiment generates a path retrieval request based on the user-input target translation path and sends it to the database to be converted. Upon receiving the path retrieval request, the database returns a list of objects corresponding to the path retrieval request. The received object list is traversed and parsed to obtain the paths and names of all objects to be processed. Based on the path and name of each object to be processed, a corresponding object retrieval request is generated and sent to the database to be converted. Upon receiving the object retrieval request, the database returns the source code to be processed corresponding to the object retrieval request in byte stream form. The database receives the source code corresponding to each object to be processed. Based on the file type of each source code, it converts each source code to be processed into the corresponding target code. Therefore, compared to existing code conversion methods, this embodiment can batch retrieve source code to be processed from the database to be converted (i.e., the AS400 system) based on the target translation path, and then automatically convert the source code to be processed into target code in batches based on the file type of each source code. Therefore, this embodiment can retrieve the source code to be processed item by item from the database in the form of a byte stream, and automatically parse and convert the code line by line according to the file type of each source code, avoiding code conversion errors and omissions, and improving the accuracy of code conversion. At the same time, compared with existing manual code conversion methods, the code conversion time of this embodiment is reduced, thus improving the code conversion efficiency.

[0107] Based on the first embodiment of the code conversion device of the present invention described above, a second embodiment of the code conversion device of the present invention is proposed.

[0108] In this embodiment, as one possible implementation, the code conversion module 803 is further configured to determine whether the source code to be processed is a file when the file type of the source code to be processed is a PF file;

[0109] The code conversion module 803 is further configured to convert the source code to be processed into an entity if the condition is met.

[0110] The code conversion module 803 is further configured to convert the source code to be processed into a data transmission object if no.

[0111] Furthermore, as one possible implementation, the code conversion module 803 is also used to convert the source code to be processed into an index when the file type of the source code to be processed is an LF file.

[0112] Furthermore, as one possible implementation, the code conversion module 803 is also used to traverse the source code to be processed when the file type of the source code to be processed is an RPGLE program, to obtain the function type and target code set of each line of code in the source code to be processed;

[0113] The code conversion module 803 is further configured to determine the target subroutine code line in the source code to be processed according to the function type, and to perform code replacement on the source code to be processed according to the target code set and the target subroutine code line to obtain intermediate source code;

[0114] The code conversion module 803 is also used to perform keyword replacement on the intermediate source code based on the function type and preset mapping relationship to obtain the corresponding JAVA pseudocode.

[0115] Furthermore, as one possible implementation, the code conversion module 803 is also used to obtain the function type of each line of code in the source code to be processed based on the header code of each line of code in the source code to be processed when the file type of the source code to be processed is an RPGLE program.

[0116] The code conversion module 803 is also used to obtain the code fragment corresponding to the code line of the preset subroutine type when the function type of any code line is a preset subroutine type;

[0117] The code conversion module 803 is also used to combine all the acquired code fragments into a target code set.

[0118] This embodiment determines whether the source code to be processed is a file when the file type is PF file; if yes, the source code is converted into an entity; otherwise, it is converted into a data transfer object. When the file type is LF file, the source code is converted into an index. When the file type is RPGLE program, the function type of each line of code is obtained from the header code of each line of code in the source code; when the function type of any line of code is a preset subroutine type, the code fragment corresponding to the line of code of the preset subroutine type is obtained; all obtained code fragments are combined into a target code set; the target subroutine code line in the source code to be processed is determined according to the function type, and the source code to be processed is replaced according to the target code set and the target subroutine code line to obtain intermediate source code; the intermediate source code is replaced with keywords based on the function type and the preset mapping relationship to obtain the corresponding JAVA pseudocode. This embodiment can batch convert source code in the database to be processed into JAVA pseudocode based on the file type of the source code to be processed. That is, this embodiment can perform program translation based on the original functional logic of the source code to be processed, and realize code conversion without affecting the functional logic of the source code to be processed.

[0119] Other embodiments or specific implementations of the code conversion device of the present invention can be found in the above-described method embodiments, and will not be repeated here.

[0120] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

[0121] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0122] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0123] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A code conversion method, characterized in that, The code conversion method includes: Based on the target translation path input by the user, a corresponding path acquisition request is generated and sent to the database to be translated. After receiving the path acquisition request, the database to be translated returns a list of objects corresponding to the path acquisition request. The target translation path is the code library path corresponding to the code that needs to be translated. The received list of objects is traversed and parsed to obtain the source code to be processed for each object. Based on the file type of each source code to be processed, the source code to be processed is converted into the corresponding target code. The file types include: PF file, LF file and / or RPGLE program; The step of traversing and parsing the received list of objects to obtain the source code to be processed corresponding to each object includes: The received list of objects is traversed and parsed to obtain the paths and names of all objects to be processed; Based on the path and name of each object to be processed, a corresponding object retrieval request is generated and sent to the database to be converted. After receiving the object retrieval request, the database to be converted feeds back the source code to be processed corresponding to the object retrieval request line by line in the form of a byte stream. Receive the source code to be processed corresponding to each of the objects to be processed.

2. The code conversion method as described in claim 1, characterized in that, The target code includes: entities. The step of converting each source code to be processed into the corresponding target code according to the file type of each source code to be processed includes: When the file type of the source code to be processed is a PF file, determine whether the source code to be processed is a file; If so, the source code to be processed will be converted into an entity.

3. The code conversion method as described in claim 2, characterized in that, The target code includes: a data transfer object; when the file type of the source code to be processed is the PF file, after determining whether the source code to be processed is a file, it further includes: If not, the source code to be processed will be converted into a data transfer object.

4. The code conversion method as described in claim 1, characterized in that, The target code includes: an index; the step of converting each source code to be processed into the corresponding target code according to the file type of each source code to be processed further includes: When the file type of the source code to be processed is an LF file, the source code to be processed is converted into an index.

5. The code conversion method as described in claim 1, characterized in that, The target code includes: JAVA pseudocode; the step of converting each source code to be processed into the corresponding target code according to the file type of each source code to be processed further includes: When the file type of the source code to be processed is an RPGLE program, the source code to be processed is traversed to obtain the function type and target code set of each line of code in the source code to be processed. The target subroutine code line in the source code to be processed is determined according to the function type, and the source code to be processed is replaced according to the target code set and the target subroutine code line to obtain intermediate source code; Based on the function type and preset mapping relationship, the intermediate source code is replaced with keywords to obtain the corresponding JAVA pseudocode.

6. The code conversion method as described in claim 5, characterized in that, When the file type of the source code to be processed is an RPGLE program, the step of traversing the source code to obtain the function type and target code set of each line of code in the source code to be processed includes: When the file type of the source code to be processed is an RPGLE program, the function type of each line of code is obtained according to the header code of each line of code in the source code to be processed; When the function type of any line of code is a preset subroutine type, obtain the code fragment corresponding to the line of code of the preset subroutine type; All the acquired code snippets are combined into a target code set.

7. A code conversion device, characterized in that, The code conversion device includes: The list acquisition module is used to generate a corresponding path acquisition request based on the target translation path input by the user and send it to the database to be converted. After receiving the path acquisition request, the database to be converted will return a list of objects corresponding to the path acquisition request. The target translation path is the code library path corresponding to the code to be translated. The source code acquisition module is used to traverse and parse the received list of objects to obtain the source code to be processed corresponding to each object to be processed. The code conversion module is used to convert each source code to be processed into the corresponding target code according to the file type of each source code to be processed. The file types include: PF file, LF file and / or RPGLE program; The source code acquisition module is further configured to traverse and parse the received object list to obtain the paths and names of all objects to be processed; generate corresponding object acquisition requests based on the paths and names of each object to be processed and send them to the database to be converted; after receiving the object acquisition request, the database to be converted will feed back the source code to be processed corresponding to the object acquisition request line by line in the form of a byte stream; and receive the source code to be processed corresponding to each object to be processed.

8. A code conversion device, characterized in that, The device includes: a memory, a processor, and a code conversion program stored in the memory and executable on the processor, the code conversion program being configured to implement the steps of the code conversion method as described in any one of claims 1 to 6.

9. A storage medium, characterized in that, The storage medium stores a code conversion program, which, when executed by a processor, implements the steps of the code conversion method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method for automatically converting RPG program into JAVA program

    CN110879710A

  • Code format conversion method and device, computer equipment and storage medium

    CN111694572A