From 932cd7a53b3996468fee5cfa63c2b2998dbe971a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Jul 2011 17:53:47 +0200 Subject: Implement support for database operations callbacks New object pragma: callback. New test: common/callback. New manual section: 10.1.4, "callback". --- odb/validator.cxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'odb/validator.cxx') diff --git a/odb/validator.cxx b/odb/validator.cxx index 998bd8b..487d69a 100644 --- a/odb/validator.cxx +++ b/odb/validator.cxx @@ -3,6 +3,8 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : GNU GPL v3; see accompanying LICENSE file +#include + #include #include @@ -138,6 +140,47 @@ namespace virtual void traverse_object (type& c) { + // Check that the callback function exist. + // + if (c.count ("callback")) + { + string name (c.get ("callback")); + tree decl ( + lookup_qualified_name ( + c.tree_node (), get_identifier (name.c_str ()), false, false)); + + if (decl == error_mark_node || TREE_CODE (decl) != BASELINK) + { + cerr << c.file () << ":" << c.line () << ":" << c.column () << ": " + << "error: unable to resolve member function '" << name << "' " + << "specified with '#pragma db callback' for class '" + << c.name () << "'" << endl; + + valid_ = false; + } + + // Figure out if we have a const version of the callback. OVL_* + // macros work for both FUNCTION_DECL and OVERLOAD. + // + for (tree o (BASELINK_FUNCTIONS (decl)); o != 0; o = OVL_NEXT (o)) + { + tree f (OVL_CURRENT (o)); + if (DECL_CONST_MEMFUNC_P (f)) + { + c.set ("callback-const", true); + break; + } + } + + //@@ Would be nice to check the signature of the function(s) + // instead of postponing it until the C++ compilation. Though + // we may still get C++ compilation errors because of const + // mismatch. + // + } + + // Check bases. + // bool base (false); for (type::inherits_iterator i (c.inherits_begin ()); -- cgit v1.1