private ChecksumWithChildren DeserializeChecksumWithChildren(ObjectReader reader, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var kind = reader.ReadString();
            var checksum = Checksum.ReadFrom(reader);

            var childrenCount = reader.ReadInt32();
            var children = new object[childrenCount];

            for (var i = 0; i < childrenCount; i++)
            {
                var childKind = reader.ReadByte();
                if (childKind == ChecksumKind)
                {
                    children[i] = Checksum.ReadFrom(reader);
                    continue;
                }

                if (childKind == ChecksumWithChildrenKind)
                {
                    children[i] = DeserializeChecksumWithChildren(reader, cancellationToken);
                    continue;
                }

                throw ExceptionUtilities.UnexpectedValue(childKind);
            }

            var checksums = s_creatorMap[kind](children);
            Contract.ThrowIfFalse(checksums.Checksum == checksum);

            return checksums;
        }
Пример #2
0
        internal static DeclaredSymbolInfo ReadFrom(ObjectReader reader)
        {
            try
            {
                var name = reader.ReadString();
                var immediateContainer = reader.ReadString();
                var entireContainer = reader.ReadString();
                var kind = (DeclaredSymbolInfoKind)reader.ReadByte();
                var spanStart = reader.ReadInt32();
                var spanLength = reader.ReadInt32();
                var parameterCount = reader.ReadUInt16();
                var typeParameterCount = reader.ReadUInt16();

                var inheritanceNamesLength = reader.ReadInt32();
                var builder = ImmutableArray.CreateBuilder<string>(inheritanceNamesLength);
                for (var i = 0; i < inheritanceNamesLength; i++)
                {
                    builder.Add(reader.ReadString());
                }

                return new DeclaredSymbolInfo(
                    name, immediateContainer, entireContainer, kind, new TextSpan(spanStart, spanLength),
                    builder.MoveToImmutable(),
                    parameterCount, typeParameterCount);
            }
            catch
            {
                return default(DeclaredSymbolInfo);
            }
        }
Пример #3
0
        private SourceText DeserializeSourceText(ObjectReader reader, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // REVIEW: why IDE services doesnt care about checksumAlgorithm?
            var checksumAlgorithm = (SourceHashAlgorithm)reader.ReadInt32();
            var webName = reader.ReadString();
            var encoding = webName == null ? null : Encoding.GetEncoding(webName);

            var kind = (SerializationKinds)reader.ReadInt32();
            if (kind == SerializationKinds.MemoryMapFile)
            {
                var name = reader.ReadString();
                var size = reader.ReadInt64();

                var tempService = _workspaceServices.GetService<ITemporaryStorageService>() as ITemporaryStorageService2;
                var storage = tempService.AttachTemporaryTextStorage(name, size, encoding, cancellationToken);

                return storage.ReadText(cancellationToken);
            }

            // TODO: should include version info here as well?

            var textService = _workspaceServices.GetService<ITextFactoryService>();
            using (var textReader = new StringReader(reader.ReadString()))
            {
                return textService.CreateText(textReader, encoding, cancellationToken);
            }
        }
Пример #4
0
        internal static BKTree ReadFrom(ObjectReader reader)
        {
            try
            {
                var concatenatedLowerCaseWords = new char[reader.ReadInt32()];
                for (var i = 0; i < concatenatedLowerCaseWords.Length; i++)
                {
                    concatenatedLowerCaseWords[i] = reader.ReadChar();
                }

                var nodeCount = reader.ReadInt32();
                var nodes = ImmutableArray.CreateBuilder<Node>(nodeCount);
                for (var i = 0; i < nodeCount; i++)
                {
                    nodes.Add(Node.ReadFrom(reader));
                }

                var edgeCount = reader.ReadInt32();
                var edges = ImmutableArray.CreateBuilder<Edge>(edgeCount);
                for (var i = 0; i < edgeCount; i++)
                {
                    edges.Add(Edge.ReadFrom(reader));
                }

                return new BKTree(concatenatedLowerCaseWords, nodes.MoveToImmutable(), edges.MoveToImmutable());
            }
            catch
            {
                Logger.Log(FunctionId.BKTree_ExceptionInCacheRead);
                return null;
            }
        }
            private IList<ValueTuple<Checksum, object>> ReadAssets(
                Stream stream, int sessionId, ISet<Checksum> checksums, CancellationToken cancellationToken)
            {
                var results = new List<ValueTuple<Checksum, object>>();

                using (var reader = new ObjectReader(stream))
                {
                    var responseSessionId = reader.ReadInt32();
                    Contract.ThrowIfFalse(sessionId == responseSessionId);

                    var count = reader.ReadInt32();
                    Contract.ThrowIfFalse(count == checksums.Count);

                    for (var i = 0; i < count; i++)
                    {
                        var responseChecksum = new Checksum(reader.ReadArray<byte>());
                        Contract.ThrowIfFalse(checksums.Contains(responseChecksum));

                        var kind = reader.ReadString();

                        // in service hub, cancellation means simply closed stream
                        var @object = _owner.RoslynServices.AssetService.Deserialize<object>(kind, reader, cancellationToken);

                        results.Add(ValueTuple.Create(responseChecksum, @object));
                    }

                    return results;
                }
            }
