Visiters added
This commit is contained in:
parent
56ce3c33c3
commit
44545f7ba6
@ -1,8 +1,8 @@
|
||||
package ast;
|
||||
|
||||
public class FieldNode extends MemberNode {
|
||||
TypeNode type;
|
||||
String name;
|
||||
public TypeNode type;
|
||||
public String name;
|
||||
|
||||
public FieldNode(TypeNode type, String name){
|
||||
this.type = type;
|
||||
|
@ -9,9 +9,13 @@ public class MethodNode extends MemberNode{
|
||||
|
||||
public ParameterListNode parameters;
|
||||
|
||||
public MethodNode(TypeNode visibility, String name, ParameterListNode parameters){
|
||||
public List<StatementNode> statements = new ArrayList<>();
|
||||
|
||||
public MethodNode(TypeNode visibility, String name, ParameterListNode parameters,
|
||||
List<StatementNode> statements){
|
||||
this.visibility = visibility;
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
this.statements = statements;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package ast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParameterListNode {
|
||||
public class ParameterListNode extends ASTNode {
|
||||
List<ParameterNode> parameters = new ArrayList<>();
|
||||
|
||||
public ParameterListNode(){
|
||||
parameters
|
||||
public ParameterListNode(List<ParameterNode> parameters){
|
||||
this.parameters = parameters;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package ast;
|
||||
|
||||
public class ParameterNode extends ASTNode {
|
||||
public TypeNode type;
|
||||
public String identifier;
|
||||
|
||||
public ParameterNode(TypeNode type, String identifier) {
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
public class ParameterNode extends ASTNode {
|
||||
public TypeNode type;
|
||||
public String identifier;
|
||||
package ast;
|
||||
|
||||
public ParameterNode(TypeNode type, String identifier) {
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProgramNode extends ASTNode {
|
||||
public List<ClassNode> classes = new ArrayList<>();
|
||||
|
||||
public void addClass(ClassNode classNode) {
|
||||
classes.add(classNode);
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package bytecode;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import ast.ProgramNode;
|
||||
import ast.ClassNode;
|
||||
|
||||
public class ByteCodeGenerator {
|
||||
|
@ -39,23 +39,17 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
|
||||
TypeNode returnType = (TypeNode) visit(ctx.type());
|
||||
String methodName = ctx.IDENTIFIER().getText();
|
||||
ParameterListNode = (ParameterListNode) visit(ctx.parameterList());
|
||||
List<ParameterNode> parameters = new ArrayList<>();
|
||||
for (SimpleJavaParser.ParameterContext parameter : ctx.parameterList()) {
|
||||
parameters.add(parameter);
|
||||
}
|
||||
MethodNode method = new MethodNode(returnType, methodName);
|
||||
|
||||
for (SimpleJavaParser.ParameterContext paramCtx : ctx.parameterList().parameter()) {
|
||||
method.parameters.add((ParameterNode) visit(paramCtx));
|
||||
}
|
||||
|
||||
ParameterListNode parameterListNode = (ParameterListNode) visit(ctx.parameterList());
|
||||
List<StatementNode> statements = new ArrayList<>();
|
||||
for (SimpleJavaParser.StatementContext stmtCtx : ctx.statement()) {
|
||||
method.statements.add((StatementNode) visit(stmtCtx));
|
||||
statements.add((StatementNode) visit(stmtCtx));
|
||||
}
|
||||
|
||||
MethodNode method = new MethodNode(returnType, methodName, parameterListNode, statements);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTNode visitType(SimpleJavaParser.TypeContext ctx) {
|
||||
return new TypeNode(ctx.getText());
|
||||
@ -78,7 +72,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
for (SimpleJavaParser.ParameterContext paramCtx : ctx.parameter()) {
|
||||
parameters.add((ParameterNode) visitParameter(paramCtx));
|
||||
}
|
||||
return new ParameterListNode(parameters); // Assuming you want to keep a dedicated node for the list
|
||||
return new ParameterListNode(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user