public BVE5Compilation(ISolutionSnapshot solutionSnapshot, IUnresolvedAssembly mainAssembly,
                               IEnumerable<IAssemblyReference> assemblyReferences)
        {
            if(solutionSnapshot == null)
                throw new ArgumentNullException("solutionSnapshot");

            if(mainAssembly == null)
                throw new ArgumentNullException("mainAssembly");

            if(assemblyReferences == null)
                throw new ArgumentNullException("assemblyReferences");

            solution_snapshot = solutionSnapshot;
            context = new SimpleTypeResolveContext(this);
            main_assembly = mainAssembly.Resolve(context);
            var assemblies = new List<IAssembly>{main_assembly};
            var referenced_assemblies = new List<IAssembly>();
            foreach(var asm_ref in assemblyReferences){
                IAssembly asm = asm_ref.Resolve(context);
                if(asm != null && !assemblies.Contains(asm))
                    assemblies.Add(asm);

                if(asm != null && !referenced_assemblies.Contains(asm))
                    referenced_assemblies.Add(asm);
            }

            this.assemblies = assemblies.AsReadOnly();
            this.referenced_assemblies = referenced_assemblies.AsReadOnly();
            this.type_cache = new PrimitiveTypeCache(this);
        }
Esempio n. 2
0
		public TypeInference(ITypeResolveContext context, Conversions conversions = null)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			this.conversions = conversions ?? Conversions.Get(context);
		}
Esempio n. 3
0
		public CecilResolvedAttribute(ITypeResolveContext context, UnresolvedAttributeBlob unresolved)
		{
			this.context = context;
			this.blob = unresolved.blob;
			this.ctorParameterTypes = unresolved.ctorParameterTypes;
			this.attributeType = unresolved.attributeType.Resolve(context);
		}
Esempio n. 4
0
		/// <summary>
		/// Gets the non-interface base types.
		/// </summary>
		/// <remarks>
		/// When <paramref name="type"/> is an interface, this method will also return base interfaces.
		/// 
		/// The output is ordered so that base types occur in before derived types.
		/// </remarks>
		public static IEnumerable<IType> GetNonInterfaceBaseTypes(this IType type, ITypeResolveContext context)
		{
			BaseTypeCollector collector = new BaseTypeCollector(context);
			collector.SkipImplementedInterfaces = true;
			collector.CollectBaseTypes(type);
			return collector;
		}
Esempio n. 5
0
 public IAssembly Resolve(ITypeResolveContext context)
 {
     var project = _solution.Projects.FirstOrDefault(p => string.Equals(p.Title, _projectTitle, StringComparison.OrdinalIgnoreCase));
     if (project != null) 
         return project.ProjectContent.Resolve(context);
     return null;
 }
			public IAssembly Resolve(ITypeResolveContext context)
			{
				IAssembly asm = context.CurrentAssembly;
				if (asm == null)
					throw new ArgumentException("A reference to the current assembly cannot be resolved in the compilation's global type resolve context.");
				return asm;
			}
Esempio n. 7
0
		/// <summary>
		/// Creates a new TypeSystemAstBuilder.
		/// </summary>
		/// <param name="context">
		/// Context used for resolving types.
		/// </param>
		public TypeSystemAstBuilder(ITypeResolveContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			InitProperties();
		}
Esempio n. 8
0
		ISymbol ISymbolReference.Resolve(ITypeResolveContext context)
		{
			var type = Resolve(context);
			if (type is ITypeDefinition)
				return (ISymbol)type;
			return null;
		}
		public IMethod ResolveConstructor(ITypeResolveContext context)
		{
			IType[] parameterTypes = null;
			if (constructorParameterTypes != null && constructorParameterTypes.Length > 0) {
				parameterTypes = new IType[constructorParameterTypes.Length];
				for (int i = 0; i < parameterTypes.Length; i++) {
					parameterTypes[i] = constructorParameterTypes[i].Resolve(context);
				}
			}
			IMethod bestMatch = null;
			foreach (IMethod ctor in attributeType.Resolve(context).GetConstructors(context)) {
				if (ctor.IsStatic)
					continue;
				if (parameterTypes == null) {
					if (ctor.Parameters.Count == 0)
						return ctor;
				} else if (ctor.Parameters.Count == parameterTypes.Length) {
					bestMatch = ctor;
					bool ok = true;
					for (int i = 0; i < parameterTypes.Length; i++) {
						if (ctor.Parameters[i].Type != parameterTypes[i]) {
							ok = false;
							break;
						}
					}
					if (ok)
						return ctor;
				}
			}
			return bestMatch;
		}
