add instVar to ast
This commit is contained in:
parent
46ac49576e
commit
112c5f2c1b
@ -3,6 +3,7 @@ package abstractSyntaxTree.Expression;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.StatementExpression.ReceivingMethod;
|
||||
import gen.DecafParser;
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
@ -10,15 +11,20 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InstVarExpression implements IExpression{
|
||||
|
||||
public RefType classRef;
|
||||
|
||||
public List<SubReceiver> receivers; ;
|
||||
public List<ReceivingMethod> receivingMethods;
|
||||
public String fieldName;
|
||||
|
||||
public InstVarExpression(RefType classRef, String fieldName){
|
||||
this.classRef = classRef;
|
||||
public InstVarExpression(List<SubReceiver> receivers, List<ReceivingMethod> receivingMethods, String fieldName){
|
||||
this.receivers = receivers;
|
||||
this.receivingMethods = receivingMethods;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
|
22
src/main/java/abstractSyntaxTree/Expression/SubReceiver.java
Normal file
22
src/main/java/abstractSyntaxTree/Expression/SubReceiver.java
Normal file
@ -0,0 +1,22 @@
|
||||
package abstractSyntaxTree.Expression;
|
||||
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.StatementExpression.NewStatementExpression;
|
||||
|
||||
public class SubReceiver implements Node {
|
||||
boolean thisExpression;
|
||||
NewStatementExpression newStatementExpression;
|
||||
String identifier;
|
||||
|
||||
public SubReceiver(boolean thisExpression) {
|
||||
this.thisExpression = thisExpression;
|
||||
}
|
||||
|
||||
public SubReceiver(NewStatementExpression newStatementExpression) {
|
||||
this.newStatementExpression = newStatementExpression;
|
||||
}
|
||||
|
||||
public SubReceiver(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
}
|
@ -217,6 +217,18 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitSubReceiver(DecafParser.SubReceiverContext ctx) {
|
||||
if (ctx.This() != null) {
|
||||
return new SubReceiver(true);
|
||||
} else if (ctx.newDecl() != null) {
|
||||
return new SubReceiver((NewStatementExpression) visit(ctx.newDecl()));
|
||||
} else if (ctx.Identifier() != null) {
|
||||
return new SubReceiver(ctx.Identifier().getText());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitNewDecl(DecafParser.NewDeclContext ctx) {
|
||||
String name = ctx.Identifier().getText();
|
||||
@ -316,13 +328,24 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
public Node visitAssignableExpr(DecafParser.AssignableExprContext ctx) {
|
||||
if (ctx.Identifier() != null) {
|
||||
return new LocalVarIdentifier(ctx.Identifier().getText());
|
||||
} else if (ctx.instVar() != null) {
|
||||
return visitInstVar(ctx.instVar());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitInstVar(DecafParser.InstVarContext ctx) {
|
||||
return super.visitInstVar(ctx);
|
||||
List<SubReceiver> receivers = new ArrayList<>();
|
||||
List<ReceivingMethod> receivingMethods = new ArrayList<>();
|
||||
String fieldName = ctx.Identifier().getText();
|
||||
for(DecafParser.SubReceiverContext subReceiver : ctx.subReceiver()) {
|
||||
receivers.add((SubReceiver) visit(subReceiver));
|
||||
}
|
||||
for(DecafParser.ReceivingMethodContext receivingMethod: ctx.receivingMethod()) {
|
||||
receivingMethods.add((ReceivingMethod) visit(receivingMethod));
|
||||
}
|
||||
return new InstVarExpression(receivers, receivingMethods, fieldName);
|
||||
}
|
||||
|
||||
public List<IExpression> generateExpressions(DecafParser.ArgumentListContext ctx) {
|
||||
|
Loading…
Reference in New Issue
Block a user