public static ResolveResult Resolve(ICompilation compilation, CppParsedFile parsedFile, CompilationUnit cu, TextLocation location,
                                            CancellationToken cancellationToken = default(CancellationToken))
        {
            AstNode node;

            return(Resolve(compilation, parsedFile, cu, location, out node, cancellationToken));
        }
        protected Tuple <ResolveResult, CppResolver> ResolveExpression(CppParsedFile file, AstNode expr, CompilationUnit unit)
        {
            if (expr == null)
            {
                return(null);
            }
            AstNode resolveNode;

            if (expr is Expression || expr is AstType)
            {
                resolveNode = expr;
            }
            else if (expr is VariableDeclarationStatement)
            {
                resolveNode = ((VariableDeclarationStatement)expr).Type;
            }
            else
            {
                resolveNode = expr;
            }

//			var newContent = ProjectContent.UpdateProjectContent (CSharpParsedFile, file);

            var csResolver = new CppAstResolver(new CppResolver(ctx), unit, CSharpParsedFile);

            var result = csResolver.Resolve(resolveNode);
            var state  = csResolver.GetResolverStateBefore(resolveNode);

            return(Tuple.Create(result, state));
        }
Esempio n. 3
0
 /// <summary>
 /// Finds all references in the given file.
 /// </summary>
 /// <param name="searchScope">The search scope for which to look.</param>
 /// <param name="parsedFile">The type system representation of the file being searched.</param>
 /// <param name="compilationUnit">The compilation unit of the file being searched.</param>
 /// <param name="compilation">The compilation for the project that contains the file.</param>
 /// <param name="callback">Callback used to report the references that were found.</param>
 /// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
 public void FindReferencesInFile(IFindReferenceSearchScope searchScope, CppParsedFile parsedFile, CompilationUnit compilationUnit,
                                  ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
 {
     if (searchScope == null)
     {
         throw new ArgumentNullException("searchScope");
     }
     FindReferencesInFile(new[] { searchScope }, parsedFile, compilationUnit, compilation, callback, cancellationToken);
 }
		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;
		}
Esempio n. 5
0
		/// <summary>
		/// Creates a new C# AST resolver.
		/// Use this overload if you are resolving code snippets (not necessarily complete files).
		/// </summary>
		/// <param name="resolver">The resolver state at the root node (to be more precise: outside the root node).</param>
		/// <param name="rootNode">The root node of the resolved tree.</param>
		/// <param name="parsedFile">The parsed file for the nodes being resolved. This parameter is used only
		/// when the root node is on the type level; it is not necessary when an expression is passed.
		/// This parameter may be null.</param>
		public CppAstResolver(CppResolver resolver, AstNode rootNode, CppParsedFile parsedFile = null)
		{
			if (resolver == null)
				throw new ArgumentNullException("resolver");
			if (rootNode == null)
				throw new ArgumentNullException("rootNode");
			this.initialResolverState = resolver;
			this.rootNode = rootNode;
			this.parsedFile = parsedFile;
			this.resolveVisitor = new ResolveVisitor(initialResolverState, parsedFile);
		}
Esempio n. 6
0
		public static ResolveResult Resolve(ICompilation compilation, CppParsedFile parsedFile, CompilationUnit cu, TextLocation location, out AstNode node,
		                                    CancellationToken cancellationToken = default(CancellationToken))
		{
			node = cu.GetNodeAt(location);
			if (node == null)
				return null;
			if (CppAstResolver.IsUnresolvableNode(node)) {
				if (node is Identifier) {
					node = node.Parent;
				} else if (node.NodeType == NodeType.Token) {
					if (node.Parent is IndexerExpression || node.Parent is ConstructorInitializer) {
						// There's no other place where one could hover to see the indexer's tooltip,
						// so we need to resolve it when hovering over the '[' or ']'.
						// For constructor initializer, the same applies to the 'base'/'this' token.
						node = node.Parent;
					} else {
						return null;
					}
				} else {
					// don't resolve arbitrary nodes - we don't want to show tooltips for everything
					return null;
				}
			} else {
				// It's a resolvable node.
				// However, we usually don't want to show the tooltip everywhere
				// For example, hovering with the mouse over an empty line between two methods causes
				// node==TypeDeclaration, but we don't want to show any tooltip.
				
				if (!node.GetChildByRole(AstNode.Roles.Identifier).IsNull) {
					// We'll suppress the tooltip for resolvable nodes if there is an identifier that
					// could be hovered over instead:
					return null;
				}
			}
			if (node == null)
				return null;
			
			if (node.Parent is ObjectCreateExpression && node.Role == ObjectCreateExpression.Roles.Type) {
				node = node.Parent;
			}
			
			InvocationExpression parentInvocation = null;
			if (node is IdentifierExpression || node is MemberReferenceExpression || node is PointerReferenceExpression) {
				// we also need to resolve the invocation
				parentInvocation = node.Parent as InvocationExpression;
			}
			
			CppAstResolver resolver = new CppAstResolver(compilation, cu, parsedFile);
			ResolveResult rr = resolver.Resolve(node, cancellationToken);
			if (rr is MethodGroupResolveResult && parentInvocation != null)
				return resolver.Resolve(parentInvocation);
			else
				return rr;
		}