Esempio n. 10
0
		public IMember Resolve(ITypeResolveContext context)
		{
			IType type = typeReference.Resolve(context);
			IEnumerable<IMember> members;
			if (entityType == EntityType.Method) {
				members = type.GetMethods(
					m => m.Name == name && m.EntityType == EntityType.Method && m.TypeParameters.Count == typeParameterCount,
					GetMemberOptions.IgnoreInheritedMembers);
			} else {
				members = type.GetMembers(
					m => m.Name == name && m.EntityType == entityType,
					GetMemberOptions.IgnoreInheritedMembers);
			}
			var resolvedParameterTypes = parameterTypes.Resolve(context);
			foreach (IMember member in members) {
				IParameterizedMember parameterizedMember = member as IParameterizedMember;
				if (parameterTypes.Count == 0) {
					if (parameterizedMember == null || parameterizedMember.Parameters.Count == 0)
						return member;
				} else if (parameterTypes.Count == parameterizedMember.Parameters.Count) {
					bool signatureMatches = true;
					for (int i = 0; i < parameterTypes.Count; i++) {
						IType type1 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(resolvedParameterTypes[i]);
						IType type2 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(parameterizedMember.Parameters[i].Type);
						if (!type1.Equals(type2)) {
							signatureMatches = false;
							break;
						}
					}
					if (signatureMatches)
						return member;
				}
			}
			return null;
		}
        IType ITypeReference.Resolve(ITypeResolveContext context)
        {
            // Strictly speaking, we might have to resolve the type in a nested compilation, similar
            // to what we're doing with ConstantExpression.
            // However, in almost all cases this will work correctly - if the resulting type is only available in the
            // nested compilation and not in this, we wouldn't be able to map it anyways.
            var ctx = context as CSharpTypeResolveContext;
            if (ctx == null) {
                ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
            }
            return ResolveType(new CSharpResolver(ctx));

            // A potential issue might be this scenario:

            // Assembly 1:
            //  class A { public class Nested {} }

            // Assembly 2: (references asm 1)
            //  class B : A {}

            // Assembly 3: (references asm 1 and 2)
            //  class C { public B.Nested Field; }

            // Assembly 4: (references asm 1 and 3, but not 2):
            //  uses C.Field;

            // Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.
        }
		/*
		sealed class CachedResult
		{
			public readonly CacheManager CacheManager;
			public readonly IType Result;
			
			public CachedResult(CacheManager cacheManager, IType result)
			{
				this.CacheManager = cacheManager;
				this.Result = result;
			}
		}
		 */
		
		public IType Resolve(ITypeResolveContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			
			/*  TODO PERF: caching disabled until we measure how much of an advantage it is
			 * (and whether other approaches like caching only the last N resolve calls in a thread-static cache would work better)
			 * Maybe even make a distinction between the really common type references (e.g. primitiveTypeReferences) and
			 * normal GetClassTypeReferences?
			CacheManager cacheManager = context.CacheManager;
			if (cacheManager != null) {
				CachedResult result = this.v_cachedResult;
				if (result != null && result.CacheManager == cacheManager)
					return result.Result;
				IType newResult = DoResolve(context);
				this.v_cachedResult = new CachedResult(cacheManager, newResult);
				cacheManager.Disposed += delegate { v_cachedResult = null; }; // maybe optimize this to use interface call instead of delegate?
				return newResult;
			} else {
				return DoResolve(context);
			}
			
		}
		
		IType DoResolve(ITypeResolveContext context)
		{
			 */
			return context.GetClass(nameSpace, name, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
		}
Esempio n. 13
0
		public bool? IsReferenceType(ITypeResolveContext context)
		{
			switch (flags.Data & (FlagReferenceTypeConstraint | FlagValueTypeConstraint)) {
				case FlagReferenceTypeConstraint:
					return true;
				case FlagValueTypeConstraint:
					return false;
			}
			// protect against cyclic dependencies between type parameters
			using (var busyLock = BusyManager.Enter(this)) {
				if (busyLock.Success) {
					foreach (ITypeReference constraintRef in this.Constraints) {
						IType constraint = constraintRef.Resolve(context);
						ITypeDefinition constraintDef = constraint.GetDefinition();
						// While interfaces are reference types, an interface constraint does not
						// force the type parameter to be a reference type; so we need to explicitly look for classes here.
						if (constraintDef != null && constraintDef.ClassType == ClassType.Class)
							return true;
						if (constraint is ITypeParameter) {
							bool? isReferenceType = constraint.IsReferenceType(context);
							if (isReferenceType.HasValue)
								return isReferenceType.Value;
						}
					}
				}
			}
			return null;
		}
Esempio n. 14
0
		public SimpleCompilation(ISolutionSnapshot solutionSnapshot, IUnresolvedAssembly mainAssembly, IEnumerable<IAssemblyReference> assemblyReferences)
		{
			if (solutionSnapshot == null)
				throw new ArgumentNullException("solutionSnapshot");
			if (mainAssembly == null)
				throw new ArgumentNullException("mainAssembly");
			if (assemblyReferences == null)
				throw new ArgumentNullException("assemblyReferences");
			this.solutionSnapshot = solutionSnapshot;
			this.context = new SimpleTypeResolveContext(this);
			this.mainAssembly = mainAssembly.Resolve(context);
			List<IAssembly> assemblies = new List<IAssembly>();
			assemblies.Add(this.mainAssembly);
			List<IAssembly> referencedAssemblies = new List<IAssembly>();
			foreach (var asmRef in assemblyReferences) {
				IAssembly asm = asmRef.Resolve(context);
				if (asm != null && !assemblies.Contains(asm))
					assemblies.Add(asm);
				if (asm != null && !referencedAssemblies.Contains(asm))
					referencedAssemblies.Add(asm);
			}
			this.assemblies = assemblies.AsReadOnly();
			this.referencedAssemblies = referencedAssemblies.AsReadOnly();
			this.knownTypeCache = new KnownTypeCache(this);
		}
Esempio n. 15
0
 /// <summary>
 /// Gets all base types.
 /// </summary>
 /// <remarks>This is the reflexive and transitive closure of <see cref="IType.GetBaseTypes"/>.
 /// Note that this method does not return all supertypes - doing so is impossible due to contravariance
 /// (and undesirable for covariance as the list could become very large).
 /// </remarks>
 public static IEnumerable<IType> GetAllBaseTypes(this IType type, ITypeResolveContext context)
 {
     List<IType> output = new List<IType>();
     Stack<ITypeDefinition> activeTypeDefinitions = new Stack<ITypeDefinition>();
     CollectAllBaseTypes(type, context, activeTypeDefinitions, output);
     return output;
 }
Esempio n. 16
0
		public IList<KeyValuePair<string, IConstantValue>> GetNamedArguments(ITypeResolveContext context)
		{
			if (namedArguments != null)
				return new ReadOnlyCollection<KeyValuePair<string, IConstantValue>>(namedArguments);
			else
				return EmptyList<KeyValuePair<string, IConstantValue>>.Instance;
		}
Esempio n. 17
0
		public IMethod ResolveConstructor(ITypeResolveContext context)
		{
			CSharpResolver r = new CSharpResolver(context);
			IType type = attributeType.Resolve(context);
			int totalArgumentCount = 0;
			if (positionalArguments != null)
				totalArgumentCount += positionalArguments.Count;
			if (namedCtorArguments != null)
				totalArgumentCount += namedCtorArguments.Count;
			ResolveResult[] arguments = new ResolveResult[totalArgumentCount];
			string[] argumentNames = new string[totalArgumentCount];
			int i = 0;
			if (positionalArguments != null) {
				while (i < positionalArguments.Count) {
					IConstantValue cv = positionalArguments[i];
					arguments[i] = cv.Resolve(context);
					i++;
				}
			}
			if (namedCtorArguments != null) {
				foreach (var pair in namedCtorArguments) {
					argumentNames[i] = pair.Key;
					arguments[i] = pair.Value.Resolve(context);
					i++;
				}
			}
			MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult;
			return mrr != null ? mrr.Member as IMethod : null;
		}
Esempio n. 18
0
		public IList<IConstantValue> GetPositionalArguments(ITypeResolveContext context)
		{
			if (namedCtorArguments == null || namedCtorArguments.Count == 0) {
				// no namedCtorArguments: just return the positionalArguments
				if (positionalArguments != null)
					return new ReadOnlyCollection<IConstantValue>(positionalArguments);
				else
					return EmptyList<IConstantValue>.Instance;
			}
			// we do have namedCtorArguments, which need to be re-ordered and appended to the positional arguments
			List<IConstantValue> result = new List<IConstantValue>(this.positionalArguments);
			IMethod method = ResolveConstructor(context);
			if (method != null) {
				for (int i = result.Count; i < method.Parameters.Count; i++) {
					IParameter p = method.Parameters[i];
					bool found = false;
					foreach (var pair in namedCtorArguments) {
						if (pair.Key == p.Name) {
							result.Add(pair.Value);
							found = true;
						}
					}
					if (!found) {
						// add the parameter's default value:
						result.Add(p.DefaultValue ?? new SimpleConstantValue(p.Type, CSharpResolver.GetDefaultValue(p.Type.Resolve(context))));
					}
				}
			}
			return result.AsReadOnly();
		}
Esempio n. 19
0
 public IAssembly Resolve(ITypeResolveContext context)
 {
     var project = _solution.Projects.FirstOrDefault(p => p.ProjectId == _projectGuid);
     if (project != null)
         return project.ProjectContent.Resolve(context);
     return null;
 }
Esempio n. 20
0
		public object GetValue(ITypeResolveContext context)
		{
			if (value is ITypeReference)
				return ((ITypeReference)value).Resolve(context);
			else
				return value;
		}
		public IType Resolve(ITypeResolveContext context)
		{
			string[] parts = typeName.Split('.');
			var assemblies = new [] { context.CurrentAssembly }.Concat(context.Compilation.Assemblies);
			for (int i = parts.Length - 1; i >= 0; i--) {
				string ns = string.Join(".", parts, 0, i);
				string name = parts[i];
				int topLevelTPC = (i == parts.Length - 1 ? typeParameterCount : 0);
				foreach (var asm in assemblies) {
					if (asm == null)
						continue;
					ITypeDefinition typeDef = asm.GetTypeDefinition(new TopLevelTypeName(ns, name, topLevelTPC));
					for (int j = i + 1; j < parts.Length && typeDef != null; j++) {
						int tpc = (j == parts.Length - 1 ? typeParameterCount : 0);
						typeDef = typeDef.NestedTypes.FirstOrDefault(n => n.Name == parts[j] && n.TypeParameterCount == tpc);
					}
					if (typeDef != null)
						return typeDef;
				}
			}
			int idx = typeName.LastIndexOf('.');
			if (idx < 0)
				return new UnknownType("", typeName, typeParameterCount);
			// give back a guessed namespace/type name
			return  new UnknownType(typeName.Substring(0, idx), typeName.Substring(idx + 1), typeParameterCount);
		}
Esempio n. 22
0
		public SimpleCompilation(ISolutionSnapshot solutionSnapshot, IUnresolvedAssembly mainAssembly, IEnumerable<IAssemblyReference> assemblyReferences)
		{
			if (solutionSnapshot == null)
				throw new ArgumentNullException("solutionSnapshot");
			if (mainAssembly == null)
				throw new ArgumentNullException("mainAssembly");
			if (assemblyReferences == null)
				throw new ArgumentNullException("assemblyReferences");
			this.solutionSnapshot = solutionSnapshot;
			this.context = new SimpleTypeResolveContext(this);
			this.mainAssembly = mainAssembly.Resolve(context);
			List<IAssembly> assemblies = new List<IAssembly>();
			assemblies.Add(this.mainAssembly);
			List<IAssembly> referencedAssemblies = new List<IAssembly>();
			foreach (var asmRef in assemblyReferences) {
				IAssembly asm;
				try {
					asm = asmRef.Resolve(context);
				} catch (InvalidOperationException) {
					throw new InvalidOperationException("Tried to initialize compilation with an invalid assembly reference. (Forgot to load the assembly reference ? - see CecilLoader)");
				}
				if (asm != null && !assemblies.Contains(asm))
					assemblies.Add(asm);
				if (asm != null && !referencedAssemblies.Contains(asm))
					referencedAssemblies.Add(asm);
			}
			this.assemblies = assemblies.AsReadOnly();
			this.referencedAssemblies = referencedAssemblies.AsReadOnly();
			this.knownTypeCache = new KnownTypeCache(this);
		}
Esempio n. 23
0
		public MemberLookup(ITypeResolveContext context, ITypeDefinition currentTypeDefinition, IProjectContent currentProject)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			this.currentTypeDefinition = currentTypeDefinition;
			this.currentProject = currentProject;
		}
