lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.generator.GeneratorBase Class Referenceabstract

Generator base class for specifying core functionality that all code generators should have. More...

Inherits AbstractLFValidator.

Inherited by org.lflang.analyses.uclid.UclidGenerator.

Classes

class  ErrorFileAndLine
 Parsed error message from a compiler is returned here. More...

Public Member Functions

void doGenerate (Resource resource, LFGeneratorContext context)
 Generate code from the Lingua Franca model contained by the specified resource.
boolean errorsOccurred ()
 Return true if errors occurred in the last call to doGenerate().
 GeneratorBase (LFGeneratorContext context)
 Create a new GeneratorBase object.
GeneratorCommandFactory getCommandFactory ()
Instantiation getMainDef ()
int getReactionBankIndex (Reaction reaction)
 Return the reaction bank index.
abstract Target getTarget ()
 Return the Targets enum for the current target.
TargetConfig getTargetConfig ()
abstract TargetTypes getTargetTypes ()
void printInfo (LFGeneratorContext context)
 Print to stdout information about what source file is being generated, what mode the generator is in, and where the generated sources are to be put.
void reportCommandErrors (String stderr)
 Parse the specified string for command errors that can be reported using marks in the Eclipse IDE.
void setReactionBankIndex (Reaction reaction, int bankIndex)
 Mark the specified reaction to belong to only the specified bank index.

Public Attributes

final LFGeneratorContext context
boolean hasModalReactors = false
 Indicates whether the current Lingua Franca program contains model reactors.
boolean hasWatchdogs = false
 Indicates whether the program has any watchdogs.
ReactorInstance main
 The main (top-level) reactor instance.
MessageReporter messageReporter
 An error reporter for reporting any errors or warnings during the code generation.

Protected Member Functions

void additionalPostProcessingForModes ()
 Hook for additional post-processing of the model.
boolean buildUsingDocker ()
 Create Dockerfiles and docker-compose.yml, build, and create a launcher.
void checkModalReactorSupport (boolean isSupported)
 Checks whether modal reactors are present and require appropriate code generation.
void checkWatchdogSupport (boolean isSupported)
 Check whether watchdogs are present and are supported.
void cleanIfNeeded (LFGeneratorContext context)
 Check if a clean was requested from the standalone compiler and perform the clean step.
void copyUserFiles (TargetConfig targetConfig, FileConfig fileConfig)
 Copy user specific files to the src-gen folder.
void createMainInstantiation ()
 If there is a main or federated reactor, then create a synthetic Instantiation for that top-level reactor and set the field mainDef to refer to it.
String getConflictingConnectionsInModalReactorsBody (VarRef source, VarRef dest)
 Return target code for forwarding reactions iff the connections have the same destination as other connections or reaction in mutually exclusive modes.
abstract DockerGenerator getDockerGenerator (LFGeneratorContext context)
 Return a DockerGenerator instance suitable for the target.
ErrorFileAndLine parseCommandOutput (String line)
 Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if the line is recognized as the first line of an error message.
void registerTransformation (AstTransformation transformation)
 Register an AST transformation to be applied to the AST.
void setReactorsAndInstantiationGraph (LFGeneratorContext.Mode mode)
 Create a new instantiation graph.

Protected Attributes

GeneratorCommandFactory commandFactory
 A factory for compiler commands.
InstantiationGraph instantiationGraph
 Graph that tracks dependencies between instantiations.
Instantiation mainDef
 Definition of the main (top-level) reactor.
Map< Reaction, Integer > reactionBankIndices = null
 Map from reactions to bank indices.
List< Reactor > reactors = new ArrayList<>()
 A list of Reactor definitions in the main resource, including non-main reactors defined in imported resources.
final TargetConfig targetConfig
 The current target configuration.

Detailed Description

Generator base class for specifying core functionality that all code generators should have.

Author
Edward A. Lee
Marten Lohstroh
Christian Menard
Matt Weber
Soroush Bateni

Constructor & Destructor Documentation

◆ GeneratorBase()

org.lflang.generator.GeneratorBase.GeneratorBase ( LFGeneratorContext context)

Create a new GeneratorBase object.

Member Function Documentation

◆ additionalPostProcessingForModes()

void org.lflang.generator.GeneratorBase.additionalPostProcessingForModes ( )
protected

Hook for additional post-processing of the model.

◆ buildUsingDocker()

