Use dynamic_cast instead of safe_cast for upcasting.
Use a map to keep track of anonymous declarations else we cannot refer to them later when needed.

This could lead to self-referencing problems when parsing (and stack overflows!).