Code generation method and system based on time sequence driving flow chart
Through the flowchart code generation method based on timing-driven flowchart, the problems of missing timing, fixed code storage methods, in-depth node information processing, low graphic data extraction efficiency and inconsistent code semantics in the prior art are solved, and efficient, stable and flexible code generation is achieved to meet the high timing requirements of complex systems.
Patent Information
- Application Number
- CN202510465638.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-15
- Publication Date
- 2025-05-13
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing code generation methods lack timing drivers and cannot accurately reflect the order of node execution, resulting in the impact of code accuracy; the generated code storage method is fixed and cannot be flexible; in complex process models, node information processing is not deep enough to achieve fine process control; the efficiency of graph data extraction and traversal search; code semantic inconsistency problems lead to increased maintenance costs.
The flowchart code generation method based on timing is adopted, and through the collaborative work of the user side, data server and code generator, configuration data is generated including the timing of the flowchart, code templates, tasks, signal configuration, etc., and the activity code is generated in-depth traversal of the syntax tree to ensure that the code accurately reflects the timing relationship.
It realizes the accurate reflection of the timing relationship in the code generation process, improves the efficiency and stability of code generation, meets the complex system development needs of high timing requirements, and can flexibly expand different application scenarios and express dynamic changes.
Smart Images

