![]() |
lingua-franca 0.10.1
Lingua Franca code generator
|
Helper class for printing code with indentation. More...
Public Member Functions | |
| CodeBuilder () | |
| Construct a new empty code emitter. | |
| CodeBuilder (CodeBuilder model) | |
| Construct a new code emitter with the text and indentation of the specified code emitter. | |
| void | endChannelIteration (PortInstance port) |
If the specified port is a multiport, then start a specified iteration over the channels of the multiport using as the channel index the variable name returned by CUtil#channelIndex(PortInstance). | |
| void | endScopedBankChannelIteration (PortInstance port, String count) |
| End a scoped block to iterate over bank members and channels for the specified port with a variable with the name given by count counting the iterations. | |
| void | endScopedBlock () |
| void | endScopedRangeBlock (RuntimeRange< PortInstance > range) |
| End a scoped block for the specified range. | |
| void | endScopedRangeBlock (SendRange srcRange, RuntimeRange< PortInstance > dstRange) |
| End a scoped block that iterates over the specified pair of ranges. | |
| String | getCode () |
| Get the code produced so far. | |
| void | indent () |
| Increase the indentation of the output code produced. | |
| void | insert (int position, String text) |
| Insert the specified text at the specified position. | |
| int | length () |
| Return the length of the code in characters. | |
| void | newLine () |
| Add a new line. | |
| void | pr (CharSequence text) |
| Append the given text to the code buffer at the current indentation level. | |
| void | pr (String format, Object... args) |
| Append the specified text plus a final newline. | |
| void | prComment (String comment) |
| Append a single-line, C-style comment to the code. | |
| void | prEndSourceLineNumber (boolean suppress) |
| Print a tag marking the end of a block corresponding to the source LF file. | |
| void | prSourceLineNumber (EObject eObject, boolean suppress) |
| Print the #line compiler directive with the line number of the specified object. | |
| CodeBuilder | removeLines (String prefix) |
| Remove all lines that start with the specified prefix and return a new CodeBuilder with the result. | |
| void | startChannelIteration (PortInstance port) |
If the specified port is a multiport, then start a specified iteration over the channels of the multiport using as the channel index the variable name returned by CUtil#channelIndex(PortInstance). | |
| void | startScopedBankChannelIteration (PortInstance port, String count) |
| Start a scoped block to iterate over bank members and channels for the specified port with a variable with the name given by count counting the iterations. | |
| void | startScopedBlock () |
| Start a scoped block, which is a section of code surrounded by curley braces and indented. | |
| void | startScopedBlock (ReactorInstance reactor) |
| Start a scoped block for the specified reactor. | |
| void | startScopedRangeBlock (RuntimeRange< PortInstance > range, String runtimeIndex, String bankIndex, String channelIndex, boolean nested) |
| Start a scoped block that iterates over the specified range of port channels. | |
| void | startScopedRangeBlock (SendRange srcRange, RuntimeRange< PortInstance > dstRange) |
| Start a scoped block that iterates over the specified pair of ranges. | |
| String | toString () |
| Return the code as a string. | |
| void | unindent () |
| Reduce the indentation by one level for generated code/. | |
| CodeMap | writeToFile (String path) throws IOException |
| Write the text to a file. | |
Helper class for printing code with indentation.
This class is backed by a StringBuilder and is used to accumulate code to be printed to a file. Its main function is to handle indentation.
| org.lflang.generator.CodeBuilder.CodeBuilder | ( | ) |
Construct a new empty code emitter.
| org.lflang.generator.CodeBuilder.CodeBuilder | ( | CodeBuilder | model | ) |
Construct a new code emitter with the text and indentation of the specified code emitter.
| model | The model code emitter. |
| void org.lflang.generator.CodeBuilder.endChannelIteration | ( | PortInstance | port | ) |
If the specified port is a multiport, then start a specified iteration over the channels of the multiport using as the channel index the variable name returned by CUtil#channelIndex(PortInstance).
If the port is not a multiport, do nothing.
| port | The port. |
| void org.lflang.generator.CodeBuilder.endScopedBankChannelIteration | ( | PortInstance | port, |
| String | count ) |
End a scoped block to iterate over bank members and channels for the specified port with a variable with the name given by count counting the iterations.
| port | The port. |
| count | The variable name to use for the counter, or null to not provide a counter. |
| void org.lflang.generator.CodeBuilder.endScopedBlock | ( | ) |
| void org.lflang.generator.CodeBuilder.endScopedRangeBlock | ( | RuntimeRange< PortInstance > | range | ) |
End a scoped block for the specified range.
| range | The send range. |
| void org.lflang.generator.CodeBuilder.endScopedRangeBlock | ( | SendRange | srcRange, |
| RuntimeRange< PortInstance > | dstRange ) |
End a scoped block that iterates over the specified pair of ranges.
| srcRange | The send range. |
| dstRange | The destination range. |
| String org.lflang.generator.CodeBuilder.getCode | ( | ) |
Get the code produced so far.
| void org.lflang.generator.CodeBuilder.indent | ( | ) |
Increase the indentation of the output code produced.
| void org.lflang.generator.CodeBuilder.insert | ( | int | position, |
| String | text ) |
Insert the specified text at the specified position.
| position | The position. |
| text | The text. |
| int org.lflang.generator.CodeBuilder.length | ( | ) |
Return the length of the code in characters.
| void org.lflang.generator.CodeBuilder.newLine | ( | ) |
Add a new line.
| void org.lflang.generator.CodeBuilder.pr | ( | CharSequence | text | ) |
Append the given text to the code buffer at the current indentation level.
| void org.lflang.generator.CodeBuilder.pr | ( | String | format, |
| Object... | args ) |
Append the specified text plus a final newline.
| format | A format string to be used by String.format or the text to append if no further arguments are given. |
| args | Additional arguments to pass to the formatter. |
| void org.lflang.generator.CodeBuilder.prComment | ( | String | comment | ) |
Append a single-line, C-style comment to the code.
| comment | The comment. |
| void org.lflang.generator.CodeBuilder.prEndSourceLineNumber | ( | boolean | suppress | ) |
Print a tag marking the end of a block corresponding to the source LF file.
| suppress | Do nothing if true. |
| void org.lflang.generator.CodeBuilder.prSourceLineNumber | ( | EObject | eObject, |
| boolean | suppress ) |
Print the #line compiler directive with the line number of the specified object.
| eObject | The node. |
| suppress | Do nothing if true. |
| CodeBuilder org.lflang.generator.CodeBuilder.removeLines | ( | String | prefix | ) |
Remove all lines that start with the specified prefix and return a new CodeBuilder with the result.
| prefix | The prefix. |
| void org.lflang.generator.CodeBuilder.startChannelIteration | ( | PortInstance | port | ) |
If the specified port is a multiport, then start a specified iteration over the channels of the multiport using as the channel index the variable name returned by CUtil#channelIndex(PortInstance).
If the port is not a multiport, do nothing. This is required to be followed by endChannelIteration(PortInstance).
| port | The port. |
| void org.lflang.generator.CodeBuilder.startScopedBankChannelIteration | ( | PortInstance | port, |
| String | count ) |
Start a scoped block to iterate over bank members and channels for the specified port with a variable with the name given by count counting the iterations.
If this port is a multiport, then the channel index variable name is that returned by CUtil#channelIndex(PortInstance).
This block is intended to be nested, where each block is put within a similar block for the reactor's parent.
This is required to be followed by a call to endScopedBankChannelIteration(PortInstance, String).
| port | The port. |
| count | The variable name to use for the counter, or null to not provide a counter. |
| void org.lflang.generator.CodeBuilder.startScopedBlock | ( | ) |
Start a scoped block, which is a section of code surrounded by curley braces and indented.
This must be followed by an endScopedBlock().
| void org.lflang.generator.CodeBuilder.startScopedBlock | ( | ReactorInstance | reactor | ) |
Start a scoped block for the specified reactor.
If the reactor is a bank, then this starts a for loop that iterates over the bank members using a standard index variable whose name is that returned by CUtil#bankIndex(ReactorInstance). If the reactor is null or is not a bank, then this simply starts a scoped block by printing an opening curly brace. This also adds a declaration of a pointer to the self struct of the reactor or bank member.
This block is intended to be nested, where each block is put within a similar block for the reactor's parent. This ensures that all (possibly nested) bank index variables are defined within the block.
This must be followed by an endScopedBlock().
| reactor | The reactor instance. |
| void org.lflang.generator.CodeBuilder.startScopedRangeBlock | ( | RuntimeRange< PortInstance > | range, |
| String | runtimeIndex, | ||
| String | bankIndex, | ||
| String | channelIndex, | ||
| boolean | nested ) |
Start a scoped block that iterates over the specified range of port channels.
This must be followed by a call to endScopedRangeBlock.
This block should NOT be nested, where each block is put within a similar block for the reactor's parent. Within the created block, every use of CUtil#reactorRef(ReactorInstance, String) must provide the second argument, a runtime index variable name, that must match the runtimeIndex parameter given here.
| range | The range of port channels. |
| runtimeIndex | A variable name to use to index the runtime instance of either port's parent or the port's parent's parent (if nested is true), or null to use the default, "runtime_index". |
| bankIndex | A variable name to use to index the bank of the port's parent or null to use the default, the string returned by CUtil#bankIndexName(ReactorInstance). |
| channelIndex | A variable name to use to index the channel or null to use the default, the string returned by CUtil#channelIndexName(PortInstance). |
| nested | If true, then the runtimeIndex variable will be set to the bank index of the port's parent's parent rather than the port's parent. |
| void org.lflang.generator.CodeBuilder.startScopedRangeBlock | ( | SendRange | srcRange, |
| RuntimeRange< PortInstance > | dstRange ) |
Start a scoped block that iterates over the specified pair of ranges.
The destination range can be wider than the source range, in which case the source range is reused until the destination range is filled. The following integer variables will be defined within the scoped block:
For convenience, the above variable names are defined in the private class variables sc, sb, sr, and dc, db, dr.
This block should NOT be nested, where each block is put within a similar block for the reactor's parent. Within the created block, every use of CUtil#reactorRef(ReactorInstance, String) and related functions must provide the above variable names.
This must be followed by a call to endScopedRangeBlock.
| srcRange | The send range. |
| dstRange | The destination range. |
| String org.lflang.generator.CodeBuilder.toString | ( | ) |
Return the code as a string.
| void org.lflang.generator.CodeBuilder.unindent | ( | ) |
Reduce the indentation by one level for generated code/.
| CodeMap org.lflang.generator.CodeBuilder.writeToFile | ( | String | path | ) | throws IOException |
Write the text to a file.
| path | The file to write the code to. |