Example #1
0
        /// <summary>
        /// Returns a unit, loaded into the given host, that matches unitReference. The host will load the unit, if necessary and possible.
        /// If the reference cannot be resolved a dummy unit is returned.
        /// </summary>
        public static IUnit Resolve(IUnitReference unitReference, IMetadataHost host)
        {
            Contract.Requires(unitReference != null);
            Contract.Requires(host != null);
            Contract.Ensures(Contract.Result <IUnit>() != null);

            return(host.LoadUnit(unitReference.UnitIdentity));
        }
 public override void Visit(IUnitReference unitReference)
 {
     if (Process(unitReference))
     {
         visitor.Visit(unitReference);
     }
     base.Visit(unitReference);
 }
Example #3
0
        public override void Visit(IMethodReference methodReference)
        {
            IGenericMethodInstanceReference /*?*/ genericMethodInstanceReference = methodReference.AsGenericMethodInstanceReference;

            if (genericMethodInstanceReference != null)
            {
                this.Visit(genericMethodInstanceReference);
                return;
            }

            if (!alreadySeen.Add(methodReference))
            {
                return;
            }

            // If we have a ref to a varargs method then we always generate an entry in the MethodRef table,
            // even if it is a method in the current module. (Note that we are not *required* to do so if
            // in fact the number of extra arguments passed is zero; in that case we are permitted to use
            // an ordinary method def token. We consistently choose to emit a method ref regardless.)

            IUnitReference /*?*/ definingUnit = TypeHelper.GetDefiningUnitReference(methodReference.GetContainingType(Context), Context);

            if (definingUnit != null && ReferenceEquals(definingUnit, this.module) && !methodReference.AcceptsExtraArguments)
            {
                return;
            }

            this.Visit((ITypeMemberReference)methodReference);
            ISpecializedMethodReference /*?*/ specializedMethodReference = methodReference.AsSpecializedMethodReference;

            if (specializedMethodReference != null)
            {
                IMethodReference unspecializedMethodReference = specializedMethodReference.UnspecializedVersion;
                this.Visit(unspecializedMethodReference.GetType(Context));
                this.Visit(unspecializedMethodReference.GetParameters(Context));
                if (unspecializedMethodReference.ReturnValueIsModified)
                {
                    this.Visit(unspecializedMethodReference.ReturnValueCustomModifiers);
                }
            }
            else
            {
                this.Visit(methodReference.GetType(Context));
                this.Visit(methodReference.GetParameters(Context));
                if (methodReference.ReturnValueIsModified)
                {
                    this.Visit(methodReference.ReturnValueCustomModifiers);
                }
            }

            if (methodReference.AcceptsExtraArguments)
            {
                this.Visit(methodReference.ExtraParameters);
            }

            ReserveMethodToken(methodReference);
        }
        private string GetAssemblyName(ITypeReference typeDef)
        {
            while (typeDef is INestedTypeDefinition)
            {
                typeDef = ((INestedTypeReference)typeDef).ContainingType;
            }
            IUnitReference unit = ((INamespaceTypeReference)typeDef).ContainingUnitNamespace.Unit;

            return(unit.Name.Value);
        }
Example #5
0
        public bool CanIncludeUnit(IUnitReference unit)
        {
            IAssemblyReference assembly = unit as IAssemblyReference;

            if (assembly == null)
            {
                assembly = (unit as IModuleReference).ContainingAssembly;
            }

            return(CanIncludeAssembly(assembly.AssemblyIdentity));
        }
Example #6
0
        public static IAssemblyReference GetAssemblyReference(this ITypeReference type)
        {
            IUnitReference unit = TypeHelper.GetDefiningUnitReference(type);

            if (unit is IAssemblyReference assembly)
            {
                return(assembly);
            }

            if (unit is IModuleReference module)
            {
                return(module.ContainingAssembly);
            }

            return(null);
        }
