summaryrefslogtreecommitdiff
path: root/odb/semantics
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-08-15 11:46:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-08-15 11:46:00 +0200
commiteacf52a9a4f3832274fdefc909ab23c13413e128 (patch)
treef1f754b6149797315f91d6f872363555201d5a65 /odb/semantics
parent396cad633b6f0559a39e5111827f9b1125c67506 (diff)
Add support for member accessors/modifiers
New pragmas: get, set, access. New test: common/access.
Diffstat (limited to 'odb/semantics')
-rw-r--r--odb/semantics/derived.cxx106
-rw-r--r--odb/semantics/derived.hxx70
-rw-r--r--odb/semantics/elements.hxx2
3 files changed, 177 insertions, 1 deletions
diff --git a/odb/semantics/derived.cxx b/odb/semantics/derived.cxx
index 562d62e..3a08c3f 100644
--- a/odb/semantics/derived.cxx
+++ b/odb/semantics/derived.cxx
@@ -2,9 +2,13 @@
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
+#include <sstream>
+
#include <cutl/compiler/type-info.hxx>
#include <odb/semantics/derived.hxx>
+using namespace std;
+
namespace semantics
{
qualifies::
@@ -25,8 +29,42 @@ namespace semantics
{
}
+ string qualifier::
+ fq_name (names* hint) const
+ {
+ if (hint != 0 || defined_ != 0)
+ return nameable::fq_name (hint);
+
+ // GCC type_as_string() for some reason cannot correctly print names
+ // like 'const std::string'. Instead it prints 'const string'.
+ //
+ type& bt (base_type ());
+
+ // Use the trailing qualifier syntax so that we don't get bogged down
+ // in stuff like 'const const foo*'. We also have to handle arrays in
+ // a special way since char[16] const is not a legal syntax.
+ //
+ string q;
+ if (c_)
+ q += " const";
+
+ if (v_)
+ q += " volatile";
+
+ if (r_)
+ q += " __restrict";
+
+ hint = qualifies ().hint ();
+
+ if (array* a = dynamic_cast<array*> (&bt))
+ return a->fq_name (hint, q);
+ else
+ return bt.fq_name (hint) + q;
+ }
+
points::
points ()
+ : hint_ (0)
{
}
@@ -36,8 +74,23 @@ namespace semantics
{
}
+ string pointer::
+ fq_name (names* hint) const
+ {
+ if (hint != 0 || defined_ != 0)
+ return nameable::fq_name (hint);
+
+ // GCC type_as_string() for some reason cannot correctly print names
+ // like 'const std::string*'. Instead it prints 'const string*'.
+ //
+ string r (base_type ().fq_name (points ().hint ()));
+ r += '*';
+ return r;
+ }
+
references::
references ()
+ : hint_ (0)
{
}
@@ -47,8 +100,23 @@ namespace semantics
{
}
+ string reference::
+ fq_name (names* hint) const
+ {
+ if (hint != 0 || defined_ != 0)
+ return nameable::fq_name (hint);
+
+ // GCC type_as_string() for some reason cannot correctly print names
+ // like 'const std::string&'. Instead it prints 'const string&'.
+ //
+ string r (base_type ().fq_name (points ().hint ()));
+ r += '&';
+ return r;
+ }
+
contains::
contains ()
+ : hint_ (0)
{
}
@@ -62,6 +130,44 @@ namespace semantics
{
}
+ string array::
+ fq_name (names* hint) const
+ {
+ // GCC type_as_string() for some reason cannot correctly print names
+ // like 'const std::string[123]'. Instead it prints 'const string[123]'.
+ //
+ string t;
+ return fq_name (hint, t);
+ }
+
+ string array::
+ fq_name (names* hint, string& t) const
+ {
+ if (hint != 0 || defined_ != 0)
+ return nameable::fq_name (hint) + t;
+
+ t += '[';
+ ostringstream ostr;
+ ostr << size ();
+ t += ostr.str ();
+
+ if (size () > 0xFFFFFFFF)
+ t += "ULL";
+ else if (size () > 2147483647)
+ t += "U";
+
+ t += ']';
+
+ type& bt (base_type ());
+ hint = contains ().hint ();
+ array* a;
+
+ if (hint != 0 || (a = dynamic_cast<array*> (&bt)) == 0)
+ return bt.fq_name (hint) + t;
+ else
+ return a->fq_name (0, t);
+ }
+
// type info
//
namespace
diff --git a/odb/semantics/derived.hxx b/odb/semantics/derived.hxx
index 7551cd4..4300290 100644
--- a/odb/semantics/derived.hxx
+++ b/odb/semantics/derived.hxx
@@ -114,6 +114,10 @@ namespace semantics
}
public:
+ virtual string
+ fq_name (names*) const;
+
+ public:
qualifier (path const&,
size_t line,
size_t column,
@@ -155,6 +159,21 @@ namespace semantics
return *pointer_;
}
+ // Name hint of the base type.
+ //
+ public:
+ void
+ hint (names& hint)
+ {
+ hint_ = &hint;
+ }
+
+ names*
+ hint () const
+ {
+ return hint_;
+ }
+
public:
points ();
@@ -173,6 +192,7 @@ namespace semantics
protected:
type_type* type_;
pointer_type* pointer_;
+ names* hint_;
};
class pointer: public derived_type
@@ -193,6 +213,10 @@ namespace semantics
}
public:
+ virtual string
+ fq_name (names*) const;
+
+ public:
pointer (path const&, size_t line, size_t column, tree);
void
@@ -228,6 +252,21 @@ namespace semantics
return *reference_;
}
+ // Name hint of the base type.
+ //
+ public:
+ void
+ hint (names& hint)
+ {
+ hint_ = &hint;
+ }
+
+ names*
+ hint () const
+ {
+ return hint_;
+ }
+
public:
references ();
@@ -246,6 +285,7 @@ namespace semantics
protected:
type_type* type_;
reference_type* reference_;
+ names* hint_;
};
class reference: public derived_type
@@ -266,6 +306,10 @@ namespace semantics
}
public:
+ virtual string
+ fq_name (names*) const;
+
+ public:
reference (path const&, size_t line, size_t column, tree);
void
@@ -301,6 +345,21 @@ namespace semantics
return *array_;
}
+ // Name hint of the base type.
+ //
+ public:
+ void
+ hint (names& hint)
+ {
+ hint_ = &hint;
+ }
+
+ names*
+ hint () const
+ {
+ return hint_;
+ }
+
public:
contains ();
@@ -319,6 +378,7 @@ namespace semantics
protected:
type_type* type_;
array_type* array_;
+ names* hint_;
};
class array: public derived_type
@@ -348,6 +408,16 @@ namespace semantics
}
public:
+ virtual string
+ fq_name (names*) const;
+
+ private:
+ friend class qualifier;
+
+ string
+ fq_name (names*, string& trailer) const;
+
+ public:
array (path const&,
size_t line,
size_t column,
diff --git a/odb/semantics/elements.hxx b/odb/semantics/elements.hxx
index ac62ff9..c9aa00e 100644
--- a/odb/semantics/elements.hxx
+++ b/odb/semantics/elements.hxx
@@ -495,7 +495,7 @@ namespace semantics
string
fq_name_ (scope_entry const*) const;
- private:
+ protected:
defines* defined_;
names_list named_;
};