Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        /// <nodoc />
        public DScriptExprEvaluator(LoggingContext loggingContext)
        {
            var configuration = new AstConversionConfiguration(
                policyRules: Enumerable.Empty <string>(),
                disableLanguagePolicies: false);

            s_parser = new RuntimeModelFactory(
                m_logger,
                loggingContext,
                new FrontEndStatistics(),
                configuration,
                workspace: null);
        }
Ejemplo n.º 3
0
        /// <nodoc />
        public ExpressionEvaluator(DebuggerState state)
        {
            m_state = state;

            var configuration = new AstConversionConfiguration(
                policyRules: Enumerable.Empty <string>(),
                disableLanguagePolicies: false);

            s_parser = new RuntimeModelFactory(
                m_logger,
                m_state.LoggingContext,
                new FrontEndStatistics(),
                configuration,
                workspace: null);
        }
Ejemplo n.º 4
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);
            }
        }