Ejemplo n.º 1
0
		IType SearchType(KnownTypeCode typeCode)
		{
			KnownTypeReference typeRef = KnownTypeReference.Get(typeCode);
			if (typeRef == null)
				return SpecialType.UnknownType;
			var typeName = new TopLevelTypeName(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount);
			foreach (IAssembly asm in compilation.Assemblies) {
				var typeDef = asm.GetTypeDefinition(typeName);
				if (typeDef != null)
					return typeDef;
			}
			return new UnknownType(typeName);
		}
        IType SearchType(BVEPrimitiveTypeCode typeCode)
        {
            var type_ref = PrimitiveTypeReference.Get(typeCode);
            if(type_ref == null)
                return SpecialType.UnknownType;

            var type_name = new TopLevelTypeName(type_ref.Namespace, type_ref.Name, 0);
            foreach(var asm in compilation.Assemblies){
                var type_def = asm.GetTypeDefinition(type_name);
                if(type_def != null)
                    return type_def;
            }
            return new UnknownType(type_name);
        }
Ejemplo n.º 3
0
		static IEntity GetEntity(ICompilation compilation, string className, string memberName)
		{
			var typeName = new TopLevelTypeName(className);
			ITypeDefinition type = compilation.MainAssembly.GetTypeDefinition(typeName);
			if (type != null) {
				if (string.IsNullOrEmpty(memberName))
					return type;
				
				IMember m = GetMember(type, memberName);
				if (m != null)
					return m;
				
				return type;
			}
			return null;
		}
		public static void NavigateTo(FileName assemblyFile, string typeName, string entityIdString)
		{
			if (assemblyFile == null)
				throw new ArgumentNullException("assemblyFile");
			if (string.IsNullOrEmpty(typeName))
				throw new ArgumentException("typeName is null or empty");
			
			var type = new TopLevelTypeName(typeName);
			var target = new DecompiledTypeReference(assemblyFile, type);
			
			foreach (var viewContent in SD.Workbench.ViewContentCollection.OfType<DecompiledViewContent>()) {
				var viewContentName = viewContent.DecompiledTypeName;
				if (viewContentName.AssemblyFile == assemblyFile && type == viewContentName.Type) {
					viewContent.WorkbenchWindow.SelectWindow();
					viewContent.JumpToEntity(entityIdString);
					return;
				}
			}
			SD.Workbench.ShowView(new DecompiledViewContent(target, entityIdString));
		}
Ejemplo n.º 5
0
		protected ITest GetTestClass(TopLevelTypeName fullName)
		{
			EnsureNestedTestsInitialized();
			return topLevelTestClasses.GetOrDefault(fullName);
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Adds/Updates/Removes the test class for the type definition.
		/// </summary>
		void UpdateType(TopLevelTypeName dirtyTypeDef, ITypeDefinition typeDef)
		{
			ITest test;
			if (topLevelTestClasses.TryGetValue(dirtyTypeDef, out test)) {
				if (typeDef == null) {
					// Test class was removed completely (no parts left)
					RemoveTestClass(dirtyTypeDef, test);
				} else {
					// Test class was modified
					// Check if it's still a test class:
					if (IsTestClass(typeDef))
						UpdateTestClass(test, typeDef);
					else
						RemoveTestClass(dirtyTypeDef, test);
				}
			} else if (typeDef != null) {
				// Test class was added
				var testClass = CreateTestClass(typeDef);
				if (testClass != null)
					AddTestClass(dirtyTypeDef, testClass);
			}
		}
Ejemplo n.º 7
0
		protected virtual void AddToDirtyList(TopLevelTypeName className)
		{
			dirtyTypeDefinitions.Add(className);
		}
        ITypeDefinition GetBuiltinTypeDefinition(string typeName)
        {
            var type_name = new TopLevelTypeName("global", typeName);
            foreach(var asm in compilation.Assemblies){
                var type_def = asm.GetTypeDefinition(type_name);
                if(type_def != null)
                    return type_def;
            }

            return null;
        }
Ejemplo n.º 9
0
		public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName)
		{
			ITypeDefinition def;
			if (GetTypes().TryGetValue(topLevelTypeName, out def))
				return def;
			else
				return null;
		}
