コード例 #1
0
        /// <summary>
        /// Runs AST conversion on the given target path.
        /// </summary>
        /// <remarks>
        /// The target path is assumed to already be part of the workspace contained by the given host
        /// </remarks>
        public static Task <SourceFileParseResult> RunAstConversionAsync(FrontEndHost host, FrontEndContext context, Script.Tracing.Logger logger, IFrontEndStatistics stats, Package package, AbsolutePath conversionTarget)
        {
            Contract.RequiresNotNull(host);
            Contract.RequiresNotNull(context);
            Contract.RequiresNotNull(logger);
            Contract.RequiresNotNull(stats);
            Contract.RequiresNotNull(package);
            Contract.Requires(conversionTarget.IsValid);

            var configuration = AstConversionConfiguration.FromConfiguration(host.Configuration.FrontEnd);
            var linter        = DiagnosticAnalyzer.Create(
                logger,
                context.LoggingContext,
                new HashSet <string>(configuration.PolicyRules),
                configuration.DisableLanguagePolicies);

            var workspace     = (Workspace)host.Workspace;
            var factory       = new RuntimeModelFactory(stats, configuration, linter, workspace);
            var parserContext = new RuntimeModelContext(
                host,
                frontEndContext: context,
                logger,
                package: package,
                origin: default(LocationData));

            var sourceFile = workspace.GetSourceFile(conversionTarget);

            return(factory.ConvertSourceFileAsync(parserContext, sourceFile));
        }
コード例 #2
0
        private async Task <bool> ConvertFileToEvaluationAsync(RuntimeModelFactory factory, AbsolutePath specPath, ISourceFile sourceFile, Package package)
        {
            using (FrontEndStatistics.SpecConversion.Start(sourceFile.Path.AbsolutePath))
            {
                // Need to skip configuration files
                if (IsConfigFile(specPath) || IsPackageConfigFile(specPath))
                {
                    return(true);
                }

                return(await m_parseQueue.ProcessFileAsync(sourceFile, ConvertFileToEvaluationAsync));
            }

            async Task <bool> ConvertFileToEvaluationAsync(ISourceFile f)
            {
                Context.CancellationToken.ThrowIfCancellationRequested();

                var parserContext = CreateParserContext(
                    this,
                    package,
                    origin: null);

                var conversionResult = await factory.ConvertSourceFileAsync(parserContext, f);

                Contract.Assert(!conversionResult.Success || conversionResult.Module != null);

                if (conversionResult.Success)
                {
                    RegisterSuccessfullyParsedModule(conversionResult.SourceFile, conversionResult, package);

                    // TODO: should the project be registered only when the parse is successful?
                    // In the original implementation (v1) the path was added all the time.
                    package.AddParsedProject(AbsolutePath.Create(parserContext.PathTable, sourceFile.FileName));
                }

                return(conversionResult.Success);
            }
        }