Method and apparatus for converting object-oriented structured code, and electronic device

By building a syntax tree and conversion rules for structured code, creating data areas and object areas, and determining the variable offset address according to the update mode, the problems of structured code conversion compilation and incremental update under the IEC61131-3 Ed4.0 standard are solved, and the effect of efficient online incremental update and improving code reusability is achieved.

WO2025060641A1PCT designated stage expired Publication Date: 2025-03-27NR ELECTRIC CO LTD +1

Patent Information

Application Number
PCT/CN2024/106070
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-09-21
Filing Date
2024-07-18
Publication Date
2025-03-27

AI Technical Summary

Technical Problem

When developing using the IEC61131-3 Ed4.0 standard, object-oriented structured code conversion compilation and incremental updates have problems such as data, association mapping of multiple inheritance objects, and section data recovery, which are difficult to achieve.

Method used

By determining the syntax tree of structured code, building conversion rules with the target language, creating data areas and object areas, determining the variable offset address according to the update pattern, generating transition code collections and task function call codes, and finally compiling and generating executable files of the target language.

Benefits of technology

It realizes efficient incremental update of object-oriented structured code, reduces code complexity, improves program reusability, and supports full update and incremental update modes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024106070_27032025_PF_FP_ABST
    Figure CN2024106070_27032025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application is a method for converting an object-oriented structured code. A syntax tree of a current structured code can be determined on the basis of a current programming standard, and a conversion rule of the structured code and a target language to be converted into is constructed. At the same time, in a memory, a data region and an object region are allocated, an offset address of a variable in the data region is determined, and finally, from the structured code, an executable file and a variable table file in the target language are generated. According to the method provided in the present application, by means of features such as encapsulation, polymorphism, and inheritance, online efficient incremental updating of the object-oriented structured code is achieved, reducing code complexity and improving reusability of a program.
Need to check novelty before this filing date? Find Prior Art

Description

Object-oriented structured code conversion method, device and electronic device Technical Field

[0001] The present application relates to the field of computer software, and in particular to an object-oriented structured code conversion method, device and electronic device. Background Art

[0002] IEC61131-3 is the programming language specification for PLC / DCS (Program Logic Control / Distributed Control System). The fourth edition, IEC61131-3 Ed4.0, was promulgated in 2022. IEC61131-3 Ed4.0 further refines classes, methods, function blocks, dynamic name binding, and clarifies specifications for encapsulation, polymorphism, and inheritance. Existing software development based on IEC61131-3 primarily uses versions prior to version 4, and the development process adopts a process-oriented approach.

[0003] The inventors of this application have discovered that when developing in the fields of motion control, fuzzy control, deep learning optimization control, etc. using the IEC61131-3 Ed4.0 standard, it is necessary to adopt an object-oriented programming method to separate data and data processing to improve code reusability and reduce dependencies between modules. However, the structured text language of the IEC61131-3 standard is a language dedicated to the industrial field. Code developed using IEC61131-3 needs to be converted and compiled into machine code before it can run. In addition, PLC / DCS usually requires online program updates without downtime. Converting, compiling, and incrementally updating object-oriented code developed using the IEC61131-3 Ed4.0 standard involves issues such as association mapping of data, multiple inheritance objects, and cross-section data recovery, which are difficult to implement.

[0004] Summary of the Invention

[0005] According to the first aspect of the present application, a method for converting object-oriented structured code is proposed, which may include: determining a syntax tree of the structured code according to the current programming standard of the structured code; constructing conversion rules for the structured code and the target language to be converted; creating a data area and an object area required for running the code corresponding to the target language in the memory; determining the offset address of the variable in the data area in the target language according to the update mode of the structured code; running the initialization function and the running function of the program organization unit according to the syntax tree, conversion rules, data area, object area, and offset address to generate a transition code set; generating a task function call code according to the transition code set; generating a variable table file according to the syntax tree, conversion rules, data area, object area, and offset address of the data area; and compiling the transition code set and the task function call code to generate an executable file in the target language.

