Browse Source

Pulled out common LoadCorrectStore pattern

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
64b80f68cf
2 changed files with 23 additions and 15 deletions
  1. +21
    -5
      IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs
  2. +2
    -10
      IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs

+ 21
- 5
IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs View File

@ -47,12 +47,13 @@ namespace IPA.Config.Stores
il.Emit(OpCodes.Call, member.Nullable_Value.GetGetMethod()); il.Emit(OpCodes.Call, member.Nullable_Value.GetGetMethod());
} }
if (!member.ConversionType.IsValueType)
var convType = member.ConversionType;
if (!convType.IsValueType)
{ {
// currently the only thing for this is where expect == Map, so do generate shit // currently the only thing for this is where expect == Map, so do generate shit
var copyFrom = typeof(IGeneratedStore<>).MakeGenericType(member.ConversionType).GetMethod(nameof(IGeneratedStore<Config>.CopyFrom));
var copyFrom = typeof(IGeneratedStore<>).MakeGenericType(convType).GetMethod(nameof(IGeneratedStore<Config>.CopyFrom));
var noCreate = il.DefineLabel(); var noCreate = il.DefineLabel();
var valLocal = GetLocal(member.Type);
var valLocal = GetLocal(convType);
if (!alwaysNew) if (!alwaysNew)
{ {
@ -69,7 +70,7 @@ namespace IPA.Config.Stores
il.Emit(OpCodes.Brtrue_S, noCreate); il.Emit(OpCodes.Brtrue_S, noCreate);
il.Emit(OpCodes.Pop); il.Emit(OpCodes.Pop);
} }
EmitCreateChildGenerated(il, member.Type, parentobj);
EmitCreateChildGenerated(il, convType, parentobj);
il.MarkLabel(noCreate); il.MarkLabel(noCreate);
il.Emit(OpCodes.Dup); il.Emit(OpCodes.Dup);
@ -79,7 +80,12 @@ namespace IPA.Config.Stores
} }
else else
{ {
// TODO: impl the rest of this
// for special value types, we'll go ahead and correct each of their members
var structure = ReadObjectMembers(convType);
var valueLocal = GetLocal(convType);
il.Emit(OpCodes.Stloc, valueLocal);
} }
if (member.IsNullable) if (member.IsNullable)
@ -87,5 +93,15 @@ namespace IPA.Config.Stores
il.MarkLabel(endLabel); il.MarkLabel(endLabel);
} }
private static void EmitLoadCorrectStore(ILGenerator il, SerializedMemberInfo member, bool shouldLock, bool alwaysNew, GetLocal GetLocal,
Action<ILGenerator> loadFrom, Action<ILGenerator> storeTo, Action<ILGenerator> parentobj)
{
EmitStore(il, member, il =>
{
EmitLoad(il, member, loadFrom); // load the member
EmitCorrectMember(il, member, shouldLock, alwaysNew, GetLocal, storeTo, parentobj); // correct it
}, storeTo);
}
} }
} }

+ 2
- 10
IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs View File

@ -124,11 +124,7 @@ namespace IPA.Config.Stores
foreach (var member in structure) foreach (var member in structure)
{ {
EmitStore(il, member, il =>
{
EmitLoad(il, member, GetMethodThis); // load the member
EmitCorrectMember(il, member, false, true, GetLocal, GetMethodThis, GetMethodThis); // correct it
}, GetMethodThis);
EmitLoadCorrectStore(il, member, false, true, GetLocal, GetMethodThis, GetMethodThis, GetMethodThis);
} }
il.Emit(OpCodes.Pop); il.Emit(OpCodes.Pop);
@ -594,11 +590,7 @@ namespace IPA.Config.Stores
{ {
il.BeginExceptionBlock(); il.BeginExceptionBlock();
EmitStore(il, member, il =>
{
EmitLoad(il, member, il => il.Emit(OpCodes.Ldarg_1));
EmitCorrectMember(il, member, false, false, GetLocal, GetMethodThis, GetMethodThis);
}, GetMethodThis);
EmitLoadCorrectStore(il, member, false, false, GetLocal, il => il.Emit(OpCodes.Ldarg_1), GetMethodThis, GetMethodThis);
il.BeginCatchBlock(typeof(Exception)); il.BeginCatchBlock(typeof(Exception));


Loading…
Cancel
Save