JS: refactor JsScope, JsName and related things, since it's became unnecessary to track scopes and declaration order of temporary JsName's
This commit is contained in:
@@ -15,7 +15,7 @@ public class JsCatchScope extends JsDeclarationScope {
|
||||
|
||||
public JsCatchScope(JsScope parent, @NotNull String ident) {
|
||||
super(parent, "Catch scope", true);
|
||||
name = new JsName(this, ident, false);
|
||||
name = new JsName(ident, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,10 +12,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* An abstract base class for named JavaScript objects.
|
||||
*/
|
||||
public class JsName extends HasMetadata implements Symbol {
|
||||
private static int ordinalGenerator;
|
||||
private final JsScope enclosing;
|
||||
private final int ordinal;
|
||||
|
||||
@NotNull
|
||||
private final String ident;
|
||||
|
||||
@@ -24,19 +20,9 @@ public class JsName extends HasMetadata implements Symbol {
|
||||
/**
|
||||
* @param ident the unmangled ident to use for this name
|
||||
*/
|
||||
JsName(JsScope enclosing, @NotNull String ident, boolean temporary) {
|
||||
this.enclosing = enclosing;
|
||||
JsName(@NotNull String ident, boolean temporary) {
|
||||
this.ident = ident;
|
||||
this.temporary = temporary;
|
||||
ordinal = temporary ? ordinalGenerator++ : 0;
|
||||
}
|
||||
|
||||
public int getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public JsScope getEnclosing() {
|
||||
return enclosing;
|
||||
}
|
||||
|
||||
public boolean isTemporary() {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.backend.ast;
|
||||
|
||||
import org.jetbrains.kotlin.js.util.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.js.util.Maps;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -43,8 +43,6 @@ public abstract class JsScope {
|
||||
@NotNull
|
||||
private final String description;
|
||||
private Map<String, JsName> names = Collections.emptyMap();
|
||||
private Map<JsName, Object> temporaryNames;
|
||||
private Set<JsName> readonlyTemporaryNames = null;
|
||||
private final JsScope parent;
|
||||
|
||||
private static final Pattern FRESH_NAME_SUFFIX = Pattern.compile("[\\$_]\\d+$");
|
||||
@@ -59,16 +57,6 @@ public abstract class JsScope {
|
||||
parent = null;
|
||||
}
|
||||
|
||||
public Set<JsName> getTemporaryNames() {
|
||||
if (temporaryNames == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if (readonlyTemporaryNames == null) {
|
||||
readonlyTemporaryNames = Collections.unmodifiableSet(temporaryNames.keySet());
|
||||
}
|
||||
return readonlyTemporaryNames;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsScope innerObjectScope(@NotNull String scopeName) {
|
||||
return new JsObjectScope(this, scopeName);
|
||||
@@ -103,14 +91,9 @@ public abstract class JsScope {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsName declareTemporaryName(@NotNull String suggestedName) {
|
||||
public static JsName declareTemporaryName(@NotNull String suggestedName) {
|
||||
assert !suggestedName.isEmpty();
|
||||
JsName name = new JsName(this, suggestedName, true);
|
||||
if (temporaryNames == null) {
|
||||
temporaryNames = new WeakHashMap<JsName, Object>();
|
||||
}
|
||||
temporaryNames.put(name, this);
|
||||
return name;
|
||||
return new JsName(suggestedName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +103,7 @@ public abstract class JsScope {
|
||||
* Future declarations of variables might however clash with the temporary.
|
||||
*/
|
||||
@NotNull
|
||||
public JsName declareTemporary() {
|
||||
public static JsName declareTemporary() {
|
||||
return declareTemporaryName("tmp$");
|
||||
}
|
||||
|
||||
@@ -171,7 +154,7 @@ public abstract class JsScope {
|
||||
}
|
||||
|
||||
public void copyOwnNames(JsScope other) {
|
||||
names = new HashMap<String, JsName>(names);
|
||||
names = new HashMap<>(names);
|
||||
names.putAll(other.names);
|
||||
}
|
||||
|
||||
@@ -182,7 +165,7 @@ public abstract class JsScope {
|
||||
|
||||
@NotNull
|
||||
protected JsName doCreateName(@NotNull String ident) {
|
||||
JsName name = new JsName(this, ident, false);
|
||||
JsName name = new JsName(ident, false);
|
||||
names = Maps.put(names, ident, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.*
|
||||
class JsObjectScope(parent: JsScope, description: String) : JsScope(parent, description)
|
||||
|
||||
object JsDynamicScope : JsScope(null, "Scope for dynamic declarations") {
|
||||
override fun doCreateName(name: String) = JsName(this, name, false)
|
||||
override fun doCreateName(name: String) = JsName(name, false)
|
||||
}
|
||||
|
||||
open class JsFunctionScope(parent: JsScope, description: String) : JsDeclarationScope(parent, description) {
|
||||
@@ -61,7 +61,7 @@ open class JsDeclarationScope(parent: JsScope, description: String, useParentSco
|
||||
else -> ident
|
||||
}
|
||||
|
||||
labelName = JsName(this@JsDeclarationScope, freshIdent, false)
|
||||
labelName = JsName(freshIdent, false)
|
||||
}
|
||||
|
||||
override fun findOwnName(name: String): JsName? =
|
||||
@@ -130,9 +130,6 @@ class DelegatingJsFunctionScopeWithTemporaryParent(
|
||||
override fun declareFreshName(suggestedName: String): JsName =
|
||||
delegatingScope.declareFreshName(suggestedName)
|
||||
|
||||
override fun declareTemporary(): JsName =
|
||||
delegatingScope.declareTemporary()
|
||||
|
||||
override fun enterLabel(label: String): JsName =
|
||||
delegatingScope.enterLabel(label)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user