Drop extra fields which covered by metadata: staticRef from JsName.
This commit is contained in:
@@ -14,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JsName extends HasMetadata implements Symbol {
|
||||
private final JsScope enclosing;
|
||||
private final String ident;
|
||||
private JsNode staticRef = null;
|
||||
|
||||
/**
|
||||
* @param ident the unmangled ident to use for this name
|
||||
@@ -28,14 +27,6 @@ public class JsName extends HasMetadata implements Symbol {
|
||||
return ident;
|
||||
}
|
||||
|
||||
public JsNode getStaticRef() {
|
||||
return staticRef;
|
||||
}
|
||||
|
||||
public void setStaticRef(JsNode staticRef) {
|
||||
this.staticRef = staticRef;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsNameRef makeRef() {
|
||||
return new JsNameRef(this);
|
||||
|
||||
+4
-3
@@ -17,11 +17,11 @@
|
||||
package org.jetbrains.k2js.inline.clean
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*
|
||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
|
||||
import com.intellij.util.containers.Stack
|
||||
import java.util.IdentityHashMap
|
||||
import org.jetbrains.k2js
|
||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
||||
import org.jetbrains.k2js.inline.util.collectReferencesInside
|
||||
import org.jetbrains.k2js.inline.util.collectFunctionReferencesInside
|
||||
|
||||
@@ -100,6 +100,7 @@ private class UnusedLocalFunctionsCollector(functions: Map<JsName, JsFunction>)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO drop name param?
|
||||
private fun processNonLocalFunction(name: JsName, function: JsFunction) {
|
||||
for (referenced in collectFunctionReferencesInside(function)) {
|
||||
tracker.markReachable(referenced)
|
||||
@@ -107,7 +108,7 @@ private class UnusedLocalFunctionsCollector(functions: Map<JsName, JsFunction>)
|
||||
}
|
||||
|
||||
private fun isFunctionReference(nameRef: HasName?): Boolean {
|
||||
return nameRef?.getName()?.getStaticRef() is JsFunction
|
||||
return nameRef?.getName()?.staticRef is JsFunction
|
||||
}
|
||||
|
||||
private fun wasProcessed(function: JsFunction?): Boolean = function in processed
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.k2js.inline.clean
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.IdentityHashMap
|
||||
@@ -78,8 +79,8 @@ private class UnusedInstanceCollector : JsVisitorWithContextImpl() {
|
||||
private fun isLocalFunctionDeclaration(jsVar: JsVars.JsVar): Boolean {
|
||||
val name = jsVar.getName()
|
||||
val expr = jsVar.getInitExpression()
|
||||
val staticRef = name?.getStaticRef()
|
||||
val staticRef = name?.staticRef
|
||||
|
||||
return staticRef != null && staticRef == expr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.google.dart.compiler.backend.js.ast.JsName
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
import com.google.dart.compiler.backend.js.ast.JsScope
|
||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
|
||||
import org.jetbrains.k2js.inline.util.aliasArgumentsIfNeeded
|
||||
import org.jetbrains.k2js.inline.util.getInnerFunction
|
||||
import org.jetbrains.k2js.inline.util.getSimpleName
|
||||
@@ -70,7 +72,7 @@ abstract class FunctionContext(
|
||||
val callName = getSimpleName(call)
|
||||
if (callName == null) continue
|
||||
|
||||
val staticRef = callName.getStaticRef()
|
||||
val staticRef = callName.staticRef
|
||||
if (staticRef !is JsFunction) continue
|
||||
|
||||
val functionCalled = staticRef as JsFunction
|
||||
@@ -125,7 +127,7 @@ abstract class FunctionContext(
|
||||
|
||||
/** in case 4, 5 get ref (reduce 4, 5 to 2, 3 accordingly) */
|
||||
if (callQualifier is JsNameRef) {
|
||||
val staticRef = (callQualifier as JsNameRef).getName()?.getStaticRef()
|
||||
val staticRef = (callQualifier as JsNameRef).getName()?.staticRef
|
||||
|
||||
callQualifier = when (staticRef) {
|
||||
is JsNameRef -> staticRef
|
||||
@@ -191,4 +193,4 @@ abstract class FunctionContext(
|
||||
|
||||
return innerClone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,18 @@
|
||||
package org.jetbrains.k2js.inline.util
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*
|
||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.IdentityHashMap
|
||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
||||
import org.jetbrains.k2js.inline.util.collectors.ReferenceNameCollector
|
||||
import org.jetbrains.k2js.inline.util.collectors.NameCollector
|
||||
import org.jetbrains.k2js.inline.util.collectors.InstanceCollector
|
||||
import org.jetbrains.k2js.inline.util.collectors.FunctionCollector
|
||||
|
||||
public fun collectFunctionReferencesInside(scope: JsNode): List<JsName> =
|
||||
collectReferencesInside(scope) filter { it.getStaticRef() is JsFunction }
|
||||
collectReferencesInside(scope) filter { it.staticRef is JsFunction }
|
||||
|
||||
public fun collectReferencesInside(scope: JsNode): List<JsName> {
|
||||
return with(ReferenceNameCollector()) {
|
||||
@@ -57,4 +58,4 @@ public fun collectInstances<T : JsNode>(klass: Class<T>, scope: JsNode): List<T>
|
||||
accept(scope)
|
||||
collected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.dart.compiler.backend.js.ast.JsReturn
|
||||
import org.jetbrains.k2js.translate.context.Namer
|
||||
import com.google.dart.compiler.backend.js.ast.HasName
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
|
||||
/**
|
||||
* Gets invocation qualifier name.
|
||||
@@ -121,5 +122,5 @@ private fun getCallerQualifierImpl(invocation: JsInvocation): JsExpression? {
|
||||
private fun getStaticRef(invocation: JsInvocation): JsNode? {
|
||||
val qualifier = invocation.getQualifier()
|
||||
val qualifierName = (qualifier as? HasName)?.getName()
|
||||
return qualifierName?.getStaticRef()
|
||||
}
|
||||
return qualifierName?.staticRef
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
import com.google.dart.compiler.backend.js.ast.JsObjectScope
|
||||
import com.google.dart.compiler.backend.js.ast.JsFunction
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
|
||||
class DefinitionPlace(
|
||||
private val scope: JsObjectScope,
|
||||
@@ -33,7 +34,7 @@ class DefinitionPlace(
|
||||
if (expression is JsFunction) {
|
||||
/** JsInliner should be able
|
||||
* to find function by name */
|
||||
name.setStaticRef(expression)
|
||||
name.staticRef = expression
|
||||
}
|
||||
|
||||
properties.add(JsPropertyInitializer(name.makeRef(), expression))
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.k2js.translate.expression;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
@@ -401,7 +402,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
FunctionDescriptor descriptor = getFunctionDescriptor(context.bindingContext(), expression);
|
||||
JsName name = context.getNameForDescriptor(descriptor);
|
||||
if (InlineUtil.getInlineType(descriptor).isInline()) {
|
||||
name.setStaticRef(alias);
|
||||
MetadataPackage.setStaticRef(name, alias);
|
||||
}
|
||||
|
||||
return new JsVars(new JsVars.JsVar(name, alias)).source(expression);
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.k2js.translate.expression
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
|
||||
@@ -167,7 +168,7 @@ private fun moveCapturedLocalInside(capturingFunction: JsFunction, capturedName:
|
||||
}
|
||||
|
||||
private fun declareAliasInsideFunction(function: JsFunction, name: JsName, alias: JsExpression) {
|
||||
name.setStaticRef(alias)
|
||||
name.staticRef = alias
|
||||
function.getInnerFunction()?.addDeclaration(name, alias)
|
||||
}
|
||||
|
||||
@@ -193,7 +194,7 @@ private fun JsFunction.addDeclaration(name: JsName, value: JsExpression?) {
|
||||
}
|
||||
|
||||
private fun HasName.getStaticRef(): JsNode? {
|
||||
return this.getName()?.getStaticRef()
|
||||
return this.getName()?.staticRef
|
||||
}
|
||||
|
||||
private fun isLocalInlineDeclaration(descriptor: CallableDescriptor): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user