示例#1
0
        /// <summary>
        /// Imports a type into the debugger's type system, and into the current generic context.
        /// </summary>
        IType Import(IType type)
        {
            IType importedType = debuggerTypeSystem.Import(type);

            if (importedType != null)
            {
                return(importedType.AcceptVisitor(context.MethodInfo.Substitution));
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Imports a type from another compilation.
        /// </summary>
        public static IType Import(this ICompilation compilation, IType type)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException("compilation");
            }
            if (type == null)
            {
                return(null);
            }
            var compilationProvider = type as ICompilationProvider;

            if (compilationProvider != null && compilationProvider.Compilation == compilation)
            {
                return(type);
            }
            IEntity typeParameterOwner         = GetTypeParameterOwner(type);
            IEntity importedTypeParameterOwner = compilation.Import(typeParameterOwner);

            if (importedTypeParameterOwner != null)
            {
                return(type.ToTypeReference().Resolve(new SimpleTypeResolveContext(importedTypeParameterOwner)));
            }
            else
            {
                return(type.ToTypeReference().Resolve(compilation.TypeResolveContext));
            }
        }
        public static IMethod Import(this ICompilation compilation, ICorDebugFunction corFunction, List <ICorDebugType> typeArgs)
        {
            IMethod definition = Import(compilation, corFunction);

            if (typeArgs == null || typeArgs.Count == 0)
            {
                return(definition);
            }
            int classTPC = definition.DeclaringTypeDefinition.TypeParameterCount;

            IType[] classTPs  = typeArgs.Take(classTPC).Select(t => compilation.Import(t)).ToArray();
            IType[] methodTPs = null;
            if (definition.TypeParameters.Count > 0)
            {
                methodTPs = typeArgs.Skip(classTPC).Select(t => compilation.Import(t)).ToArray();
            }
            return(new SpecializedMethod(definition, new TypeParameterSubstitution(classTPs, methodTPs)));
        }
示例#4
0
        static void SearchCompilation(ISearchProgressMonitor monitor, ICompilation comp, ITypeDefinition cls, IMember member)
        {
            var importedType = comp.Import(cls);

            if (importedType == null)
            {
                return;
            }

            IMember impMember = null;

            if (member != null)
            {
                impMember = comp.Import(member);
                if (impMember == null)
                {
                    return;
                }
            }

            foreach (var derivedType in comp.MainAssembly.GetAllTypeDefinitions())
            {
                if (!derivedType.IsDerivedFrom(importedType))
                {
                    continue;
                }
                IEntity result;
                if (member != null)
                {
                    result = FindDerivedMember(impMember, derivedType);
                    if (result == null)
                    {
                        continue;
                    }
                }
                else
                {
                    result = derivedType;
                }
                ReportResult(monitor, result);
            }
        }
		CSharpTypeResolveContext MapToNestedCompilation(CSharpTypeResolveContext context, ICompilation nestedCompilation)
		{
			var nestedContext = new CSharpTypeResolveContext(nestedCompilation.MainAssembly);
			if (context.CurrentUsingScope != null) {
				nestedContext = nestedContext.WithUsingScope(context.CurrentUsingScope.UnresolvedUsingScope.Resolve(nestedCompilation));
			}
			if (context.CurrentTypeDefinition != null) {
				nestedContext = nestedContext.WithCurrentTypeDefinition(nestedCompilation.Import(context.CurrentTypeDefinition));
			}
			return nestedContext;
		}
示例#6
0
 VSharpTypeResolveContext MapToNestedCompilation(VSharpTypeResolveContext context, ICompilation nestedCompilation)
 {
     var nestedContext = new VSharpTypeResolveContext(nestedCompilation.MainAssembly);
     if (context.CurrentUsingScope != null)
     {
         nestedContext = nestedContext.WithUsingScope(context.CurrentUsingScope.UnresolvedUsingScope.ResolveScope(nestedCompilation));
     }
     if (context.CurrentTypeDefinition != null)
     {
         nestedContext = nestedContext.WithCurrentTypeDefinition(nestedCompilation.Import(context.CurrentTypeDefinition));
     }
     return nestedContext;
 }
示例#7
0
		public XamlSymbolSearch(IProject project, ISymbol entity)
		{
			compilation = SD.ParserService.GetCompilation(project);
			if (entity is IEntity)
				this.entity = compilation.Import((IEntity)entity);
			interestingFileNames = new List<FileName>();
			if (this.entity == null)
				return;
			foreach (var item in project.Items.OfType<FileProjectItem>().Where(i => i.FileName.HasExtension(".xaml")))
				interestingFileNames.Add(item.FileName);
			workAmount = interestingFileNames.Count;
			workAmountInverse = 1.0 / workAmount;
		}
