Exemplo n.º 1
0
        /// <summary>
        /// See if a type reference refers to a type definition that is compiler generated.
        /// </summary>
        /// <param name="typeReference"></param>
        /// <returns></returns>
        internal static bool IsCompilerGenerated(ITypeReference /*!*/ typeReference)
        {
            if (AttributeHelper.Contains(typeReference.ResolvedType.Attributes, typeReference.PlatformType.SystemRuntimeCompilerServicesCompilerGeneratedAttribute))
            {
                return(true);
            }
            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference as IGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null && IsCompilerGenerated(genericTypeInstanceReference.GenericType))
            {
                return(true);
            }
            ISpecializedNestedTypeReference specializedNestedType = typeReference as ISpecializedNestedTypeReference;

            if (specializedNestedType != null && IsCompilerGenerated(specializedNestedType.UnspecializedVersion))
            {
                return(true);
            }
            ISpecializedNestedTypeDefinition specializedNestedTypeDefinition = typeReference as ISpecializedNestedTypeDefinition;

            if (specializedNestedTypeDefinition != null && IsCompilerGenerated(specializedNestedTypeDefinition.UnspecializedVersion))
            {
                return(true);
            }
            INestedTypeReference nestedTypeReference = UnspecializedMethods.AsUnspecializedNestedTypeReference(typeReference);

            if (nestedTypeReference != null)
            {
                return(IsCompilerGenerated(nestedTypeReference.ContainingType));
            }
            return(false);
        }
