mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
JS: remove legacy way to generate names, fix issue with duplication of some top-level names in no-optimization mode
Fix #860
This commit is contained in:
parent
997a31b683
commit
86efdb0809
|
@ -38,7 +38,6 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import org.teavm.ast.ControlFlowEntry;
|
import org.teavm.ast.ControlFlowEntry;
|
||||||
import org.teavm.backend.javascript.codegen.AliasProvider;
|
|
||||||
import org.teavm.backend.javascript.codegen.DefaultAliasProvider;
|
import org.teavm.backend.javascript.codegen.DefaultAliasProvider;
|
||||||
import org.teavm.backend.javascript.codegen.DefaultNamingStrategy;
|
import org.teavm.backend.javascript.codegen.DefaultNamingStrategy;
|
||||||
import org.teavm.backend.javascript.codegen.MinifyingAliasProvider;
|
import org.teavm.backend.javascript.codegen.MinifyingAliasProvider;
|
||||||
|
@ -124,7 +123,6 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
private MethodNodeCache astCache = EmptyMethodNodeCache.INSTANCE;
|
private MethodNodeCache astCache = EmptyMethodNodeCache.INSTANCE;
|
||||||
private final Set<MethodReference> asyncMethods = new HashSet<>();
|
private final Set<MethodReference> asyncMethods = new HashSet<>();
|
||||||
private List<VirtualMethodContributor> customVirtualMethods = new ArrayList<>();
|
private List<VirtualMethodContributor> customVirtualMethods = new ArrayList<>();
|
||||||
private int topLevelNameLimit = 500000;
|
|
||||||
private boolean strict;
|
private boolean strict;
|
||||||
private BoundCheckInsertion boundCheckInsertion = new BoundCheckInsertion();
|
private BoundCheckInsertion boundCheckInsertion = new BoundCheckInsertion();
|
||||||
private NullCheckInsertion nullCheckInsertion = new NullCheckInsertion(NullCheckFilter.EMPTY);
|
private NullCheckInsertion nullCheckInsertion = new NullCheckInsertion(NullCheckFilter.EMPTY);
|
||||||
|
@ -212,10 +210,6 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
this.debugEmitter = debugEmitter;
|
this.debugEmitter = debugEmitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTopLevelNameLimit(int topLevelNameLimit) {
|
|
||||||
this.topLevelNameLimit = topLevelNameLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStrict(boolean strict) {
|
public void setStrict(boolean strict) {
|
||||||
this.strict = strict;
|
this.strict = strict;
|
||||||
}
|
}
|
||||||
|
@ -352,9 +346,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void emit(ListableClassHolderSource classes, Writer writer, BuildTarget target) {
|
private void emit(ListableClassHolderSource classes, Writer writer, BuildTarget target) {
|
||||||
AliasProvider aliasProvider = obfuscated
|
var aliasProvider = obfuscated ? new MinifyingAliasProvider() : new DefaultAliasProvider();
|
||||||
? new MinifyingAliasProvider(topLevelNameLimit)
|
|
||||||
: new DefaultAliasProvider(topLevelNameLimit);
|
|
||||||
DefaultNamingStrategy naming = new DefaultNamingStrategy(aliasProvider, controller.getUnprocessedClassSource());
|
DefaultNamingStrategy naming = new DefaultNamingStrategy(aliasProvider, controller.getUnprocessedClassSource());
|
||||||
DebugInformationEmitter debugEmitterToUse = debugEmitter;
|
DebugInformationEmitter debugEmitterToUse = debugEmitter;
|
||||||
if (debugEmitterToUse == null) {
|
if (debugEmitterToUse == null) {
|
||||||
|
@ -426,10 +418,12 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
var epilogue = rememberingWriter.save();
|
var epilogue = rememberingWriter.save();
|
||||||
rememberingWriter.clear();
|
rememberingWriter.clear();
|
||||||
|
|
||||||
var frequencyEstimator = new NameFrequencyEstimator();
|
if (renderingContext.isMinifying()) {
|
||||||
declarations.replay(frequencyEstimator, RememberedSource.FILTER_REF);
|
var frequencyEstimator = new NameFrequencyEstimator();
|
||||||
epilogue.replay(frequencyEstimator, RememberedSource.FILTER_REF);
|
declarations.replay(frequencyEstimator, RememberedSource.FILTER_REF);
|
||||||
frequencyEstimator.apply(naming);
|
epilogue.replay(frequencyEstimator, RememberedSource.FILTER_REF);
|
||||||
|
frequencyEstimator.apply(naming);
|
||||||
|
}
|
||||||
|
|
||||||
var sourceWriter = builder.build(writer);
|
var sourceWriter = builder.build(writer);
|
||||||
sourceWriter.setDebugInformationEmitter(debugEmitterToUse);
|
sourceWriter.setDebugInformationEmitter(debugEmitterToUse);
|
||||||
|
|
|
@ -22,19 +22,17 @@ import org.teavm.model.MethodReference;
|
||||||
public interface AliasProvider {
|
public interface AliasProvider {
|
||||||
String getFieldAlias(FieldReference field);
|
String getFieldAlias(FieldReference field);
|
||||||
|
|
||||||
ScopedName getStaticFieldAlias(FieldReference field);
|
String getStaticFieldAlias(FieldReference field);
|
||||||
|
|
||||||
ScopedName getStaticMethodAlias(MethodReference method);
|
String getStaticMethodAlias(MethodReference method);
|
||||||
|
|
||||||
String getMethodAlias(MethodDescriptor method);
|
String getMethodAlias(MethodDescriptor method);
|
||||||
|
|
||||||
ScopedName getClassAlias(String className);
|
String getClassAlias(String className);
|
||||||
|
|
||||||
String getFunctionAlias(String name);
|
String getFunctionAlias(String name);
|
||||||
|
|
||||||
ScopedName getClassInitAlias(String className);
|
String getClassInitAlias(String className);
|
||||||
|
|
||||||
String getScopeAlias();
|
|
||||||
|
|
||||||
void reserveName(String name);
|
void reserveName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,21 +26,14 @@ import org.teavm.model.MethodDescriptor;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
public class DefaultAliasProvider implements AliasProvider {
|
public class DefaultAliasProvider implements AliasProvider {
|
||||||
private int topLevelAliasLimit;
|
private final Map<String, String> classAliases = new HashMap<>();
|
||||||
private final Map<String, ScopedName> classAliases = new HashMap<>();
|
|
||||||
private final Set<String> knownAliases = new HashSet<>(200, 0.5f);
|
private final Set<String> knownAliases = new HashSet<>(200, 0.5f);
|
||||||
private final ObjectIntMap<String> knowAliasesCounter = new ObjectIntHashMap<>();
|
private final ObjectIntMap<String> knowAliasesCounter = new ObjectIntHashMap<>();
|
||||||
private final Set<String> knownScopedAliases = new HashSet<>(200, 0.5f);
|
|
||||||
private final ObjectIntMap<String> knowScopedAliasesCounter = new ObjectIntHashMap<>();
|
|
||||||
private final Set<String> knownVirtualAliases = new HashSet<>(200, 0.5f);
|
private final Set<String> knownVirtualAliases = new HashSet<>(200, 0.5f);
|
||||||
private final ObjectIntMap<String> knowVirtualAliasesCounter = new ObjectIntHashMap<>();
|
private final ObjectIntMap<String> knowVirtualAliasesCounter = new ObjectIntHashMap<>();
|
||||||
|
|
||||||
public DefaultAliasProvider(int topLevelAliasLimit) {
|
|
||||||
this.topLevelAliasLimit = topLevelAliasLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getClassAlias(String cls) {
|
public String getClassAlias(String cls) {
|
||||||
return classAliases.computeIfAbsent(cls, key -> makeUniqueTopLevel(suggestAliasForClass(key)));
|
return classAliases.computeIfAbsent(cls, key -> makeUniqueTopLevel(suggestAliasForClass(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +88,7 @@ public class DefaultAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getStaticMethodAlias(MethodReference method) {
|
public String getStaticMethodAlias(MethodReference method) {
|
||||||
String suggested = method.getDescriptor().getName();
|
String suggested = method.getDescriptor().getName();
|
||||||
switch (suggested) {
|
switch (suggested) {
|
||||||
case "<init>":
|
case "<init>":
|
||||||
|
@ -106,7 +99,7 @@ public class DefaultAliasProvider implements AliasProvider {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeUniqueTopLevel(getClassAlias(method.getClassName()).value + "_" + suggested);
|
return makeUniqueTopLevel(getClassAlias(method.getClassName()) + "_" + suggested);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -115,8 +108,8 @@ public class DefaultAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getStaticFieldAlias(FieldReference field) {
|
public String getStaticFieldAlias(FieldReference field) {
|
||||||
return makeUniqueTopLevel(getClassAlias(field.getClassName()).value + "_" + field.getFieldName());
|
return makeUniqueTopLevel(getClassAlias(field.getClassName()) + "_" + field.getFieldName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,25 +118,16 @@ public class DefaultAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getClassInitAlias(String className) {
|
public String getClassInitAlias(String className) {
|
||||||
return makeUniqueTopLevel(suggestAliasForClass(className) + "_$callClinit");
|
return makeUniqueTopLevel(suggestAliasForClass(className) + "_$callClinit");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getScopeAlias() {
|
|
||||||
return makeUnique(knownAliases, knowAliasesCounter, "$java");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reserveName(String name) {
|
public void reserveName(String name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScopedName makeUniqueTopLevel(String suggested) {
|
private String makeUniqueTopLevel(String suggested) {
|
||||||
if (knownAliases.size() < topLevelAliasLimit) {
|
return makeUnique(knownAliases, knowAliasesCounter, suggested);
|
||||||
return new ScopedName(false, makeUnique(knownAliases, knowAliasesCounter, suggested));
|
|
||||||
} else {
|
|
||||||
return new ScopedName(true, makeUnique(knownScopedAliases, knowScopedAliasesCounter, suggested));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String sanitize(String s) {
|
private String sanitize(String s) {
|
||||||
|
|
|
@ -33,13 +33,12 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
private final AliasProvider aliasProvider;
|
private final AliasProvider aliasProvider;
|
||||||
private final ClassReaderSource classSource;
|
private final ClassReaderSource classSource;
|
||||||
private final Map<MethodDescriptor, String> aliases = new HashMap<>();
|
private final Map<MethodDescriptor, String> aliases = new HashMap<>();
|
||||||
private final Map<Key, ScopedName> privateAliases = new HashMap<>();
|
private final Map<Key, String> privateAliases = new HashMap<>();
|
||||||
private final Map<String, ScopedName> classAliases = new HashMap<>();
|
private final Map<String, String> classAliases = new HashMap<>();
|
||||||
private final Map<FieldReference, String> fieldAliases = new HashMap<>();
|
private final Map<FieldReference, String> fieldAliases = new HashMap<>();
|
||||||
private final Map<FieldReference, ScopedName> staticFieldAliases = new HashMap<>();
|
private final Map<FieldReference, String> staticFieldAliases = new HashMap<>();
|
||||||
private final Map<String, String> functionAliases = new HashMap<>();
|
private final Map<String, String> functionAliases = new HashMap<>();
|
||||||
private final Map<String, ScopedName> classInitAliases = new HashMap<>();
|
private final Map<String, String> classInitAliases = new HashMap<>();
|
||||||
private String scopeName;
|
|
||||||
|
|
||||||
public DefaultNamingStrategy(AliasProvider aliasProvider, ClassReaderSource classSource) {
|
public DefaultNamingStrategy(AliasProvider aliasProvider, ClassReaderSource classSource) {
|
||||||
this.aliasProvider = aliasProvider;
|
this.aliasProvider = aliasProvider;
|
||||||
|
@ -47,7 +46,7 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getNameFor(String cls) {
|
public String getNameFor(String cls) {
|
||||||
return classAliases.computeIfAbsent(cls, key -> aliasProvider.getClassAlias(cls));
|
return classAliases.computeIfAbsent(cls, key -> aliasProvider.getClassAlias(cls));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,16 +61,16 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getFullNameFor(MethodReference method) {
|
public String getFullNameFor(MethodReference method) {
|
||||||
return getFullNameFor(method, NO_CLASSIFIER);
|
return getFullNameFor(method, NO_CLASSIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getNameForInit(MethodReference method) {
|
public String getNameForInit(MethodReference method) {
|
||||||
return getFullNameFor(method, INIT_CLASSIFIER);
|
return getFullNameFor(method, INIT_CLASSIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScopedName getFullNameFor(MethodReference method, byte classifier) {
|
private String getFullNameFor(MethodReference method, byte classifier) {
|
||||||
MethodReference originalMethod = method;
|
MethodReference originalMethod = method;
|
||||||
method = getRealMethod(method);
|
method = getRealMethod(method);
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
|
@ -98,8 +97,8 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getFullNameFor(FieldReference field) {
|
public String getFullNameFor(FieldReference field) {
|
||||||
ScopedName alias = staticFieldAliases.get(field);
|
var alias = staticFieldAliases.get(field);
|
||||||
if (alias == null) {
|
if (alias == null) {
|
||||||
FieldReference realField = getRealField(field);
|
FieldReference realField = getRealField(field);
|
||||||
if (realField.equals(field)) {
|
if (realField.equals(field)) {
|
||||||
|
@ -118,18 +117,10 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getNameForClassInit(String className) {
|
public String getNameForClassInit(String className) {
|
||||||
return classInitAliases.computeIfAbsent(className, key -> aliasProvider.getClassInitAlias(key));
|
return classInitAliases.computeIfAbsent(className, key -> aliasProvider.getClassInitAlias(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getScopeName() {
|
|
||||||
if (scopeName == null) {
|
|
||||||
scopeName = aliasProvider.getScopeAlias();
|
|
||||||
}
|
|
||||||
return scopeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reserveName(String name) {
|
public void reserveName(String name) {
|
||||||
aliasProvider.reserveName(name);
|
aliasProvider.reserveName(name);
|
||||||
|
|
|
@ -23,19 +23,12 @@ import org.teavm.model.MethodDescriptor;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
public class MinifyingAliasProvider implements AliasProvider {
|
public class MinifyingAliasProvider implements AliasProvider {
|
||||||
private int topLevelAliasLimit;
|
|
||||||
private static final String startLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
private static final String startLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
private static final String startVirtualLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
private static final String startVirtualLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
private int lastSuffix;
|
private int lastSuffix;
|
||||||
private int lastScopedSuffix;
|
|
||||||
private int lastVirtual;
|
private int lastVirtual;
|
||||||
private final Set<String> usedAliases = new HashSet<>();
|
private final Set<String> usedAliases = new HashSet<>();
|
||||||
private final Set<String> usedVirtualAliases = new HashSet<>();
|
private final Set<String> usedVirtualAliases = new HashSet<>();
|
||||||
private final Set<String> usedScopedAliases = new HashSet<>();
|
|
||||||
|
|
||||||
public MinifyingAliasProvider(int topLevelAliasLimit) {
|
|
||||||
this.topLevelAliasLimit = topLevelAliasLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFieldAlias(FieldReference field) {
|
public String getFieldAlias(FieldReference field) {
|
||||||
|
@ -47,12 +40,12 @@ public class MinifyingAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getStaticFieldAlias(FieldReference field) {
|
public String getStaticFieldAlias(FieldReference field) {
|
||||||
return createTopLevelName();
|
return createTopLevelName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getStaticMethodAlias(MethodReference method) {
|
public String getStaticMethodAlias(MethodReference method) {
|
||||||
return createTopLevelName();
|
return createTopLevelName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +59,7 @@ public class MinifyingAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getClassAlias(String className) {
|
public String getClassAlias(String className) {
|
||||||
return createTopLevelName();
|
return createTopLevelName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,37 +69,20 @@ public class MinifyingAliasProvider implements AliasProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopedName getClassInitAlias(String className) {
|
public String getClassInitAlias(String className) {
|
||||||
return createTopLevelName();
|
return createTopLevelName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getScopeAlias() {
|
|
||||||
String result;
|
|
||||||
do {
|
|
||||||
result = RenderingUtil.indexToId(lastSuffix++, startLetters);
|
|
||||||
} while (!usedAliases.add(result) || RenderingUtil.KEYWORDS.contains(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reserveName(String name) {
|
public void reserveName(String name) {
|
||||||
usedAliases.add(name);
|
usedAliases.add(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScopedName createTopLevelName() {
|
private String createTopLevelName() {
|
||||||
if (usedAliases.size() < topLevelAliasLimit) {
|
String result;
|
||||||
String result;
|
do {
|
||||||
do {
|
result = RenderingUtil.indexToId(lastSuffix++, startLetters);
|
||||||
result = RenderingUtil.indexToId(lastSuffix++, startLetters);
|
} while (!usedAliases.add(result) || RenderingUtil.KEYWORDS.contains(result));
|
||||||
} while (!usedAliases.add(result) || RenderingUtil.KEYWORDS.contains(result));
|
return result;
|
||||||
return new ScopedName(false, result);
|
|
||||||
} else {
|
|
||||||
String result;
|
|
||||||
do {
|
|
||||||
result = RenderingUtil.indexToId(lastScopedSuffix++, startLetters);
|
|
||||||
} while (!usedScopedAliases.add(result) || RenderingUtil.KEYWORDS.contains(result));
|
|
||||||
return new ScopedName(true, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,23 +20,21 @@ import org.teavm.model.MethodDescriptor;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
public interface NamingStrategy {
|
public interface NamingStrategy {
|
||||||
ScopedName getNameFor(String cls);
|
String getNameFor(String cls);
|
||||||
|
|
||||||
String getNameFor(MethodDescriptor method);
|
String getNameFor(MethodDescriptor method);
|
||||||
|
|
||||||
ScopedName getNameForInit(MethodReference method);
|
String getNameForInit(MethodReference method);
|
||||||
|
|
||||||
ScopedName getFullNameFor(MethodReference method);
|
String getFullNameFor(MethodReference method);
|
||||||
|
|
||||||
String getNameFor(FieldReference field);
|
String getNameFor(FieldReference field);
|
||||||
|
|
||||||
ScopedName getFullNameFor(FieldReference method);
|
String getFullNameFor(FieldReference method);
|
||||||
|
|
||||||
String getNameForFunction(String name);
|
String getNameForFunction(String name);
|
||||||
|
|
||||||
ScopedName getNameForClassInit(String className);
|
String getNameForClassInit(String className);
|
||||||
|
|
||||||
String getScopeName();
|
|
||||||
|
|
||||||
void reserveName(String name);
|
void reserveName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,8 +151,8 @@ public class OutputSourceWriter extends SourceWriter implements LocationProvider
|
||||||
return appendName(naming.getNameForClassInit(className));
|
return appendName(naming.getNameForClassInit(className));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SourceWriter appendName(ScopedName name) {
|
private SourceWriter appendName(String name) {
|
||||||
append(name.value);
|
append(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019 Alexey Andreev.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.teavm.backend.javascript.codegen;
|
|
||||||
|
|
||||||
public class ScopedName {
|
|
||||||
public final boolean scoped;
|
|
||||||
public final String value;
|
|
||||||
|
|
||||||
public ScopedName(boolean scoped, String value) {
|
|
||||||
this.scoped = scoped;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -240,15 +240,6 @@ public final class TeaVMRunner {
|
||||||
private void parseGenerationOptions() {
|
private void parseGenerationOptions() {
|
||||||
tool.setObfuscated(commandLine.hasOption("m"));
|
tool.setObfuscated(commandLine.hasOption("m"));
|
||||||
tool.setStrict(commandLine.hasOption("strict"));
|
tool.setStrict(commandLine.hasOption("strict"));
|
||||||
|
|
||||||
if (commandLine.hasOption("max-toplevel-names")) {
|
|
||||||
try {
|
|
||||||
tool.setMaxTopLevelNames(Integer.parseInt(commandLine.getOptionValue("max-toplevel-names")));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
System.err.println("'--max-toplevel-names' must be integer number");
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseDebugOptions() {
|
private void parseDebugOptions() {
|
||||||
|
|
|
@ -76,7 +76,6 @@ public class TeaVMTool {
|
||||||
private String targetFileName = "";
|
private String targetFileName = "";
|
||||||
private boolean obfuscated = true;
|
private boolean obfuscated = true;
|
||||||
private boolean strict;
|
private boolean strict;
|
||||||
private int maxTopLevelNames = 1000000;
|
|
||||||
private String mainClass;
|
private String mainClass;
|
||||||
private String entryPointName = "main";
|
private String entryPointName = "main";
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
|
@ -134,10 +133,6 @@ public class TeaVMTool {
|
||||||
this.strict = strict;
|
this.strict = strict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxTopLevelNames(int maxTopLevelNames) {
|
|
||||||
this.maxTopLevelNames = maxTopLevelNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIncremental() {
|
public boolean isIncremental() {
|
||||||
return incremental;
|
return incremental;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +319,6 @@ public class TeaVMTool {
|
||||||
javaScriptTarget = new JavaScriptTarget();
|
javaScriptTarget = new JavaScriptTarget();
|
||||||
javaScriptTarget.setObfuscated(obfuscated);
|
javaScriptTarget.setObfuscated(obfuscated);
|
||||||
javaScriptTarget.setStrict(strict);
|
javaScriptTarget.setStrict(strict);
|
||||||
javaScriptTarget.setTopLevelNameLimit(maxTopLevelNames);
|
|
||||||
|
|
||||||
debugEmitter = debugInformationGenerated || sourceMapsFileGenerated
|
debugEmitter = debugInformationGenerated || sourceMapsFileGenerated
|
||||||
? new DebugInformationBuilder(referenceCache) : null;
|
? new DebugInformationBuilder(referenceCache) : null;
|
||||||
|
|
|
@ -56,8 +56,6 @@ public interface BuildStrategy {
|
||||||
|
|
||||||
void setStrict(boolean strict);
|
void setStrict(boolean strict);
|
||||||
|
|
||||||
void setMaxTopLevelNames(int maxTopLevelNames);
|
|
||||||
|
|
||||||
void setProperties(Properties properties);
|
void setProperties(Properties properties);
|
||||||
|
|
||||||
void setTransformers(String[] transformers);
|
void setTransformers(String[] transformers);
|
||||||
|
|
|
@ -53,7 +53,6 @@ public class InProcessBuildStrategy implements BuildStrategy {
|
||||||
private boolean fastDependencyAnalysis;
|
private boolean fastDependencyAnalysis;
|
||||||
private boolean obfuscated;
|
private boolean obfuscated;
|
||||||
private boolean strict;
|
private boolean strict;
|
||||||
private int maxTopLevelNames = 1000000;
|
|
||||||
private boolean sourceMapsFileGenerated;
|
private boolean sourceMapsFileGenerated;
|
||||||
private boolean debugInformationGenerated;
|
private boolean debugInformationGenerated;
|
||||||
private boolean sourceFilesCopied;
|
private boolean sourceFilesCopied;
|
||||||
|
@ -157,11 +156,6 @@ public class InProcessBuildStrategy implements BuildStrategy {
|
||||||
this.strict = strict;
|
this.strict = strict;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMaxTopLevelNames(int maxTopLevelNames) {
|
|
||||||
this.maxTopLevelNames = maxTopLevelNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTransformers(String[] transformers) {
|
public void setTransformers(String[] transformers) {
|
||||||
this.transformers = transformers.clone();
|
this.transformers = transformers.clone();
|
||||||
|
@ -243,7 +237,6 @@ public class InProcessBuildStrategy implements BuildStrategy {
|
||||||
|
|
||||||
tool.setObfuscated(obfuscated);
|
tool.setObfuscated(obfuscated);
|
||||||
tool.setStrict(strict);
|
tool.setStrict(strict);
|
||||||
tool.setMaxTopLevelNames(maxTopLevelNames);
|
|
||||||
tool.setIncremental(incremental);
|
tool.setIncremental(incremental);
|
||||||
tool.getTransformers().addAll(Arrays.asList(transformers));
|
tool.getTransformers().addAll(Arrays.asList(transformers));
|
||||||
tool.getClassesToPreserve().addAll(Arrays.asList(classesToPreserve));
|
tool.getClassesToPreserve().addAll(Arrays.asList(classesToPreserve));
|
||||||
|
|
|
@ -134,11 +134,6 @@ public class RemoteBuildStrategy implements BuildStrategy {
|
||||||
request.strict = strict;
|
request.strict = strict;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMaxTopLevelNames(int maxTopLevelNames) {
|
|
||||||
request.maxTopLevelNames = maxTopLevelNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTransformers(String[] transformers) {
|
public void setTransformers(String[] transformers) {
|
||||||
request.transformers = transformers.clone();
|
request.transformers = transformers.clone();
|
||||||
|
|
|
@ -156,7 +156,6 @@ public class BuildDaemon extends UnicastRemoteObject implements RemoteBuildServi
|
||||||
tool.setFastDependencyAnalysis(request.fastDependencyAnalysis);
|
tool.setFastDependencyAnalysis(request.fastDependencyAnalysis);
|
||||||
tool.setObfuscated(request.obfuscated);
|
tool.setObfuscated(request.obfuscated);
|
||||||
tool.setStrict(request.strict);
|
tool.setStrict(request.strict);
|
||||||
tool.setMaxTopLevelNames(request.maxTopLevelNames);
|
|
||||||
tool.setWasmVersion(request.wasmVersion);
|
tool.setWasmVersion(request.wasmVersion);
|
||||||
tool.setMinHeapSize(request.minHeapSize);
|
tool.setMinHeapSize(request.minHeapSize);
|
||||||
tool.setMaxHeapSize(request.maxHeapSize);
|
tool.setMaxHeapSize(request.maxHeapSize);
|
||||||
|
|
|
@ -41,7 +41,6 @@ public class RemoteBuildRequest implements Serializable {
|
||||||
public String cacheDirectory;
|
public String cacheDirectory;
|
||||||
public boolean obfuscated;
|
public boolean obfuscated;
|
||||||
public boolean strict;
|
public boolean strict;
|
||||||
public int maxTopLevelNames = 1000000;
|
|
||||||
public Properties properties;
|
public Properties properties;
|
||||||
public TeaVMOptimizationLevel optimizationLevel;
|
public TeaVMOptimizationLevel optimizationLevel;
|
||||||
public boolean fastDependencyAnalysis;
|
public boolean fastDependencyAnalysis;
|
||||||
|
|
|
@ -829,7 +829,6 @@ public class CodeServlet extends HttpServlet {
|
||||||
jsTarget.setObfuscated(false);
|
jsTarget.setObfuscated(false);
|
||||||
jsTarget.setAstCache(astCache);
|
jsTarget.setAstCache(astCache);
|
||||||
jsTarget.setDebugEmitter(debugInformationBuilder);
|
jsTarget.setDebugEmitter(debugInformationBuilder);
|
||||||
jsTarget.setTopLevelNameLimit(2000);
|
|
||||||
jsTarget.setStrict(true);
|
jsTarget.setStrict(true);
|
||||||
vm.setOptimizationLevel(TeaVMOptimizationLevel.SIMPLE);
|
vm.setOptimizationLevel(TeaVMOptimizationLevel.SIMPLE);
|
||||||
vm.setCacheStatus(classSource);
|
vm.setCacheStatus(classSource);
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.teavm.gradle.tasks;
|
||||||
import org.gradle.api.provider.Property;
|
import org.gradle.api.provider.Property;
|
||||||
import org.gradle.api.tasks.Input;
|
import org.gradle.api.tasks.Input;
|
||||||
import org.gradle.api.tasks.Optional;
|
import org.gradle.api.tasks.Optional;
|
||||||
import org.teavm.gradle.api.OptimizationLevel;
|
|
||||||
import org.teavm.tooling.TeaVMTargetType;
|
import org.teavm.tooling.TeaVMTargetType;
|
||||||
import org.teavm.tooling.builder.BuildStrategy;
|
import org.teavm.tooling.builder.BuildStrategy;
|
||||||
|
|
||||||
|
@ -53,8 +52,5 @@ public abstract class GenerateJavaScriptTask extends TeaVMTask {
|
||||||
builder.setStrict(getStrict().get());
|
builder.setStrict(getStrict().get());
|
||||||
builder.setSourceMapsFileGenerated(getSourceMap().get());
|
builder.setSourceMapsFileGenerated(getSourceMap().get());
|
||||||
builder.setEntryPointName(getEntryPointName().get());
|
builder.setEntryPointName(getEntryPointName().get());
|
||||||
if (getOptimization().get() == OptimizationLevel.NONE) {
|
|
||||||
builder.setMaxTopLevelNames(1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,6 @@ public class TeaVMCompileMojo extends AbstractMojo {
|
||||||
@Parameter(property = "teavm.strict", defaultValue = "false")
|
@Parameter(property = "teavm.strict", defaultValue = "false")
|
||||||
private boolean strict;
|
private boolean strict;
|
||||||
|
|
||||||
@Parameter(property = "teavm.maxTopLevelNames", defaultValue = "10000")
|
|
||||||
private int maxTopLevelNames = 10000;
|
|
||||||
|
|
||||||
@Parameter
|
@Parameter
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
|
||||||
|
@ -166,7 +163,6 @@ public class TeaVMCompileMojo extends AbstractMojo {
|
||||||
builder.setClassPathEntries(prepareClassPath());
|
builder.setClassPathEntries(prepareClassPath());
|
||||||
builder.setObfuscated(minifying);
|
builder.setObfuscated(minifying);
|
||||||
builder.setStrict(strict);
|
builder.setStrict(strict);
|
||||||
builder.setMaxTopLevelNames(maxTopLevelNames);
|
|
||||||
builder.setTargetDirectory(targetDirectory.getAbsolutePath());
|
builder.setTargetDirectory(targetDirectory.getAbsolutePath());
|
||||||
if (transformers != null) {
|
if (transformers != null) {
|
||||||
builder.setTransformers(transformers);
|
builder.setTransformers(transformers);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user