lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.generator.c.CReactionGenerator Class Reference

Generate code for reactions. More...

Static Public Member Functions

static void generateBuiltinTriggeredReactionsArray (Set< Integer > reactions, String name, CodeBuilder body, CodeBuilder constructorCode)
static String generateDeadlineFunctionHeader (TypeParameterizedReactor tpr, int reactionIndex)
 Return the top level C function header for the deadline function numbered "reactionIndex" in "r".
static String generateDeadlineFunctionName (TypeParameterizedReactor tpr, int reactionIndex)
 Returns the name of the deadline function for reaction.
static String generateDelayBody (String ref, String actionName, InferredType type)
 Generate code for the body of a reaction that takes an input and schedules an action with the value of that input.
static String generateForwardBody (String outputName, String targetType, String actionName, InferredType type)
static String generateFunction (String header, String init, Code code, boolean suppressLineDirectives)
static String generateFunctionHeader (String functionName)
 Return the start of a function declaration for a function that takes a void* argument and returns void.
static String generateInitializationForReaction (String body, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex, CTypes types, MessageReporter messageReporter, Instantiation mainDef, boolean requiresTypes)
 Generate necessary initialization code inside the body of the reaction that belongs to reactor decl.
static String generateOutputVariablesInReaction (VarRef effect, TypeParameterizedReactor tpr, MessageReporter messageReporter, boolean requiresTypes)
 Generate into the specified string builder the code to initialize local variables for outputs in a reaction function from the "self" struct.
static String generateReaction (Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex, Instantiation mainDef, MessageReporter messageReporter, CTypes types, TargetConfig targetConfig, boolean requiresType)
 Generate a reaction function definition for a reactor.
static void generateReactionAndTriggerStructs (CodeBuilder body, TypeParameterizedReactor tpr, CodeBuilder constructorCode, CTypes types)
 Generate the fields of the self struct and statements for the constructor to create and initialize a reaction_t struct for each reaction in the specified reactor and a trigger_t struct for each trigger (input, action, timer, or output of a contained reactor).
static String generateReactionFunctionHeader (TypeParameterizedReactor tpr, int reactionIndex)
 Return the top level C function header for the reaction numbered "reactionIndex" in "r".
static String generateReactionFunctionName (TypeParameterizedReactor tpr, int reactionIndex)
 Return the function name for specified reaction of the specified reactor.
static String generateStpFunctionHeader (TypeParameterizedReactor tpr, int reactionIndex)
static String generateStpFunctionName (TypeParameterizedReactor tpr, int reactionIndex)
 Returns the name of the stp function for reaction.
static String generateWatchdogVariablesInReaction (VarRef effect)
 Generate into the specified string builder the code to initialize local variables for watchdogs in a reaction function from the "self" struct.
static int maxContainedReactorBankWidth (Instantiation containedReactor, LinkedList< Instantiation > breadcrumbs, int max, Instantiation mainDef)
 Return the maximum bank width for the given instantiation within all instantiations of its parent reactor.

Static Protected Attributes

static String DISABLE_REACTION_INITIALIZATION_MARKER

Detailed Description

Generate code for reactions.

Member Function Documentation

◆ generateBuiltinTriggeredReactionsArray()

void org.lflang.generator.c.CReactionGenerator.generateBuiltinTriggeredReactionsArray ( Set< Integer > reactions,
String name,
CodeBuilder body,
CodeBuilder constructorCode )
static

◆ generateDeadlineFunctionHeader()

String org.lflang.generator.c.CReactionGenerator.generateDeadlineFunctionHeader ( TypeParameterizedReactor tpr,
int reactionIndex )
static

Return the top level C function header for the deadline function numbered "reactionIndex" in "r".

Parameters
tprThe reactor declaration
reactionIndexThe reaction index.
Returns
The function name for the deadline function.

◆ generateDeadlineFunctionName()

String org.lflang.generator.c.CReactionGenerator.generateDeadlineFunctionName ( TypeParameterizedReactor tpr,
int reactionIndex )
static

Returns the name of the deadline function for reaction.

Parameters
tprThe reactor with the deadline
reactionIndexThe number assigned to this reaction deadline

◆ generateDelayBody()

String org.lflang.generator.c.CReactionGenerator.generateDelayBody ( String ref,
String actionName,
InferredType type )
static

Generate code for the body of a reaction that takes an input and schedules an action with the value of that input.

Parameters
refReference to the input port.
actionNameThe action to schedule
typeThe type of the data.

◆ generateForwardBody()

String org.lflang.generator.c.CReactionGenerator.generateForwardBody ( String outputName,
String targetType,
String actionName,
InferredType type )
static

◆ generateFunction()

String org.lflang.generator.c.CReactionGenerator.generateFunction ( String header,
String init,
Code code,
boolean suppressLineDirectives )
static

◆ generateFunctionHeader()

String org.lflang.generator.c.CReactionGenerator.generateFunctionHeader ( String functionName)
static

Return the start of a function declaration for a function that takes a void* argument and returns void.

Parameters
functionName
Returns

◆ generateInitializationForReaction()

String org.lflang.generator.c.CReactionGenerator.generateInitializationForReaction ( String body,
Reaction reaction,
TypeParameterizedReactor tpr,
int reactionIndex,
CTypes types,
MessageReporter messageReporter,
Instantiation mainDef,
boolean requiresTypes )
static

Generate necessary initialization code inside the body of the reaction that belongs to reactor decl.

