use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ExpressionTypingServices method getBodyExpressionType.
@NotNull
public KotlinType getBodyExpressionType(@NotNull BindingTrace trace, @NotNull LexicalScope outerScope, @NotNull DataFlowInfo dataFlowInfo, @NotNull KtDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor) {
KtExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null;
LexicalScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace, expressionTypingComponents.overloadChecker);
ExpressionTypingContext context = ExpressionTypingContext.newContext(trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE);
KotlinTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, function.hasBlockBody());
KotlinType type = typeInfo.getType();
if (type != null) {
return type;
} else {
return ErrorUtils.createErrorType("Error function type");
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ControlFlowAnalyzer method process.
public void process(@NotNull BodiesResolveContext c) {
for (KtFile file : c.getFiles()) {
checkDeclarationContainer(c, file);
}
for (KtClassOrObject aClass : c.getDeclaredClasses().keySet()) {
checkDeclarationContainer(c, aClass);
}
for (KtScript script : c.getScripts().keySet()) {
checkDeclarationContainer(c, script);
}
for (KtSecondaryConstructor constructor : c.getSecondaryConstructors().keySet()) {
checkSecondaryConstructor(constructor);
}
for (Map.Entry<KtNamedFunction, SimpleFunctionDescriptor> entry : c.getFunctions().entrySet()) {
KtNamedFunction function = entry.getKey();
SimpleFunctionDescriptor functionDescriptor = entry.getValue();
KotlinType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType() ? NO_EXPECTED_TYPE : functionDescriptor.getReturnType();
checkFunction(c, function, expectedReturnType);
}
for (Map.Entry<KtProperty, PropertyDescriptor> entry : c.getProperties().entrySet()) {
KtProperty property = entry.getKey();
PropertyDescriptor propertyDescriptor = entry.getValue();
checkProperty(c, property, propertyDescriptor);
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class InlineCodegen method createMethodNode.
@NotNull
static SMAPAndMethodNode createMethodNode(@NotNull final FunctionDescriptor functionDescriptor, @NotNull JvmMethodSignature jvmSignature, @NotNull ExpressionCodegen codegen, @NotNull CodegenContext context, boolean callDefault, @Nullable ResolvedCall<?> resolvedCall) {
if (InlineCodegenUtil.isSpecialEnumMethod(functionDescriptor)) {
assert resolvedCall != null : "Resolved call for " + functionDescriptor + " should be not null";
Map<TypeParameterDescriptor, KotlinType> arguments = resolvedCall.getTypeArguments();
assert arguments.size() == 1 : "Resolved call for " + functionDescriptor + " should have 1 type argument";
MethodNode node = InlineCodegenUtil.createSpecialEnumMethodBody(codegen, functionDescriptor.getName().asString(), arguments.keySet().iterator().next().getDefaultType(), codegen.getState().getTypeMapper());
return new SMAPAndMethodNode(node, SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
} else if (CoroutineCodegenUtilKt.isBuiltInSuspendCoroutineOrReturnInJvm(functionDescriptor)) {
return new SMAPAndMethodNode(CoroutineCodegenUtilKt.createMethodNodeForSuspendCoroutineOrReturn(functionDescriptor, codegen.getState().getTypeMapper()), SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
}
final GenerationState state = codegen.getState();
final Method asmMethod = callDefault ? state.getTypeMapper().mapDefaultMethod(functionDescriptor, context.getContextKind()) : jvmSignature.getAsmMethod();
MethodId methodId = new MethodId(DescriptorUtils.getFqNameSafe(functionDescriptor.getContainingDeclaration()), asmMethod);
final CallableMemberDescriptor directMember = getDirectMemberAndCallableFromObject(functionDescriptor);
if (!isBuiltInArrayIntrinsic(functionDescriptor) && !(directMember instanceof DeserializedCallableMemberDescriptor)) {
return doCreateMethodNodeFromSource(functionDescriptor, jvmSignature, codegen, context, callDefault, state, asmMethod);
}
SMAPAndMethodNode resultInCache = InlineCacheKt.getOrPut(state.getInlineCache().getMethodNodeById(), methodId, new Function0<SMAPAndMethodNode>() {
@Override
public SMAPAndMethodNode invoke() {
SMAPAndMethodNode result = doCreateMethodNodeFromCompiled(directMember, state, asmMethod);
if (result == null) {
throw new IllegalStateException("Couldn't obtain compiled function body for " + functionDescriptor);
}
return result;
}
});
return resultInCache.copyWithNewNode(cloneMethodNode(resultInCache.getNode()));
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class InlineCodegenUtil method createSpecialEnumMethodBody.
public static MethodNode createSpecialEnumMethodBody(@NotNull ExpressionCodegen codegen, @NotNull String name, @NotNull KotlinType type, @NotNull KotlinTypeMapper typeMapper) {
boolean isValueOf = "enumValueOf".equals(name);
Type invokeType = typeMapper.mapType(type);
String desc = getSpecialEnumFunDescriptor(invokeType, isValueOf);
MethodNode node = new MethodNode(API, Opcodes.ACC_STATIC, "fake", desc, null, null);
codegen.putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.ENUM_REIFIED, new InstructionAdapter(node));
if (isValueOf) {
node.visitInsn(Opcodes.ACONST_NULL);
node.visitVarInsn(Opcodes.ALOAD, 0);
node.visitMethodInsn(Opcodes.INVOKESTATIC, ENUM_TYPE.getInternalName(), "valueOf", Type.getMethodDescriptor(ENUM_TYPE, JAVA_CLASS_TYPE, AsmTypes.JAVA_STRING_TYPE), false);
} else {
node.visitInsn(Opcodes.ICONST_0);
node.visitTypeInsn(Opcodes.ANEWARRAY, ENUM_TYPE.getInternalName());
}
node.visitInsn(Opcodes.ARETURN);
node.visitMaxs(isValueOf ? 3 : 2, isValueOf ? 1 : 0);
return node;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class CodegenAnnotatingVisitor method recordLocalVariablePropertyMetadata.
private void recordLocalVariablePropertyMetadata(LocalVariableDescriptor variableDescriptor) {
KotlinType delegateType = JvmCodegenUtil.getPropertyDelegateType(variableDescriptor, bindingContext);
if (delegateType == null)
return;
LocalVariableDescriptor delegateVariableDescriptor = new LocalVariableDescriptor(variableDescriptor.getContainingDeclaration(), Annotations.Companion.getEMPTY(), variableDescriptor.getName(), delegateType, false, false, SourceElement.NO_SOURCE);
bindingTrace.record(LOCAL_VARIABLE_DELEGATE, variableDescriptor, delegateVariableDescriptor);
LocalVariableDescriptor metadataVariableDescriptor = new LocalVariableDescriptor(variableDescriptor.getContainingDeclaration(), Annotations.Companion.getEMPTY(), Name.identifier(variableDescriptor.getName().asString() + "$metadata"), ReflectionTypes.Companion.createKPropertyStarType(DescriptorUtilsKt.getModule(variableDescriptor)), false, false, SourceElement.NO_SOURCE);
bindingTrace.record(LOCAL_VARIABLE_PROPERTY_METADATA, variableDescriptor, metadataVariableDescriptor);
}
Aggregations