use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class IntrinsicAssignmentTranslator method translateRightExpression.
private JsExpression translateRightExpression(TranslationContext context, KtBinaryExpression expression) {
JsExpression result = TranslationUtils.translateRightExpression(context, expression, rightBlock);
KotlinType leftType = context.bindingContext().getType(expression.getLeft());
KotlinType rightType = context.bindingContext().getType(expression.getRight());
if (rightType != null && KotlinBuiltIns.isCharOrNullableChar(rightType)) {
if (leftType != null && KotlinBuiltIns.isStringOrNullableString(leftType)) {
result = JsAstUtils.charToString(result);
} else if (leftType == null || !KotlinBuiltIns.isCharOrNullableChar(leftType)) {
result = JsAstUtils.charToBoxedChar(result);
}
}
return result;
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class OverloadedAssignmentTranslator method overloadedMethodInvocation.
@NotNull
private JsExpression overloadedMethodInvocation(AccessTranslator accessTranslator) {
JsBlock innerBlock = new JsBlock();
TranslationContext innerContext = context().innerBlock(innerBlock);
JsExpression oldValue = accessTranslator.translateAsGet();
JsBlock argumentBlock = new JsBlock();
TranslationContext argumentContext = innerContext.innerBlock(argumentBlock);
KtExpression argumentPsi = expression.getRight();
assert argumentPsi != null;
JsExpression argument = Translation.translateAsExpression(argumentPsi, argumentContext);
if (!argumentBlock.isEmpty()) {
oldValue = innerContext.defineTemporary(oldValue);
innerContext.addStatementsToCurrentBlockFrom(argumentBlock);
}
Map<KtExpression, JsExpression> aliases = new HashMap<KtExpression, JsExpression>();
aliases.put(argumentPsi, argument);
innerContext = innerContext.innerContextWithAliasesForExpressions(aliases);
JsExpression result = CallTranslator.translate(innerContext, resolvedCall, oldValue);
context().addStatementsToCurrentBlockFrom(innerBlock);
return result;
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class UnaryOperationTranslator method translate.
@NotNull
public static JsExpression translate(@NotNull KtUnaryExpression expression, @NotNull TranslationContext context) {
IElementType operationToken = expression.getOperationReference().getReferencedNameElementType();
if (operationToken == KtTokens.EXCLEXCL) {
KtExpression baseExpression = getBaseExpression(expression);
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
return sure(translatedExpression, context);
}
if (operationToken == KtTokens.MINUS) {
KtExpression baseExpression = getBaseExpression(expression);
if (baseExpression instanceof KtConstantExpression) {
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
assert compileTimeValue != null : message(expression, "Expression is not compile time value: " + expression.getText() + " ");
Object value = getCompileTimeValue(context.bindingContext(), expression, compileTimeValue);
if (value instanceof Long) {
return JsAstUtils.newLong((Long) value, context);
}
}
}
if (IncrementTranslator.isIncrement(operationToken)) {
return IncrementTranslator.translate(expression, context);
}
JsExpression baseExpression = TranslationUtils.translateBaseExpression(context, expression);
if (isExclForBinaryEqualLikeExpr(expression, baseExpression)) {
return translateExclForBinaryEqualLikeExpr((JsBinaryOperation) baseExpression);
}
ResolvedCall<? extends FunctionDescriptor> resolvedCall = CallUtilKt.getFunctionResolvedCallWithAssert(expression, context.bindingContext());
return CallTranslator.translate(context, resolvedCall, baseExpression);
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class ArrayAccessTranslator method getCached.
@NotNull
@Override
public AccessTranslator getCached() {
Map<KtExpression, JsExpression> aliases = new HashMap<KtExpression, JsExpression>();
JsExpression arrayExpression = context().cacheExpressionIfNeeded(getArrayExpression());
aliases.put(expression.getArrayExpression(), arrayExpression);
for (KtExpression ktExpression : expression.getIndexExpressions()) {
JsExpression jsExpression = context().cacheExpressionIfNeeded(Translation.translateAsExpression(ktExpression, context()));
aliases.put(ktExpression, jsExpression);
}
return new CachedArrayAccessTranslator(expression, context().innerContextWithAliasesForExpressions(aliases), arrayExpression);
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class QualifiedExpressionTranslator method translateQualifiedExpression.
@NotNull
public static JsNode translateQualifiedExpression(@NotNull KtQualifiedExpression expression, @NotNull TranslationContext context) {
ResolvedCall<?> call = CallUtilKt.getResolvedCall(expression, context.bindingContext());
JsExpression receiver = null;
if (call != null) {
receiver = translateReceiver(expression, context);
}
KtExpression selector = getSelector(expression);
return dispatchToCorrectTranslator(receiver, selector, context);
}
Aggregations