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 CppTypeResolveContext;

            if (ctx == null)
            {
                ctx = new CppTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
            }
            return(ResolveType(new CppResolver(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.
        }
 public ResolvedUsingScope(CppTypeResolveContext context, UsingScope usingScope)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (usingScope == null)
     {
         throw new ArgumentNullException("usingScope");
     }
     this.parentContext = context;
     this.usingScope    = usingScope;
     if (usingScope.Parent != null)
     {
         if (context.CurrentUsingScope == null)
         {
             throw new InvalidOperationException();
         }
     }
     else
     {
         if (context.CurrentUsingScope != null)
         {
             throw new InvalidOperationException();
         }
     }
 }
示例#3
0
        public CppTypeResolveContext GetTypeResolveContext(ICompilation compilation, TextLocation loc)
        {
            var rctx = new CppTypeResolveContext(compilation.MainAssembly);

            rctx = rctx.WithUsingScope(GetUsingScope(loc).Resolve(compilation));
            var curDef = GetInnermostTypeDefinition(loc);

            if (curDef != null)
            {
                var resolvedDef = curDef.Resolve(rctx).GetDefinition();
                if (resolvedDef == null)
                {
                    return(rctx);
                }
                rctx = rctx.WithCurrentTypeDefinition(resolvedDef);

                var curMember = resolvedDef.Members.FirstOrDefault(m => m.Region.FileName == FileName && m.Region.Begin <= loc && loc < m.BodyRegion.End);
                if (curMember != null)
                {
                    rctx = rctx.WithCurrentMember(curMember);
                }
            }

            return(rctx);
        }
		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 CppTypeResolveContext;
			if (ctx == null) {
				ctx = new CppTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
			}
			return ResolveType(new CppResolver(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.
		}
示例#5
0
			public CSharpResolvedAttribute(CppTypeResolveContext context, CppAttribute unresolved)
			{
				this.context = context;
				this.unresolved = unresolved;
				// Pretty much any access to the attribute checks the type first, so
				// we don't need to use lazy-loading for that.
				this.attributeType = unresolved.AttributeType.Resolve(context);
			}
示例#6
0
		public CppResolver(ICompilation compilation)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			this.compilation = compilation;
			this.conversions = Conversions.Get(compilation);
			this.context = new CppTypeResolveContext(compilation.MainAssembly);
		}
示例#7
0
 public CSharpResolvedAttribute(CppTypeResolveContext context, CppAttribute unresolved)
 {
     this.context    = context;
     this.unresolved = unresolved;
     // Pretty much any access to the attribute checks the type first, so
     // we don't need to use lazy-loading for that.
     this.attributeType = unresolved.AttributeType.Resolve(context);
 }
		public CppParameterCompletionEngine (IDocument document, IParameterCompletionDataFactory factory, IProjectContent content, CppTypeResolveContext ctx, CompilationUnit unit, CppParsedFile parsedFile) : base (content, ctx, unit, parsedFile)
		{
			if (document == null)
				throw new ArgumentNullException ("document");
			if (factory == null)
				throw new ArgumentNullException ("factory");
			this.document = document;
			this.factory = factory;
		}
示例#9
0
		public CppResolver(CppTypeResolveContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.compilation = context.Compilation;
			this.conversions = Conversions.Get(compilation);
			this.context = context;
			if (context.CurrentTypeDefinition != null)
				currentTypeDefinitionCache = new TypeDefinitionCache(context.CurrentTypeDefinition);
		}
示例#10
0
		private CppResolver(ICompilation compilation, Conversions conversions, CppTypeResolveContext context, bool checkForOverflow, bool isWithinLambdaExpression, TypeDefinitionCache currentTypeDefinitionCache, ImmutableStack<IVariable> localVariableStack, ObjectInitializerContext objectInitializerStack)
		{
			this.compilation = compilation;
			this.conversions = conversions;
			this.context = context;
			this.checkForOverflow = checkForOverflow;
			this.isWithinLambdaExpression = isWithinLambdaExpression;
			this.currentTypeDefinitionCache = currentTypeDefinitionCache;
			this.localVariableStack = localVariableStack;
			this.objectInitializerStack = objectInitializerStack;
		}
示例#11
0
        /// <summary>
        /// Resolves the namespace represented by this using scope.
        /// </summary>
        public ResolvedUsingScope Resolve(ICompilation compilation)
        {
            CacheManager       cache    = compilation.CacheManager;
            ResolvedUsingScope resolved = (ResolvedUsingScope)cache.GetShared(this);

            if (resolved == null)
            {
                var csContext = new CppTypeResolveContext(compilation.MainAssembly, parent != null ? parent.Resolve(compilation) : null);
                resolved = (ResolvedUsingScope)cache.GetOrAddShared(this, new ResolvedUsingScope(csContext, this));
            }
            return(resolved);
        }
示例#12
0
		public CppCompletionEngine (IDocument document, ICompletionDataFactory factory, IProjectContent content, CppTypeResolveContext ctx, CompilationUnit unit, CppParsedFile parsedFile) : base (content, ctx, unit, parsedFile)
		{
			if (document == null)
				throw new ArgumentNullException ("document");
			if (factory == null)
				throw new ArgumentNullException ("factory");
			this.document = document;
			this.factory = factory;
			// Set defaults for additional input properties
			this.FormattingPolicy = new CppFormattingOptions();
			this.EolMarker = Environment.NewLine;
			this.IndentString = "\t";
		}
示例#13
0
		public ResolvedUsingScope(CppTypeResolveContext context, UsingScope usingScope)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			if (usingScope == null)
				throw new ArgumentNullException("usingScope");
			this.parentContext = context;
			this.usingScope = usingScope;
			if (usingScope.Parent != null) {
				if (context.CurrentUsingScope == null)
					throw new InvalidOperationException();
			} else {
				if (context.CurrentUsingScope != null)
					throw new InvalidOperationException();
			}
		}
		protected CppCompletionEngineBase (IProjectContent content, CppTypeResolveContext ctx, CompilationUnit unit, CppParsedFile parsedFile)
		{
			if (content == null)
				throw new ArgumentNullException ("content");
			if (ctx == null)
				throw new ArgumentNullException ("ctx");
			if (unit == null)
				throw new ArgumentNullException ("unit");
			if (parsedFile == null)
				throw new ArgumentNullException ("parsedFile");
			
			this.ProjectContent = content;
			this.ctx = ctx;
			this.Unit = unit;
			this.CSharpParsedFile = parsedFile;
		}
