From 319def6da0c6d17c29f66c0ea5837a58988a67d7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 24 Jul 2011 14:56:11 +0200 Subject: Add support for resetting options accumulated with options pragma --- odb/context.cxx | 99 +++++++++++++++++++++++++++++++++++++++++++++++++-------- odb/pragma.cxx | 26 +++++++++------ 2 files changed, 102 insertions(+), 23 deletions(-) diff --git a/odb/context.cxx b/odb/context.cxx index 39a01f7..3b684ea 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -325,10 +325,45 @@ column_options (semantics::data_member& m) // semantics::type& t (m.type ()); - string mo (m.get ("options", string ())); - string to (t.get ("options", string ())); + string r; + + if (t.count ("options")) + { + strings const& o (t.get ("options")); + + for (strings::const_iterator i (o.begin ()); i != o.end (); ++i) + { + if (i->empty ()) + r.clear (); + else + { + if (!r.empty ()) + r += ' '; + + r += *i; + } + } + } - return to + (mo.empty () || to.empty () ? "" : " ") + mo; + if (m.count ("options")) + { + strings const& o (m.get ("options")); + + for (strings::const_iterator i (o.begin ()); i != o.end (); ++i) + { + if (i->empty ()) + r.clear (); + else + { + if (!r.empty ()) + r += ' '; + + r += *i; + } + } + } + + return r; } string context:: @@ -344,24 +379,60 @@ column_options (semantics::data_member& m, string const& kp) semantics::type& c (m.type ()); semantics::type& t (member_type (m, kp)); - string r (t.get ("options", string ())); + string r; - string o (c.get (k, string ())); - if (!o.empty ()) + if (t.count ("options")) { - if (!r.empty ()) - r += ' '; + strings const& o (t.get ("options")); - r += o; + for (strings::const_iterator i (o.begin ()); i != o.end (); ++i) + { + if (i->empty ()) + r.clear (); + else + { + if (!r.empty ()) + r += ' '; + + r += *i; + } + } + } + + if (c.count (k)) + { + strings const& o (c.get (k)); + + for (strings::const_iterator i (o.begin ()); i != o.end (); ++i) + { + if (i->empty ()) + r.clear (); + else + { + if (!r.empty ()) + r += ' '; + + r += *i; + } + } } - o = m.get (k, string ()); - if (!o.empty ()) + if (m.count (k)) { - if (!r.empty ()) - r += ' '; + strings const& o (m.get (k)); - r += o; + for (strings::const_iterator i (o.begin ()); i != o.end (); ++i) + { + if (i->empty ()) + r.clear (); + else + { + if (!r.empty ()) + r += ' '; + + r += *i; + } + } } return r; diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 6e1ecfa..23d3fd3 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -514,11 +514,11 @@ handle_pragma (cpp_reader* reader, p == "key_options" || p == "id_options") { - // options ("") - // value_options ("") - // index_options ("") - // key_options ("") - // id_options ("") + // options ([""]) + // value_options ([""]) + // index_options ([""]) + // key_options ([""]) + // id_options ([""]) // // Make sure we've got the correct declaration type. @@ -534,20 +534,28 @@ handle_pragma (cpp_reader* reader, tt = pragma_lex (&t); - if (tt != CPP_STRING) + // An empty options specifier signals options reset. + // + if (tt == CPP_STRING) + { + val = TREE_STRING_POINTER (t); + tt = pragma_lex (&t); + } + // Empty options specifier signals options reset. + // + else if (tt != CPP_CLOSE_PAREN) { error () << "options string expected in db pragma '" << p << "'" << endl; return; } - val = TREE_STRING_POINTER (t); - - if (pragma_lex (&t) != CPP_CLOSE_PAREN) + if (tt != CPP_CLOSE_PAREN) { error () << "')' expected at the end of db pragma '" << p << "'" << endl; return; } + mode = pragma::accumulate; tt = pragma_lex (&t); } else if (p == "type" || -- cgit v1.1