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(); } }
public IBinaryOperatorUniqueIdentifier GetIdentifier(IIntermediateBinaryOperatorCoercionMember member) { return(TypeSystemIdentifiers.GetBinaryOperatorIdentifier(member.Operator, member.UserSpecificQualifier, member.ContainingSide, member.OtherSide)); }