Factor out repeated code in dumping template declarations.