Oh something I forgot. You should really start littering your code with pragma(msg, ...) statements to better understand what it does.You can for example make your generator output "pramga(msg, T.stringof);" to find out what T actually is.
Kind Regards Benjamin Thaut