@@ -17,11 +17,16 @@ private const val MANGLED_VALUE_PROP = "kotlinx\$atomicfu\$value"
17
17
18
18
private const val TRACE_CONSTRUCTOR = " atomicfu\\ \$ Trace\\ \$ "
19
19
private const val TRACE_APPEND = " atomicfu\\ \$ Trace\\ \$ append\\ \$ "
20
+ private const val TRACE_NAMED = " atomicfu\\ \$ Trace\\ \$ named\\ \$ "
21
+ private const val TRACE_FORMAT = " TraceFormat"
22
+ private const val TRACE_FORMAT_CONSTRUCTOR = " atomicfu\\ \$ $TRACE_FORMAT \\ \$ "
23
+ private const val TRACE_FORMAT_FORMAT = " atomicfu\\ \$ TraceFormat\\ \$ format\\ \$ "
20
24
21
25
private const val RECEIVER = " \$ receiver"
22
26
private const val SCOPE = " scope"
23
27
private const val FACTORY = " factory"
24
28
private const val REQUIRE = " require"
29
+ private const val PROTOTYPE = " prototype"
25
30
private const val KOTLINX_ATOMICFU = " 'kotlinx-atomicfu'"
26
31
private const val KOTLINX_ATOMICFU_PACKAGE = " kotlinx.atomicfu"
27
32
private const val KOTLIN_TYPE_CHECK = " Kotlin.isType"
@@ -33,6 +38,7 @@ private const val GET_ELEMENT = "get\\\$atomicfu"
33
38
private const val LOCKS = " locks"
34
39
private const val REENTRANT_LOCK_ATOMICFU_SINGLETON = " $LOCKS .reentrantLock\\ \$ atomicfu"
35
40
41
+
36
42
private val MANGLE_VALUE_REGEX = Regex (" .${Pattern .quote(MANGLED_VALUE_PROP )} " )
37
43
// matches index until the first occurence of ')', parenthesised index expressions not supported
38
44
private val ARRAY_GET_ELEMENT_REGEX = Regex (" .$GET_ELEMENT \\ ((.*)\\ )" )
@@ -44,6 +50,7 @@ class AtomicFUTransformerJS(
44
50
private val atomicConstructors = mutableSetOf<String >()
45
51
private val atomicArrayConstructors = mutableMapOf<String , String ?>()
46
52
private val traceConstructors = mutableSetOf<String >()
53
+ private val traceFormatObjects = mutableSetOf<String >()
47
54
48
55
override fun transform () {
49
56
info(" Transforming to $outputDir " )
@@ -122,10 +129,10 @@ class AtomicFUTransformerJS(
122
129
}
123
130
}
124
131
Token .FUNCTION -> {
125
- // erasing 'kotlinx-atomicfu' module passed as parameter
126
132
if (node is FunctionNode ) {
127
133
val it = node.params.listIterator()
128
134
while (it.hasNext()) {
135
+ // erasing 'kotlinx-atomicfu' module passed as parameter
129
136
if (isAtomicfuModule(it.next())) {
130
137
it.remove()
131
138
}
@@ -208,13 +215,19 @@ class AtomicFUTransformerJS(
208
215
} else if (initializer.matches(Regex (kotlinxAtomicfuModuleName(TRACE_CONSTRUCTOR )))) {
209
216
traceConstructors.add(varInit.target.toSource())
210
217
node.replaceChild(stmt, EmptyLine ())
211
- } else if (initializer.matches(Regex (kotlinxAtomicfuModuleName(LOCKS ) ))){
218
+ } else if (initializer.matches(Regex (kotlinxAtomicfuModuleName(""" ( $ LOCKS| $TRACE_FORMAT_CONSTRUCTOR | $TRACE_NAMED ) """ )))) {
212
219
node.replaceChild(stmt, EmptyLine ())
213
220
}
214
221
}
215
222
}
216
223
}
217
224
}
225
+ if (node is PropertyGet && node.property.toSource().matches(Regex (TRACE_FORMAT_FORMAT ))) {
226
+ val target = node.target
227
+ if (target is PropertyGet && target.property.toSource().matches(Regex (PROTOTYPE ))) {
228
+ traceFormatObjects.add(target.target.toSource())
229
+ }
230
+ }
218
231
if (node is VariableInitializer && node.initializer is PropertyGet ) {
219
232
val initializer = node.initializer.toSource()
220
233
if (initializer.matches(Regex (REENTRANT_LOCK_ATOMICFU_SINGLETON ))) {
@@ -333,6 +346,35 @@ class AtomicFUTransformerJS(
333
346
}
334
347
}
335
348
}
349
+ if (node is Assignment && node.left is PropertyGet ) {
350
+ val left = node.left as PropertyGet
351
+ if (traceFormatObjects.contains(left.target.toSource())) {
352
+ if (node.right is FunctionCall ) {
353
+ // TraceFormatObject initialization
354
+ (node.right as FunctionCall ).arguments = listOf (Name ().also { it.identifier = " null" })
355
+ }
356
+ }
357
+ }
358
+ // remove TraceFormatObject constructor definition
359
+ if (node is FunctionNode && traceFormatObjects.contains(node.name)) {
360
+ val body = node.body
361
+ for (stmt in body) { body.replaceChild(stmt, EmptyLine ()) }
362
+ }
363
+ // remove TraceFormat from TraceFormatObject interfaces
364
+ if (node is Assignment && node.left is PropertyGet && node.right is ObjectLiteral ) {
365
+ val left = node.left as PropertyGet
366
+ val metadata = node.right as ObjectLiteral
367
+ if (traceFormatObjects.contains(left.target.toSource())) {
368
+ for (e in metadata.elements) {
369
+ if (e.right is ArrayLiteral ) {
370
+ val array = (e.right as ArrayLiteral ).toSource()
371
+ if (array.contains(TRACE_FORMAT )) {
372
+ (e.right as ArrayLiteral ).elements = emptyList()
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
336
378
return true
337
379
}
338
380
@@ -543,7 +585,7 @@ class AtomicFUTransformerJS(
543
585
}
544
586
}
545
587
546
- private class EmptyLine : EmptyExpression () {
588
+ private class EmptyLine : EmptyExpression () {
547
589
override fun toSource (depth : Int ) = " \n "
548
590
}
549
591
0 commit comments