Exemplo n.º 1
0
 public void WriteUsingInfo(ImportDebugInformation import_info)
 {
     Write(CustomMetadataType.UsingInfo, () => {
         writer.WriteUInt16((ushort)1);
         writer.WriteUInt16((ushort)import_info.Targets.Count);
     });
 }
Exemplo n.º 2
0
        private ImportDebugInformation Clone(ImportDebugInformation import, MethodDefinition context)
        {
            var importDebugInfo = new ImportDebugInformation();

            if (import.HasCustomDebugInformations)
            {
                importDebugInfo.CustomDebugInformations.AddRange(import.CustomDebugInformations);
            }

            if (import.Parent != null)
            {
                importDebugInfo.Parent = Clone(import.Parent, context);
            }

            if (import.HasTargets)
            {
                foreach (var importTarget in import.Targets)
                {
                    var targetCopy = new ImportTarget(importTarget.Kind);
                    if (importTarget.Alias != null)
                    {
                        targetCopy.Alias = importTarget.Alias;
                    }
                    if (importTarget.Namespace != null)
                    {
                        targetCopy.Namespace = importTarget.Namespace;
                    }

                    if (importTarget.AssemblyReference != null)
                    {
                        if (_repackContext.MergedAssemblies.Any(x => x.Name.Name == importTarget.AssemblyReference.Name))
                        {
                            continue;
                        }
                        targetCopy.AssemblyReference = (AssemblyNameReference)_repackContext.PlatformFixer.FixPlatformVersion(importTarget.AssemblyReference);
                    }
                    if (importTarget.AssemblyReference != null)
                    {
                        targetCopy.AssemblyReference = targetCopy.AssemblyReference;
                    }

                    if (importTarget.Type != null)
                    {
                        targetCopy.Type = Import(importTarget.Type, context);
                    }

                    importDebugInfo.Targets.Add(targetCopy);
                }
            }

            return(importDebugInfo);
        }
Exemplo n.º 3
0
        static ImportDebugInformation GetImport(PdbScope scope, ModuleDefinition module)
        {
            if (scope.usedNamespaces.IsNullOrEmpty())
            {
                return(null);
            }

            var import = new ImportDebugInformation();

            foreach (var used_namespace in scope.usedNamespaces)
            {
                if (string.IsNullOrEmpty(used_namespace))
                {
                    continue;
                }

                ImportTarget target = null;
                var          value  = used_namespace.Substring(1);
                switch (used_namespace [0])
                {
                case 'U':
                    target = new ImportTarget(ImportTargetKind.ImportNamespace)
                    {
                        @namespace = value
                    };
                    break;

                case 'T': {
                    var type = TypeParser.ParseType(module, value);
                    if (type != null)
                    {
                        target = new ImportTarget(ImportTargetKind.ImportType)
                        {
                            type = type
                        }
                    }
                    ;
                    break;
                }

                case 'A':
                    var index = used_namespace.IndexOf(' ');
                    if (index < 0)
                    {
                        target = new ImportTarget(ImportTargetKind.ImportNamespace)
                        {
                            @namespace = used_namespace
                        };
                        break;
                    }
                    var alias_value        = used_namespace.Substring(1, index - 1);
                    var alias_target_value = used_namespace.Substring(index + 2);
                    switch (used_namespace [index + 1])
                    {
                    case 'U':
                        target = new ImportTarget(ImportTargetKind.DefineNamespaceAlias)
                        {
                            alias = alias_value, @namespace = alias_target_value
                        };
                        break;

                    case 'T':
                        var type = TypeParser.ParseType(module, alias_target_value);
                        if (type != null)
                        {
                            target = new ImportTarget(ImportTargetKind.DefineTypeAlias)
                            {
                                alias = alias_value, type = type
                            }
                        }
                        ;
                        break;
                    }
                    break;

                case '*':
                    target = new ImportTarget(ImportTargetKind.ImportNamespace)
                    {
                        @namespace = value
                    };
                    break;

                case '@':
                    if (!value.StartsWith("P:"))
                    {
                        continue;
                    }

                    target = new ImportTarget(ImportTargetKind.ImportNamespace)
                    {
                        @namespace = value.Substring(2)
                    };
                    break;
                }

                if (target != null)
                {
                    import.Targets.Add(target);
                }
            }

            return(import);
        }

        void ReadSequencePoints(PdbFunction function, MethodDebugInformation info)
        {
            if (function.lines == null)
            {
                return;
            }

            info.sequence_points = new Collection <SequencePoint> ();

            foreach (PdbLines lines in function.lines)
            {
                ReadLines(lines, info);
            }
        }

        void ReadLines(PdbLines lines, MethodDebugInformation info)
        {
            var document = GetDocument(lines.file);

            foreach (var line in lines.lines)
            {
                ReadLine(line, document, info);
            }
        }