public OperationRetBoolBinder(PythonBinaryOperationBinder operationBinder, ConversionBinder conversionBinder) :
     base(new BinderMappingInfo(
             operationBinder,
             ParameterMappingInfo.Parameter(0),
             ParameterMappingInfo.Parameter(1)
         ),
         new BinderMappingInfo(
             conversionBinder,
             ParameterMappingInfo.Action(0)
         )
     ) {
     _opBinder = operationBinder;
     _convBinder = conversionBinder;
 }
Example #2
0
 /// <summary>
 ///  Various helpers related to calling Python __*__ conversion methods 
 /// </summary>
 private Expression/*!*/ GetConversionFailedReturnValue(ConversionBinder/*!*/ convertToAction, DynamicMetaObject/*!*/ self) {
     switch (convertToAction.ResultKind) {
         case ConversionResultKind.ImplicitTry:
         case ConversionResultKind.ExplicitTry:
             return DefaultBinder.GetTryConvertReturnValue(convertToAction.Type);
         case ConversionResultKind.ExplicitCast:
         case ConversionResultKind.ImplicitCast:
             DefaultBinder db = BinderState.GetBinderState(convertToAction).Binder;
             return DefaultBinder.MakeError(
                 db.MakeConversionError(
                     convertToAction.Type,
                     self.Expression
                 )
             );
         default:
             throw new InvalidOperationException(convertToAction.ResultKind.ToString());
     }
 }
Example #3
0
        internal ConversionBinder/*!*/ Convert(Type/*!*/ type, ConversionResultKind resultKind) {
            if (_conversionBinders == null) {
                Interlocked.CompareExchange(
                    ref _conversionBinders,
                    new Dictionary<Type, ConversionBinder>[(int)ConversionResultKind.ExplicitTry + 1], // max conversion result kind
                    null
                );
            }

            if (_conversionBinders[(int)resultKind] == null) {
                Interlocked.CompareExchange(
                    ref _conversionBinders[(int)resultKind],
                    new Dictionary<Type, ConversionBinder>(),
                    null
                );
            }

            Dictionary<Type, ConversionBinder> dict = _conversionBinders[(int)resultKind];
            lock (dict) {
                ConversionBinder res;
                if (!dict.TryGetValue(type, out res)) {
                    dict[type] = res = new ConversionBinder(this, type, resultKind);
                }

                return res;
            }
        }