Merge branch 'main' into Tests

This commit is contained in:
Lucas 2024-07-01 23:31:00 +02:00
commit 771b92bfd7
38 changed files with 866 additions and 120 deletions

2
.idea/misc.xml generated
View File

@ -6,7 +6,7 @@
<PerGrammarGenerationSettings> <PerGrammarGenerationSettings>
<option name="fileName" value="$PROJECT_DIR$/src/main/java/parser/SimpleJava.g4" /> <option name="fileName" value="$PROJECT_DIR$/src/main/java/parser/SimpleJava.g4" />
<option name="autoGen" value="true" /> <option name="autoGen" value="true" />
<option name="outputDir" value="C:\Users\Johannes\Documents\Github\JavaCompiler\src\main\java" /> <option name="outputDir" value="C:\Users\ARB00075\Documents\DH\Compilerbau\NichtHaskell2.0\src\main\java" />
<option name="libDir" value="" /> <option name="libDir" value="" />
<option name="encoding" value="" /> <option name="encoding" value="" />
<option name="pkg" value="parser.generated" /> <option name="pkg" value="parser.generated" />

View File

@ -1,5 +1,6 @@
package ast; package ast;
import bytecode.visitor.ProgramVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
@ -18,4 +19,9 @@ public class ProgramNode implements ASTNode, Visitable {
public TypeCheckResult accept(SemanticVisitor visitor) { public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(ProgramVisitor programVisitor) {
programVisitor.visit(this);
}
} }

View File

