提交 391da867 编写于 作者: M Maxim Shafirov

latest work on class codegen

上级 5d34c9ba
......@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.types.ClassDescriptor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import java.util.List;
......@@ -15,25 +16,29 @@ import java.util.List;
*/
public class ClassCodegen {
private final Project project;
private final ClassVisitor v;
private final BindingContext bindingContext;
private final Codegens factory;
public ClassCodegen(Project project, Codegens v, JetClass jetClass, BindingContext bindingContext) {
public ClassCodegen(Project project, Codegens factory, BindingContext bindingContext) {
this.project = project;
this.v = null;
this.factory = factory;
this.bindingContext = bindingContext;
ClassDescriptor descriptor = bindingContext.getClassDescriptor(jetClass);
}
public void generate(JetClass aClass) {
ClassDescriptor descriptor = bindingContext.getClassDescriptor(aClass);
String fqName = CodeGenUtil.getInternalInterfaceName(descriptor);
List<JetDelegationSpecifier> delegationSpecifiers = jetClass.getDelegationSpecifiers();
List<JetDelegationSpecifier> delegationSpecifiers = aClass.getDelegationSpecifiers();
for (JetDelegationSpecifier specifier : delegationSpecifiers) {
JetType superType = bindingContext.resolveTypeReference(specifier.getTypeReference());
String superClassFQN = CodeGenUtil.getInternalInterfaceName((ClassDescriptor) superType.getConstructor().getDeclarationDescriptor());
}
//descriptor.
/*
ClassVisitor v = factory.forClassImplementation(descriptor);
v.visit(Opcodes.V1_6,
Opcodes.ACC_PUBLIC,
fqName.replace('.', '/'),
......@@ -42,24 +47,17 @@ public class ClassCodegen {
"java/lang/Object",
new String[0]
);
*/
}
public void generate(JetNamespace namespace) {
final PropertyCodegen propertyCodegen = new PropertyCodegen(v);
final FunctionCodegen functionCodegen = new FunctionCodegen(v, JetStandardLibrary.getJetStandardLibrary(project), bindingContext);
for (JetDeclaration declaration : namespace.getDeclarations()) {
for (JetDeclaration declaration : aClass.getDeclarations()) {
if (declaration instanceof JetProperty) {
propertyCodegen.gen((JetProperty) declaration, namespace);
propertyCodegen.genInInterface((JetProperty) declaration);
}
else if (declaration instanceof JetFunction) {
functionCodegen.gen((JetFunction) declaration, namespace);
functionCodegen.genInInterface((JetFunction) declaration);
}
}
}
public ClassVisitor getVisitor() {
return v;
}
}
......@@ -2,6 +2,7 @@ package org.jetbrains.jet.codegen;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.lang.psi.JetNamespace;
import org.jetbrains.jet.lang.types.ClassDescriptor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.util.TraceClassVisitor;
......@@ -41,6 +42,18 @@ public class Codegens {
return visitor;
}
public ClassVisitor forClassInterface(ClassDescriptor aClass) {
return newVisitor(CodeGenUtil.getInternalInterfaceName(aClass));
}
public ClassVisitor forClassImplementation(ClassDescriptor aClass) {
return newVisitor(CodeGenUtil.getInternalImplementationName(aClass));
}
public ClassVisitor forClassDelegatingImplementation(ClassDescriptor aClass) {
return newVisitor(CodeGenUtil.getInternalDelegatingImplementationName(aClass));
}
public NamespaceCodegen forNamespace(JetNamespace namespace) {
assert !isDone : "Already done!";
String fqName = namespace.getFQName();
......
......@@ -27,11 +27,19 @@ public class FunctionCodegen {
typeMapper = new JetTypeMapper(standardLibrary, bindingContext);
}
public void gen(JetFunction f, JetNamespace owner) {
public void genInNamespace(JetFunction f) {
gen(f);
}
public void gen(JetFunction f, JetClass owner) {
public void genInInterface(JetFunction f) {
}
public void genInImplementation(JetFunction f) {
}
public void genInDelegatingImplementation(JetFunction f) {
}
......
......@@ -41,10 +41,10 @@ public class NamespaceCodegen {
for (JetDeclaration declaration : namespace.getDeclarations()) {
if (declaration instanceof JetProperty) {
propertyCodegen.gen((JetProperty) declaration, namespace);
propertyCodegen.genInNamespace((JetProperty) declaration);
}
else if (declaration instanceof JetFunction) {
functionCodegen.gen((JetFunction) declaration, namespace);
functionCodegen.genInNamespace((JetFunction) declaration);
}
}
}
......@@ -59,8 +59,4 @@ public class NamespaceCodegen {
}
return fqName.replace('.', '/') + "/namespace";
}
public ClassVisitor getVisitor() {
return v;
}
}
package org.jetbrains.jet.codegen;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetNamespace;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.objectweb.asm.ClassVisitor;
......@@ -15,11 +13,19 @@ public class PropertyCodegen {
this.v = v;
}
public void gen(JetProperty p, JetNamespace owner) {
public void genInNamespace(JetProperty p) {
}
public void gen(JetProperty p, JetClass owner) {
public void genInInterface(JetProperty p) {
}
public void genInImplementation(JetProperty p) {
}
public void genInDelegatingImplementation(JetProperty p) {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册