summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/Finders
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-06 00:02:10 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-06 00:02:10 -0400
commitf16e477fc22bf76c33d8860acda090a199a0dcdb (patch)
treecfd1c0701869b7254b8122e9ab56a5652df729de /src/SMAPI/Framework/ModLoading/Finders
parentcfc07c1ee58b113c4e2ec8d6de28a57397589068 (diff)
downloadSMAPI-f16e477fc22bf76c33d8860acda090a199a0dcdb.tar.gz
SMAPI-f16e477fc22bf76c33d8860acda090a199a0dcdb.tar.bz2
SMAPI-f16e477fc22bf76c33d8860acda090a199a0dcdb.zip
add base instruction handler (#711)
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders')
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs26
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs26
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs26
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs26
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs25
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs25
6 files changed, 30 insertions, 124 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs
index 898bafb4..1a7ae636 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs
@@ -1,10 +1,11 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
namespace StardewModdingAPI.Framework.ModLoading.Finders
{
/// <summary>Finds incompatible CIL instructions that reference a given event.</summary>
- internal class EventFinder : IInstructionHandler
+ internal class EventFinder : BaseInstructionHandler
{
/*********
** Fields
@@ -20,13 +21,6 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/*********
- ** Accessors
- *********/
- /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
- public string NounPhrase { get; }
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -34,30 +28,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/// <param name="eventName">The event name for which to find references.</param>
/// <param name="result">The result to return for matching instructions.</param>
public EventFinder(string fullTypeName, string eventName, InstructionHandleResult result)
+ : base(nounPhrase: $"{fullTypeName}.{eventName} event")
{
this.FullTypeName = fullTypeName;
this.EventName = eventName;
this.Result = result;
- this.NounPhrase = $"{fullTypeName}.{eventName} event";
- }
-
- /// <summary>Perform the predefined logic for a method if applicable.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="method">The method definition containing the instruction.</param>
- /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
- /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged)
- {
- return InstructionHandleResult.None;
}
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
/// <param name="module">The assembly module containing the instruction.</param>
/// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The instruction to handle.</param>
+ /// <param name="instruction">The CIL instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
return this.IsMatch(instruction)
? this.Result
diff --git a/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs
index 606ca8b7..9ae07916 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs
@@ -1,10 +1,11 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
namespace StardewModdingAPI.Framework.ModLoading.Finders
{
/// <summary>Finds incompatible CIL instructions that reference a given field.</summary>
- internal class FieldFinder : IInstructionHandler
+ internal class FieldFinder : BaseInstructionHandler
{
/*********
** Fields
@@ -20,13 +21,6 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/*********
- ** Accessors
- *********/
- /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
- public string NounPhrase { get; }
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -34,30 +28,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/// <param name="fieldName">The field name for which to find references.</param>
/// <param name="result">The result to return for matching instructions.</param>
public FieldFinder(string fullTypeName, string fieldName, InstructionHandleResult result)
+ : base(nounPhrase: $"{fullTypeName}.{fieldName} field")
{
this.FullTypeName = fullTypeName;
this.FieldName = fieldName;
this.Result = result;
- this.NounPhrase = $"{fullTypeName}.{fieldName} field";
- }
-
- /// <summary>Perform the predefined logic for a method if applicable.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="method">The method definition containing the instruction.</param>
- /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
- /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged)
- {
- return InstructionHandleResult.None;
}
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
/// <param name="module">The assembly module containing the instruction.</param>
/// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The instruction to handle.</param>
+ /// <param name="instruction">The CIL instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
return this.IsMatch(instruction)
? this.Result
diff --git a/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs
index 9ca246ff..75584f1f 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs
@@ -1,10 +1,11 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
namespace StardewModdingAPI.Framework.ModLoading.Finders
{
/// <summary>Finds incompatible CIL instructions that reference a given method.</summary>
- internal class MethodFinder : IInstructionHandler
+ internal class MethodFinder : BaseInstructionHandler
{
/*********
** Fields
@@ -20,13 +21,6 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/*********
- ** Accessors
- *********/
- /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
- public string NounPhrase { get; }
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -34,30 +28,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/// <param name="methodName">The method name for which to find references.</param>
/// <param name="result">The result to return for matching instructions.</param>
public MethodFinder(string fullTypeName, string methodName, InstructionHandleResult result)
+ : base(nounPhrase: $"{fullTypeName}.{methodName} method")
{
this.FullTypeName = fullTypeName;
this.MethodName = methodName;
this.Result = result;
- this.NounPhrase = $"{fullTypeName}.{methodName} method";
- }
-
- /// <summary>Perform the predefined logic for a method if applicable.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="method">The method definition containing the instruction.</param>
- /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
- /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged)
- {
- return InstructionHandleResult.None;
}
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
/// <param name="module">The assembly module containing the instruction.</param>
/// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The instruction to handle.</param>
+ /// <param name="instruction">The CIL instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
return this.IsMatch(instruction)
? this.Result
diff --git a/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs
index 0677aa88..811420c5 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs
@@ -1,10 +1,11 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
namespace StardewModdingAPI.Framework.ModLoading.Finders
{
/// <summary>Finds incompatible CIL instructions that reference a given property.</summary>
- internal class PropertyFinder : IInstructionHandler
+ internal class PropertyFinder : BaseInstructionHandler
{
/*********
** Fields
@@ -20,13 +21,6 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/*********
- ** Accessors
- *********/
- /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
- public string NounPhrase { get; }
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -34,30 +28,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/// <param name="propertyName">The property name for which to find references.</param>
/// <param name="result">The result to return for matching instructions.</param>
public PropertyFinder(string fullTypeName, string propertyName, InstructionHandleResult result)
+ : base(nounPhrase: $"{fullTypeName}.{propertyName} property")
{
this.FullTypeName = fullTypeName;
this.PropertyName = propertyName;
this.Result = result;
- this.NounPhrase = $"{fullTypeName}.{propertyName} property";
- }
-
- /// <summary>Perform the predefined logic for a method if applicable.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="method">The method definition containing the instruction.</param>
- /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
- /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged)
- {
- return InstructionHandleResult.None;
}
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
/// <param name="module">The assembly module containing the instruction.</param>
/// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The instruction to handle.</param>
+ /// <param name="instruction">The CIL instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
return this.IsMatch(instruction)
? this.Result
diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs
index 459e3210..1029d350 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs
@@ -2,12 +2,13 @@ using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
namespace StardewModdingAPI.Framework.ModLoading.Finders
{
/// <summary>Finds references to a field, property, or method which returns a different type than the code expects.</summary>
/// <remarks>This implementation is purely heuristic. It should never return a false positive, but won't detect all cases.</remarks>
- internal class ReferenceToMemberWithUnexpectedTypeFinder : IInstructionHandler
+ internal class ReferenceToMemberWithUnexpectedTypeFinder : BaseInstructionHandler
{
/*********
** Fields
@@ -17,39 +18,23 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/*********
- ** Accessors
- *********/
- /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
- public string NounPhrase { get; private set; } = "";
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="validateReferencesToAssemblies">The assembly names to which to heuristically detect broken references.</param>
public ReferenceToMemberWithUnexpectedTypeFinder(string[] validateReferencesToAssemblies)
+ : base(nounPhrase: "")
{
this.ValidateReferencesToAssemblies = new HashSet<string>(validateReferencesToAssemblies);
}
- /// <summary>Perform the predefined logic for a method if applicable.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="method">The method definition containing the instruction.</param>
- /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
- /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged)
- {
- return InstructionHandleResult.None;
- }
-
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
/// <param name="module">The assembly module containing the instruction.</param>
/// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The instruction to handle.</param>
+ /// <param name="instruction">The CIL instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
// field reference
FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction);
diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
index 44b531a5..fefa88f4 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
@@ -2,12 +2,13 @@ using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
namespace StardewModdingAPI.Framework.ModLoading.Finders
{
/// <summary>Finds references to a field, property, or method which no longer exists.</summary>
/// <remarks>This implementation is purely heuristic. It should never return a false positive, but won't detect all cases.</remarks>
- internal class ReferenceToMissingMemberFinder : IInstructionHandler
+ internal class ReferenceToMissingMemberFinder : BaseInstructionHandler
{
/*********
** Fields
@@ -17,39 +18,23 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
/*********
- ** Accessors
- *********/
- /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
- public string NounPhrase { get; private set; } = "";
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="validateReferencesToAssemblies">The assembly names to which to heuristically detect broken references.</param>
public ReferenceToMissingMemberFinder(string[] validateReferencesToAssemblies)
+ : base(nounPhrase: "")
{
this.ValidateReferencesToAssemblies = new HashSet<string>(validateReferencesToAssemblies);
}
- /// <summary>Perform the predefined logic for a method if applicable.</summary>
- /// <param name="module">The assembly module containing the instruction.</param>
- /// <param name="method">The method definition containing the instruction.</param>
- /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
- /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged)
- {
- return InstructionHandleResult.None;
- }
-
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
/// <param name="module">The assembly module containing the instruction.</param>
/// <param name="cil">The CIL processor.</param>
- /// <param name="instruction">The instruction to handle.</param>
+ /// <param name="instruction">The CIL instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
// field reference
FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction);