mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
JS: fix naming of variables in no-obfuscation mode
This commit is contained in:
parent
a1355bb2f7
commit
6543e68f8a
|
@ -56,6 +56,10 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext {
|
|||
statementRenderer = new StatementRenderer(context, writer);
|
||||
}
|
||||
|
||||
public void setCurrentMethod(MethodNode node) {
|
||||
statementRenderer.setCurrentMethod(node);
|
||||
}
|
||||
|
||||
public boolean isThreadLibraryUsed() {
|
||||
return threadLibraryUsed;
|
||||
}
|
||||
|
@ -76,9 +80,9 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext {
|
|||
threadLibraryUsed = false;
|
||||
this.async = async;
|
||||
statementRenderer.setAsync(async);
|
||||
statementRenderer.setCurrentMethod(node);
|
||||
prepareVariables(node);
|
||||
node.acceptVisitor(this);
|
||||
statementRenderer.clear();
|
||||
}
|
||||
|
||||
private void prepareVariables(MethodNode method) {
|
||||
|
|
|
@ -794,8 +794,6 @@ public class Renderer implements RenderingManager {
|
|||
writer.emitMethod(ref.getDescriptor());
|
||||
|
||||
writer.appendMethodBody(ref).ws().append("=").ws();
|
||||
methodBodyRenderer.renderParameters(ref, method.getModifiers());
|
||||
writer.sameLineWs().append("=>").ws().append("{").indent().softNewLine();
|
||||
if (method.hasModifier(ElementModifier.NATIVE)) {
|
||||
renderNativeBody(method, classSource);
|
||||
} else {
|
||||
|
@ -822,6 +820,7 @@ public class Renderer implements RenderingManager {
|
|||
}
|
||||
|
||||
var async = asyncMethods.contains(reference);
|
||||
renderMethodPrologue(reference, method.getModifiers());
|
||||
methodBodyRenderer.renderNative(generator, async, reference);
|
||||
threadLibraryUsed |= methodBodyRenderer.isThreadLibraryUsed();
|
||||
}
|
||||
|
@ -885,10 +884,18 @@ public class Renderer implements RenderingManager {
|
|||
var entry = decompileRegular(decompiler, method);
|
||||
node = entry.method;
|
||||
}
|
||||
|
||||
methodBodyRenderer.setCurrentMethod(node);
|
||||
renderMethodPrologue(method.getReference(), method.getModifiers());
|
||||
methodBodyRenderer.render(node, async);
|
||||
threadLibraryUsed |= methodBodyRenderer.isThreadLibraryUsed();
|
||||
}
|
||||
|
||||
private void renderMethodPrologue(MethodReference reference, Set<ElementModifier> modifier) {
|
||||
methodBodyRenderer.renderParameters(reference, modifier);
|
||||
writer.sameLineWs().append("=>").ws().append("{").indent().softNewLine();
|
||||
}
|
||||
|
||||
private AstCacheEntry decompileRegular(Decompiler decompiler, MethodHolder method) {
|
||||
if (astCache == null) {
|
||||
return decompileRegularCacheMiss(decompiler, method);
|
||||
|
|
|
@ -120,6 +120,7 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor {
|
|||
variableNameGenerator.setCurrentMethod(null);
|
||||
locationStack.clear();
|
||||
lastEmittedLocation = TextLocation.EMPTY;
|
||||
variableNameGenerator.clear();
|
||||
}
|
||||
|
||||
public boolean isAsync() {
|
||||
|
|
|
@ -30,6 +30,21 @@ public class VariableNameGenerator {
|
|||
|
||||
public VariableNameGenerator(boolean minifying) {
|
||||
this.minifying = minifying;
|
||||
|
||||
}
|
||||
|
||||
public void setCurrentMethod(MethodNode currentMethod) {
|
||||
this.currentMethod = currentMethod;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
cachedVariableNames.clear();
|
||||
usedVariableNames.clear();
|
||||
cachedVariableNameLastIndex = 0;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (!minifying) {
|
||||
usedVariableNames.add("$tmp");
|
||||
usedVariableNames.add("$ptr");
|
||||
|
@ -37,10 +52,6 @@ public class VariableNameGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public void setCurrentMethod(MethodNode currentMethod) {
|
||||
this.currentMethod = currentMethod;
|
||||
}
|
||||
|
||||
public String variableName(int index) {
|
||||
if (!minifying) {
|
||||
while (index >= cachedVariableNames.size()) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user