private ICliMetadataCustomAttribute GetCustomAttribute(_ICliManager identityManager, ICliMetadataCustomAttributeTableRow target, _ICliMetadataBlobEntry entry)
        {
            uint offset = target.ValueIndex + entry.LengthByteCount;

            this.reader.BaseStream.Seek(offset, SeekOrigin.Begin);
            return((ICliMetadataCustomAttribute)(entry.Signature = SignatureParser.ParseCustomAttribute(reader, metadataRoot, identityManager, target, (uint)entry.Length)));
        }
Exemple #2
0
        public CliParameterMemberDictionary(_ICliManager manager, uint methodIndex, ICliMetadataRoot metadataRoot, TParent parent, int dropoff = 0)
        {
            this.manager = manager;
            this.parent  = parent;
            var method = metadataRoot.TableStream.MethodDefinitionTable[(int)methodIndex];

            this.signature = method.Signature;
            bool skipFirst = false;

            if (method.Parameters.Count > 0 &&
                method.Parameters[0].Sequence == 0)
            {
                skipFirst = true;
            }
            if (dropoff != 0)
            {
                if (skipFirst)
                {
                    this.Initialize(method.Parameters.Skip(1).Drop(dropoff).ToArray());
                }
                else
                {
                    this.Initialize(method.Parameters.Drop(dropoff).ToArray());
                }
            }
            else if (skipFirst)
            {
                this.Initialize(method.Parameters.Skip(1).ToArray());
            }
            else
            {
                this.Initialize(method.Parameters);
            }
        }
Exemple #3
0
 internal CliMetadataCollection(IControlledCollection <ICliMetadataCustomAttributeTableRow> sourceData, IMetadataEntity declarationPoint, _ICliManager identityManager)
 {
     this.declarationPoint = declarationPoint;
     this.sourceData       = sourceData;
     this.metadataSet      = new IMetadatum[this.Count];
     this.identityManager  = identityManager;
 }
Exemple #4
0
 public CliMetadatum(ICliMetadataCustomAttributeTableRow metadataEntry, _ICliAssembly owner)
 {
     this.declarationPoint = owner;
     this.metadataEntry    = metadataEntry;
     this.identityManager  = owner.IdentityManager;
     this.parameters       = new Lazy <IEnumerable <MetadatumTypedParameter> >(() => this.GetParameters().SinglePass(), true);
     this.namedParameters  = new Lazy <IEnumerable <MetadatumNamedParameter> >(() => this.GetNamedParameters().SinglePass(), true);;
 }
Exemple #5
0
 public CliSignatureTypeCollection(_ICliManager manager, ICliMetadataMethodSignature signature, IType activeType, IMethodSignatureMember activeMethod)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (signature == null)
     {
         throw new ArgumentNullException("signature");
     }
     this.manager        = manager;
     this.signatureTypes = new IType[signature.Parameters.Count];
     this.ActiveType     = activeType;
     this.ActiveMethod   = activeMethod;
     this.signature      = signature;
 }
        public ICliMetadataCustomAttribute _GetCustomAttribute(_ICliManager identityManager, ICliMetadataCustomAttributeTableRow target)
        {
            uint heapIndex = target.ValueIndex;

            if (heapIndex >= this.Size)
            {
                throw new ArgumentOutOfRangeException("heapIndex");
            }
            SmallBlobEntry  smallResult;
            MediumBlobEntry mediumResult;
            LargeBlobEntry  largeResult;

            lock (this.syncObject)
            {
                if (smallEntries.TryGetValue(heapIndex, out smallResult))
                {
                    if (smallResult.Signature == null)
                    {
                        GetCustomAttribute(identityManager, target, smallResult);
                    }
                    return((ICliMetadataCustomAttribute)smallResult.Signature);
                }
                else if (mediumEntries.TryGetValue(heapIndex, out mediumResult))
                {
                    if (mediumResult.Signature == null)
                    {
                        GetCustomAttribute(identityManager, target, mediumResult);
                    }
                    return((ICliMetadataCustomAttribute)mediumResult.Signature);
                }
                else if (!largEntries.TryGetValue(heapIndex, out largeResult))
                {
                    throw new IndexOutOfRangeException("heapIndex");
                }
                else
                {
                    if (largeResult.Signature == null)
                    {
                        GetCustomAttribute(identityManager, target, largeResult);
                    }
                    return((ICliMetadataCustomAttribute)largeResult.Signature);
                }
            }
            throw new ArgumentOutOfRangeException("heapIndex");
        }
