private void checkReturn(BlockContext block) { if (returnType == ValueType.VOID) { method.visitInsn(Opcodes.RETURN); return; } if (block.blockStatement() != null) { int lastStatement = block.blockStatement().size() - 1; BlockStatementContext blockStatement = block.blockStatement(lastStatement); if (blockStatement.statement() != null) { StatementContext statement = blockStatement.statement(); if (statement.jumpStatement() != null) { JumpStatementContext jumpStatement = statement.jumpStatement(); if (jumpStatement.returnSt != null) { return; } } } } throw new GenerationException( "Last statement of function with non-null return type must be return. String: " + block.getText()); }
public void visitStatement(StatementContext statement) { if (statement.expression() != null) { new ExpressionVisitor(symbolTable, method).visitExpression(statement.expression()); } else if (statement.assignment() != null) { new AssignmentVisitor(symbolTable, method).visitAssignment(statement.assignment()); } else if (statement.block() != null) { visitBlock(statement.block()); } else if (statement.jumpStatement() != null) { visitJumpStatement(statement.jumpStatement()); } else if (statement.IF() != null) { new IfStatementVisitor(this, symbolTable, method).visitIfStatement(statement); } else if (statement.forStatement() != null) { new CycleStatementVisitor(this, symbolTable, method) .visitForStatement(statement.forStatement()); } else if (statement.WHILE() != null) { new CycleStatementVisitor(this, symbolTable, method).visitWhileStatement(statement); } }