[0006] According to the above implementation scheme, the object-oriented structured code conversion method proposed in this application can determine the syntax tree of the current structured code according to the current programming standard, and construct the conversion rules between the structured code and the target language to be converted, while allocating the data area and the object area, determining the offset address of the variable in the data area, and finally generating the executable file and variable table file of the target language from the structured code. The method proposed in this application can reuse the data area, and realizes the online efficient incremental update of the object-oriented structured code through the features of encapsulation, polymorphic integration, etc., reduces the code complexity and improves the reusability of the program.

[0007] According to some embodiments, the step of determining the offset address of the variable in the target language in the data area according to the update mode of the structured code may include: when the update mode of the structured code is a complete update download mode, allocating the offset address of the variable in the data area according to a preset address allocation rule; when the update mode of the structured code is an incremental update download mode, determining the offset address of the variable in the data area according to the variable update situation.

[0008] According to the method of the above implementation scheme, the method proposed in this application determines the offset address of the variable in the data area according to the update mode of the structured code, and can allocate addresses to the variables in both full update and incremental update modes, thereby greatly improving the running efficiency of the program.

[0009] According to a second aspect of the present application, a device for converting object-oriented structured code is provided, which may include:

[0010] The syntax processing module can be used to determine the syntax tree of the structured code according to the current programming standard of the structured code, and construct the conversion rules between the structured code and the target language to be converted; the address processing module can be used to create the data area and object area required for the code running corresponding to the target language in the memory, and determine the offset address of the variable in the target language in the data area according to the update mode of the structured code; the code processing module can be used to run the initialization function and the running function of the program organization unit according to the syntax tree, conversion rules and data area, object area, and offset address, generate a transition code set, and generate a task function call code according to the transition code set; the target file generation module can be used to generate a variable table file according to the syntax tree, conversion rules, data area, object area and the offset address of the data area, compile the transition code set and the task function call code, and generate an executable file in the target language.

[0011] According to the third aspect of the present application, an electronic device is proposed, which may include: a processor; and a memory storing a computer program, wherein when the computer program is executed by the processor, the processor executes the method described in the first aspect of the present application.

[0012] According to a fourth aspect of the present application, a non-transitory computer-readable storage medium is proposed, on which computer-readable instructions are stored. When the instructions are executed by a processor, the processor executes the method described in the first aspect of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without exceeding the scope of protection required by this application.

[0014] FIG1 is a flow chart of an object-oriented structured code conversion method 1000 of the present application;

[0015] FIG2 is a schematic flow chart of step S101 in the method 1000 of FIG1 ;

[0016] FIG3 is a flow chart of step S104 in the method 1000 of FIG1 ;

[0017] FIG4 is a flow chart of step S1042 included in step S104 in the method 1000 of FIG1 ;

[0018] FIG5 is a flow chart of step S105A of a specific embodiment of step S105 in FIG1 ;

[0019] FIG6 is a flow chart of step S105B of a specific embodiment of step S105 in FIG1 ;

[0020] FIG7 is a schematic structural diagram of an object-oriented structured code conversion device 7000 of the present application;

[0021] FIG8 is a structural diagram of an electronic device provided in this application. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.

[0023] Fig. 1 is a flow chart of the object-oriented structured code conversion method 1000 of the present application. As shown in Fig. 1 , the method 1000 includes steps S101 to S108.

[0024] In some specific embodiments, in step S101, an object-oriented structured code conversion device (e.g., a processor, hereinafter described using a processor as an example) determines a syntax tree for the structured code based on the current programming standard for the structured code. In step S101, the structured code is source code written in a structured text language. In some specific embodiments, in step S101, the processor defines the data structures required to construct the syntax tree and performs lexical scanning and syntactic scanning on the structured code to form a syntax tree.

