Example #1
0
 IIntermediateBinaryOperatorCoercionMember IIntermediateBinaryOperatorCoercionMemberDictionary.Add(CoercibleBinaryOperators op, BinaryOpCoercionContainingSide containingSide, IType otherSide, IType returnType)
 {
     return(this.Add(op, containingSide, otherSide, returnType));
 }
Example #2
0
 /// <summary>
 /// Returns the <see cref="IIntermediateBinaryOperatorCoercionMember{TType, TIntermediateType}"/> which
 /// coerces the <paramref name="op"/> provided with the
 /// parent contained on the <paramref name="side"/> provided with
 /// <paramref name="otherSide"/> provided.
 /// </summary>
 /// <param name="op">The <see cref="CoercibleBinaryOperators"/>
 /// coerced by the <see cref="IIntermediateBinaryOperatorCoercionMember{TType, TIntermediateType}"/>
 /// to find.</param>
 /// <param name="side">The side at which the containing type
 /// is in the coercion.</param>
 /// <param name="otherSide">The type of the other side in the coercion.</param>
 /// <returns>A <see cref="IIntermediateBinaryOperatorCoercionMember{TType, TIntermediateType}"/> instance
 /// that coerces the <paramref name="op"/> provided.</returns>
 public IIntermediateBinaryOperatorCoercionMember <TType, TIntermediateType> this[CoercibleBinaryOperators op, BinaryOpCoercionContainingSide side, IType otherSide]
 {
     get
     {
         foreach (var binOpC in this.Values)
         {
             if (binOpC.Operator == op && binOpC.ContainingSide == side && binOpC.OtherSide.Equals(otherSide))
             {
                 return(binOpC);
             }
         }
         return(null);
     }
 }
Example #3
0
            public IIntermediateBinaryOperatorCoercionMember <TType, TIntermediateType> Add(CoercibleBinaryOperators op, BinaryOpCoercionContainingSide containingSide, IType otherSide, IType returnType)
            {
                BinaryOperatorMember member = this.Parent.GetNewBinaryOperator(op, containingSide, returnType);//new BinaryOperatorMember(this.Parent);

                if (containingSide != BinaryOpCoercionContainingSide.Both)
                {
                    if (otherSide == null)
                    {
                        throw new ArgumentNullException("otherSide");
                    }
                    else
                    {
                        member.OtherSide = otherSide;
                    }
                }
                this.AddDeclaration(member);
                return(member);
            }
Example #4
0
 IBinaryOperatorCoercionMember IBinaryOperatorCoercionMemberDictionary.this[CoercibleBinaryOperators op, BinaryOpCoercionContainingSide side, IType otherSide]
 {
     get { return(this[op, side, otherSide]); }
 }
Example #5
0
        internal static IBinaryOperatorUniqueIdentifier GetBinaryOperatorIdentifier(ICliMetadataMethodDefinitionTableRow methodDef, IType owner, _ICliManager manager)
        {
            var left  = manager.ObtainTypeReference(methodDef.Signature.Parameters[0].ParameterType, owner, null, owner == null ? null : owner.Assembly);
            var right = manager.ObtainTypeReference(methodDef.Signature.Parameters[1].ParameterType, owner, null, owner == null ? null : owner.Assembly);
            BinaryOpCoercionContainingSide containingSide =
                (left == owner && right == owner) ? BinaryOpCoercionContainingSide.Both :
                left == owner ? BinaryOpCoercionContainingSide.LeftSide :
                right == owner ? BinaryOpCoercionContainingSide.RightSide : BinaryOpCoercionContainingSide.Invalid;
            IType otherSide = containingSide == BinaryOpCoercionContainingSide.LeftSide ?
                              right : containingSide == BinaryOpCoercionContainingSide.RightSide ?
                              left : owner;

            if (containingSide == BinaryOpCoercionContainingSide.Invalid)
            {
                /* *
                 * Fix for generic types which have binary operators which contain the owner's type-parameters as part of a closure.
                 * This is effectively redundant
                 * */
                var genericOwner = owner as IGenericType;
                if (genericOwner != null)
                {
                    if (genericOwner.IsGenericConstruct && genericOwner.IsGenericDefinition)
                    {
                        var genericOwnerSelfClosure = genericOwner.MakeGenericClosure((from IGenericParameter gp in genericOwner.TypeParameters.Values
                                                                                       select(IType) gp).ToArray());
                        containingSide =
                            (left == genericOwnerSelfClosure && right == genericOwnerSelfClosure) ? BinaryOpCoercionContainingSide.Both :
                            left == genericOwnerSelfClosure ? BinaryOpCoercionContainingSide.LeftSide :
                            right == genericOwnerSelfClosure ? BinaryOpCoercionContainingSide.RightSide : BinaryOpCoercionContainingSide.Invalid;
                    }
                    otherSide = containingSide == BinaryOpCoercionContainingSide.LeftSide ?
                                right : containingSide == BinaryOpCoercionContainingSide.RightSide ?
                                left : genericOwner;
                }
            }
            switch (methodDef.Name)
            {
            case CliCommon.BinaryOperatorNames.Addition:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.Add, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.BitwiseAnd:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.BitwiseAnd, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.BitwiseOr:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.BitwiseOr, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.Division:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.Divide, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.Equality:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.IsEqualTo, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.ExclusiveOr:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.ExclusiveOr, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.GreaterThan:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.GreaterThan, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.GreaterThanOrEqual:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.GreaterThanOrEqualTo, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.Inequality:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.IsNotEqualTo, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.LeftShift:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.LeftShift, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.LessThan:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.LessThan, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.LessThanOrEqual:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.LessThanOrEqualTo, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.Modulus:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.Modulus, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.Multiply:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.Multiply, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.RightShift:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.RightShift, containingSide, otherSide));

            case CliCommon.BinaryOperatorNames.Subtraction:
                return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(CoercibleBinaryOperators.Subtract, containingSide, otherSide));

            default:
                throw new InvalidOperationException();
            }
        }
Example #6
0
 internal static IBinaryOperatorUniqueIdentifier GetBinaryOperatorIdentifier(CoercibleBinaryOperators @operator, BinaryOpCoercionContainingSide containingSide = BinaryOpCoercionContainingSide.Both, IType otherSide = null)
 {
     return(new DefaultBinaryOperatorUniqueIdentifier(@operator, containingSide, otherSide));
 }
Example #7
0
 public IBinaryOperatorCoercionMember <TCoercionParent> this[CoercibleBinaryOperators op, BinaryOpCoercionContainingSide side, IType otherSide]
 {
     get {
         foreach (var element in this.Values)
         {
             if (element.Operator == op && element.ContainingSide == side &&
                 element.OtherSide == otherSide)
             {
                 return(element);
             }
         }
         throw new KeyNotFoundException();
     }
 }