@@ -12,7 +12,6 @@ import java.util.concurrent.ConcurrentHashMap
12
12
typealias DocWriter = () -> Any
13
13
typealias InlineModuleCreator = (Symbol , Writable ) -> Unit
14
14
15
-
16
15
/* *
17
16
* Initializes RustCrate -> InnerModule data structure.
18
17
*/
@@ -40,7 +39,7 @@ fun RustCrate.createInlineModuleCreator(): InlineModuleCreator {
40
39
41
40
/* *
42
41
* If the passed in `shape` is a synthetic extracted shape resulting from a constrained struct member,
43
- * the `Writable` is called using the structure's builder module. Otherwise the `Writable` is called
42
+ * the `Writable` is called using the structure's builder module. Otherwise, the `Writable` is called
44
43
* using the given `module`.
45
44
*/
46
45
fun RustCrate.withModuleOrWithStructureBuilderModule (
@@ -133,22 +132,15 @@ private val crateToInlineModule: ConcurrentHashMap<RustCrate, InnerModule> =
133
132
134
133
class InnerModule (debugMode : Boolean ) {
135
134
private val topLevelModuleWriters: MutableSet <RustWriter > = mutableSetOf ()
136
- private val inlineModuleWriters: HashMap <RustWriter , MutableList <InlineModuleWithWriter >> = hashMapOf ()
137
- private val docWriters: HashMap <RustModule .LeafModule , MutableList <DocWriter >> = hashMapOf ()
135
+ private val inlineModuleWriters: ConcurrentHashMap <RustWriter , MutableList <InlineModuleWithWriter >> = ConcurrentHashMap ()
136
+ private val docWriters: ConcurrentHashMap <RustModule .LeafModule , MutableList <DocWriter >> = ConcurrentHashMap ()
138
137
private val writerCreator = RustWriter .factory(debugMode)
139
138
private val emptyLineCount: Int = writerCreator
140
139
.apply (" lines-it-always-writes.rs" , " crate" )
141
140
.toString()
142
141
.split(" \n " )[0 ]
143
142
.length
144
143
145
- private fun createNewInlineModule (): RustWriter {
146
- val writer = writerCreator.apply (" unknown-module-would-never-be-written.rs" , " crate" )
147
- // There has never been a child of the top most inner module, hence create a new one
148
- inlineModuleWriters[writer] = mutableListOf ()
149
- return writer
150
- }
151
-
152
144
fun withInlineModule (outerWriter : RustWriter , innerModule : RustModule .LeafModule , docWriter : DocWriter ? = null, writable : Writable ) {
153
145
if (docWriter != null ) {
154
146
val moduleDocWriterList = docWriters.getOrPut(innerModule) { mutableListOf () }
@@ -220,6 +212,17 @@ class InnerModule(debugMode : Boolean) {
220
212
withInlineModule(writer, bottomMost, docWriter, writable)
221
213
}
222
214
215
+ /* *
216
+ * Creates an in memory writer and registers it with a map of RustWriter -> listOf(Inline descendent modules)
217
+ */
218
+ private fun createNewInlineModule (): RustWriter {
219
+ val writer = writerCreator.apply (" unknown-module-would-never-be-written.rs" , " crate" )
220
+ // Register the new RustWriter in the map to allow further descendent inline modules to be created inside it.
221
+ inlineModuleWriters[writer] = mutableListOf ()
222
+ return writer
223
+ }
224
+
225
+
223
226
/* *
224
227
* Returns the complete hierarchy of a `RustModule.LeafModule` from top to bottom
225
228
*/
@@ -316,28 +319,6 @@ class InnerModule(debugMode : Boolean) {
316
319
}
317
320
}
318
321
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"
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)
339
- }
340
-
341
322
private fun writeDocs (innerModule : RustModule .LeafModule ) {
342
323
docWriters[innerModule]?.forEach{
343
324
it()
0 commit comments