a helper function to add a string before templatedecl
add forward decls for templates and records

Partially handle the problem of forward decls.
In some cases, we will still generate uncompilable code.