Didier Villevalois
05/28/2022, 10:34 AMIrGenerationExtension
but at the level of the FIR (i.e. after semantic resolution but before the lowerings). I know that FIR is still in active development but maybe there are already something that I can use.
Thanks a lot to you all for any help you can provide me.raulraja
05/28/2022, 11:45 AMraulraja
05/28/2022, 11:46 AMFirDeclarationGenerationExtension
raulraja
05/28/2022, 11:47 AMmcpiroman
05/28/2022, 12:09 PMDidier Villevalois
05/28/2022, 1:02 PMdmitriy.novozhilov
05/29/2022, 9:35 AMDidier Villevalois
05/29/2022, 9:45 AMDidier Villevalois
05/29/2022, 9:49 AMdmitriy.novozhilov
05/29/2022, 9:51 AMDidier Villevalois
05/29/2022, 9:59 AMdmitriy.novozhilov
05/29/2022, 10:01 AMraulraja
05/29/2022, 10:03 AMraulraja
05/29/2022, 10:05 AMDidier Villevalois
05/29/2022, 10:17 AMKtExpression
node. In this library, is also defined a top-level function:
fun <T> quote(t: T): KtExpression = TODO("This should have been rewritten by our compiler plugin!")
Say i would have some user code like this:
import mylib.*
val someExpression = quote(1 + 1);
This would be rewritten by:
import mylib.*
val someExpression = KtBinaryExpression(
KtIntegerLiteralExpression(1),
BinaryOperator.PLUS,
KtIntegerLiteralExpression(1),
);
Please, forgive me, the AST classes are completely fictitious for now. I hope my intent is more clear.dmitriy.novozhilov
05/29/2022, 10:26 AMDidier Villevalois
05/29/2022, 10:27 AMdmitriy.novozhilov
05/29/2022, 10:28 AMDidier Villevalois
05/29/2022, 10:33 AMDidier Villevalois
05/29/2022, 10:38 AMDidier Villevalois
05/29/2022, 11:25 AM1+1
example was just to give a tiny example. I hope you understood what I meant. Is this more clear?dmitriy.novozhilov
05/30/2022, 7:14 AMParsing of Java source files up to Java 1.8 version (that runs with Java 1.6+)You can just depend on parser from
kotlin-compiler-embeddable
and call it programatically
An immutable abstract syntax tree with fluent mutatorsPSI and LighterAST are immutable by default in compiler. AFAIK there are some mutation API for PSI in Arrow-meta
Lexical preservation of whitespaces and commentsPSI supports it by default
Formatting of new (and already formatted) abstract syntax trees with formatting settingsPSI and IDEA supports it
[Experimental] Matching/Filtering/Searching of abstract syntax trees with patternsCheck Arrow-meta
[Experimental] Quasi-quotes of Java snippets to ease the building of new abstract syntax treesSame
Semantic analysis of abstract syntax treesIf you want to just observe results of compilation at some stage, then there are some different APIs for that •
AnalysisHandlerExtension
for K1 frontend
• IrGenerationExtension
for IR backends
• KSP (Kotlin Symbol Processing) for frontend-independent view
• For K2 (FIR) frontend there is no such API yet, but we are considering on adding it
A add-on mechanism to enable syntactic and semantic extensionsThere are already some extensions in Kotlin compiler, and I'm not sure about some other extension points. You can check one of threads above, where I gave links to documentation of existing FIR extensions. K1 and IR extensions are well described in some community articles
dmitriy.novozhilov
05/30/2022, 7:24 AMsomeExpression
will have KtExpression
type on frontend, then you can easily implement it on backed: just call parser for argument, build PSI for it, and create constructors call basing of PSI you get.
If you want to change type of someExpression
based on results of parsing of specific args, then it can not be reached by existing FIR API, because it flaws its design principles