mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-24 01:19:48 +00:00
Update AP to allow (but warn) coerced multi-target reference conflicts
This commit is contained in:
1 parent
2a64bc35b4
commit
c6ce27efb0
6 files changed
+108
-10
No files matched your search
@@ -64,9 +64,9 @@ abstract class AnnotatedMixinElementHandler {
|
||||
*/
|
||||
abstract static class AnnotatedElement<E extends Element> {
|
||||
|
||||
private final E element;
|
||||
protected final E element;
|
||||
|
||||
private final AnnotationHandle annotation;
|
||||
protected final AnnotationHandle annotation;
|
||||
|
||||
private final String desc;
|
||||
|
||||
@@ -508,5 +508,14 @@ abstract class AnnotatedMixinElementHandler {
|
||||
}
|
||||
return stripped;
|
||||
}
|
||||
|
||||
protected static <T extends IMapping<T>> ObfuscationData<T> stripDescriptors(ObfuscationData<T> data) {
|
||||
ObfuscationData<T> stripped = new ObfuscationData<T>();
|
||||
for (ObfuscationType type : data) {
|
||||
T mapping = data.get(type);
|
||||
stripped.put(type, mapping.transform(null));
|
||||
}
|
||||
return stripped;
|
||||
}
|
||||
|
||||
}
|
||||
+37
-1
@@ -30,9 +30,11 @@ import java.util.Map;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
@@ -42,6 +44,7 @@ import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor.CompilerEnvironment;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IReferenceManager;
|
||||
import org.spongepowered.tools.obfuscation.mirror.AnnotationHandle;
|
||||
import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
|
||||
import org.spongepowered.tools.obfuscation.struct.InjectorRemap;
|
||||
@@ -67,6 +70,21 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
return this.state.shouldRemap();
|
||||
}
|
||||
|
||||
public boolean hasCoerceArgument() {
|
||||
if (!this.annotation.toString().equals("@Inject")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (VariableElement param : this.element.getParameters()) {
|
||||
AnnotationHandle coerce = AnnotationHandle.of(param, Coerce.class);
|
||||
if (coerce != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addMessage(Diagnostic.Kind kind, CharSequence msg, Element element, AnnotationHandle annotation) {
|
||||
this.state.addMessage(kind, msg, element, annotation);
|
||||
}
|
||||
@@ -192,14 +210,32 @@ class AnnotatedMixinElementHandlerInjector extends AnnotatedMixinElementHandler
|
||||
}
|
||||
}
|
||||
|
||||
IReferenceManager refMap = this.obf.getReferenceManager();
|
||||
try {
|
||||
// If the original owner is unspecified, and the mixin is multi-target, we strip the owner from the obf mappings
|
||||
if ((targetMember.owner == null && this.mixin.isMultiTarget()) || target.isSimulated()) {
|
||||
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripOwnerData(obfData);
|
||||
}
|
||||
this.obf.getReferenceManager().addMethodMapping(this.classRef, reference, obfData);
|
||||
refMap.addMethodMapping(this.classRef, reference, obfData);
|
||||
} catch (ReferenceConflictException ex) {
|
||||
String conflictType = this.mixin.isMultiTarget() ? "Multi-target" : "Target";
|
||||
|
||||
if (elem.hasCoerceArgument() && targetMember.owner == null && targetMember.desc == null) {
|
||||
MemberInfo oldMember = MemberInfo.parse(ex.getOld());
|
||||
MemberInfo newMember = MemberInfo.parse(ex.getNew());
|
||||
if (oldMember.name.equals(newMember.name)) {
|
||||
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripDescriptors(obfData);
|
||||
refMap.setAllowConflicts(true);
|
||||
refMap.addMethodMapping(this.classRef, reference, obfData);
|
||||
refMap.setAllowConflicts(false);
|
||||
|
||||
// This is bad because in notch mappings, using the bare target name might cause everything to explode
|
||||
elem.printMessage(this.ap, Kind.WARNING, "Coerced " + conflictType + " reference has conflicting descriptors for " + targetName
|
||||
+ ": Storing bare references " + obfData.values() + " in refMap");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
elem.printMessage(this.ap, Kind.ERROR, conflictType + " reference conflict for " + targetName + ": " + reference + " -> "
|
||||
+ ex.getNew() + " previously defined as " + ex.getOld());
|
||||
}
|
||||
|
||||
@@ -123,13 +123,27 @@ public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ObfuscationData[%sDEFAULT=%s]", this.listValues(), this.defaultValue);
|
||||
return String.format("ObfuscationData[%s,DEFAULT=%s]", this.listValues(), this.defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the values in this data set
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public String values() {
|
||||
return "[" + this.listValues() + "]";
|
||||
}
|
||||
|
||||
private String listValues() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean delim = false;
|
||||
for (ObfuscationType type : this.data.keySet()) {
|
||||
sb.append(type.getKey()).append('=').append(this.data.get(type)).append(',');
|
||||
if (delim) {
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append(type.getKey()).append('=').append(this.data.get(type));
|
||||
delim = true;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -89,11 +89,31 @@ public class ReferenceManager implements IReferenceManager {
|
||||
*/
|
||||
private final ReferenceMapper refMapper = new ReferenceMapper();
|
||||
|
||||
private boolean allowConflicts;
|
||||
|
||||
public ReferenceManager(IMixinAnnotationProcessor ap, List<ObfuscationEnvironment> environments) {
|
||||
this.ap = ap;
|
||||
this.environments = environments;
|
||||
this.outRefMapFileName = this.ap.getOption(SupportedOptions.OUT_REFMAP_FILE);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IReferenceManager
|
||||
* #getAllowConflicts()
|
||||
*/
|
||||
@Override
|
||||
public boolean getAllowConflicts() {
|
||||
return this.allowConflicts;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.tools.obfuscation.interfaces.IReferenceManager
|
||||
* #setAllowConflicts(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setAllowConflicts(boolean allowConflicts) {
|
||||
this.allowConflicts = allowConflicts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out stored mappings
|
||||
@@ -214,12 +234,12 @@ public class ReferenceManager implements IReferenceManager {
|
||||
|
||||
protected void addMapping(ObfuscationType type, String className, String reference, String newReference) {
|
||||
String oldReference = this.refMapper.addMapping(type.getKey(), className, reference, newReference);
|
||||
if (oldReference != null && !oldReference.equals(newReference)) {
|
||||
throw new ReferenceConflictException(oldReference, newReference);
|
||||
}
|
||||
|
||||
if (type.isDefault()) {
|
||||
this.refMapper.addMapping(null, className, reference, newReference);
|
||||
}
|
||||
|
||||
if (!this.allowConflicts && oldReference != null && !oldReference.equals(newReference)) {
|
||||
throw new ReferenceConflictException(oldReference, newReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,12 +29,30 @@ import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationData;
|
||||
import org.spongepowered.tools.obfuscation.ReferenceManager.ReferenceConflictException;
|
||||
|
||||
/**
|
||||
* Consumer for generated references, builds the refmap during an AP pass and
|
||||
* supports writing the generated refmap to file once the AP run is complete
|
||||
*/
|
||||
public interface IReferenceManager {
|
||||
|
||||
/**
|
||||
* Set whether this reference manager should allow conflicts to be inserted
|
||||
* without raising an exception. Set to allow overrides to be written into
|
||||
* the refmap when necessary
|
||||
*
|
||||
* @param allowConflicts allow conflicts without raising an exception
|
||||
*/
|
||||
public void setAllowConflicts(boolean allowConflicts);
|
||||
|
||||
/**
|
||||
* Get whether replacement mappings are allowed. Normally a mapping conflict
|
||||
* will raise a {@link ReferenceConflictException}.
|
||||
*
|
||||
* @return true if conflicts are allowed
|
||||
*/
|
||||
public boolean getAllowConflicts();
|
||||
|
||||
/**
|
||||
* Write the generated refmap to file
|
||||
|
||||
Reference in new issue
Block a user