Exemple #7
0
 internal static ICliMetadataRoot GetEventDelegateMetadataRoot(ICliMetadataEventTableRow metadataEntry, _ICliManager manager)
 {
     return(manager.ResolveScope(metadataEntry.SignatureType).MetadataRoot);
 }
Exemple #8
0
        internal static uint GetEventDelegateMethod(ICliMetadataEventTableRow metadataEntry, _ICliManager manager)
        {
            var signatureType = manager.ObtainTypeReference(metadataEntry.SignatureType);

            if (!(signatureType is IDelegateType))
            {
                throw new BadImageFormatException("Event must reference a delegate type to properly function.");
            }
            var delegateType = (ICliDelegateType)signatureType;

            return(delegateType.InvokeMethodIndex);
        }
Exemple #9
0
        internal static IUnaryOperatorUniqueIdentifier GetUnaryOperatorIdentifier(ICliMetadataMethodDefinitionTableRow methodDef, IType owner, _ICliManager manager)
        {
            switch (methodDef.Name)
            {
            case CliCommon.UnaryOperatorNames.Decrement:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.Decrement));

            case CliCommon.UnaryOperatorNames.False:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.EvaluatesToFalse));

            case CliCommon.UnaryOperatorNames.Increment:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.Increment));

            case CliCommon.UnaryOperatorNames.LogicalNot:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.LogicalInvert));

            case CliCommon.UnaryOperatorNames.Negation:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.Negation));

            case CliCommon.UnaryOperatorNames.OnesComplement:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.Complement));

            case CliCommon.UnaryOperatorNames.Plus:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.Plus));

            case CliCommon.UnaryOperatorNames.True:
                return(TypeSystemIdentifiers.GetUnaryOperatorIdentifier(CoercibleUnaryOperators.EvaluatesToTrue));

            default:
                throw new InvalidOperationException();
            }
        }
Exemple #10
0
        internal static IGeneralMemberUniqueIdentifier GetTypeCoercionOperatorIdentifier(ICliMetadataMethodDefinitionTableRow methodDef, IType owner, _ICliManager manager)
        {
            var coercionParameter = methodDef.Signature.Parameters.FirstOrDefault();

            if (coercionParameter == null)
            {
                return(null);
            }
            var coercionType = manager.ObtainTypeReference(coercionParameter.ParameterType, owner, null, owner == null ? null : owner.Assembly);
            var returnType   = manager.ObtainTypeReference(methodDef.Signature.ReturnType, owner, null, owner == null ? null : owner.Assembly);

            if (coercionType == null || returnType == null)
            {
                return(null);
            }
            var genericOwner = owner as IGenericType;
            TypeConversionRequirement requirement = (methodDef.Name == CliCommon.TypeCoercionNames.Implicit) ? TypeConversionRequirement.Implicit : (methodDef.Name == CliCommon.TypeCoercionNames.Explicit) ? TypeConversionRequirement.Explicit : TypeConversionRequirement.Unknown;

            if (genericOwner == null)
            {
                goto nonGenericResolution;
            }
            else
            {
                if (owner.IsGenericConstruct)
                {
                    if (TypesAreEquivalent(owner, coercionType))
                    {
                        return(TypeSystemIdentifiers.GetTypeOperatorFromIdentifier(requirement, returnType));
                    }
                    else if (TypesAreEquivalent(owner, returnType))
                    {
                        return(TypeSystemIdentifiers.GetTypeOperatorToIdentifier(requirement, coercionType));
                    }
                    else
                    {
                        goto nonGenericResolution;
                    }
                }
                else
                {
                    goto nonGenericResolution;
                }
            }
nonGenericResolution:
            if (owner == coercionType)
            {
                return(TypeSystemIdentifiers.GetTypeOperatorFromIdentifier(requirement, returnType));
            }
            else if (owner == returnType)
            {
                return(TypeSystemIdentifiers.GetTypeOperatorToIdentifier(requirement, coercionType));
            }
            else
            {
                return(null);
            }
        }