Ejemplo n.º 10
0
        ITypeDefinition GetTypeDefinition(string name)
        {
            ICompilation compilation = project.GetCompilationUnit();
            var typeName = new TopLevelTypeName(name);

            foreach (IAssembly assembly in compilation.Assemblies) {
                ITypeDefinition typeDefinition = assembly.GetTypeDefinition(typeName);
                if (typeDefinition != null) {
                    return typeDefinition;
                }
            }

            return null;
        }
			public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName)
			{
				IUnresolvedTypeDefinition td;
				ITypeReference typeRef;
				if (unresolvedAssembly.typeDefinitions.TryGetValue(topLevelTypeName, out td))
					return GetTypeDefinition(td);
				else if (unresolvedAssembly.typeForwarders.TryGetValue(topLevelTypeName, out typeRef))
					return typeRef.Resolve(compilation.TypeResolveContext).GetDefinition();
				else
					return null;
			}
		public IUnresolvedTypeDefinition GetTypeDefinition(string ns, string name, int typeParameterCount)
		{
			var key = new TopLevelTypeName(ns ?? string.Empty, name, typeParameterCount);
			IUnresolvedTypeDefinition td;
			if (typeDefinitions.TryGetValue(key, out td))
				return td;
			else
				return null;
		}
		/// <summary>
		/// Adds a type forwarder.
		/// This adds both an assembly attribute and an internal forwarder entry, which will be used
		/// by the resolved assembly to provide the forwarded types.
		/// </summary>
		/// <param name="typeName">The name of the type.</param>
		/// <param name="referencedType">The reference used to look up the type in the target assembly.</param>
		public void AddTypeForwarder(TopLevelTypeName typeName, ITypeReference referencedType)
		{
			if (referencedType == null)
				throw new ArgumentNullException("referencedType");
			FreezableHelper.ThrowIfFrozen(this);
			var attribute = new DefaultUnresolvedAttribute(typeForwardedToAttributeTypeRef, new[] { KnownTypeReference.Type });
			attribute.PositionalArguments.Add(new TypeOfConstantValue(referencedType));
			assemblyAttributes.Add(attribute);
			
			typeForwarders[typeName] = referencedType;
		}
		/// <summary>
		/// Adds a new top-level type definition to this assembly.
		/// </summary>
		/// <remarks>DefaultUnresolvedAssembly does not support partial classes.
		/// Adding more than one part of a type will cause an ArgumentException.</remarks>
		public void AddTypeDefinition(IUnresolvedTypeDefinition typeDefinition)
		{
			if (typeDefinition == null)
				throw new ArgumentNullException("typeDefinition");
			if (typeDefinition.DeclaringTypeDefinition != null)
				throw new ArgumentException("Cannot add nested types.");
			FreezableHelper.ThrowIfFrozen(this);
			var key = new TopLevelTypeName(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameters.Count);
			typeDefinitions.Add(key, typeDefinition);
		}
Ejemplo n.º 15
0
        public IUnresolvedAssembly LoadAssembly(Assembly assembly)
        {
            if (assembly == null)
                throw new ArgumentNullException ("assembly");

            // Read assembly and module attributes
            IList<IUnresolvedAttribute> assemblyAttributes = new List<IUnresolvedAttribute>();
            IList<IUnresolvedAttribute> moduleAttributes = new List<IUnresolvedAttribute>();
            AddAttributes(assembly, assemblyAttributes);
            AddAttributes(assembly.ManifestModule, moduleAttributes);

            assemblyAttributes = interningProvider.InternList(assemblyAttributes);
            moduleAttributes = interningProvider.InternList(moduleAttributes);

            currentAssemblyDefinition = assembly;
            currentAssembly = new IkvmUnresolvedAssembly (assembly.FullName, DocumentationProvider);
            currentAssembly.Location = assembly.Location;
            currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes);
            currentAssembly.ModuleAttributes.AddRange(moduleAttributes);
            // Register type forwarders:
            foreach (var type in assembly.ManifestModule.__GetExportedTypes ()) {
                if (type.Assembly != assembly) {
                    int typeParameterCount;
                    string ns = type.Namespace;
                    string name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
                    ns = interningProvider.Intern(ns);
                    name = interningProvider.Intern(name);
                    var typeRef = new GetClassTypeReference(GetAssemblyReference(type.Assembly), ns, name, typeParameterCount);
                    typeRef = interningProvider.Intern(typeRef);
                    var key = new TopLevelTypeName(ns, name, typeParameterCount);
                    currentAssembly.AddTypeForwarder(key, typeRef);
                }
            }

            // Create and register all types:
            var ikvmTypeDefs = new List<IKVM.Reflection.Type>();
            var typeDefs = new List<DefaultUnresolvedTypeDefinition>();

            foreach (var td in assembly.GetTypes ()) {
                if (td.DeclaringType != null)
                    continue;
                CancellationToken.ThrowIfCancellationRequested();

                if (IncludeInternalMembers || td.IsPublic) {
                    string name = td.Name;
                    if (name.Length == 0)
                        continue;

                    var t = CreateTopLevelTypeDefinition(td);
                    ikvmTypeDefs.Add(td);
                    typeDefs.Add(t);
                    currentAssembly.AddTypeDefinition(t);
                    // The registration will happen after the members are initialized
                }
            }

            // Initialize the type's members:
            for (int i = 0; i < typeDefs.Count; i++) {
                InitTypeDefinition(ikvmTypeDefs[i], typeDefs[i]);
            }

            // Freezing the assembly here is important:
            // otherwise it will be frozen when a compilation is first created
            // from it. But freezing has the effect of changing some collection instances
            // (to ReadOnlyCollection). This hidden mutation was causing a crash
            // when the FastSerializer was saving the assembly at the same time as
            // the first compilation was created from it.
            // By freezing the assembly now, we ensure it is usable on multiple
            // threads without issues.
            currentAssembly.Freeze();

            var result = currentAssembly;
            currentAssembly = null;
            return result;
        }
