@@ -131,7 +131,7 @@ private data class InlineModuleWithWriter(val inlineModule : RustModule.LeafModu
131
131
private val crateToInlineModule: ConcurrentHashMap <RustCrate , InnerModule > =
132
132
ConcurrentHashMap ()
133
133
134
- class InnerModule (private val debugMode : Boolean ) {
134
+ class InnerModule (debugMode : Boolean ) {
135
135
private val topLevelModuleWriters: MutableSet <RustWriter > = mutableSetOf ()
136
136
private val inlineModuleWriters: HashMap <RustWriter , MutableList <InlineModuleWithWriter >> = hashMapOf()
137
137
private val docWriters: HashMap <RustModule .LeafModule , MutableList <DocWriter >> = hashMapOf()
@@ -179,10 +179,10 @@ class InnerModule(private val debugMode : Boolean) {
179
179
rustCrate.withModule(topMost) {
180
180
var writer = this
181
181
hierarchy.forEach {
182
- writer = getWriter(writer, it as RustModule . LeafModule )
182
+ writer = getWriter(writer, it)
183
183
}
184
184
185
- withInlineModule(writer, bottomMost as RustModule . LeafModule , docWriter, writable)
185
+ withInlineModule(writer, bottomMost, docWriter, writable)
186
186
}
187
187
} else {
188
188
check(! bottomMost.isInline()) {
@@ -214,10 +214,10 @@ class InnerModule(private val debugMode : Boolean) {
214
214
// Create an entry in the HashMap for all the descendent modules in the hierarchy.
215
215
var writer = outerWriter
216
216
hierarchy.forEach {
217
- writer = getWriter(writer, it as RustModule . LeafModule )
217
+ writer = getWriter(writer, it)
218
218
}
219
219
220
- withInlineModule(writer, bottomMost as RustModule . LeafModule , docWriter, writable)
220
+ withInlineModule(writer, bottomMost, docWriter, writable)
221
221
}
222
222
223
223
/* *
@@ -228,7 +228,7 @@ class InnerModule(private val debugMode : Boolean) {
228
228
var hierarchy = listOf<RustModule .LeafModule >()
229
229
230
230
while (current is RustModule .LeafModule ) {
231
- hierarchy = listOf (current as RustModule . LeafModule ) + hierarchy
231
+ hierarchy = listOf (current) + hierarchy
232
232
current = current.parent
233
233
}
234
234
@@ -275,7 +275,6 @@ class InnerModule(private val debugMode : Boolean) {
275
275
* has never been registered before then a new `RustWriter` is created and returned.
276
276
*/
277
277
private fun getWriter (outerWriter : RustWriter , inlineModule : RustModule .LeafModule ): RustWriter {
278
- // Is this one of our inner writers?
279
278
val nestedModuleWriter = inlineModuleWriters[outerWriter]
280
279
if (nestedModuleWriter != null ) {
281
280
return findOrAddToList(nestedModuleWriter, inlineModule)
@@ -301,16 +300,42 @@ class InnerModule(private val debugMode : Boolean) {
301
300
inlineModuleList : MutableList <InlineModuleWithWriter >,
302
301
lookForModule : RustModule .LeafModule
303
302
): RustWriter {
304
- val inlineModule = inlineModuleList.firstOrNull() {
305
- it.inlineModule == lookForModule
303
+ val inlineModuleAndWriter = inlineModuleList.firstOrNull() {
304
+ it.inlineModule.name == lookForModule.name
306
305
}
307
- return if (inlineModule == null ) {
306
+ return if (inlineModuleAndWriter == null ) {
308
307
val inlineWriter = createNewInlineModule()
309
308
inlineModuleList.add(InlineModuleWithWriter (lookForModule, inlineWriter))
310
309
inlineWriter
311
310
} else {
312
- inlineModule.writer
311
+ check(inlineModuleAndWriter.inlineModule == lookForModule) {
312
+ " the two inline modules have the same name but different attributes on them"
313
+ }
314
+
315
+ inlineModuleAndWriter.writer
316
+ }
317
+ }
318
+
319
+ private fun combine (inlineModuleWithWriter : InlineModuleWithWriter , inlineModule : RustModule .LeafModule ) : InlineModuleWithWriter {
320
+ check(inlineModuleWithWriter.inlineModule.name == inlineModule.name) {
321
+ " only inline module objects that have the same name can be combined"
322
+ }
323
+ check(inlineModuleWithWriter.inlineModule.rustMetadata.visibility == inlineModule.rustMetadata.visibility) {
324
+ " only inline modules with same visibility can be combined"
313
325
}
326
+ check(inlineModuleWithWriter.inlineModule.inline && inlineModule.inline) {
327
+ " both modules need to be inline to be combined together"
328
+ }
329
+
330
+ val newModule = RustModule .new(
331
+ name = inlineModule.name,
332
+ parent = inlineModuleWithWriter.inlineModule.parent,
333
+ documentation = inlineModuleWithWriter.inlineModule.documentation?.plus(" \n " )?.plus(inlineModule.documentation) ? : inlineModule.documentation,
334
+ visibility = inlineModule.rustMetadata.visibility,
335
+ additionalAttributes = inlineModuleWithWriter.inlineModule.rustMetadata.additionalAttributes + inlineModule.rustMetadata.additionalAttributes,
336
+ inline = inlineModule.inline
337
+ )
338
+ return InlineModuleWithWriter (newModule, inlineModuleWithWriter.writer)
314
339
}
315
340
316
341
private fun writeDocs (innerModule : RustModule .LeafModule ) {
0 commit comments