IR: first smoke test

This commit is contained in:
Dmitry Petrov
2016-08-02 16:13:48 +03:00
committed by Dmitry Petrov
parent 520a3133bc
commit ad405f26fd
34 changed files with 1296 additions and 0 deletions
+4
View File
@@ -51,6 +51,10 @@
<module fileurl="file://$PROJECT_DIR$/idea-runner/idea-runner.iml" filepath="$PROJECT_DIR$/idea-runner/idea-runner.iml" group="ide" />
<module fileurl="file://$PROJECT_DIR$/idea/idea-test-framework/idea-test-framework.iml" filepath="$PROJECT_DIR$/idea/idea-test-framework/idea-test-framework.iml" group="ide" />
<module fileurl="file://$PROJECT_DIR$/compiler/preloader/instrumentation/instrumentation.iml" filepath="$PROJECT_DIR$/compiler/preloader/instrumentation/instrumentation.iml" group="compiler/cli" />
<module fileurl="file://$PROJECT_DIR$/compiler/ir/ir.backend.jvm/ir.backend.jvm.iml" filepath="$PROJECT_DIR$/compiler/ir/ir.backend.jvm/ir.backend.jvm.iml" group="compiler/ir" />
<module fileurl="file://$PROJECT_DIR$/compiler/ir/ir.psi2ir/ir.psi2ir.iml" filepath="$PROJECT_DIR$/compiler/ir/ir.psi2ir/ir.psi2ir.iml" group="compiler/ir" />
<module fileurl="file://$PROJECT_DIR$/compiler/ir/ir.tests/ir.tests.iml" filepath="$PROJECT_DIR$/compiler/ir/ir.tests/ir.tests.iml" group="compiler/ir" />
<module fileurl="file://$PROJECT_DIR$/compiler/ir/ir.tree/ir.tree.iml" filepath="$PROJECT_DIR$/compiler/ir/ir.tree/ir.tree.iml" group="compiler/ir" />
<module fileurl="file://$PROJECT_DIR$/j2k/j2k.iml" filepath="$PROJECT_DIR$/j2k/j2k.iml" group="j2k" />
<module fileurl="file://$PROJECT_DIR$/plugins/java-model-wrappers/java-model-wrappers.iml" filepath="$PROJECT_DIR$/plugins/java-model-wrappers/java-model-wrappers.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/jps-plugin/jps-plugin.iml" filepath="$PROJECT_DIR$/jps-plugin/jps-plugin.iml" group="ide/jps" />
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="ir.tree" />
</component>
</module>
@@ -0,0 +1,19 @@
/*
* 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.xbackend.jvm
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="frontend" />
<orderEntry type="module" module-name="ir.tree" />
</component>
</module>
@@ -0,0 +1,36 @@
/*
* 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.psi2ir
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrFileImpl
import org.jetbrains.kotlin.ir.declarations.IrModule
import org.jetbrains.kotlin.psi.KtFile
import java.util.*
class IrElementFactory(val irModule: IrModule, val sourceManager: PsiSourceManager) {
val ktFileToIrFile = LinkedHashMap<KtFile, IrFile>()
fun createIrFile(ktFile: KtFile, descriptor: PackageFragmentDescriptor): IrFile {
val fileEntry = sourceManager.getOrCreateFileEntry(ktFile)
val irFile = IrFileImpl(fileEntry.getRootSourceLocation(), irModule, fileEntry.getRecognizableName(), fileEntry, descriptor)
ktFileToIrFile.put(ktFile, irFile)
return irFile
}
}
@@ -0,0 +1,133 @@
/*
* 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.psi2ir
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrDummyBody
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
interface IrGenerator {
val context: IrGeneratorContext
operator fun <K, V : Any> ReadOnlySlice<K, V>.get(key: K): V? =
context.bindingContext[this, key]
}
interface IrDeclarationGenerator : IrGenerator {
val irDeclaration: IrDeclaration
val parent: IrDeclarationGenerator?
}
class IrModuleGenerator(override val context: IrGeneratorContext) : IrDeclarationGenerator {
override val irDeclaration: IrModule get() = context.irModule
override val parent: IrDeclarationGenerator? get() = null
fun generateModuleContent() {
for (ktFile in context.inputFiles) {
val packageFragmentDescriptor = BindingContext.FILE_TO_PACKAGE_FRAGMENT[ktFile] ?: TODO("Handle unresolved code")
val irFile = context.irElementFactory.createIrFile(ktFile, packageFragmentDescriptor)
irDeclaration.addFile(irFile)
val generator = IrFileGenerator(context, ktFile, irFile, this)
generator.generateFileContent()
}
}
}
abstract class IrDeclarationGeneratorBase(
override val context: IrGeneratorContext,
override val irDeclaration: IrDeclaration,
override val parent: IrDeclarationGenerator,
val file: PsiSourceManager.PsiFileEntry
) : IrDeclarationGenerator {
fun generateAnnotationEntries(annotationEntries: List<KtAnnotationEntry>) {
// TODO create IrAnnotation's for each KtAnnotationEntry
}
fun generateMemberDeclaration(ktDeclaration: KtDeclaration, containingDeclaration: IrCompoundDeclaration) {
when (ktDeclaration) {
is KtNamedFunction ->
generateFunctionDeclaration(ktDeclaration, containingDeclaration)
is KtProperty ->
generatePropertyDeclaration(ktDeclaration, containingDeclaration)
is KtClassOrObject ->
TODO("classOrObject")
is KtTypeAlias ->
TODO("typealias")
}
}
fun generateFunctionDeclaration(ktNamedFunction: KtNamedFunction, containingDeclaration: IrCompoundDeclaration) {
val sourceLocation = file.getSourceLocationForElement(ktNamedFunction)
val functionDescriptor = BindingContext.FUNCTION[ktNamedFunction] ?: TODO("unresolved fun")
val body = generateExpressionBody(ktNamedFunction.bodyExpression ?: TODO("function without body expression"))
val irFunction = IrFunctionImpl(sourceLocation, containingDeclaration, functionDescriptor, body)
containingDeclaration.addChildDeclaration(irFunction)
}
fun generatePropertyDeclaration(ktProperty: KtProperty, containingDeclaration: IrCompoundDeclaration) {
val sourceLocation = file.getSourceLocationForElement(ktProperty)
val variableDescriptor = BindingContext.VARIABLE[ktProperty] ?: TODO("unresolved property")
val propertyDescriptor = variableDescriptor as? PropertyDescriptor ?: TODO("not a property?")
if (ktProperty.hasDelegate()) TODO("handle delegated property")
val initializer = ktProperty.initializer?.let { generateExpressionBody(it) }
val irProperty = IrSimplePropertyImpl(sourceLocation, containingDeclaration, propertyDescriptor, initializer)
containingDeclaration.addChildDeclaration(irProperty)
val irGetter: IrPropertyGetter? = ktProperty.getter?.let { ktGetter ->
val getterLocation = file.getSourceLocationForElement(ktGetter)
val accessorDescriptor = BindingContext.PROPERTY_ACCESSOR[ktGetter] ?: TODO("unresolved getter")
val getterDescriptor = accessorDescriptor as? PropertyGetterDescriptor ?: TODO("not a getter?")
val getterBody = generateExpressionBody(ktGetter.bodyExpression ?: TODO("default getter"))
IrPropertyGetterImpl(getterLocation, irProperty, getterDescriptor, getterBody)
}
val irSetter: IrPropertySetter? = ktProperty.setter?.let { ktSetter ->
val getterLocation = file.getSourceLocationForElement(ktSetter)
val accessorDescriptor = BindingContext.PROPERTY_ACCESSOR[ktSetter] ?: TODO("unresolved setter")
val setterDescriptor = accessorDescriptor as? PropertySetterDescriptor ?: TODO("not a setter?")
val getterBody = generateExpressionBody(ktSetter.bodyExpression ?: TODO("default setter"))
IrPropertySetterImpl(getterLocation, irProperty, setterDescriptor, getterBody)
}
irProperty.initialize(irGetter, irSetter)
}
fun generateExpressionBody(ktExpression: KtExpression): IrBody {
val sourceLocation = file.getSourceLocationForElement(ktExpression)
// TODO
return IrDummyBody(sourceLocation)
}
}
class IrFileGenerator(
context: IrGeneratorContext,
val ktFile: KtFile,
override val irDeclaration: IrFile,
override val parent: IrModuleGenerator
) : IrDeclarationGeneratorBase(context, irDeclaration, parent, irDeclaration.fileEntry as PsiSourceManager.PsiFileEntry) {
fun generateFileContent() {
generateAnnotationEntries(ktFile.annotationEntries)
for (topLevelDeclaration in ktFile.declarations) {
generateMemberDeclaration(topLevelDeclaration, irDeclaration)
}
}
}
@@ -0,0 +1,34 @@
/*
* 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.psi2ir
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrModule
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
class IrGeneratorContext(
val inputFiles: List<KtFile>,
val irModule: IrModule,
val bindingContext: BindingContext
) {
val moduleDescriptor: ModuleDescriptor get() = irModule.descriptor
val sourceManager = PsiSourceManager()
val irElementFactory = IrElementFactory(irModule, sourceManager)
}
@@ -0,0 +1,67 @@
/*
* 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.psi2ir
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.SourceLocationManager
import org.jetbrains.kotlin.ir.fileIndex
import org.jetbrains.kotlin.ir.fileOffset
import java.util.*
class PsiSourceManager : SourceLocationManager {
class PsiFileEntry (val index: Int, val file: PsiFile) : SourceLocationManager.FileEntry {
private val document = file.viewProvider.document
override fun getLineNumber(sourceLocation: SourceLocation): Int =
document?.getLineNumber(sourceLocation.fileOffset) ?: -1
override fun getColumnNumber(sourceLocation: SourceLocation): Int =
document?.getLineStartOffset(sourceLocation.fileOffset) ?: -1
fun getRootSourceLocation(): SourceLocation =
SourceLocation(index, 0)
fun getSourceLocationForElement(element: PsiElement): SourceLocation =
SourceLocation(index, element.textOffset)
fun getRecognizableName(): String = file.virtualFile?.path ?: file.name
override fun toString(): String = "#$index: ${getRecognizableName()}"
}
private val fileEntries = ArrayList<PsiFileEntry>()
private val fileEntriesByPsiFile = HashMap<PsiFile, PsiFileEntry>()
override fun getFileEntry(sourceLocation: Long): PsiFileEntry? =
fileEntries.getOrNull(sourceLocation.fileIndex)
fun createFileEntry(psiFile: PsiFile): PsiFileEntry {
if (psiFile in fileEntriesByPsiFile) error("PsiFileEntry is already created for $psiFile")
val newEntry = PsiFileEntry(fileEntries.size, psiFile)
fileEntries.add(newEntry)
fileEntriesByPsiFile[psiFile] = newEntry
return newEntry
}
fun getOrCreateFileEntry(psiFile: PsiFile): PsiFileEntry =
fileEntriesByPsiFile.getOrElse(psiFile) { createFileEntry(psiFile) }
fun getFileEntry(psiFile: PsiFile): PsiFileEntry? = fileEntriesByPsiFile[psiFile]
}
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="tests-common" scope="TEST" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="module" module-name="cli" scope="TEST" />
<orderEntry type="module" module-name="frontend" scope="TEST" />
<orderEntry type="module" module-name="ir.tree" scope="TEST" />
<orderEntry type="module" module-name="ir.psi2ir" scope="TEST" />
<orderEntry type="library" scope="TEST" name="junit-4.12" level="project" />
</component>
</module>
@@ -0,0 +1,51 @@
/*
* 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
import org.jetbrains.kotlin.codegen.CodegenTestCase
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleImpl
import org.jetbrains.kotlin.psi2ir.IrGeneratorContext
import org.jetbrains.kotlin.psi2ir.IrModuleGenerator
import org.jetbrains.kotlin.resolve.AnalyzingUtils
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.test.ConfigurationKind
import java.io.File
abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>, javaFilesDir: File?) {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, javaFilesDir)
loadMultiFiles(files)
doTest(wholeFile, files)
}
protected abstract fun doTest(wholeFile: File, testFiles: List<TestFile>)
protected fun generateIrFilesAsSingleModule(testFiles: List<TestFile>): Map<TestFile, IrFile> {
assert(myFiles != null) { "myFiles not initialized" }
assert(myEnvironment != null) { "myEnvironment not initialized" }
val analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(myFiles.psiFiles, myEnvironment)
analysisResult.throwIfError()
AnalyzingUtils.throwExceptionOnErrors(analysisResult.bindingContext)
val irModule = IrModuleImpl(analysisResult.moduleDescriptor)
val irGeneratorContext = IrGeneratorContext(myFiles.psiFiles, irModule, analysisResult.bindingContext)
IrModuleGenerator(irGeneratorContext).generateModuleContent()
return testFiles.filter { it.name.endsWith(".kt") }.zip(irModule.files).toMap()
}
}
@@ -0,0 +1,101 @@
/*
* 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
import com.intellij.openapi.util.text.StringUtil
import junit.framework.TestCase
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.utils.rethrow
import java.io.File
import java.io.FileWriter
import java.io.PrintWriter
import java.util.*
import java.util.regex.Pattern
abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
override fun doTest(wholeFile: File, testFiles: List<TestFile>) {
val dir = wholeFile.parentFile
for ((testFile, irFile) in generateIrFilesAsSingleModule(testFiles)) {
doTestIrFileAgainstExpectations(dir, testFile, irFile)
}
}
protected fun doTestIrFileAgainstExpectations(dir: File, testFile: TestFile, irFile: IrFile) {
val expectations = parseExpectations(dir, testFile)
val irFileDump = irFile.dump()
expectations.irExpectedTextFile?.let { expectFile ->
KotlinTestUtils.assertEqualsToFile(expectFile, irFileDump)
}
val expected = StringBuilder()
val actual = StringBuilder()
for (expectation in expectations.regexps) {
expected.append(expectation.numberOfOccurrences).append(" ").append(expectation.needle).append("\n")
val actualCount = StringUtil.findMatches(irFileDump, Pattern.compile("(" + expectation.needle + ")")).size
actual.append(actualCount).append(" ").append(expectation.needle).append("\n")
}
try {
TestCase.assertEquals(irFileDump, expected.toString(), actual.toString())
}
catch (e: Throwable) {
println(irFileDump)
throw rethrow(e)
}
}
protected class Expectations(val irExpectedTextFile: File?, val regexps: List<RegexpInText>)
protected class RegexpInText(val numberOfOccurrences: Int, val needle: String) {
constructor(countStr: String, needle: String) : this(Integer.valueOf(countStr), needle)
}
companion object {
private val EXPECTED_OCCURRENCES_PATTERN = Regex("""^\s*//\s*(\d+)\s*(.*)$""")
private val EXPECT_TXT_PATTERN = Regex("""^\s*//\s*IR_FILE_TXT\s+(.*)$""")
private fun parseExpectations(dir: File, testFile: TestFile): Expectations {
var expectedTextFileName: String? = null
val regexps = ArrayList<RegexpInText>()
for (line in testFile.content.split("\n")) {
EXPECTED_OCCURRENCES_PATTERN.matchEntire(line)?.let { matchResult ->
regexps.add(RegexpInText(matchResult.groupValues[1], matchResult.groupValues[2]))
}
EXPECT_TXT_PATTERN.matchEntire(line)?.let { matchResult ->
expectedTextFileName = matchResult.groupValues[1]
}
}
val expectedTextFile: File? = expectedTextFileName?.let {
val textFile = File(dir, expectedTextFileName)
if (!textFile.exists()) {
TestCase.assertTrue("Can't create an IR expected text file: ${textFile.absolutePath}", textFile.createNewFile())
PrintWriter(FileWriter(textFile)).use {
it.println("$expectedTextFileName: new IR expected text file for ${testFile.name}")
}
}
textFile
}
return Expectations(expectedTextFile, regexps)
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="frontend" />
</component>
</module>
@@ -0,0 +1,27 @@
/*
* 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
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrElement {
val sourceLocation: SourceLocation
fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R
fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D): Unit
}
abstract class IrElementBase(override val sourceLocation: SourceLocation) : IrElement
@@ -0,0 +1,32 @@
/*
* 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
typealias SourceLocation = Long
fun SourceLocation(index: Int, offset: Int) =
(index.toLong() shl 32) + offset.toLong()
const val NO_LOCATION: SourceLocation = -1L
const val UNDEFINED_INDEX: Int = -1
const val UNDEFINED_OFFSET: Int = -1
val SourceLocation.fileIndex: Int
get() = if (this == NO_LOCATION) UNDEFINED_INDEX else (this ushr 32).toInt()
val SourceLocation.fileOffset: Int
get() = if (this == NO_LOCATION) UNDEFINED_OFFSET else (this and 0xFFFFFFFFL).toInt()
@@ -0,0 +1,28 @@
/*
* 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
import org.jetbrains.kotlin.ir.SourceLocation
interface SourceLocationManager {
interface FileEntry {
fun getLineNumber(sourceLocation: SourceLocation): Int
fun getColumnNumber(sourceLocation: SourceLocation): Int
}
fun getFileEntry(sourceLocation: SourceLocation): FileEntry?
}
@@ -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.declarations
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrClass : IrCompoundDeclaration {
override val descriptor: ClassDescriptor
}
class IrClassImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration,
override val descriptor: ClassDescriptor
) : IrCompoundDeclarationBase(sourceLocation, containingDeclaration), IrClass {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitClass(this, data)
}
@@ -0,0 +1,63 @@
/*
* 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.declarations
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.util.*
interface IrDeclaration : IrElement {
val descriptor: DeclarationDescriptor
val containingDeclaration: IrDeclaration?
}
interface IrCompoundDeclaration : IrDeclaration {
val childDeclarations: List<IrDeclaration>
fun addChildDeclaration(child: IrDeclaration)
}
interface IrDeclarationNonRoot : IrDeclaration {
override val containingDeclaration: IrDeclaration
}
abstract class IrDeclarationBase(
sourceLocation: SourceLocation,
override val containingDeclaration: IrDeclaration?
) : IrElementBase(sourceLocation), IrDeclaration
abstract class IrDeclarationNonRootBase(
sourceLocation: SourceLocation,
override val containingDeclaration: IrDeclaration
) : IrElementBase(sourceLocation), IrDeclarationNonRoot
abstract class IrCompoundDeclarationBase(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration?
) : IrDeclarationBase(sourceLocation, containingDeclaration), IrCompoundDeclaration {
override val childDeclarations: MutableList<IrDeclaration> = ArrayList()
override fun addChildDeclaration(child: IrDeclaration) {
childDeclarations.add(child)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
childDeclarations.forEach { it.accept(visitor, data) }
}
}
@@ -0,0 +1,39 @@
/*
* 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.declarations
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.SourceLocationManager
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrFile : IrCompoundDeclaration {
val name: String
val fileEntry: SourceLocationManager.FileEntry
override val descriptor: PackageFragmentDescriptor
}
class IrFileImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrModule,
override val name: String,
override val fileEntry: SourceLocationManager.FileEntry,
override val descriptor: PackageFragmentDescriptor
) : IrCompoundDeclarationBase(sourceLocation, containingDeclaration), IrFile {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitFile(this, data)
}
@@ -0,0 +1,49 @@
/*
* 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.declarations
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrBody : IrElement
interface IrFunction : IrDeclarationNonRoot {
override val descriptor: FunctionDescriptor
val body: IrBody
}
abstract class IrFunctionBase(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration
) : IrDeclarationNonRootBase(sourceLocation, containingDeclaration), IrFunction {
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
body.accept(visitor, data)
}
}
class IrFunctionImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration,
override val descriptor: FunctionDescriptor,
override val body: IrBody
) : IrFunctionBase(sourceLocation, containingDeclaration) {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitFunction(this, data)
}
@@ -0,0 +1,50 @@
/*
* 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.declarations
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.NO_LOCATION
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.util.*
interface IrModule : IrCompoundDeclaration {
override val descriptor: ModuleDescriptor
val files: List<IrFile>
fun addFile(file: IrFile)
}
class IrModuleImpl(override val descriptor: ModuleDescriptor) : IrDeclarationBase(NO_LOCATION, null), IrModule {
override val files: MutableList<IrFile> = ArrayList()
override val childDeclarations: List<IrDeclaration> get() = files
override fun addFile(file: IrFile) {
files.add(file)
}
override fun addChildDeclaration(child: IrDeclaration) {
if (child !is IrFile) throw IllegalArgumentException("Only IrFile can be contained in IrModule, got $child")
addFile(child)
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitModule(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
files.forEach { it.accept(visitor, data) }
}
}
@@ -0,0 +1,84 @@
/*
* 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.declarations
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrProperty : IrDeclarationNonRoot {
override val descriptor: PropertyDescriptor
val getter: IrPropertyGetter?
val setter: IrPropertySetter?
}
interface IrSimpleProperty : IrProperty {
val valueInitializer: IrBody?
}
interface IrDelegatedProperty : IrProperty {
val delegateInitializer: IrBody
}
abstract class IrPropertyBase(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration,
override val descriptor: PropertyDescriptor
) : IrDeclarationNonRootBase(sourceLocation, containingDeclaration), IrProperty {
override var getter: IrPropertyGetter? = null
override var setter: IrPropertySetter? = null
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
getter?.accept(visitor, data)
setter?.accept(visitor, data)
}
fun initialize(getter: IrPropertyGetter?, setter: IrPropertySetter?) {
this.getter = getter
this.setter = setter
}
}
class IrSimplePropertyImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration,
descriptor: PropertyDescriptor,
override val valueInitializer: IrBody?
) : IrPropertyBase(sourceLocation, containingDeclaration, descriptor), IrSimpleProperty {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitSimpleProperty(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
valueInitializer?.accept(visitor, data)
super.acceptChildren(visitor, data)
}
}
class IrDelegatedPropertyImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrDeclaration,
descriptor: PropertyDescriptor,
override val delegateInitializer: IrBody
) : IrPropertyBase(sourceLocation, containingDeclaration, descriptor), IrDelegatedProperty {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitDelegatedProperty(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
delegateInitializer.accept(visitor, data)
super.acceptChildren(visitor, data)
}
}
@@ -0,0 +1,62 @@
/*
* 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.declarations
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrPropertyAccessor : IrFunction {
override val descriptor: PropertyAccessorDescriptor
val property: IrProperty get() = containingDeclaration as IrProperty
}
interface IrPropertyGetter : IrPropertyAccessor {
override val descriptor: PropertyGetterDescriptor
}
interface IrPropertySetter : IrPropertyAccessor {
override val descriptor: PropertySetterDescriptor
}
abstract class IrPropertyAccessorBase(
sourceLocation: SourceLocation,
containingDeclaration: IrProperty,
override val body: IrBody
) : IrFunctionBase(sourceLocation, containingDeclaration), IrPropertyAccessor
class IrPropertyGetterImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrProperty,
override val descriptor: PropertyGetterDescriptor,
body: IrBody
) : IrPropertyAccessorBase(sourceLocation, containingDeclaration, body), IrPropertyGetter {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertyGetter(this, data)
}
class IrPropertySetterImpl(
sourceLocation: SourceLocation,
containingDeclaration: IrProperty,
override val descriptor: PropertySetterDescriptor,
body: IrBody
) : IrPropertyAccessorBase(sourceLocation, containingDeclaration, body), IrPropertySetter {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertySetter(this, data)
}
@@ -0,0 +1,30 @@
/*
* 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.expressions
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.declarations.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrDummyBody(override val sourceLocation: SourceLocation) : IrBody {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitElement(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
// No children
}
}
@@ -0,0 +1,22 @@
/*
* 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.expressions
import org.jetbrains.kotlin.ir.IrElement
interface IrExpression : IrElement
@@ -0,0 +1,40 @@
/*
* 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.util
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.utils.Printer
fun IrDeclaration.dump(): String {
val sb = StringBuilder()
accept(DumpIrTreeVisitor(sb), null)
return sb.toString()
}
class DumpIrTreeVisitor(out: Appendable): IrElementVisitorVoid {
val printer = Printer(out, " ")
val elementRenderer = RenderIrElementVisitor()
override fun visitElement(element: IrElement) {
printer.println(element.accept(elementRenderer, null))
printer.pushIndent()
element.acceptChildren(this, null)
printer.popIndent()
}
}
@@ -0,0 +1,65 @@
/*
* 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.util
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitElement(element: IrElement, data: Nothing?): String =
"??? ${element.javaClass.simpleName}"
override fun visitDeclaration(declaration: IrDeclaration, data: Nothing?): String =
"??? ${declaration.javaClass.simpleName} ${declaration.descriptor.name}"
override fun visitFile(declaration: IrFile, data: Nothing?): String =
"IrFile ${declaration.name}"
override fun visitFunction(declaration: IrFunction, data: Nothing?): String =
"IrFunction ${declaration.renderDescriptor()}"
override fun visitProperty(declaration: IrProperty, data: Nothing?): String =
"IrProperty ${declaration.renderDescriptor()}"
override fun visitPropertyGetter(declaration: IrPropertyGetter, data: Nothing?): String =
"IrPropertyGetter ${declaration.renderDescriptor()}"
override fun visitPropertySetter(declaration: IrPropertySetter, data: Nothing?): String =
"IrPropertySetter ${declaration.renderDescriptor()}"
override fun visitExpression(expression: IrExpression, data: Nothing?): String =
expression.javaClass.simpleName
companion object {
private val DESCRIPTOR_RENDERER = DescriptorRenderer.withOptions {
withDefinedIn = false
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE
includePropertyConstant = true
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
verbose = true
modifiers = DescriptorRendererModifier.ALL
}
private fun IrDeclaration.renderDescriptor(): String = DESCRIPTOR_RENDERER.render(descriptor)
}
}
@@ -0,0 +1,39 @@
/*
* 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.visitors
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
interface IrElementVisitor<out R, in D> {
fun visitElement(element: IrElement, data: D): R
fun visitDeclaration(declaration: IrDeclaration, data: D): R = visitElement(declaration, data)
fun visitCompoundDeclaration(declaration: IrCompoundDeclaration, data: D): R = visitDeclaration(declaration, data)
fun visitModule(declaration: IrModule, data: D): R = visitCompoundDeclaration(declaration, data)
fun visitFile(declaration: IrFile, data: D): R = visitCompoundDeclaration(declaration, data)
fun visitClass(declaration: IrClass, data: D): R = visitCompoundDeclaration(declaration, data)
fun visitFunction(declaration: IrFunction, data: D): R = visitDeclaration(declaration, data)
fun visitPropertyGetter(declaration: IrPropertyGetter, data: D): R = visitFunction(declaration, data)
fun visitPropertySetter(declaration: IrPropertySetter, data: D): R = visitFunction(declaration, data)
fun visitProperty(declaration: IrProperty, data: D): R = visitDeclaration(declaration, data)
fun visitSimpleProperty(declaration: IrSimpleProperty, data: D): R = visitProperty(declaration, data)
fun visitDelegatedProperty(declaration: IrDelegatedProperty, data: D): R = visitProperty(declaration, data)
fun visitExpression(expression: IrExpression, data: D): R = visitElement(expression, data)
}
@@ -0,0 +1,45 @@
/*
* 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.visitors
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
interface IrElementVisitorVoid : IrElementVisitor<Unit, Nothing?> {
fun visitElement(element: IrElement)
fun visitDeclaration(declaration: IrDeclaration) = visitElement(declaration)
fun visitCompoundDeclaration(declaration: IrCompoundDeclaration) = visitDeclaration(declaration)
fun visitModule(declaration: IrModule) = visitCompoundDeclaration(declaration)
fun visitFile(declaration: IrFile) = visitCompoundDeclaration(declaration)
fun visitClass(declaration: IrClass) = visitCompoundDeclaration(declaration)
fun visitFunction(declaration: IrFunction) = visitDeclaration(declaration)
fun visitPropertyGetter(declaration: IrPropertyGetter) = visitFunction(declaration)
fun visitPropertySetter(declaration: IrPropertySetter) = visitFunction(declaration)
fun visitProperty(declaration: IrProperty) = visitDeclaration(declaration)
// Delegating methods from IrDeclarationVisitor
override fun visitElement(element: IrElement, data: Nothing?) = visitElement(element)
override fun visitDeclaration(declaration: IrDeclaration, data: Nothing?) = visitDeclaration(declaration)
override fun visitCompoundDeclaration(declaration: IrCompoundDeclaration, data: Nothing?) = visitCompoundDeclaration(declaration)
override fun visitModule(declaration: IrModule, data: Nothing?) = visitModule(declaration)
override fun visitFile(declaration: IrFile, data: Nothing?) = visitFile(declaration)
override fun visitClass(declaration: IrClass, data: Nothing?) = visitClass(declaration)
override fun visitFunction(declaration: IrFunction, data: Nothing?) = visitFunction(declaration)
override fun visitPropertyGetter(declaration: IrPropertyGetter, data: Nothing?) = visitPropertyGetter(declaration)
override fun visitPropertySetter(declaration: IrPropertySetter, data: Nothing?) = visitPropertySetter(declaration)
override fun visitProperty(declaration: IrProperty, data: Nothing?) = visitProperty(declaration)
}
+17
View File
@@ -0,0 +1,17 @@
fun testFun() {}
val testSimpleVal = 1
val testValWithGetter: Int get() = 42
var testSimpleVar = 2
var testVarWithAccessors: Int
get() = 42
set(v) {}
// 1 IrFunction public fun testFun
// 1 IrProperty public val testSimpleVal
// 1 IrProperty public val testValWithGetter
// 2 IrPropertyGetter
// 1 IrProperty public var testSimpleVar
// 1 IrProperty public var testVarWithAccessors
// 1 IrPropertyGetter
// IR_FILE_TXT smoke.txt
+15
View File
@@ -0,0 +1,15 @@
IrFile /smoke.kt
IrFunction public fun testFun(): kotlin.Unit
??? IrDummyBody
IrProperty public val testSimpleVal: kotlin.Int = 1
??? IrDummyBody
IrProperty public val testValWithGetter: kotlin.Int
IrPropertyGetter public fun <get-testValWithGetter>(): kotlin.Int
??? IrDummyBody
IrProperty public var testSimpleVar: kotlin.Int
??? IrDummyBody
IrProperty public var testVarWithAccessors: kotlin.Int
IrPropertyGetter public fun <get-testVarWithAccessors>(): kotlin.Int
??? IrDummyBody
IrPropertySetter public fun <set-testVarWithAccessors>(/*0*/ v: kotlin.Int): kotlin.Unit
??? IrDummyBody
+1
View File
@@ -66,5 +66,6 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module" module-name="ir.tests" scope="TEST" />
</component>
</module>
@@ -0,0 +1,43 @@
/*
* 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;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/ir/irText")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
public void testAllFilesPresentInIrText() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("smoke.kt")
public void testSmoke() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/smoke.kt");
doTest(fileName);
}
}
+1
View File
@@ -40,5 +40,6 @@
<orderEntry type="module" module-name="idea-android-output-parser" scope="TEST" />
<orderEntry type="module" module-name="idea-maven" scope="TEST" />
<orderEntry type="module" module-name="uast-kotlin" scope="TEST" />
<orderEntry type="module" module-name="ir.tests" scope="TEST" />
</component>
</module>
@@ -121,6 +121,7 @@ import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest
import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest
import org.jetbrains.kotlin.idea.stubs.AbstractStubBuilderTest
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
import org.jetbrains.kotlin.ir.AbstractIrTextTestCase
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
@@ -239,6 +240,10 @@ fun main(args: Array<String>) {
model("codegen/bytecodeText")
}
testClass<AbstractIrTextTestCase>() {
model("ir/irText")
}
testClass<AbstractBytecodeListingTest>() {
model("codegen/bytecodeListing")
}