Exemple #11
0
        internal static IGeneralGenericSignatureMemberUniqueIdentifier GetMethodIdentifier(ICliMetadataMethodDefinitionTableRow methodDef, IType owner, _ICliManager manager, Func <IMethodSignatureMember> memberGetter)
        {
            bool typeParamCheck = methodDef.MetadataRoot.TableStream.GenericParameterTable != null;

            if (typeParamCheck)
            {
                return(TypeSystemIdentifiers.GetGenericSignatureIdentifier(methodDef.Name, methodDef.TypeParameters.Count, (from p in methodDef.Signature.Parameters
                                                                                                                            select manager.ObtainTypeReference(p.ParameterType, owner, memberGetter(), owner == null ? null : owner.Assembly)).SinglePass()));
            }
            else
            {
                return(TypeSystemIdentifiers.GetGenericSignatureIdentifier(methodDef.Name, 0, (from p in methodDef.Signature.Parameters
                                                                                               select manager.ObtainTypeReference(p.ParameterType, owner, memberGetter(), owner == null ? null : owner.Assembly)).SinglePass()));
            }
        }
Exemple #12
0
        internal static IGeneralSignatureMemberUniqueIdentifier GetIndexerIdentifier(ICliMetadataPropertyTableRow indexerDef, IType owner, _ICliManager manager)
        {
            ICliMetadataMethodDefinitionTableRow targetMethod = null;
            bool knockOffLast = false;
            var  getMethod    = targetMethod = indexerDef.GetMethod;

            if (getMethod == null)
            {
                targetMethod = indexerDef.SetMethod;
                if (targetMethod == null)
                {
                    var semanticMethod = indexerDef.Methods.FirstOrDefault();
                    if (semanticMethod != null)
                    {
                        targetMethod = semanticMethod.Method;
                    }
                }
                else
                {
                    knockOffLast = true;
                }
            }
            if (targetMethod != null)
            {
                return(TypeSystemIdentifiers.GetSignatureIdentifier(indexerDef.Name, (from p in (knockOffLast ? targetMethod.Signature.Parameters.Take(targetMethod.Signature.Parameters.Count - 1) : targetMethod.Signature.Parameters)
                                                                                      select manager.ObtainTypeReference(p.ParameterType, owner, null, owner == null ? null : owner.Assembly)).SinglePass()));
            }
            else
            {
                return(TypeSystemIdentifiers.GetSignatureIdentifier(indexerDef.Name));
            }
        }
Exemple #13
0
 internal static ISignatureMemberUniqueIdentifier GetEventIdentifier(ICliMetadataEventTableRow eventDef, IType owner, _ICliManager manager)
 {
     return(TypeSystemIdentifiers.GetSignatureIdentifier(eventDef.Name, (from p in ((IDelegateType)manager.ObtainTypeReference(eventDef.SignatureType, owner, null, owner == null ? null : owner.Assembly)).Parameters.Values
                                                                         select p.ParameterType).SinglePass()));
 }
Exemple #14
0
 internal static ISignatureMemberUniqueIdentifier GetCtorIdentifier(ICliMetadataMethodDefinitionTableRow methodDef, IType owner, _ICliManager manager)
 {
     return(TypeSystemIdentifiers.GetCtorSignatureIdentifier((from p in methodDef.Signature.Parameters
                                                              select manager.ObtainTypeReference(p.ParameterType, owner, null, owner == null ? null : owner.Assembly)).SinglePass()));
 }
