diff --git a/RunSharp/RunSharp.csproj b/RunSharp/RunSharp.csproj index d1f88ff..e211e3b 100644 --- a/RunSharp/RunSharp.csproj +++ b/RunSharp/RunSharp.csproj @@ -34,6 +34,7 @@ prompt 4 bin\Debug\RunSharp.XML + 1591 pdbonly @@ -44,6 +45,7 @@ 4 true bin\Release\RunSharp.XML + 1591 true diff --git a/RunSharpIKVM/RunSharp_IKVM.csproj b/RunSharpIKVM/RunSharp_IKVM.csproj index 212baf4..fdf593c 100644 --- a/RunSharpIKVM/RunSharp_IKVM.csproj +++ b/RunSharpIKVM/RunSharp_IKVM.csproj @@ -34,6 +34,7 @@ prompt 4 bin\Debug\RunSharp.XML + 1591 pdbonly @@ -44,6 +45,7 @@ 4 true bin\Release\RunSharp.XML + 1591 false diff --git a/RunSharpShared/Aqla/AttributeMap.cs b/RunSharpShared/Aqla/AttributeMap.cs index 3a9ed55..058696e 100644 --- a/RunSharpShared/Aqla/AttributeMap.cs +++ b/RunSharpShared/Aqla/AttributeMap.cs @@ -225,7 +225,9 @@ public override bool TryGet(string key, bool publicOnly, out object value) value = null; return false; } + private readonly Attribute _attribute; + public ReflectionAttributeMap(Attribute attribute) { _attribute = attribute; diff --git a/RunSharpShared/Aqla/CompilerOptions.cs b/RunSharpShared/Aqla/CompilerOptions.cs index 21e46b2..307a6e6 100644 --- a/RunSharpShared/Aqla/CompilerOptions.cs +++ b/RunSharpShared/Aqla/CompilerOptions.cs @@ -47,8 +47,6 @@ limitations under the License. using System.Reflection.Emit; #endif -using System; - namespace TriAxis.RunSharp { /// @@ -76,8 +74,6 @@ public void SetFrameworkOptions(Type from, ITypeMapper mapper) } } - private string _imageRuntimeVersion; - private int _metaDataVersion; /// /// The TargetFrameworkAttribute FrameworkName value to burn into the generated assembly /// @@ -96,6 +92,10 @@ public void SetFrameworkOptions(Type from, ITypeMapper mapper) public string OutputPath { get; set; } #if FEAT_IKVM + + private string _imageRuntimeVersion; + private int _metaDataVersion; + /// /// The name of the container that holds the key pair. /// diff --git a/RunSharpShared/CodeGen.Statements.cs b/RunSharpShared/CodeGen.Statements.cs index eeeb090..cec2a1c 100644 --- a/RunSharpShared/CodeGen.Statements.cs +++ b/RunSharpShared/CodeGen.Statements.cs @@ -395,36 +395,34 @@ public void ThrowAssert(Operand condition, Operand message) #endregion #region Event subscription - public void SubscribeEvent(Operand target, string eventName, Operand handler) - { - if ((object)target == null) - throw new ArgumentNullException(nameof(target)); - if ((object)handler == null) - throw new ArgumentNullException(nameof(handler)); - IMemberInfo evt = TypeMapper.TypeInfo.FindEvent(target.GetReturnType(TypeMapper), eventName, target.IsStaticTarget); - MethodInfo mi = ((EventInfo)evt.Member).GetAddMethod(); - if (!target.IsStaticTarget) - target.EmitGet(this); - handler.EmitGet(this); - EmitCallHelper(mi, target); - } - - public void UnsubscribeEvent(Operand target, string eventName, Operand handler) + public void SubscribeEvent(Operand target, string eventName, Operand handler) + { + SubscribeOrUnsubscribeEvent(target, eventName, handler, true); + } + + public void UnsubscribeEvent(Operand target, string eventName, Operand handler) { - if ((object)target == null) - throw new ArgumentNullException(nameof(target)); - if ((object)handler == null) - throw new ArgumentNullException(nameof(handler)); + SubscribeOrUnsubscribeEvent(target, eventName, handler, false); + } - IMemberInfo evt = TypeMapper.TypeInfo.FindEvent(target.GetReturnType(TypeMapper), eventName, target.IsStaticTarget); - MethodInfo mi = ((EventInfo)evt.Member).GetRemoveMethod(); - if (!target.IsStaticTarget) - target.EmitGet(this); - handler.EmitGet(this); - EmitCallHelper(mi, target); - } -#endregion + void SubscribeOrUnsubscribeEvent(Operand target, string eventName, Operand handler, bool subscribe) + { + if ((object)target == null) + throw new ArgumentNullException(nameof(target)); + if ((object)handler == null) + throw new ArgumentNullException(nameof(handler)); + + IMemberInfo evt = TypeMapper.TypeInfo.FindEvent(target.GetReturnType(TypeMapper), eventName, target.IsStaticTarget); + var eventInfo = (EventInfo)evt.Member; + MethodInfo mi = subscribe ? eventInfo.GetAddMethod() : eventInfo.GetRemoveMethod(); + if (!target.IsStaticTarget) + target.EmitGet(this); + handler.EmitGet(this); + EmitCallHelper(mi, target); + } + + #endregion public void InitObj(Operand target) { @@ -458,36 +456,15 @@ interface IContinuable public void Break() { - BeforeStatement(); - - bool useLeave = false; - - foreach (Block blk in _blocks) - { - ExceptionBlock xb = blk as ExceptionBlock; - - if (xb != null) - { - if (xb.IsFinally) - throw new InvalidOperationException(Properties.Messages.ErrInvalidFinallyBranch); - - useLeave = true; - } - - IBreakable brkBlock = blk as IBreakable; - - if (brkBlock != null) - { - IL.Emit(useLeave ? OpCodes.Leave : OpCodes.Br, brkBlock.GetBreakTarget()); - IsReachable = false; - return; - } - } - - throw new InvalidOperationException(Properties.Messages.ErrInvalidBreak); + LeaveBlock(blk => (blk as IBreakable)?.GetBreakTarget()); } - public void Continue() + public void Continue() + { + LeaveBlock(blk => (blk as IContinuable)?.GetContinueTarget()); + } + + void LeaveBlock(RunSharpFunc tryGetJumpLabel) { BeforeStatement(); @@ -505,11 +482,12 @@ public void Continue() useLeave = true; } - IContinuable cntBlock = blk as IContinuable; - if (cntBlock != null) - { - IL.Emit(useLeave ? OpCodes.Leave : OpCodes.Br, cntBlock.GetContinueTarget()); + Label? label = tryGetJumpLabel(blk); + + if (label != null) + { + IL.Emit(useLeave ? OpCodes.Leave : OpCodes.Br, label.Value); IsReachable = false; return; } diff --git a/RunSharpShared/Conversion.cs b/RunSharpShared/Conversion.cs index 4c2e9cc..a071e02 100644 --- a/RunSharpShared/Conversion.cs +++ b/RunSharpShared/Conversion.cs @@ -331,27 +331,7 @@ public static Conversion FindImplicit(List collection, Type @from, } } - if (sx == null || tx == null) - return new Ambiguous(typeMapper); - - UserDefined match = null; - - for (int i = 0; i < collection.Count; i++) - { - UserDefined udc = collection[i]; - if (udc._fromType == sx && udc._toType == tx) - { - if (match != null) - return new Ambiguous(typeMapper); // ambiguous match - else - match = udc; - } - } - - if (match == null) - return new Ambiguous(typeMapper); - - return match; + return FindConversation_Match(collection, sx, tx, typeMapper); } public static Conversion FindExplicit(List collection, Type @from, Type to, ITypeMapper typeMapper) @@ -438,28 +418,29 @@ public static Conversion FindExplicit(List collection, Type @from, } } - if (sx == null || tx == null) - return new Ambiguous(typeMapper); + return FindConversation_Match(collection, sx, tx, typeMapper); + } - UserDefined match = null; + static Conversion FindConversation_Match(List collection, Type sx, Type tx, ITypeMapper typeMapper) + { + if (sx == null || tx == null) + return new Ambiguous(typeMapper); - for (int i = 0; i < collection.Count; i++) - { - UserDefined udc = collection[i]; - if (udc._fromType == sx && udc._toType == tx) - { - if (match != null) - return new Ambiguous(typeMapper); // ambiguous match - else - match = udc; - } - } + Conversion match = null; - if (match == null) - return new Ambiguous(typeMapper); - - return match; - } + for (int i = 0; i < collection.Count; i++) + { + UserDefined udc = collection[i]; + if (udc._fromType == sx && udc._toType == tx) + { + if (match != null) + return new Ambiguous(typeMapper); // ambiguous match + match = udc; + } + } + + return match ?? new Ambiguous(typeMapper); + } } #endregion diff --git a/RunSharpShared/DelegateGen.cs b/RunSharpShared/DelegateGen.cs index 5a1dc74..e5da653 100644 --- a/RunSharpShared/DelegateGen.cs +++ b/RunSharpShared/DelegateGen.cs @@ -53,9 +53,7 @@ public class DelegateGen : SignatureGen TypeGen _delegateType; List _customAttributes; readonly TypeGen _owner2; - - public ITypeMapper TypeMapper => _owner != null ? _owner.TypeMapper : _owner2.TypeMapper; - + public DelegateGen(AssemblyGen owner, string name, Type returnType, TypeAttributes attrs) : base(returnType, owner.TypeMapper) { diff --git a/RunSharpSilverlight/RunSharp_Silverlight.csproj b/RunSharpSilverlight/RunSharp_Silverlight.csproj index 03dce7f..9980d83 100644 --- a/RunSharpSilverlight/RunSharp_Silverlight.csproj +++ b/RunSharpSilverlight/RunSharp_Silverlight.csproj @@ -53,6 +53,7 @@ 4 Bin\Debug\RunSharp.XML AllRules.ruleset + 1591 pdbonly @@ -65,6 +66,7 @@ 4 bin\Release\RunSharp.XML AllRules.ruleset + 1591 true @@ -97,7 +99,8 @@ PreserveNewest - + +