Esempio n. 24
0
		/// <summary>
		/// Creates a new TypeSystemAstBuilder.
		/// </summary>
		/// <param name="resolver">
		/// A resolver initialized for the position where the type will be inserted.
		/// </param>
		public TypeSystemAstBuilder(CSharpResolver resolver)
		{
			if (resolver == null)
				throw new ArgumentNullException("resolver");
			this.resolver = resolver;
			this.context = resolver.Context;
			InitProperties();
		}
		/// <summary>
		/// Creates a <see cref="CompositeTypeResolveContext"/> that combines the given resolve contexts.
		/// If one of the input parameters is null, the other input parameter is returned directly.
		/// If both input parameters are null, the function returns null.
		/// </summary>
		public static ITypeResolveContext Combine(ITypeResolveContext a, ITypeResolveContext b)
		{
			if (a == null)
				return b;
			if (b == null)
				return a;
			return new CompositeTypeResolveContext(new [] { a, b });
		}
Esempio n. 26
0
 public IAssembly Resolve(ITypeResolveContext context)
 {
     var project = _solution.Projects.FirstOrDefault(p => p.ProjectId == _projectGuid);
     if (project != null)
         return project.ProjectContent.Resolve(context);
     Console.WriteLine("Could not find project " + _projectTitle);
     return null;
 }
