move static tree analysis to TypeVisitor