Rename package k2js -> kotlin.js in js.inliner
org.jetbrains.k2js.inline -> org.jetbrains.kotlin.js.inline
This commit is contained in:
+10
-17
@@ -14,37 +14,30 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline;
|
package org.jetbrains.kotlin.js.inline;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.k2js.inline.context.*;
|
import org.jetbrains.kotlin.js.inline.context.FunctionContext;
|
||||||
|
import org.jetbrains.kotlin.js.inline.context.InliningContext;
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.aliasArgumentsIfNeeded;
|
import org.jetbrains.kotlin.js.inline.context.NamingContext;
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.collectInstances;
|
import org.jetbrains.kotlin.js.inline.context.StatementContext;
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.getCallerQualifier;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.getSimpleIdent;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.hasCallerQualifier;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.isCallInvocation;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.needToAlias;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.renameLocalNames;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.replaceReturns;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.replaceThisReference;
|
|
||||||
import static org.jetbrains.k2js.inline.clean.CleanPackage.removeDefaultInitializers;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.kotlin.js.inline.clean.CleanPackage.removeDefaultInitializers;
|
||||||
|
import static org.jetbrains.kotlin.js.inline.util.UtilPackage.*;
|
||||||
|
|
||||||
class FunctionInlineMutator {
|
class FunctionInlineMutator {
|
||||||
|
|
||||||
private final JsInvocation call;
|
private final JsInvocation call;
|
||||||
private final InliningContext inliningContext;
|
private final InliningContext inliningContext;
|
||||||
private final FunctionContext functionContext;
|
|
||||||
private final JsFunction invokedFunction;
|
private final JsFunction invokedFunction;
|
||||||
private final boolean isResultNeeded;
|
private final boolean isResultNeeded;
|
||||||
private final NamingContext namingContext;
|
private final NamingContext namingContext;
|
||||||
private JsBlock body;
|
private final JsBlock body;
|
||||||
private JsExpression resultExpr = null;
|
private JsExpression resultExpr = null;
|
||||||
private JsLabel breakLabel = null;
|
private JsLabel breakLabel = null;
|
||||||
|
|
||||||
@@ -73,7 +66,7 @@ class FunctionInlineMutator {
|
|||||||
this.inliningContext = inliningContext;
|
this.inliningContext = inliningContext;
|
||||||
this.call = call;
|
this.call = call;
|
||||||
|
|
||||||
functionContext = inliningContext.getFunctionContext();
|
FunctionContext functionContext = inliningContext.getFunctionContext();
|
||||||
invokedFunction = functionContext.getFunctionDefinition(call);
|
invokedFunction = functionContext.getFunctionDefinition(call);
|
||||||
body = invokedFunction.getBody().deepCopy();
|
body = invokedFunction.getBody().deepCopy();
|
||||||
isResultNeeded = isResultNeeded(call);
|
isResultNeeded = isResultNeeded(call);
|
||||||
+6
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,9 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline
|
package org.jetbrains.kotlin.js.inline
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
import com.google.dart.compiler.backend.js.ast.JsStatement
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
|
|
||||||
class InlineableResult(val inlineableBody: JsStatement, val resultExpression: JsExpression?)
|
class InlineableResult(
|
||||||
|
val inlineableBody: JsStatement,
|
||||||
|
val resultExpression: JsExpression?
|
||||||
|
)
|
||||||
+8
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,27 +14,25 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline;
|
package org.jetbrains.kotlin.js.inline;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage;
|
import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.types.lang.InlineStrategy;
|
import org.jetbrains.jet.lang.types.lang.InlineStrategy;
|
||||||
import org.jetbrains.k2js.inline.context.*;
|
import org.jetbrains.kotlin.js.inline.context.*;
|
||||||
import org.jetbrains.k2js.inline.exception.InlineRecursionException;
|
import org.jetbrains.kotlin.js.inline.exception.InlineRecursionException;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.inline.FunctionInlineMutator.getInlineableCallReplacement;
|
|
||||||
import static org.jetbrains.k2js.inline.clean.CleanPackage.removeUnusedFunctionDefinitions;
|
|
||||||
import static org.jetbrains.k2js.inline.clean.CleanPackage.removeUnusedLocalFunctionDeclarations;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.IdentitySet;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.collectNamedFunctions;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.refreshLabelNames;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.flattenStatement;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.flattenStatement;
|
||||||
|
import static org.jetbrains.kotlin.js.inline.FunctionInlineMutator.getInlineableCallReplacement;
|
||||||
|
import static org.jetbrains.kotlin.js.inline.clean.CleanPackage.removeUnusedFunctionDefinitions;
|
||||||
|
import static org.jetbrains.kotlin.js.inline.clean.CleanPackage.removeUnusedLocalFunctionDeclarations;
|
||||||
|
import static org.jetbrains.kotlin.js.inline.util.UtilPackage.*;
|
||||||
|
|
||||||
public class JsInliner extends JsVisitorWithContextImpl {
|
public class JsInliner extends JsVisitorWithContextImpl {
|
||||||
|
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.clean
|
package org.jetbrains.kotlin.js.inline.clean
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||||
+9
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,18 +14,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.clean
|
package org.jetbrains.kotlin.js.inline.clean
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
import org.jetbrains.kotlin.js.inline.util.IdentitySet
|
||||||
|
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
private class ReferenceTracker<Reference, RemoveCandidate : JsNode> {
|
private class ReferenceTracker<Reference, RemoveCandidate : JsNode> {
|
||||||
private val reachable = IdentityHashMap<Reference, Boolean>()
|
private val reachable = IdentityHashMap<Reference, Boolean>()
|
||||||
private val removableCandidates = IdentityHashMap<Reference, RemoveCandidate>()
|
private val removableCandidates = IdentityHashMap<Reference, RemoveCandidate>()
|
||||||
private val refereceFromTo = IdentityHashMap<Reference, MutableSet<Reference>>()
|
private val referenceFromTo = IdentityHashMap<Reference, MutableSet<Reference>>()
|
||||||
private val visited = IdentitySet<Reference>()
|
private val visited = IdentitySet<Reference>()
|
||||||
|
|
||||||
public val removable: List<RemoveCandidate>
|
public val removable: List<RemoveCandidate>
|
||||||
@@ -42,12 +41,12 @@ private class ReferenceTracker<Reference, RemoveCandidate : JsNode> {
|
|||||||
reachable.put(reference, false)
|
reachable.put(reference, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun addRemovableReference(referer: Reference, referenced: Reference) {
|
public fun addRemovableReference(referrer: Reference, referenced: Reference) {
|
||||||
if (!isKnown(referenced)) return
|
if (!isKnown(referenced)) return
|
||||||
|
|
||||||
getReferencedBy(referer).add(referenced)
|
getReferencedBy(referrer).add(referenced)
|
||||||
|
|
||||||
if (isReachable(referer)) {
|
if (isReachable(referrer)) {
|
||||||
markReachable(referenced)
|
markReachable(referenced)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,8 +64,8 @@ private class ReferenceTracker<Reference, RemoveCandidate : JsNode> {
|
|||||||
reachable[reference] = true
|
reachable[reference] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getReferencedBy(referer: Reference): MutableSet<Reference> {
|
private fun getReferencedBy(referrer: Reference): MutableSet<Reference> {
|
||||||
return refereceFromTo.getOrPut(referer, { IdentitySet<Reference>() })
|
return referenceFromTo.getOrPut(referrer, { IdentitySet<Reference>() })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isKnown(ref: Reference): Boolean {
|
private fun isKnown(ref: Reference): Boolean {
|
||||||
+4
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,21 +14,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.clean
|
package org.jetbrains.kotlin.js.inline.clean
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.metadata.hasDefaultValue
|
import com.google.dart.compiler.backend.js.ast.metadata.hasDefaultValue
|
||||||
|
|
||||||
import org.jetbrains.k2js.inline.util.toIdentitySet
|
import org.jetbrains.kotlin.js.inline.util.toIdentitySet
|
||||||
import org.jetbrains.k2js.inline.util.zipWithDefault
|
import org.jetbrains.kotlin.js.inline.util.zipWithDefault
|
||||||
import org.jetbrains.k2js.translate.context.Namer
|
import org.jetbrains.k2js.translate.context.Namer
|
||||||
import org.jetbrains.k2js.translate.context.Namer.isUndefined
|
import org.jetbrains.k2js.translate.context.Namer.isUndefined
|
||||||
import org.jetbrains.k2js.translate.utils.JsAstUtils.flattenStatement
|
import org.jetbrains.k2js.translate.utils.JsAstUtils.flattenStatement
|
||||||
|
|
||||||
import java.util.IdentityHashMap
|
|
||||||
import java.util.Collections
|
|
||||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes initializers for default parameters with defined arguments given
|
* Removes initializers for default parameters with defined arguments given
|
||||||
* Expands initializers for default parameters with undefined arguments given
|
* Expands initializers for default parameters with undefined arguments given
|
||||||
+4
-7
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,17 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.clean
|
package org.jetbrains.kotlin.js.inline.clean
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||||
import com.google.dart.compiler.backend.js.ast.metadata.isLocal
|
import com.google.dart.compiler.backend.js.ast.metadata.isLocal
|
||||||
|
|
||||||
import com.intellij.util.containers.Stack
|
import org.jetbrains.kotlin.js.inline.util.IdentitySet
|
||||||
import java.util.IdentityHashMap
|
import org.jetbrains.kotlin.js.inline.util.collectFunctionReferencesInside
|
||||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
|
||||||
import org.jetbrains.k2js.inline.util.collectReferencesInside
|
|
||||||
import org.jetbrains.k2js.inline.util.collectFunctionReferencesInside
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes unused function definitions:
|
* Removes unused function definitions:
|
||||||
+4
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,14 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.clean
|
package org.jetbrains.kotlin.js.inline.clean
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||||
|
|
||||||
import java.util.ArrayList
|
import org.jetbrains.kotlin.js.inline.util.collectReferencesInside
|
||||||
import java.util.IdentityHashMap
|
|
||||||
import org.jetbrains.k2js
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes unused local function declarations like:
|
* Removes unused local function declarations like:
|
||||||
@@ -59,7 +57,7 @@ private class UnusedInstanceCollector : JsVisitorWithContextImpl() {
|
|||||||
val currentStatement = currentNode as JsStatement
|
val currentStatement = currentNode as JsStatement
|
||||||
tracker.addCandidateForRemoval(name, currentStatement)
|
tracker.addCandidateForRemoval(name, currentStatement)
|
||||||
|
|
||||||
val references = k2js.inline.util.collectReferencesInside(x)
|
val references = collectReferencesInside(x)
|
||||||
references.filterNotNull()
|
references.filterNotNull()
|
||||||
.forEach { tracker.addRemovableReference(name, it) }
|
.forEach { tracker.addRemovableReference(name, it) }
|
||||||
|
|
||||||
+8
-16
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,24 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.context
|
package org.jetbrains.kotlin.js.inline.context
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsEmpty
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsFunction
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsInvocation
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLiteral
|
|
||||||
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 com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||||
|
|
||||||
import org.jetbrains.k2js.inline.util.aliasArgumentsIfNeeded
|
import org.jetbrains.kotlin.js.inline.util.aliasArgumentsIfNeeded
|
||||||
import org.jetbrains.k2js.inline.util.getInnerFunction
|
import org.jetbrains.kotlin.js.inline.util.getInnerFunction
|
||||||
import org.jetbrains.k2js.inline.util.getSimpleName
|
import org.jetbrains.kotlin.js.inline.util.getSimpleName
|
||||||
import org.jetbrains.k2js.inline.util.isCallInvocation
|
import org.jetbrains.kotlin.js.inline.util.isCallInvocation
|
||||||
import org.jetbrains.k2js.inline.util.isFunctionCreator
|
import org.jetbrains.kotlin.js.inline.util.isFunctionCreator
|
||||||
|
|
||||||
import com.intellij.util.containers.ContainerUtil
|
import com.intellij.util.containers.ContainerUtil
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
+2
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,9 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.context
|
package org.jetbrains.kotlin.js.inline.context
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
|
||||||
|
|
||||||
trait InliningContext {
|
trait InliningContext {
|
||||||
public val statementContext: StatementContext
|
public val statementContext: StatementContext
|
||||||
@@ -24,4 +22,3 @@ trait InliningContext {
|
|||||||
|
|
||||||
public fun newNamingContext(): NamingContext
|
public fun newNamingContext(): NamingContext
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.context
|
package org.jetbrains.kotlin.js.inline.context
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||||
+3
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,16 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.context
|
package org.jetbrains.kotlin.js.inline.context
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVars.JsVar
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
|
|
||||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||||
import org.jetbrains.k2js.inline.util.replaceNames
|
import org.jetbrains.kotlin.js.inline.util.replaceNames
|
||||||
|
|
||||||
class NamingContext(
|
class NamingContext(
|
||||||
private val scope: JsScope,
|
private val scope: JsScope,
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.context
|
package org.jetbrains.kotlin.js.inline.context
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
import com.google.dart.compiler.backend.js.ast.JsStatement
|
||||||
@@ -44,4 +44,4 @@ abstract class StatementContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun getEmptyStatement(): JsStatement
|
protected abstract fun getEmptyStatement(): JsStatement
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.exception;
|
package org.jetbrains.kotlin.js.inline.exception;
|
||||||
|
|
||||||
public class InlineRecursionException extends RuntimeException {
|
public class InlineRecursionException extends RuntimeException {
|
||||||
public InlineRecursionException() {
|
public InlineRecursionException() {
|
||||||
super("Encountered mutual inline recursion, inline will lead to stackoverflow");
|
super("Encountered mutual inline recursion, inline will lead to stack overflow");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,18 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
import com.google.dart.compiler.backend.js.ast.metadata.staticRef
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
import org.jetbrains.k2js.inline.util.IdentitySet
|
import org.jetbrains.kotlin.js.inline.util.collectors.ReferenceNameCollector
|
||||||
import org.jetbrains.k2js.inline.util.collectors.ReferenceNameCollector
|
import org.jetbrains.kotlin.js.inline.util.collectors.NameCollector
|
||||||
import org.jetbrains.k2js.inline.util.collectors.NameCollector
|
import org.jetbrains.kotlin.js.inline.util.collectors.InstanceCollector
|
||||||
import org.jetbrains.k2js.inline.util.collectors.InstanceCollector
|
import org.jetbrains.kotlin.js.inline.util.collectors.FunctionCollector
|
||||||
import org.jetbrains.k2js.inline.util.collectors.FunctionCollector
|
|
||||||
|
|
||||||
public fun collectFunctionReferencesInside(scope: JsNode): List<JsName> =
|
public fun collectFunctionReferencesInside(scope: JsNode): List<JsName> =
|
||||||
collectReferencesInside(scope) filter { it.staticRef is JsFunction }
|
collectReferencesInside(scope) filter { it.staticRef is JsFunction }
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
@@ -62,4 +62,4 @@ public fun <T, R> Iterable<T>.zipWithDefault(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.collectors
|
package org.jetbrains.kotlin.js.inline.util.collectors
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
||||||
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer
|
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer
|
||||||
@@ -34,7 +34,7 @@ class FunctionCollector : RecursiveJsVisitor() {
|
|||||||
val value = x?.getValueExpr()
|
val value = x?.getValueExpr()
|
||||||
|
|
||||||
if (label is JsNameRef && value is JsFunction) {
|
if (label is JsNameRef && value is JsFunction) {
|
||||||
val name = (label as JsNameRef).getName()
|
val name = label.getName()
|
||||||
val function = value as JsFunction
|
val function = value as JsFunction
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
@@ -42,4 +42,4 @@ class FunctionCollector : RecursiveJsVisitor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.collectors
|
package org.jetbrains.kotlin.js.inline.util.collectors
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||||
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
||||||
@@ -30,4 +30,4 @@ class InstanceCollector<T : JsNode>(val klass: Class<T>) : RecursiveJsVisitor()
|
|||||||
|
|
||||||
super.visitElement(node)
|
super.visitElement(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,12 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.collectors
|
package org.jetbrains.kotlin.js.inline.util.collectors
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsScope
|
import com.google.dart.compiler.backend.js.ast.JsScope
|
||||||
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
||||||
import com.google.dart.compiler.backend.js.ast.JsFunction
|
import com.google.dart.compiler.backend.js.ast.JsFunction
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLabel
|
|
||||||
import com.google.dart.compiler.backend.js.ast.HasName
|
import com.google.dart.compiler.backend.js.ast.HasName
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName
|
import com.google.dart.compiler.backend.js.ast.JsName
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVars
|
import com.google.dart.compiler.backend.js.ast.JsVars
|
||||||
@@ -48,4 +47,4 @@ class NameCollector(private val scope: JsScope) : RecursiveJsVisitor() {
|
|||||||
|
|
||||||
names.put(ident, name)
|
names.put(ident, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.collectors
|
package org.jetbrains.kotlin.js.inline.util.collectors
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName
|
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.JsNameRef
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
import org.jetbrains.k2js
|
import org.jetbrains.kotlin.js.inline.util.IdentitySet
|
||||||
|
|
||||||
class ReferenceNameCollector : JsVisitorWithContextImpl() {
|
class ReferenceNameCollector : JsVisitorWithContextImpl() {
|
||||||
private val referenceSet = k2js.inline.util.IdentitySet<JsName>()
|
private val referenceSet = IdentitySet<JsName>()
|
||||||
|
|
||||||
public val references: List<JsName>
|
public val references: List<JsName>
|
||||||
get() = referenceSet.toList()
|
get() = referenceSet.toList()
|
||||||
@@ -34,4 +34,4 @@ class ReferenceNameCollector : JsVisitorWithContextImpl() {
|
|||||||
referenceSet.add(name)
|
referenceSet.add(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsFunction
|
import com.google.dart.compiler.backend.js.ast.JsFunction
|
||||||
import com.google.dart.compiler.backend.js.ast.JsReturn
|
import com.google.dart.compiler.backend.js.ast.JsReturn
|
||||||
@@ -41,4 +41,4 @@ public fun JsFunction.getInnerFunction(): JsFunction? {
|
|||||||
val returnExpr = (statement as? JsReturn)?.getExpression()
|
val returnExpr = (statement as? JsReturn)?.getExpression()
|
||||||
|
|
||||||
return returnExpr as? JsFunction
|
return returnExpr as? JsFunction
|
||||||
}
|
}
|
||||||
+2
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,16 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsInvocation
|
import com.google.dart.compiler.backend.js.ast.JsInvocation
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpressionStatement
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName
|
import com.google.dart.compiler.backend.js.ast.JsName
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||||
import com.google.dart.compiler.backend.js.ast.JsFunction
|
import com.google.dart.compiler.backend.js.ast.JsFunction
|
||||||
import com.google.dart.compiler.backend.js.ast.JsReturn
|
|
||||||
import org.jetbrains.k2js.translate.context.Namer
|
import org.jetbrains.k2js.translate.context.Namer
|
||||||
import com.google.dart.compiler.backend.js.ast.HasName
|
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.JsNode
|
||||||
+5
-12
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,20 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVars.JsVar
|
|
||||||
import org.jetbrains.k2js.inline.util.collectLocalNames
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.HashMap
|
|
||||||
import java.util.IdentityHashMap
|
|
||||||
|
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
import org.jetbrains.k2js.inline.context.NamingContext
|
import org.jetbrains.kotlin.js.inline.context.NamingContext
|
||||||
import org.jetbrains.k2js.inline.util.needToAlias
|
import org.jetbrains.kotlin.js.inline.util.rewriters.LabelNameRefreshingVisitor
|
||||||
import org.jetbrains.k2js.inline.util.rewriters.LabelNameRefreshingVisitor
|
|
||||||
|
|
||||||
public fun aliasArgumentsIfNeeded(
|
public fun aliasArgumentsIfNeeded(
|
||||||
context: NamingContext,
|
context: NamingContext,
|
||||||
@@ -83,4 +76,4 @@ public fun refreshLabelNames(
|
|||||||
val visitor = LabelNameRefreshingVisitor(context, scope)
|
val visitor = LabelNameRefreshingVisitor(context, scope)
|
||||||
visitor.accept(function.getBody())
|
visitor.accept(function.getBody())
|
||||||
context.applyRenameTo(function)
|
context.applyRenameTo(function)
|
||||||
}
|
}
|
||||||
+6
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,17 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLiteral
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName
|
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.JsNameRef
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
import org.jetbrains.kotlin.js.inline.util.rewriters.NameReplacingVisitor
|
||||||
import org.jetbrains.k2js.inline.util.rewriters.NameReplacingVisitor
|
import org.jetbrains.kotlin.js.inline.util.rewriters.ReturnReplacingVisitor
|
||||||
import org.jetbrains.k2js.inline.util.rewriters.ReturnReplacingVisitor
|
import org.jetbrains.kotlin.js.inline.util.rewriters.ThisReplacingVisitor
|
||||||
import org.jetbrains.k2js.inline.util.rewriters.ThisReplacingVisitor
|
|
||||||
|
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
|
|
||||||
@@ -38,4 +36,4 @@ public fun replaceReturns(scope: JsNode, resultRef: JsNameRef?, breakLabel: JsNa
|
|||||||
|
|
||||||
public fun replaceThisReference<T : JsNode>(node: T, replacement: JsExpression) {
|
public fun replaceThisReference<T : JsNode>(node: T, replacement: JsExpression) {
|
||||||
ThisReplacingVisitor(replacement).accept(node)
|
ThisReplacingVisitor(replacement).accept(node)
|
||||||
}
|
}
|
||||||
+4
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,16 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.rewriters
|
package org.jetbrains.kotlin.js.inline.util.rewriters
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
||||||
import com.google.dart.compiler.backend.js.ast.JsFunctionScope
|
import com.google.dart.compiler.backend.js.ast.JsFunctionScope
|
||||||
import org.jetbrains.k2js.inline.context.NamingContext
|
import org.jetbrains.kotlin.js.inline.context.NamingContext
|
||||||
import com.google.dart.compiler.backend.js.ast.JsFunction
|
import com.google.dart.compiler.backend.js.ast.JsFunction
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLabel
|
import com.google.dart.compiler.backend.js.ast.JsLabel
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContinue
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsBreak
|
|
||||||
|
|
||||||
class LabelNameRefreshingVisitor(val context: NamingContext, val functionScope: JsFunctionScope) : JsVisitorWithContextImpl() {
|
class LabelNameRefreshingVisitor(val context: NamingContext, val functionScope: JsFunctionScope) : JsVisitorWithContextImpl() {
|
||||||
override fun visit(x: JsFunction?, ctx: JsContext?): Boolean = false
|
override fun visit(x: JsFunction?, ctx: JsContext?): Boolean = false
|
||||||
@@ -43,4 +41,4 @@ class LabelNameRefreshingVisitor(val context: NamingContext, val functionScope:
|
|||||||
super.endVisit(x, ctx)
|
super.endVisit(x, ctx)
|
||||||
functionScope.exitLabel()
|
functionScope.exitLabel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.rewriters
|
package org.jetbrains.kotlin.js.inline.util.rewriters
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName
|
import com.google.dart.compiler.backend.js.ast.JsName
|
||||||
@@ -55,4 +55,4 @@ class NameReplacingVisitor(private val replaceMap: Map<JsName, JsExpression>) :
|
|||||||
ctx.replaceMe(replacementLabel)
|
ctx.replaceMe(replacementLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.rewriters
|
package org.jetbrains.kotlin.js.inline.util.rewriters
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsBreak
|
import com.google.dart.compiler.backend.js.ast.JsBreak
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
@@ -24,9 +24,8 @@ import com.google.dart.compiler.backend.js.ast.JsFunction
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||||
import com.google.dart.compiler.backend.js.ast.JsObjectLiteral
|
import com.google.dart.compiler.backend.js.ast.JsObjectLiteral
|
||||||
import com.google.dart.compiler.backend.js.ast.JsReturn
|
import com.google.dart.compiler.backend.js.ast.JsReturn
|
||||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
import com.google.dart.compiler.backend.js.ast.JsVisitorWithContextImpl
|
||||||
import org.jetbrains.k2js.inline.util.canHaveSideEffect
|
import org.jetbrains.kotlin.js.inline.util.canHaveSideEffect
|
||||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||||
|
|
||||||
class ReturnReplacingVisitor(private val resultRef: JsNameRef?, private val breakLabel: JsNameRef?) : JsVisitorWithContextImpl() {
|
class ReturnReplacingVisitor(private val resultRef: JsNameRef?, private val breakLabel: JsNameRef?) : JsVisitorWithContextImpl() {
|
||||||
@@ -67,4 +66,4 @@ class ReturnReplacingVisitor(private val resultRef: JsNameRef?, private val brea
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util.rewriters
|
package org.jetbrains.kotlin.js.inline.util.rewriters
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
@@ -31,4 +31,4 @@ class ThisReplacingVisitor(private val thisReplacement: JsExpression) : JsVisito
|
|||||||
override fun visit(x: JsFunction?, ctx: JsContext?) = false
|
override fun visit(x: JsFunction?, ctx: JsContext?) = false
|
||||||
|
|
||||||
override fun visit(x: JsObjectLiteral?, ctx: JsContext?) = false
|
override fun visit(x: JsObjectLiteral?, ctx: JsContext?) = false
|
||||||
}
|
}
|
||||||
+3
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.k2js.inline.util
|
package org.jetbrains.kotlin.js.inline.util
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsArrayAccess
|
import com.google.dart.compiler.backend.js.ast.JsArrayAccess
|
||||||
import com.google.dart.compiler.backend.js.ast.JsArrayLiteral
|
import com.google.dart.compiler.backend.js.ast.JsArrayLiteral
|
||||||
@@ -22,17 +22,11 @@ import com.google.dart.compiler.backend.js.ast.JsBinaryOperation
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsConditional
|
import com.google.dart.compiler.backend.js.ast.JsConditional
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
import com.google.dart.compiler.backend.js.ast.JsInvocation
|
import com.google.dart.compiler.backend.js.ast.JsInvocation
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLiteral
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLiteral.JsThisRef
|
import com.google.dart.compiler.backend.js.ast.JsLiteral.JsThisRef
|
||||||
import com.google.dart.compiler.backend.js.ast.JsLiteral.JsValueLiteral
|
import com.google.dart.compiler.backend.js.ast.JsLiteral.JsValueLiteral
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNew
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||||
import com.google.dart.compiler.backend.js.ast.JsObjectLiteral
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsPostfixOperation
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsPrefixOperation
|
|
||||||
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
|
||||||
import com.google.dart.compiler.backend.js.ast.JsBinaryOperator
|
|
||||||
|
|
||||||
public fun canHaveSideEffect(x: JsExpression): Boolean {
|
public fun canHaveSideEffect(x: JsExpression): Boolean {
|
||||||
return with(SideEffectVisitor()) {
|
return with(SideEffectVisitor()) {
|
||||||
@@ -85,4 +79,4 @@ private class NeedToAliasVisitor() : SideEffectVisitor() {
|
|||||||
is JsInvocation -> isFunctionCreatorInvocation(node)
|
is JsInvocation -> isFunctionCreatorInvocation(node)
|
||||||
else -> super.isSideEffectFree(node)
|
else -> super.isSideEffectFree(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.test.semantics;
|
package org.jetbrains.k2js.test.semantics;
|
||||||
|
|
||||||
import org.jetbrains.k2js.inline.exception.InlineRecursionException;
|
|
||||||
import org.jetbrains.k2js.test.SingleFileTranslationWithDirectivesTest;
|
import org.jetbrains.k2js.test.SingleFileTranslationWithDirectivesTest;
|
||||||
|
import org.jetbrains.kotlin.js.inline.exception.InlineRecursionException;
|
||||||
|
|
||||||
public final class InlineTest extends SingleFileTranslationWithDirectivesTest {
|
public final class InlineTest extends SingleFileTranslationWithDirectivesTest {
|
||||||
public InlineTest() {
|
public InlineTest() {
|
||||||
|
|||||||
@@ -16,12 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.test.utils;
|
package org.jetbrains.k2js.test.utils;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.JsFunction;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.collectNamedFunctions;
|
import static org.jetbrains.kotlin.js.inline.util.UtilPackage.collectNamedFunctions;
|
||||||
|
|
||||||
public class AstSearchUtil {
|
public class AstSearchUtil {
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ import com.google.dart.compiler.backend.js.ast.JsNode;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.jetbrains.jet.InTextDirectivesUtils.findLinesWithPrefixesRemoved;
|
import static org.jetbrains.jet.InTextDirectivesUtils.findLinesWithPrefixesRemoved;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.jetbrains.kotlin.js.inline.util.UtilPackage.collectInstances;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.jetbrains.k2js.inline.util.UtilPackage.collectInstances;
|
|
||||||
|
|
||||||
public class DirectiveTestUtils {
|
public class DirectiveTestUtils {
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ import org.jetbrains.js.compiler.sourcemap.SourceMapBuilder;
|
|||||||
import org.jetbrains.k2js.analyze.TopDownAnalyzerFacadeForJS;
|
import org.jetbrains.k2js.analyze.TopDownAnalyzerFacadeForJS;
|
||||||
import org.jetbrains.k2js.config.Config;
|
import org.jetbrains.k2js.config.Config;
|
||||||
import org.jetbrains.k2js.facade.exceptions.TranslationException;
|
import org.jetbrains.k2js.facade.exceptions.TranslationException;
|
||||||
import org.jetbrains.k2js.inline.JsInliner;
|
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
|
import org.jetbrains.kotlin.js.inline.JsInliner;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -86,9 +86,6 @@ public final class K2JSTranslator {
|
|||||||
String prefix = FileUtilsPackage.readTextOrEmpty(outputPrefixFile);
|
String prefix = FileUtilsPackage.readTextOrEmpty(outputPrefixFile);
|
||||||
String postfix = FileUtilsPackage.readTextOrEmpty(outputPostfixFile);
|
String postfix = FileUtilsPackage.readTextOrEmpty(outputPostfixFile);
|
||||||
|
|
||||||
StringBuilder outBuilder = new StringBuilder(programCode.length() + prefix.length() + postfix.length());
|
|
||||||
outBuilder.append(prefix).append(programCode).append(postfix);
|
|
||||||
|
|
||||||
List<File> sourceFiles = ContainerUtil.map(files, new Function<JetFile, File>() {
|
List<File> sourceFiles = ContainerUtil.map(files, new Function<JetFile, File>() {
|
||||||
@Override
|
@Override
|
||||||
public File fun(JetFile file) {
|
public File fun(JetFile file) {
|
||||||
@@ -98,13 +95,13 @@ public final class K2JSTranslator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SimpleOutputFile jsFile = new SimpleOutputFile(sourceFiles, outputFile.getName(), outBuilder.toString());
|
SimpleOutputFile jsFile = new SimpleOutputFile(sourceFiles, outputFile.getName(), prefix + programCode + postfix);
|
||||||
List<SimpleOutputFile> outputFiles = new SmartList<SimpleOutputFile>(jsFile);
|
List<SimpleOutputFile> outputFiles = new SmartList<SimpleOutputFile>(jsFile);
|
||||||
|
|
||||||
if (sourceMapBuilder != null) {
|
if (sourceMapBuilder != null) {
|
||||||
sourceMapBuilder.skipLinesAtBeginning(StringUtil.getLineBreakCount(prefix));
|
sourceMapBuilder.skipLinesAtBeginning(StringUtil.getLineBreakCount(prefix));
|
||||||
SimpleOutputFile sourcemapFile = new SimpleOutputFile(sourceFiles, sourceMapBuilder.getOutFile().getName(), sourceMapBuilder.build());
|
SimpleOutputFile sourceMapFile = new SimpleOutputFile(sourceFiles, sourceMapBuilder.getOutFile().getName(), sourceMapBuilder.build());
|
||||||
outputFiles.add(sourcemapFile);
|
outputFiles.add(sourceMapFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputFileCollection outputFileCollection = new SimpleOutputFileCollection(outputFiles);
|
OutputFileCollection outputFileCollection = new SimpleOutputFileCollection(outputFiles);
|
||||||
|
|||||||
+2
-6
@@ -28,13 +28,9 @@ import org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionDescriptor
|
|||||||
import org.jetbrains.k2js.translate.utils.FunctionBodyTranslator.translateFunctionBody
|
import org.jetbrains.k2js.translate.utils.FunctionBodyTranslator.translateFunctionBody
|
||||||
import org.jetbrains.k2js.translate.utils.TranslationUtils.simpleReturnFunction
|
import org.jetbrains.k2js.translate.utils.TranslationUtils.simpleReturnFunction
|
||||||
import org.jetbrains.jet.lang.descriptors.MemberDescriptor
|
import org.jetbrains.jet.lang.descriptors.MemberDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
|
|
||||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils
|
|
||||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||||
import com.google.dart.compiler.backend.js.ast.JsVars.JsVar
|
|
||||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||||
import com.intellij.util.SmartList
|
import org.jetbrains.kotlin.js.inline.util.getInnerFunction
|
||||||
import org.jetbrains.k2js.inline.util.getInnerFunction
|
|
||||||
import org.jetbrains.jet.lang.types.lang.InlineUtil
|
import org.jetbrains.jet.lang.types.lang.InlineUtil
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||||
|
|
||||||
@@ -133,7 +129,7 @@ private fun moveCapturedLocalInside(capturingFunction: JsFunction, capturedName:
|
|||||||
CapturedArgsParams()
|
CapturedArgsParams()
|
||||||
}
|
}
|
||||||
is JsInvocation ->
|
is JsInvocation ->
|
||||||
moveCapturedLocalInside(capturingFunction, capturedName, localFunAlias as JsInvocation)
|
moveCapturedLocalInside(capturingFunction, capturedName, localFunAlias)
|
||||||
else ->
|
else ->
|
||||||
throw AssertionError("Local function reference has wrong alias $localFunAlias")
|
throw AssertionError("Local function reference has wrong alias $localFunAlias")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user