format ASTGenerator
This commit is contained in:
parent
82384886c6
commit
403b31c550
@ -32,27 +32,27 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
List<FieldDecl> fieldDecls = new ArrayList<>();
|
||||
List<MethodDecl> methodDecls = new ArrayList<>();
|
||||
boolean hasMain;
|
||||
if(ctx.MainMethodDecl() != null) {
|
||||
if (ctx.MainMethodDecl() != null) {
|
||||
hasMain = true;
|
||||
MethodDecl mainMethod = new MethodDecl(name, "void", "main", new ParameterList(new ArrayList<>()),(BlockStatement) visitBlock(ctx.block()));
|
||||
MethodDecl mainMethod = new MethodDecl(name, "void", "main", new ParameterList(new ArrayList<>()), (BlockStatement) visitBlock(ctx.block()));
|
||||
methodDecls.add(mainMethod);
|
||||
} else {
|
||||
hasMain = false;
|
||||
}
|
||||
for (DecafParser.LocalVarDeclContext fieldDecl: ctx.localVarDecl()) {
|
||||
for (DecafParser.LocalVarDeclContext fieldDecl : ctx.localVarDecl()) {
|
||||
fieldDecls.add((FieldDecl) generateFieldDecl(fieldDecl));
|
||||
}
|
||||
for (DecafParser.ConstuctorDeclContext constDecl: ctx.constuctorDecl()) {
|
||||
for (DecafParser.ConstuctorDeclContext constDecl : ctx.constuctorDecl()) {
|
||||
MethodDecl constructor = ((MethodDecl) visit(constDecl));
|
||||
constructor.classThatContainsMethod = name;
|
||||
methodDecls.add(constructor);
|
||||
}
|
||||
for (DecafParser.MethodDeclContext methodDecl: ctx.methodDecl()) {
|
||||
for (DecafParser.MethodDeclContext methodDecl : ctx.methodDecl()) {
|
||||
MethodDecl method = (MethodDecl) visit(methodDecl);
|
||||
method.classThatContainsMethod = name;
|
||||
methodDecls.add(method);
|
||||
}
|
||||
return new RefType(name,fieldDecls, methodDecls, hasMain);
|
||||
return new RefType(name, fieldDecls, methodDecls, hasMain);
|
||||
}
|
||||
|
||||
public Node generateFieldDecl(DecafParser.LocalVarDeclContext ctx) {
|
||||
@ -99,7 +99,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
} else {
|
||||
type = ctx.type().getText();
|
||||
}
|
||||
return new MethodDecl("", type , name, parameterList, block);
|
||||
return new MethodDecl("", type, name, parameterList, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,7 +110,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
@Override
|
||||
public Node visitParameterList(DecafParser.ParameterListContext ctx) {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
for (DecafParser.ParameterContext parameter: ctx.parameter()) {
|
||||
for (DecafParser.ParameterContext parameter : ctx.parameter()) {
|
||||
parameters.add((Parameter) visit(parameter));
|
||||
}
|
||||
return new ParameterList(parameters);
|
||||
@ -151,7 +151,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
@Override
|
||||
public Node visitBlock(DecafParser.BlockContext ctx) {
|
||||
List<IStatement> stmts = new ArrayList<>();
|
||||
for (DecafParser.StatementContext stmt: ctx.statement()) {
|
||||
for (DecafParser.StatementContext stmt : ctx.statement()) {
|
||||
Node statement = visitStatement(stmt);
|
||||
stmts.add((IStatement) statement);
|
||||
}
|
||||
@ -211,7 +211,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
public Node visitAssign(DecafParser.AssignContext ctx) {
|
||||
Node right = visitExpression(ctx.expression());
|
||||
Node left = visitAssignableExpr(ctx.assignableExpr());
|
||||
return new AssignStatementExpression(ctx.Assign().getText(),(IExpression) left, (IExpression) right);
|
||||
return new AssignStatementExpression(ctx.Assign().getText(), (IExpression) left, (IExpression) right);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -219,7 +219,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
String methodName = ctx.Identifier().getText();
|
||||
List<IExpression> arguments = generateExpressions(ctx.argumentList());
|
||||
List<ReceivingMethod> receivingMethods = new ArrayList<>();
|
||||
for(DecafParser.ReceivingMethodContext receivingMethod: ctx.receivingMethod()) {
|
||||
for (DecafParser.ReceivingMethodContext receivingMethod : ctx.receivingMethod()) {
|
||||
receivingMethods.add((ReceivingMethod) visit(receivingMethod));
|
||||
}
|
||||
if (ctx.receiver() != null) {
|
||||
@ -320,14 +320,14 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
if (ctx.IntValue() != null) {
|
||||
int value = Integer.parseInt(ctx.IntValue().getText());
|
||||
return new IntConstantExpression(value);
|
||||
} else if(ctx.Identifier() != null) {
|
||||
} else if (ctx.Identifier() != null) {
|
||||
String identifier = ctx.Identifier().getText();
|
||||
return new LocalVarIdentifier(identifier);
|
||||
} else if(ctx.instVar() != null) {
|
||||
} else if (ctx.instVar() != null) {
|
||||
return visitInstVar(ctx.instVar());
|
||||
} else if(ctx.methodCall() != null) {
|
||||
} else if (ctx.methodCall() != null) {
|
||||
return visitMethodCall(ctx.methodCall());
|
||||
} else if(ctx.calcExpr() != null) {
|
||||
} else if (ctx.calcExpr() != null) {
|
||||
return visitCalcExpr(ctx.calcExpr());
|
||||
}
|
||||
return null;
|
||||
@ -336,7 +336,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
@Override
|
||||
public Node visitNonCalcExpr(DecafParser.NonCalcExprContext ctx) {
|
||||
String operator;
|
||||
if(ctx.nonCalcOperator().LogicalOpertor() != null) {
|
||||
if (ctx.nonCalcOperator().LogicalOpertor() != null) {
|
||||
operator = ctx.nonCalcOperator().LogicalOpertor().getText();
|
||||
} else {
|
||||
operator = ctx.nonCalcOperator().ComparisonOperator().getText();
|
||||
@ -373,10 +373,10 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
List<SubReceiver> receivers = new ArrayList<>();
|
||||
List<ReceivingMethod> receivingMethods = new ArrayList<>();
|
||||
String fieldName = ctx.Identifier().getText();
|
||||
for(DecafParser.SubReceiverContext subReceiver : ctx.subReceiver()) {
|
||||
for (DecafParser.SubReceiverContext subReceiver : ctx.subReceiver()) {
|
||||
receivers.add((SubReceiver) visit(subReceiver));
|
||||
}
|
||||
for(DecafParser.ReceivingMethodContext receivingMethod: ctx.receivingMethod()) {
|
||||
for (DecafParser.ReceivingMethodContext receivingMethod : ctx.receivingMethod()) {
|
||||
receivingMethods.add((ReceivingMethod) visit(receivingMethod));
|
||||
}
|
||||
return new InstVarExpression(receivers, receivingMethods, fieldName);
|
||||
|
Loading…
Reference in New Issue
Block a user