Some changes
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
fbff03c3d7
commit
8eba420d48
@ -2,6 +2,7 @@ package ast.statementexpressions;
|
||||
|
||||
import ast.expressions.unaryexpressions.MemberAccessNode;
|
||||
import ast.type.type.ITypeNode;
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import semantic.TypeCheckResult;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ast.statements;
|
||||
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import semantic.TypeCheckResult;
|
||||
import visitor.Visitable;
|
||||
@ -22,4 +23,9 @@ public class BlockNode implements IStatementNode, Visitable {
|
||||
return visitor.analyze(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(MethodVisitor methodVisitor) {
|
||||
methodVisitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ast.statements;
|
||||
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import semantic.TypeCheckResult;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ast.statements;
|
||||
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import semantic.TypeCheckResult;
|
||||
|
||||
@ -20,6 +21,11 @@ public class IfElseNode implements IStatementNode {
|
||||
elseIfStatements.add(elseIfStament);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(MethodVisitor methodVisitor) {
|
||||
methodVisitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult accept(SemanticVisitor visitor) {
|
||||
return visitor.analyze(this);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ast.statements;
|
||||
|
||||
import ast.expressions.IExpressionNode;
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import semantic.TypeCheckResult;
|
||||
|
||||
@ -17,6 +18,11 @@ public class WhileNode implements IStatementNode {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(MethodVisitor methodVisitor) {
|
||||
methodVisitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult accept(SemanticVisitor visitor) {
|
||||
return visitor.analyze(this);
|
||||
|
@ -16,6 +16,8 @@ import ast.statementexpressions.crementexpressions.DecrementNode;
|
||||
import ast.statementexpressions.crementexpressions.IncrementNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||
import ast.statements.*;
|
||||
import ast.type.AccessModifierNode;
|
||||
import ast.type.EnumAccessModifierNode;
|
||||
import ast.type.ValueNode;
|
||||
import ast.type.type.BaseType;
|
||||
import ast.type.type.ReferenceType;
|
||||
@ -78,8 +80,10 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MainMethodNode mainMethodNode) {
|
||||
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(mainMethodNode.accesModifier),
|
||||
mainMethodNode.getIdentifier(),
|
||||
AccessModifierNode accessModifierNode = new AccessModifierNode("");
|
||||
accessModifierNode.accessType = EnumAccessModifierNode.PUBLIC_STATIC;
|
||||
methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
|
||||
"main",
|
||||
"([Ljava/lang/String;)V",
|
||||
null,
|
||||
null);
|
||||
@ -318,9 +322,17 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
|
||||
// Statements
|
||||
|
||||
@Override
|
||||
public void visit(BlockNode blockNode) {
|
||||
for(IStatementNode statementNode : blockNode.statements) {
|
||||
statementNode.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfElseNode ifElseNode) {
|
||||
Label elseLabel = new Label();
|
||||
Label endLabel = new Label();
|
||||
|
||||
Label[] elseIfLabels = new Label[ifElseNode.elseIfStatements.size()];
|
||||
for (int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
|
||||
@ -338,7 +350,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
|
||||
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++) {
|
||||
@ -357,6 +368,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
if (ifElseNode.elseStatement != null) {
|
||||
methodVisitor.visitLabel(elseLabel);
|
||||
ifElseNode.elseStatement.block.accept(this);
|
||||
} else {
|
||||
methodVisitor.visitLabel(elseLabel);
|
||||
}
|
||||
|
||||
methodVisitor.visitLabel(endLabel);
|
||||
|
@ -43,6 +43,7 @@ public interface MethodVisitor {
|
||||
void visit(UnaryNode unaryExpressionNode);
|
||||
|
||||
// statements
|
||||
void visit(BlockNode blockNode);
|
||||
void visit(IfElseNode ifElseNode);
|
||||
|
||||
void visit(IncrementNode incrementNode);
|
||||
|
Loading…
Reference in New Issue
Block a user