示例#8
0
        Value Visit(MemberResolveResult result)
        {
            var importedMember = debuggerTypeSystem.Import(result.Member);

            if (importedMember == null)
            {
                throw new GetValueException("Member not found!");
            }
            Value target = null;

            if (!importedMember.IsStatic)
            {
                if (importedMember.DeclaringType.Equals(context.MethodInfo.DeclaringType) && result.TargetResult == null)
                {
                    target = context.GetThisValue(true);
                }
                else if (result.TargetResult == null)
                {
                    throw new GetValueException("An object reference is required for the non-static field, method, or property '" + importedMember.FullName + "'");
                }
                else
                {
                    target = Convert(result.TargetResult);
                }
            }
            if (!allowMethodInvoke && (importedMember is IMethod))
            {
                throw new InvalidOperationException("Method invocation not allowed in the current context!");
            }
            Value val = Value.GetMemberValue(evalThread, target, importedMember.Specialize(context.MethodInfo.Substitution));

            if (val == null)
            {
                throw new GetValueException("Member not found!");
            }
            return(val);
        }
 public XamlSymbolSearch(IProject project, ISymbol entity)
 {
     compilation = SD.ParserService.GetCompilation(project);
     if (entity is IEntity)
     {
         this.entity = compilation.Import((IEntity)entity);
     }
     interestingFileNames = new List <FileName>();
     if (this.entity == null)
     {
         return;
     }
     foreach (var item in project.Items.OfType <FileProjectItem>().Where(i => i.FileName.HasExtension(".xaml")))
     {
         interestingFileNames.Add(item.FileName);
     }
     workAmount        = interestingFileNames.Count;
     workAmountInverse = 1.0 / workAmount;
 }
