Make the dependencies cache aware of preprocessor extensions changes.

Also clean up tree traversal by type into its own subclass.