This information contains all the required data relating to inferred types, type nullability, usages, calls, and so on.įor example, using this information we can understand that the variable is nullable and null-checks are redundant. In the end we should also mention the BindingContext - it is the extra data collected by Kotlin compiler. While currently FIR is still in the early stages of development, it will aid in the development of new analysis tools, that are tightly integrated into the compiler infrastructure. Usage of IR and compiler plugins can significantly reduce the complexity of static analysis compared to that using AST or PSI, and is especially important for analysis rules that require type resolution.įuture versions of Kotlin will also utilize a new frontend for IR, called Frontend IR (FIR). These plugins can help to analyze the code while possessing all the required contexts (such as imported methods, classes, and so on). IR also allows the creation of the common compiler plugin API. While reducing the complexity of the compiler infrastructure and splitting language-specific operations from platform-specific, Which are used to create platform specific builds. This new intermediate representation (also in a tree format) is designed to serve as a common representation for different compiler backends (JVM, JS or Native), Starting from version 1.4, Kotlin now has a new representation layer - a new Intermediate Representation (IR). It will be represented by the following PSI tree: This is an obvious implementation of a syntax tree written in Java and containing familiar methods, such as: Put simply, in Kotlin, AST is a high-level interface used to work with nodes of the tree, whereas PSI is a more specific implementation.ĪST nodes are represented with the special interface ASTNode. PSI contains functionality capable of working not only with high-level syntactical features, but with particular language specifics. Kotlin Compiler builds a simple Abstract Syntax Tree (AST) from the code and enriches it to a special extended AST, called Program Structure Interface PSI. And the main thing that should be done by compiler to process the code is to build proper intermediate representation. Kotlin compiler requires several stages to parse and preprocess the code. In this post we will briefly describe different Internal Representations provided by Kotlin compiler. Types of Internal Representation of Kotlin code
0 Comments
Leave a Reply. |