Exemple #1
0
        /// <summary>
        /// Returns true if the given snapshot is still valid and all the parsed spec has the same symbols.
        /// </summary>
        private CanReuseSnapshotResult GetSnapshotReuseState(Possible <ISourceFile>[] specs, IWorkspaceBindingSnapshot snapshot)
        {
            var dirtySpecs   = new List <ISourceFile>();
            var invalidSpecs = new List <ISourceFile>();

            foreach (var s in specs)
            {
                // All specs should be valid here, getting result from the 'Result' property directly.
                ISourceFile spec = s.Result;

                var state = snapshot.TryGetSpecState(spec.GetAbsolutePath(FrontEndContext.PathTable));
                if (state == null)
                {
                    // If symbols is missing from the snapshot, we can't reuse it
                    return(CanReuseSnapshotResult.Invalid);
                }

                Contract.Assert(spec.BindingSymbols != null);
                Contract.Assert(state.BindingSymbols != null);

                if (spec.BindingSymbols.DeclaredSymbolsFingerprint != state.BindingSymbols.DeclaredSymbolsFingerprint)
                {
                    invalidSpecs.Add(spec);
                }
                else if (spec.BindingSymbols.ReferencedSymbolsFingerprint != state.BindingSymbols.ReferencedSymbolsFingerprint)
                {
                    dirtySpecs.Add(spec);
                }
            }

            return(new CanReuseSnapshotResult(dirtySpecs, invalidSpecs));
        }
Exemple #2
0
        private static ParsedModule CreateModuleFor(RuntimeModelContext context, ISourceFile sourceFile)
        {
            const string ModuleName = "ModuleWith1File";
            var          specPath   = sourceFile.GetAbsolutePath(context.PathTable);

            var moduleRootDirectory = specPath.GetParent(context.PathTable);
            var moduleDefinition    = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                new ModuleDescriptor(
                    id: ModuleId.Create(context.StringTable, ModuleName),
                    name: ModuleName,
                    displayName: ModuleName,
                    version: "1.0.0",
                    resolverKind: KnownResolverKind.SourceResolverKind,
                    resolverName: "DScriptExpression"),
                moduleRootDirectory: moduleRootDirectory,
                moduleConfigFile: moduleRootDirectory.Combine(context.PathTable, "package.config.dsc"),
                specs: new [] { specPath },
                allowedModuleDependencies: null,
                cyclicalFriendModules: null
                );

            return(new ParsedModule(moduleDefinition, new Dictionary <AbsolutePath, ISourceFile>()
            {
                [specPath] = sourceFile
            }));
        }
Exemple #3
0
            /// <inheritdoc />
            public override bool IsPreludeFile(ISourceFile sourceFile)
            {
                if (m_workspace.PreludeModule != null)
                {
                    var filePath = sourceFile.GetAbsolutePath(m_pathTable);
                    return(m_workspace.PreludeModule.Specs.ContainsKey(filePath));
                }

                return(false);
            }
Exemple #4
0
        private static bool IsWellKnownModule(ISourceFile sourceFile, DiagnosticContext context)
        {
            if (context.Workspace == null)
            {
                // This rule is applicable only when the workspace is used.
                return(true);
            }

            var module = context.Workspace.GetModuleBySpecFileName(sourceFile.GetAbsolutePath(context.PathTable));

            return(WellKnownTransformerWrappers.Contains(module.Descriptor.Name));
        }
Exemple #5
0
        /// <summary>
        /// Constructs a function scope with a parent <paramref name="namespaceScope"/>.
        /// </summary>
        internal FunctionScope(PathTable pathTable, StringTable stringTable, ISourceFile sourceFile, NamespaceScope namespaceScope)
            : this()
        {
            Contract.Requires(pathTable != null);
            Contract.Requires(stringTable != null);
            Contract.Requires(sourceFile != null);

            m_pathTable      = pathTable;
            m_stringTable    = stringTable;
            m_sourceFile     = sourceFile;
            m_namespaceScope = namespaceScope;
            m_sourceFilePath = sourceFile.GetAbsolutePath(pathTable);
        }
Exemple #6
0
        private FunctionScope(PathTable pathTable, StringTable stringTable, ISourceFile sourceFile, FunctionScope parentScope)
        {
            Contract.Requires(stringTable != null);
            Contract.Requires(sourceFile != null);

            m_stringTable = stringTable;
            m_sourceFile  = sourceFile;
            m_pathTable   = pathTable;

            m_nextIndex       = parentScope.m_nextIndex;
            Captures          = m_nextIndex;
            m_scopedVarsStack = new Stack <BlockScope>();
            m_scopedVarsStack.Push(new BlockScope(this));
            m_parent         = parentScope;
            m_namespaceScope = null;
            m_sourceFilePath = sourceFile.GetAbsolutePath(pathTable);
        }
Exemple #7
0
        private void UpdateAndSaveSnapshot(Possible <ISourceFile>[] parseResults, IWorkspaceBindingSnapshot snapshot)
        {
            if (!FrontEndConfiguration.ConstructAndSaveBindingFingerprint())
            {
                return;
            }

            foreach (var sourceFile in parseResults)
            {
                ISourceFile source = sourceFile.Result;
                Contract.Assert(source.BindingSymbols != null, "source.BindingSymbols != null");

                snapshot.UpdateBindingFingerprint(
                    source.GetAbsolutePath(FrontEndContext.PathTable),
                    source.BindingSymbols.ReferencedSymbolsFingerprint,
                    source.BindingSymbols.DeclaredSymbolsFingerprint);
            }

            SaveFrontEndSnapshot(snapshot);
        }
Exemple #8
0
 private static bool IsPrelude([CanBeNull] ISourceFile sourceFile, DiagnosticContext context)
 {
     return(sourceFile != null && context.Workspace.PreludeModule?.Specs.ContainsKey(sourceFile.GetAbsolutePath(context.PathTable)) == true);
 }