Make forward declaration generation more flexible.

Forward declarations are now a list of declarations, which can be added
to at any time, and are rendered at the top of each program.