backend: untie IR builders from psi2ir generators
This commit is contained in:
committed by
SvyatoslavScherbina
parent
fa95d4d2a8
commit
9054a5eb5e
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.builders
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
|
|
||||||
|
// TODO: rename Generator* to IrGenerator* when contributing back to Kotlin.
|
||||||
|
|
||||||
|
interface Generator {
|
||||||
|
val context: GeneratorContext
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GeneratorWithScope : Generator {
|
||||||
|
val scope: Scope
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GeneratorContext {
|
||||||
|
val irBuiltIns: IrBuiltIns
|
||||||
|
val builtIns: KotlinBuiltIns get() = irBuiltIns.builtIns
|
||||||
|
}
|
||||||
+11
-20
@@ -16,19 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.builders
|
package org.jetbrains.kotlin.ir.builders
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
|
||||||
import org.jetbrains.kotlin.psi2ir.generators.Generator
|
|
||||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
|
||||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorWithScope
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -50,7 +43,7 @@ abstract class IrStatementsBuilder<out T : IrElement>(
|
|||||||
scope: Scope,
|
scope: Scope,
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int
|
endOffset: Int
|
||||||
) : IrBuilderWithScope(context, scope, startOffset, endOffset), GeneratorWithScope {
|
) : IrBuilderWithScope(context, scope, startOffset, endOffset) {
|
||||||
operator fun IrStatement.unaryPlus() {
|
operator fun IrStatement.unaryPlus() {
|
||||||
addStatement(this)
|
addStatement(this)
|
||||||
}
|
}
|
||||||
@@ -114,23 +107,21 @@ fun <T : IrBuilder> T.at(startOffset: Int, endOffset: Int): T {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : IrBuilder> T.at(psiElement: PsiElement): T {
|
inline fun GeneratorWithScope.irBlock(startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET,
|
||||||
this.startOffset = psiElement.startOffset
|
origin: IrStatementOrigin? = null,
|
||||||
this.endOffset = psiElement.endOffset
|
resultType: KotlinType? = null,
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun GeneratorWithScope.irBlock(ktElement: KtElement? = null, origin: IrStatementOrigin? = null, resultType: KotlinType? = null,
|
|
||||||
body: IrBlockBuilder.() -> Unit
|
body: IrBlockBuilder.() -> Unit
|
||||||
): IrExpression =
|
): IrExpression =
|
||||||
IrBlockBuilder(context, scope,
|
IrBlockBuilder(context, scope,
|
||||||
ktElement?.startOffset ?: UNDEFINED_OFFSET,
|
startOffset,
|
||||||
ktElement?.endOffset ?: UNDEFINED_OFFSET,
|
endOffset,
|
||||||
origin, resultType
|
origin, resultType
|
||||||
).block(body)
|
).block(body)
|
||||||
|
|
||||||
inline fun GeneratorWithScope.irBlockBody(ktElement: KtElement? = null, body: IrBlockBodyBuilder.() -> Unit) : IrBlockBody =
|
inline fun GeneratorWithScope.irBlockBody(startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET,
|
||||||
|
body: IrBlockBodyBuilder.() -> Unit
|
||||||
|
) : IrBlockBody =
|
||||||
IrBlockBodyBuilder(context, scope,
|
IrBlockBodyBuilder(context, scope,
|
||||||
ktElement?.startOffset ?: UNDEFINED_OFFSET,
|
startOffset,
|
||||||
ktElement?.endOffset ?: UNDEFINED_OFFSET
|
endOffset
|
||||||
).blockBody(body)
|
).blockBody(body)
|
||||||
-1
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
|
||||||
|
|
||||||
class IrMemberFunctionBuilder(
|
class IrMemberFunctionBuilder(
|
||||||
context: GeneratorContext,
|
context: GeneratorContext,
|
||||||
|
|||||||
Reference in New Issue
Block a user