Exemple #1
0
        public static ParseCoordinator Create(IVBE vbe, RubberduckParserState state, IAttributeParser attributeParser, IModuleExporter exporter, string serializedDeclarationsPath = null)
        {
            var path = serializedDeclarationsPath ??
                       Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(MockParser)).Location), "TestFiles", "Resolver");
            Func <IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture));
            var projectManager = new SynchronousProjectManager(state, vbe);
            var moduleToModuleReferenceManager = new ModuleToModuleReferenceManager();
            var supertypeClearer   = new SynchronousSupertypeClearer(state);
            var parserStateManager = new SynchronousParserStateManager(state);
            var referenceRemover   = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager);
            var comSynchronizer    = new SynchronousCOMReferenceSynchronizer(
                state,
                parserStateManager,
                path);
            var builtInDeclarationLoader = new BuiltInDeclarationLoader(
                state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(state),
                new SpecialFormDeclarations(state),
                new FormEventDeclarations(state),
                new AliasDeclarations(state),
            });
            var parseRunner = new SynchronousParseRunner(
                state,
                parserStateManager,
                preprocessorFactory,
                attributeParser,
                exporter);
            var declarationResolveRunner = new SynchronousDeclarationResolveRunner(
                state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new SynchronousReferenceResolveRunner(
                state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner
                );
            var parsingCacheService = new ParsingCacheService(
                state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer
                );

            return(new ParseCoordinator(
                       state,
                       parsingStageService,
                       parsingCacheService,
                       projectManager,
                       parserStateManager,
                       true));
        }
Exemple #2
0
        public static ConfiguredParserResult CreateConfiguredParser(this IVBE vbe, string serializedDeclarationsPath = null)
        {
            var state = new RubberduckParserState(vbe, new ConcurrentlyConstructedDeclarationFinderFactory());

            var moduleToModuleReferenceManager = new ModuleToModuleReferenceManager();
            var parserStateManager             = new SynchronousParserStateManager(state);
            var referenceRemover = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager);
            var supertypeClearer = new SupertypeClearer(state);
            var comSynchronizer  = new SynchronousCOMReferenceSynchronizer(state, parserStateManager, @"C:\");

            var parseRunner = new SynchronousParseRunner(state,
                                                         parserStateManager,
                                                         () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture)),
                                                         new AttributeParser(),
                                                         new ModuleExporter());

            var declarationResolveRunner = new SynchronousDeclarationResolveRunner(state, parserStateManager, comSynchronizer);
            var referenceResolveRunner   = new SynchronousReferenceResolveRunner(state, parserStateManager, moduleToModuleReferenceManager, referenceRemover);

            var parsingCacheService = new ParsingCacheService(state, moduleToModuleReferenceManager, referenceRemover, supertypeClearer);

            var parsingStageService = new ParsingStageService(comSynchronizer,
                                                              new BuiltInDeclarationLoader(state,
                                                                                           new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(state),
                new SpecialFormDeclarations(state),
                new FormEventDeclarations(state),
                new AliasDeclarations(state)
            }),
                                                              parseRunner,
                                                              declarationResolveRunner,
                                                              referenceResolveRunner);

            IProjectManager projectManager = new SynchronousProjectManager(state, vbe);
            var             parser         = new ParseCoordinator(state, parsingStageService, parsingCacheService, projectManager, parserStateManager, true);

            return(new ConfiguredParserResult {
                ParseCoordinator = parser, ProjectManager = projectManager
            });
        }
