示例#1
0
        protected void ResolveReferences(DeclarationFinder finder, QualifiedModuleName module, IParseTree tree, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            Logger.Debug("Resolving identifier references in '{0}'... (thread {1})", module.Name, Thread.CurrentThread.ManagedThreadId);

            var resolver = new IdentifierReferenceResolver(module, finder);
            var listener = new IdentifierReferenceListener(resolver);

            if (!string.IsNullOrWhiteSpace(tree.GetText().Trim()))
            {
                var walker = new ParseTreeWalker();
                try
                {
                    var watch = Stopwatch.StartNew();
                    walker.Walk(listener, tree);
                    watch.Stop();
                    Logger.Debug("Binding resolution done for component '{0}' in {1}ms (thread {2})", module.Name,
                                 watch.ElapsedMilliseconds, Thread.CurrentThread.ManagedThreadId);

                    //Evaluation of the overall status has to be defered to allow processing of undeclared variables before setting the ready state.
                    _parserStateManager.SetModuleState(module, ParserState.Ready, token, false);
                }
                catch (OperationCanceledException)
                {
                    throw;  //We do not want to set an error state if the exception was just caused by some cancellation.
                }
                catch (Exception exception)
                {
                    Logger.Error(exception, "Exception thrown resolving '{0}' (thread {1}).", module.Name, Thread.CurrentThread.ManagedThreadId);
                    _parserStateManager.SetModuleState(module, ParserState.ResolverError, token);
                }
            }
        }
        protected void ResolveDeclarations(QualifiedModuleName module, IParseTree tree, CancellationToken token)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                var projectDeclaration = GetOrCreateProjectDeclaration(module);

                Logger.Debug("Creating declarations for module {0}.", module.Name);

                var declarationsListener = new DeclarationSymbolsListener(_state, module, _state.GetModuleAnnotations(module), _state.GetModuleAttributes(module), projectDeclaration);
                ParseTreeWalker.Default.Walk(declarationsListener, tree);
                foreach (var createdDeclaration in declarationsListener.CreatedDeclarations)
                {
                    _state.AddDeclaration(createdDeclaration);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, "Exception thrown acquiring declarations for '{0}' (thread {1}).", module.Name, Thread.CurrentThread.ManagedThreadId);
                _parserStateManager.SetModuleState(module, ParserState.ResolverError, token);
            }
            stopwatch.Stop();
            Logger.Debug("{0}ms to resolve declarations for component {1}", stopwatch.ElapsedMilliseconds, module.Name);
        }
示例#3
0
        protected void ResolveDeclarations(QualifiedModuleName module, IParseTree tree, IDictionary <string, ProjectDeclaration> projects, CancellationToken token)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                if (!projects.TryGetValue(module.ProjectId, out var projectDeclaration))
                {
                    Logger.Error($"Tried to add module {module} with projectId {module.ProjectId} for which no project declaration exists.");
                }
                Logger.Debug($"Creating declarations for module {module.Name}.");

                var annotations = _state.GetModuleAnnotations(module).ToList();
                var attributes  = _state.GetModuleAttributes(module);
                var membersAllowingAttributes = _state.GetMembersAllowingAttributes(module);

                var moduleDeclaration = NewModuleDeclaration(module, tree, annotations, attributes, projectDeclaration);
                _state.AddDeclaration(moduleDeclaration);

                var controlDeclarations = DeclarationsFromControls(moduleDeclaration);
                foreach (var declaration in controlDeclarations)
                {
                    _state.AddDeclaration(declaration);
                }

                var declarationsListener = new DeclarationSymbolsListener(moduleDeclaration, annotations, attributes, membersAllowingAttributes);
                ParseTreeWalker.Default.Walk(declarationsListener, tree);
                foreach (var createdDeclaration in declarationsListener.CreatedDeclarations)
                {
                    _state.AddDeclaration(createdDeclaration);
                }

                //This is a hack to deal with annotations on module level variables.
                var memberAnnotations = declarationsListener.CreatedDeclarations
                                        .SelectMany(declaration => declaration.Annotations)
                                        .ToHashSet();
                moduleDeclaration.RemoveAnnotations(memberAnnotations);
            }
            catch (Exception exception)
            {
                Logger.Error(exception, $"Exception thrown acquiring declarations for '{module.Name}' (thread {Thread.CurrentThread.ManagedThreadId}).");
                _parserStateManager.SetModuleState(module, ParserState.ResolverError, token);
            }
            stopwatch.Stop();
            Logger.Debug($"{stopwatch.ElapsedMilliseconds}ms to resolve declarations for component {module.Name}");
        }