Search

EP-4740104-A1 - METHOD AND CODE GENERATOR CONTROLLER TO GENERATE SET OF SOURCE CODE FILES

EP4740104A1EP 4740104 A1EP4740104 A1EP 4740104A1EP-4740104-A1

Abstract

A code generator controller is configured to receive a plurality of test models and generate a set of source code files based on code templates. Moreover, the test models cover all possible code templates. Moreover, the code generator controller is further configured to generate an annotation file comprising annotations for each generated set of source code files. The annotations indicate which templates were used to produce the computer code instructions generate an annotation abstract syntax tree for each annotation file generate a code abstract syntax tree for each generated set of source code files and generate one superior abstract syntax tree structure representing all possible outputs for the code generator based on the code abstract syntax trees and the annotation abstract syntax tree.

Inventors

  • CORFINI, Sara
  • DINATALE, Marco
  • GIGLIO, MARCO

Assignees

  • Shenzhen Yinwang Intelligent Technologies Co., Ltd.

Dates

Publication Date
20260513
Application Date
20230804

Claims (11)

  1. 1. A code generator controller (102) configured to receive a plurality of test models (104) and generate a set of source code files (106) based on code templates, wherein the plurality of test models (104) covers all possible code templates, wherein the code generator controller (102) is further configured to: generate an annotation file (108) comprising annotations (110) for each generated set of source code files, wherein the annotations (110) indicate which templates were used to produce the computer code instructions, generate an annotation abstract syntax tree for each annotation file, generate a code abstract syntax tree for each generated set of source code files, and generate one superior abstract syntax tree structure representing all possible outputs for the code generator based on the code abstract syntax trees and the annotation abstract syntax tree.
  2. 2. The code generator controller (102) according to claim 1, wherein the code generator controller (102) is further configured to generate the superior AST structure by extracting nodes of each code AST using a parser, extracting nodes of the templates from each annotation AST, and merging these nodes.
  3. 3. The code generator controller (102) according to any preceding claim, wherein the code generator controller (102) is further configured to generate the set of source code files (106) as comprising the annotation file, wherein the annotations (110) are interleaved with the computer code instructions.
  4. 4. The code generator controller (102) according to any preceding claim, wherein the annotations (110) in the annotation file (108) allow for backtracking each character generated in the computer code instructions to the code generator template responsible for generating the character.
  5. 5. A code generator controller (302) configured to receive a production model (304) and generate a set of source code files (306) based on code templates, wherein the code generator controller (302) is further configured to receive a superior AST structure as per any preceding claim and to verify the computer code instructions based on the superior AST structure by generating an annotation file (308) for the generated set of source code files (306), generating an annotation abstract syntax tree for the annotation file (308), generating a code abstract syntax tree for the generated set of source code files (306), generating one production superior abstract syntax tree structure representing the generated computer code instructions based on the code abstract syntax trees and the annotation abstract syntax tree, and comparing the production superior AST to the received superior AST structure to determine if each node of the production superior AST has a corresponding node in the received superior AST structure, and if so, verifying the computer code instructions.
  6. 6. The code generator controller (302) according to claim 5, wherein the code generator controller (302) is further configured to compare the production superior AST to the received superior AST structure by recursively navigating both the production superior AST and the received superior AST structure and applying a matching rule, wherein the matching rule depends on a type of a node currently visited.
  7. 7. The code generator controller (302) according to claim 6, wherein the code generator controller (302) is further configured to navigate the production superior AST and the received superior AST structure by starting the matching in a node of the production superior AST and determine that there is a match if annotation node of the production superior AST has the same name, same number of children and if an analysis on the children indicates no error as a corresponding node in the received superior AST structure.
  8. 8. A method (200) for a code generator controller (102) configured to receive a plurality of test models (104) and generate a set of source code files (106) based on code templates, wherein the plurality of test models (104) covers all possible code templates, the method (200) comprising: generating an annotation file (108) comprising annotations (110) for each generated set of source code files (106), wherein the annotations (110) indicate which templates were used to produce the computer code instructions, generating an annotation abstract syntax tree for each annotation file, generating a code abstract syntax tree for each generated set of source code files, and generating one superior abstract syntax tree structure representing all possible outputs for the code generator based on the code abstract syntax trees and the annotation abstract syntax tree.
  9. 9. A computer program product comprising program instructions for performing the method (200) according to claim 8, when executed by one or more processors in a code generator system.
  10. 10. A method (400) for a code generator controller (302) configured to receive a production model (304) and generate a set of source code files (306) based on code templates, the method (400) comprising: receiving a superior AST structure as per any preceding claim and to verifying the computer code instructions based on the superior AST structure by generating an annotation file (308) for the generated set of source code files (306), generating an annotation abstract syntax tree for the annotation file (308), generating a code abstract syntax tree for the generated set of source code files (306), generating one production superior abstract syntax tree structure representing the generated computer code instructions based on the code abstract syntax tree and the annotation abstract syntax tree, and comparing the production superior AST to the received superior AST structure to determine if each node of the production superior AST has a corresponding node in the received superior AST structure, and if so, verifying the computer code instructions.
  11. 1. A computer program product comprising program instructions for performing the method (400) according to claim 10, when executed by one or more processors in a code generator system.

