Minor cleanup in JS backend
This commit is contained in:
@@ -13,14 +13,10 @@ import java.util.List;
|
|||||||
* Represents a JavaScript block in the global scope.
|
* Represents a JavaScript block in the global scope.
|
||||||
*/
|
*/
|
||||||
public class JsGlobalBlock extends JsBlock {
|
public class JsGlobalBlock extends JsBlock {
|
||||||
|
@Override
|
||||||
public JsGlobalBlock() {
|
public boolean isGlobalBlock() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean isGlobalBlock() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.js.backend.ast;
|
package org.jetbrains.kotlin.js.backend.ast;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Taken from GWT project with modifications.
|
* Taken from GWT project with modifications.
|
||||||
* Original:
|
* Original:
|
||||||
* repository: https://gwt.googlesource.com/gwt
|
* repository: https://gwt.googlesource.com/gwt
|
||||||
@@ -33,15 +33,15 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class JsVisitorWithContextImpl extends JsVisitorWithContext {
|
public class JsVisitorWithContextImpl extends JsVisitorWithContext {
|
||||||
|
|
||||||
protected final Stack<JsContext<JsStatement>> statementContexts = new Stack<JsContext<JsStatement>>();
|
protected final Stack<JsContext<JsStatement>> statementContexts = new Stack<>();
|
||||||
|
|
||||||
public class ListContext<T extends JsNode> extends JsContext<T> {
|
public class ListContext<T extends JsNode> extends JsContext<T> {
|
||||||
private List<T> nodes;
|
private List<T> nodes;
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
// Those are reset in every iteration of traverse()
|
// Those are reset in every iteration of traverse()
|
||||||
private final List<T> previous = new SmartList<T>();
|
private final List<T> previous = new SmartList<>();
|
||||||
private final List<T> next = new SmartList<T>();
|
private final List<T> next = new SmartList<>();
|
||||||
private boolean removed = false;
|
private boolean removed = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -138,7 +138,7 @@ public class JsVisitorWithContextImpl extends JsVisitorWithContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void checkReplacement(@SuppressWarnings("UnusedParameters") JsNode origNode, JsNode newNode) {
|
private static void checkReplacement(@SuppressWarnings("UnusedParameters") JsNode origNode, JsNode newNode) {
|
||||||
if (newNode == null) throw new RuntimeException("Cannot replace with null");
|
if (newNode == null) throw new RuntimeException("Cannot replace with null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ public class JsVisitorWithContextImpl extends JsVisitorWithContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T extends JsStatement> JsStatement doAcceptStatement(T statement) {
|
protected <T extends JsStatement> JsStatement doAcceptStatement(T statement) {
|
||||||
List<JsStatement> statements = new SmartList<JsStatement>(statement);
|
List<JsStatement> statements = new SmartList<>(statement);
|
||||||
doAcceptStatementList(statements);
|
doAcceptStatementList(statements);
|
||||||
|
|
||||||
if (statements.size() == 1) {
|
if (statements.size() == 1) {
|
||||||
@@ -166,7 +166,7 @@ public class JsVisitorWithContextImpl extends JsVisitorWithContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doAcceptStatementList(List<JsStatement> statements) {
|
protected void doAcceptStatementList(List<JsStatement> statements) {
|
||||||
ListContext<JsStatement> context = new ListContext<JsStatement>();
|
ListContext<JsStatement> context = new ListContext<>();
|
||||||
statementContexts.push(context);
|
statementContexts.push(context);
|
||||||
context.traverse(statements);
|
context.traverse(statements);
|
||||||
statementContexts.pop();
|
statementContexts.pop();
|
||||||
|
|||||||
@@ -18,16 +18,12 @@ package org.jetbrains.kotlin.js.inline.context
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.js.backend.ast.*
|
import org.jetbrains.kotlin.js.backend.ast.*
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.synthetic
|
import org.jetbrains.kotlin.js.backend.ast.metadata.synthetic
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.IdentityHashMap
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
|
||||||
import org.jetbrains.kotlin.js.inline.util.replaceNames
|
import org.jetbrains.kotlin.js.inline.util.replaceNames
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||||
|
|
||||||
class NamingContext(private val statementContext: JsContext<JsStatement>) {
|
class NamingContext(private val statementContext: JsContext<JsStatement>) {
|
||||||
private val renamings = IdentityHashMap<JsName, JsExpression>()
|
private val renamings = mutableMapOf<JsName, JsExpression>()
|
||||||
private val declarations = ArrayList<JsVars>()
|
private val declarations = mutableListOf<JsVars>()
|
||||||
private var addedDeclarations = false
|
private var addedDeclarations = false
|
||||||
|
|
||||||
fun applyRenameTo(target: JsNode): JsNode {
|
fun applyRenameTo(target: JsNode): JsNode {
|
||||||
|
|||||||
Reference in New Issue
Block a user