use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class DestructuringDeclarationTranslator method translate.
private JsVars translate() {
if (initializer != null) {
context().getCurrentBlock().getStatements().add(JsAstUtils.newVar(multiObjectName, initializer));
}
List<JsVars.JsVar> jsVars = new ArrayList<JsVars.JsVar>();
JsNameRef multiObjNameRef = multiObjectName.makeRef();
for (KtDestructuringDeclarationEntry entry : multiDeclaration.getEntries()) {
VariableDescriptor descriptor = BindingContextUtils.getNotNull(context().bindingContext(), BindingContext.VARIABLE, entry);
// Do not call `componentX` for destructuring entry called _
if (descriptor.getName().isSpecial())
continue;
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
assert entryInitCall != null : "Entry init call must be not null";
JsExpression entryInitializer = CallTranslator.translate(context(), entryInitCall, multiObjNameRef);
FunctionDescriptor candidateDescriptor = entryInitCall.getCandidateDescriptor();
if (CallExpressionTranslator.shouldBeInlined(candidateDescriptor, context())) {
setInlineCallMetadata(entryInitializer, entry, entryInitCall, context());
}
KotlinType returnType = candidateDescriptor.getReturnType();
if (returnType != null && KotlinBuiltIns.isCharOrNullableChar(returnType) && !KotlinBuiltIns.isCharOrNullableChar(descriptor.getType())) {
entryInitializer = JsAstUtils.charToBoxedChar(entryInitializer);
}
JsName name = context().getNameForDescriptor(descriptor);
if (isVarCapturedInClosure(context().bindingContext(), descriptor)) {
JsNameRef alias = getCapturedVarAccessor(name.makeRef());
entryInitializer = JsAstUtils.wrapValue(alias, entryInitializer);
}
jsVars.add(new JsVars.JsVar(name, entryInitializer));
}
return new JsVars(jsVars, true);
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class InOperationTranslator method translateInt.
@Nullable
private JsExpression translateInt() {
ResolvedCall<? extends CallableDescriptor> rightCall = CallUtilKt.getResolvedCallWithAssert(right, bindingContext());
if (!(rightCall.getResultingDescriptor() instanceof FunctionDescriptor)) {
return null;
}
FunctionDescriptor callDescriptor = (FunctionDescriptor) rightCall.getResultingDescriptor();
if (!INT_RANGE_TEST.apply(callDescriptor)) {
return null;
}
if (!(rightCall.getDispatchReceiver() instanceof ExpressionReceiver)) {
return null;
}
KtExpression lower = ((ExpressionReceiver) rightCall.getDispatchReceiver()).getExpression();
KtExpression upper = rightCall.getCall().getValueArguments().get(0).getArgumentExpression();
assert upper != null : "Parse error occurred: " + PsiUtilsKt.getTextWithLocation(right);
return translateInt(lower, upper);
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class KotlinOverloadTest method assertOverloadabilityRelation.
private void assertOverloadabilityRelation(String funA, String funB, boolean expectedIsError) {
FunctionDescriptor a = makeFunction(funA);
FunctionDescriptor b = makeFunction(funB);
boolean aOverloadableWithB = overloadChecker.isOverloadable(a, b);
assertEquals(expectedIsError, !aOverloadableWithB);
boolean bOverloadableWithA = overloadChecker.isOverloadable(b, a);
assertEquals(expectedIsError, !bOverloadableWithA);
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class TailRecursionCodegen method generateTailRecursion.
public void generateTailRecursion(ResolvedCall<?> resolvedCall) {
CallableDescriptor fd = CoroutineCodegenUtilKt.unwrapInitialDescriptorForSuspendFunction(resolvedCall.getResultingDescriptor());
assert fd instanceof FunctionDescriptor : "Resolved call doesn't refer to the function descriptor: " + fd;
CallableMethod callable = (CallableMethod) codegen.resolveToCallable((FunctionDescriptor) fd, false, resolvedCall);
List<ResolvedValueArgument> arguments = resolvedCall.getValueArgumentsByIndex();
if (arguments == null) {
throw new IllegalStateException("Failed to arrange value arguments by index: " + fd);
}
if (((FunctionDescriptor) fd).isSuspend()) {
AsmUtil.pop(v, callable.getValueParameters().get(callable.getValueParameters().size() - 1).getAsmType());
}
assignParameterValues(fd, callable, arguments);
if (callable.getExtensionReceiverType() != null) {
if (resolvedCall.getExtensionReceiver() != fd.getExtensionReceiverParameter().getValue()) {
StackValue expression = context.getReceiverExpression(codegen.typeMapper);
expression.store(StackValue.onStack(callable.getExtensionReceiverType()), v, true);
} else {
AsmUtil.pop(v, callable.getExtensionReceiverType());
}
}
if (callable.getDispatchReceiverType() != null) {
AsmUtil.pop(v, callable.getDispatchReceiverType());
}
v.goTo(context.getMethodStartLabel());
}
use of org.jetbrains.kotlin.descriptors.FunctionDescriptor in project kotlin by JetBrains.
the class ForLoopConventionsChecker method checkIterableConvention.
@Nullable
public KotlinType checkIterableConvention(@NotNull ExpressionReceiver loopRange, @NotNull ExpressionTypingContext context) {
KtExpression loopRangeExpression = loopRange.getExpression();
// Make a fake call loopRange.iterator(), and try to resolve it
OverloadResolutionResults<FunctionDescriptor> iteratorResolutionResults = fakeCallResolver.resolveFakeCall(context, loopRange, OperatorNameConventions.ITERATOR, loopRangeExpression, loopRangeExpression, FakeCallKind.ITERATOR, Collections.<KtExpression>emptyList());
if (!iteratorResolutionResults.isSuccess())
return null;
ResolvedCall<FunctionDescriptor> iteratorResolvedCall = iteratorResolutionResults.getResultingCall();
context.trace.record(LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRangeExpression, iteratorResolvedCall);
FunctionDescriptor iteratorFunction = iteratorResolvedCall.getResultingDescriptor();
checkIfOperatorModifierPresent(loopRangeExpression, iteratorFunction, context.trace);
KotlinType iteratorType = iteratorFunction.getReturnType();
//noinspection ConstantConditions
KotlinType hasNextType = checkConventionForIterator(context, loopRangeExpression, iteratorType, OperatorNameConventions.HAS_NEXT, HAS_NEXT_FUNCTION_AMBIGUITY, HAS_NEXT_MISSING, HAS_NEXT_FUNCTION_NONE_APPLICABLE, LOOP_RANGE_HAS_NEXT_RESOLVED_CALL);
if (hasNextType != null && !builtIns.isBooleanOrSubtype(hasNextType)) {
context.trace.report(HAS_NEXT_FUNCTION_TYPE_MISMATCH.on(loopRangeExpression, hasNextType));
}
return checkConventionForIterator(context, loopRangeExpression, iteratorType, OperatorNameConventions.NEXT, NEXT_AMBIGUITY, NEXT_MISSING, NEXT_NONE_APPLICABLE, LOOP_RANGE_NEXT_RESOLVED_CALL);
}
Aggregations