NewStatementExpression start
This commit is contained in:
parent
21dff015b5
commit
519d891743
@ -56,8 +56,9 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
|||||||
@Override
|
@Override
|
||||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||||
//Generate Bytecode for the receiver
|
//Generate Bytecode for the receiver
|
||||||
if(classThatHasTheMethodIfNotThis != null){
|
if (classThatHasTheMethodIfNotThis != null) {
|
||||||
//TODO: classThatHasTheMethodIfNotThis must be an object --> instance of the class not the class itself
|
//TODO: classThatHasTheMethodIfNotThis must be an object --> instance of the class not the class itself
|
||||||
|
// Need to call codeGen so it pushes the instance onto the stack, which will be popped of
|
||||||
//classThatHasTheMethodIfNotThis.codeGen();
|
//classThatHasTheMethodIfNotThis.codeGen();
|
||||||
|
|
||||||
String descriptor;
|
String descriptor;
|
||||||
@ -65,29 +66,29 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
|||||||
for (MethodDecl methodDecl : methodDecls) {
|
for (MethodDecl methodDecl : methodDecls) {
|
||||||
if (methodDecl.name.equals(methodName)) {
|
if (methodDecl.name.equals(methodName)) {
|
||||||
//Get the method descriptor
|
//Get the method descriptor
|
||||||
//descriptor = methodDecl.getMethodDescriptor(methodContext);
|
descriptor = methodDecl.getMethodDescriptor(methodContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classThatHasTheMethodIfNotThis.name, methodName, descriptor, false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classThatHasTheMethodIfNotThis.name, methodName, descriptor, false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Load this onto the stack
|
// Load this onto the stack
|
||||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
}
|
|
||||||
|
|
||||||
for (IExpression argument : arguments) {
|
for (IExpression argument : arguments) {
|
||||||
argument.codeGen(mv, localVars, typeContext);
|
argument.codeGen(mv, localVars, typeContext);
|
||||||
}
|
|
||||||
|
|
||||||
// Get the method descriptor
|
|
||||||
String descriptor;
|
|
||||||
List<MethodDecl> methodDecls = thisClass.methodDecls;
|
|
||||||
for (MethodDecl methodDecl : methodDecls) {
|
|
||||||
if (methodDecl.name.equals(methodName)) {
|
|
||||||
//Get the method descriptor
|
|
||||||
//descriptor = methodDecl.getMethodDescriptor(methodContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the method descriptor
|
||||||
|
String descriptor;
|
||||||
|
List<MethodDecl> methodDecls = thisClass.methodDecls;
|
||||||
|
for (MethodDecl methodDecl : methodDecls) {
|
||||||
|
if (methodDecl.name.equals(methodName)) {
|
||||||
|
//Get the method descriptor
|
||||||
|
descriptor = methodDecl.getMethodDescriptor(methodContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, thisClass.name, methodName, descriptor, false);
|
||||||
}
|
}
|
||||||
//mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, thisClass.name, methodName, descriptor, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import abstractSyntaxTree.Expression.IExpression;
|
|||||||
import abstractSyntaxTree.Parameter.ParameterList;
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
import abstractSyntaxTree.Statement.IStatement;
|
import abstractSyntaxTree.Statement.IStatement;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -13,6 +14,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public class NewStatementExpression extends AbstractType implements IExpression, IStatement {
|
public class NewStatementExpression extends AbstractType implements IExpression, IStatement {
|
||||||
|
|
||||||
|
private String className;
|
||||||
|
|
||||||
|
public NewStatementExpression(String className) {
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws Exception {
|
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws Exception {
|
||||||
@ -21,11 +27,12 @@ public class NewStatementExpression extends AbstractType implements IExpression,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||||
|
//Create new instance of the class
|
||||||
|
mv.visitTypeInsn(Opcodes.NEW, className);
|
||||||
|
|
||||||
}
|
//Duplicate the reference, so I can use it after the INVOKE consumes one
|
||||||
|
mv.visitInsn(Opcodes.DUP);
|
||||||
@Override
|
//Call the constructor
|
||||||
public void codeGen(MethodVisitor mv, HashMap<String, HashMap<String, String>> typeContext, LinkedHashMap<String, String> localVars) throws Exception {
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", "()V", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user