Exemple #15
0
        internal static ICompilerErrorCollection ValidateMetadata(IAssembly hostAssembly, ICliMetadataRoot metadataRoot, _ICliManager identityManager)
        {
            CompilerErrorCollection resultErrorCollection = new CompilerErrorCollection();

            /* *
             * Read in the tables so each table isn't read in a disjointed manner.
             * *
             * Until the validation reaches full scope, this will actually slow
             * things down; determination of speed increase will be when full
             * metadata coverage is reached.
             * */
            //Parallel.ForEach(metadataRoot.TableStream.Values, table => table.Read());
            ValidateModuleTable(hostAssembly, metadataRoot, resultErrorCollection);
            ValidateTypeReferenceTable(hostAssembly, metadataRoot, resultErrorCollection);
            ValidateTypeDefinitionTable(hostAssembly, metadataRoot, resultErrorCollection, identityManager);
            ValidateAssemblyTable(hostAssembly, metadataRoot, resultErrorCollection);
            return(resultErrorCollection);
        }
Exemple #16
0
 internal Parameters(_ICliManager manager, ICliMetadataEventTableRow metadataEntry, CliEventSignatureMember <TEvent, TEventParent> parent)
     : base(manager, metadataEntry, parent)
 {
 }
Exemple #17
0
        internal static bool IsLastParams <TParent, TParameter>(this IParameterParent <TParent, TParameter> parent, ICliAssembly assembly, _ICliManager manager)
            where TParent :
        IParameterParent <TParent, TParameter>
            where TParameter :
        class,
        IParameterMember <TParent>
        {
            var @params   = parent.Parameters;
            var lastParam = @params.Count == 0 ? (TParameter)null : @params[@params.Keys[@params.Count - 1]];

            if (lastParam == null)
            {
                return(false);
            }
            return(lastParam.IsDefined(manager.ObtainTypeReference(assembly.RuntimeEnvironment.ParamArrayMetadatum, assembly)));
        }
