Example #1
0
        public static ILSpyUnresolvedFile Create(DecompiledTypeReference name, AstBuilder builder)
        {
            var writer = new StringWriter();
            var target = new TextWriterTokenWriter(writer)
            {
                IndentationString = "\t"
            };
            var output = new DebugInfoTokenWriterDecorator(TokenWriter.WrapInWriterThatSetsLocationsInAST(target));

            builder.RunTransformations();
            var syntaxTree = builder.SyntaxTree;

            syntaxTree.AcceptVisitor(new InsertParenthesesVisitor {
                InsertParenthesesForReadability = true
            });
            syntaxTree.AcceptVisitor(new CSharpOutputVisitor(output, FormattingOptionsFactory.CreateSharpDevelop()));
            ILSpyUnresolvedFile file = new ILSpyUnresolvedFile(name);
            var v = new TypeSystemConvertVisitor(file);

            syntaxTree.AcceptVisitor(v);

            file.MemberLocations = output.MemberLocations;
            file.DebugSymbols    = output.DebugSymbols;
            file.output          = writer.ToString();

            return(file);
        }
Example #2
0
        public IEnumerable <Debugger.SequencePoint> GetSequencePoints(Module module, string filename, int line, int column)
        {
            var name = DecompiledTypeReference.FromFileName(filename);

            if (name == null || !FileUtility.IsEqualFileName(module.FullPath, name.AssemblyFile))
            {
                yield break;
            }

            var file = SD.ParserService.ParseFile(name.ToFileName()) as ILSpyUnresolvedFile;

            if (file == null)
            {
                yield break;
            }

            TextLocation loc = new TextLocation(line, column);

            foreach (var symbols in file.DebugSymbols.Values.Where(s => s.StartLocation <= loc && loc <= s.EndLocation))
            {
                Decompiler.SequencePoint seq = null;
                if (column != 0)
                {
                    seq = symbols.SequencePoints.FirstOrDefault(p => p.StartLocation <= loc && loc <= p.EndLocation);
                }
                if (seq == null)
                {
                    seq = symbols.SequencePoints.FirstOrDefault(p => line <= p.StartLocation.Line);
                }
                if (seq != null)
                {
                    yield return(seq.ToDebugger(symbols, filename));
                }
            }
        }
        public static void NavigateTo(FileName assemblyFile, string typeName, string entityIdString)
        {
            if (assemblyFile == null)
            {
                throw new ArgumentNullException("assemblyFile");
            }
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException("typeName is null or empty");
            }

            var type   = new TopLevelTypeName(typeName);
            var target = new DecompiledTypeReference(assemblyFile, type);

            foreach (var viewContent in SD.Workbench.ViewContentCollection.OfType <DecompiledViewContent>())
            {
                var viewContentName = viewContent.DecompiledTypeName;
                if (viewContentName.AssemblyFile == assemblyFile && type == viewContentName.Type)
                {
                    viewContent.WorkbenchWindow.SelectWindow();
                    viewContent.JumpToEntity(entityIdString);
                    return;
                }
            }
            SD.Workbench.ShowView(new DecompiledViewContent(target, entityIdString));
        }
Example #4
0
        public static ILSpyUnresolvedFile GetSymbols(IMethod method)
        {
            var typeName = DecompiledTypeReference.FromTypeDefinition(method.DeclaringTypeDefinition);

            if (typeName == null)
            {
                return(null);
            }
            return(SD.ParserService.ParseFile(typeName.ToFileName()) as ILSpyUnresolvedFile);
        }
        public static ILSpyFullParseInformation DecompileType(DecompiledTypeReference name, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            var astBuilder = CreateAstBuilder(name, cancellationToken);

            return(new ILSpyFullParseInformation(ILSpyUnresolvedFile.Create(name, astBuilder), null, astBuilder.SyntaxTree));
        }
        public static ILSpyUnresolvedFile GetSymbols(IMethod method)
        {
            var typeName = DecompiledTypeReference.FromTypeDefinition(method.DeclaringTypeDefinition);

            if (typeName == null)
            {
                return(null);
            }
            SD.Log.DebugFormatted("GetSymbols for: {0}", typeName.ToFileName());
            // full parse info required to make ParserService caching possible...
            return(SD.ParserService.Parse(typeName.ToFileName()).UnresolvedFile as ILSpyUnresolvedFile);
        }
        public DecompiledViewContent(DecompiledTypeReference typeName, string entityTag)
        {
            this.DecompiledTypeName = typeName;

            this.Services = codeEditor.GetRequiredService <IServiceContainer>();
            codeEditor.PrimaryTextEditor.TextArea.LeftMargins.RemoveAll(m => m is ChangeMarkerMargin);
            this.jumpToEntityIdStringWhenDecompilationFinished = entityTag;
            this.TitleName = "[" + ReflectionHelper.SplitTypeParameterCountFromReflectionName(typeName.Type.Name) + "]";

            InitializeView();

            SD.BookmarkManager.BookmarkRemoved += BookmarkManager_Removed;
            SD.BookmarkManager.BookmarkAdded   += BookmarkManager_Added;

            this.codeEditor.FileName = this.DecompiledTypeName.ToFileName();
            this.codeEditor.ActiveTextEditor.IsReadOnly         = true;
            this.codeEditor.ActiveTextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
        }
Example #8
0
        public ICompilation CreateCompilationForSingleFile(FileName fileName, IUnresolvedFile unresolvedFile)
        {
            DecompiledTypeReference reference = DecompiledTypeReference.FromFileName(fileName);

            if (reference != null)
            {
                var model = SD.GetService <IClassBrowser>().FindAssemblyModel(reference.AssemblyFile);
                if (model == null)
                {
                    model = SD.AssemblyParserService.GetAssemblyModelSafe(reference.AssemblyFile, true);
                }
                if (model != null)
                {
                    return(model.Context.GetCompilation());
                }
            }
            return(new CSharpProjectContent()
                   .AddOrUpdateFiles(unresolvedFile)
                   .CreateCompilation());
        }
Example #9
0
        static AstBuilder CreateAstBuilder(DecompiledTypeReference name, CancellationToken cancellationToken = default(CancellationToken))
        {
            ModuleDefinition module = GetModuleDefinitionFromCache(name.AssemblyFile);

            if (module == null)
            {
                throw new InvalidOperationException("Could not find assembly file");
            }
            TypeDefinition typeDefinition = module.GetType(name.Type.ReflectionName);

            if (typeDefinition == null)
            {
                throw new InvalidOperationException("Could not find type");
            }
            DecompilerContext context = new DecompilerContext(module);

            context.CancellationToken = cancellationToken;
            AstBuilder astBuilder = new AstBuilder(context);

            astBuilder.AddType(typeDefinition);
            return(astBuilder);
        }
Example #10
0
 public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested, IProject parentProject, CancellationToken cancellationToken)
 {
     return(ILSpyDecompilerService.DecompileType(DecompiledTypeReference.FromFileName(fileName), cancellationToken));
 }
Example #11
0
 ILSpyUnresolvedFile(DecompiledTypeReference name)
 {
     this.name = name;
     FileName  = name.ToFileName();
 }
 public IViewContent CreateContentForFile(OpenedFile file)
 {
     return(new DecompiledViewContent(DecompiledTypeReference.FromFileName(file.FileName), ""));
 }
 static ILSpyUnresolvedFile DoDecompile(DecompiledTypeReference name, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(ILSpyUnresolvedFile.Create(name, CreateAstBuilder(name, cancellationToken)));
 }