Fixed missing parameters in Program, MethodDecl, and RefType
This commit is contained in:
parent
ab19751146
commit
9fa9dfdfb6
@ -46,7 +46,7 @@ public class MethodDecl implements Node {
|
|||||||
|
|
||||||
//Need to get the returnType of the method if it is an object
|
//Need to get the returnType of the method if it is an object
|
||||||
// methodContext (class, (returnType, (identifier, parameter)))
|
// methodContext (class, (returnType, (identifier, parameter)))
|
||||||
public void codeGen(ClassWriter cw, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
public void codeGen(ClassWriter cw, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||||
|
|
||||||
localVars.put("this", classThatContainsMethod);
|
localVars.put("this", classThatContainsMethod);
|
||||||
for (Parameter param : parameters.parameterList) {
|
for (Parameter param : parameters.parameterList) {
|
||||||
@ -75,7 +75,7 @@ public class MethodDecl implements Node {
|
|||||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", descriptor, false);
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", descriptor, false);
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
codeBlock.codeGen(mv, localVars);
|
codeBlock.codeGen(mv, localVars, typeContext);
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
|
|
||||||
//automatically computed max stack and max locals
|
//automatically computed max stack and max locals
|
||||||
@ -87,7 +87,7 @@ public class MethodDecl implements Node {
|
|||||||
MethodVisitor mv = cw.visitMethod(access, name, "([Ljava/lang/String;)V", null, null);
|
MethodVisitor mv = cw.visitMethod(access, name, "([Ljava/lang/String;)V", null, null);
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
codeBlock.codeGen(mv, localVars);
|
codeBlock.codeGen(mv, localVars, typeContext);
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
|
|
||||||
mv.visitMaxs(0, 0);
|
mv.visitMaxs(0, 0);
|
||||||
@ -97,7 +97,7 @@ public class MethodDecl implements Node {
|
|||||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, name, getMethodDescriptor(methodContext), null, null);
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, name, getMethodDescriptor(methodContext), null, null);
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
codeBlock.codeGen(mv, localVars);
|
codeBlock.codeGen(mv, localVars, typeContext);
|
||||||
|
|
||||||
// We have to check the return type to get the return opcode
|
// We have to check the return type to get the return opcode
|
||||||
// For methods which return an actual value, the return opcode is created in the method body to ensure the
|
// For methods which return an actual value, the return opcode is created in the method body to ensure the
|
||||||
|
@ -2,6 +2,7 @@ package abstractSyntaxTree.Class;
|
|||||||
|
|
||||||
import TypeCheck.AbstractType;
|
import TypeCheck.AbstractType;
|
||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
|
import abstractSyntaxTree.Expression.IExpression;
|
||||||
import abstractSyntaxTree.Node;
|
import abstractSyntaxTree.Node;
|
||||||
import abstractSyntaxTree.Parameter.ParameterList;
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
@ -29,6 +30,7 @@ public class RefType extends AbstractType implements Node {
|
|||||||
this.fieldDecls = fieldDecls;
|
this.fieldDecls = fieldDecls;
|
||||||
this.methodDecls = methodDecls;
|
this.methodDecls = methodDecls;
|
||||||
this.hasMain = hasMain;
|
this.hasMain = hasMain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext,
|
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext,
|
||||||
@ -75,7 +77,7 @@ public class RefType extends AbstractType implements Node {
|
|||||||
// Method for code generation which iterates over all the field declarations
|
// Method for code generation which iterates over all the field declarations
|
||||||
// and method declarations and calls their CodeGen methods
|
// and method declarations and calls their CodeGen methods
|
||||||
|
|
||||||
public void codeGen(ClassWriter cw, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
public void codeGen(ClassWriter cw, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||||
|
|
||||||
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null,
|
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null,
|
||||||
"java/lang/Object", null);
|
"java/lang/Object", null);
|
||||||
@ -85,7 +87,7 @@ public class RefType extends AbstractType implements Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (MethodDecl method : methodDecls) {
|
for (MethodDecl method : methodDecls) {
|
||||||
method.codeGen(cw, methodContext);
|
method.codeGen(cw, methodContext, typeContext);
|
||||||
}
|
}
|
||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class Program implements Node {
|
|||||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||||
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, oneClass.name, null, "java/lang/Object", null);
|
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, oneClass.name, null, "java/lang/Object", null);
|
||||||
|
|
||||||
// oneClass.codeGen(cw);
|
oneClass.codeGen(cw, methodContext, typeContext);
|
||||||
|
|
||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
byte[] bytecode = cw.toByteArray();
|
byte[] bytecode = cw.toByteArray();
|
||||||
|
Loading…
Reference in New Issue
Block a user