Source files made available where "emitting" is reported
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
@@ -51,10 +52,14 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassBuilder newVisitor(String filePath) {
|
ClassBuilder newVisitor(String outputFilePath, PsiFile sourceFile) {
|
||||||
state.getProgress().log("Emitting: " + filePath);
|
return newVisitor(outputFilePath, Collections.singletonList(sourceFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassBuilder newVisitor(String outputFilePath, Collection<? extends PsiFile> sourceFiles) {
|
||||||
|
state.getProgress().log("Emitting: " + outputFilePath);
|
||||||
final ClassBuilder answer = builderFactory.newClassBuilder();
|
final ClassBuilder answer = builderFactory.newClassBuilder();
|
||||||
generators.put(filePath, answer);
|
generators.put(outputFilePath, answer);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +101,7 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
return answer.toString();
|
return answer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamespaceCodegen forNamespace(final FqName fqName, Collection<JetFile> files) {
|
public NamespaceCodegen forNamespace(final FqName fqName, final Collection<JetFile> files) {
|
||||||
assert !isDone : "Already done!";
|
assert !isDone : "Already done!";
|
||||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||||
if (codegen == null) {
|
if (codegen == null) {
|
||||||
@@ -104,7 +109,10 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected ClassBuilder createClassBuilder() {
|
protected ClassBuilder createClassBuilder() {
|
||||||
return newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getInternalName() + ".class");
|
return newVisitor(
|
||||||
|
NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getInternalName() + ".class",
|
||||||
|
files
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
codegen = new NamespaceCodegen(onDemand, fqName, state, files);
|
codegen = new NamespaceCodegen(onDemand, fqName, state, files);
|
||||||
@@ -114,20 +122,21 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
return codegen;
|
return codegen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassBuilder forClassImplementation(ClassDescriptor aClass) {
|
public ClassBuilder forClassImplementation(ClassDescriptor aClass, PsiFile sourceFile) {
|
||||||
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.IMPL);
|
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.IMPL);
|
||||||
if (isPrimitive(type)) {
|
if (isPrimitive(type)) {
|
||||||
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
|
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
|
||||||
}
|
}
|
||||||
return newVisitor(type.getInternalName() + ".class");
|
return newVisitor(type.getInternalName() + ".class", sourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassBuilder forNamespacepart(String name) {
|
public ClassBuilder forNamespacepart(String internalName, PsiFile sourceFile) {
|
||||||
return newVisitor(name + ".class");
|
return newVisitor(internalName + ".class", sourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassBuilder forTraitImplementation(ClassDescriptor aClass, GenerationState state) {
|
public ClassBuilder forTraitImplementation(ClassDescriptor aClass, GenerationState state, PsiFile sourceFile) {
|
||||||
return newVisitor(
|
return newVisitor(
|
||||||
state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName() + ".class");
|
state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName() + ".class",
|
||||||
|
sourceFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
assert descriptor != null;
|
assert descriptor != null;
|
||||||
|
|
||||||
name = classNameForAnonymousClass(state.getBindingContext(), fun);
|
name = classNameForAnonymousClass(state.getBindingContext(), fun);
|
||||||
final ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName() + ".class");
|
final ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName() + ".class", fun.getContainingFile());
|
||||||
|
|
||||||
final FunctionDescriptor funDescriptor = bindingContext.get(BindingContext.FUNCTION, fun);
|
final FunctionDescriptor funDescriptor = bindingContext.get(BindingContext.FUNCTION, fun);
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
JvmClassName className =
|
JvmClassName className =
|
||||||
classNameForAnonymousClass(bindingContext, objectDeclaration);
|
classNameForAnonymousClass(bindingContext, objectDeclaration);
|
||||||
ClassBuilder classBuilder = state.getFactory().newVisitor(className.getInternalName() + ".class");
|
ClassBuilder classBuilder = state.getFactory().newVisitor(
|
||||||
|
className.getInternalName() + ".class",
|
||||||
|
literal.getContainingFile());
|
||||||
|
|
||||||
final ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
|
final ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
|
||||||
assert classDescriptor != null;
|
assert classDescriptor != null;
|
||||||
@@ -271,7 +273,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
JvmClassName className =
|
JvmClassName className =
|
||||||
classNameForAnonymousClass(bindingContext, declaration);
|
classNameForAnonymousClass(bindingContext, declaration);
|
||||||
ClassBuilder classBuilder = state.getFactory().newVisitor(className.getInternalName() + ".class");
|
ClassBuilder classBuilder = state.getFactory().newVisitor(
|
||||||
|
className.getInternalName() + ".class",
|
||||||
|
declaration.getContainingFile()
|
||||||
|
);
|
||||||
|
|
||||||
final CodegenContext objectContext = context.intoAnonymousClass(descriptor, this);
|
final CodegenContext objectContext = context.intoAnonymousClass(descriptor, this);
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class MemberCodegen extends GenerationStateAware {
|
|||||||
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
||||||
|
|
||||||
if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
|
if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
|
||||||
ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state);
|
ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state, aClass.getContainingFile());
|
||||||
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state)
|
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state)
|
||||||
.generate();
|
.generate();
|
||||||
traitBuilder.done();
|
traitBuilder.done();
|
||||||
@@ -123,7 +123,7 @@ public class MemberCodegen extends GenerationStateAware {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor);
|
ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor, aClass.getContainingFile());
|
||||||
|
|
||||||
final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state);
|
final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state);
|
||||||
|
|
||||||
|
|||||||
@@ -153,12 +153,11 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (k > 0) {
|
if (k > 0) {
|
||||||
PsiFile containingFile = file.getContainingFile();
|
|
||||||
String namespaceInternalName = JvmClassName.byFqNameWithoutInnerClasses(name.child(Name.identifier(JvmAbi.PACKAGE_CLASS))).getInternalName();
|
String namespaceInternalName = JvmClassName.byFqNameWithoutInnerClasses(name.child(Name.identifier(JvmAbi.PACKAGE_CLASS))).getInternalName();
|
||||||
String className = getMultiFileNamespaceInternalName(namespaceInternalName, containingFile);
|
String className = getMultiFileNamespaceInternalName(namespaceInternalName, file);
|
||||||
ClassBuilder builder = state.getFactory().forNamespacepart(className);
|
ClassBuilder builder = state.getFactory().forNamespacepart(className, file);
|
||||||
|
|
||||||
builder.defineClass(containingFile, V1_6,
|
builder.defineClass(file, V1_6,
|
||||||
ACC_PUBLIC/*|ACC_SUPER*/,
|
ACC_PUBLIC/*|ACC_SUPER*/,
|
||||||
className,
|
className,
|
||||||
null,
|
null,
|
||||||
@@ -166,7 +165,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
"java/lang/Object",
|
"java/lang/Object",
|
||||||
new String[0]
|
new String[0]
|
||||||
);
|
);
|
||||||
builder.visitSource(containingFile.getName(), null);
|
builder.visitSource(file.getName(), null);
|
||||||
|
|
||||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||||
if (declaration instanceof JetNamedFunction) {
|
if (declaration instanceof JetNamedFunction) {
|
||||||
@@ -310,4 +309,4 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
String namespaceInternalName = namespaceJvmClassName.getInternalName();
|
String namespaceInternalName = namespaceJvmClassName.getInternalName();
|
||||||
return NamespaceCodegen.getMultiFileNamespaceInternalName(namespaceInternalName, file);
|
return NamespaceCodegen.getMultiFileNamespaceInternalName(namespaceInternalName, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,10 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
||||||
assert className != null;
|
assert className != null;
|
||||||
|
|
||||||
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName() + ".class");
|
ClassBuilder classBuilder = classFileFactory.newVisitor(
|
||||||
|
className.getInternalName() + ".class",
|
||||||
|
scriptDeclaration.getContainingFile()
|
||||||
|
);
|
||||||
classBuilder.defineClass(scriptDeclaration,
|
classBuilder.defineClass(scriptDeclaration,
|
||||||
V1_6,
|
V1_6,
|
||||||
ACC_PUBLIC,
|
ACC_PUBLIC,
|
||||||
|
|||||||
Reference in New Issue
Block a user