Example #1
0
 protected virtual void EmitEventInvocationWithTryCatchIfNeeded(
     EventInvocation invocationStyle,
     Type exceptionType,
     CompositeMethodGenerationInfo invokeMethod,
     CILMethod eventMethodToInvoke,
     Action <MethodIL> loadEventAction,
     Boolean storeResult
     )
 {
     invokeMethod.IL.EmitTryCatch(
         EXCEPTION_TYPE,
         il2 =>
     {
         loadEventAction(il2);
         for (Int32 idx = 0; idx < invokeMethod.Parameters.Count; ++idx)
         {
             il2.EmitLoadArg(invokeMethod.Parameters[idx].Position + 1);
         }
         il2.EmitCall(eventMethodToInvoke);
         if (storeResult && !VOID_TYPE.Equals(eventMethodToInvoke.GetReturnType()))
         {
             var resultB = invokeMethod.GetOrCreateLocal(LB_RESULT, invokeMethod.ReturnType);
             il2.EmitStoreLocal(resultB);
         }
     },
         EventInvocation.INVOKE_DIRECTLY.Equals(invocationStyle) ? (Action <MethodIL>)null : il2 =>
     {
         if (exceptionType != null)
         {
             this.EmitStoreExceptionListWithinCatch(invokeMethod);
         }
         else
         {
             throw new InternalException("Non-direct event invocation style, but no exception type specified.");
         }
     },
         false
         );
 }
Example #2
0
 protected override void Visit_VOID_TYPE(VOID_TYPE node)
 {
     /* MOVE CODE HERE */
 }
Example #3
0
 protected virtual void Visit_VOID_TYPE(VOID_TYPE node)
 {
 }
Example #4
0
        protected virtual void EmitEventInvocationMethodCore(
            EventModel eventModel,
            CompositeTypeGenerationInfo thisGenerationInfo,
            CILField eventField,
            CILTypeBase fieldType,
            CompositeMethodGenerationInfo invokeMethod,
            CILMethod eventMethodToInvoke,
            Action <LocalBuilder, EventInvocation, Type> actualEventInvoking
            )
        {
            var eventInfo = eventModel.NativeInfo;
            var il        = invokeMethod.IL;

            var eventLB             = il.DeclareLocal(fieldType);
            var afterNullCheckLabel = il.DefineLabel();

            il
            .EmitLoadThisField(eventField)
            .EmitStoreLocal(eventLB)
            .EmitLoadLocal(eventLB)
            .EmitBranch(BranchType.IF_FALSE, afterNullCheckLabel);

            EventInvocation invocationStyle;
            Type            exceptionType;

            this.GetEventInvocationStyle(eventModel, out invocationStyle, out exceptionType);

            actualEventInvoking(eventLB, invocationStyle, exceptionType);

            // Throw exception if needed
            if (EventInvocation.INVOKE_ALL.Equals(invocationStyle))
            {
                // TODO TODO TODO
                this.EmitThrowIfExceptionListHasAny(invokeMethod, exceptionType.GetConstructor(EXCEPTION_ENUMERABLE_ARRAY).NewWrapper(this.ctx));
            }

            if (!VOID_TYPE.Equals(eventMethodToInvoke.GetReturnType()))
            {
                //LocalBuilder amountOfDeadB;
                //if ( invokeMethod.TryGetLocal( LB_AMOUNT_OF_DEAD_EVENT_INFOS, out amountOfDeadB ) )
                //{
                //   il
                //      .EmitLoadLocal( amountOfDeadB )
                //      .EmitBranch( BranchType.IF_FALSE, afterNullCheckLabel );
                //}
                LocalBuilder resultB;
                if (invokeMethod.TryGetLocal(LB_RESULT, out resultB))
                {
                    il.EmitLoadLocal(resultB);
                }
                var returnLabel = il.DefineLabel();
                il
                .EmitBranch(BranchType.ALWAYS, returnLabel)
                .MarkLabel(afterNullCheckLabel)
                .EmitLoadString("The event " + eventInfo.Name + " in ")
                .EmitReflectionObjectOf(TypeGenerationUtils.CreateTypeForEmitting(eventInfo.DeclaringType.NewWrapper(this.ctx), thisGenerationInfo.GenericArguments, null))
                .EmitCall(TO_STRING_METHOD)
                .EmitLoadString(" is not set.")
                .EmitCall(STRING_CONCAT_METHOD_3)
                .EmitThrowNewException(INVALID_OPERATION_EXCEPTION_CTOR_WITH_STRING)
                .MarkLabel(returnLabel);
            }
            else
            {
                il.MarkLabel(afterNullCheckLabel);
            }

            il.EmitReturn();
        }