Пример #6
0
        private OptionSet DeserializeOptionSet(ObjectReader reader, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var language = reader.ReadString();

            var serializationService = GetOptionsSerializationService(language);
            return serializationService.ReadOptionSetFrom(reader, cancellationToken);
        }
 internal WithTwoChildren(ObjectReader reader)
     : base(reader)
 {
     this.SlotCount = 2;
     _child0 = (GreenNode)reader.ReadValue();
     this.AdjustFlagsAndWidth(_child0);
     _child1 = (GreenNode)reader.ReadValue();
     this.AdjustFlagsAndWidth(_child1);
 }
 internal SyntaxIdentifierWithTrailingTrivia(ObjectReader reader)
     : base(reader)
 {
     var trailing = (GreenNode)reader.ReadValue();
     if (trailing != null)
     {
         this.AdjustFlagsAndWidth(trailing);
         _trailing = trailing;
     }
 }
        public override ParseOptions ReadParseOptionsFrom(ObjectReader reader, CancellationToken cancellationToken)
        {
            ReadParseOptionsFrom(reader, out var kind, out var documentationMode, out var features, cancellationToken);

            var languageVersion = (LanguageVersion)reader.ReadInt32();
            var preprocessorSymbolNames = reader.ReadArray<string>();

            var options = new CSharpParseOptions(languageVersion, documentationMode, kind, preprocessorSymbolNames);
            return options.WithFeatures(features);
        }
Пример #10
0
        private SolutionChecksumObjectInfo DeserializeSolutionSnapshotInfo(ObjectReader reader, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var solutionId = DeserializeSolutionId(reader, cancellationToken);
            // var version = VersionStamp.ReadFrom(reader);
            var filePath = reader.ReadString();

            return new SolutionChecksumObjectInfo(solutionId, VersionStamp.Create(), filePath);
        }
        public MetadataReference ReadMetadataReferenceFrom(ObjectReader reader, CancellationToken cancellationToken)
        {
            var type = reader.ReadString();
            if (type == nameof(PortableExecutableReference))
            {
                return ReadPortableExecutableReferenceFrom(reader, cancellationToken);
            }

            throw ExceptionUtilities.UnexpectedValue(type);
        }
        private static bool TryReadVersion(ObjectReader reader, string formatVersion, out VersionStamp version)
        {
            version = VersionStamp.Default;
            if (reader.ReadString() != formatVersion)
            {
                return false;
            }

            version = VersionStamp.ReadFrom(reader);
            return true;
        }
            internal WithManyChildrenBase(ObjectReader reader)
                : base(reader)
            {
                var length = reader.ReadInt32();

                this.children = new ArrayElement<GreenNode>[length];
                for (var i = 0; i < length; i++)
                {
                    this.children[i].Value = (GreenNode)reader.ReadValue();
                }

                this.InitializeChildren();
            }