Esempio n. 27
0
		public ResolveResult Resolve(ITypeResolveContext context)
		{
			if (value is ITypeReference) {
				return new TypeOfResolveResult(type.Resolve(context), ((ITypeReference)value).Resolve(context));
			} else {
				return new ConstantResolveResult(type.Resolve(context), value);
			}
		}
		public override ITypeParameter CreateResolvedTypeParameter(ITypeResolveContext context)
		{
			if (context.CurrentMember is IMethod) {
				return new ResolvedMethodTypeParameterWithInheritedConstraints(this, context);
			} else {
				return base.CreateResolvedTypeParameter(context);
			}
		}
 public IMember Resolve(ITypeResolveContext context)
 {
     IMethod method = accessorReference.Resolve(context) as IMethod;
     if (method != null)
         return method.AccessorOwner;
     else
         return null;
 }
Esempio n. 30
0
		public DefaultResolvedMethod(IUnresolvedMethod unresolved, ITypeResolveContext parentContext, bool isExtensionMethod)
			: base(unresolved, parentContext)
		{
			this.Parameters = unresolved.Parameters.CreateResolvedParameters(context);
			this.ReturnTypeAttributes = unresolved.ReturnTypeAttributes.CreateResolvedAttributes(parentContext);
			this.TypeParameters = unresolved.TypeParameters.CreateResolvedTypeParameters(context);
			this.IsExtensionMethod = isExtensionMethod;
		}