Esempio n. 7
0
        /// <summary>
        /// Finds all references of a given variable.
        /// </summary>
        /// <param name="variable">The variable for which to look.</param>
        /// <param name="parsedFile">The type system representation of the file being searched.</param>
        /// <param name="compilationUnit">The compilation unit of the file being searched.</param>
        /// <param name="compilation">The compilation.</param>
        /// <param name="callback">Callback used to report the references that were found.</param>
        /// <param name="cancellationToken">Cancellation token that may be used to cancel the operation.</param>
        public void FindLocalReferences(IVariable variable, CppParsedFile parsedFile, CompilationUnit compilationUnit,
                                        ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
        {
            if (variable == null)
            {
                throw new ArgumentNullException("variable");
            }
            var searchScope = new SearchScope(c => new FindLocalReferencesNavigator(variable));

            searchScope.declarationCompilation = compilation;
            FindReferencesInFile(searchScope, parsedFile, compilationUnit, compilation, callback, cancellationToken);
        }
Esempio n. 8
0
		/// <summary>
		/// Creates a new C# AST resolver.
		/// Use this overload if you are resolving within a complete C# file.
		/// </summary>
		/// <param name="compilation">The current compilation.</param>
		/// <param name="parsedFile">
		/// Result of the <see cref="TypeSystemConvertVisitor"/> for the file being passed. This is used for setting up the context on the resolver. The parsed file must be registered in the compilation.
		/// </param>
		/// <param name="compilationUnit">The compilation unit corresponding to the specified parsed file.</param>
		public CppAstResolver(ICompilation compilation, CompilationUnit compilationUnit, CppParsedFile parsedFile)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			if (parsedFile == null)
				throw new ArgumentNullException("parsedFile");
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			this.initialResolverState = new CppResolver(compilation);
			this.rootNode = compilationUnit;
			this.parsedFile = parsedFile;
			this.resolveVisitor = new ResolveVisitor(initialResolverState, parsedFile);
		}
Esempio n. 9
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";
		}
Esempio n. 10
0
 /// <summary>
 /// Creates a new C# AST resolver.
 /// Use this overload if you are resolving code snippets (not necessarily complete files).
 /// </summary>
 /// <param name="resolver">The resolver state at the root node (to be more precise: outside the root node).</param>
 /// <param name="rootNode">The root node of the resolved tree.</param>
 /// <param name="parsedFile">The parsed file for the nodes being resolved. This parameter is used only
 /// when the root node is on the type level; it is not necessary when an expression is passed.
 /// This parameter may be null.</param>
 public CppAstResolver(CppResolver resolver, AstNode rootNode, CppParsedFile parsedFile = null)
 {
     if (resolver == null)
     {
         throw new ArgumentNullException("resolver");
     }
     if (rootNode == null)
     {
         throw new ArgumentNullException("rootNode");
     }
     this.initialResolverState = resolver;
     this.rootNode             = rootNode;
     this.parsedFile           = parsedFile;
     this.resolveVisitor       = new ResolveVisitor(initialResolverState, parsedFile);
 }
Esempio n. 11
0
		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;
		}
Esempio n. 12
0
 /// <summary>
 /// Creates a new C# AST resolver.
 /// Use this overload if you are resolving within a complete C# file.
 /// </summary>
 /// <param name="compilation">The current compilation.</param>
 /// <param name="parsedFile">
 /// Result of the <see cref="TypeSystemConvertVisitor"/> for the file being passed. This is used for setting up the context on the resolver. The parsed file must be registered in the compilation.
 /// </param>
 /// <param name="compilationUnit">The compilation unit corresponding to the specified parsed file.</param>
 public CppAstResolver(ICompilation compilation, CompilationUnit compilationUnit, CppParsedFile parsedFile)
 {
     if (compilation == null)
     {
         throw new ArgumentNullException("compilation");
     }
     if (parsedFile == null)
     {
         throw new ArgumentNullException("parsedFile");
     }
     if (compilationUnit == null)
     {
         throw new ArgumentNullException("compilationUnit");
     }
     this.initialResolverState = new CppResolver(compilation);
     this.rootNode             = compilationUnit;
     this.parsedFile           = parsedFile;
     this.resolveVisitor       = new ResolveVisitor(initialResolverState, parsedFile);
 }
        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;
        }
