/** * \file paranoid_visitor.cpp */ INTERFACE: #include "ptree_program_visitor.h" template class Paranoid_visitor : public Ptree_program_visitor { typedef Ptree_program_visitor Super; public: using Super::operator new; using Super::operator delete; Paranoid_visitor(Source* src) : Super(src), Ptree_visitor(src) { } }; IMPLEMENTATION: #include #include #include "except.h" template virtual T Paranoid_visitor::default_action(Ptree* p) { if (p) bogus_ptree_error(std::string("Unexpected node type `") + typeid(*p).name() + "' encountered", p); else bogus_ptree_error("Unexpected empty node encountered", p); return T(0); // silence compiler } // FIXME: move this to Ptree_visitor? PUBLIC template T Paranoid_visitor::visit_and_catch(Ptree* p) { try { return visit(p); } catch(Compile_error& e) { e.print(std::cerr, p); return T(0); } }