Пример #14
0
        public static BloomFilter ReadFrom(ObjectReader reader)
        {
            var version = reader.ReadString();
            if (!string.Equals(version, SerializationFormat, StringComparison.Ordinal))
            {
                return null;
            }

            var isCaseSensitive = reader.ReadBoolean();
            int hashFunctionCount = reader.ReadInt32();
            var bitArray = ReadBitArray(reader);
            return new BloomFilter(bitArray, hashFunctionCount, isCaseSensitive);
        }
        public override OptionSet ReadOptionSetFrom(ObjectReader reader, CancellationToken cancellationToken)
        {
            OptionSet options = new SerializedPartialOptionSet();

            options = ReadOptionSetFrom(options, LanguageNames.CSharp, reader, cancellationToken);

            foreach (var option in CSharpCodeStyleOptions.GetCodeStyleOptions())
            {
                options = ReadOptionFrom(options, option, reader, cancellationToken);
            }

            return options;
        }
        public override ParseOptions ReadParseOptionsFrom(ObjectReader reader, CancellationToken cancellationToken)
        {
            SourceCodeKind kind;
            DocumentationMode documentationMode;
            IEnumerable<KeyValuePair<string, string>> features;
            ReadParseOptionsFrom(reader, out kind, out documentationMode, out features, cancellationToken);

            var languageVersion = (LanguageVersion)reader.ReadInt32();
            var preprocessorSymbolNames = reader.ReadArray<string>();

            var options = new CSharpParseOptions(languageVersion, documentationMode, kind, preprocessorSymbolNames);
            return options.WithFeatures(features);
        }
Пример #17
0
        private static BitArray ReadBitArray(ObjectReader reader)
        {
            // TODO: find a way to use pool
            var length = reader.ReadInt32();
            var bytes = new byte[length];

            for (var i = 0; i < bytes.Length; i++)
            {
                bytes[i] = reader.ReadByte();
            }

            return new BitArray(bytes);
        }
Пример #18
0
        public static DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult> Deserialize(
            ObjectReader reader, IDictionary<string, DiagnosticAnalyzer> analyzerMap, Project project, VersionStamp version, CancellationToken cancellationToken)
        {
            var diagnosticDataSerializer = new DiagnosticDataSerializer(VersionStamp.Default, VersionStamp.Default);

            var analysisMap = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, DiagnosticAnalysisResult>();

            var analysisCount = reader.ReadInt32();
            for (var i = 0; i < analysisCount; i++)
            {
                var analyzer = analyzerMap[reader.ReadString()];

                var syntaxLocalMap = Deserialize(reader, diagnosticDataSerializer, project, cancellationToken);
                var semanticLocalMap = Deserialize(reader, diagnosticDataSerializer, project, cancellationToken);
                var nonLocalMap = Deserialize(reader, diagnosticDataSerializer, project, cancellationToken);

                var others = diagnosticDataSerializer.ReadFrom(reader, project, cancellationToken);

                var analysisResult = new DiagnosticAnalysisResult(
                    project.Id, version,
                    syntaxLocalMap, semanticLocalMap, nonLocalMap, others,
                    documentIds: null, fromBuild: false);

                analysisMap.Add(analyzer, analysisResult);
            }

            var telemetryMap = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, AnalyzerTelemetryInfo>();

            var telemetryCount = reader.ReadInt32();
            for (var i = 0; i < telemetryCount; i++)
            {
                var analyzer = analyzerMap[reader.ReadString()];
                var telemetryInfo = Deserialize(reader, cancellationToken);

                telemetryMap.Add(analyzer, telemetryInfo);
            }

            var exceptionMap = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, ImmutableArray<DiagnosticData>>();

            var exceptionCount = reader.ReadInt32();
            for (var i = 0; i < exceptionCount; i++)
            {
                var analyzer = analyzerMap[reader.ReadString()];
                var exceptions = diagnosticDataSerializer.ReadFrom(reader, project, cancellationToken);

                exceptionMap.Add(analyzer, exceptions);
            }

            return DiagnosticAnalysisResultMap.Create(analysisMap.ToImmutable(), telemetryMap.ToImmutable(), exceptionMap.ToImmutable());
        }
        public override ParseOptions ReadParseOptionsFrom(ObjectReader reader, CancellationToken cancellationToken)
        {
            ReadParseOptionsFrom(reader, out var kind, out var documentationMode, out var features, cancellationToken);

            var languageVersion = (LanguageVersion)reader.ReadInt32();
            var preprocessorSymbolNames = reader.ReadArray<string>();

            var options = new CSharpParseOptions(languageVersion, documentationMode, kind);

            // use WithPreprocessorSymbols instead of constructor to bypass preprocessor validation.
            // https://github.com/dotnet/roslyn/issues/15797
            return options.WithPreprocessorSymbols(preprocessorSymbolNames)
                          .WithFeatures(features);
        }
