private void AddFallbackMemberTest(Type t, EventTracker et)
 {
     if (t == typeof(EventTracker))
     {
         //
         // Test Generated:
         //   ScriptingRuntimeHelpers.GetEventHandlerType(((EventTracker)args[0]).Event) == et.Event.EventHandlerType
         //
         _rule.AddTest(
             Ast.Equal(
                 Ast.Call(
                     typeof(ScriptingRuntimeHelpers).GetMethod("GetEventHandlerType"),
                     Ast.Property(
                         Ast.Convert(
                             _rule.Parameters[0],
                             typeof(EventTracker)
                             ),
                         typeof(EventTracker).GetProperty("Event")
                         )
                     ),
                 Ast.Constant(et.Event.EventHandlerType)
                 )
             );
     }
     else if (t == typeof(BoundMemberTracker))
     {
         //
         // Test Generated:
         //   ScriptingRuntimeHelpers.GetEventHandlerType(((EventTracker)((BoundMemberTracker)args[0]).BountTo).Event) == et.Event.EventHandlerType
         //
         _rule.AddTest(
             Ast.Equal(
                 Ast.Call(
                     typeof(ScriptingRuntimeHelpers).GetMethod("GetEventHandlerType"),
                     Ast.Property(
                         Ast.Convert(
                             Ast.Property(
                                 Ast.Convert(
                                     _rule.Parameters[0],
                                     typeof(BoundMemberTracker)
                                     ),
                                 typeof(BoundMemberTracker).GetProperty("BoundTo")
                                 ),
                             typeof(EventTracker)
                             ),
                         typeof(EventTracker).GetProperty("Event")
                         )
                     ),
                 Ast.Constant(et.Event.EventHandlerType)
                 )
             );
     }
 }
Example #2
0
        private bool MakeGetMemberRule(OldGetMemberAction action, CodeContext context, RuleBuilder rule)
        {
            object value;

            if (TryGetValue(action.Name, out value))
            {
                Debug.Assert(value is MemberTracker);
                MemberTracker memValue = (MemberTracker)value;

                rule.MakeTest(typeof(NamespaceTracker));
                rule.AddTest(
                    Expression.Equal(
                        Expression.Property(
                            Expression.Convert(rule.Parameters[0], typeof(NamespaceTracker)),
                            typeof(NamespaceTracker).GetProperty("Id")
                            ),
                        Expression.Constant(Id)
                        )
                    );


                Expression target = context.LanguageContext.Binder.ReturnMemberTracker(memValue.DeclaringType, memValue);

                rule.Target = rule.MakeReturn(context.LanguageContext.Binder, target);
                return(true);
            }
            return(false);
        }
Example #3
0
        public void MakeRule()
        {
            Type toType    = Action.ToType;
            Type knownType = CompilerHelpers.GetVisibleType(_rule.Parameters[0].Type);

            // check for conversion to object first...
            if (TryConvertToObject(toType, knownType))
            {
                _rule.AddTest(Ast.Constant(true));
                return;
            }

            // do checks that aren't based upon strongly knowing the object's type (and don't require tests)
            if (TryAllConversions(toType, knownType))
            {
                _rule.AddTest(Ast.Constant(true));
                return;
            }

            // try again w/ a test for the known-type
            Type type = CompilerHelpers.GetType(_arg);

            _rule.AddTest(_rule.MakeTypeTest(type, 0));

            if (TryAllConversions(toType, type))
            {
                return;
            }

            // finally try conversions that aren't based upon the incoming type at all but
            // are last chance conversions based on the destination type
            if (TryExtraConversions(toType))
            {
                return;
            }

            // no conversion is available, make an error rule.
            MakeErrorTarget();
        }
Example #4
0
        private bool MakeGetMemberRule(OldGetMemberAction action, CodeContext context, RuleBuilder rule) {
            object value;
            if (TryGetValue(action.Name, out value)) {
                Debug.Assert(value is MemberTracker);
                MemberTracker memValue = (MemberTracker)value;

                rule.MakeTest(typeof(NamespaceTracker));
                rule.AddTest(
                    Expression.Equal(
                        Expression.Property(
                            Expression.Convert(rule.Parameters[0], typeof(NamespaceTracker)),
                            typeof(NamespaceTracker).GetProperty("Id")
                        ),
                        AstUtils.Constant(Id)
                    )
                );


                Expression target = context.LanguageContext.Binder.ReturnMemberTracker(memValue.DeclaringType, memValue);

                rule.Target = rule.MakeReturn(context.LanguageContext.Binder, target);
                return true;
            }
            return false;
        }