package abstractSyntaxTree.Statement; import TypeCheck.TypeCheckResult; import TypeCheck.AbstractType; import org.objectweb.asm.*; import java.util.HashMap; import java.util.List; public class BlockStatement extends AbstractType implements IStatement{ //We will need a parameter which holds the symbol table HashMap localVars; HashMap typeIndentifierTable; // from program List statements; // do we need expression, statementexpression public BlockStatement(List statements, HashMap localVars, HashMap typeIndentifierTable){ 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 } } }