Example #7
0
        public override void Visit(IFieldReference fieldReference)
        {
            if (!alreadySeen.Add(fieldReference))
            {
                return;
            }

            IUnitReference definingUnit = MetadataWriter.GetDefiningUnitReference(fieldReference.GetContainingType(Context), Context);

            if (definingUnit != null && ReferenceEquals(definingUnit, this.module))
            {
                return;
            }

            this.Visit((ITypeMemberReference)fieldReference);
            this.Visit(fieldReference.GetType(Context));
            ReserveFieldToken(fieldReference);
        }
Example #8
0
        /// <summary>
        /// Use this routine, rather than IUnitReference.Dispatch, to call the appropriate derived overload of an IUnitReference.
        /// The former routine will call Visit(IAssembly) rather than Visit(IAssemblyReference), etc.
        /// in the case where a definition is used as the reference to itself.
        /// </summary>
        /// <param name="unitReference">A reference to a unit. Note that a unit can serve as a reference to itself.</param>
        private void DispatchAsReference(IUnitReference unitReference)
        {
            IAssemblyReference assemblyReference = unitReference as IAssemblyReference;

            if (assemblyReference != null)
            {
                this.Visit(assemblyReference);
                return;
            }

            IModuleReference moduleReference = unitReference as IModuleReference;

            if (moduleReference != null)
            {
                this.Visit(moduleReference);
                return;
            }
        }
Example #9
0
        private void VisitExportedType(ITypeReference exportedType)
        {
            // Do not visit the reference to aliased type, it does not get into the type ref table based only on its membership of the exported types collection.
            // but DO visit the reference to assembly (if any) that defines the aliased type. That assembly might not already be in the assembly reference list.
            IUnitReference     definingUnit     = MetadataWriter.GetDefiningUnitReference(exportedType, Context);
            IAssemblyReference definingAssembly = definingUnit as IAssemblyReference;

            if (definingAssembly != null)
            {
                Visit(definingAssembly);
            }
            else
            {
                definingAssembly = ((IModuleReference)definingUnit).GetContainingAssembly(Context);
                if (definingAssembly != null && !ReferenceEquals(definingAssembly, Context.Module.GetContainingAssembly(Context)))
                {
                    Visit(definingAssembly);
                }
            }
        }
Example #10
0
 /// <summary>
 /// Returns true if the given two unit references are to be considered equivalent.
 /// </summary>
 public static bool UnitsAreEquivalent(IUnitReference unit1, IUnitReference unit2)
 {
     if (unit1 == null || unit2 == null)
     {
         return(false);
     }
     if (unit1 == unit2)
     {
         return(true);
     }
     if (UnitHelper.AssembliesAreEquivalent(unit1 as IAssemblyReference, unit2 as IAssemblyReference))
     {
         return(true);
     }
     if (UnitHelper.ModulesAreEquivalent(unit1 as IModuleReference, unit2 as IModuleReference))
     {
         return(true);
     }
     return(false);
 }