Exemplo n.º 2
0
        // Returns true if we need to look at the children, false otherwise.
        private bool VisitTypeReference(ITypeReference typeReference)
        {
            if (!this.alreadySeen.Add(typeReference))
            {
                if (!this.typeReferenceNeedsToken)
                {
                    return(false);
                }

                this.typeReferenceNeedsToken = false;
                if (!this.alreadyHasToken.Add(typeReference))
                {
                    return(false);
                }

                RecordTypeReference(typeReference);

                return(false);
            }

            INestedTypeReference /*?*/ nestedTypeReference = typeReference.AsNestedTypeReference;

            if (this.typeReferenceNeedsToken || nestedTypeReference != null ||
                (typeReference.TypeCode(Context) == PrimitiveTypeCode.NotPrimitive && typeReference.AsNamespaceTypeReference != null))
            {
                ISpecializedNestedTypeReference /*?*/ specializedNestedTypeReference = (nestedTypeReference == null ? null :
                                                                                        nestedTypeReference.AsSpecializedNestedTypeReference);
                if (specializedNestedTypeReference != null)
                {
                    INestedTypeReference unspecializedNestedTypeReference = specializedNestedTypeReference.UnspecializedVersion;
                    if (this.alreadyHasToken.Add(unspecializedNestedTypeReference))
                    {
                        RecordTypeReference(unspecializedNestedTypeReference);
                    }
                }

                if (this.typeReferenceNeedsToken && this.alreadyHasToken.Add(typeReference))
                {
                    RecordTypeReference(typeReference);
                }

                if (nestedTypeReference != null)
                {
                    this.typeReferenceNeedsToken = (typeReference.AsSpecializedNestedTypeReference == null);
                    this.Visit(nestedTypeReference.GetContainingType(Context));
                }
            }

            //This code was in CCI, but appears wrong to me. There is no need to visit attributes of types that are
            //being referenced, only those being defined. This code causes additional spurious typerefs and memberrefs to be
            //emitted. If the attributes can't be resolved, it causes a NullReference.
            //
            //if ((typeReference.AsTypeDefinition(Context) == null))
            //{
            //    this.Visit(typeReference.GetAttributes(Context));
            //}

            this.typeReferenceNeedsToken = false;
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the reference of a method in the closure class as used by other methods in the same class.
        /// </summary>
        private IMethodReference GetReferenceOfMethodUsedByPeers(IMethodDefinition method)
        {
            IMethodReference methodReference = null;
            ITypeReference   typeReference   = this.ClosureDefinitionReference;
            ISpecializedNestedTypeReference specializedNestedTypeRef = typeReference as ISpecializedNestedTypeReference;
            IGenericTypeInstanceReference   genericInstanceRef       = typeReference as IGenericTypeInstanceReference;

            if (specializedNestedTypeRef != null || genericInstanceRef != null)
            {
                methodReference = new SpecializedMethodReference()
                {
                    ContainingType        = typeReference,
                    GenericParameterCount = method.GenericParameterCount,
                    InternFactory         = this.host.InternFactory,
                    UnspecializedVersion  = method,
                    Type = method.Type,
                    Name = method.Name,
                    CallingConvention     = method.CallingConvention,
                    Parameters            = method.ParameterCount == 0 ? null : new List <IParameterTypeInformation>(((IMethodReference)method).Parameters),
                    ExtraParameters       = null,
                    ReturnValueIsByRef    = method.ReturnValueIsByRef,
                    ReturnValueIsModified = method.ReturnValueIsModified,
                    Attributes            = null,
                };
            }
            else
            {
                methodReference = method;
            }
            return(methodReference);
        }
 public override void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     if (Process(specializedNestedTypeReference))
     {
         visitor.Visit(specializedNestedTypeReference);
     }
     base.Visit(specializedNestedTypeReference);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Copies specialized nested type references since their containing types may involve type parameters, but
        /// leaves other kinds of nested type references alone.
        /// </summary>
        /// <param name="nestedTypeReference">The nested type reference.</param>
        public override INestedTypeReference Visit(INestedTypeReference nestedTypeReference)
        {
            ISpecializedNestedTypeReference /*?*/ specializedNestedTypeReference = nestedTypeReference as ISpecializedNestedTypeReference;

            if (specializedNestedTypeReference != null)
            {
                return(this.Visit(specializedNestedTypeReference));
            }
            return(nestedTypeReference);
        }
Exemplo n.º 6
0
        public static INamedTypeReference CanonicalizeTypeReference(ITypeReference type)
        {
            while (type != null)
            {
                IModifiedTypeReference          modifiedType = type as IModifiedTypeReference;
                IPointerTypeReference           ptrType      = type as IPointerTypeReference;
                IManagedPointerType             refType      = type as IManagedPointerType;
                IArrayTypeReference             arrType      = type as IArrayTypeReference;
                IGenericTypeInstanceReference   genType      = type as IGenericTypeInstanceReference;
                ISpecializedNestedTypeReference nestedType   = type as ISpecializedNestedTypeReference;
                // TODO: Why doesn't ISpecializedNestedTypeDefinition derive from ISpecializedNestedTypeReference?
                ISpecializedNestedTypeDefinition nestedTypeDef = type as ISpecializedNestedTypeDefinition;

                if (modifiedType != null)
                {
                    type = modifiedType.UnmodifiedType;
                }
                else if (ptrType != null)
                {
                    type = ptrType.TargetType;
                }
                else if (refType != null)
                {
                    type = refType.TargetType;
                }
                else if (arrType != null)
                {
                    type = arrType.ElementType;
                }
                else if (genType != null)
                {
                    type = genType.GenericType;
                }
                else if (nestedType != null)
                {
                    type = nestedType.UnspecializedVersion;
                }
                else if (nestedTypeDef != null)
                {
                    type = nestedTypeDef.UnspecializedVersion;
                }
                else /* ITypeDefinition */
                {
                    break;
                }
            }

            return(type as INamedTypeReference);
        }
Exemplo n.º 7
0
        public static ITypeReference UnWrap(this ITypeReference reference)
        {
            IPointerTypeReference pointer = reference as IPointerTypeReference;

            if (pointer != null)
            {
                return(pointer.TargetType.UnWrap());
            }

            IArrayTypeReference array = reference as IArrayTypeReference;

            if (array != null)
            {
                return(array.ElementType.UnWrap());
            }

            IModifiedTypeReference modified = reference as IModifiedTypeReference;

            if (modified != null)
            {
                return(modified.UnmodifiedType.UnWrap());
            }

            ISpecializedNestedTypeReference specialized = reference as ISpecializedNestedTypeReference;

            if (specialized != null)
            {
                return(specialized.UnspecializedVersion.UnWrap());
            }

            IGenericTypeInstanceReference instantiation = reference as IGenericTypeInstanceReference;

            if (instantiation != null)
            {
                return(instantiation.GenericType.UnWrap());
            }

            Contract.Assert(reference is INamedTypeReference ||
                            reference is INestedTypeReference ||
                            reference is INamespaceTypeReference ||
                            reference is IGenericTypeParameterReference ||
                            reference is IGenericMethodParameterReference ||
                            reference is IFunctionPointerTypeReference ||
                            reference is IManagedPointerType,
                            string.Format("Unexpected type reference that we may need to unwrap {0}", (reference != null ? reference.GetType().FullName : "null")));

            return(reference);
        }
        public static ITypeReference UnWrap(this ITypeReference reference)
        {
            IPointerTypeReference pointer = reference as IPointerTypeReference;

            if (pointer != null)
            {
                return(pointer.TargetType.UnWrap());
            }

            IArrayTypeReference array = reference as IArrayTypeReference;

            if (array != null)
            {
                return(array.ElementType.UnWrap());
            }

            IModifiedTypeReference modified = reference as IModifiedTypeReference;

            if (modified != null)
            {
                return(modified.UnmodifiedType.UnWrap());
            }

            ISpecializedNestedTypeReference specialized = reference as ISpecializedNestedTypeReference;

            if (specialized != null)
            {
                return(specialized.UnspecializedVersion.UnWrap());
            }

            IGenericTypeInstanceReference instantiation = reference as IGenericTypeInstanceReference;

            if (instantiation != null)
            {
                return(instantiation.GenericType.UnWrap());
            }

            Contract.Assert(reference is INamedTypeReference ||
                            reference is INestedTypeReference ||
                            reference is INamespaceTypeReference ||
                            reference is IGenericTypeParameterReference ||
                            reference is IGenericMethodParameterReference ||
                            reference is IFunctionPointerTypeReference,
                            string.Format(CultureInfo.CurrentCulture, LocalizedStrings.UnexpectedTypeReference, (reference?.GetType()?.FullName ?? "null")));

            return(reference);
        }
Exemplo n.º 9
0
        public static T UnWrapMember <T>(this T member)
            where T : ITypeMemberReference
        {
            IGenericMethodInstanceReference genericMethod = member as IGenericMethodInstanceReference;

            if (genericMethod != null)
            {
                return((T)genericMethod.GenericMethod.UnWrapMember());
            }

            ISpecializedNestedTypeReference type = member as ISpecializedNestedTypeReference;

            if (type != null)
            {
                return((T)type.UnspecializedVersion.UnWrapMember());
            }

            ISpecializedMethodReference method = member as ISpecializedMethodReference;

            if (method != null)
            {
                return((T)method.UnspecializedVersion.UnWrapMember());
            }

            ISpecializedFieldReference field = member as ISpecializedFieldReference;

            if (field != null)
            {
                return((T)field.UnspecializedVersion.UnWrapMember());
            }

            ISpecializedPropertyDefinition property = member as ISpecializedPropertyDefinition;

            if (property != null)
            {
                return((T)property.UnspecializedVersion.UnWrapMember());
            }

            ISpecializedEventDefinition evnt = member as ISpecializedEventDefinition;

            if (evnt != null)
            {
                return((T)evnt.UnspecializedVersion.UnWrapMember());
            }

            return(member);
        }
        internal static ITypeReference GetUninstantiatedGenericType(this ITypeReference typeReference, EmitContext context)
        {
            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                return(genericTypeInstanceReference.GetGenericType(context));
            }

            ISpecializedNestedTypeReference specializedNestedType = typeReference.AsSpecializedNestedTypeReference;

            if (specializedNestedType != null)
            {
                return(specializedNestedType.GetUnspecializedVersion(context));
            }

            return(typeReference);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Given a field definition in the closure class, get its reference as will be used by the methods in the closure class.
        /// </summary>
        internal IFieldReference GetReferenceOfFieldUsedByPeers(IFieldDefinition fieldDef)
        {
            IFieldReference fieldReference = null;
            ITypeReference  typeReference  = this.ClosureDefinitionReference;
            ISpecializedNestedTypeReference nestedTypeRef          = typeReference as ISpecializedNestedTypeReference;
            IGenericTypeInstanceReference   genericTypeInstanceRef = typeReference as IGenericTypeInstanceReference;

            if (nestedTypeRef != null || genericTypeInstanceRef != null)
            {
                fieldReference = new SpecializedFieldReference()
                {
                    ContainingType       = typeReference,
                    InternFactory        = this.host.InternFactory,
                    Name                 = fieldDef.Name,
                    UnspecializedVersion = fieldDef,
                    Type                 = fieldDef.Type
                };
            }
            else
            {
                fieldReference = fieldDef;
            }
            return(fieldReference);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Performs some computation with the given specialized nested type reference.
 /// </summary>
 public virtual void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Traverses the specialized method reference.
 /// </summary>
 public void Traverse(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     Contract.Requires(specializedNestedTypeReference != null);
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(specializedNestedTypeReference)) return;
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(specializedNestedTypeReference);
       if (this.stopTraversal) return;
       this.TraverseChildren(specializedNestedTypeReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(specializedNestedTypeReference);
 }
Exemplo n.º 14
0
 public override void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     allElements.Add(new InvokInfo(Traverser, "ISpecializedNestedTypeReference", specializedNestedTypeReference));
 }
 public override void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     if(Process(specializedNestedTypeReference)){visitor.Visit(specializedNestedTypeReference);}
     base.Visit(specializedNestedTypeReference);
 }
 /// <summary>
 /// Rewrites the given specialized nested type reference.
 /// </summary>
 public virtual INestedTypeReference Rewrite(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     return specializedNestedTypeReference;
 }