[0025] Optionally, the current programming standard of the structured code is the IEC61131-Ed4.0 standard, and the target language to be converted is the C++ language. Optionally, in step S101, the processor uses a lexical analyzer and a grammatical analyzer to perform lexical scanning and grammatical scanning on the structured code. Optionally, the lexical analyzer used is Flex, and the grammatical analyzer used is Bison.

[0026] In step S102, the processor constructs conversion rules for the structured code and the target language to be converted. In some specific embodiments, in step S102, the conversion rules include a variable type mapping table, a statement mapping table, and a structured component conversion rule.

[0027] In some specific embodiments, the target language to be converted is C++. In step S102, the variable type mapping table includes converting variables in the structured code into variables in the C++ language. For example, the SINT in the structured code is converted into the char type of the target language, and the REAL in the structured code is converted into the float type. Optionally, basic types in the structured code, such as TIME, DATE, TOD, DT, STRING, and WSTRING, are converted into C++ structures. For example, TIME is converted into the IEC_TIME type, where IEC_TIME is defined as follows:

[0028] In some specific embodiments, the target language to be converted is C++. In step S102, the statement mapping table includes the conversion of statements in the structured code and C++ statements. For example, assignment statements are converted to C++ assignment statements; arithmetic statements are converted to C++ arithmetic statements; logical operations are converted to C++ logical operations; IF_ELSE_IF is converted to C++ if-else-if statements; FOR loops are converted to C++ for statements; WHILE and REPEAT_UNTIL statements are converted to C++ while statements; CASE statements are converted to C++ switch-case or if-else-if statements. If the judgment values ​​of the CASE branches are all integer constants, they are converted to switch-case statements. If the CASE branches include value ranges, expressions, or non-numeric constants, they are converted to if-else-if statements. EXIT statements are converted to C++ break statements; CONTINUE statements are converted to C++ continue statements.

[0029] In some specific embodiments, in step S102, the structured component conversion rules include conversion rules for functions, interfaces, classes, and functional blocks in the structured code and objects in the C++ language.

[0030] Optionally, the "function block" in the structured code is converted into a data structure and a class in the C++ language. The member variables in the C++ data structure include the function block's input variables, output variables, local variables, parent function block data structure instance, and function block C++ class pointer; the C++ class includes a constructor with the same name as the function block, a destructor with the same name as the function block, a function block execution function, a function block member function, a function block's input / output variables, and a function block data structure pointer.

[0031] Optionally, the "class" in the structured code is converted into a data structure and C++ class definition in the C++ language. The member variables in the data structure in the C++ language include the class's public variables, protected variables, private variables, parent class data structure instances, and C++ class pointers; the C++ class includes a constructor, a destructor, a function execution function, a member function, and a class data structure pointer. In some specific embodiments, in step S102, the input variables defined in the class member function of the structured code are converted into C++ class member function input parameters, and the output variables defined in the class member function of the structured code are converted into C++ class member function reference type parameters.

[0032] Optionally, the "interface" in the structured code is converted into a data structure and a C++ class definition in the C++ language. The C++ data structure has only one pointer type variable associated with the C++ interface class. In some specific embodiments, in step S102, the interface member functions in the structured text language are converted into public member functions in the C++ interface class.

[0033] Optionally, "functions" in structured code are converted to functions in C++. "Structures" in structured code are converted to structures in C++. "Arrays" in structured code are converted to arrays in C++, and the array subscripts and subscripts are converted to zero-based numbers. "Enumerations" in structured code are converted to enumerations in C++, and "namespaces" in structured code are converted to namespaces in C++.

[0034] In some specific embodiments, in step S103, the processor creates a data area and an object area in memory required for executing the target language code. In step S103, the data area allocates member data corresponding to the C++ class instance, and the object area manages dynamically allocated C++ class object pointers. The class instance in the object area and the structure in the data area are interconnected through pointers.

