summaryrefslogtreecommitdiff
path: root/xsd/xsd/cxx/elements.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'xsd/xsd/cxx/elements.hxx')
-rw-r--r--xsd/xsd/cxx/elements.hxx208
1 files changed, 104 insertions, 104 deletions
diff --git a/xsd/xsd/cxx/elements.hxx b/xsd/xsd/cxx/elements.hxx
index 59938c5..4b36da9 100644
--- a/xsd/xsd/cxx/elements.hxx
+++ b/xsd/xsd/cxx/elements.hxx
@@ -1,31 +1,29 @@
// file : xsd/cxx/elements.hxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef CXX_ELEMENTS_HXX
#define CXX_ELEMENTS_HXX
+#include <set>
+#include <map>
+#include <vector>
#include <ostream>
-#include <cult/types.hxx>
-#include <cult/containers/set.hxx>
-#include <cult/containers/map.hxx>
-#include <cult/containers/vector.hxx>
-
-#include <backend-elements/regex.hxx>
+#include <cutl/re.hxx>
#include <xsd-frontend/semantic-graph.hxx>
#include <xsd-frontend/traversal.hxx>
+#include <types.hxx>
#include <elements.hxx>
+
+#include <cxx/options.hxx>
#include <cxx/literal-map.hxx>
namespace CXX
{
using std::endl;
- typedef WideString String;
-
// On some platforms std::toupper can be something other than a
// function with C++ linkage.
@@ -39,7 +37,7 @@ namespace CXX
struct UnrepresentableCharacter
{
- UnrepresentableCharacter (String const& str, Size pos)
+ UnrepresentableCharacter (String const& str, size_t pos)
: str_ (str), pos_ (pos)
{
}
@@ -50,7 +48,7 @@ namespace CXX
return str_;
}
- Size
+ size_t
position () const
{
return pos_;
@@ -58,14 +56,14 @@ namespace CXX
private:
String str_;
- Size pos_;
+ size_t pos_;
};
struct NoNamespaceMapping
{
NoNamespaceMapping (SemanticGraph::Path const& file,
- UnsignedLong line,
- UnsignedLong column,
+ size_t line,
+ size_t column,
String const& ns)
: file_ (file),
line_ (line),
@@ -81,13 +79,13 @@ namespace CXX
return file_;
}
- UnsignedLong
+ size_t
line () const
{
return line_;
}
- UnsignedLong
+ size_t
column () const
{
return column_;
@@ -101,8 +99,8 @@ namespace CXX
private:
SemanticGraph::Path file_;
- UnsignedLong line_;
- UnsignedLong column_;
+ size_t line_;
+ size_t column_;
String ns_;
};
@@ -136,57 +134,47 @@ namespace CXX
class Context
{
public:
- typedef BackendElements::Regex::Pattern<WideChar> RegexPat;
- typedef BackendElements::Regex::Expression<WideChar> Regex;
- typedef Cult::Containers::Vector<Regex> RegexMapping;
- typedef Cult::Containers::Map<String, String> MapMapping;
- typedef Cult::Containers::Map<String, String> MappingCache;
+ typedef cutl::re::wregex RegexPat;
+ typedef cutl::re::wregexsub Regex;
+ typedef std::vector<Regex> RegexMapping;
+ typedef std::map<String, String> MapMapping;
+ typedef std::map<String, String> MappingCache;
- typedef Cult::Containers::Map<String, String> ReservedNameMap;
- typedef Cult::Containers::Set<String> KeywordSet;
+ typedef std::map<String, String> ReservedNameMap;
+ typedef std::set<String> KeywordSet;
+
+ typedef CXX::options options_type;
public:
Context (std::wostream& o,
SemanticGraph::Schema& root,
SemanticGraph::Path const& path,
- StringLiteralMap const* custom_literals_map,
- NarrowString const& char_type__,
- NarrowString const& char_encoding__,
- Boolean include_with_brackets__,
- NarrowString const& include_prefix__,
- NarrowString const& esymbol,
- Containers::Vector<NarrowString> const& nsm,
- Containers::Vector<NarrowString> const& nsr,
- Boolean trace_namespace_regex_,
- Containers::Vector<NarrowString> const& include_regex,
- Boolean trace_include_regex_,
- Boolean inline_,
- Containers::Vector<NarrowString> const& reserved_name);
+ options_type const& ops,
+ StringLiteralMap const* custom_literals_map);
protected:
Context (Context& c)
: os (c.os),
schema_root (c.schema_root),
schema_path (c.schema_path),
+ options (c.options),
+ std (c.std),
char_type (c.char_type),
char_encoding (c.char_encoding),
L (c.L),
string_type (c.string_type),
+ auto_ptr (c.auto_ptr),
string_literal_map (c.string_literal_map),
- include_with_brackets (c.include_with_brackets),
- include_prefix (c.include_prefix),
type_exp (c.type_exp),
inst_exp (c.inst_exp),
inl (c.inl),
ns_mapping_cache (c.ns_mapping_cache),
xs_ns_ (c.xs_ns_),
cxx_id_expr (c.cxx_id_expr),
- trace_namespace_regex (c.trace_namespace_regex),
urn_mapping (c.urn_mapping),
nsr_mapping (c.nsr_mapping),
nsm_mapping (c.nsm_mapping),
include_mapping (c.include_mapping),
- trace_include_regex (c.trace_include_regex),
reserved_name_map (c.reserved_name_map),
keyword_set (c.keyword_set)
{
@@ -196,25 +184,24 @@ namespace CXX
: os (o),
schema_root (c.schema_root),
schema_path (c.schema_path),
+ options (c.options),
+ std (c.std),
char_type (c.char_type),
char_encoding (c.char_encoding),
L (c.L),
string_type (c.string_type),
+ auto_ptr (c.auto_ptr),
string_literal_map (c.string_literal_map),
- include_with_brackets (c.include_with_brackets),
- include_prefix (c.include_prefix),
type_exp (c.type_exp),
inst_exp (c.inst_exp),
inl (c.inl),
ns_mapping_cache (c.ns_mapping_cache),
xs_ns_ (c.xs_ns_),
cxx_id_expr (c.cxx_id_expr),
- trace_namespace_regex (c.trace_namespace_regex),
urn_mapping (c.urn_mapping),
nsr_mapping (c.nsr_mapping),
nsm_mapping (c.nsm_mapping),
include_mapping (c.include_mapping),
- trace_include_regex (c.trace_include_regex),
reserved_name_map (c.reserved_name_map),
keyword_set (c.keyword_set)
{
@@ -232,11 +219,11 @@ namespace CXX
// advanced by 1 if this Unicode character takes more than one
// underlying character.
//
- static UnsignedLong
- unicode_char (String const& str, Size& pos);
+ static unsigned int
+ unicode_char (String const& str, size_t& pos);
- static UnsignedLong
- unicode_char (WideChar const*& p);
+ static unsigned int
+ unicode_char (wchar_t const*& p);
// Escape C++ keywords and illegal characters.
//
@@ -283,7 +270,7 @@ namespace CXX
// Fully-qualified C++ name.
//
String
- fq_name (SemanticGraph::Nameable& n, Char const* name_key = "name");
+ fq_name (SemanticGraph::Nameable& n, char const* name_key = "name");
public:
static SemanticGraph::Type&
@@ -294,7 +281,7 @@ namespace CXX
process_include_path (String const&) const;
public:
- static Boolean
+ static bool
skip (SemanticGraph::Member& m)
{
// "Subsequent" local element.
@@ -303,28 +290,28 @@ namespace CXX
m.context ().count ("min") == 0;
}
- static UnsignedLong
+ static size_t
min (SemanticGraph::Member const& m)
{
- return m.context ().get<UnsignedLong> ("min");
+ return m.context ().get<size_t> ("min");
}
- static UnsignedLong
+ static size_t
min (SemanticGraph::Any const& a)
{
- return a.context ().get<UnsignedLong> ("min");
+ return a.context ().get<size_t> ("min");
}
- static UnsignedLong
+ static size_t
max (SemanticGraph::Member const& m)
{
- return m.context ().get<UnsignedLong> ("max");
+ return m.context ().get<size_t> ("max");
}
- static UnsignedLong
+ static size_t
max (SemanticGraph::Any const& a)
{
- return a.context ().get<UnsignedLong> ("max");
+ return a.context ().get<size_t> ("max");
}
public:
@@ -342,14 +329,17 @@ namespace CXX
SemanticGraph::Schema& schema_root;
SemanticGraph::Path const& schema_path;
+ options_type const& options;
+
+ cxx_version std;
+
String& char_type;
String& char_encoding;
String& L; // string literal prefix
String& string_type;
- StringLiteralMap const* string_literal_map;
+ String& auto_ptr;
- Boolean& include_with_brackets;
- String& include_prefix;
+ StringLiteralMap const* string_literal_map;
String& type_exp;
String& inst_exp;
@@ -367,9 +357,7 @@ namespace CXX
String char_encoding_;
String L_;
String string_type_;
-
- Boolean include_with_brackets_;
- String include_prefix_;
+ String auto_ptr_;
String type_exp_;
String inst_exp_;
@@ -378,7 +366,6 @@ namespace CXX
private:
RegexPat const cxx_id_expr_;
RegexPat const& cxx_id_expr;
- Boolean trace_namespace_regex;
Regex urn_mapping_;
RegexMapping nsr_mapping_;
MapMapping nsm_mapping_;
@@ -389,7 +376,6 @@ namespace CXX
RegexMapping include_mapping_;
RegexMapping const& include_mapping;
- Boolean trace_include_regex;
ReservedNameMap const& reserved_name_map;
ReservedNameMap reserved_name_map_;
@@ -398,16 +384,16 @@ namespace CXX
KeywordSet keyword_set_;
};
- inline UnsignedLong Context::
- unicode_char (String const& str, Size& pos)
+ inline unsigned int Context::
+ unicode_char (String const& str, size_t& pos)
{
- if (sizeof (WideChar) == 4)
+ if (sizeof (wchar_t) == 4)
{
return str[pos];
}
- else if (sizeof (WideChar) == 2)
+ else if (sizeof (wchar_t) == 2)
{
- WideChar x (str[pos]);
+ wchar_t x (str[pos]);
if (x < 0xD800 || x > 0xDBFF)
return x;
@@ -418,16 +404,16 @@ namespace CXX
return 0;
}
- inline UnsignedLong Context::
- unicode_char (WideChar const*& p)
+ inline unsigned int Context::
+ unicode_char (wchar_t const*& p)
{
- if (sizeof (WideChar) == 4)
+ if (sizeof (wchar_t) == 4)
{
return *p;
}
- else if (sizeof (WideChar) == 2)
+ else if (sizeof (wchar_t) == 2)
{
- WideChar x (*p);
+ wchar_t x (*p);
if (x < 0xD800 || x > 0xDBFF)
return x;
@@ -438,6 +424,21 @@ namespace CXX
return 0;
}
+ // Sources traverser that goes into each schema only once.
+ //
+ struct Sources: Traversal::Sources
+ {
+ virtual void
+ traverse (SemanticGraph::Sources& s)
+ {
+ if (schemas_.insert (&s.schema ()).second)
+ Traversal::Sources::traverse (s);
+ }
+
+ private:
+ std::set<SemanticGraph::Schema*> schemas_;
+ };
+
// Usual namespace mapping.
//
struct Namespace: Traversal::Namespace
@@ -447,10 +448,10 @@ namespace CXX
// First scope name if always empty (global scope). The last flag
// signals the last scope.
//
- virtual Void
- enter (Type&, String const& name, Boolean last) = 0;
+ virtual void
+ enter (Type&, String const& name, bool last) = 0;
- virtual Void
+ virtual void
leave () = 0;
};
@@ -465,10 +466,10 @@ namespace CXX
{
}
- virtual Void
+ virtual void
pre (Type&);
- virtual Void
+ virtual void
post (Type&);
private:
@@ -476,36 +477,35 @@ namespace CXX
ScopeTracker* st_;
};
-
//
//
template <typename X>
struct Has : X
{
- Has (Boolean& result)
+ Has (bool& result)
: result_ (result)
{
}
- virtual Void
+ virtual void
traverse (typename X::Type&)
{
result_ = true;
}
private:
- Boolean& result_;
+ bool& result_;
};
// Checks if scope 'Y' names any of 'X'
//
template <typename X, typename Y>
- Boolean
+ bool
has (Y& y)
{
using SemanticGraph::Scope;
- Boolean result (false);
+ bool result (false);
Has<X> t (result);
for (Scope::NamesIterator i (y.names_begin ()), e (y.names_end ());
@@ -518,12 +518,12 @@ namespace CXX
// Checks if the compositor has any particle of 'X'
//
template <typename X>
- Boolean
+ bool
has_particle (SemanticGraph::Compositor& y)
{
using SemanticGraph::Compositor;
- Boolean result (false);
+ bool result (false);
Has<X> t (result);
for (Compositor::ContainsIterator i (y.contains_begin ()),
@@ -543,7 +543,7 @@ namespace CXX
// Specialization for Complex
//
template <typename X>
- Boolean
+ bool
has_particle (SemanticGraph::Complex& c)
{
return c.contains_compositor_p () &&
@@ -562,61 +562,61 @@ namespace CXX
Traversal::Fundamental::Id,
Traversal::Fundamental::IdRef
{
- virtual Void
+ virtual void
fundamental_type (SemanticGraph::Fundamental::Type& t) = 0;
- virtual Void
+ virtual void
fundamental_template (SemanticGraph::Fundamental::Type& t) = 0;
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::Type& t)
{
fundamental_type (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::String& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::NormalizedString& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::Token& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::Name& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::NameToken& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::NCName& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::Id& t)
{
fundamental_template (t);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Fundamental::IdRef& t)
{
fundamental_template (t);