NichtHaskell/Source/abstractSyntaxTree/Statement/BlockStatement.java
Jochen Seyfried 2527d15467 Added Bytecodegeneration to the missing classes
Also included some TODOs in areas where parameters and some connections are missing
2024-05-07 13:50:51 +02:00

45 lines
1.4 KiB
Java

package abstractSyntaxTree.Statement;
import TypeCheck.TypeCheckResult;
import TypeCheck.AbstractType;
import abstractSyntaxTree.Expression.IExpression;
import org.objectweb.asm.MethodVisitor;
import java.util.List;
public class BlockStatement extends AbstractType implements IStatement{
//We will need a parameter which holds the symbol table
List<IStatement> statements;
public BlockStatement(List<IStatement> statements){
this.statements = statements;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckResult result = new TypeCheckResult();
if(statements.size() == 0){
result.type = "void";
}
TypeCheckResult blockType = null;
for (IStatement statement : statements) {
TypeCheckResult typeOfCurrentStatement = statement.typeCheck();
if (blockType == null) {
blockType = typeOfCurrentStatement;
} else if (!typeOfCurrentStatement.equals(blockType) && !blockType.equals("void")) {
throw new IllegalArgumentException("different statement types");
}
}
return result;
}
@Override
public void CodeGen(MethodVisitor mv) throws Exception {
for (IStatement statement : statements) {
statement.CodeGen(mv); //TODO: I think we need to pass the symbol table here
}
}
}