Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
289231030a
@ -4,6 +4,7 @@ import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Program;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
@ -18,11 +19,13 @@ import java.util.Objects;
|
||||
public class FieldDecl extends AbstractType implements Node {
|
||||
|
||||
public String type; // from parser
|
||||
public String identifier; // from parser
|
||||
public String identifier;// from parser
|
||||
public IExpression expression;
|
||||
|
||||
public FieldDecl(String type, String identifier){
|
||||
public FieldDecl(String type, String identifier, IExpression expression){
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
this.expression = expression;
|
||||
}
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, String>> typeContext) throws TypeCheckException {
|
||||
|
||||
|
@ -56,7 +56,12 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
}
|
||||
|
||||
public Node generateFieldDecl(DecafParser.LocalVarDeclContext ctx) {
|
||||
return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText());
|
||||
if (ctx.expression() != null) {
|
||||
IExpression expression = (IExpression) visit(ctx.expression());
|
||||
return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText(), expression);
|
||||
} else {
|
||||
return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -198,7 +203,6 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
return new AssignStatementExpression(ctx.Assign().getText(),(IExpression) left, (IExpression) right);
|
||||
}
|
||||
|
||||
//
|
||||
@Override
|
||||
public Node visitMethodCall(DecafParser.MethodCallContext ctx) {
|
||||
String methodName = ctx.Identifier().getText();
|
||||
|
Loading…
Reference in New Issue
Block a user