Exemplo n.º 17
0
 public void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Performs some computation with the given specialized nested type reference.
 /// </summary>
 public virtual void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
 }
Exemplo n.º 19
0
 public virtual void onMetadataElement(ISpecializedNestedTypeReference specializedNestedTypeReference) { }
Exemplo n.º 20
0
 /// <summary>
 /// Traverses the children of the specialized nested type reference.
 /// </summary>
 public virtual void TraverseChildren(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     Contract.Requires(specializedNestedTypeReference != null);
       this.TraverseChildren((INestedTypeReference)specializedNestedTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(specializedNestedTypeReference.UnspecializedVersion);
 }
Exemplo n.º 21
0
 public void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     this.traverser.Traverse(specializedNestedTypeReference);
 }
Exemplo n.º 22
0
 public virtual void onMetadataElement(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
 }
Exemplo n.º 23
0
 /// <summary>
 /// Performs some computation with the given specialized nested type reference.
 /// </summary>
 public void Visit(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     this.Visit((INestedTypeReference)specializedNestedTypeReference);
 }
Exemplo n.º 24
0
        public override void TraverseChildren(ISpecializedNestedTypeReference specializedNestedTypeReference)
{ MethodEnter(specializedNestedTypeReference);
            base.TraverseChildren(specializedNestedTypeReference);
     MethodExit();   }
Exemplo n.º 25
0
 public override void TraverseChildren(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     MethodEnter(specializedNestedTypeReference);
     base.TraverseChildren(specializedNestedTypeReference);
     MethodExit();
 }
Exemplo n.º 26
0
 /// <summary>
 /// Traverses the children of the specialized nested type reference.
 /// </summary>
 public virtual void TraverseChildren(ISpecializedNestedTypeReference specializedNestedTypeReference)
 {
     this.TraverseChildren((INestedTypeReference)specializedNestedTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(specializedNestedTypeReference.UnspecializedVersion);
 }