Пример #1
0
        void ResolveButtonClick(object sender, EventArgs e)
        {
            SimpleProjectContent     project        = new SimpleProjectContent();
            TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(project, "dummy.cs");

            compilationUnit.AcceptVisitor(convertVisitor, null);
            project.UpdateProjectContent(null, convertVisitor.ParsedFile.TopLevelTypeDefinitions, null, null);

            List <ITypeResolveContext> projects = new List <ITypeResolveContext>();

            projects.Add(project);
            projects.AddRange(builtInLibs.Value);

            using (var context = new CompositeTypeResolveContext(projects).Synchronize()) {
                CSharpResolver resolver = new CSharpResolver(context);

                IResolveVisitorNavigator navigator = null;
                if (csharpTreeView.SelectedNode != null)
                {
                    navigator = new NodeListResolveVisitorNavigator(new[] { (AstNode)csharpTreeView.SelectedNode.Tag });
                }
                ResolveVisitor visitor = new ResolveVisitor(resolver, convertVisitor.ParsedFile, navigator);
                visitor.Scan(compilationUnit);
                csharpTreeView.BeginUpdate();
                ShowResolveResultsInTree(csharpTreeView.Nodes, visitor);
                csharpTreeView.EndUpdate();
            }
        }
Пример #2
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);
                }
            }
        }
 void VisitVisibleNodes(AstNode node, IResolveVisitorNavigator currentNavigator, AlAstResolver resolver, int start, int end)
 {
     if (!AlAstResolver.IsUnresolvableNode(node))
     {
         currentNavigator.Resolved(node, resolver.Resolve(node));
     }
     for (var child = node.FirstChild; child != null; child = child.NextSibling)
     {
         if (child.StartLocation.Line <= end && child.EndLocation.Line >= start)
         {
             VisitVisibleNodes(child, currentNavigator, resolver, start, end);
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Applies a resolver navigator. This will resolve the nodes requested by the navigator, and will inform the
 /// navigator of the results.
 /// This method must be called as the first operation on the CSharpAstResolver, it is invalid to apply a navigator
 /// after a portion of the file was already resolved.
 /// </summary>
 public void ApplyNavigator(IResolveVisitorNavigator navigator, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (navigator == null)
     {
         throw new ArgumentNullException("navigator");
     }
     if (resolveVisitor != null)
     {
         throw new InvalidOperationException("Applying a navigator is only valid as the first operation on the CSharpAstResolver.");
     }
     resolveVisitor = new ResolveVisitor(initialResolverState, parsedFile, navigator);
     lock (resolveVisitor)
         resolveVisitor.Scan(rootNode);
 }
        void FindCurrentReferences(int start, int end)
        {
            ICompilation           compilation = SD.ParserService.GetCompilationForFile(editor.FileName);
            AlFullParseInformation parseInfo   = SD.ParserService.GetCachedParseInformation(editor.FileName) as AlFullParseInformation;

            if (currentSymbolReference == null || parseInfo == null)
            {
                return;
            }

            IResolveVisitorNavigator currentNavigator = InitNavigator(compilation);
            AlAstResolver            resolver         = parseInfo.GetResolver(compilation);

            if (currentNavigator == null || resolver == null)
            {
                return;
            }

            VisitVisibleNodes(parseInfo.SyntaxTree, currentNavigator, resolver, start, end);
        }
Пример #6
0
        /// <summary>
        /// Applies a resolver navigator. This will resolve the nodes requested by the navigator, and will inform the
        /// navigator of the results.
        /// This method must be called as the first operation on the CSharpAstResolver, it is invalid to apply a navigator
        /// after a portion of the file was already resolved.
        /// </summary>
        public void ApplyNavigator(IResolveVisitorNavigator navigator, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (navigator == null)
            {
                throw new ArgumentNullException("navigator");
            }

            if (resolverInitialized)
            {
                throw new InvalidOperationException("Applying a navigator is only valid as the first operation on the CSharpAstResolver.");
            }

            resolverInitialized = true;
            resolveVisitor.cancellationToken = cancellationToken;
            resolveVisitor.SetNavigator(navigator);
            try {
                resolveVisitor.Scan(rootNode);
            } finally {
                resolveVisitor.SetNavigator(null);
                resolveVisitor.cancellationToken = CancellationToken.None;
            }
        }
        IResolveVisitorNavigator InitNavigator(ICompilation compilation)
        {
            if (currentSymbolReference == null || compilation == null)
            {
                return(null);
            }
            var            symbol         = currentSymbolReference.Resolve(compilation.TypeResolveContext);
            FindReferences findReferences = new FindReferences();

            if (symbol == null)
            {
                return(null);
            }
            var searchScopes = findReferences.GetSearchScopes(symbol);

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

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

            if (searchScopes.Count == 1)
            {
                combinedNavigator = navigators[0];
            }
            else
            {
                combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
            }
            return(combinedNavigator);
        }
Пример #8
0
		/// <summary>
		/// Applies a resolver navigator. This will resolve the nodes requested by the navigator, and will inform the
		/// navigator of the results.
		/// This method must be called as the first operation on the CSharpAstResolver, it is invalid to apply a navigator
		/// after a portion of the file was already resolved.
		/// </summary>
		public void ApplyNavigator(IResolveVisitorNavigator navigator, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (navigator == null)
				throw new ArgumentNullException("navigator");
			
			lock (resolveVisitor) {
				if (resolverInitialized)
					throw new InvalidOperationException("Applying a navigator is only valid as the first operation on the CSharpAstResolver.");
				
				resolverInitialized = true;
				resolveVisitor.cancellationToken = cancellationToken;
				resolveVisitor.SetNavigator(navigator);
				try {
					resolveVisitor.Scan(rootNode);
				} finally {
					resolveVisitor.SetNavigator(null);
					resolveVisitor.cancellationToken = CancellationToken.None;
				}
			}
		}
 public ConstantModeResolveVisitorNavigator(ResolveVisitorNavigationMode mode, IResolveVisitorNavigator targetForResolveCalls)
 {
     this.mode = mode;
     this.targetForResolveCalls = targetForResolveCalls;
 }
Пример #10
0
        /// <summary>
        /// Finds all references in the given file.
        /// </summary>
        /// <param name="searchScopes">The search scopes for which to look.</param>
        /// <param name="unresolvedFile">The type system representation of the file being searched.</param>
        /// <param name="syntaxTree">The syntax tree 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, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree,
		                                 ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken)
        {
            if (searchScopes == null)
                throw new ArgumentNullException("searchScopes");
            if (syntaxTree == null)
                throw new ArgumentNullException("syntaxTree");
            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, syntaxTree);
            cancellationToken.ThrowIfCancellationRequested();
            CSharpAstResolver resolver = new CSharpAstResolver(compilation, syntaxTree, unresolvedFile);
            resolver.ApplyNavigator(combinedNavigator, cancellationToken);
            foreach (var n in navigators) {
                var frn = n as FindReferenceNavigator;
                if (frn != null)
                    frn.NavigatorDone(resolver, cancellationToken);
            }
        }
Пример #11
0
			public ConstantModeResolveVisitorNavigator(ResolveVisitorNavigationMode mode, IResolveVisitorNavigator targetForResolveCalls)
			{
				this.mode = mode;
				this.targetForResolveCalls = targetForResolveCalls;
			}
Пример #12
0
		/// <summary>
		/// Applies a resolver navigator. This will resolve the nodes requested by the navigator, and will inform the
		/// navigator of the results.
		/// This method must be called as the first operation on the CSharpAstResolver, it is invalid to apply a navigator
		/// after a portion of the file was already resolved.
		/// </summary>
		public void ApplyNavigator(IResolveVisitorNavigator navigator, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (navigator == null)
				throw new ArgumentNullException("navigator");
			if (resolveVisitor != null)
				throw new InvalidOperationException("Applying a navigator is only valid as the first operation on the CSharpAstResolver.");
			resolveVisitor = new ResolveVisitor(initialResolverState, parsedFile, navigator);
			lock (resolveVisitor)
				resolveVisitor.Scan(rootNode);
		}
		public DetectSkippableNodesNavigator(IResolveVisitorNavigator navigator, AstNode root)
		{
			this.navigator = navigator;
			Init(root);
		}
		IResolveVisitorNavigator InitNavigator(ICompilation compilation)
		{
			if (currentSymbolReference == null || compilation == null)
				return null;
			var symbol = currentSymbolReference.Resolve(compilation.TypeResolveContext);
			FindReferences findReferences = new FindReferences();
			if (symbol == null) return null;
			var searchScopes = findReferences.GetSearchScopes(symbol);
			if (searchScopes.Count == 0)
				return null;
			var navigators = new IResolveVisitorNavigator[searchScopes.Count];
			for (int i = 0; i < navigators.Length; i++) {
				navigators[i] = searchScopes[i].GetNavigator(compilation, ColorizeMatch);
			}
			IResolveVisitorNavigator combinedNavigator;
			if (searchScopes.Count == 1) {
				combinedNavigator = navigators[0];
			}
			else {
				combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
			}
			return combinedNavigator;
		}
		void VisitVisibleNodes(AstNode node, IResolveVisitorNavigator currentNavigator, CSharpAstResolver resolver, int start, int end)
		{
			if (!CSharpAstResolver.IsUnresolvableNode(node))
				currentNavigator.Resolved(node, resolver.Resolve(node, caretMovementTokenSource.Token));
			for (var child = node.FirstChild; child != null; child = child.NextSibling) {
				if (child.StartLocation.Line <= end && child.EndLocation.Line >= start)
					VisitVisibleNodes(child, currentNavigator, resolver, start, end);
			}
		}
Пример #16
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, CSharpParsedFile 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;
			IResolveVisitorNavigator navigator;
			if (searchScopes.Count == 1) {
				navigator = searchScopes[0].GetNavigator(compilation, callback);
			} else {
				IResolveVisitorNavigator[] navigators = new IResolveVisitorNavigator[searchScopes.Count];
				for (int i = 0; i < navigators.Length; i++) {
					navigators[i] = searchScopes[i].GetNavigator(compilation, callback);
				}
				navigator = new CompositeResolveVisitorNavigator(navigators);
			}
			
			cancellationToken.ThrowIfCancellationRequested();
			navigator = new DetectSkippableNodesNavigator(navigator, compilationUnit);
			cancellationToken.ThrowIfCancellationRequested();
			CSharpAstResolver resolver = new CSharpAstResolver(compilation, compilationUnit, parsedFile);
			resolver.ApplyNavigator(navigator, cancellationToken);
		}
Пример #17
0
 public DetectSkippableNodesNavigator(IResolveVisitorNavigator navigator, AstNode root)
 {
     this.navigator = navigator;
     Init(root);
 }