[0035] In step S104, the processor determines the offset address of the variable in the data area in the target language based on the update mode of the structured code. In some specific embodiments, in step S104, the update mode of the structured code is a complete update mode, and the processor allocates the offset address of the variable in the data area according to a preset address allocation rule. Optionally, the address allocation rule is a memory boundary alignment rule. In some specific embodiments, in step S104, the update mode of the structured code is an incremental update mode, and the processor determines the offset address of the variable in the data area based on the variable update status.

[0036] In some specific embodiments, in step S105, the processor executes the initialization function and the execution function of the program organization unit based on the syntax tree, conversion rules, data area, object area, and offset address to generate a transition code set. The transition code set includes data area variable address association setting code and initial value setting code, object area class instance creation code, program organization unit execution function call code, function block execution function call code, class execution function call code, function block member function call code, and class member function call code. In some specific embodiments, in step S105, if the update mode of the structured code is the incremental update mode, the transition code set also includes incremental initialization code, initialization code for newly added variables, and object area instance creation code for newly added variables.

[0037] In some specific embodiments, in step S106, the processor generates a task function calling code based on the transition code set. In step S106, the processor calls the running function of the program organization unit in the transition code set to generate the task function calling code.

[0038] In some specific embodiments, in step S107, the processor generates a variable table file based on the syntax tree, conversion rules, data area, object area, and data area offset address. In step S107, the variable table file includes the variable names, variable types, and data area variable addresses of the member variables corresponding to the function blocks and classes in the target language to be converted, as well as the source offset address, destination offset address, and size information in the structured code to be copied to memory. In some specific embodiments, in step S108, the processor compiles the transition code set and the task function call code to generate an executable file in the target language.

[0039] The object-oriented structured code conversion method proposed in this application determines the syntax tree of the current structured code according to current programming standards, constructs conversion rules between the structured code and the target language to be converted, allocates data areas and object areas, determines the offset addresses of variables in the data areas, and finally generates executable files and variable table files in the target language from the structured code. The method proposed in this application can reuse data areas and realizes efficient online incremental updates of object-oriented structured code through features such as encapsulation and polymorphic integration, reducing code complexity and improving program reusability.

[0040] Fig. 2 is a flow chart of step S101 in the method 1000 of Fig. 1. As shown in Fig. 2, step S101 includes steps S1011 to S1012.

[0041] In some specific embodiments, in step S1011, the processor generates a lexical file and a grammar file according to a programming standard. For example, in step S1011, the lexical file includes a plurality of regular expressions, each of which represents a definition of a keyword, function, or variable, and the grammar file includes a definition of a programming grammar. Optionally, in step S1011, the programming standard is IEC 61131-3 Ed 4.0.

[0042] In some specific embodiments, in step S1012, the processor generates a syntax tree based on the lexical file and the syntax file. Optionally, in step S101, the processor uses a lexical analyzer and a syntax analyzer to perform lexical scanning and syntax scanning on the structured code. Optionally, the lexical analyzer used is Flex, and the syntax analyzer used is Bison.

[0043] According to the implementation shown in Figure 2, the method of the present application generates a lexical file and a grammar file according to the current programming standard of the structured language, and further generates a syntax tree, which can generate syntax trees corresponding to different programming standards, thereby effectively converting structured code into target language code, especially realizing the conversion of structured code based on the IEC61131-3 Ed4.0 standard.

[0044] Fig. 3 is a flow chart of step S104 in the method 1000 of Fig. 1. As shown in Fig. 3, step S104 includes steps S1041 and S1042.

[0045] In step S1041, when the update mode of the structured code is the complete update download mode, the processor allocates the offset address of the variable in the data area according to a preset address allocation rule. Optionally, in step S1041, the preset address allocation rule is a memory boundary alignment rule.

[0046] In some specific embodiments, in step S1042, when the update mode of the structured code is the incremental update download mode, the processor determines the offset address of the variable in the data area based on the variable update status. In some specific embodiments, in step S1042, when in the incremental update download mode, the processor connects to the operating environment of the controller or personal computer running the structured code to obtain the variable update status, which includes the offset address and type information of the variable in the data area. In step S1042, the processor determines the offset address of the variable in the data area based on the relationship between the variable update status and the preset conditions.

