From 15e6fd2b0976f82eb1ef10d2d26912d12e4f0a99 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 2 Apr 2010 18:41:18 +0200 Subject: Implement pragma support --- odb/pragma.hxx | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 odb/pragma.hxx (limited to 'odb/pragma.hxx') 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 +// 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 + +#include +#include +#include +#include + +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_list; + +// A set of pragmas. Insertion of a pragma with the same name +// overrides the old value. +// +struct pragma_set: std::set +{ + typedef std::set base; + + void + insert (pragma const& p) + { + std::pair r (base::insert (p)); + + if (!r.second) + { + pragma& x (const_cast (*r.first)); + x = p; + } + } + + template + 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 loc_pragmas; + +// Pragmas associated with this declaration. +// +typedef std::map 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 -- cgit v1.1