aboutsummaryrefslogtreecommitdiff
path: root/odb/pragma.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-04-02 18:41:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-04-02 18:41:18 +0200
commit15e6fd2b0976f82eb1ef10d2d26912d12e4f0a99 (patch)
treeebec92c4dd0ef6998c22fbe7e0971463615973db /odb/pragma.hxx
parent33e79981967fe82d392c90974031abd444e1f9f8 (diff)
Implement pragma support
Diffstat (limited to 'odb/pragma.hxx')
-rw-r--r--odb/pragma.hxx89
1 files changed, 89 insertions, 0 deletions
diff --git a/odb/pragma.hxx b/odb/pragma.hxx
new file mode 100644
index 0000000..1a8a98f
--- /dev/null
+++ b/odb/pragma.hxx
@@ -0,0 +1,89 @@
+// file : odb/pragma.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_PRAGMA_HXX
+#define ODB_PRAGMA_HXX
+
+#include <odb/gcc.hxx>
+
+#include <map>
+#include <set>
+#include <vector>
+#include <string>
+
+struct pragma
+{
+ pragma (std::string const& n, std::string const& v, location_t l)
+ : name (n), value (v), loc (l)
+ {
+ }
+
+ bool
+ operator< (pragma const& y) const
+ {
+ return name < y.name;
+ }
+
+ std::string name;
+ std::string value;
+ location_t loc;
+};
+
+typedef std::vector<pragma> pragma_list;
+
+// A set of pragmas. Insertion of a pragma with the same name
+// overrides the old value.
+//
+struct pragma_set: std::set<pragma>
+{
+ typedef std::set<pragma> base;
+
+ void
+ insert (pragma const& p)
+ {
+ std::pair<iterator, bool> r (base::insert (p));
+
+ if (!r.second)
+ {
+ pragma& x (const_cast<pragma&> (*r.first));
+ x = p;
+ }
+ }
+
+ template <typename I>
+ void
+ insert (I begin, I end)
+ {
+ for (; begin != end; ++begin)
+ insert (*begin);
+ }
+};
+
+
+// Position pragmas inside a class or namespace. The key for the
+// namespace case is the global_namespace node.
+//
+typedef std::map<tree, pragma_list> loc_pragmas;
+
+// Pragmas associated with this declaration.
+//
+typedef std::map<tree, pragma_set> decl_pragmas;
+
+extern loc_pragmas loc_pragmas_;
+extern decl_pragmas decl_pragmas_;
+
+extern "C" void
+register_odb_pragmas (void*, void*);
+
+// Check that the pragma is applicable to the declaration. Return true
+// on success, complain and return false otherwise.
+//
+bool
+check_decl_type (tree decl,
+ std::string const& name,
+ std::string const& prag,
+ location_t);
+
+#endif // ODB_PRAGMA_HXX