Пример #1
0
        private XmlAnnotationFile ParseAnnotationFile(
            [NotNull] Type benchmarkType,
            [NotNull] string resourceFileName,
            [NotNull] IMessageLogger messageLogger)
        {
            var resourceKey      = GetResourceKey(benchmarkType);
            var resourceChecksum = PdbHelpers.TryGetChecksum(resourceKey, PdbChecksumAlgorithm.Sha1);
            var fileChecksum     = PdbHelpers.TryGetChecksum(resourceFileName, PdbChecksumAlgorithm.Sha1);

            if (!resourceChecksum.EqualsTo(fileChecksum))
            {
                var expected = resourceChecksum.ToHexString();
                var actual   = fileChecksum.ToHexString();
                messageLogger.WriteSetupErrorMessage(
                    $"{PdbChecksumAlgorithm.Sha1} checksum validation failed. File '{resourceFileName}'." +
                    $"{Environment.NewLine}\tActual: 0x{actual}" +
                    $"{Environment.NewLine}\tExpected: 0x{expected}");

                return(new XmlAnnotationFile(resourceFileName, null));
            }

            var xmlAnnotationDoc = XmlAnnotationHelpers.TryParseXmlAnnotationDoc(resourceFileName, messageLogger);

            return(new XmlAnnotationFile(resourceFileName, xmlAnnotationDoc));
        }
        private static bool TryValidate(SourceAnnotationInfo documentInfo, IMessageLogger messageLogger)
        {
            bool result = true;

            if (documentInfo.SourceLanguage != SourceLanguage.CSharp)
            {
                messageLogger.WriteSetupErrorMessage(
                    $"Document language {documentInfo.SourceLanguage} is unsupported. File '{documentInfo.Path}'.");
                result = false;
            }

            if (documentInfo.MethodLinesMap.IsEmpty)
            {
                // TODO: improve message
                messageLogger.WriteSetupErrorMessage(
                    $"No methods found in document '{documentInfo.Path}'.");
                result = false;
            }

            if (!documentInfo.MethodLinesMap.IsMerged)
            {
                var methodsIntersection = documentInfo.MethodLinesMap
                                          .GetIntersections()
                                          .FirstOrDefault(i => i.Ranges.Count > 1);
                DebugCode.BugIf(methodsIntersection.IsEmpty, "methodsIntersection.IsEmpty");

                var methodNames = methodsIntersection.Ranges.Select(r => r.Key.Name).Join(", ");

                // TODO: improve message
                messageLogger.WriteSetupErrorMessage(
                    $"Some of methods in document share same source lines {methodsIntersection.IntersectionRange}: " +
                    $"{methodNames}. Document '{documentInfo.Path}'.");
                result = false;
            }

            var symbolsChecksum = documentInfo.Checksum;
            var fileChecksum    = PdbHelpers.TryGetChecksum(documentInfo.Path, documentInfo.ChecksumAlgorithm);

            if (!symbolsChecksum.EqualsTo(fileChecksum))
            {
                var expected = symbolsChecksum.ToHexString();
                var actual   = fileChecksum.ToHexString();
                messageLogger.WriteSetupErrorMessage(
                    $"{PdbChecksumAlgorithm.Sha1} checksum validation failed. File '{documentInfo.Path}'." +
                    $"{Environment.NewLine}\tActual: 0x{actual}" +
                    $"{Environment.NewLine}\tExpected: 0x{expected}");

                result = false;
            }

            return(result);
        }
Пример #3
0
        private static void GetConstants(
            ArrayBuilder <LocalSymbol> builder,
            MethodSymbol method,
            ArrayBuilder <ISymUnmanagedScope> scopes,
            MetadataDecoder metadataDecoder,
            ImmutableDictionary <string, ImmutableArray <bool> > dynamicLocalConstantMap,
            SourceAssemblySymbol containingAssembly)
        {
            foreach (var scope in scopes)
            {
                foreach (var constant in scope.GetConstants())
                {
                    string name      = constant.GetName();
                    object rawValue  = constant.GetValue();
                    var    signature = constant.GetSignature();

                    var info = metadataDecoder.GetLocalInfo(signature);
                    Debug.Assert(!info.IsByRef);
                    Debug.Assert(!info.IsPinned);
                    var type = info.Type;
                    if (type.IsErrorType())
                    {
                        continue;
                    }

                    var constantValue = PdbHelpers.GetConstantValue(type.EnumUnderlyingType(), rawValue);

                    ImmutableArray <bool> dynamicFlags;
                    if (dynamicLocalConstantMap != null && dynamicLocalConstantMap.TryGetValue(name, out dynamicFlags))
                    {
                        type = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(
                            type,
                            containingAssembly,
                            RefKind.None,
                            dynamicFlags);
                    }

                    builder.Add(new EELocalConstantSymbol(method, name, type, constantValue));
                }
            }
        }