IrTypes: generateAnnotationConstructorCall -> ConstantValueGenerator

This commit is contained in:
Dmitry Petrov
2018-05-31 15:07:53 +03:00
parent 3a11767fae
commit a9d0e6d3da
5 changed files with 57 additions and 72 deletions
@@ -20,15 +20,15 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.ir.util.AnnotationGenerator
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile
class ModuleGenerator(override val context: GeneratorContext) : Generator {
private val annotationGenerator = AnnotationGenerator(context.moduleDescriptor, context.symbolTable)
private val constantValueGenerator = ConstantValueGenerator(context.moduleDescriptor, context.symbolTable, null)
fun generateModuleFragment(ktFiles: Collection<KtFile>): IrModuleFragment =
generateModuleFragmentWithoutDependencies(ktFiles).also { irModule ->
@@ -60,7 +60,7 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
for (ktAnnotationEntry in ktFile.annotationEntries) {
val annotationDescriptor = getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry)
irFile.fileAnnotations.add(annotationDescriptor)
irFile.annotations.add(annotationGenerator.generateAnnotationConstructorCall(annotationDescriptor))
irFile.annotations.add(constantValueGenerator.generateAnnotationConstructorCall(annotationDescriptor))
}
for (ktDeclaration in ktFile.declarations) {
@@ -222,7 +222,7 @@ class StatementGenerator(
)
fun generateConstantExpression(expression: KtExpression, constant: CompileTimeConstant<*>): IrExpression =
ConstantValueGenerator(context.moduleDescriptor, context.symbolTable, null, null).generateConstantValueAsExpression(
ConstantValueGenerator(context.moduleDescriptor, context.symbolTable, null).generateConstantValueAsExpression(
expression.startOffset,
expression.endOffset,
constant.toConstantValue(getInferredTypeWithImplicitCastsOrFail(expression))