Add common statement generation logic and spec tests