JS backend: Fix tracked used descriptors

This commit is contained in:
Erokhin Stanislav
2013-12-27 17:33:26 +04:00
parent 4617e730d6
commit 75dd459bdf
6 changed files with 59 additions and 7 deletions
@@ -72,4 +72,16 @@ public final class ClosureTest extends SingleFileTranslationTest {
public void testClosureThisInConstructor() throws Exception {
checkFooBoxIsOk();
}
public void testClosureFunctionAsArgument() throws Exception {
checkFooBoxIsOk();
}
public void testClosureLocalFunction() throws Exception {
checkFooBoxIsOk();
}
public void testClosureLocalLiteralFunction() throws Exception {
checkFooBoxIsOk();
}
}
@@ -164,7 +164,6 @@ public final class StaticContext {
packageFqName.isRoot() ? null : getQualifierForParentPackage(packageFqName.parent()));
}
// TODO: usage tracker
@NotNull
public JsName getNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
JsName name = names.get(descriptor.getOriginal());
@@ -171,6 +171,7 @@ public class TranslationContext {
@NotNull
public JsName getNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
descriptorUsedInThisContext(descriptor); // TODO drop this
return staticContext.getNameForDescriptor(descriptor);
}
@@ -186,6 +187,7 @@ public class TranslationContext {
@NotNull
public JsNameRef getQualifiedReference(@NotNull DeclarationDescriptor descriptor) {
descriptorUsedInThisContext(descriptor); // TODO drop this
return staticContext.getQualifiedReference(descriptor);
}
@@ -261,9 +263,7 @@ public class TranslationContext {
@Nullable
public JsExpression getAliasForDescriptor(@NotNull DeclarationDescriptor descriptor) {
if (usageTracker != null) {
usageTracker.triggerUsed(descriptor);
}
descriptorUsedInThisContext(descriptor);
return aliasingContext.getAliasForDescriptor(descriptor);
}
@@ -278,9 +278,7 @@ public class TranslationContext {
effectiveDescriptor = descriptor;
}
if (usageTracker != null) {
usageTracker.triggerUsed(effectiveDescriptor);
}
descriptorUsedInThisContext(effectiveDescriptor);
JsExpression alias = aliasingContext.getAliasForDescriptor(effectiveDescriptor);
return alias == null ? JsLiteral.THIS : alias;
@@ -297,4 +295,10 @@ public class TranslationContext {
public JsNameRef define(String name, JsExpression expression) {
return getDefinitionPlace().define(name, expression);
}
private void descriptorUsedInThisContext(DeclarationDescriptor effectiveDescriptor) {
if (usageTracker != null) {
usageTracker.triggerUsed(effectiveDescriptor);
}
}
}
@@ -0,0 +1,11 @@
package foo
fun test(f: () -> String): String {
val funLit = { f() }
return funLit()
}
fun box(): String {
return test { "OK" }
}
@@ -0,0 +1,12 @@
package foo
fun test(): String {
fun f(): String = "OK"
val funLit = { f() }
return funLit()
}
fun box(): String {
return test()
}
@@ -0,0 +1,14 @@
package foo
val k = {"K"}
fun test(): String {
val o = {"O"}
val funLit = { o() + k() }
return funLit()
}
fun box(): String {
return test()
}