Ejemplo n.º 16
0
 public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
		void AddTestClass(TopLevelTypeName fullName, ITest test)
		{
			topLevelTestClasses.Add(fullName, test);
			TestCollection testNamespace = FindOrCreateNamespace(NestedTestCollection, project.RootNamespace, fullName.Namespace);
			testNamespace.Add(test);
		}
Ejemplo n.º 18
0
		void RemoveTestClass(TopLevelTypeName fullName, ITest test)
		{
			topLevelTestClasses.Remove(fullName);
			TestCollection testNamespace = FindNamespace(NestedTestCollection, project.RootNamespace, fullName.Namespace);
			if (testNamespace != null) {
				testNamespace.Remove(test);
				if (testNamespace.Count == 0) {
					// Remove the namespace
					RemoveTestNamespace(NestedTestCollection, project.RootNamespace, fullName.Namespace);
				}
			}
			OnTestClassRemoved(test);
		}
				ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount)
				{
					var key = new TopLevelTypeName(ns.FullName, name, typeParameterCount);
					IUnresolvedTypeDefinition unresolvedTypeDef;
					if (assembly.unresolvedTypeDict.TryGetValue(key, out unresolvedTypeDef))
						return assembly.GetTypeDefinition(unresolvedTypeDef);
					else
						return null;
				}
Ejemplo n.º 20
0
		protected override void AddToDirtyList(TopLevelTypeName className)
		{
			// When a base class is invalidated, also invalidate all derived classes
			base.AddToDirtyList(className);
			foreach (var derivedClass in inheritedTestClasses[className]) {
				base.AddToDirtyList(derivedClass.FullTypeName.TopLevelTypeName);
			}
		}
			public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName)
			{
				IUnresolvedTypeDefinition td;
				ITypeReference typeRef;
				if (unresolvedAssembly.typeDefinitions.TryGetValue(topLevelTypeName, out td))
					return GetTypeDefinition(td);
				if (unresolvedAssembly.typeForwarders.TryGetValue(topLevelTypeName, out typeRef)) {
					// Protect against cyclic type forwarders:
					using (var busyLock = BusyManager.Enter(typeRef)) {
						if (busyLock.Success)
							return typeRef.Resolve(compilation.TypeResolveContext).GetDefinition();
					}
				}
				return null;
			}
Ejemplo n.º 22
0
			ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount)
			{
				var key = new TopLevelTypeName(fullName, name, typeParameterCount);
				if (types != null) {
					ITypeDefinition typeDef;
					if (types.TryGetValue(key, out typeDef))
						return typeDef;
					else
						return null;
				} else {
					return assembly.GetTypeDefinition(key);
				}
			}
        public ResolveResult ResolveTypeName(string typeName)
        {
            if(!BVE5ResourceManager.IsBuiltinTypeName(typeName))	//Try to match in case-insensitive way
                return ErrorResult;

            var type_name = new TopLevelTypeName("global", typeName, 0);
            var type_def = compilation.MainAssembly.GetTypeDefinition(type_name);
            if(type_def != null)
                return new TypeResolveResult(type_def);

            return ErrorResult;
        }