示例#10
0
        public static bool Equals(ICompilation comp, IList <IParameter> x, IList <IParameter> y)
        {
            if (x == y)
            {
                return(true);
            }
            if (x == null || y == null || x.Count != y.Count)
            {
                return(false);
            }
            for (int i = 0; i < x.Count; i++)
            {
                var a = x[i];
                var b = y[i];
                if (a == null && b == null)
                {
                    continue;
                }
                if (a == null || b == null)
                {
                    return(false);
                }

                // We want to consider the parameter lists "Method<T>(T a)" and "Method<S>(S b)" as equal.
                // However, the parameter types are not considered equal, as T is a different type parameter than S.
                // In order to compare the method signatures, we will normalize all method type parameters.
                IType aType = a.Type.AcceptVisitor(normalizationVisitor);
                IType bType = b.Type.AcceptVisitor(normalizationVisitor);
                bType = comp.Import(bType);
                if (!aType.Equals(bType))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#11
0
 /// <summary>
 /// Imports a member from another compilation.
 /// </summary>
 public static IField Import(this ICompilation compilation, IField field)
 {
     return((IField)compilation.Import((IMember)field));
 }
示例#12
0
 /// <summary>
 /// Imports a member from another compilation.
 /// </summary>
 public static IMethod Import(this ICompilation compilation, IMethod method)
 {
     return((IMethod)compilation.Import((IMember)method));
 }
示例#13
0
 /// <summary>
 /// Gets the file names that possibly contain references to the element being searched for.
 /// </summary>
 public IEnumerable<CSharpUnresolvedFile> GetInterestingFiles(IFindReferenceSearchScope searchScope, ICompilation compilation)
 {
     if (searchScope == null)
         throw new ArgumentNullException("searchScope");
     if (compilation == null)
         throw new ArgumentNullException("compilation");
     var pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
     if (pc == null)
         throw new ArgumentException("Main assembly is not a project content");
     if (searchScope.TopLevelTypeDefinition != null) {
         ITypeDefinition topLevelTypeDef = compilation.Import(searchScope.TopLevelTypeDefinition);
         if (topLevelTypeDef == null) {
             // This compilation cannot have references to the target entity.
             return EmptyList<CSharpUnresolvedFile>.Instance;
         }
         switch (searchScope.Accessibility) {
             case Accessibility.None:
             case Accessibility.Private:
                 if (topLevelTypeDef.ParentAssembly == compilation.MainAssembly)
                     return topLevelTypeDef.Parts.Select(p => p.UnresolvedFile).OfType<CSharpUnresolvedFile>().Distinct();
                 else
                     return EmptyList<CSharpUnresolvedFile>.Instance;
             case Accessibility.Protected:
                 return GetInterestingFilesProtected(topLevelTypeDef);
             case Accessibility.Internal:
                 if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                     return pc.Files.OfType<CSharpUnresolvedFile>();
                 else
                     return EmptyList<CSharpUnresolvedFile>.Instance;
             case Accessibility.ProtectedAndInternal:
                 if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                     return GetInterestingFilesProtected(topLevelTypeDef);
                 else
                     return EmptyList<CSharpUnresolvedFile>.Instance;
             case Accessibility.ProtectedOrInternal:
                 if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                     return pc.Files.OfType<CSharpUnresolvedFile>();
                 else
                     return GetInterestingFilesProtected(topLevelTypeDef);
             default:
                 return pc.Files.OfType<CSharpUnresolvedFile>();
         }
     } else {
         return pc.Files.OfType<CSharpUnresolvedFile>();
     }
 }
示例#14
0
		static IEnumerable<ITypeDefinition> Import (ICompilation compilation, IEnumerable<ITypeDefinition> types)
		{
			return types.Select (t => compilation.Import (t));
		}
		static void SearchCompilation (ISearchProgressMonitor monitor, ICompilation comp, ITypeDefinition cls, IMember member)
		{
			var importedType = comp.Import (cls);
			if (importedType == null) {
				return;
			}

			IMember impMember = null;
			if (member != null) {
				impMember = comp.Import (member);
				if (impMember == null) {
					return;
				}
			}

			foreach (var derivedType in comp.MainAssembly.GetAllTypeDefinitions ()) {
				if (!derivedType.IsDerivedFrom (importedType))
					continue;
				IEntity result;
				if (member != null) {
					result = FindDerivedMember (impMember, derivedType);
					if (result == null)
						continue;
				}
				else {
					result = derivedType;
				}
				ReportResult (monitor, result);
			}
		}
示例#16
0
 /// <summary>
 /// Imports a member from another compilation.
 /// </summary>
 public static IEvent Import(this ICompilation compilation, IEvent ev)
 {
     return((IEvent)compilation.Import((IMember)ev));
 }
示例#17
0
 static IEnumerable <ITypeDefinition> Import(ICompilation compilation, IEnumerable <ITypeDefinition> types)
 {
     return(types.Select(t => compilation.Import(t)));
 }
示例#18
0
        /// <summary>
        /// Gets the file names that possibly contain references to the element being searched for.
        /// </summary>
        public IEnumerable <CppParsedFile> GetInterestingFiles(IFindReferenceSearchScope searchScope, ICompilation compilation)
        {
            if (searchScope == null)
            {
                throw new ArgumentNullException("searchScope");
            }
            if (compilation == null)
            {
                throw new ArgumentNullException("compilation");
            }
            var pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (pc == null)
            {
                throw new ArgumentException("Main assembly is not a project content");
            }
            if (searchScope.TopLevelTypeDefinition != null)
            {
                ITypeDefinition topLevelTypeDef = compilation.Import(searchScope.TopLevelTypeDefinition);
                if (topLevelTypeDef == null)
                {
                    // This compilation cannot have references to the target entity.
                    return(EmptyList <CppParsedFile> .Instance);
                }
                switch (searchScope.Accessibility)
                {
                case Accessibility.None:
                case Accessibility.Private:
                    if (topLevelTypeDef.ParentAssembly == compilation.MainAssembly)
                    {
                        return(topLevelTypeDef.Parts.Select(p => p.ParsedFile).OfType <CppParsedFile>().Distinct());
                    }
                    else
                    {
                        return(EmptyList <CppParsedFile> .Instance);
                    }

                case Accessibility.Protected:
                    return(GetInterestingFilesProtected(topLevelTypeDef));

                case Accessibility.Internal:
                    if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                    {
                        return(pc.Files.OfType <CppParsedFile>());
                    }
                    else
                    {
                        return(EmptyList <CppParsedFile> .Instance);
                    }

                case Accessibility.ProtectedAndInternal:
                    if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                    {
                        return(GetInterestingFilesProtected(topLevelTypeDef));
                    }
                    else
                    {
                        return(EmptyList <CppParsedFile> .Instance);
                    }

                case Accessibility.ProtectedOrInternal:
                    if (topLevelTypeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))
                    {
                        return(pc.Files.OfType <CppParsedFile>());
                    }
                    else
                    {
                        return(GetInterestingFilesProtected(topLevelTypeDef));
                    }

                default:
                    return(pc.Files.OfType <CppParsedFile>());
                }
            }
            else
            {
                return(pc.Files.OfType <CppParsedFile>());
            }
        }
示例#19
0
 /// <summary>
 /// Imports a member from another compilation.
 /// </summary>
 public static IProperty Import(this ICompilation compilation, IProperty property)
 {
     return((IProperty)compilation.Import((IMember)property));
 }
示例#20
0
        public static bool Equals(ICompilation comp, IList<IParameter> x, IList<IParameter> y)
        {
            if (x == y)
                return true;
            if (x == null || y == null || x.Count != y.Count)
                return false;
            for (int i = 0; i < x.Count; i++) {
                var a = x[i];
                var b = y[i];
                if (a == null && b == null)
                    continue;
                if (a == null || b == null)
                    return false;

                // We want to consider the parameter lists "Method<T>(T a)" and "Method<S>(S b)" as equal.
                // However, the parameter types are not considered equal, as T is a different type parameter than S.
                // In order to compare the method signatures, we will normalize all method type parameters.
                IType aType = a.Type.AcceptVisitor(normalizationVisitor);
                IType bType = b.Type.AcceptVisitor(normalizationVisitor);
                bType = comp.Import (bType);
                if (!aType.Equals(bType))
                    return false;
            }
            return true;
        }