Exemple #3
0
        public void Initialize(Microsoft.Vbe.Interop.VBE vbe)
        {
            if (_parser != null)
            {
                throw new InvalidOperationException("ParserState is already initialized.");
            }

            _vbe       = new VBE(vbe);
            _vbeEvents = VBEEvents.Initialize(_vbe);
            var declarationFinderFactory = new ConcurrentlyConstructedDeclarationFinderFactory();
            var projectRepository        = new ProjectsRepository(_vbe);

            _state = new RubberduckParserState(null, projectRepository, declarationFinderFactory, _vbeEvents);
            _state.StateChanged += _state_StateChanged;

            var exporter = new ModuleExporter();

            Func <IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(_vbe.Version, CultureInfo.InvariantCulture));

            _attributeParser = new AttributeParser(exporter, preprocessorFactory, _state.ProjectsProvider);
            var projectManager = new RepositoryProjectManager(projectRepository);
            var moduleToModuleReferenceManager = new ModuleToModuleReferenceManager();
            var parserStateManager             = new ParserStateManager(_state);
            var referenceRemover         = new ReferenceRemover(_state, moduleToModuleReferenceManager);
            var supertypeClearer         = new SupertypeClearer(_state);
            var comSynchronizer          = new COMReferenceSynchronizer(_state, parserStateManager);
            var builtInDeclarationLoader = new BuiltInDeclarationLoader(
                _state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(_state),
                new SpecialFormDeclarations(_state),
                new FormEventDeclarations(_state),
                new AliasDeclarations(_state),
                //new RubberduckApiDeclarations(_state)
            }
                );
            var parseRunner = new ParseRunner(
                _state,
                parserStateManager,
                preprocessorFactory,
                _attributeParser,
                exporter);
            var declarationResolveRunner = new DeclarationResolveRunner(
                _state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new ReferenceResolveRunner(
                _state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner
                );
            var parsingCacheService = new ParsingCacheService(
                _state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer
                );

            _parser = new ParseCoordinator(
                _state,
                parsingStageService,
                parsingCacheService,
                projectManager,
                parserStateManager
                );
        }
