Parsing decompiled source using target language's extensions

Answered

I'm able to decompile the .beam files used on the Erlang BEAM VM to faked Elixir code, using

 

<filetype.decompiler filetype="BEAM" implementationClass="org.elixir_lang.beam.Decompiler"/>

 

but, the text is shown as just plain text.  How do I get the editor tab to highlight and annotate the code from the decompiler so it works like normal Elixir code from .ex and .exs files?  I'd also like to index the decompiled code so that I can do Go To Declaration to the decompiled modules and functions in those modules.

4 comments
Comment actions Permalink

For basic highlighting, you need to implement `SyntaxHighlighterProvider` and register it via `syntaxHighlighter` EP.

1
Comment actions Permalink

For indexing, there is `FileBasedIndexExtension` (EP: `fileBasedIndex`). But to make "Go To Declaration" work you will need to change existing resolve code to look into the index.

0
Comment actions Permalink

I have the syntax highlighting working using the syntax highlighter, but as you probably know, the syntax highlighter only handles highlighting lexer tokens.

<syntaxHighlighter key="BEAM" factoryClass="org.elixir_lang.ElixirSyntaxHighlighterFactory"/>

To get full highlighting on normal source files I have a bunch of annotators, but the problem is that the annotator extensions expect a `language` attribute and the compiled .beam files don't have a language since it's a binary format (so a FileType, but not a LanguageFileType).  

How do I use these annotators

<annotator implementationClass="org.elixir_lang.annonator.Alias" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Atom" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Callable" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.EscapeSequence" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Kernel" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Map" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.ModuleAttribute" language="Elixir"/>

against the decompiled source?

 

I ended up using the "mirror" system that Java .class decompilation uses, so I was able to reuse the structure view from the normal source files, by asking the compiled BeamFileImpl for it's mirror, which gave me a normal ElixirFile like a normal source file.

<structureViewBuilder key="BEAM" factoryClass="org.elixir_lang.beam.StructureViewBuilderProvider"/>

 Can I leverage the mirror system for annotators?

 

 

0
Comment actions Permalink

Sorry, don't have a ready answer. AFAIK annotators are invoked by `GeneralHighlightingPass`, and IDEA omits certain passes for binary files (see `TextEditorBackgroundHighlighter.getPasses()`).

You may try to register a custom highlighting pass for BEAM files and make it call existing annotators.

0

Please sign in to leave a comment.