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
|
||||
// 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);
|
||||
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.visitCode();
|
||||
codeBlock.codeGen(mv, localVars);
|
||||
codeBlock.codeGen(mv, localVars, typeContext);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
|
||||
//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);
|
||||
|
||||
mv.visitCode();
|
||||
codeBlock.codeGen(mv, localVars);
|
||||
codeBlock.codeGen(mv, localVars, typeContext);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
|
||||
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);
|
||||
|
||||
mv.visitCode();
|
||||
codeBlock.codeGen(mv, localVars);
|
||||
codeBlock.codeGen(mv, localVars, typeContext);
|
||||
|
||||
// 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
|
||||
|
@ -2,6 +2,7 @@ package abstractSyntaxTree.Class;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
@ -29,6 +30,7 @@ public class RefType extends AbstractType implements Node {
|
||||
this.fieldDecls = fieldDecls;
|
||||
this.methodDecls = methodDecls;
|
||||
this.hasMain = hasMain;
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
// 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,
|
||||
"java/lang/Object", null);
|
||||
@ -85,7 +87,7 @@ public class RefType extends AbstractType implements Node {
|
||||
}
|
||||
|
||||
for (MethodDecl method : methodDecls) {
|
||||
method.codeGen(cw, methodContext);
|
||||
method.codeGen(cw, methodContext, typeContext);
|
||||
}
|
||||
cw.visitEnd();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class Program implements Node {
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
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();
|
||||
byte[] bytecode = cw.toByteArray();
|
||||
|
Loading…
Reference in New Issue
Block a user