Esempio n. 14
0
		/// <summary>
		/// Finds all references in the given file.
		/// </summary>
		/// <param name="searchScopes">The search scopes for which to look.</param>
		/// <param name="parsedFile">The type system representation of the file being searched.</param>
		/// <param name="compilationUnit">The compilation unit of the file being searched.</param>
		/// <param name="compilation">The compilation for the project that contains the file.</param>
		/// <param name="callback">Callback used to report the references that were found.</param>
		/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
		public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CppParsedFile parsedFile, CompilationUnit compilationUnit,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
		{
			if (searchScopes == null)
				throw new ArgumentNullException("searchScopes");
			if (parsedFile == null)
				throw new ArgumentNullException("parsedFile");
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			if (callback == null)
				throw new ArgumentNullException("callback");
			
			if (searchScopes.Count == 0)
				return;
			var navigators = new IResolveVisitorNavigator[searchScopes.Count];
			for (int i = 0; i < navigators.Length; i++) {
				navigators[i] = searchScopes[i].GetNavigator(compilation, callback);
			}
			IResolveVisitorNavigator combinedNavigator;
			if (searchScopes.Count == 1) {
				combinedNavigator = navigators[0];
			} else {
				combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
			}
			
			cancellationToken.ThrowIfCancellationRequested();
			combinedNavigator = new DetectSkippableNodesNavigator(combinedNavigator, compilationUnit);
			cancellationToken.ThrowIfCancellationRequested();
			CppAstResolver resolver = new CppAstResolver(compilation, compilationUnit, parsedFile);
			resolver.ApplyNavigator(combinedNavigator, cancellationToken);
			foreach (var n in navigators) {
				var frn = n as FindReferenceNavigator;
				if (frn != null)
					frn.NavigatorDone(resolver, cancellationToken);
			}
		}