[0047] According to the embodiment shown in FIG3 , the method of the present application determines the offset address of the variable in the data area according to the update mode, thereby achieving efficient division of the variable address in both the full update mode and the incremental update mode.

[0048] Fig. 4 is a flow chart of step S1042 included in step S104 in method 1000 of Fig. 1. As shown in Fig. 4, step S1042 includes steps S401 to S405.

[0049] In some specific embodiments, in step S401, if the variable update condition satisfies a first address update condition, the processor uses the offset address of the variable with the same name as the offset address of the updated variable. Optionally, the first address update condition includes that the updated variable has a variable with the same name and type in the data area.

[0050] In some specific embodiments, in step S402, if the variable update condition satisfies the second address update condition, the processor sets the memory space corresponding to the variable in the data area to free. Optionally, the second address update condition includes that there is no variable with the same name as the variable in the data area among all the updated variables.

[0051] In some specific embodiments, in step S403 and step S404, there are one or more fragments of free areas in the memory of the data area. In step S403, when the variable update situation satisfies the third address update condition, the processor determines whether there is a free area in the data area that matches the memory space occupied by the updated variable. The processing area compares the size of the memory space occupied by the updated variable with the size of all currently existing free areas to determine whether there is a matching free area. In some specific embodiments, in step S404, there is a free area in the data area that matches the memory space occupied by the updated variable, and the processor uses the free area as the offset address of the updated variable.

[0052] In some specific embodiments, in step S405, if there is no free area in the data area that matches the memory space occupied by the updated variable, the processor uses the end of the data area as the offset address of the updated variable. In step S405, the end of the data area is the boundary of the portion of the data area memory that stores content.

[0053] According to the implementation shown in Figure 4, the method of the present application determines the offset address of the variable in the data area according to the variable update situation in the incremental update mode, realizes efficient and reasonable division of the variable address in the incremental update, improves the system speed and saves memory space.

[0054] Fig. 5 is a flowchart of step S105A of a specific embodiment of step S105 in Fig. 1. In the embodiment shown in Fig. 5, step S105A includes steps S1051 and S1052.

[0055] In some specific embodiments, in step S1051, the processor executes the initialization function of the program organization unit to generate variable initialization code and object area class instance creation code. In some specific embodiments, in step S1052, the processor executes the execution function of the program organization unit to generate function call code, function block execution function call code, class execution function call code, and member function call code.

[0056] According to the implementation shown in Figure 5, the method of the present application obtains a transition code set by running the initialization function and the running function of the program organization unit, which can ensure the subsequent generation of task chain call code, and thus ensure that the target file after structured code conversion is available.

[0057] Figure 6 is a flow chart of step S105B of a specific embodiment of step S105 in Figure 1. In the embodiment shown in Figure 6, step S105B includes steps S1053 to S1055. Steps S1053 to S1054 are the same as steps S1051 to S1052 in Figure 5 and are not described in detail here.

[0058] In some specific embodiments, in step S1055, the processor runs the execution function of the program organization unit to generate an incremental code collection. Optionally, the incremental code collection includes incremental initialization code, initialization code for newly added variables, and object area instance creation code for newly added variables.

[0059] According to the implementation shown in Figure 6, the method of the present application can generate transition code including a collection of incremental codes when the update mode of the structured code is an incremental update mode, and can ensure the effectiveness and reusability of the conversion of the structured code when the incremental update mode is included.

[0060] 7 is a schematic diagram of the structure of an object-oriented structured code conversion device 7000 of the present application. As shown in FIG7 , the device 7000 includes a syntax processing module 701 , an address processing module 702 , a code processing module 703 and a target file generation module 704 .