示例#15
0
		IList<IAttribute> GetAttributes(ref IList<IAttribute> field, bool assemblyAttributes)
		{
			IList<IAttribute> result = field;
			if (result != null) {
				LazyInit.ReadBarrier();
				return result;
			} else {
				result = new List<IAttribute>();
				foreach (var parsedFile in projectContent.Files.OfType<CppParsedFile>()) {
					var attributes = assemblyAttributes ? parsedFile.AssemblyAttributes : parsedFile.ModuleAttributes;
					var context = new CppTypeResolveContext(this, parsedFile.RootUsingScope.Resolve(compilation));
					foreach (var unresolvedAttr in attributes) {
						result.Add(unresolvedAttr.CreateResolvedAttribute(context));
					}
				}
				return LazyInit.GetOrSet(ref field, result);
			}
		}
示例#16
0
        IList <IAttribute> GetAttributes(ref IList <IAttribute> field, bool assemblyAttributes)
        {
            IList <IAttribute> result = field;

            if (result != null)
            {
                LazyInit.ReadBarrier();
                return(result);
            }
            else
            {
                result = new List <IAttribute>();
                foreach (var parsedFile in projectContent.Files.OfType <CppParsedFile>())
                {
                    var attributes = assemblyAttributes ? parsedFile.AssemblyAttributes : parsedFile.ModuleAttributes;
                    var context    = new CppTypeResolveContext(this, parsedFile.RootUsingScope.Resolve(compilation));
                    foreach (var unresolvedAttr in attributes)
                    {
                        result.Add(unresolvedAttr.CreateResolvedAttribute(context));
                    }
                }
                return(LazyInit.GetOrSet(ref field, result));
            }
        }
示例#17
0
		CppResolver WithContext(CppTypeResolveContext newContext)
		{
			return new CppResolver(compilation, conversions, newContext, checkForOverflow, isWithinLambdaExpression, currentTypeDefinitionCache, localVariableStack, objectInitializerStack);
		}
示例#18
0
		internal static ReachabilityAnalysis Create(Statement statement, Func<AstNode, CancellationToken, ResolveResult> resolver, CppTypeResolveContext typeResolveContext, CancellationToken cancellationToken)
		{
			var cfgBuilder = new ControlFlowGraphBuilder();
			var cfg = cfgBuilder.BuildControlFlowGraph(statement, resolver, typeResolveContext, cancellationToken);
			return Create(cfg, cancellationToken);
		}
示例#19
0
		/// <summary>
		/// Resolves the namespace represented by this using scope.
		/// </summary>
		public ResolvedUsingScope Resolve(ICompilation compilation)
		{
			CacheManager cache = compilation.CacheManager;
			ResolvedUsingScope resolved = (ResolvedUsingScope)cache.GetShared(this);
			if (resolved == null) {
				var csContext = new CppTypeResolveContext(compilation.MainAssembly, parent != null ? parent.Resolve(compilation) : null);
				resolved = (ResolvedUsingScope)cache.GetOrAddShared(this, new ResolvedUsingScope(csContext, this));
			}
			return resolved;
		}