From bb76e9388009ed0bb2512034f8cd48a7d19aabb3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Jun 2010 16:29:02 +0200 Subject: Next chunk of functionality --- odb/pragma.cxx | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 169 insertions(+), 14 deletions(-) (limited to 'odb/pragma.cxx') diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 33d69f0..eff1312 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -84,16 +84,19 @@ check_decl_type (tree d, string const& name, string const& p, location_t l) int tc (TREE_CODE (d)); char const* pc (p.c_str ()); - if (p == "column") + if (p == "id" || + p == "column" || + p == "type") { if (tc != FIELD_DECL) { error_at (l, "name %qs in odb pragma %qs does not refer to " - "a member variable", name.c_str (), pc); + "a data member", name.c_str (), pc); return false; } } - else if (p == "table") + else if (p == "object" || + p == "table") { if (tc != RECORD_TYPE) { @@ -122,7 +125,136 @@ handle_pragma (string const& p) tree decl (0); location_t loc (input_location); - if (p == "column") + if (p == "object") + { + // object [()] + // + + tt = pragma_lex (&t); + + if (tt == CPP_OPEN_PAREN) + { + tt = pragma_lex (&t); + + if (tt == CPP_NAME || tt == CPP_SCOPE) + { + string name; + decl = parse_scoped_name (t, tt, name, true, p); + + if (decl == 0) + return; + + // Make sure we've got the correct declaration type. + // + if (!check_decl_type (decl, name, p, loc)) + return; + + if (tt != CPP_CLOSE_PAREN) + { + error ("%qs expected at the end of odb pragma %qs", ")", pc); + return; + } + + tt = pragma_lex (&t); + } + else + { + error ("type name expected in odb pragma %qs", pc); + return; + } + } + } + else if (p == "table") + { + // table ([,] "") + // + + if (pragma_lex (&t) != CPP_OPEN_PAREN) + { + error ("%qs expected after odb pragma %qs", "(", pc); + return; + } + + tt = pragma_lex (&t); + + if (tt == CPP_NAME || tt == CPP_SCOPE) + { + string name; + decl = parse_scoped_name (t, tt, name, true, p); + + if (decl == 0) + return; + + // Make sure we've got the correct declaration type. + // + if (!check_decl_type (decl, name, p, loc)) + return; + + if (tt != CPP_COMMA) + { + error ("table name expected in odb pragma %qs", pc); + return; + } + + tt = pragma_lex (&t); + } + + if (tt != CPP_STRING) + { + error ("table name expected in odb pragma %qs", pc); + return; + } + + val = TREE_STRING_POINTER (t); + + if (pragma_lex (&t) != CPP_CLOSE_PAREN) + { + error ("%qs expected at the end of odb pragma %qs", ")", pc); + return; + } + + tt = pragma_lex (&t); + } + else if (p == "id") + { + // id [()] + // + + tt = pragma_lex (&t); + + if (tt == CPP_OPEN_PAREN) + { + tt = pragma_lex (&t); + + if (tt == CPP_NAME || tt == CPP_SCOPE) + { + string name; + decl = parse_scoped_name (t, tt, name, false, p); + + if (decl == 0) + return; + + // Make sure we've got the correct declaration type. + // + if (!check_decl_type (decl, name, p, loc)) + return; + + if (tt != CPP_CLOSE_PAREN) + { + error ("%qs expected at the end of odb pragma %qs", ")", pc); + return; + } + + tt = pragma_lex (&t); + } + else + { + error ("data member name expected in odb pragma %qs", pc); + return; + } + } + } + else if (p == "column") { // column ([,] "") // @@ -170,10 +302,12 @@ handle_pragma (string const& p) error ("%qs expected at the end of odb pragma %qs", ")", pc); return; } + + tt = pragma_lex (&t); } - else if (p == "table") + else if (p == "type") { - // table ([,] "") + // type ([,] "") // if (pragma_lex (&t) != CPP_OPEN_PAREN) @@ -187,7 +321,7 @@ handle_pragma (string const& p) if (tt == CPP_NAME || tt == CPP_SCOPE) { string name; - decl = parse_scoped_name (t, tt, name, true, p); + decl = parse_scoped_name (t, tt, name, false, p); if (decl == 0) return; @@ -199,7 +333,7 @@ handle_pragma (string const& p) if (tt != CPP_COMMA) { - error ("table name expected in odb pragma %qs", pc); + error ("type name expected in odb pragma %qs", pc); return; } @@ -208,7 +342,7 @@ handle_pragma (string const& p) if (tt != CPP_STRING) { - error ("table name expected in odb pragma %qs", pc); + error ("type name expected in odb pragma %qs", pc); return; } @@ -219,6 +353,8 @@ handle_pragma (string const& p) error ("%qs expected at the end of odb pragma %qs", ")", pc); return; } + + tt = pragma_lex (&t); } else { @@ -244,8 +380,6 @@ handle_pragma (string const& p) // See if there are any more pragmas. // - tt = pragma_lex (&t); - if (tt == CPP_NAME) { handle_pragma (IDENTIFIER_POINTER (t)); @@ -255,9 +389,9 @@ handle_pragma (string const& p) } extern "C" void -handle_pragma_odb_column (cpp_reader*) +handle_pragma_odb_object (cpp_reader*) { - handle_pragma ("column"); + handle_pragma ("object"); } extern "C" void @@ -267,8 +401,29 @@ handle_pragma_odb_table (cpp_reader*) } extern "C" void +handle_pragma_odb_id (cpp_reader*) +{ + handle_pragma ("id"); +} + +extern "C" void +handle_pragma_odb_column (cpp_reader*) +{ + handle_pragma ("column"); +} + +extern "C" void +handle_pragma_odb_type (cpp_reader*) +{ + handle_pragma ("type"); +} + +extern "C" void register_odb_pragmas (void*, void*) { - c_register_pragma_with_expansion ("odb", "column", handle_pragma_odb_column); + c_register_pragma_with_expansion ("odb", "object", handle_pragma_odb_object); c_register_pragma_with_expansion ("odb", "table", handle_pragma_odb_table); + c_register_pragma_with_expansion ("odb", "id", handle_pragma_odb_id); + c_register_pragma_with_expansion ("odb", "column", handle_pragma_odb_column); + c_register_pragma_with_expansion ("odb", "type", handle_pragma_odb_type); } -- cgit v1.1