add expression to LocalVarDecl in ast
This commit is contained in:
parent
e23d84cd09
commit
c8c12e4d9a
@ -4,6 +4,7 @@ import TypeCheck.AbstractType;
|
|||||||
import TypeCheck.TypeCheckException;
|
import TypeCheck.TypeCheckException;
|
||||||
import TypeCheck.TypeCheckHelper;
|
import TypeCheck.TypeCheckHelper;
|
||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
|
import abstractSyntaxTree.Expression.IExpression;
|
||||||
import abstractSyntaxTree.Parameter.ParameterList;
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
@ -13,9 +14,11 @@ import java.util.*;
|
|||||||
public class LocalVarDecl extends AbstractType implements IStatement{
|
public class LocalVarDecl extends AbstractType implements IStatement{
|
||||||
String type;
|
String type;
|
||||||
String identifier;
|
String identifier;
|
||||||
public LocalVarDecl(String type, String identifier) {
|
IExpression expression;
|
||||||
|
public LocalVarDecl(String type, String identifier, IExpression expression) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
this.expression = expression;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
||||||
|
@ -60,7 +60,12 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node visitLocalVarDecl(DecafParser.LocalVarDeclContext ctx) {
|
public Node visitLocalVarDecl(DecafParser.LocalVarDeclContext ctx) {
|
||||||
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText());
|
if (ctx.expression() != null) {
|
||||||
|
IExpression expression = (IExpression) visit(ctx.expression());
|
||||||
|
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText(), expression);
|
||||||
|
} else {
|
||||||
|
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user