[FIR] Build raw FIR for code fragments
This commit is contained in:
+31
-12
@@ -1088,23 +1088,28 @@ open class PsiRawFirBuilder(
|
|||||||
aliasSource = importDirective.alias?.nameIdentifier?.toFirSourceElement()
|
aliasSource = importDirective.alias?.nameIdentifier?.toFirSourceElement()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (declaration in file.declarations) {
|
|
||||||
declarations += when (declaration) {
|
if (file is KtCodeFragment) {
|
||||||
is KtScript -> {
|
declarations += convertCodeFragment(file)
|
||||||
require(file.declarations.size == 1) { "Expect the script to be the only declaration in the file $name" }
|
} else {
|
||||||
convertScript(declaration, this.name) {
|
for (declaration in file.declarations) {
|
||||||
for (configurator in baseSession.extensionService.scriptConfigurators) {
|
declarations += when (declaration) {
|
||||||
with(configurator) { configure(this@buildFile) }
|
is KtScript -> {
|
||||||
|
require(file.declarations.size == 1) { "Expect the script to be the only declaration in the file $name" }
|
||||||
|
convertScript(declaration, this.name) {
|
||||||
|
for (configurator in baseSession.extensionService.scriptConfigurators) {
|
||||||
|
with(configurator) { configure(this@buildFile) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
is KtDestructuringDeclaration -> buildErrorTopLevelDestructuringDeclaration(declaration.toFirSourceElement())
|
||||||
|
else -> declaration.convert()
|
||||||
}
|
}
|
||||||
is KtDestructuringDeclaration -> buildErrorTopLevelDestructuringDeclaration(declaration.toFirSourceElement())
|
|
||||||
else -> declaration.convert()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (danglingModifierList in file.danglingModifierLists) {
|
for (danglingModifierList in file.danglingModifierLists) {
|
||||||
declarations += buildErrorTopLevelDeclarationForDanglingModifierList(danglingModifierList)
|
declarations += buildErrorTopLevelDeclarationForDanglingModifierList(danglingModifierList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1157,6 +1162,20 @@ open class PsiRawFirBuilder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun convertCodeFragment(file: KtCodeFragment): FirCodeFragment {
|
||||||
|
return buildCodeFragment {
|
||||||
|
source = file.toFirSourceElement()
|
||||||
|
moduleData = baseModuleData
|
||||||
|
origin = FirDeclarationOrigin.Source
|
||||||
|
symbol = FirCodeFragmentSymbol()
|
||||||
|
block = when (file) {
|
||||||
|
is KtExpressionCodeFragment -> file.getContentElement()?.toFirBlock() ?: buildEmptyExpressionBlock()
|
||||||
|
is KtBlockCodeFragment -> configureBlockWithoutBuilding(file.getContentElement()).build()
|
||||||
|
else -> error("Unexpected code fragment type: " + file::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: if no original FirScript is passed here, the invalid script could be constructed, consider throwing an error
|
// TODO: if no original FirScript is passed here, the invalid script could be constructed, consider throwing an error
|
||||||
override fun visitScript(script: KtScript, data: FirElement?): FirElement {
|
override fun visitScript(script: KtScript, data: FirElement?): FirElement {
|
||||||
val ktFile = script.containingKtFile
|
val ktFile = script.containingKtFile
|
||||||
|
|||||||
Reference in New Issue
Block a user