How code is generated

When you build an application from a Business Application diagram, the files are input into the Code Generation Engine and application code files are output as 4gl.

Figure: Code Generation flow

This figure is a flow diagram BA Diagrams flowing to XML files flowing to Code Generation Engine flowing to 4gl Application code.

BAM consolidates and generates

Data Consolidation
The input from the BA diagram and related entities is gathered into a single XML file.
Code Generation
The XML file and a code template are used to generate the application code. The default Tcl template produces Genero 4gl files, but another tool could be used to generate the code (XSL translator for example).
Custom code
Custom code is added to the generated code. The recommended method is using code events, except for some code that can only be provided using the POINT or BLOCK method. The custom code is preserved when the code is regenerated.

Configuring the code generation

The build rules define the series of commands used to build and generate the code.
Note:

If you use code events for custom code, the code is written to files based on the entity name (for example, entity_name.4fdm). These files are compiled like any other .4gl files in your project.

In general, the build rules for code generation:
  • Save custom code added by the user to the generated source files.
  • Generate the new source files without user code.
  • Restore the user code in the generated files.
  • Compile the written and generated source files.
  • Link the compiled files.

To view default build rules, select Projects > Edit Build Rules and then select the Language, for example, Genero (no link). Figure 2 shows the build rules used to generate the code for a Program entity in the Business Application Diagram, while Figure 3 shows the default link rules.

Figure: Default build rule for a generated program entity

Screenshot showing default build rule for a 4PRG program entity.
Table 1. Default build rule example
Build rule command Description
$(generate) The $(generate) command creates an intermediary XML file from modeled entities.
$(blockpoint) -code BLOCK/POINT is extracted from previously generated and modified code.
tclsh The tclsh executable generates the final file by using both a Tcl template file and the intermediary XML file created by the $(generate) command.
Table 2. Default build rule example
Build rule command Description
$(echo) The $(echo) command prints a string to the Output window.
$(fglcomp) The fglcomp tool compiles BDL program sources files into a p-code version.
tclsh The tclsh executable generates the final file by using both a Tcl template file and the intermediary XML file created by the $(generate) command.
$(gslint) The $(gslint) command runs the gslint file from the source file path.
$(delete) The $(delete) command removes the given files or directories in a platform independent way. When deleting a directory, the delete is recursive; all subdirectories and files contained within the directory are deleted.

For a full list, see Command line options for build, link, execution rules.

Tip:

To better understand what is happening during the build of the program, turn on verbose mode using Tools > Preferences (or, if you are on a Mac, > Preferences), then Compiler and Runtime > Compilation. Compile a diagram file, program, or application and view the results in the output.