Пример #20
0
        /// <summary>
        /// this is for a project in a solution
        /// </summary>
        private static async Task<ValueTuple<bool, SymbolTreeInfo>> LoadOrCreateAsync(Project project, CancellationToken cancellationToken)
        {
            if (await project.IsForkedProjectWithSemanticChangesAsync(cancellationToken).ConfigureAwait(false))
            {
                return ValueTuple.Create(false, await CreateAsync(project, cancellationToken).ConfigureAwait(false));
            }

            var persistentStorageService = project.Solution.Workspace.Services.GetService<IPersistentStorageService>();
            var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

            // attempt to load from persisted state
            SymbolTreeInfo info;
            var succeeded = false;
            using (var storage = persistentStorageService.GetStorage(project.Solution))
            {
                using (var stream = await storage.ReadStreamAsync(project, ProjectSymbolTreeInfoPersistenceName, cancellationToken).ConfigureAwait(false))
                {
                    if (stream != null)
                    {
                        using (var reader = new ObjectReader(stream))
                        {
                            info = ReadFrom(reader);
                            if (info != null && VersionStamp.CanReusePersistedVersion(version, info.version))
                            {
                                return ValueTuple.Create(true, info);
                            }
                        }
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();

                // compute it if we couldn't load it from cache
                info = await CreateAsync(project, cancellationToken).ConfigureAwait(false);
                if (info != null)
                {
                    using (var stream = SerializableBytes.CreateWritableStream())
                    using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
                    {
                        info.WriteTo(writer);
                        stream.Position = 0;

                        succeeded = await storage.WriteStreamAsync(project, ProjectSymbolTreeInfoPersistenceName, stream, cancellationToken).ConfigureAwait(false);
                    }
                }
            }

            return ValueTuple.Create(succeeded, info);
        }
Пример #21
0
        private ProjectChecksumObjectInfo DeserializeProjectSnapshotInfo(ObjectReader reader, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var projectId = DeserializeProjectId(reader, cancellationToken);

            // var version = VersionStamp.ReadFrom(reader);
            var name = reader.ReadString();
            var assemblyName = reader.ReadString();
            var language = reader.ReadString();
            var filePath = reader.ReadString();
            var outputFilePath = reader.ReadString();

            return new ProjectChecksumObjectInfo(projectId, VersionStamp.Create(), name, assemblyName, language, filePath, outputFilePath);
        }
            public static IdentifierInfo? ReadFrom(ObjectReader reader)
            {
                try
                {
                    var identifierFilter = BloomFilter.ReadFrom(reader);
                    var escapedIdentifierFilter = BloomFilter.ReadFrom(reader);

                    return new IdentifierInfo(identifierFilter, escapedIdentifierFilter);
                }
                catch (Exception)
                {
                }

                return null;
            }
        private static SyntaxTreeIdentifierInfo ReadFrom(ObjectReader reader, VersionStamp version)
        {
            try
            {
                var identifierFilter = BloomFilter.ReadFrom(reader);
                var escapedIdentifierFilter = BloomFilter.ReadFrom(reader);

                return new SyntaxTreeIdentifierInfo(version, identifierFilter, escapedIdentifierFilter);
            }
            catch (Exception)
            {
            }

            return null;
        }
 internal SyntaxTokenWithTrivia(ObjectReader reader)
     : base(reader)
 {
     var leading = (CSharpSyntaxNode)reader.ReadValue();
     if (leading != null)
     {
         this.AdjustFlagsAndWidth(leading);
         this.LeadingField = leading;
     }
     var trailing = (CSharpSyntaxNode)reader.ReadValue();
     if (trailing != null)
     {
         this.AdjustFlagsAndWidth(trailing);
         this.TrailingField = trailing;
     }
 }
 internal SyntaxIdentifierWithTrivia(ObjectReader reader)
     : base(reader)
 {
     var leading = (CSharpSyntaxNode)reader.ReadValue();
     if (leading != null)
     {
         this.AdjustFlagsAndWidth(leading);
         _leading = leading;
     }
     var trailing = (CSharpSyntaxNode)reader.ReadValue();
     if (trailing != null)
     {
         _trailing = trailing;
         this.AdjustFlagsAndWidth(trailing);
     }
 }
        public void VersionStamp_RoundTripText()
        {
            using (var writerStream = new MemoryStream())
            using (var writer = new ObjectWriter(writerStream))
            {
                var versionStamp = VersionStamp.Create();
                versionStamp.WriteTo(writer);

                using (var readerStream = new MemoryStream(writerStream.ToArray()))
                using (var reader = new ObjectReader(readerStream))
                {
                    var deserializedVersionStamp = VersionStamp.ReadFrom(reader);

                    Assert.Equal(versionStamp, deserializedVersionStamp);
                }
            }
        }
        public override CompilationOptions ReadCompilationOptionsFrom(ObjectReader reader, CancellationToken cancellationToken)
        {
            ReadCompilationOptionsFrom(
                reader,
                out var outputKind, out var reportSuppressedDiagnostics, out var moduleName, out var mainTypeName, out var scriptClassName,
                out var optimizationLevel, out var checkOverflow, out var cryptoKeyContainer, out var cryptoKeyFile, out var cryptoPublicKey,
                out var delaySign, out var platform, out var generalDiagnosticOption, out var warningLevel, out var specificDiagnosticOptions,
                out var concurrentBuild, out var deterministic, out var publicSign, out var xmlReferenceResolver, out var sourceReferenceResolver,
                out var metadataReferenceResolver, out var assemblyIdentityComparer, out var strongNameProvider, cancellationToken);

            var usings = reader.ReadArray<string>();
            var allowUnsafe = reader.ReadBoolean();

            return new CSharpCompilationOptions(
                outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName, usings, optimizationLevel, checkOverflow, allowUnsafe,
                cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions, concurrentBuild,
                deterministic, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, assemblyIdentityComparer, strongNameProvider, publicSign);
        }
            public static DeclarationInfo? ReadFrom(ObjectReader reader)
            {
                try
                {
                    var declaredSymbolCount = reader.ReadInt32();
                    var builder = ImmutableArray.CreateBuilder<DeclaredSymbolInfo>(declaredSymbolCount);
                    for (int i = 0; i < declaredSymbolCount; i++)
                    {
                        builder.Add(DeclaredSymbolInfo.ReadFrom(reader));
                    }

                    return new DeclarationInfo(builder.MoveToImmutable());
                }
                catch (Exception)
                {
                }

                return null;
            }
            private static Task<object> ReadAssetAsync(
                Stream stream, TraceSource logger, int serviceId, Checksum checksum, CancellationToken cancellationToken)
            {
                using (var reader = new ObjectReader(stream))
                {
                    var responseServiceId = reader.ReadInt32();
                    Contract.ThrowIfFalse(serviceId == responseServiceId);

                    var responseChecksum = new Checksum(reader.ReadArray<byte>());
                    Contract.ThrowIfFalse(checksum == responseChecksum);

                    var kind = reader.ReadString();

                    // in service hub, cancellation means simply closed stream
                    var @object = RoslynServices.AssetService.Deserialize<object>(kind, reader, cancellationToken);

                    return Task.FromResult(@object);
                }
            }
        private static SyntaxTreeDeclarationInfo ReadFrom(ObjectReader reader, VersionStamp version)
        {
            try
            {
                var declaredSymbolCount = reader.ReadInt32();
                var declaredSymbols = new DeclaredSymbolInfo[declaredSymbolCount];
                for (int i = 0; i < declaredSymbolCount; i++)
                {
                    declaredSymbols[i] = DeclaredSymbolInfo.ReadFrom(reader);
                }

                return new SyntaxTreeDeclarationInfo(version, declaredSymbols);
            }
            catch (Exception)
            {
            }

            return null;
        }
Пример #31
0
 internal static SpellChecker ReadFrom(ObjectReader reader)
 {
     return(new SpellChecker(BKTree.ReadFrom(reader)));
 }