Esempio n. 31
0
 public override IMember CreateResolved(ITypeResolveContext context)
 {
     return(new ResolvedPropertySpec(this, context));
 }
 public static IMember Resolve(ITypeResolveContext context,
                               SymbolKind symbolKind,
                               string name,
                               ITypeReference explicitInterfaceTypeReference  = null,
                               IList <string> typeParameterNames              = null,
                               IList <ITypeReference> parameterTypeReferences = null)
 {
     if (context.CurrentTypeDefinition == null)
     {
         return(null);
     }
     if (parameterTypeReferences == null)
     {
         parameterTypeReferences = EmptyList <ITypeReference> .Instance;
     }
     if (typeParameterNames == null || typeParameterNames.Count == 0)
     {
         // non-generic member
         // In this case, we can simply resolve the parameter types in the given context
         var parameterTypes = parameterTypeReferences.Resolve(context);
         if (explicitInterfaceTypeReference == null)
         {
             foreach (IMember member in context.CurrentTypeDefinition.Members)
             {
                 if (member.IsExplicitInterfaceImplementation)
                 {
                     continue;
                 }
                 if (IsNonGenericMatch(member, symbolKind, name, parameterTypes))
                 {
                     return(member);
                 }
             }
         }
         else
         {
             IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(context);
             foreach (IMember member in context.CurrentTypeDefinition.Members)
             {
                 if (!member.IsExplicitInterfaceImplementation)
                 {
                     continue;
                 }
                 if (member.ImplementedInterfaceMembers.Count != 1)
                 {
                     continue;
                 }
                 if (IsNonGenericMatch(member, symbolKind, name, parameterTypes))
                 {
                     if (explicitInterfaceType.Equals(member.ImplementedInterfaceMembers[0].DeclaringType))
                     {
                         return(member);
                     }
                 }
             }
         }
     }
     else
     {
         // generic member
         // In this case, we must specify the correct context for resolving the parameter types
         foreach (IMethod method in context.CurrentTypeDefinition.Methods)
         {
             if (method.SymbolKind != symbolKind)
             {
                 continue;
             }
             if (method.Name != name)
             {
                 continue;
             }
             if (method.Parameters.Count != parameterTypeReferences.Count)
             {
                 continue;
             }
             // Compare type parameter count and names:
             if (!typeParameterNames.SequenceEqual(method.TypeParameters.Select(tp => tp.Name)))
             {
                 continue;
             }
             // Once we know the type parameter names are fitting, we can resolve the
             // type references in the context of the method:
             var contextForMethod = context.WithCurrentMember(method);
             var parameterTypes   = parameterTypeReferences.Resolve(contextForMethod);
             if (!IsParameterTypeMatch(method, parameterTypes))
             {
                 continue;
             }
             if (explicitInterfaceTypeReference == null)
             {
                 if (!method.IsExplicitInterfaceImplementation)
                 {
                     return(method);
                 }
             }
             else if (method.IsExplicitInterfaceImplementation && method.ImplementedInterfaceMembers.Count == 1)
             {
                 IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(contextForMethod);
                 if (explicitInterfaceType.Equals(method.ImplementedInterfaceMembers[0].DeclaringType))
                 {
                     return(method);
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 33
0
        internal SpecializedParameterizedMember(IType declaringType, IParameterizedMember memberDefinition, TypeVisitor substitution, ITypeResolveContext context)
            : base(declaringType, memberDefinition, substitution, context)
        {
            var paramDefs = memberDefinition.Parameters;

            if (paramDefs.Count == 0)
            {
                this.parameters = EmptyList <IParameter> .Instance;
            }
            else
            {
                var parameters = new IParameter[paramDefs.Count];
                for (int i = 0; i < parameters.Length; i++)
                {
                    ITypeReference newType = Substitute(paramDefs[i].Type, substitution, context);
                    if (newType != paramDefs[i].Type)
                    {
                        parameters[i] = new DefaultParameter(paramDefs[i])
                        {
                            Type = newType
                        };
                    }
                    else
                    {
                        parameters[i] = paramDefs[i];
                    }
                }
                this.parameters = Array.AsReadOnly(parameters);
            }
        }
Esempio n. 34
0
 public ISymbol Resolve(ITypeResolveContext context)
 {
     return(new DefaultParameter(type.Resolve(context), name, region: region, isRef: isRef, isOut: isOut, isParams: isParams, isOptional: isOptional, defaultValue: defaultValue));
 }
Esempio n. 35
0
 IType IConstantValue.GetValueType(ITypeResolveContext context)
 {
     Contract.Requires(context != null);
     Contract.Ensures(Contract.Result <IType>() != null);
     return(null);
 }
Esempio n. 36
0
 IEvent IUnresolvedEvent.Resolve(ITypeResolveContext context)
 {
     return((IEvent)Resolve(context));
 }
Esempio n. 37
0
 public IType Resolve(ITypeResolveContext context)
 {
     return(new ByReferenceType(elementType.Resolve(context)));
 }
Esempio n. 38
0
 public override IMember CreateResolved(ITypeResolveContext context)
 {
     return(new DefaultResolvedEvent(this, context));
 }
Esempio n. 39
0
 public static IList <IType> Resolve(this IList <ITypeReference> typeReferences, ITypeResolveContext context)
 {
     if (typeReferences == null)
     {
         throw new ArgumentNullException("typeReferences");
     }
     if (typeReferences.Count == 0)
     {
         return(EmptyList <IType> .Instance);
     }
     else
     {
         return(new ProjectedList <ITypeResolveContext, ITypeReference, IType>(context, typeReferences, (c, t) => t.Resolve(c)));
     }
 }
Esempio n. 40
0
 object IConstantValue.GetValue(ITypeResolveContext context)
 {
     Contract.Requires(context != null);
     return(null);
 }
Esempio n. 41
0
 public IType Resolve(ITypeResolveContext context)
 {
     return(this);
 }
Esempio n. 42
0
        MemberList GetMemberList()
        {
            var result = LazyInit.VolatileRead(ref this.memberList);

            if (result != null)
            {
                return(result);
            }
            List <IUnresolvedMember>   unresolvedMembers  = new List <IUnresolvedMember>();
            List <ITypeResolveContext> contextPerMember   = new List <ITypeResolveContext>();
            List <PartialMethodInfo>   partialMethodInfos = null;
            bool addDefaultConstructorIfRequired          = false;

            foreach (IUnresolvedTypeDefinition part in parts)
            {
                ITypeResolveContext parentContextForPart = part.CreateResolveContext(parentContext);
                ITypeResolveContext contextForPart       = parentContextForPart.WithCurrentTypeDefinition(this);
                foreach (var member in part.Members)
                {
                    IUnresolvedMethod method = member as IUnresolvedMethod;
                    if (method != null && method.IsPartial)
                    {
                        // Merge partial method declaration and implementation
                        if (partialMethodInfos == null)
                        {
                            partialMethodInfos = new List <PartialMethodInfo>();
                        }
                        PartialMethodInfo newInfo      = new PartialMethodInfo(method, contextForPart);
                        PartialMethodInfo existingInfo = null;
                        foreach (var info in partialMethodInfos)
                        {
                            if (newInfo.IsSameSignature(info, Compilation.NameComparer))
                            {
                                existingInfo = info;
                                break;
                            }
                        }
                        if (existingInfo != null)
                        {
                            // Add the unresolved method to the PartialMethodInfo:
                            existingInfo.AddPart(method, contextForPart);
                        }
                        else
                        {
                            partialMethodInfos.Add(newInfo);
                        }
                    }
                    else
                    {
                        unresolvedMembers.Add(member);
                        contextPerMember.Add(contextForPart);
                    }
                }

                addDefaultConstructorIfRequired |= part.AddDefaultConstructorIfRequired;
            }
            if (addDefaultConstructorIfRequired)
            {
                TypeKind kind = this.Kind;
                if (kind == TypeKind.Class && !this.IsStatic && !unresolvedMembers.Any(m => m.EntityType == EntityType.Constructor && !m.IsStatic) ||
                    kind == TypeKind.Enum || kind == TypeKind.Struct)
                {
                    contextPerMember.Add(parts[0].CreateResolveContext(parentContext).WithCurrentTypeDefinition(this));
                    unresolvedMembers.Add(DefaultUnresolvedMethod.CreateDefaultConstructor(parts[0]));
                }
            }
            result = new MemberList(contextPerMember, unresolvedMembers, partialMethodInfos);
            return(LazyInit.GetOrSet(ref this.memberList, result));
        }
Esempio n. 43
0
 public static IList <IParameter> CreateResolvedParameters(this IList <IUnresolvedParameter> parameters, ITypeResolveContext context)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters");
     }
     if (parameters.Count == 0)
     {
         return(EmptyList <IParameter> .Instance);
     }
     else
     {
         return(new ProjectedList <ITypeResolveContext, IUnresolvedParameter, IParameter>(context, parameters, (c, a) => a.CreateResolvedParameter(c)));
     }
 }
Esempio n. 44
0
 protected AbstractResolvedEntity(IUnresolvedEntity unresolved, ITypeResolveContext parentContext)
 {
     this.unresolved    = unresolved ?? throw new ArgumentNullException("unresolved");
     this.parentContext = parentContext ?? throw new ArgumentNullException("parentContext");
     this.Attributes    = unresolved.Attributes.CreateResolvedAttributes(parentContext);
 }
 IField IUnresolvedField.Resolve(ITypeResolveContext context)
 {
     return((IField)Resolve(context));
 }
Esempio n. 46
0
 IModule IModuleReference.Resolve(ITypeResolveContext context)
 {
     return(new MinimalCorlib(context.Compilation));
 }
 IMethod IUnresolvedMethod.Resolve(ITypeResolveContext context)
 {
     return((IMethod)Resolve(context));
 }
Esempio n. 48
0
 IProperty IUnresolvedProperty.Resolve(ITypeResolveContext context)
 {
     return((IProperty)Resolve(context));
 }
Esempio n. 49
0
 public Expression ResolveConstant(ITypeResolveContext context)
 {
     return(new ErrorExpression(type.Resolve(context)));
 }
Esempio n. 50
0
 public static IList <IAttribute> CreateResolvedAttributes(this IList <IUnresolvedAttribute> attributes, ITypeResolveContext context)
 {
     if (attributes == null)
     {
         throw new ArgumentNullException("attributes");
     }
     if (attributes.Count == 0)
     {
         return(EmptyList <IAttribute> .Instance);
     }
     else
     {
         return(new ProjectedList <ITypeResolveContext, IUnresolvedAttribute, IAttribute>(context, attributes, (c, a) => a.CreateResolvedAttribute(c)));
     }
 }
Esempio n. 51
0
 internal static ITypeReference Substitute(ITypeReference type, TypeVisitor substitution, ITypeResolveContext context)
 {
     if (substitution == null)
     {
         return(type);
     }
     if (context != null)
     {
         return(type.Resolve(context).AcceptVisitor(substitution));
     }
     else
     {
         return(SubstitutionTypeReference.Create(type, substitution));
     }
 }
Esempio n. 52
0
 public IType Resolve(ITypeResolveContext context)
 {
     return(new ArrayType(context.Compilation, elementType.Resolve(context), dimensions));
 }
Esempio n. 53
0
        internal SpecializedMember(IType declaringType, IMember memberDefinition, TypeVisitor substitution, ITypeResolveContext context)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }
            if (memberDefinition == null)
            {
                throw new ArgumentNullException("memberDefinition");
            }

            this.declaringType    = declaringType;
            this.memberDefinition = memberDefinition;
            this.returnType       = Substitute(memberDefinition.ReturnType, substitution, context);
        }
Esempio n. 54
0
 internal GenericContext(ITypeResolveContext context)
 {
     this.ClassTypeParameters  = context.CurrentTypeDefinition?.TypeParameters;
     this.MethodTypeParameters = (context.CurrentMember as IMethod)?.TypeParameters;
 }
Esempio n. 55
0
 internal CSharpAssembly(ICompilation compilation, CSharpProjectContent projectContent)
 {
     this.compilation    = compilation;
     this.projectContent = projectContent;
     this.context        = new SimpleTypeResolveContext(this);
 }
 IAttribute IUnresolvedAttribute.CreateResolvedAttribute(ITypeResolveContext context)
 {
     return(secDecl.Resolve(context.CurrentAssembly)[index]);
 }
Esempio n. 57
0
 public bool?IsReferenceType(ITypeResolveContext context)
 {
     return(genericType.IsReferenceType(context));
 }
Esempio n. 58
0
        public IEnumerable <IType> GetBaseTypes(ITypeResolveContext context)
        {
            Substitution substitution = new Substitution(typeArguments);

            return(genericType.GetBaseTypes(context).Select(t => t.AcceptVisitor(substitution)));
        }
 public IType Resolve(ITypeResolveContext context)
 {
     return(context.Compilation.FindType(knownTypeCode));
 }
Esempio n. 60
0
        // There is intentionally no Resolve() overload for IList<IMemberReference>: the resulting IList<Member> would
        // contains nulls when there are resolve errors.

        public static IList <ResolveResult> Resolve(this IList <IConstantValue> constantValues, ITypeResolveContext context)
        {
            if (constantValues == null)
            {
                throw new ArgumentNullException("constantValues");
            }
            if (constantValues.Count == 0)
            {
                return(EmptyList <ResolveResult> .Instance);
            }
            else
            {
                return(new ProjectedList <ITypeResolveContext, IConstantValue, ResolveResult>(context, constantValues, (c, t) => t.Resolve(c)));
            }
        }