From eacf52a9a4f3832274fdefc909ab23c13413e128 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Aug 2012 11:46:00 +0200 Subject: Add support for member accessors/modifiers New pragmas: get, set, access. New test: common/access. --- odb/pragma.cxx | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 9 deletions(-) (limited to 'odb/pragma.cxx') diff --git a/odb/pragma.cxx b/odb/pragma.cxx index ffe711f..d440f82 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -378,7 +378,10 @@ check_spec_decl_type (tree d, p == "transient" || p == "version" || p == "index" || - p == "unique") + p == "unique" || + p == "get" || + p == "set" || + p == "access") { if (tc != FIELD_DECL) { @@ -853,12 +856,56 @@ handle_pragma (cxx_lexer& l, { // index // unique + // + + // Make sure we've got the correct declaration type. + // + if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc)) + return; + + tt = l.next (tl, &tn); + } + else if (p == "get" || + p == "set" || + p == "access") + { + // get(name|expr) + // set(name|expr) + // access(name|expr) + // // Make sure we've got the correct declaration type. // if (decl != 0 && !check_spec_decl_type (decl, decl_name, p, loc)) return; + if (l.next (tl, &tn) != CPP_OPEN_PAREN) + { + error (l) << "'(' expected after db pragma " << p << endl; + return; + } + + tt = l.next (tl, &tn); + + val = member_access (loc); + if (!parse_expression (l, tt, tl, tn, val.value ().expr, p)) + return; // Diagnostics has already been issued. + + if (tt != CPP_CLOSE_PAREN) + { + error (l) << "')' expected at the end of db pragma " << p << endl; + return; + } + + // Convert access to the get/set pair. + // + if (p == "access") + { + add_pragma ( + pragma (p, "get", val, loc, &check_spec_decl_type, 0), decl, ns); + name = "set"; + } + tt = l.next (tl, &tn); } else if (p == "table") @@ -1259,10 +1306,7 @@ handle_pragma (cxx_lexer& l, // Expression. // if (s) - { - vq.expr.push_back (cxx_token (0, CPP_STRING)); - vq.expr.back ().literal = str; - } + vq.expr.push_back (cxx_token (0, CPP_STRING, str)); if (!parse_expression (l, tt, tl, tn, vq.expr, p)) return; // Diagnostics has already been issued. @@ -2160,10 +2204,7 @@ handle_pragma_qualifier (cxx_lexer& l, string const& p) if (qual) break; - cxx_token ct (l.location (), tt); - ct.literal = tl; - ct.node = tn; - saved_tokens.push_back (ct); + saved_tokens.push_back (cxx_token (l.location (), tt, tl, tn)); } if (balance != 0) @@ -2431,6 +2472,9 @@ handle_pragma_qualifier (cxx_lexer& l, string const& p) else if (p == "id" || p == "auto" || p == "unique" || + p == "get" || + p == "set" || + p == "access" || p == "column" || p == "value_column" || p == "index_column" || -- cgit v1.1