boolean org.lflang.generator.GeneratorBase.buildUsingDocker ( )
protected

Create Dockerfiles and docker-compose.yml, build, and create a launcher.

◆ checkModalReactorSupport()

void org.lflang.generator.GeneratorBase.checkModalReactorSupport ( boolean isSupported)
protected

Checks whether modal reactors are present and require appropriate code generation.

This will set the hasModalReactors variable.

Parameters
isSupportedindicates if modes are supported by this code generation.

◆ checkWatchdogSupport()

void org.lflang.generator.GeneratorBase.checkWatchdogSupport ( boolean isSupported)
protected

Check whether watchdogs are present and are supported.

Parameters
isSupportedindicates whether or not this is a supported target and whether or not it is a threaded runtime.

◆ cleanIfNeeded()

void org.lflang.generator.GeneratorBase.cleanIfNeeded ( LFGeneratorContext context)
protected

Check if a clean was requested from the standalone compiler and perform the clean step.

◆ copyUserFiles()

void org.lflang.generator.GeneratorBase.copyUserFiles ( TargetConfig targetConfig,
FileConfig fileConfig )
protected

Copy user specific files to the src-gen folder.

This should be overridden by the target generators.

Parameters
targetConfigThe targetConfig to read the files from.
fileConfigThe fileConfig used to make the copy and resolve paths.

◆ createMainInstantiation()

void org.lflang.generator.GeneratorBase.createMainInstantiation ( )
protected

If there is a main or federated reactor, then create a synthetic Instantiation for that top-level reactor and set the field mainDef to refer to it.

◆ doGenerate()

void org.lflang.generator.GeneratorBase.doGenerate ( Resource resource,
LFGeneratorContext context )

Generate code from the Lingua Franca model contained by the specified resource.

This is the main entry point for code generation. This base class finds all reactor class definitions, including any reactors defined in imported .lf files (except any main reactors in those imported files), and adds them to the reactors list. If errors occur during generation, then a subsequent call to errorsOccurred() will return true.

Parameters
resourceThe resource containing the source code.
contextContext relating to invocation of the code generator. In standalone mode, this object is also used to relay CLI arguments.

Reimplemented in org.lflang.analyses.uclid.UclidGenerator.

◆ errorsOccurred()

boolean org.lflang.generator.GeneratorBase.errorsOccurred ( )

Return true if errors occurred in the last call to doGenerate().

This will return true if any of the reportError methods was called.

Returns
True if errors occurred.

◆ getCommandFactory()

GeneratorCommandFactory org.lflang.generator.GeneratorBase.getCommandFactory ( )

◆ getConflictingConnectionsInModalReactorsBody()

String org.lflang.generator.GeneratorBase.getConflictingConnectionsInModalReactorsBody ( VarRef source,
VarRef dest )
protected

Return target code for forwarding reactions iff the connections have the same destination as other connections or reaction in mutually exclusive modes.

This method needs to be overridden in target specific code generators that support modal reactors.

◆ getDockerGenerator()

abstract DockerGenerator org.lflang.generator.GeneratorBase.getDockerGenerator ( LFGeneratorContext context)
abstractprotected

Return a DockerGenerator instance suitable for the target.

Reimplemented in org.lflang.analyses.uclid.UclidGenerator.

◆ getMainDef()

Instantiation org.lflang.generator.GeneratorBase.getMainDef ( )

◆ getReactionBankIndex()

int org.lflang.generator.GeneratorBase.getReactionBankIndex ( Reaction reaction)

Return the reaction bank index.

See also
setReactionBankIndex
Parameters
reactionThe reaction.
Returns
The reaction bank index, if one has been set, and -1 otherwise.

◆ getTarget()

abstract Target org.lflang.generator.GeneratorBase.getTarget ( )
abstract

Return the Targets enum for the current target.

Reimplemented in org.lflang.analyses.uclid.UclidGenerator.

◆ getTargetConfig()

TargetConfig org.lflang.generator.GeneratorBase.getTargetConfig ( )

◆ getTargetTypes()

abstract TargetTypes org.lflang.generator.GeneratorBase.getTargetTypes ( )
abstract

◆ parseCommandOutput()

ErrorFileAndLine org.lflang.generator.GeneratorBase.parseCommandOutput ( String line)
protected

Given a line of text from the output of a compiler, return an instance of ErrorFileAndLine if the line is recognized as the first line of an error message.

