Renaming again
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
f27a7471bc
commit
fd8d451ba7
@ -1,6 +1,8 @@
|
||||
package ast.members;
|
||||
|
||||
import ast.statements.BlockNode;
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import visitor.Visitable;
|
||||
|
||||
public class MainMethodNode extends MethodNode implements Visitable {
|
||||
public BlockNode block;
|
||||
|
@ -4,8 +4,8 @@ import ast.ASTNode;
|
||||
import ast.expressions.IExpressionNode;
|
||||
|
||||
public class IfNode implements ASTNode {
|
||||
IExpressionNode expression;
|
||||
BlockNode block;
|
||||
public IExpressionNode expression;
|
||||
public BlockNode block;
|
||||
|
||||
public IfNode(IExpressionNode expression, BlockNode block) {
|
||||
this.expression = expression;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package bytecode;
|
||||
|
||||
import ast.parameter.ParameterNode;
|
||||
import ast.parameters.ParameterNode;
|
||||
import ast.type.*;
|
||||
import ast.type.type.BaseType;
|
||||
import ast.type.type.ReferenceType;
|
||||
|
@ -1,7 +1,16 @@
|
||||
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.MainMethodNode;
|
||||
import ast.members.MethodNode;
|
||||
import ast.parameters.ParameterNode;
|
||||
import ast.statementexpressions.AssignNode;
|
||||
import ast.statements.*;
|
||||
import ast.type.type.BaseType;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
@ -94,15 +103,15 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
// Binary expressions
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpressionNode binaryExpressionNode) {
|
||||
binaryExpressionNode.accept(this);
|
||||
public void visit(BinaryNode binaryNode) {
|
||||
binaryNode.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CalculationExpressionNode calculationExpressionNode) {
|
||||
calculationExpressionNode.dotExpression.accept(this);
|
||||
calculationExpressionNode.calculationExpression.accept(this);
|
||||
switch (calculationExpressionNode.operator) {
|
||||
public void visit(CalculationNode calculat) {
|
||||
calculat.dotExpression.accept(this);
|
||||
calculat.calculationExpression.accept(this);
|
||||
switch (calculat.operator) {
|
||||
case PLUS:
|
||||
methodVisitor.visitInsn(IADD);
|
||||
break;
|
||||
@ -113,10 +122,10 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DotExpressionNode dotExpressionNode) {
|
||||
dotExpressionNode.dotExpression.accept(this);
|
||||
dotExpressionNode.dotSubstractionExpression.accept(this);
|
||||
switch (dotExpressionNode.operator) {
|
||||
public void visit(DotNode dotNode) {
|
||||
dotNode.dotExpression.accept(this);
|
||||
dotNode.dotSubstractionExpression.accept(this);
|
||||
switch (dotNode.operator) {
|
||||
case DIV:
|
||||
methodVisitor.visitInsn(IDIV);
|
||||
break;
|
||||
@ -130,50 +139,50 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DotSubstractionExpressionNode dotSubstractionExpressionNode) {
|
||||
public void visit(DotSubstractionNode dotSubstractionNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NonCalculationExpressionNode nonCalculationExpressionNode) {
|
||||
public void visit(NonCalculationNode nonCalculationNode) {
|
||||
Label labelFalse = new Label();
|
||||
Label labelTrue = new Label();
|
||||
switch (nonCalculationExpressionNode.operator) {
|
||||
switch (nonCalculationNode.operator) {
|
||||
case AND:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
|
||||
break;
|
||||
case OR:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IFNE, labelTrue);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
|
||||
break;
|
||||
case GREATER:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IF_ICMPLE, labelFalse);
|
||||
break;
|
||||
case LESS:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IF_ICMPGE, labelFalse);
|
||||
break;
|
||||
case GREATER_EQUAL:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IF_ICMPLT, labelFalse);
|
||||
break;
|
||||
case LESS_EQUAL:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IF_ICMPGT, labelFalse);
|
||||
break;
|
||||
case EQUAL:
|
||||
nonCalculationExpressionNode.unaryExpression.accept(this);
|
||||
nonCalculationExpressionNode.expression.accept(this);
|
||||
nonCalculationNode.unaryExpression.accept(this);
|
||||
nonCalculationNode.expression.accept(this);
|
||||
|
||||
break;
|
||||
case NOT_EQUAL:
|
||||
@ -191,12 +200,12 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NotExpressionNode notExpressionNode) {
|
||||
public void visit(NotNode notNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpressionNode unaryExpressionNode) {
|
||||
public void visit(UnaryNode unaryNode) {
|
||||
|
||||
}
|
||||
|
||||
@ -204,35 +213,30 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
// Statements
|
||||
|
||||
@Override
|
||||
public void visit(ElseStatementNode elseStatementNode) {
|
||||
public void visit(ElseNode elseNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfElseStatementNode ifElseStatementNode) {
|
||||
public void visit(IfElseNode ifElseNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStatementNode ifStatementNode) {
|
||||
public void visit(IfNode ifNode) {
|
||||
// Process condition
|
||||
Label elseLabel = new Label();
|
||||
|
||||
ifStatementNode.expression.accept(this);
|
||||
ifNode.expression.accept(this);
|
||||
|
||||
methodVisitor.visitJumpInsn(IFLE, elseLabel);
|
||||
|
||||
// Process block
|
||||
for (IStatementNode statementNode : ifStatementNode.block.statements) {
|
||||
for (IStatementNode statementNode : ifNode.block.statements) {
|
||||
statementNode.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStatementNode forStatementNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVariableDeclarationNode localVariableDeclarationNode) {
|
||||
// Process expression
|
||||
@ -242,26 +246,26 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignStatementExpressionNode assignStatementExpressionNode) {
|
||||
public void visit(AssignNode assignNode) {
|
||||
// Process expression
|
||||
assignStatementExpressionNode.expression.accept(this);
|
||||
assignNode.expression.accept(this);
|
||||
// Store result of expression in variable
|
||||
if (assignStatementExpressionNode.assignable.memberAccess.thisExpr) {
|
||||
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(assignStatementExpressionNode.assignable.identifier));
|
||||
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(assignNode.assignable.identifier));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnStatementNode returnStatementNode) {
|
||||
if (returnStatementNode.voidReturn) { // Return nothing
|
||||
public void visit(ReturnNode returnNode) {
|
||||
if (returnNode.voidReturn) { // Return nothing
|
||||
methodVisitor.visitInsn(RETURN);
|
||||
} else { // Return something
|
||||
// Process expression
|
||||
returnStatementNode.expression.accept(this);
|
||||
returnNode.expression.accept(this);
|
||||
// Return result of expression
|
||||
methodVisitor.visitInsn(IRETURN);
|
||||
}
|
||||
@ -269,7 +273,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(WhileStatementNode whileStatementNode) {
|
||||
public void visit(WhileNode whileNode) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,37 @@
|
||||
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.MainMethodNode;
|
||||
import ast.members.MethodNode;
|
||||
import ast.statementexpressions.AssignNode;
|
||||
import ast.statements.*;
|
||||
|
||||
public interface MethodVisitor {
|
||||
void visit(ConstructorNode constructorNode);
|
||||
void visit(MethodNode methodNode);
|
||||
void visit(MainMethodNode mainMethodNode);
|
||||
|
||||
void visit(BinaryExpressionNode binaryExpressionNode);
|
||||
void visit(CalculationExpressionNode calculationExpressionNode);
|
||||
void visit(DotExpressionNode dotExpressionNode);
|
||||
void visit(DotSubstractionExpressionNode dotSubstractionExpressionNode);
|
||||
void visit(NonCalculationExpressionNode nonCalculationExpressionNode);
|
||||
void visit(BinaryNode binaryNode);
|
||||
void visit(CalculationNode calculationNode);
|
||||
void visit(DotNode dotNode);
|
||||
void visit(DotSubstractionNode dotSubstractionNode);
|
||||
void visit(NonCalculationNode nonCalculationNode);
|
||||
|
||||
void visit(MemberAccessNode memberAccessNode);
|
||||
void visit(NotExpressionNode notExpressionNode);
|
||||
void visit(UnaryExpressionNode unaryExpressionNode);
|
||||
void visit(NotNode notExpressionNode);
|
||||
void visit(UnaryNode unaryExpressionNode);
|
||||
|
||||
void visit(ElseStatementNode elseStatementNode);
|
||||
void visit(IfElseStatementNode ifElseStatementNode);
|
||||
void visit(IfStatementNode ifStatementNode);
|
||||
void visit(ElseNode elseNode);
|
||||
void visit(IfElseNode ifElseNode);
|
||||
void visit(IfNode ifNode);
|
||||
|
||||
void visit(AssignStatementExpressionNode assignStatementExpressionNode);
|
||||
void visit(AssignNode assignNode);
|
||||
|
||||
void visit(ForStatementNode forStatementNode);
|
||||
void visit(LocalVariableDeclarationNode localVariableDeclarationNode);
|
||||
void visit(ReturnStatementNode returnStatementNode);
|
||||
void visit(WhileStatementNode whileStatementNode);
|
||||
void visit(ReturnNode returnNode);
|
||||
void visit(WhileNode whileNode);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user