translator: print error message

This commit is contained in:
e5l
2016-08-09 17:01:38 +03:00
parent 7e08333cde
commit 2971ec6cd8
2 changed files with 8 additions and 17 deletions
@@ -4,8 +4,6 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -15,7 +13,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant
import org.kotlinnative.translator.exceptions.UnimplementedException
import org.kotlinnative.translator.llvm.* import org.kotlinnative.translator.llvm.*
import org.kotlinnative.translator.llvm.types.* import org.kotlinnative.translator.llvm.types.*
import java.util.* import java.util.*
@@ -32,7 +29,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
if (isBlock) { if (isBlock) {
expressionWalker(expr, scopeDepth) expressionWalker(expr, scopeDepth)
} else { } else {
var result = evaluateExpression(expr, scopeDepth)!! var result = evaluateExpression(expr, scopeDepth)!!
when (result) { when (result) {
is LLVMVariable -> { is LLVMVariable -> {
@@ -205,7 +201,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
return evaluateClassScopedDotExpression(clazz, selectorExpr, scopeDepth) return evaluateClassScopedDotExpression(clazz, selectorExpr, scopeDepth)
} }
private fun evaluateExtensionExpression(receiver: KtExpression, selector: KtCallExpression, scopeDepth: Int): LLVMSingleValue? { private fun evaluateExtensionExpression(receiver: KtExpression, selector: KtCallExpression, scopeDepth: Int): LLVMSingleValue? {
val receiverType = state.bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, receiver) val receiverType = state.bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, receiver)
val standardType = LLVMMapStandardType(receiverType!!.type!!) val standardType = LLVMMapStandardType(receiverType!!.type!!)
@@ -221,9 +216,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
} }
val args = mutableListOf(loadArgumentIfRequired(receiverExpression, typeThisArgument)) val args = mutableListOf(loadArgumentIfRequired(receiverExpression, typeThisArgument))
args.addAll(loadArgsIfRequired(names, extensionCodegen.args)) args.addAll(loadArgsIfRequired(names, extensionCodegen.args))
return evaluateFunctionCallExpression(LLVMVariable(extensionCodegen.fullName, extensionCodegen.returnType!!.type, scope = LLVMVariableScope()), args) return evaluateFunctionCallExpression(LLVMVariable(extensionCodegen.fullName, extensionCodegen.returnType!!.type, scope = LLVMVariableScope()), args)
} }
@@ -336,7 +329,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
return evaluateFunctionCallExpression(LLVMVariable(function, descriptor.returnType!!.type, scope = LLVMVariableScope()), args) return evaluateFunctionCallExpression(LLVMVariable(function, descriptor.returnType!!.type, scope = LLVMVariableScope()), args)
} }
if (state.classes.containsKey(name)) { if (state.classes.containsKey(name)) {
val descriptor = state.classes[name] ?: return null val descriptor = state.classes[name] ?: return null
val args = loadArgsIfRequired(names, descriptor.constructorFields) val args = loadArgsIfRequired(names, descriptor.constructorFields)
@@ -478,9 +470,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
private fun evaluatePostfixExpression(expr: KtPostfixExpression, scopeDepth: Int): LLVMSingleValue? { private fun evaluatePostfixExpression(expr: KtPostfixExpression, scopeDepth: Int): LLVMSingleValue? {
val operator = expr.operationToken val operator = expr.operationToken
val left = evaluateExpression(expr.baseExpression, scopeDepth) ?: throw UnsupportedOperationException("Wrong binary exception") val left = evaluateExpression(expr.baseExpression, scopeDepth) ?: throw UnsupportedOperationException("Wrong binary exception")
return executePostfixExpression(operator, expr.operationReference, left as LLVMVariable) return executePostfixExpression(operator, expr.operationReference, left as LLVMVariable)
} }
@@ -579,7 +569,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
} }
} }
private fun addPrimitiveBinaryOperation(operator: IElementType, referenceName: KtSimpleNameExpression?, firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMVariable { private fun addPrimitiveBinaryOperation(operator: IElementType, referenceName: KtSimpleNameExpression?, firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMVariable {
val firstNativeOp = codeBuilder.receiveNativeValue(firstOp) val firstNativeOp = codeBuilder.receiveNativeValue(firstOp)
val secondNativeOp = codeBuilder.receiveNativeValue(secondOp) val secondNativeOp = codeBuilder.receiveNativeValue(secondOp)
@@ -621,9 +610,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
private fun evaluateConstantExpression(expr: KtConstantExpression): LLVMConstant { private fun evaluateConstantExpression(expr: KtConstantExpression): LLVMConstant {
val expressionKotlinType = state.bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, expr)!!.type!! val expressionKotlinType = state.bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, expr)!!.type!!
val expressionValue = state.bindingContext.get(BindingContext.COMPILE_TIME_VALUE, expr)?.getValue(expressionKotlinType) val expressionValue = state.bindingContext.get(BindingContext.COMPILE_TIME_VALUE, expr)?.getValue(expressionKotlinType)
val type = LLVMMapStandardType(expressionKotlinType) val type = LLVMMapStandardType(expressionKotlinType)
return LLVMConstant(expressionValue?.toString() ?: "", type, pointer = 0) return LLVMConstant(expressionValue?.toString() ?: "", type, pointer = 0)
} }
@@ -695,6 +682,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
evaluateWhenItem(item, targetExpression, resultVariable, nextLabel, endLabel, item.isElse, scopeDepth + 1) evaluateWhenItem(item, targetExpression, resultVariable, nextLabel, endLabel, item.isElse, scopeDepth + 1)
codeBuilder.addComment("end new when item") codeBuilder.addComment("end new when item")
} }
codeBuilder.addComment("else branch of when expression") codeBuilder.addComment("else branch of when expression")
codeBuilder.markWithLabel(nextLabel) codeBuilder.markWithLabel(nextLabel)
codeBuilder.addUnconditionalJump(endLabel) codeBuilder.addUnconditionalJump(endLabel)
@@ -758,6 +746,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
codeBuilder.storeVariable(resultVariable, thenResultExpression ?: return null) codeBuilder.storeVariable(resultVariable, thenResultExpression ?: return null)
codeBuilder.addUnconditionalJump(endLabel) codeBuilder.addUnconditionalJump(endLabel)
codeBuilder.markWithLabel(elseLabel) codeBuilder.markWithLabel(elseLabel)
val elseResultExpression = evaluateExpression(elseExpression, scopeDepth + 1) val elseResultExpression = evaluateExpression(elseExpression, scopeDepth + 1)
codeBuilder.storeVariable(resultVariable, elseResultExpression ?: return null) codeBuilder.storeVariable(resultVariable, elseResultExpression ?: return null)
codeBuilder.addUnconditionalJump(endLabel) codeBuilder.addUnconditionalJump(endLabel)
@@ -815,7 +804,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
reference.pointer += 1 reference.pointer += 1
codeBuilder.storeNull(reference) codeBuilder.storeNull(reference)
variableManager.addVariable(identifier, reference, scopeDepth) variableManager.addVariable(identifier, reference, scopeDepth)
return null return null
} }
@@ -3,7 +3,10 @@ package org.kotlinnative.translator
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.* import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
@@ -37,7 +40,7 @@ class TranslationState(val environment: KotlinCoreEnvironment, val bindingContex
fun parseAndAnalyze(sources: List<String>, disposer: Disposable, arm: Boolean = false): TranslationState { fun parseAndAnalyze(sources: List<String>, disposer: Disposable, arm: Boolean = false): TranslationState {
val configuration = CompilerConfiguration() val configuration = CompilerConfiguration()
val messageCollector = GroupingMessageCollector(object : MessageCollector { val messageCollector = object : MessageCollector {
private var hasError = false private var hasError = false
override fun hasErrors(): Boolean = hasError override fun hasErrors(): Boolean = hasError
@@ -46,7 +49,7 @@ fun parseAndAnalyze(sources: List<String>, disposer: Disposable, arm: Boolean =
println("[report] $message") println("[report] $message")
hasError = severity.isError || hasError hasError = severity.isError || hasError
} }
}) }
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
configuration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME) configuration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)