Skip to content

Commit 42fc1ad

Browse files
committed
More docs
1 parent dd61844 commit 42fc1ad

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcConnectionGenerator.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ class UcConnectionGenerator(
138138
} else {
139139
UcChannelQueue(portVarRef, emptyList())
140140
}
141-
142141
}
143142

144-
145143
companion object {
146144
private val Connection.delayString
147145
get(): String = this.delay.orNever().toCCode()
@@ -151,6 +149,11 @@ class UcConnectionGenerator(
151149
/** A global list of FederatedConnectionBundles. It is computed once and reused when code-generating */
152150
private var allFederatedConnectionBundles: List<UcFederatedConnectionBundle> = emptyList()
153151

152+
/**
153+
* This function takes a list of grouped connections and creates the necessary FederatedConnectionBundles.
154+
* The bundles are written to the global variable allFederatedConnectionBundles and shared accross federates.
155+
* Thus, this function should only be called once during code-gen.
156+
*/
154157
private fun createFederatedConnectionBundles(groupedConnections: List<UcGroupedConnection>) {
155158
val groupedSet = HashSet(groupedConnections)
156159
val bundles = mutableListOf<UcFederatedConnectionBundle>()
@@ -181,14 +184,15 @@ class UcConnectionGenerator(
181184
}
182185

183186
init {
187+
// Only pass through all federates and add NetworkInterface objects to them once.
184188
if (isFederated && !federateInterfacesInitialized) {
185189
for (fed in allFederates) {
186190
UcNetworkInterfaceFactory.createInterfaces(fed).forEach { fed.addInterface(it) }
187191
}
188192
federateInterfacesInitialized = true
189193
}
190194

191-
// Only parse out federated connection bundles once for the very first federate
195+
// Parse out all GroupedConnections. Note that this is repeated for each federate.
192196
val channels = mutableListOf<UcConnectionChannel>()
193197
reactor.allConnections.forEach { channels.addAll(parseConnectionChannels(it, allFederates)) }
194198
val grouped = groupConnections(channels)
@@ -212,10 +216,11 @@ class UcConnectionGenerator(
212216
.filter { it.channels.fold(true) { acc, c -> acc && (c.src.federate == currentFederate) } }
213217
)
214218
} else {
219+
// In the non-federated case, all grouped connections are handled togehter.
215220
nonFederatedConnections.addAll(grouped)
216221
}
217222

218-
// Assign a unique ID to each connection to avoid possible naming conflicts.
223+
// Assign a unique ID to each connection to avoid possible naming conflicts in the generated code.
219224
val allGroupedConnections =
220225
federatedConnectionBundles.map { it.groupedConnections }.flatten().plus(nonFederatedConnections)
221226
allGroupedConnections.forEachIndexed { idx, el ->

0 commit comments

Comments
 (0)