Compare commits
No commits in common. "e99b7adcd4997be209009c76f365dbf00c12e685" and "b5b6f763e0a04dfd0eb07dad4839c654fa5ac2dc" have entirely different histories.
e99b7adcd4
...
b5b6f763e0
@ -18,6 +18,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
public Node visitProgram(DecafParser.ProgramContext ctx) {
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
for (DecafParser.ClassdeclContext classDecl : ctx.classdecl()) {
|
||||
// Node refType = new RefType(classDecl.Identifier().getText(), new ArrayList<>(), new ArrayList<>());
|
||||
classes.add((RefType) visit(classDecl));
|
||||
}
|
||||
return new Program(classes);
|
||||
@ -27,22 +28,13 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
public Node visitClassdecl(DecafParser.ClassdeclContext ctx) {
|
||||
List<FieldDecl> fieldDecls = new ArrayList<>();
|
||||
List<MethodDecl> methodDecls = new ArrayList<>();
|
||||
boolean hasMain;
|
||||
if(ctx.MainMethodDecl() != null) {
|
||||
hasMain = true;
|
||||
} else {
|
||||
hasMain = false;
|
||||
}
|
||||
for (DecafParser.LocalVarDeclContext fieldDecl: ctx.localVarDecl()) {
|
||||
fieldDecls.add((FieldDecl) visit(fieldDecl));
|
||||
}
|
||||
for (DecafParser.ConstuctorDeclContext constDecl: ctx.constuctorDecl()) {
|
||||
methodDecls.add((MethodDecl) visit(constDecl));
|
||||
}
|
||||
for (DecafParser.MethodDeclContext methodDecl: ctx.methodDecl()) {
|
||||
methodDecls.add((MethodDecl) visit(methodDecl));
|
||||
}
|
||||
return new RefType(ctx.Identifier().getText(),fieldDecls, methodDecls, hasMain);
|
||||
return new RefType(ctx.Identifier().getText(),fieldDecls, methodDecls);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,37 +42,25 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitConstuctorDecl(DecafParser.ConstuctorDeclContext ctx) {
|
||||
String name = ctx.Identifier().getText();
|
||||
ParameterList parameterList = (ParameterList) visit(ctx.parameterList());
|
||||
return new MethodDecl("", "", name, parameterList, new BlockStatement(new ArrayList<>(), "void"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitMethodDecl(DecafParser.MethodDeclContext ctx) {
|
||||
String type;
|
||||
String name = ctx.Identifier().getText();
|
||||
ParameterList parameterList = (ParameterList) visit(ctx.parameterList());
|
||||
if (ctx.Void() != null) {
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
if (ctx.Void() != null) {
|
||||
type = "void";
|
||||
} else {
|
||||
type = ctx.type().getText();
|
||||
}
|
||||
return new MethodDecl("", type , name, parameterList, new BlockStatement(new ArrayList<>(), "void"));
|
||||
DecafParser.ParameterListContext parameterListContext = ctx.parameterList();
|
||||
for (DecafParser.ParameterContext parameter: parameterListContext.parameter()) {
|
||||
parameterList.add((Parameter) visit(parameter));
|
||||
}
|
||||
return new MethodDecl("", type , name, new ParameterList(parameterList), new BlockStatement(new ArrayList<>(), "void"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitParameter(DecafParser.ParameterContext ctx) {
|
||||
return new Parameter(ctx.type().getText(), ctx.Identifier().getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitParameterList(DecafParser.ParameterListContext ctx) {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
for (DecafParser.ParameterContext parameter: ctx.parameter()) {
|
||||
parameters.add((Parameter) visit(parameter));
|
||||
}
|
||||
return new ParameterList(parameters);
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,14 @@ public class RefType extends AbstractType implements IClass, Node {
|
||||
public String name;
|
||||
public List<FieldDecl> fieldDecls;
|
||||
public List<MethodDecl> methodDecls;
|
||||
boolean hasMain;
|
||||
|
||||
public RefType(String name,
|
||||
List<FieldDecl> fieldDecls,
|
||||
List<MethodDecl> methodDecls,
|
||||
boolean hasMain
|
||||
List<MethodDecl> methodDecls
|
||||
){
|
||||
this.name = name;
|
||||
this.fieldDecls = fieldDecls;
|
||||
this.methodDecls = methodDecls;
|
||||
this.hasMain = hasMain;
|
||||
}
|
||||
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext,
|
||||
|
@ -1,13 +1,12 @@
|
||||
package abstractSyntaxTree.Statement;
|
||||
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Node;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public interface IStatement extends Node {
|
||||
public interface IStatement {
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user