Description

METHOD AND CODE GENERATOR CONTROLLER TO GENERATE SET OF SOURCE CODE FILES TECHNICAL FIELD The present disclosure relates generally to the field of source code generators and more specifically, to a code generator controller and a method for the code generator controller to receive a plurality of test models and generate a set of source code files based on code templates. BACKGROUND Generally, a code generator is an application that acts as a key component in a model-based design (MBD) process that takes a model as an input and generates code as an output. The code generator is used to provide a clear separation between the code and a logic of the application that is further used to generate the code in a convenient and reliable manner. Conventionally, code generators are widely used in embedded systems for different domains, such as automotive, avionics, and the like. However, such code generators may contain bugs, errors, and malfunctions at runtime due to which the output of the code generators is affected adversely. Therefore, the output generated by the code generators is required to be verified thoroughly, especially in several applications in which safety plays a major role. Conventional code generators are used to generate a behavioural code from a functional model of the application and a structural code from an architectural model. However, such conventional code generators may fail to generate executable codes if an error occurs during their execution, which is not desirable. Conventionally, certain attempts have been made to verify the correctness of the generated code by the conventional code generators, such as by performing a visual inspection through different navigating tools, backtracking the generated codes, and the like. However, such attempts are impractical and time-consuming and require either analysis of large portions of the generated code or in-depth knowledge of the generated code and the generated logic, which is not desirable. As a result, there exists a technical problem of how to provide an efficient, accurate and reliable process for verification of the code generated by the code generators. Therefore, in light of the foregoing discussion, there exists a need to overcome the aforementioned drawbacks associated with the conventional methods of verifying the codes generated by the code generators. SUMMARY The present disclosure provides a code generator controller and a method for the code generator controller configured to receive a plurality of test models and generate a set of source code files based on code templates. The present disclosure provides a solution to the existing problem of how to provide an efficient, accurate and reliable verification of the code generated by the code generators. An objective of the present disclosure is to provide a solution that overcomes at least partially the problems encountered in the prior art and provides an improved code generator controller and an improved method for the code generator controller for the verification of an automatically generated code. One or more objectives of the present disclosure are achieved by the solutions provided in the enclosed independent claims. Advantageous implementations of the present disclosure are further defined in the dependent claims. In one aspect, the present disclosure provides a code generator controller configured to receive a plurality of test models and generate a set of source code files based on code templates. Moreover, the plurality of test models covers all code templates, and the code generator controller is further configured to generate one or more annotation files comprising annotations for each generated set of source code files. Moreover, the annotations indicate which templates were used to produce the computer code instructions. Furthermore, the code generator controller is configured to generate an annotation abstract syntax tree for each annotation file, generate a code abstract syntax tree for each generated set of source code files, and generate one superior abstract syntax tree structure representing all possible outputs for the code generator based on the code abstract syntax trees and the annotation abstract syntax tree. The code generator controller is configured to verify the automatic code generation efficiently, accurately, and reliably from the plurality of test models (model-to-text transformation) or text (text-to-text transformation). The code generator controller is further configured to generate the set of source code files after receiving the plurality of test models that cover all the possible potential scenarios or variations in the code templates to ensure that the code generator is capable of handling different scenarios and requirements effectively and efficiently with desired functionality specified by the plurality of test models. Furthermore, the code generator controller is configured to generate the annotation file for each of the generated set