Parameters
bodyThe body of the reaction. Used to check for the DISABLE_REACTION_INITIALIZATION_MARKER.
reactionThe initialization code will be generated for this specific reaction
tprThe reactor that has the reaction
reactionIndexThe index of the reaction relative to other reactions in the reactor, starting from 0
typesThe C-specific type conversion functions.
messageReporterUsed to report errors and warnings.
mainDefThe main reactor instantiation.
requiresTypesWhether type information is required.

◆ generateOutputVariablesInReaction()

String org.lflang.generator.c.CReactionGenerator.generateOutputVariablesInReaction ( VarRef effect,
TypeParameterizedReactor tpr,
MessageReporter messageReporter,
boolean requiresTypes )
static

Generate into the specified string builder the code to initialize local variables for outputs in a reaction function from the "self" struct.

Parameters
effectThe effect declared by the reaction. This must refer to an output.
tprThe reactor containing the reaction.
messageReporterUsed to report errors and warnings.
requiresTypesWhether type information is required.

◆ generateReaction()

String org.lflang.generator.c.CReactionGenerator.generateReaction ( Reaction reaction,
TypeParameterizedReactor tpr,
int reactionIndex,
Instantiation mainDef,
MessageReporter messageReporter,
CTypes types,
TargetConfig targetConfig,
boolean requiresType )
static

Generate a reaction function definition for a reactor.

This function will have a single argument that is a void* pointing to a struct that contains parameters, state variables, inputs (triggering or not), actions (triggering or produced), and outputs.

Parameters
reactionThe reaction.
tprThe reactor.
reactionIndexThe position of the reaction within the reactor.
mainDefThe main reactor instantiation.
messageReporterUsed to report errors and warnings.
typesThe C-specific type conversion functions.
targetConfigThe target configuration.
requiresTypeWhether type information is required.

◆ generateReactionAndTriggerStructs()

void org.lflang.generator.c.CReactionGenerator.generateReactionAndTriggerStructs ( CodeBuilder body,
TypeParameterizedReactor tpr,
CodeBuilder constructorCode,
CTypes types )
static

Generate the fields of the self struct and statements for the constructor to create and initialize a reaction_t struct for each reaction in the specified reactor and a trigger_t struct for each trigger (input, action, timer, or output of a contained reactor).

Parameters
bodyThe place to put the code for the self struct.
tprTypeParameterizedReactor
constructorCodeThe place to put the constructor code.
typesThe C-specific type conversion functions.

◆ generateReactionFunctionHeader()

String org.lflang.generator.c.CReactionGenerator.generateReactionFunctionHeader ( TypeParameterizedReactor tpr,
int reactionIndex )
static

Return the top level C function header for the reaction numbered "reactionIndex" in "r".

Parameters
tprThe reactor declaration
reactionIndexThe reaction index.
Returns
The function name for the reaction.

◆ generateReactionFunctionName()

String org.lflang.generator.c.CReactionGenerator.generateReactionFunctionName ( TypeParameterizedReactor tpr,
int reactionIndex )
static

Return the function name for specified reaction of the specified reactor.

Parameters
tprThe reactor
reactionIndexThe reaction index.
Returns
The function name for the reaction.

◆ generateStpFunctionHeader()

String org.lflang.generator.c.CReactionGenerator.generateStpFunctionHeader ( TypeParameterizedReactor tpr,
int reactionIndex )
static

◆ generateStpFunctionName()

String org.lflang.generator.c.CReactionGenerator.generateStpFunctionName ( TypeParameterizedReactor tpr,
int reactionIndex )
static

Returns the name of the stp function for reaction.

Parameters
tprThe reactor with the stp
reactionIndexThe number assigned to this reaction deadline

◆ generateWatchdogVariablesInReaction()

String org.lflang.generator.c.CReactionGenerator.generateWatchdogVariablesInReaction ( VarRef effect)
static

Generate into the specified string builder the code to initialize local variables for watchdogs in a reaction function from the "self" struct.

Parameters
effectThe effect declared by the reaction. This must refer to a watchdog.

◆ maxContainedReactorBankWidth()

int org.lflang.generator.c.CReactionGenerator.maxContainedReactorBankWidth ( Instantiation containedReactor,
LinkedList< Instantiation > breadcrumbs,
int max,
Instantiation mainDef )
static

Return the maximum bank width for the given instantiation within all instantiations of its parent reactor.

On the first call to this method, the breadcrumbs should be null and the max argument should be zero. On recursive calls, breadcrumbs is a list of nested instantiations, the max is the maximum width found so far. The search for instances of the parent reactor will begin with the last instantiation in the specified list.

This rather complicated method is used when a reaction sends or receives data to or from a bank of contained reactors. There will be an array of structs on the self struct of the parent, and the size of the array is conservatively set to the maximum of all the identified bank widths. This is a bit wasteful of memory, but it avoids having to malloc the array for each instance, and in typical usage, there will be few instances or instances that are all the same width.

Parameters
containedReactorThe contained reactor instantiation.
breadcrumbsnull on first call (non-recursive).
max0 on first call.
mainDefThe main reactor instantiation.

Member Data Documentation

◆ DISABLE_REACTION_INITIALIZATION_MARKER

String org.lflang.generator.c.CReactionGenerator.DISABLE_REACTION_INITIALIZATION_MARKER
staticprotected
Initial value:
=
"// **** Do not include initialization code in this reaction."

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/c/CReactionGenerator.java