Esempio n. 15
0
        public static ResolveResult Resolve(ICompilation compilation, CppParsedFile parsedFile, CompilationUnit cu, TextLocation location, out AstNode node,
                                            CancellationToken cancellationToken = default(CancellationToken))
        {
            node = cu.GetNodeAt(location);
            if (node == null)
            {
                return(null);
            }
            if (CppAstResolver.IsUnresolvableNode(node))
            {
                if (node is Identifier)
                {
                    node = node.Parent;
                }
                else if (node.NodeType == NodeType.Token)
                {
                    if (node.Parent is IndexerExpression || node.Parent is ConstructorInitializer)
                    {
                        // There's no other place where one could hover to see the indexer's tooltip,
                        // so we need to resolve it when hovering over the '[' or ']'.
                        // For constructor initializer, the same applies to the 'base'/'this' token.
                        node = node.Parent;
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    // don't resolve arbitrary nodes - we don't want to show tooltips for everything
                    return(null);
                }
            }
            else
            {
                // It's a resolvable node.
                // However, we usually don't want to show the tooltip everywhere
                // For example, hovering with the mouse over an empty line between two methods causes
                // node==TypeDeclaration, but we don't want to show any tooltip.

                if (!node.GetChildByRole(AstNode.Roles.Identifier).IsNull)
                {
                    // We'll suppress the tooltip for resolvable nodes if there is an identifier that
                    // could be hovered over instead:
                    return(null);
                }
            }
            if (node == null)
            {
                return(null);
            }

            if (node.Parent is ObjectCreateExpression && node.Role == ObjectCreateExpression.Roles.Type)
            {
                node = node.Parent;
            }

            InvocationExpression parentInvocation = null;

            if (node is IdentifierExpression || node is MemberReferenceExpression || node is PointerReferenceExpression)
            {
                // we also need to resolve the invocation
                parentInvocation = node.Parent as InvocationExpression;
            }

            CppAstResolver resolver = new CppAstResolver(compilation, cu, parsedFile);
            ResolveResult  rr       = resolver.Resolve(node, cancellationToken);

            if (rr is MethodGroupResolveResult && parentInvocation != null)
            {
                return(resolver.Resolve(parentInvocation));
            }
            else
            {
                return(rr);
            }
        }
Esempio n. 16
0
		public static ResolveResult Resolve(ICompilation compilation, CppParsedFile parsedFile, CompilationUnit cu, TextLocation location,
		                                    CancellationToken cancellationToken = default(CancellationToken))
		{
			AstNode node;
			return Resolve(compilation, parsedFile, cu, location, out node, cancellationToken);
		}
Esempio n. 17
0
        /// <summary>
        /// Finds all references in the given file.
        /// </summary>
        /// <param name="searchScopes">The search scopes for which to look.</param>
        /// <param name="parsedFile">The type system representation of the file being searched.</param>
        /// <param name="compilationUnit">The compilation unit of the file being searched.</param>
        /// <param name="compilation">The compilation for the project that contains the file.</param>
        /// <param name="callback">Callback used to report the references that were found.</param>
        /// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
        public void FindReferencesInFile(IList <IFindReferenceSearchScope> searchScopes, CppParsedFile parsedFile, CompilationUnit compilationUnit,
                                         ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
        {
            if (searchScopes == null)
            {
                throw new ArgumentNullException("searchScopes");
            }
            if (parsedFile == null)
            {
                throw new ArgumentNullException("parsedFile");
            }
            if (compilationUnit == null)
            {
                throw new ArgumentNullException("compilationUnit");
            }
            if (compilation == null)
            {
                throw new ArgumentNullException("compilation");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (searchScopes.Count == 0)
            {
                return;
            }
            var navigators = new IResolveVisitorNavigator[searchScopes.Count];

            for (int i = 0; i < navigators.Length; i++)
            {
                navigators[i] = searchScopes[i].GetNavigator(compilation, callback);
            }
            IResolveVisitorNavigator combinedNavigator;

            if (searchScopes.Count == 1)
            {
                combinedNavigator = navigators[0];
            }
            else
            {
                combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
            }

            cancellationToken.ThrowIfCancellationRequested();
            combinedNavigator = new DetectSkippableNodesNavigator(combinedNavigator, compilationUnit);
            cancellationToken.ThrowIfCancellationRequested();
            CppAstResolver resolver = new CppAstResolver(compilation, compilationUnit, parsedFile);

            resolver.ApplyNavigator(combinedNavigator, cancellationToken);
            foreach (var n in navigators)
            {
                var frn = n as FindReferenceNavigator;
                if (frn != null)
                {
                    frn.NavigatorDone(resolver, cancellationToken);
                }
            }
        }
Esempio n. 18
0
		protected Tuple<ResolveResult, CppResolver> ResolveExpression (CppParsedFile file, AstNode expr, CompilationUnit unit)
		{
			if (expr == null)
				return null;
			AstNode resolveNode;
			if (expr is Expression || expr is AstType) {
				resolveNode = expr;
			} else if (expr is VariableDeclarationStatement) {
				resolveNode = ((VariableDeclarationStatement)expr).Type;
			} else {
				resolveNode = expr;
			}
			
//			var newContent = ProjectContent.UpdateProjectContent (CSharpParsedFile, file);
			
			var csResolver = new CppAstResolver(new CppResolver (ctx), unit, CSharpParsedFile);
			
			var result = csResolver.Resolve (resolveNode);
			var state = csResolver.GetResolverStateBefore (resolveNode);
			return Tuple.Create (result, state);
		}
Esempio n. 19
0
		/// <summary>
		/// Finds all references in the given file.
		/// </summary>
		/// <param name="searchScope">The search scope for which to look.</param>
		/// <param name="parsedFile">The type system representation of the file being searched.</param>
		/// <param name="compilationUnit">The compilation unit of the file being searched.</param>
		/// <param name="compilation">The compilation for the project that contains the file.</param>
		/// <param name="callback">Callback used to report the references that were found.</param>
		/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
		public void FindReferencesInFile(IFindReferenceSearchScope searchScope, CppParsedFile parsedFile, CompilationUnit compilationUnit,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
		{
			if (searchScope == null)
				throw new ArgumentNullException("searchScope");
			FindReferencesInFile(new[] { searchScope }, parsedFile, compilationUnit, compilation, callback, cancellationToken);
		}
 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;
 }
Esempio n. 21
0
		/// <summary>
		/// Finds all references of a given variable.
		/// </summary>
		/// <param name="variable">The variable for which to look.</param>
		/// <param name="parsedFile">The type system representation of the file being searched.</param>
		/// <param name="compilationUnit">The compilation unit of the file being searched.</param>
		/// <param name="compilation">The compilation.</param>
		/// <param name="callback">Callback used to report the references that were found.</param>
		/// <param name="cancellationToken">Cancellation token that may be used to cancel the operation.</param>
		public void FindLocalReferences(IVariable variable, CppParsedFile parsedFile, CompilationUnit compilationUnit,
		                                ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
		{
			if (variable == null)
				throw new ArgumentNullException("variable");
			var searchScope = new SearchScope(c => new FindLocalReferencesNavigator(variable));
			searchScope.declarationCompilation = compilation;
			FindReferencesInFile(searchScope, parsedFile, compilationUnit, compilation, callback, cancellationToken);
		}