@ -2,10 +2,12 @@ package ast.expressions.binaryexpressions;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import ast.type.type.*; import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable;
public class BinaryNode implements IExpressionNode { public class BinaryNode implements IExpressionNode, Visitable {
private ITypeNode typeNode; private ITypeNode typeNode;
@ -23,4 +25,9 @@ public class BinaryNode implements IExpressionNode {
public void setType(ITypeNode type) { public void setType(ITypeNode type) {
this.typeNode = type; this.typeNode = type;
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,6 +1,7 @@
package ast.expressions.binaryexpressions; package ast.expressions.binaryexpressions;
import ast.type.type.*; import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -33,4 +34,10 @@ public class CalculationNode extends BinaryNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,6 +1,7 @@
package ast.expressions.binaryexpressions; package ast.expressions.binaryexpressions;
import ast.type.type.*; import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -34,4 +35,9 @@ public class DotNode extends BinaryNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -4,6 +4,7 @@ import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode; import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.type.type.*; import ast.type.type.*;
import ast.type.ValueNode; import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -36,4 +37,9 @@ public class DotSubstractionNode extends BinaryNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -3,6 +3,7 @@ package ast.expressions.binaryexpressions;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import ast.expressions.unaryexpressions.UnaryNode; import ast.expressions.unaryexpressions.UnaryNode;
import ast.type.type.*; import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -42,4 +43,9 @@ public class NonCalculationNode extends BinaryNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,6 +1,7 @@
package ast.expressions.unaryexpressions; package ast.expressions.unaryexpressions;
import ast.ASTNode; import ast.ASTNode;
import bytecode.visitor.MethodVisitor;
import ast.type.type.ITypeNode; import ast.type.type.ITypeNode;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -23,6 +24,10 @@ public class MemberAccessNode implements ASTNode, Visitable {
} }
@Override @Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public TypeCheckResult accept(SemanticVisitor visitor) { public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this); return visitor.analyze(this);
} }

View File

@ -2,12 +2,26 @@ package ast.expressions.unaryexpressions;
import ast.ASTNode; import ast.ASTNode;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class NotNode implements ASTNode { public class NotNode implements ASTNode, Visitable {
public IExpressionNode expression; public IExpressionNode expression;
public NotNode(IExpressionNode expression) { public NotNode(IExpressionNode expression) {
this.expression = expression; this.expression = expression;
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;
}
} }

View File

@ -4,6 +4,7 @@ import ast.expressions.IExpressionNode;
import ast.statements.IStatementNode; import ast.statements.IStatementNode;
import ast.type.type.*; import ast.type.type.*;
import ast.type.ValueNode; import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -61,4 +62,9 @@ public class UnaryNode implements IExpressionNode {
this.type = type; this.type = type;
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -0,0 +1,11 @@
package ast.literal;
public class BooleanLiteralNode {
private String value;
public BooleanLiteralNode(String value) {this.value = value;}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,11 @@
package ast.literal;
public class CharLiteralNode {
public String value;
public CharLiteralNode(String value) {this.value = value;}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,31 @@
package ast.literal;
import ast.expression.ExpressionNode;
import ast.type.TypeNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class LiteralNode implements ExpressionNode {
public String value;
private TypeNode type;
public LiteralNode(String value, TypeNode type) {
this.value = value;
this.type = type;
}
public TypeNode getType() {
return type;
}
public void setType(TypeNode type) {
this.type = type;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;
}
}

View File

@ -3,12 +3,14 @@ package ast.members;
import ast.parameters.ParameterNode; import ast.parameters.ParameterNode;
import ast.statements.BlockNode; import ast.statements.BlockNode;
import ast.type.AccessModifierNode; import ast.type.AccessModifierNode;
import bytecode.visitor.MethodVisitor;
import visitor.Visitable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public class ConstructorNode extends MethodNode { public class ConstructorNode extends MethodNode implements Visitable {
public AccessModifierNode accessType; public AccessModifierNode accessType;
public String identifier; public String identifier;
public List<ParameterNode> parameters = new ArrayList<>(); public List<ParameterNode> parameters = new ArrayList<>();
@ -25,6 +27,10 @@ public class ConstructorNode extends MethodNode {
} }
@Override @Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public boolean isSame(MethodNode methodNode) { public boolean isSame(MethodNode methodNode) {
if (!(Objects.equals(this.identifier, methodNode.getIdentifier())) if (!(Objects.equals(this.identifier, methodNode.getIdentifier()))
|| getParameters().size() != methodNode.getParameters().size()) { || getParameters().size() != methodNode.getParameters().size()) {

View File

@ -2,6 +2,8 @@ package ast.members;
import ast.type.AccessModifierNode; import ast.type.AccessModifierNode;
import ast.type.type.ITypeNode; import ast.type.type.ITypeNode;
import bytecode.visitor.ClassVisitor;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
@ -22,4 +24,9 @@ public class FieldNode implements MemberNode, Visitable {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
} }

View File

@ -1,10 +1,18 @@
package ast.members; package ast.members;
import ast.statements.BlockNode; import ast.statements.BlockNode;
import bytecode.visitor.MethodVisitor;
import visitor.Visitable;
public class MainMethodNode extends MethodNode { public class MainMethodNode extends MethodNode implements Visitable {
public BlockNode block;
public MainMethodNode(BlockNode block) { public MainMethodNode(BlockNode block) {
this.block = block; this.block = block;
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -21,7 +21,8 @@ public class MethodNode implements MemberNode, Visitable {
public List<ParameterNode> parameters = new ArrayList<>(); public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block; public BlockNode block;
public MethodNode() {} public MethodNode() {
}
public MethodNode(String accessModifier, ITypeNode type, Boolean voidType, String identifier, BlockNode block){ public MethodNode(String accessModifier, ITypeNode type, Boolean voidType, String identifier, BlockNode block){
this.accesModifier = new AccessModifierNode(accessModifier); this.accesModifier = new AccessModifierNode(accessModifier);

View File

@ -0,0 +1,11 @@
package ast.statement;
import ast.statements.IStatementNode;
import java.util.List;
public class BlockStatementNode {
List<IStatementNode> statements;
public BlockStatementNode(List<IStatementNode> statements) {this.statements = statements;}
}

View File

@ -1,6 +1,7 @@
package ast.statementexpressions; package ast.statementexpressions;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -18,4 +19,9 @@ public class AssignNode implements IStatementExpressionNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,6 +1,7 @@
package ast.statementexpressions; package ast.statementexpressions;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -24,4 +25,9 @@ public class NewDeclarationNode implements IStatementExpressionNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -2,8 +2,10 @@ package ast.statementexpressions.crementexpressions;
import ast.statementexpressions.AssignableNode; import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode; import ast.statementexpressions.IStatementExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable;
public class DecrementNode implements IStatementExpressionNode { public class DecrementNode implements IStatementExpressionNode {
public CrementType crementType; public CrementType crementType;
@ -19,4 +21,9 @@ public class DecrementNode implements IStatementExpressionNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -2,6 +2,7 @@ package ast.statementexpressions.crementexpressions;
import ast.statementexpressions.AssignableNode; import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode; import ast.statementexpressions.IStatementExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -19,4 +20,9 @@ public class IncrementNode implements IStatementExpressionNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -2,11 +2,15 @@ package ast.statementexpressions.methodcallstatementnexpressions;
import ast.ASTNode; import ast.ASTNode;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ChainedMethodNode implements ASTNode { public class ChainedMethodNode implements ASTNode, Visitable {
public String identifier; public String identifier;
public List<IExpressionNode> expressions = new ArrayList<>(); public List<IExpressionNode> expressions = new ArrayList<>();
@ -17,4 +21,14 @@ public class ChainedMethodNode implements ASTNode {
public void addExpression(IExpressionNode expression) { public void addExpression(IExpressionNode expression) {
expressions.add(expression); expressions.add(expression);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;
}
} }

View File

@ -2,6 +2,7 @@ package ast.statementexpressions.methodcallstatementnexpressions;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import ast.statements.IStatementNode; import ast.statements.IStatementNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -32,4 +33,9 @@ public class MethodCallNode implements IStatementNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -3,6 +3,7 @@ package ast.statementexpressions.methodcallstatementnexpressions;
import ast.ASTNode; import ast.ASTNode;
import ast.expressions.unaryexpressions.MemberAccessNode; import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.NewDeclarationNode; import ast.statementexpressions.NewDeclarationNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
@ -30,6 +31,10 @@ public class TargetNode implements ASTNode, Visitable {
} }
@Override @Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public TypeCheckResult accept(SemanticVisitor visitor) { public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this); return visitor.analyze(this);
} }

View File

@ -0,0 +1,10 @@
package ast.statements;
import java.util.List;
public class BlockStatementNode {
List<IStatementNode> statements;
public BlockStatementNode(List<IStatementNode> statements) {this.statements = statements;}
}

View File

@ -1,6 +1,5 @@
package ast.statements; package ast.statements;
import ast.ASTNode;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;

View File

@ -1,6 +1,5 @@
package ast.statements; package ast.statements;
import ast.ASTNode;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;

View File

@ -1,6 +1,5 @@
package ast.statements; package ast.statements;
import ast.ASTNode;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;

View File

@ -2,6 +2,7 @@ package ast.statements;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import ast.type.type.*; import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -23,4 +24,9 @@ public class LocalVariableDeclarationNode implements IStatementNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,6 +1,7 @@
package ast.statements; package ast.statements;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -21,4 +22,9 @@ public class ReturnNode implements IStatementNode {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,6 +1,5 @@
package ast.statements; package ast.statements;
import ast.ASTNode;
import ast.expressions.IExpressionNode; import ast.expressions.IExpressionNode;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;

View File

@ -1,6 +1,7 @@
package ast.type; package ast.type;
import ast.ASTNode; import ast.ASTNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
@ -14,6 +15,10 @@ public class ValueNode implements ASTNode, Visitable {
this.value = value; this.value = value;
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override @Override
public TypeCheckResult accept(SemanticVisitor visitor) { public TypeCheckResult accept(SemanticVisitor visitor) {

View File

@ -2,21 +2,78 @@ package bytecode;
import ast.ProgramNode; import ast.ProgramNode;
import ast.ClassNode; import ast.ClassNode;
import ast.members.MainMethodNode;
import ast.members.MemberNode;
import bytecode.visitor.ProgramVisitor; import bytecode.visitor.ProgramVisitor;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
public class ByteCodeGenerator implements ProgramVisitor { public class ByteCodeGenerator implements ProgramVisitor {
private final String outputDirectoryPath; private JarOutputStream jarOutputStream;
private ByteArrayOutputStream byteArrayOutputStream;
private String outputDirectory;
public ByteCodeGenerator(String outputDirectoryPath) { public ByteCodeGenerator(String outputDirectory) {
this.outputDirectoryPath = outputDirectoryPath; this.outputDirectory = outputDirectory;
} }
@Override @Override
public void visit(ProgramNode programNode) { public void visit(ProgramNode programNode) {
for (ClassNode classDeclarationNode : programNode.classes) { byteArrayOutputStream = new ByteArrayOutputStream();
// ClassCodeGen classCodeGen = new ClassCodeGen(); try {
// classDeclarationNode.accept(classCodeGen); Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
boolean foundMainClass = false;
for (ClassNode classNode : programNode.classes) {
if (foundMainClass) {
break;
}
for (MemberNode memberNode : classNode.members) {
if (memberNode instanceof MainMethodNode) {
manifest.getMainAttributes().putValue("Main-Class", classNode.identifier);
foundMainClass = true;
break;
}
}
}
jarOutputStream = new JarOutputStream(byteArrayOutputStream, manifest);
} catch (IOException e) {
throw new RuntimeException(e);
}
for (ClassNode classDeclarationNode : programNode.classes) {
ClassCodeGen classCodeGen = new ClassCodeGen(jarOutputStream, outputDirectory);
classDeclarationNode.accept(classCodeGen);
}
try {
jarOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
saveJarFile(byteArrayOutputStream.toByteArray(), "output.jar");
}
private void saveJarFile(byte[] jarBytes, String jarFileName) {
File directory = new File(outputDirectory);
if (!directory.exists()) {
directory.mkdirs();
}
File jarFile = new File(directory, jarFileName);
try (FileOutputStream fos = new FileOutputStream(jarFile)) {
fos.write(jarBytes);
} catch (IOException e) {
e.printStackTrace();
}
} }
}
} }

View File

@ -10,26 +10,31 @@ import bytecode.visitor.ClassVisitor;
import java.io.File; import java.io.File;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
public class ClassCodeGen implements ClassVisitor { public class ClassCodeGen implements ClassVisitor {
private Mapper mapper; private Mapper mapper;
private ClassWriter classWriter; private ClassWriter classWriter;
private final String outputDirectoryPath; private JarOutputStream jarOutputStream;
private String outputDirectory;
public ClassCodeGen(String outputDirectoryPath) { public ClassCodeGen(JarOutputStream jarOutputStream, String outputDirectory) {
this.outputDirectoryPath = outputDirectoryPath;
mapper = new Mapper(); mapper = new Mapper();
this.jarOutputStream = jarOutputStream;
this.outputDirectory = outputDirectory;
} }
@Override @Override
public void visit(ClassNode classNode) { public void visit(ClassNode classNode) {
classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
// classWriter.visit(Opcodes.V1_5, mapper.mapAccessTypeToOpcode(classNode.accessType), classNode.identifier, null, classWriter.visit(Opcodes.V1_5, mapper.mapAccessTypeToOpcode(classNode.accessType), classNode.identifier, null,
// "java/lang/Object", null); "java/lang/Object", null);
for (MemberNode memberNode : classNode.members) { for (MemberNode memberNode : classNode.members) {
if (memberNode instanceof FieldNode) { if (memberNode instanceof FieldNode) {
@ -41,28 +46,27 @@ public class ClassCodeGen implements ClassVisitor {
} }
classWriter.visitEnd(); classWriter.visitEnd();
printIntoClassFile(classWriter.toByteArray(), classNode.identifier); writeToJar(classWriter.toByteArray(), classNode.identifier);
printIntoClassFile(classWriter.toByteArray(), classNode.identifier, outputDirectory);
classWriter.visitEnd(); classWriter.visitEnd();
} }
@Override @Override
public void visit(FieldNode fieldNode) { public void visit(FieldNode fieldNode) {
if(fieldNode.type instanceof BaseType baseTypeNode){ if (fieldNode.type instanceof BaseType) {
// classWriter.visitField(mapper.mapAccessTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar(baseTypeNode.enumType), null, null ); classWriter.visitField(mapper.mapAccessTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar((BaseType) fieldNode.type), null, null);
} }
classWriter.visitEnd(); classWriter.visitEnd();
} }
private void printIntoClassFile(byte[] byteCode, String name) { private void printIntoClassFile(byte[] byteCode, String name, String outputDirectory) {
// String outputDirectoryPath = "src/main/resources/output"; File directory = new File(outputDirectory);
// System.out.println("Output directory path: " + outputDirectoryPath);
File directory = new File(outputDirectoryPath);
if (!directory.exists()) { if (!directory.exists()) {
directory.mkdirs(); directory.mkdirs();
} }
String filePath = outputDirectoryPath + "/" + name + ".class"; String filePath = outputDirectory + "/" + name + ".class";
try { try {
FileOutputStream fileOutputStream = new FileOutputStream(filePath); FileOutputStream fileOutputStream = new FileOutputStream(filePath);
fileOutputStream.write(byteCode); fileOutputStream.write(byteCode);
@ -71,4 +75,15 @@ public class ClassCodeGen implements ClassVisitor {
e.printStackTrace(); e.printStackTrace();
} }
} }
private void writeToJar(byte[] byteCode, String className) {
try {
JarEntry jarEntry = new JarEntry(className + ".class");
jarOutputStream.putNextEntry(jarEntry);
jarOutputStream.write(byteCode);
jarOutputStream.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
}
} }

View File

@ -1,41 +1,60 @@
package bytecode; package bytecode;
import ast.parameters.ParameterNode;
import ast.type.*; import ast.type.*;
import ast.type.type.BaseType;
import ast.type.type.ReferenceType;
import ast.type.type.TypeEnum;
import org.objectweb.asm.Opcodes;
import java.util.List;
public class Mapper { public class Mapper {
// public int mapAccessTypeToOpcode(AccessModifierNode type) { public int mapAccessTypeToOpcode(AccessModifierNode accessModifierNode) {
// switch (type.enumAccessTypeNode) { switch (accessModifierNode.accessType) {
// case EnumAccessTypeNode.PUBLIC: case EnumAccessModifierNode.PUBLIC:
// return Opcodes.ACC_PUBLIC; return Opcodes.ACC_PUBLIC;
// case EnumAccessTypeNode.PRIVATE: case EnumAccessModifierNode.PRIVATE:
// return Opcodes.ACC_PRIVATE; return Opcodes.ACC_PRIVATE;
// } case EnumAccessModifierNode.PUBLIC_STATIC:
// return 0; return Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
// } case EnumAccessModifierNode.PRIVATE_STATIC:
return Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC;
}
return 0;
}
// public String generateMethodDescriptor(BaseTypeNode baseTypeNode, ParameterListNode parameterListNode) { public String generateMethodDescriptor(BaseType type, List<ParameterNode> parameters) {
// String descriptor = "("; String descriptor = "(";
// for(ParameterNode parameterNode : parameterListNode.parameters) { for (ParameterNode parameterNode : parameters) {
// descriptor += getTypeChar(EnumTypeNode.INT); descriptor += getTypeChar((BaseType) parameterNode.type);
// } }
// descriptor += ")"; descriptor += ")";
// descriptor += getTypeChar(baseTypeNode.enumType); descriptor += getTypeChar(type);
// return descriptor; return descriptor;
// } }
// public String getTypeChar(TypeEnum enumTypeNode) { public String generateMethodDescriptor(ReferenceType type, List<ParameterNode> parameters) {
// String typeChar = ""; String descriptor = "()V";
// switch (enumTypeNode) { return descriptor;
// case TypeEnum.INT: }
// typeChar = "I";
// break; public String getTypeChar(BaseType type) {
// case TypeEnum.CHAR: String typeChar = "";
// typeChar = "C"; switch (type.getTypeEnum()) {
// break; case TypeEnum.INT:
// case TypeEnum.BOOLEAN: typeChar = "I";
// typeChar = "Z"; break;
// break; case TypeEnum.CHAR:
// } typeChar = "C";
// return typeChar; break;
// } case TypeEnum.BOOL:
typeChar = "Z";
break;
case TypeEnum.VOID:
typeChar = "V";
break;
}
return typeChar;
}
} }

View File

@ -1,9 +1,28 @@
package bytecode; package bytecode;
import ast.expressions.binaryexpressions.*;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.NotNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.members.ConstructorNode; import ast.members.ConstructorNode;
import ast.members.MainMethodNode;
import ast.members.MethodNode; import ast.members.MethodNode;
import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.ValueNode;
import ast.type.type.BaseType;
import ast.type.type.TypeEnum;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -25,70 +44,433 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
localVaribales = new ArrayList<>(); localVaribales = new ArrayList<>();
} }
// Method nodes
@Override @Override
public void visit(ConstructorNode constructorNode) { public void visit(ConstructorNode constructorNode) {
// methodVisitor = methodVisitor =
// classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.visibility), classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accessType),
// "<init>", "<init>",
// "()V", mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters),
// null, null,
// null); null);
methodVisitor.visitCode(); methodVisitor.visitCode();
localVaribales.add("this");
// Add all method parameters to localVariables
for (ParameterNode parameterNode : constructorNode.parameters) {
localVaribales.add(parameterNode.identifier);
}
methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(1, 1); // Visit all statements
for (IStatementNode statementNode : constructorNode.block.statements) {
statementNode.accept(this);
}
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
@Override
public void visit(MainMethodNode mainMethodNode) {
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(mainMethodNode.accesModifier),
mainMethodNode.getIdentifier(),
"([Ljava/lang/String;)V",
null,
null);
methodVisitor.visitCode();
localVaribales.add("this");
localVaribales.add("args");
// Visit all statements
for (IStatementNode statementNode : mainMethodNode.block.statements) {
statementNode.accept(this);
}
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd(); methodVisitor.visitEnd();
} }
@Override @Override
public void visit(MethodNode methodNode) { public void visit(MethodNode methodNode) {
// if (methodNode.type instanceof BaseTypeNode baseTypeNode) { methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.accesModifier),
// methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.visibility), methodNode.getIdentifier(),
// methodNode.identifier, mapper.generateMethodDescriptor((BaseType) methodNode.getType(), methodNode.parameters),
// mapper.generateMethodDescriptor(baseTypeNode, methodNode.parameters), null,
// null, null);
// null);
methodVisitor.visitCode(); methodVisitor.visitCode();
localVaribales.add("this"); localVaribales.add("this");
// for (ParameterNode parameterNode : methodNode.parameters.parameters) { // Add all method parameters to localVariables
// localVaribales.add(parameterNode.identifier); for (ParameterNode parameterNode : methodNode.parameters) {
// } localVaribales.add(parameterNode.identifier);
}
//test(); // Visit all statements
methodVisitor.visitMaxs(1, localVaribales.size()); for (IStatementNode statementNode : methodNode.block.statements) {
methodVisitor.visitEnd(); statementNode.accept(this);
// } }
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
} }
// public void test() {
// Label start = new Label(); // Binary expressions
// Label loop = new Label();
// Label end = new Label(); @Override
// methodVisitor.visitLabel(start); public void visit(BinaryNode binaryNode) {
// //methodVisitor.visitVarInsn(Opcodes.ICONST_M1, 99); binaryNode.accept(this);
// //methodVisitor.visitInsn(Opcodes.ICONST_5); }
// methodVisitor.visitLdcInsn(99);
// // methodVisitor.visitInsn(Opcodes.ICONST_0); @Override
// //methodVisitor.visitVarInsn(Opcodes.ILOAD, 2); public void visit(CalculationNode calculationNode) {
// methodVisitor.visitVarInsn(Opcodes.ISTORE, 1); calculationNode.dotExpression.accept(this);
// methodVisitor.visitLabel(loop); calculationNode.calculationExpression.accept(this);
// methodVisitor.visitVarInsn(Opcodes.ILOAD, 1); switch (calculationNode.operator) {
// methodVisitor.visitInsn(Opcodes.ICONST_5); case PLUS:
// methodVisitor.visitJumpInsn(Opcodes.IF_ICMPGE, end); methodVisitor.visitInsn(IADD);
// methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, break;
// "java/lang/System", "out", case MINUS:
// "Ljava/io/PrintStream;"); methodVisitor.visitInsn(ISUB);
// methodVisitor.visitLdcInsn("Bytecode"); break;
// methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, }
// "java/io/PrintStream", "println", }
// "(Ljava/lang/String;)V", false);
// methodVisitor.visitIincInsn(1, 1); @Override
// methodVisitor.visitJumpInsn(Opcodes.GOTO, loop); public void visit(DotNode dotNode) {
// methodVisitor.visitLabel(end); dotNode.dotExpression.accept(this);
// methodVisitor.visitVarInsn(Opcodes.ILOAD, 1); dotNode.dotSubstractionExpression.accept(this);
// methodVisitor.visitInsn(Opcodes.IRETURN); switch (dotNode.operator) {
// methodVisitor.visitEnd(); case DIV:
// } methodVisitor.visitInsn(IDIV);
break;
case MULT:
methodVisitor.visitInsn(IMUL);
break;
case MOD:
methodVisitor.visitInsn(IREM);
break;
}
}
@Override
public void visit(DotSubstractionNode dotSubstractionNode) {
if (dotSubstractionNode.value != null) {
dotSubstractionNode.value.accept(this);
} else if (dotSubstractionNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVaribales.indexOf(dotSubstractionNode.identifier));
} else if (dotSubstractionNode.memberAccess != null) {
dotSubstractionNode.memberAccess.accept(this);
} else if (dotSubstractionNode.methodCall != null) {
dotSubstractionNode.methodCall.accept(this);
} else if (dotSubstractionNode.calculationExpression != null) {
dotSubstractionNode.calculationExpression.accept(this);
}
}
@Override
public void visit(NonCalculationNode nonCalculationNode) {
Label labelFalse = new Label();
Label labelTrue = new Label();
switch (nonCalculationNode.operator) {
case AND:
nonCalculationNode.unaryExpression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, labelFalse); // Value compared to 0 (false)
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
break;
case OR:
nonCalculationNode.unaryExpression.accept(this);
methodVisitor.visitJumpInsn(IFNE, labelTrue);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
break;
case GREATER:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPLE, labelFalse);
break;
case LESS:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPGE, labelFalse);
break;
case GREATER_EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPLT, labelFalse);
break;
case LESS_EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPGT, labelFalse);
break;
case EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
if (nonCalculationNode.unaryExpression.getType() instanceof BaseType && nonCalculationNode.expression.getType() instanceof BaseType) {
methodVisitor.visitJumpInsn(IF_ICMPNE, labelFalse);
} else {
methodVisitor.visitJumpInsn(IF_ACMPNE, labelFalse);
}
break;
case NOT_EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
if (nonCalculationNode.unaryExpression.getType() instanceof BaseType && nonCalculationNode.expression.getType() instanceof BaseType) {
methodVisitor.visitJumpInsn(IF_ACMPEQ, labelFalse);
} else {
methodVisitor.visitJumpInsn(IF_ACMPEQ, labelFalse);
}
break;
}
Label labelEndLogicalExpression = new Label();
methodVisitor.visitLabel(labelTrue);
methodVisitor.visitInsn(ICONST_1); // true
methodVisitor.visitJumpInsn(GOTO, labelEndLogicalExpression);
methodVisitor.visitLabel(labelFalse);
methodVisitor.visitInsn(ICONST_0); // false
methodVisitor.visitLabel(labelEndLogicalExpression);
}
// Unary expressions
@Override
public void visit(MemberAccessNode memberAccessNode) {
if (memberAccessNode.thisExpr) {
//methodVisitor.visitFieldInsn(PUTFIELD);
}
}
@Override
public void visit(NotNode notNode) {
Label labelFalse = new Label();
Label labelTrue = new Label();
notNode.expression.accept(this);
methodVisitor.visitJumpInsn(Opcodes.IFNE, labelFalse); // false if value is true (value != 0)
Label labelEndLogicalExpression = new Label();
methodVisitor.visitLabel(labelTrue);
methodVisitor.visitInsn(ICONST_1); // true
methodVisitor.visitJumpInsn(GOTO, labelEndLogicalExpression);
methodVisitor.visitLabel(labelFalse);
methodVisitor.visitInsn(ICONST_0); // false
methodVisitor.visitLabel(labelEndLogicalExpression);
}
@Override
public void visit(UnaryNode unaryNode) {
}
// Statements
@Override
public void visit(IfElseNode ifElseNode) {
Label elseLabel = new Label();
Label[] elseIfLabels = new Label[ifElseNode.elseIfStatements.size()];
for(int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
elseIfLabels[i] = new Label();
}
ifElseNode.ifStatement.expression.accept(this);
if (ifElseNode.elseIfStatements.isEmpty()) {
// No else if
methodVisitor.visitJumpInsn(IFEQ, elseLabel);
} else {
// else if statements
methodVisitor.visitJumpInsn(IFEQ, elseIfLabels[0]);
}
ifElseNode.ifStatement.block.accept(this); // accept if block
Label endLabel = new Label();
methodVisitor.visitJumpInsn(GOTO, endLabel);
for(int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
methodVisitor.visitLabel(elseIfLabels[i]);
ifElseNode.elseIfStatements.get(i).expression.accept(this);
if(i + 1 < elseIfLabels.length) {
// at least one more else if
methodVisitor.visitJumpInsn(IFEQ, elseIfLabels[i+1]);
} else {
methodVisitor.visitJumpInsn(IFEQ, elseLabel);
}
ifElseNode.elseIfStatements.get(i).block.accept(this);
methodVisitor.visitJumpInsn(GOTO, endLabel);
}
if(ifElseNode.elseStatement != null) {
methodVisitor.visitLabel(elseLabel);
ifElseNode.elseStatement.block.accept(this);
}
methodVisitor.visitLabel(endLabel);
}
@Override
public void visit(LocalVariableDeclarationNode localVariableDeclarationNode) {
// Process expression
localVariableDeclarationNode.expression.accept(this);
// Store result of expression in variable
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(localVariableDeclarationNode.identifier));
}
@Override
public void visit(AssignNode assignNode) {
// Process expression
assignNode.expression.accept(this);
// Store result of expression in variable
if (assignNode.assignable.memberAccess.thisExpr) {
// Global var
// /methodVisitor.visitFieldInsn(PUTFIELD, identifierExpressionNode.name, identifierExpressionNode1.name, mapper.getTypeChar(((BaseTypeNode) type).enumType));
} else {
// Local var
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(assignNode.assignable.identifier));
}
}
@Override
public void visit(NewDeclarationNode newDeclarationNode) {
}
@Override
public void visit(ValueNode valueNode) {
switch (valueNode.valueType) {
case INT_VALUE:
int intValue = Integer.parseInt(valueNode.value);
if (intValue >= Byte.MIN_VALUE && intValue <= Byte.MAX_VALUE) { // load int as byte
methodVisitor.visitIntInsn(BIPUSH, intValue);
} else if (intValue >= Short.MIN_VALUE && intValue <= Short.MAX_VALUE) { // load int as short
methodVisitor.visitIntInsn(SIPUSH, intValue);
} else { // load int as const
methodVisitor.visitLdcInsn(intValue);
}
break;
case BOOLEAN_VALUE:
if (valueNode.value.equals("true")) {
methodVisitor.visitInsn(ICONST_1);
} else {
methodVisitor.visitInsn(ICONST_0);
}
break;
case CHAR_VALUE:
char charValue = valueNode.value.charAt(0);
if (charValue <= Byte.MAX_VALUE) { // load char as byte
methodVisitor.visitIntInsn(BIPUSH, charValue);
} else if (charValue <= Short.MAX_VALUE) { // load char as short
methodVisitor.visitIntInsn(SIPUSH, charValue);
} else { // load char as const
methodVisitor.visitLdcInsn(charValue);
}
break;
case NULL_VALUE:
methodVisitor.visitInsn(ACONST_NULL);
break;
}
}
@Override
public void visit(ReturnNode returnNode) {
if (returnNode.voidReturn) { // Return nothing
methodVisitor.visitInsn(RETURN);
} else { // Return something
// Process expression
returnNode.expression.accept(this);
// Return result of expression
methodVisitor.visitInsn(IRETURN);
}
}
@Override
public void visit(WhileNode whileNode) {
Label loopLabel = new Label();
Label endOfLoopLabel = new Label();
methodVisitor.visitLabel(loopLabel);
// while loop
whileNode.expression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, endOfLoopLabel); // if condition is false, jump out of loop
whileNode.block.accept(this);
methodVisitor.visitJumpInsn(GOTO, loopLabel);
methodVisitor.visitLabel(endOfLoopLabel);
}
@Override
public void visit(DecrementNode decrementNode) {
switch (decrementNode.crementType) {
case PREFIX: // --i
if (decrementNode.assignableExpression.memberAccess == null) { // local Var
methodVisitor.visitIincInsn(localVaribales.indexOf(decrementNode.assignableExpression.identifier), -1);
} else { // Field or var from other object
}
break;
case SUFFIX: // i--
if (decrementNode.assignableExpression.memberAccess == null) { // local Var
methodVisitor.visitIincInsn(localVaribales.indexOf(decrementNode.assignableExpression.identifier), -1);
} else { // Field or var from other object
}
break;
}
}
@Override
public void visit(IncrementNode incrementNode) {
switch (incrementNode.crementType) {
case PREFIX: // ++i
if (incrementNode.assignableExpression.memberAccess == null) { // local Var
methodVisitor.visitIincInsn(localVaribales.indexOf(incrementNode.assignableExpression.identifier), 1);
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(incrementNode.assignableExpression.identifier));
} else { // Field or var from other object
}
break;
case SUFFIX: // i++
if (incrementNode.assignableExpression.memberAccess == null) { // local Var
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(incrementNode.assignableExpression.identifier));
methodVisitor.visitIincInsn(localVaribales.indexOf(incrementNode.assignableExpression.identifier), 1);
} else { // Field or var from other object
}
break;
}
}
@Override
public void visit(ChainedMethodNode chainedMethodNode) {
}
@Override
public void visit(MethodCallNode methodCallNode) {
}
@Override
public void visit(TargetNode targetNode) {
}
} }

View File

@ -1,9 +1,60 @@
package bytecode.visitor; package bytecode.visitor;
import ast.expressions.binaryexpressions.*;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.NotNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.members.ConstructorNode; import ast.members.ConstructorNode;
import ast.members.MainMethodNode;
import ast.members.MethodNode; import ast.members.MethodNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.ValueNode;
public interface MethodVisitor { public interface MethodVisitor {
// members
void visit(ConstructorNode constructorNode); void visit(ConstructorNode constructorNode);
void visit(MethodNode methodNode); void visit(MethodNode methodNode);
void visit(MainMethodNode mainMethodNode);
// Binary expressions
void visit(BinaryNode binaryNode);
void visit(CalculationNode calculationNode);
void visit(DotNode dotNode);
void visit(DotSubstractionNode dotSubstractionNode);
void visit(NonCalculationNode nonCalculationNode);
// Unary expressions
void visit(MemberAccessNode memberAccessNode);
void visit(NotNode notExpressionNode);
void visit(UnaryNode unaryExpressionNode);
// statements
void visit(IfElseNode ifElseNode);
void visit(LocalVariableDeclarationNode localVariableDeclarationNode);
void visit(ReturnNode returnNode);
void visit(WhileNode whileNode);
// statement expression
void visit(DecrementNode decrementNode);
void visit(IncrementNode incrementNode);
void visit(ChainedMethodNode chainedMethodNode);
void visit(MethodCallNode methodCallNode);
void visit(TargetNode targetNode);
void visit(AssignNode assignNode);
void visit(NewDeclarationNode newDeclarationNode);
// type
void visit(ValueNode valueNode);
} }