コード例 #1
0
        /// <summary>
        /// Typechecks a given <paramref name="workspace"/> (which must support
        /// semantic model, i.e., be of type <see cref="SemanticWorkspace"/>).
        /// </summary>
        public ISemanticModel Typecheck(Workspace workspace)
        {
            var semanticModel = workspace.GetSemanticModel();

            WorkspaceTestBase.AssertNoSemanticErrors(semanticModel);
            return(semanticModel);
        }
コード例 #2
0
        /// <summary>
        /// Builds and returns a <see cref="Workspace"/> from a given module repository (<see cref="ModuleRepository"/>).
        /// Before returning, asserts that the built workspace contains no failures.
        /// </summary>
        public async Task <Workspace> ParseAsync(ModuleRepository repo)
        {
            var workspace = await ParseNoErrorCheckAsync(repo);

            WorkspaceTestBase.AssertNoWorkspaceFailures(workspace);
            return(workspace);
        }
コード例 #3
0
        protected KeyValuePair <AbsolutePath, ISourceFile> LoadAndTypecheckFile(
            FrontEndContext context,
            string testSource,
            string[] extraSources,
            Dictionary <string, string> modules,
            out Workspace workspace,
            bool preserveTrivia = false)
        {
            var wsHelper = new WorkspaceTestBase(pathTable: context.PathTable, preludeName: FrontEndHost.PreludeModuleName, nameResolutionSemantics: NameResolutionSemantics.ImplicitProjectReferences);
            var repo     = wsHelper.CreateEmptyContent();

            var testModule = ModuleDescriptor.CreateForTesting("TestModule");

            repo.AddContent(testModule, testSource);
            if (extraSources != null)
            {
                repo.AddContent(testModule, extraSources);
            }

            repo.AddContent(FrontEndHost.PreludeModuleName,
                            File.ReadAllText(@"Libs/lib.core.d.ts"),
                            File.ReadAllText(@"Libs/Prelude.IO.ts"),
                            "namespace Tool {export declare function option(value: string): any;}");
            if (modules != null)
            {
                foreach (var kv in modules)
                {
                    repo.AddContent(ModuleDescriptor.CreateForTesting(kv.Key), kv.Value);
                }
            }

            workspace = wsHelper.CreateSematicWorkspaceFromContent(testModule, preserveTrivia, repo).GetAwaiter().GetResult();
            WorkspaceTestBase.AssertNoWorkspaceFailures(workspace);

            var semanticModel = workspace.GetSemanticModel();

            WorkspaceTestBase.AssertNoSemanticErrors(semanticModel);

            return(workspace.Modules.First(m => m.Descriptor.Name == "TestModule").Specs.First(f => f.Key.GetName(context.PathTable).ToString(context.StringTable) == "0.dsc"));
        }
コード例 #4
0
        public WorkspaceEvaluationHelper(string testOutputDirectory, FrontEndContext context = null, bool forTesting = false)
        {
            AstLogger      = global::BuildXL.FrontEnd.Script.Tracing.Logger.CreateLogger(preserveLogEvents: true);
            FrontEndLogger = global::BuildXL.FrontEnd.Core.Tracing.Logger.CreateLogger(preserveLogEvents: true);

            var pathTable           = new PathTable();
            var pathBasedFileSystem = new InMemoryFileSystem(pathTable);

            FrontEndContext = context ?? FrontEndContext.CreateInstanceForTesting(pathTable: pathTable, fileSystem: pathBasedFileSystem);

            FrontEndStatistics = new FrontEndStatistics();
            Engine             = new BasicFrontEndEngineAbstraction(
                FrontEndContext.PathTable,
                FrontEndContext.FileSystem
                );
            WorkspaceHelper = new WorkspaceTestBase(
                PathTable,
                FrontEndHost.PreludeModuleName,
                NameResolutionSemantics.ImplicitProjectReferences,
                cancellationToken: FrontEndContext.CancellationToken);
            SrcRoot = AbsolutePath.Create(PathTable, Path.Combine(testOutputDirectory, "src"));
            ObjRoot = AbsolutePath.Create(PathTable, Path.Combine(testOutputDirectory, "obj"));
        }