Exemple #4
0
        public static (SynchronousParseCoordinator parser, IRewritingManager rewritingManager) CreateWithRewriteManager(IVBE vbe, RubberduckParserState state, IProjectsRepository projectRepository, string serializedComProjectsPath = null)
        {
            var vbeVersion = double.Parse(vbe.Version, CultureInfo.InvariantCulture);
            var compilationArgumentsProvider = MockCompilationArgumentsProvider(vbeVersion);
            var compilationsArgumentsCache   = new CompilationArgumentsCache(compilationArgumentsProvider);

            var path = serializedComProjectsPath ??
                       Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(MockParser)).Location), "Testfiles", "Resolver");
            var preprocessorErrorListenerFactory = new PreprocessingParseErrorListenerFactory();
            var preprocessorParser              = new VBAPreprocessorParser(preprocessorErrorListenerFactory, preprocessorErrorListenerFactory);
            var preprocessor                    = new VBAPreprocessor(preprocessorParser, compilationsArgumentsCache);
            var mainParseErrorListenerFactory   = new MainParseErrorListenerFactory();
            var mainTokenStreamParser           = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory);
            var tokenStreamProvider             = new SimpleVBAModuleTokenStreamProvider();
            var stringParser                    = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor);
            var projectManager                  = new RepositoryProjectManager(projectRepository);
            var moduleToModuleReferenceManager  = new ModuleToModuleReferenceManager();
            var supertypeClearer                = new SynchronousSupertypeClearer(state);
            var parserStateManager              = new SynchronousParserStateManager(state);
            var referenceRemover                = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager);
            var baseComDeserializer             = new XmlComProjectSerializer(path);
            var comDeserializer                 = new StaticCachingComDeserializerDecorator(baseComDeserializer);
            var referencedDeclarationsCollector = new SerializedReferencedDeclarationsCollector(comDeserializer);
            var comSynchronizer                 = new SynchronousCOMReferenceSynchronizer(
                state,
                parserStateManager,
                projectRepository,
                referencedDeclarationsCollector);
            var builtInDeclarationLoader = new BuiltInDeclarationLoader(
                state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(state),
                new SpecialFormDeclarations(state),
                new FormEventDeclarations(state),
                new AliasDeclarations(state),
            });
            var codePaneSourceCodeHandler = new CodePaneSourceCodeHandler(projectRepository);
            //We use the same handler because to achieve consistency between the return values.
            var attributesSourceCodeHandler = codePaneSourceCodeHandler;
            var moduleParser = new ModuleParser(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler,
                stringParser);
            var parseRunner = new SynchronousParseRunner(
                state,
                parserStateManager,
                moduleParser);
            var declarationResolveRunner = new SynchronousDeclarationResolveRunner(
                state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new SynchronousReferenceResolveRunner(
                state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner
                );
            var parsingCacheService = new ParsingCacheService(
                state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer,
                compilationsArgumentsCache
                );
            var tokenStreamCache      = new StateTokenStreamCache(state);
            var moduleRewriterFactory = new ModuleRewriterFactory(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler);
            var rewriterProvider      = new RewriterProvider(tokenStreamCache, moduleRewriterFactory);
            var rewriteSessionFactory = new RewriteSessionFactory(state, rewriterProvider);
            var rewritingManager      = new RewritingManager(rewriteSessionFactory);

            var parser = new SynchronousParseCoordinator(
                state,
                parsingStageService,
                parsingCacheService,
                projectManager,
                parserStateManager,
                rewritingManager);

            return(parser, rewritingManager);
        }
        public static (SynchronousParseCoordinator parser, IRewritingManager rewritingManager) CreateWithRewriteManager(IVBE vbe, RubberduckParserState state, IProjectsRepository projectRepository, string serializedComProjectsPath = null, IDictionary <string, IEnumerable <string> > documentModuleSupertypeNames = null)
        {
            var vbeVersion = double.Parse(vbe.Version, CultureInfo.InvariantCulture);
            var compilationArgumentsProvider      = MockCompilationArgumentsProvider(vbeVersion);
            var compilationsArgumentsCache        = new CompilationArgumentsCache(compilationArgumentsProvider);
            var userComProjectsRepository         = MockUserComProjectRepository();
            var documentSuperTypesProvider        = MockDocumentSuperTypeNamesProvider(documentModuleSupertypeNames);
            var ignoredProjectsSettingsProvider   = MockIgnoredProjectsSettingsProviderMock();
            var projectsToBeLoadedFromComSelector = new ProjectsToResolveFromComProjectsSelector(projectRepository, ignoredProjectsSettingsProvider);

            var path = serializedComProjectsPath ??
                       Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(MockParser)).Location), "Testfiles", "Resolver");
            var preprocessorErrorListenerFactory = new PreprocessingParseErrorListenerFactory();
            var preprocessorParser               = new VBAPreprocessorParser(preprocessorErrorListenerFactory, preprocessorErrorListenerFactory);
            var preprocessor                     = new VBAPreprocessor(preprocessorParser, compilationsArgumentsCache);
            var mainParseErrorListenerFactory    = new MainParseErrorListenerFactory();
            var mainTokenStreamParser            = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory);
            var tokenStreamProvider              = new SimpleVBAModuleTokenStreamProvider();
            var stringParser                     = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor);
            var vbaParserAnnotationFactory       = new VBAParserAnnotationFactory(WellKnownAnnotations());
            var projectManager                   = new RepositoryProjectManager(projectRepository);
            var moduleToModuleReferenceManager   = new ModuleToModuleReferenceManager();
            var supertypeClearer                 = new SynchronousSupertypeClearer(state);
            var parserStateManager               = new SynchronousParserStateManager(state);
            var referenceRemover                 = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager);
            var baseComDeserializer              = new XmlComProjectSerializer(new MockFileSystem(), path);
            var comDeserializer                  = new StaticCachingComDeserializerDecorator(baseComDeserializer);
            var declarationsFromComProjectLoader = new DeclarationsFromComProjectLoader();
            var referencedDeclarationsCollector  = new SerializedReferencedDeclarationsCollector(declarationsFromComProjectLoader, comDeserializer);
            var userComProjectSynchronizer       = new UserComProjectSynchronizer(state, declarationsFromComProjectLoader, userComProjectsRepository, projectsToBeLoadedFromComSelector);
            var comSynchronizer                  = new SynchronousCOMReferenceSynchronizer(
                state,
                parserStateManager,
                projectRepository,
                referencedDeclarationsCollector);
            var builtInDeclarationLoader = new BuiltInDeclarationLoader(
                state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(state),
                new SpecialFormDeclarations(state),
                new FormEventDeclarations(state),
                new AliasDeclarations(state),
            });
            var codePaneComponentSourceCodeHandler = new CodeModuleComponentSourceCodeHandler();
            var codePaneSourceCodeHandler          = new ComponentSourceCodeHandlerSourceCodeHandlerAdapter(codePaneComponentSourceCodeHandler, projectRepository);
            //We use the same handler because to achieve consistency between the return values.
            var attributesSourceCodeHandler = codePaneSourceCodeHandler;
            var moduleParser = new ModuleParser(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler,
                stringParser,
                vbaParserAnnotationFactory);
            var parseRunner = new SynchronousParseRunner(
                state,
                parserStateManager,
                moduleParser);
            var declarationResolveRunner = new SynchronousDeclarationResolveRunner(
                state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new SynchronousReferenceResolveRunner(
                state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover,
                documentSuperTypesProvider);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner,
                userComProjectSynchronizer
                );
            var parsingCacheService = new ParsingCacheService(
                state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer,
                compilationsArgumentsCache,
                userComProjectsRepository,
                projectsToBeLoadedFromComSelector
                );
            var tokenStreamCache      = new StateTokenStreamCache(state);
            var moduleRewriterFactory = new ModuleRewriterFactory(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler);
            var rewriterProvider              = new RewriterProvider(tokenStreamCache, moduleRewriterFactory);
            var selectionService              = new SelectionService(vbe, projectRepository);
            var selectionRecoverer            = new SelectionRecoverer(selectionService, state);
            var rewriteSessionFactory         = new RewriteSessionFactory(state, rewriterProvider, selectionRecoverer);
            var stubMembersAttributeRecoverer = new Mock <IMemberAttributeRecovererWithSettableRewritingManager>().Object;
            var rewritingManager              = new RewritingManager(rewriteSessionFactory, stubMembersAttributeRecoverer);

            var parser = new SynchronousParseCoordinator(
                state,
                parsingStageService,
                parsingCacheService,
                projectManager,
                parserStateManager,
                rewritingManager);

            return(parser, rewritingManager);
        }
