Suggested improvement by Rafael Espindola to use isa<> in a few places
instead of dyn_cast<>.