From ad82296958864bd7302be345e4b25003e307334f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 16 Jun 2015 14:04:40 +0200 Subject: Use (!) to denote database in modifier expressions --- odb/context.cxx | 29 ++++++++++++++++++----------- odb/context.hxx | 3 ++- odb/relational/source.cxx | 8 ++++++-- odb/relational/source.hxx | 16 ++++++++++++---- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/odb/context.cxx b/odb/context.cxx index 726495f..d6336d1 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -68,7 +68,7 @@ add_space (string& s) } string member_access:: -translate (string const& obj, string const& val) const +translate (string const& obj, string const& val, string const& db) const { if (empty ()) { @@ -91,12 +91,6 @@ translate (string const& obj, string const& val) const // switch (tt) { - case CPP_NOT: - { - add_space (r); - r += '!'; - break; - } case CPP_COMMA: { r += ", "; @@ -235,6 +229,7 @@ translate (string const& obj, string const& val) const r += tl; break; } + case CPP_NOT: case CPP_QUERY: { if (ptt == CPP_OPEN_PAREN) @@ -245,13 +240,25 @@ translate (string const& obj, string const& val) const tt = l.next (tl); if (tt == CPP_CLOSE_PAREN) - r += val; + { + if (ptt == CPP_NOT) + { + if (db.empty ()) + { + error (loc) << "database instance (!) not available in this " + << "context" << endl; + throw operation_failed (); + } + + r += db; + } + else + r += val; + } else { - // The same as in the default case. - // add_space (r); - r += "? "; + r += (ptt == CPP_NOT ? "!" : "? "); } continue; // We have already gotten the next token. } diff --git a/odb/context.hxx b/odb/context.hxx index 57e50a7..3b283ee 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -296,7 +296,8 @@ struct member_access // std::string translate (std::string const& obj, - std::string const& val = std::string ()) const; + std::string const& val = std::string (), + std::string const& db = std::string ()) const; location loc; const char* kind; // accessor/modifier; used for diagnostics. diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index c2144b4..4bb8e9d 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -1289,7 +1289,9 @@ traverse_object (type& c) os << "// From " << location_string (ma.loc, true) << endl; if (ma.placeholder ()) - os << ma.translate ("obj", "id (sts.id_image ())") << ";" + os << ma.translate ( + "obj", "id (sts.id_image ())", + "static_cast<" + db.string () + "::database&> (db)") << ";" << endl; else { @@ -1546,7 +1548,9 @@ traverse_object (type& c) os << "// From " << location_string (ma.loc, true) << endl; if (ma.placeholder ()) - os << ma.translate ("obj", "id (sts.id_image (i))") << ";" + os << ma.translate ( + "obj", "id (sts.id_image (i))", + "static_cast<" + db.string () + "::database&> (db)") << ";" << endl; else { diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx index 7774739..5880a2b 100644 --- a/odb/relational/source.hxx +++ b/odb/relational/source.hxx @@ -2753,7 +2753,9 @@ namespace relational if (!ma.synthesized) os << "// From " << location_string (ma.loc, true) << endl; - os << ma.translate ("o", "v") << ";"; + os << ma.translate ( + "o", "v", "*static_cast<" + db.string () + "::database*> (db)") + << ";"; } } @@ -3234,7 +3236,9 @@ namespace relational os << "// From " << location_string (ma.loc, true) << endl; if (ma.placeholder ()) - os << ma.translate ("o", r) << ";"; + os << ma.translate ( + "o", r, "*static_cast<" + db.string () + "::database*> (db)") + << ";"; else os << ma.translate ("o") << " = " << r << ";"; } @@ -3248,7 +3252,9 @@ namespace relational os << "// From " << location_string (ma.loc, true) << endl; if (ma.placeholder ()) - os << ma.translate ("o", o) << ";"; + os << ma.translate ( + "o", o, "*static_cast<" + db.string () + "::database*> (db)") + << ";"; else os << ma.translate ("o") << " = " << o << ";"; } @@ -5320,7 +5326,9 @@ namespace relational if (!ma.synthesized) os << "// From " << location_string (ma.loc, true) << endl; - os << ma.translate (obj_prefix_, "v") << ";"; + os << ma.translate ( + obj_prefix_, "v", "static_cast<" + db.string () + + "::database&> (db)") << ";"; } os << "}"; -- cgit v1.1