[0061] In some specific embodiments, the syntax processing module 701 determines a syntax tree for the structured code based on the current programming standard for the structured code. Optionally, the structured code is source code written in a structured text language. In some specific embodiments, the syntax processing module 701 defines the data structure required to form the syntax tree and generates the syntax tree by performing a lexical scan and a syntactic scan on the structured code.

[0062] Optionally, the current programming standard for the structured code is IEC61131-Ed4.0, and the target language to be converted is C++. Optionally, the syntax processing module 701 uses a lexical analyzer and a syntax analyzer to perform lexical scanning and syntax scanning on the structured code. Optionally, the lexical analyzer used is Flex, and the syntax analyzer used is Bison.

[0063] In some specific embodiments, the syntax processing module 701 constructs conversion rules between the structured code and the target language to be converted. Optionally, the conversion rules include a variable type mapping table, a statement mapping table, and a structured component conversion rule.

[0064] In some specific embodiments, the target language to be converted is C++. Optionally, the variable type mapping table includes converting variables in the structured code into variables in the C++ language. For example, the SINT in the structured code is converted into the char type of the target language, and the REAL in the structured code is converted into the float type. Optionally, the syntax processing module 701 converts basic types in the structured code such as TIME, DATE, TOD, DT, STRING, and WSTRING into C++ structures, for example, TIME is converted into the IEC_TIME type, where the definition of IEC_TIME is as follows:

[0065] In some specific embodiments, the target language to be converted is C++, and the statement mapping table includes the conversion of statements in the structured code and C++ statements. For example, the syntax processing module 701 converts assignment statements into C++ assignment statements; arithmetic statements into C++ arithmetic statements; logical operations into C++ logical operations; IF_ELSE_IF into C++ if-else-if statements; FOR loops into C++ for statements; WHILE and REPEAT_UNTIL statements into C++ while statements; CASE statements into C++ switch-case or if-else-if statements. If the judgment values ​​of the CASE branches are all integer constants, they are converted into switch-case statements. If the CASE branches include value ranges, expressions, or non-numeric constants, they are converted into if-else-if statements. EXIT statements are converted into C++ break statements; CONTINUE statements are converted into C++ continue statements.

[0066] In some specific embodiments, the structured component conversion rules include conversion rules for functions, interfaces, classes, and functional blocks in the structured code and objects in the C++ language.

[0067] Optionally, the syntax processing module 701 converts the "function block" in the structured code into a data structure and a class in the C++ language. The member variables in the C++ data structure include the function block's input variables, output variables, local variables, parent function block data structure instance, and function block C++ class pointer; the C++ class includes a constructor with the same name as the function block, a destructor with the same name as the function block, a function block execution function, a function block member function, a function block's input / output variables, and a function block data structure pointer.

[0068] Optionally, the syntax processing module 701 converts the "class" in the structured code into a data structure and C++ class definition in the C++ language. The member variables in the data structure in the C++ language include the class's public variables, protected variables, private variables, parent class data structure instances, and C++ class pointers; the C++ class includes a constructor, a destructor, a function execution function, a member function, and a class data structure pointer. In some specific embodiments, the syntax processing module 701 converts the input variables of the class member function definition in the structured code into C++ class member function input parameters, and converts the output variables of the class member function definition in the structured code into C++ class member function reference type parameters.

[0069] Optionally, the syntax processing module 701 converts the "interface" in the structured text into a data structure and a C++ class definition in the C++ language. The C++ data structure has only one pointer type variable associated with the C++ interface class. In some specific embodiments, the syntax processing module 701 converts the interface member functions in the structured text language into public member functions in the C++ interface class.

[0070] Optionally, the syntax processing module 701 converts a "function" in the structured code into a function in the C++ language. The syntax processing module 701 converts a "structure" in the structured code into a structure in the C++ language. The syntax processing module 701 converts an "array" in the structured code into an array in the C++ language, and performs a conversion process to count the array subscripts and subscripts starting from zero. The syntax processing module 701 converts an "enumeration" in the structured code into an enumeration in the C++ language, and converts a "namespace" in the structured code into a namespace in the C++ language.