Exemple #18
0
        private static void ValidateTypeDefinitionTable(IAssembly hostAssembly, ICliMetadataRoot metadataRoot, CompilerErrorCollection resultErrorCollection, _ICliManager identityManager)
        {
            var typeDefTable = metadataRoot.TableStream.TypeDefinitionTable;

            if (typeDefTable == null)
            {
                return;
            }
            int maxTypeDef  = typeDefTable.Count;
            int maxTypeRef  = metadataRoot.TableStream.TypeRefTable == null ? 0 : metadataRoot.TableStream.TypeRefTable.Count;
            int maxTypeSpec = metadataRoot.TableStream.TypeSpecificationTable == null ? 0 : metadataRoot.TableStream.TypeSpecificationTable.Count;

            Parallel.ForEach(typeDefTable.ToArray(), typeDefinition =>
            {
                var typeAttributes = typeDefinition.TypeAttributes;
                if (((int)(typeAttributes ^ (typeAttributes & (TypeAttributes)0xD77DBF))) != 0)
                {
                    /* *
                     * Flags must contain only those values specified by System.Reflection.TypeAttributes
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0202a, hostAssembly, typeDefinition);
                }
                if (((typeAttributes & TypeAttributes.SequentialLayout) == TypeAttributes.SequentialLayout) &&
                    ((typeAttributes & TypeAttributes.ExplicitLayout) == TypeAttributes.SequentialLayout))
                {
                    /* *
                     * Sequential Layout and Explicit Layout cannot be set together.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0202b, hostAssembly, typeDefinition);
                }
                if (((typeAttributes & TypeAttributes.AutoClass) == TypeAttributes.AutoClass) &&
                    ((typeAttributes & TypeAttributes.UnicodeClass) == TypeAttributes.UnicodeClass))
                {
                    /* *
                     * UnicodeClass and AutoClass flags cannot be set together.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0202c, hostAssembly, typeDefinition);
                }
                if ((typeAttributes & TypeAttributes.HasSecurity) == TypeAttributes.HasSecurity)
                {
                    if (!(CheckForDeclSecurityRow(metadataRoot, typeDefinition) || CheckForSecuritySuppressionAttribute(metadataRoot, typeDefTable, typeDefinition)))
                    {
                        /* *
                         * If HasSecurity is set, then the type must contain at least one
                         * DeclSecurity row, or a custom attribute called
                         * SuppressUnmanagedCodeSecurityAttribute.
                         * */
                        resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0202d, hostAssembly, typeDefinition);
                    }
                    if ((typeAttributes & TypeAttributes.Interface) == TypeAttributes.Interface)
                    {
                        /* *
                         * Interfaces are allowed to have the HasSecurity flag set; however,
                         * the security system ignores any permission requests attached to
                         * that interface.
                         * */
                        resultErrorCollection.ModelWarning(CliWarningsAndErrors.CliMetadata0202g, hostAssembly, typeDefinition);
                    }
                }
                else if (CheckForDeclSecurityRow(metadataRoot, typeDefinition))
                {
                    /* *
                     * If this type owns one (or more) DeclSecurity rows, then the HasSecurity
                     * flag must be set.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0202e, hostAssembly, typeDefinition);
                }
                else if (CheckForSecuritySuppressionAttribute(metadataRoot, typeDefTable, typeDefinition))
                {
                    /* *
                     * If this type has a custom attribute called SuppressUnmanagedCodeSecurityAttribute,
                     * then the HasSecurity flag must be set.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0202f, hostAssembly, typeDefinition);
                }
                if (string.IsNullOrEmpty(typeDefinition.Name))
                {
                    /* *
                     * Name shall index a non-empty string in the String Heap.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0203, hostAssembly, typeDefinition);
                }
                string name  = typeDefinition.Name,
                @namespace   = typeDefinition.Namespace;
                int maxIndex = 0;
                switch (typeDefinition.ExtendsSource)
                {
                case CliMetadataTypeDefOrRefTag.TypeDefinition:
                    maxIndex = maxTypeDef;
                    break;

                case CliMetadataTypeDefOrRefTag.TypeReference:
                    maxIndex = maxTypeRef;
                    break;

                case CliMetadataTypeDefOrRefTag.TypeSpecification:
                    maxIndex = maxTypeSpec;
                    break;
                }

                /* *
                 * If the index is beyond the allowed ranges, don't even check the
                 * 'Extends' part as it'll yield an exception.
                 * *
                 * The exception being if there's no actual reference in the first place,
                 * when the source is a type def and the index is zero.
                 * */
                if (!(typeDefinition.ExtendsSource == CliMetadataTypeDefOrRefTag.TypeDefinition && typeDefinition.ExtendsIndex == 0) &&
                    (1 > typeDefinition.ExtendsIndex || typeDefinition.ExtendsIndex > maxIndex))
                {
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0211a, hostAssembly, typeDefinition);
                }
                else if (typeDefinition.Extends == null && (typeAttributes & TypeAttributes.Interface) != TypeAttributes.Interface)
                {
                    if (!(CliCommon.IsSpecialModule(typeDefinition) ||
                          CliCommon.IsBaseObject(identityManager, typeDefinition)))
                    {
                        /* *
                         * Every class (with exception to System.Object and the special class
                         * <Module>) shall extend one, and only one, other Class - so Extends
                         * is for a Class shall be non-null.
                         * */
                        resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0208, hostAssembly, typeDefinition);
                    }
                }
                else if (typeDefinition.Extends != null &&
                         name == "Object" &&
                         @namespace == "System" &&
                         typeDefinition.DeclaringType == null)
                {
                    /* *
                     * System.Object must have an extends value of null.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0209, hostAssembly, typeDefinition);
                }
                else if (name == "ValueType" &&
                         @namespace == "System" &&
                         typeDefinition.DeclaringType == null)
                {
                    if (!CliCommon.IsBaseObject(identityManager, typeDefinition.Extends))
                    {
                        /* *
                         * System.ValueType must have an extends value of System.Object
                         * */
                        resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0210, hostAssembly, typeDefinition);
                    }
                }
                else if (typeDefinition.Extends != null)
                {
                    var extendsDef = identityManager.ResolveScope(typeDefinition.Extends);
                    if (extendsDef != null)
                    {
                        var events = extendsDef.Events;
                        if (CliCommon.IsValueType(identityManager, extendsDef) || ((extendsDef.TypeAttributes & TypeAttributes.Interface) == TypeAttributes.Interface))
                        {
                            resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0211b, hostAssembly, typeDefinition, extendsDef);
                        }
                        if ((extendsDef.TypeAttributes & TypeAttributes.Sealed) == TypeAttributes.Sealed)
                        {
                            resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0211c, hostAssembly, typeDefinition, extendsDef);
                        }
                        List <ICliMetadataTypeDefinitionTableRow> extendsTable = new List <ICliMetadataTypeDefinitionTableRow>();
                        ICliMetadataTypeDefinitionTableRow current             = typeDefinition;
                        while (current != null)
                        {
                            if (extendsTable.Contains(current))
                            {
                                /* *
                                 * A class shall not extend itself, or any of its children (i.e.,
                                 * its derived classes), because this will introduce loops in the
                                 * hierarchy tree.
                                 * */
                                resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0212, hostAssembly, typeDefinition);
                                break;
                            }
                            extendsTable.Add(current);
                            current = identityManager.ResolveScope(current.Extends);
                        }
                    }
                }

                /* *
                 * ToDo: Add code here to check the name identifier against CLS rules.
                 * Warning CliMetadata0204
                 * */
                if (typeDefinition.NamespaceIndex != 0 && typeDefinition.Namespace == string.Empty)
                {
                    /* *
                     * If non-null, Namespace shall index a non-empty string in the
                     * String Heap.
                     * */
                    resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0206, hostAssembly, typeDefinition);
                }

                /* *
                 * ToDo: Add code here to check the namespace identifier against CLS rules.
                 * Warning CliMetadata0207
                 * */
            });
        }