Otherwise, return null. This base class simply returns null.

Parameters
lineA line of output from a compiler or other external tool that might generate errors.
Returns
If the line is recognized as the start of an error message, then return a class containing the path to the file on which the error occurred (or null if there is none), the line number (or the string "1" if there is none), the character position (or the string "0" if there is none), and the message (or an empty string if there is none).

◆ printInfo()

void org.lflang.generator.GeneratorBase.printInfo ( LFGeneratorContext context)

Print to stdout information about what source file is being generated, what mode the generator is in, and where the generated sources are to be put.

◆ registerTransformation()

void org.lflang.generator.GeneratorBase.registerTransformation ( AstTransformation transformation)
protected

Register an AST transformation to be applied to the AST.

The transformations will be applied in the order that they are registered in.

◆ reportCommandErrors()

void org.lflang.generator.GeneratorBase.reportCommandErrors ( String stderr)

Parse the specified string for command errors that can be reported using marks in the Eclipse IDE.

In this class, we attempt to parse the messages to look for file and line information, thereby generating marks on the appropriate lines. This should not be called in standalone mode.

Parameters
stderrThe output on standard error of executing a command.

◆ setReactionBankIndex()

void org.lflang.generator.GeneratorBase.setReactionBankIndex ( Reaction reaction,
int bankIndex )

Mark the specified reaction to belong to only the specified bank index.

This is needed because reactions cannot declare a specific bank index as an effect or trigger. Reactions that send messages between federates, including absent messages, need to be specific to a bank member.

Parameters
reactionThe reaction.
bankIndexThe bank index, or -1 if there is no bank.

◆ setReactorsAndInstantiationGraph()

void org.lflang.generator.GeneratorBase.setReactorsAndInstantiationGraph ( LFGeneratorContext.Mode mode)
protected

Create a new instantiation graph.

This is a graph where each node is a Reactor (not a ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement like a = new A(); After creating the graph, sort the reactors in topological order and assign them to the reactors class variable. Hence, after this method returns, this.reactors will be a list of Reactors such that any reactor is preceded in the list by reactors that it instantiates.

Member Data Documentation

◆ commandFactory

GeneratorCommandFactory org.lflang.generator.GeneratorBase.commandFactory
protected

A factory for compiler commands.

◆ context

final LFGeneratorContext org.lflang.generator.GeneratorBase.context

◆ hasModalReactors

boolean org.lflang.generator.GeneratorBase.hasModalReactors = false

Indicates whether the current Lingua Franca program contains model reactors.

◆ hasWatchdogs

boolean org.lflang.generator.GeneratorBase.hasWatchdogs = false

Indicates whether the program has any watchdogs.

This is used to check for support.

◆ instantiationGraph

InstantiationGraph org.lflang.generator.GeneratorBase.instantiationGraph
protected

Graph that tracks dependencies between instantiations.

This is a graph where each node is a Reactor (not a ReactorInstance) and an arc from Reactor A to Reactor B means that B contains an instance of A, constructed with a statement like a = new A(); After creating the graph, sort the reactors in topological order and assign them to the reactors class variable. Hence, after this method returns, this.reactors will be a list of Reactors such that any reactor is preceded in the list by reactors that it instantiates.

◆ main

ReactorInstance org.lflang.generator.GeneratorBase.main

The main (top-level) reactor instance.

◆ mainDef

Instantiation org.lflang.generator.GeneratorBase.mainDef
protected

Definition of the main (top-level) reactor.

This is an automatically generated AST node for the top-level reactor.

◆ messageReporter

MessageReporter org.lflang.generator.GeneratorBase.messageReporter

An error reporter for reporting any errors or warnings during the code generation.

◆ reactionBankIndices

Map<Reaction, Integer> org.lflang.generator.GeneratorBase.reactionBankIndices = null
protected

Map from reactions to bank indices.

◆ reactors

List<Reactor> org.lflang.generator.GeneratorBase.reactors = new ArrayList<>()
protected

A list of Reactor definitions in the main resource, including non-main reactors defined in imported resources.

These are ordered in the list in such a way that each reactor is preceded by any reactor that it instantiates using a command like foo = new Foo();

◆ targetConfig

final TargetConfig org.lflang.generator.GeneratorBase.targetConfig
protected

The current target configuration.


The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/generator/GeneratorBase.java