[0071] In some specific embodiments, the address processing module 702 creates a data area and an object area in memory required for executing the target language code. The address processing module 702 allocates member data corresponding to the C++ class instance to the data area, and manages dynamically allocated C++ class object pointers in the object area. The class instances in the object area and the structures in the data area are linked to each other through pointers.

[0072] In some specific embodiments, the address processing module 702 determines the offset address of the variable in the data area in the target language based on the update mode of the structured code. In some specific embodiments, the update mode of the structured code is a complete update mode, and the address processing module 702 allocates the offset address of the variable in the data area according to a preset address allocation rule. Optionally, the address allocation rule is a memory boundary alignment rule. In some specific embodiments, the update mode of the structured code is an incremental update mode, and the address processing module 702 determines the offset address of the variable in the data area based on the variable update status.

[0073] In some specific embodiments, the code processing module 703 runs the initialization function and execution function of the program organization unit based on the syntax tree, conversion rules, data area, object area, and offset address to generate a transition code set. The transition code set includes data area variable address association setting code and initial value setting code, object area class instance creation code, program organization unit execution function call code, function block execution function call code, class execution function call code, function block member function call code, and class member function call code. In some specific embodiments, when the structured code update mode is incremental update mode, the transition code set also includes incremental initialization code, initialization code for newly added variables, and object area instance creation code for newly added variables.

[0074] In some specific embodiments, the code processing module 703 generates the task function calling code based on the transition code set. The code processing module 703 calls the running function of the program organization unit in the transition code set to generate the task function calling code.

[0075] In some specific embodiments, the target file generation module 704 generates a variable table file based on the syntax tree, conversion rules, data area, object area, and data area offset address. In some specific embodiments, the variable table file includes the variable names, variable types, and data area variable addresses of the member variables corresponding to the function blocks and classes of the target language to be converted, as well as the source offset address, destination offset address, and size information in the structured code to be copied into memory. In some specific embodiments, the target file generation module 704 compiles the transition code set and the task function call code to generate an executable file in the target language.

[0076] FIG8 is a structural diagram of an electronic device provided in this application.

[0077] Referring to FIG8 , FIG8 provides an electronic device including a processor and a memory. The memory stores computer instructions, and when the computer instructions are executed by the processor, the processor executes the computer instructions to implement the method and detailed solution shown in FIG1 .

[0078] It should be understood that the above-described device embodiments are merely illustrative, and the devices disclosed herein may also be implemented in other ways. For example, the division of units / modules described in the above-described embodiments is merely a logical functional division, and actual implementations may employ alternative divisions. For example, multiple units, modules, or components may be combined or integrated into another system, or some features may be omitted or not implemented.

[0079] In addition, unless otherwise specified, the functional units / modules in the various embodiments of the present invention may be integrated into a single unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The aforementioned integrated units / modules may be implemented in the form of hardware or software program modules.

[0080] If the integrated unit / module is implemented in hardware, the hardware may be a digital circuit, an analog circuit, or the like. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, and the like. Unless otherwise specified, the processor or chip may be any appropriate hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC. Unless otherwise specified, the on-chip cache, off-chip memory, and storage may be any appropriate magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), and the like.

[0081] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned memory includes: various media that can store program codes, such as a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0082] An embodiment of the present application further provides a non-transitory computer storage medium storing a computer program. When the computer program is executed by multiple processors, the processors execute the method and detailed solution shown in FIG. 1 .

[0083] The embodiments of the present application are described in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only intended to help understand the method and core ideas of the present application. At the same time, changes or modifications made by those skilled in the art based on the ideas of the present application, the specific implementation methods, and the scope of application of the present application, all fall within the scope of protection of the present application. In summary, the contents of this specification should not be construed as limiting the present application.

Claims