Exemple #6
0
        // vbe is the com coclass interface from the interop assembly.
        // There is no shared interface between VBA and VB6 types, hence object.
        internal Parser(object vbe) : this()
        {
            if (_parser != null)
            {
                throw new InvalidOperationException("ParserState is already initialized.");
            }

            _vbe       = RootComWrapperFactory.GetVbeWrapper(vbe);
            _vbeEvents = VBEEvents.Initialize(_vbe);
            var declarationFinderFactory = new ConcurrentlyConstructedDeclarationFinderFactory();
            var projectRepository        = new ProjectsRepository(_vbe);

            _state = new RubberduckParserState(_vbe, projectRepository, declarationFinderFactory, _vbeEvents);
            _state.StateChanged += _state_StateChanged;
            var vbeVersion = double.Parse(_vbe.Version, CultureInfo.InvariantCulture);
            var predefinedCompilationConstants = new VBAPredefinedCompilationConstants(vbeVersion);
            var typeLibProvider = new TypeLibWrapperProvider(projectRepository);
            var compilationArgumentsProvider     = new CompilationArgumentsProvider(typeLibProvider, _dispatcher, predefinedCompilationConstants);
            var compilationsArgumentsCache       = new CompilationArgumentsCache(compilationArgumentsProvider);
            var preprocessorErrorListenerFactory = new PreprocessingParseErrorListenerFactory();
            var preprocessorParser              = new VBAPreprocessorParser(preprocessorErrorListenerFactory, preprocessorErrorListenerFactory);
            var preprocessor                    = new VBAPreprocessor(preprocessorParser, compilationsArgumentsCache);
            var mainParseErrorListenerFactory   = new MainParseErrorListenerFactory();
            var mainTokenStreamParser           = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory);
            var tokenStreamProvider             = new SimpleVBAModuleTokenStreamProvider();
            var stringParser                    = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor);
            var projectManager                  = new RepositoryProjectManager(projectRepository);
            var moduleToModuleReferenceManager  = new ModuleToModuleReferenceManager();
            var parserStateManager              = new ParserStateManager(_state);
            var referenceRemover                = new ReferenceRemover(_state, moduleToModuleReferenceManager);
            var supertypeClearer                = new SupertypeClearer(_state);
            var comLibraryProvider              = new ComLibraryProvider();
            var referencedDeclarationsCollector = new LibraryReferencedDeclarationsCollector(comLibraryProvider);
            var comSynchronizer                 = new COMReferenceSynchronizer(_state, parserStateManager, projectRepository, referencedDeclarationsCollector);
            var builtInDeclarationLoader        = new BuiltInDeclarationLoader(
                _state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(_state),
                new SpecialFormDeclarations(_state),
                new FormEventDeclarations(_state),
                new AliasDeclarations(_state),
                //new RubberduckApiDeclarations(_state)
            }
                );
            var codePaneSourceCodeHandler   = new CodePaneSourceCodeHandler(projectRepository);
            var sourceFileHandler           = _vbe.TempSourceFileHandler;
            var attributesSourceCodeHandler = new SourceFileHandlerSourceCodeHandlerAdapter(sourceFileHandler, projectRepository);
            var moduleParser = new ModuleParser(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler,
                stringParser);
            var parseRunner = new ParseRunner(
                _state,
                parserStateManager,
                moduleParser);
            var declarationResolveRunner = new DeclarationResolveRunner(
                _state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new ReferenceResolveRunner(
                _state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner
                );
            var parsingCacheService = new ParsingCacheService(
                _state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer,
                compilationsArgumentsCache
                );

            _parser = new SynchronousParseCoordinator(
                _state,
                parsingStageService,
                parsingCacheService,
                projectManager,
                parserStateManager
                );
        }