Skip to content

Commit

Permalink
start disaster
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Sep 25, 2024
1 parent 6baf7e2 commit eebd7e1
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
*/
public class SimpleTypeSingleIndex extends Index {
private final Map<LocalVariableEntry, String> parameters = new HashMap<>();
private final Map<LocalVariableEntry, List<String>> parameterFallbacks = new HashMap<>();
private final Map<FieldEntry, String> fields = new HashMap<>();
private final Map<ClassNode, Map<String, FieldBuildingEntry>> fieldCache = new HashMap<>();
private SimpleTypeFieldNamesRegistry registry;
Expand Down Expand Up @@ -104,6 +105,10 @@ public void dropCache() {
return this.parameters.get(paramEntry);
}

public @Nullable List<String> getParamFallbacks(LocalVariableEntry paramEntry) {
return this.parameterFallbacks.get(paramEntry);
}

public Set<FieldEntry> getFields() {
return this.fields.keySet();
}
Expand Down Expand Up @@ -179,6 +184,7 @@ public void visitClassNode(ClassProvider provider, ClassNode node) {
int index = param.index() + (isStatic ? 0 : 1);
var paramEntry = new LocalVariableEntry(methodEntry, index);
this.parameters.put(paramEntry, name);
this.parameterFallbacks.put(paramEntry, param.entry.fallback().stream().map(Name::local).toList());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.representation.entry.Entry;
Expand All @@ -24,14 +25,15 @@
import org.quiltmc.enigma_plugin.index.CodecIndex;
import org.quiltmc.enigma_plugin.index.JarIndexer;

import java.util.List;
import java.util.Map;

public class CodecNameProposer extends NameProposer {
public static final String ID = "codecs";
private final CodecIndex index;

public CodecNameProposer(JarIndexer index) {
super(ID);
public CodecNameProposer(JarIndexer index, @Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
this.index = index.getIndex(CodecIndex.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.representation.entry.Entry;
import org.quiltmc.enigma.api.translation.representation.entry.FieldEntry;
import org.quiltmc.enigma_plugin.index.JarIndexer;
import org.quiltmc.enigma_plugin.index.constant_fields.ConstantFieldIndex;

import java.util.List;
import java.util.Map;

public class ConstantFieldNameProposer extends NameProposer {
public static final String ID = "constant_fields";
private final ConstantFieldIndex fieldIndex;

public ConstantFieldNameProposer(JarIndexer index) {
super(ID);
public ConstantFieldNameProposer(JarIndexer index, @Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
this.fieldIndex = index.getIndex(ConstantFieldIndex.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper;
Expand All @@ -25,14 +26,15 @@
import org.quiltmc.enigma_plugin.index.ConstructorParametersIndex;
import org.quiltmc.enigma_plugin.index.JarIndexer;

import java.util.List;
import java.util.Map;

public class ConstructorParamsNameProposer extends NameProposer {
public static final String ID = "constructor_params";
private final ConstructorParametersIndex index;

public ConstructorParamsNameProposer(JarIndexer index) {
super(ID);
public ConstructorParamsNameProposer(JarIndexer index, @Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
this.index = index.getIndex(ConstructorParametersIndex.class);
}

Expand All @@ -48,13 +50,13 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
continue;
}

this.insertDynamicProposal(mappings, parameter, newMapping);
this.insertDynamicProposal(mappings, remapper, parameter, newMapping);
}
} else if (obfEntry instanceof LocalVariableEntry parameter && this.index.isParameterLinked(parameter)) {
FieldEntry linkedField = this.index.getLinkedField(parameter);

if (!this.hasJarProposal(remapper, linkedField)) {
this.insertDynamicProposal(mappings, linkedField, newMapping);
this.insertDynamicProposal(mappings, remapper, linkedField, newMapping);
}

for (LocalVariableEntry param : this.index.getParametersForField(linkedField)) {
Expand All @@ -63,7 +65,7 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
}

if (param != parameter) {
this.insertDynamicProposal(mappings, param, newMapping);
this.insertDynamicProposal(mappings, remapper, param, newMapping);
}
}
} else if (obfEntry == null) {
Expand All @@ -76,7 +78,7 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
FieldEntry linkedField = this.index.getLinkedField(parameter);
EntryMapping mapping = remapper.getMapping(linkedField);

this.insertDynamicProposal(mappings, parameter, mapping);
this.insertDynamicProposal(mappings, remapper, parameter, mapping);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper;
Expand All @@ -36,8 +37,8 @@ public class DelegateParametersNameProposer extends NameProposer {
private static final List<String> IGNORED_SOURCE_PLUGIN_IDS = Stream.of(ID, SimpleTypeFieldNameProposer.ID).map(NameProposer::getSourcePluginId).toList();
private final DelegateParametersIndex index;

public DelegateParametersNameProposer(JarIndexer index) {
super(ID);
public DelegateParametersNameProposer(JarIndexer index, @Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
this.index = index.getIndex(DelegateParametersIndex.class);
}

Expand Down Expand Up @@ -93,7 +94,7 @@ private void proposeNameUpwards(EntryRemapper remapper, Map<Entry<?>, EntryMappi
continue;
}

this.insertDynamicProposal(mappings, link, name);
this.insertDynamicProposal(mappings, remapper, link, name);
this.proposeNameUpwards(remapper, mappings, link, name, depth + 1);
}
}
Expand Down Expand Up @@ -127,7 +128,7 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
var parameterNames = namesByMethod.get(method);

for (var name : parameterNames.keySet()) {
this.insertDynamicProposal(mappings, parameterNames.get(name), name);
this.insertDynamicProposal(mappings, remapper, parameterNames.get(name), name);
}
}

Expand All @@ -143,7 +144,7 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
}

if (newMapping.targetName() == null) {
this.insertDynamicProposal(mappings, paramEntry, name);
this.insertDynamicProposal(mappings, remapper, paramEntry, name);
}

this.proposeNameUpwards(remapper, mappings, paramEntry, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
Expand All @@ -24,14 +25,15 @@
import org.quiltmc.enigma.api.translation.representation.entry.LocalVariableEntry;
import org.quiltmc.enigma.api.translation.representation.entry.MethodEntry;

import java.util.List;
import java.util.Map;

public class EqualsNameProposer extends NameProposer {
public static final String ID = "equals";
private static final MethodDescriptor EQUALS_DESCRIPTOR = new MethodDescriptor("(Ljava/lang/Object;)Z");

public EqualsNameProposer() {
super(ID);
public EqualsNameProposer(@Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper;
Expand All @@ -27,14 +28,15 @@
import org.quiltmc.enigma_plugin.index.JarIndexer;
import org.quiltmc.enigma_plugin.util.Descriptors;

import java.util.List;
import java.util.Map;

public class GetterSetterNameProposer extends NameProposer {
public static final String ID = "getter_setter";
private final GetterSetterIndex index;

public GetterSetterNameProposer(JarIndexer index) {
super(ID);
public GetterSetterNameProposer(JarIndexer index, @Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
this.index = index.getIndex(GetterSetterIndex.class);
}

Expand Down Expand Up @@ -73,7 +75,7 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
continue;
}

this.insertDynamicProposal(mappings, method, newName);
this.insertDynamicProposal(mappings, remapper, method, newName);
}

for (LocalVariableEntry parameter : this.index.getLinkedParameters()) {
Expand All @@ -89,7 +91,7 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry
continue;
}

this.insertDynamicProposal(mappings, parameter, newName);
this.insertDynamicProposal(mappings, remapper, parameter, newName);
}

return;
Expand All @@ -105,9 +107,9 @@ public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, Entry

if (link instanceof MethodEntry method) {
var newName = getMethodName(name, method);
this.insertDynamicProposal(mappings, method, newName);
this.insertDynamicProposal(mappings, remapper, method, newName);
} else if (link instanceof LocalVariableEntry parameter) {
this.insertDynamicProposal(mappings, parameter, name);
this.insertDynamicProposal(mappings, remapper, parameter, name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.representation.entry.Entry;
import org.quiltmc.enigma.api.translation.representation.entry.FieldEntry;
import org.quiltmc.enigma_plugin.index.JarIndexer;
import org.quiltmc.enigma_plugin.index.LoggerIndex;

import java.util.List;
import java.util.Map;

/**
Expand All @@ -32,8 +34,8 @@ public class LoggerNameProposer extends NameProposer {
public static final String ID = "logger";
private final LoggerIndex index;

public LoggerNameProposer(JarIndexer index) {
super(ID);
public LoggerNameProposer(JarIndexer index, @Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
this.index = index.getIndex(LoggerIndex.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
Expand All @@ -24,6 +25,7 @@
import org.quiltmc.enigma.api.translation.representation.entry.FieldEntry;
import org.quiltmc.enigma.api.translation.representation.entry.MethodEntry;

import java.util.List;
import java.util.Map;

/**
Expand All @@ -33,8 +35,8 @@
public class MojangNameProposer extends NameProposer {
public static final String ID = "map_non_hashed";

public MojangNameProposer() {
super(ID);
public MojangNameProposer(@Nullable List<NameProposer> proposerList) {
super(ID, proposerList);
}

@Override
Expand All @@ -50,7 +52,7 @@ public void insertProposedNames(JarIndex index, Map<Entry<?>, EntryMapping> mapp

for (MethodEntry method : entryIndex.getMethods()) {
String name = method.getName();
if (!name.startsWith("m_")) {
if (!name.startsWith("m_") && !method.isConstructor()) {
this.insertProposal(mappings, method, name);
}
}
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/org/quiltmc/enigma_plugin/proposal/NameProposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@

package org.quiltmc.enigma_plugin.proposal;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.source.TokenType;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper;
import org.quiltmc.enigma.api.translation.representation.entry.Entry;
import org.quiltmc.enigma.api.translation.representation.entry.LocalVariableEntry;
import org.quiltmc.enigma_plugin.QuiltEnigmaPlugin;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class NameProposer {
private final String id;
@Nullable
private final List<NameProposer> proposers = new ArrayList<>();

public NameProposer(String id) {
public NameProposer(String id, @Nullable List<NameProposer> proposerList) {
this.id = id;
}

Expand All @@ -51,28 +57,35 @@ public void insertProposal(Map<Entry<?>, EntryMapping> mappings, Entry<?> entry,
}

public void insertProposal(Map<Entry<?>, EntryMapping> mappings, Entry<?> entry, String name) {
this.insertProposal(mappings, entry, name, TokenType.JAR_PROPOSED);
this.insertProposal(mappings, null, entry, name, TokenType.JAR_PROPOSED);
}

public void insertDynamicProposal(Map<Entry<?>, EntryMapping> mappings, Entry<?> entry, EntryMapping mapping) {
public void insertDynamicProposal(Map<Entry<?>, EntryMapping> mappings, EntryRemapper remapper, Entry<?> entry, EntryMapping mapping) {
if (mapping != null) {
if (mapping.targetName() != null && !mapping.targetName().isEmpty()) {
this.insertDynamicProposal(mappings, entry, mapping.targetName());
this.insertDynamicProposal(mappings, remapper, entry, mapping.targetName());
} else {
this.insertDynamicProposal(mappings, entry, (String) null);
this.insertDynamicProposal(mappings, remapper, entry, (String) null);
}
}
}

public void insertDynamicProposal(Map<Entry<?>, EntryMapping> mappings, Entry<?> entry, String name) {
this.insertProposal(mappings, entry, name, TokenType.DYNAMIC_PROPOSED);
public void insertDynamicProposal(Map<Entry<?>, EntryMapping> mappings, EntryRemapper remapper, Entry<?> entry, String name) {
this.insertProposal(mappings, remapper, entry, name, TokenType.DYNAMIC_PROPOSED);
}

private void insertProposal(Map<Entry<?>, EntryMapping> mappings, Entry<?> entry, String name, TokenType tokenType) {
private void insertProposal(Map<Entry<?>, EntryMapping> mappings, @Nullable EntryRemapper remapper, Entry<?> entry, String name, TokenType tokenType) {
if (!mappings.containsKey(entry)) {
if (name != null) {
EntryMapping mapping = new EntryMapping(name, null, tokenType, this.getSourcePluginId());
mappings.put(entry, mapping);

// god awful
if (tokenType == TokenType.DYNAMIC_PROPOSED && entry instanceof LocalVariableEntry param && !(this instanceof SimpleTypeFieldNameProposer)) {
this.proposers.stream().filter(nameProposer -> nameProposer instanceof SimpleTypeFieldNameProposer).findFirst().ifPresent(nameProposer -> {
((SimpleTypeFieldNameProposer) nameProposer).fixConflicts(mappings, remapper, param, name);
});
}
} else {
mappings.put(entry, null);
}
Expand Down
Loading

0 comments on commit eebd7e1

Please sign in to comment.