1. A method for converting object-oriented structured code, characterized in that: include: Determining a syntax tree of the structured code according to a current programming standard of the structured code; Constructing conversion rules between the structured code and the target language to be converted; Creating a data area and an object area in the memory required for running the code corresponding to the target language; Determine the offset address of the variable in the target language in the data area according to the update mode of the structured code; An initialization function and an operation function of a program organization unit are executed according to the syntax tree, the conversion rule, the data area, the object area, and the offset address to generate a transition code set; Generate a task function calling code according to the transition code set; Generate a variable table file according to the syntax tree, the conversion rule, the data area, the object area and the offset address of the data area; The transition code set and the task function calling code are compiled to generate an executable file in the target language.

2. The method according to claim 1, characterized in that Determining the syntax tree of the structured code according to the current programming standard of the structured code includes: Generate a lexical file and a grammar file according to the programming standard; The syntax tree is generated according to the lexical file and the syntax file.

3. The method according to claim 1, characterized in that The step of determining the offset address of the variable in the target language in the data area according to the update mode of the structured code comprises: In the case where the update mode of the structured code is a complete update download mode, allocating the offset address of the variable in the data area according to a preset address allocation rule; When the update mode of the structured code is the incremental update download mode, the offset address of the variable in the data area is determined according to the variable update situation.

4. The method according to claim 3, characterized in that Determining the offset address of the variable in the data area according to the variable update situation includes: When the variable update condition satisfies the first address update condition, the offset address of the variable with the same name is used as the offset address of the updated variable; When the variable update condition satisfies the second address update condition, the memory space corresponding to the variable in the data area is set to free; In the case where the variable update condition satisfies the third address update condition, determining whether there is a free area in the data area that matches the memory space occupied by the updated variable; If yes, use the free area as the offset address of the updated variable; If not, the end of the data area is used as the offset address of the updated variable.

5. The method according to claim 1, characterized in that The generating of the transition code set comprises: Running the initialization function of the program organization unit to generate variable initialization code and object area class instance creation code; The running function of the program organization unit is run to generate function calling code, function block running function calling code, class running function calling code and member function calling code.

6. The method according to claim 5, characterized in that In the case where the update mode of the structured code is the incremental update mode, the initialization function and the running function of the program organization unit are run according to the syntax tree, the conversion rule, the data area, the object area, and the offset address to generate a transition code set further includes: The running function of the program organization unit is run to generate an incremental code collection.

7. The method according to claim 1, characterized in that The conversion rules include a variable type mapping table, a statement mapping table and a structured component conversion rule.

8. An object-oriented structured code conversion device, characterized in that: include: A syntax processing module, used to determine the syntax tree of the structured code according to the current programming standard of the structured code, and to construct a conversion rule between the structured code and the target language to be converted; An address processing module, used for creating a data area and an object area required for the code running corresponding to the target language in the memory, and determining the offset address of the variable in the target language in the data area according to the update mode of the structured code; A code processing module, used to run the initialization function and the running function of the program organization unit according to the syntax tree, the conversion rule, the data area, the object area, and the offset address, generate a transition code set, and generate a task function call code according to the transition code set; The target file generation module is used to generate a variable table file according to the syntax tree, the conversion rules, the data area, the object area and the offset address of the data area, compile the transition code set and the task function call code, and generate an executable file of the target language.

9. An electronic device, comprising: processor; A memory storing a computer program, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium having computer-readable instructions stored thereon, which, when executed by a processor, causes the processor to perform the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Cross-platform code conversion method and equipment

    CN113535184A

  • Method and device for converting PLSQL code, electronic equipment and storage medium

    CN114816422A

  • Compiling method of structured text programming language, compiler and electronic equipment

    CN116360788A

  • Object-oriented structured code conversion method and device and electronic equipment

    CN117311720A

  • Pattern matching over structured literals

    US20080127068A1

Cited By

  • Code conversion method and device, electronic equipment and computer readable storage medium

    CN120085874A