Figure CN119987848A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software development, and in particular, relates to a code generation method and system based on a timing-driven flow chart. Background Art
[0002] As the complexity of systems continues to increase, how to improve code generation efficiency has become an important issue in the software development process. Using graphical tools and process models to convert the system's logical structure into code can significantly improve code writing efficiency and reduce human errors. However, existing code generation methods have the following problems: (1) Lack of timing drive: The method of generating code based on flowcharts fails to fully consider the impact of timing factors on process execution. In many scenarios where the execution order needs to be precisely controlled, the lack of timing causes the code to be unable to correctly reflect the order of node execution, which in turn affects the correctness of the generated code. (2) The generated configuration files and code storage methods are relatively fixed, lacking flexible expansion for different application scenarios. Especially when faced with complex business logic, they cannot fully express dynamically changing processes. (3) In complex process models, the information processing of complex interactions and conditional judgments between nodes is relatively simple, lacking in-depth processing of node information and failing to achieve more sophisticated process control; (4) When faced with complex processes, the extraction and traversal search of graphic data may be inefficient. Especially when the program flowchart is large, the complexity and time consumption of the search path may increase significantly. (5) The generated code has semantic inconsistency: the existing technology can generate Figure 1 However, there may be deviations between the graphical semantics of the flowchart and the actual logic of the program. Especially when the flowchart is complex, the automatically generated code may not fully meet the developer's expectations, resulting in increased subsequent maintenance costs. Summary of the invention
[0003] In order to solve the above technical problems, the present invention provides a code generation method and system based on a timing-driven flowchart.
[0004] In a first aspect, the present invention provides a code generation method based on a timing driven flow chart, comprising: The user end starts the code generator process, generates request information and sends it to the code generator; The data server configures the nodes of the flowchart and the relationship between the nodes, reads the configuration of the flowchart and parses it into a syntax tree, and associates and maps the syntax tree with the flowchart; The data server generates configuration data; the configuration data includes the timing of the flowchart, the code template used when generating the code, the task, the signal configuration, the code style, the data source information used when generating the flowchart code, and the code generation template; The code generator reads the request information and the configuration data on the data server, calls the configuration data, and generates a code file.
[0005] In a second aspect, the present invention provides a code generation system based on a timing driven flow chart, comprising a user terminal, a data server and a code generator; The client is used to start the code generator process and generate request information and send it to the code generator; A data server is used to generate configuration data; the configuration data includes the timing of the flowchart, the code template used when generating the code, the task, the signal configuration, the code style, the data source information used when generating the flowchart code, and the code generation template; The code generator is used to read the request information and the configuration data on the data server, call the configuration data, and generate the code file.
[0006] Based on the above technical solution, the present invention can also be improved as follows.
[0007] Furthermore, the syntax tree is associated with the flowchart, including: one-to-one correspondence between each node of the syntax tree and each node of the flowchart, and one-to-one correspondence between the edges of the syntax tree and the relationship of the flowchart.
[0008] Furthermore, the request information includes at least one of configuration data and command line parameters.
[0009] Furthermore, the code generator reads the request information and the configuration data on the data server, calls the configuration data, and generates a code file, including: The code generator reads the configuration of the script in the configuration data according to the request information, and reads the corresponding flowchart configuration according to the configuration of the script; Generate a corresponding syntax tree for each flowchart used by the script, and deeply traverse the syntax tree to generate active code according to the code generation template; The code generator reads the corresponding timing configuration file in the server according to the timing of the script configuration in the configuration data, generates the activity code and the runtime registration code according to the code generation template, writes them into the script file, and generates the script code; The code generator analyzes the task and signal configurations used in the script code and the activity code, and reads the corresponding task and signal configurations in the configuration data; The code generator generates codes corresponding to the task and signal configuration according to the code generation template, and writes the codes into the code file; The code generator uploads the code file to the data server.
[0010] Furthermore, all task codes are written into task context files, and all signal codes are written into signal context files; the generated files include script codes, activity codes, task context codes, and signal context codes.
[0011] Furthermore, the code file includes script code, activity code, signal context code and task context code.
[0012] Furthermore, after the code generator generates the code according to the request information and the configuration data on the data server, it returns the generated code to the user end and waits for the next request information.
[0013] Furthermore, tasks and signal configurations are named using path names.
[0014] Furthermore, when generating the code for each node of the flowchart, all signal configurations on the node are analyzed, the same prefix is extracted as the context, and the signal configuration is simplified using the context manager statement.
[0015] The beneficial effects of the present invention are as follows: the present invention combines timing information and flow charts, and the automatically generated code can more accurately reflect the timing relationship and logical structure in the system, overcoming the problems of low extraction and search efficiency of program flow charts, lack of timing control and semantic inconsistency of generated code, effectively improving the efficiency and stability of code generation, meeting the development needs of complex systems with high timing requirements, and being able to flexibly expand to different application scenarios, especially when faced with complex business logic, fully expressing dynamically changing processes. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A schematic diagram of a code generation method based on a timing-driven flow chart provided in Example 1 of the present invention; Figure 2 The following is a flowchart of the data server of the present invention; Figure 3 Flowchart for generating code files for the code generator. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0018] Example 1 As an example, Figure 1 As shown, in order to solve the above technical problems, this embodiment provides a code generation method based on a timing driven flow chart, including: The user end starts the code generator process, generates request information and sends it to the code generator; The data server configures the nodes of the flowchart and the relationship between the nodes, reads the configuration of the flowchart and parses it into a syntax tree, and associates and maps the syntax tree with the flowchart; The data server generates configuration data; the configuration data includes the timing of the flowchart, the code template used when generating the code, the task, signal configuration, code style, the data source information used when generating the flowchart code, and the code generation template; as shown in the attached Figure 2 The workflow diagram of the data server is shown.
[0019] The code generator reads the request information and the configuration data on the data server, calls the configuration data, and generates a code file.
[0020] In actual application, the method can realize at least two operation modes: server mode and batch mode.
[0021] The specific process of server mode is: the user starts the code generator process, the code generator starts the HTTP service, when there is a request information, the code generator generates a code file according to the configuration data in the request information and the configuration data on the data server, the code generator returns the generated code file to the requester and continues to wait for the next request information. Batch mode can realize local code generation.
[0022] The specific process of batch mode is: the user starts the code generator process, the code generator generates the code file according to the command line parameters in the request information, and exits the process after completion. The specific generation process is the same as the code file generation method corresponding to a single request information in server mode. The command line parameters include the script ID of the target code, etc. The server mode can realize remote code generation.
[0023] The present invention combines timing information and flow charts, and the automatically generated code can more accurately reflect the timing relationship and logical structure in the system, overcoming the problems of low extraction and search efficiency of program flow charts, lack of timing control and semantic inconsistency of generated code, effectively improving the efficiency and stability of code generation, and meeting the needs of complex system development with high timing requirements.
[0024] Optionally, the data server configures the nodes of the flowchart and the relationship between the nodes, expressed in JSON format. The nodes include the start, end, branch, branch merge, modification signal, timing change, execution trigger, output to record, check and record, and stop simulation, etc. The relationship between nodes is used to represent the transfer of control between nodes.
[0025] The timing representation of the flowchart is the time point at which the flowchart is called, which can be expressed in JSON format. Optionally, the time point includes the simulation initialization time, the specified time, the periodic running time point, the task start and the task completion. The code template used when generating the code can be expressed in mustache format. Task and signal configuration are the data used when generating the code, which can be expressed in mustache format. A true task represents a thread of simulation, and the signal configuration represents the data on each port used by the task, including the signal configuration type, such as: bool, int, uint, real32 and real64. The code style is the style used when generating the code, expressed as a command line parameter. The data source information used when generating the flowchart code can be expressed in JSON format. The code generation template is the template used when generating the code, expressed in mustache format. The code file is the final code file generated, which can be expressed as a python file.
[0026] Optionally, the syntax tree is associated with the flowchart, including: one-to-one correspondence between each node of the syntax tree and each node of the flowchart, and one-to-one correspondence between the edges of the syntax tree and the relationship of the flowchart.
[0027] Optionally, the request information includes at least one of configuration data and command line parameters.
[0028] Optionally, the code generator reads the request information and the configuration data on the data server, calls the configuration data, and generates a code file, including: The code generator reads the configuration of the script in the configuration data according to the request information, and reads the corresponding flowchart configuration according to the configuration of the script; Generate a corresponding syntax tree for each flowchart used by the script, and deeply traverse the syntax tree to generate active code according to the code generation template; The code generator reads the corresponding timing configuration file in the server according to the timing of the script configuration in the configuration data, generates the activity code and the runtime registration code according to the code generation template, writes them into the script file, and generates the script code; The code generator analyzes the task and signal configurations used in the script code and the activity code, and reads the corresponding task and signal configurations in the configuration data; The code generator generates codes corresponding to the task and signal configuration according to the code generation template, and writes the codes into the code file; The code generator uploads the code file to the data server.
[0029] For example: when a user requests to provide the script ID of the target python code, after receiving the request, the code generator goes to the data server to read the script configuration according to the script ID, and then goes to the data server to read the related flowchart configuration according to the script configuration. The data server generates a corresponding syntax tree for each flowchart used by the script, and then deeply traverses the syntax tree to generate activity code according to the code generation template; after generating the activity code, the code generator goes to the server to read the corresponding timing configuration file according to the timing in the script configuration, and then generates the activity code and runtime registration code according to the code generation template, and writes them into the script file; after generating the script file, the code generator analyzes the task and signal configuration used in the script code and the activity code, and then goes to the data server to read the corresponding task and signal configuration; the code generator generates the code corresponding to the task and signal configuration according to the code generation template, and all task codes are written into the task context file, and all signal codes are written into the signal context file; finally, these generated files (including scripts, activities, task contexts and signal contexts) are uploaded to the data server for subsequent use by users.
[0030] Optionally, all task codes are written into task context files, and all signal codes are written into signal context files; the generated files include script code, activity code, task context code, and signal context code.
[0031] Script code is the entry file for all generated code execution, such as the script.py file. A script code will call one or more activity codes according to the timing configuration; activity code is the code file corresponding to the flowchart, and one flowchart corresponds to an activity code file, such as the action.py file; signal context code is the set of all signals during the execution of the activity code, such as signal_context.py; task context code is the set of all tasks when the script code and the activity code are running, such as the task_context.py file.
[0032] Optionally, the code file includes script code, activity code, signal context code, and task context code.
[0033] Optionally, after the code generator generates the code according to the request information and the configuration data on the data server, it returns the generated code to the user end and waits for the next request information.
[0034] Optionally, tasks and signal configurations are named using path names.
[0035] As an optional implementation, tasks and signals are distinguished by path names, for example: "A system A device / C processor / D task" and "A system / B device / C2 processor / D task", although both are D tasks, they are two tasks with the same name on different processors, namely D tasks. Similarly, "A system / B device / C processor / D task / E component / F port / G signal" and "A system / B device / C processor / D task / E component / F2 port / G signal" represent signals with the same name on two different ports under the same task (A system / B device / C processor / D task), namely G signals.
[0036] Optionally, when generating the code for each node of the flowchart, analyze all signal configurations on the node, extract the same prefix as the context, and use the context manager statement to simplify the signal configuration.
[0037] In the flowchart, if a node writes data to multiple signals, the common pseudocode is: "A system / B device / C processor / D task / E component / F port / G signal = 1" and "A system / B device / C processor / D task / E component / F port / G2 signal = 2". Since each signal path name is very long, it is inconvenient to write and read. Therefore, when generating the code for each node in the flowchart, all the signals involved in the node are analyzed, and the same prefix is extracted as the context. The context manager statement, that is, the with statement, is used to simplify the writing of the signal, such as: "with A system.B device.C processor.D task.E component.F port", the above pseudocode is simplified to: "ctx.G signal = 1" and "ctx.G2 signal = 2". The generated code is easy to read and modify. Python natively supports Chinese task and signal names, making task and signal names easy to identify and understand. The with statement aggregates related task and signal prefixes, making writing easier.
[0038] Example 2 Based on the same principle as the method shown in Embodiment 1 of the present invention, the embodiment of the present invention also provides a code generation system based on a timing driven flow chart, including a user terminal, a data server and a code generator; The client is used to start the code generator process and generate request information and send it to the code generator; A data server is used to generate configuration data; the configuration data includes the timing of the flowchart, the code template used when generating the code, the task, the signal configuration, the code style, the data source information used when generating the flowchart code, and the code generation template; The code generator is used to read the request information and the configuration data on the data server, call the configuration data, and generate the code file.
[0039] Optionally, the syntax tree is associated with the flowchart, including: one-to-one correspondence between each node of the syntax tree and each node of the flowchart, and one-to-one correspondence between the edges of the syntax tree and the relationship of the flowchart.
[0040] Optionally, the request information includes at least one of configuration data and command line parameters.
[0041] Optionally, the code generator reads the request information and the configuration data on the data server, calls the configuration data, and generates a code file, including: The code generator reads the configuration of the script in the configuration data according to the request information, and reads the corresponding flowchart configuration according to the configuration of the script; Generate a corresponding syntax tree for each flowchart used by the script, and deeply traverse the syntax tree to generate active code according to the code generation template; The code generator reads the corresponding timing configuration file in the server according to the timing of the script configuration in the configuration data, generates the activity code and the runtime registration code according to the code generation template, writes them into the script file, and generates the script code; The code generator analyzes the task and signal configurations used in the script code and the activity code, and reads the corresponding task and signal configurations in the configuration data; The code generator generates codes corresponding to the task and signal configuration according to the code generation template, and writes the codes into the code file; The code generator uploads the code file to the data server.
[0042] Optionally, all task codes are written into task context files, and all signal codes are written into signal context files; the generated files include script code, activity code, task context code, and signal context code.
[0043] Optionally, the code file includes script code, activity code, signal context code, and task context code.
[0044] Optionally, after the code generator generates the code according to the request information and the configuration data on the data server, it returns the generated code to the user end and waits for the next request information.
[0045] Optionally, tasks and signal configurations are named using path names.
[0046] Optionally, when generating the code for each node of the flowchart, analyze all signal configurations on the node, extract the same prefix as the context, and use the context manager statement to simplify the signal configuration.
[0047] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A code generation method based on a timing driven flow chart, characterized in that: include: The user end starts the code generator process, generates request information and sends it to the code generator; The data server configures the nodes of the flowchart and the relationship between the nodes, reads the configuration of the flowchart and parses it into a syntax tree, and associates and maps the syntax tree with the flowchart; The data server generates configuration data; the configuration data includes the timing of the flowchart, the code template used when generating the code, the task, the signal configuration, the code style, the data source information used when generating the flowchart code, and the code generation template; The code generator reads the request information and the configuration data on the data server, and calls the configuration data to generate a code file.
2. The code generation method based on the timing driven flowchart according to claim 1 is characterized in that: The syntax tree is associated with the flowchart, including: one-to-one correspondence between each node of the syntax tree and each node of the flowchart, and one-to-one correspondence between the edges of the syntax tree and the relationship of the flowchart.
3. The code generation method based on the timing driven flowchart according to claim 1 is characterized in that: The request information includes at least one of configuration data and command line parameters.
4. The code generation method based on the timing driven flow chart according to claim 1 is characterized in that: The code generator reads the request information and the configuration data on the data server, calls the configuration data, and generates code files, including: The code generator reads the configuration of the script in the configuration data according to the request information, and reads the corresponding flowchart configuration according to the configuration of the script; Generate a corresponding syntax tree for each flowchart used by the script, and deeply traverse the syntax tree to generate active code according to the code generation template; The code generator reads the corresponding timing configuration file in the server according to the timing of the script configuration in the configuration data, generates the activity code and the runtime registration code according to the code generation template, writes them into the script file, and generates the script code; The code generator analyzes the task and signal configurations used in the script code and the activity code, and reads the corresponding task and signal configurations in the configuration data; The code generator generates codes corresponding to the task and signal configuration according to the code generation template, and writes the codes into the code file; The code generator uploads the code file to the data server.
5. The code generation method based on the timing driven flow chart according to claim 4 is characterized in that: All task codes are written into task context files, and all signal codes are written into signal context files; the generated files include script code, activity code, task context code, and signal context code.
6. The code generation method based on a timing driven flowchart according to any one of claims 1 or 4, characterized in that: The code file includes script code, activity code, signal context code and task context code.
7. The code generation method based on the timing driven flow chart according to claim 1 is characterized in that: The code generator generates the code according to the request information and the configuration data on the data server, returns the generated code to the user end and waits for the next request information.
8. The code generation method based on the timing driven flow chart according to claim 1 is characterized in that: Task and signal configurations are named using path names.
9. The code generation method based on the timing driven flow chart according to claim 1, characterized in that: When generating the code for each node in the flowchart, all signal configurations on the node are analyzed, the same prefix is extracted as the context, and the signal configuration is simplified using the context manager statement.
10. A code generation system based on a timing driven flow chart, characterized in that: Including user end, data server and code generator; The client is used to start the code generator process and generate request information and send it to the code generator; A data server is used to generate configuration data; the configuration data includes the timing of the flowchart, the code template used when generating the code, the task, the signal configuration, the code style, the data source information used when generating the flowchart code, and the code generation template; The code generator is used to read the request information and the configuration data on the data server, call the configuration data, and generate the code file.
Citation Information
Patent Citations
Method for implementing code programming by graphical operations
CN102915242A
Method and device for performing software integration on multiple model codes
CN108279885A
Front-end code generation method and device, computer equipment and storage medium
CN112685036A
Code generation method and device based on syntax tree and electronic equipment
CN115048104A
Cited By
Low-code platform building method and system based on AI assistance
CN121433629A
AI-assisted low-code platform building method and system
CN121433629B