Exemple #19
0
 internal ParameterDictionary(_ICliManager manager, uint methodIndex, ICliMetadataRoot metadataRoot, TIndexer parent, bool fromSetter)
     : base(manager, methodIndex, metadataRoot, parent, fromSetter ? 1 : 0)
 {
 }
Exemple #20
0
 public ParameterDictionary(_ICliManager manager, uint methodIndex, ICliMetadataRoot metadataRoot, TCtor parent)
     : base(manager, methodIndex, metadataRoot, parent)
 {
 }
Exemple #21
0
 public CliParameterMemberDictionary(_ICliManager manager, uint methodIndex, ICliMetadataRoot metadataRoot, TParent parent, IMethodSignatureMember activeMethod)
     : this(manager, methodIndex, metadataRoot, parent)
 {
     this.activeMethod = activeMethod;
 }
Exemple #22
0
 protected ParameterDictionary(_ICliManager manager, ICliMetadataEventTableRow metadataEntry, CliEventSignatureMember <TEvent, TEventParameter, TEventParent> parent)
     : base(manager, CliMemberExtensions.GetEventDelegateMethod(metadataEntry, manager), CliMemberExtensions.GetEventDelegateMetadataRoot(metadataEntry, manager), (TEvent)(object)parent)
 {
 }
Exemple #23
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();
            }
        }
Exemple #24
0
 internal CtorMember(IStructType parent, ICliMetadataMethodDefinitionTableRow metadataEntry, _ICliManager identityManager, IGeneralSignatureMemberUniqueIdentifier uniqueIdentifier)
     : base(parent, metadataEntry, identityManager, uniqueIdentifier)
 {
 }
Exemple #25
0
 protected CliConstructorMember(TCtorParent parent, ICliMetadataMethodDefinitionTableRow metadataEntry, _ICliManager identityManager, IGeneralSignatureMemberUniqueIdentifier uniqueIdentifier)
     : base(parent, metadataEntry)
 {
     this.identityManager  = identityManager;
     this.uniqueIdentifier = uniqueIdentifier;
 }