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}"); }
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), _state.GetMembersAllowingAttributes(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); }