Example #11
0
        /// <summary>
        /// Returns true if the given two unit references are to be considered equivalent as containers.
        /// </summary>
        public static bool UnitsAreContainmentEquivalent(IUnitReference unit1, IUnitReference unit2)
        {
            if (unit1 == null || unit2 == null)
            {
                return(false);
            }
            if (unit1 == unit2)
            {
                return(true);
            }
            IModuleReference /*?*/ moduleRef1 = unit1 as IModuleReference;
            IModuleReference /*?*/ moduleRef2 = unit2 as IModuleReference;

            if (moduleRef1 != null && moduleRef2 != null)
            {
                if (UnitHelper.AssembliesAreEquivalent(moduleRef1.ContainingAssembly, moduleRef2.ContainingAssembly))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #12
0
        public override void Visit(INamespaceTypeReference namespaceTypeReference)
        {
            if (!this.typeReferenceNeedsToken && namespaceTypeReference.TypeCode != PrimitiveTypeCode.NotPrimitive)
            {
                return;
            }

            RecordTypeReference(namespaceTypeReference);

            IUnitReference unit = namespaceTypeReference.GetUnit(Context);

            IAssemblyReference assemblyReference = unit as IAssemblyReference;

            if (assemblyReference != null)
            {
                this.Visit(assemblyReference);
            }
            else
            {
                IModuleReference moduleReference = unit as IModuleReference;
                if (moduleReference != null)
                {
                    // If this is a module from a referenced multi-module assembly,
                    // the assembly should be used as the resolution scope.
                    assemblyReference = moduleReference.GetContainingAssembly(Context);
                    if (assemblyReference != null && assemblyReference != Context.Module.GetContainingAssembly(Context))
                    {
                        this.Visit(assemblyReference);
                    }
                    else
                    {
                        this.Visit(moduleReference);
                    }
                }
            }
        }
Example #13
0
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 public virtual void Visit(IUnitReference unitReference)
 {
     //IUnitReference is a base interface that should never be implemented directly.
       //Get unitReference to call the most type specific visitor.
       unitReference.Dispatch(this);
 }
Example #14
0
 /// <summary>
 /// Use this routine, rather than IUnitReference.Dispatch, to call the appropriate derived overload of an IUnitReference.
 /// The former routine will call Visit(IAssembly) rather than Visit(IAssemblyReference), etc.
 /// in the case where a definition is used as the reference to itself.
 /// </summary>
 /// <param name="unitReference">A reference to a unit. Note that a unit can serve as a reference to itself.</param>
 private void DispatchAsReference(IUnitReference unitReference)
 {
     IAssemblyReference/*?*/ assemblyReference = unitReference as IAssemblyReference;
       if (assemblyReference != null) {
     this.Visit(assemblyReference);
     return;
       }
       IModuleReference/*?*/ moduleReference = unitReference as IModuleReference;
       if (moduleReference != null) {
     this.Visit(moduleReference);
     return;
       }
 }
Example #15
0
 public override void Visit(IUnitReference unitReference)
 {
     allElements.Add(new InvokInfo(Traverser, "IUnitReference", unitReference));
 }
Example #16
0
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 /// <param name="unitReference">The unit reference.</param>
 public virtual void Visit(IUnitReference unitReference)
 {
     // IUnitReference is a base interface that should never be implemented directly.
     // Get unitReference to call the most type specific visitor.
     unitReference.Dispatch(this);
 }
Example #17
0
    private static bool IsWinMD(IUnitReference unitRef) {
      IAssembly assembly = unitRef.ResolvedUnit as IAssembly;
      if (assembly == null || assembly is Dummy || !assembly.ContainsForeignTypes)
        return false;

      foreach (string version in assembly.TargetRuntimeVersion.Split(';')) {
        if (version.StartsWith(VERSION_PREFIX_WINRT, StringComparison.OrdinalIgnoreCase)) {
          return true;
        }
      }

      return false;
    }
Example #18
0
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 public void Visit(IUnitReference unitReference)
 {
     if (unitReference.Name.Value == string.Empty) {
       this.ReportError(MetadataError.EmptyName, unitReference);
     }
 }
Example #19
0
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 public virtual void Visit(IUnitReference unitReference)
 {
 }
Example #20
0
 /// <summary>
 /// Traverses the children of the unit reference.
 /// </summary>
 public virtual void TraverseChildren(IUnitReference unitReference)
 {
     //no children to traverse
 }
Example #21
0
    uint GetUnitRootNamespaceInternId(IUnitReference unitReference) {
      Contract.Requires(unitReference != null);

      IAssemblyReference/*?*/ assemblyReference = unitReference as IAssemblyReference;
      if (assemblyReference != null) {
        AssemblyStore assemblyStore = this.GetAssemblyStore(assemblyReference.UnifiedAssemblyIdentity);
        return assemblyStore.RootNamespaceInternedId;
      }
      IModuleReference/*?*/ moduleReference = unitReference as IModuleReference;
      if (moduleReference != null) {
        ModuleStore moduleStore = this.GetModuleStore(moduleReference.ModuleIdentity);
        return moduleStore.RootNamespaceInternedId;
      }
      return 0;
    }
Example #22
0
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 /// <param name="unitReference">The unit reference.</param>
 public virtual void Visit(IUnitReference unitReference)
   //^ ensures this.path.Count == old(this.path.Count);
 {
   if (this.stopTraversal) return;
   this.DispatchAsReference(unitReference);
 }
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 public virtual void Visit(IUnitReference unitReference)
 {
     Contract.Requires(unitReference != null);
 }
Example #24
0
 public Unit(IUnitReference reference)
 {
     Reference = reference;
     Health    = MaxHealth;
     Energy    = MaxEnergy;
 }
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 public virtual void Visit(IUnitReference unitReference)
 {
     Contract.Requires(unitReference != null);
 }
Example #26
0
 /// <summary>
 /// Traverses the specified unit reference.
 /// </summary>
 public void Traverse(IUnitReference unitReference)
 {
     Contract.Requires(unitReference != null);
       unitReference.DispatchAsReference(this.dispatchingVisitor);
 }
Example #27
0
 private IEnumerable <IPrimarySourceLocation> GetPrimarySourceLocationsForDelegate(IUnitReference unit, IEnumerable <Microsoft.Cci.ILocation> location, bool exact)
 {
     return(this.sourceLocationProvider.GetPrimarySourceLocationsFor(location));
 }
Example #28
0
 /// <summary>
 /// Traverses the children of the unit reference.
 /// </summary>
 public virtual void TraverseChildren(IUnitReference unitReference)
 {
     Contract.Requires(unitReference != null);
       //unit reference attributes are distinct from unit definition attributes. When a definition serves as a reference, the reference is assumed to be unattributed.
       if (!(unitReference is IUnit))
     this.Traverse(unitReference.Attributes);
 }
Example #29
0
 public override void Visit(IUnitReference unitReference) {
   unitReference.ResolvedUnit.Dispatch(this);
 }
Example #30
0
 /// <summary>
 /// Allocates a reference to a root unit namespace.
 /// </summary>
 /// <param name="unit">A reference to the unit that defines the referenced namespace.</param>
 public RootUnitNamespaceReference(IUnitReference unit)
 {
     this.unit = unit;
 }
Example #31
0
 public virtual void Visit(IUnitReference unitReference)
 {
     this.DispatchAsReference(unitReference);
 }
Example #32
0
 public virtual void Visit(IUnitReference unitReference)
 {
     this.DispatchAsReference(unitReference);
 }
 public override void Visit(IUnitReference unitReference)
 {
     if(Process(unitReference)){visitor.Visit(unitReference);}
     base.Visit(unitReference);
 }
Example #34
0
        public bool CanIncludeUnit(IUnitReference unit)
        {
            IAssemblyReference assembly = unit as IAssemblyReference;
            if (assembly == null)
            {
                assembly = (unit as IModuleReference).ContainingAssembly;
            }

            return CanIncludeAssembly(assembly.AssemblyIdentity);
        }
Example #35
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Visits the specified unit reference.
 /// </summary>
 /// <param name="unitReference">The unit reference.</param>
 public virtual void Visit(IUnitReference unitReference)
 {
     if (this.stopTraversal) return;
       this.DispatchAsReference(unitReference);
 }
        public override void TraverseChildren(IUnitReference unitReference)
{ MethodEnter(unitReference);
            base.TraverseChildren(unitReference);
     MethodExit();   }
 /// <summary>
 /// Rewrites the specified unit reference.
 /// </summary>
 public virtual IUnitReference Rewrite(IUnitReference unitReference)
 {
     return unitReference;
 }
Example #38
0
 public override void TraverseChildren(IUnitReference unitReference)
 {
     MethodEnter(unitReference);
     base.TraverseChildren(unitReference);
     MethodExit();
 }
Example #39
0
 /// <summary>
 /// Traverses the specified unit reference.
 /// </summary>
 public void Traverse(IUnitReference unitReference)
 {
     unitReference.DispatchAsReference(this.dispatchingVisitor);
 }