Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions Examples/Library/Reader/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// author : Boris Kolpackov <boris@dre.vanderbilt.edu>

#include <iostream>
#include <type_traits>
#include <utility>

#include "../dom.hpp"
#include "library.hpp"
Expand Down Expand Up @@ -29,37 +31,38 @@ main (int argc, char* argv[])
{
using namespace Lib;

Library const& lib = library (doc);
static_assert (std::is_same_v<decltype (std::declval<Library&> ().book ()),
Library::book_container_type&>);
static_assert (std::is_same_v<decltype (std::declval<Library const&> ().book ()),
Library::book_container_type const&>);

for (Library::book_const_iterator b (lib.begin_book ());
b != lib.end_book (); ++b)
Library const& lib = reader::library (doc);

for (Book const& b : lib.book ())
{
wcerr << endl
<< L"ISBN : " << b->isbn () << endl
<< L"Title : " << b->title () << endl;
<< L"ISBN : " << b.isbn () << endl
<< L"Title : " << b.title () << endl;

for (Book::author_const_iterator a (b->begin_author ());
a != b->end_author ();
++a)
for (Author const& a : b.author ())
{
wcerr << L"Author : " << a->name () << endl;
wcerr << L"Author : " << a.name () << endl;

if (a->recommends_p () /* @@ VC7.1 && a->recommends () */)
::XMLSchema::IDREF<ACE_TCHAR> const* recommends_if_set_ptr = a.recommends_if_set ();
if (recommends_if_set_ptr)
{
Book const& rec = static_cast<Book const&> (*(a->recommends ()));
Book const& rec = static_cast<Book const&> (**recommends_if_set_ptr);
wcerr << L"Recommends : " << rec.title () << endl;
}
}

for (Book::character_const_iterator c (b->begin_character ());
c != b->end_character ();
++c)
for (Character const& c : b.character ())
{
wcerr << L"Character : " << c->name () << L" - "
<< c->qualification () << endl;
wcerr << L"Character : " << c.name () << L" - "
<< c.qualification () << endl;
}

wcerr << L"Available : " << b->available () << endl;
wcerr << L"Available : " << b.available () << endl;
}

// Example of traversal usage. Here we are going to dump
Expand Down
2 changes: 2 additions & 0 deletions Tests/Escape/escape.mpc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project (xsc_test_escape): xscdefaults {
requires += xsc
custom_only = 1
xscflags += --cxx-cpp17
XSC_Files {
test.xsd
}
Expand All @@ -13,5 +14,6 @@ project (xsc_test_escape_generated): xscrt {

Source_Files {
test.cpp
escape_api.cpp
}
}
18 changes: 18 additions & 0 deletions Tests/Escape/escape_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "test.hpp"

#include <type_traits>
#include <utility>

namespace
{
using EscapedClass = test::_cxx_class;

static_assert (std::is_same_v<decltype (std::declval<EscapedClass const&> ()._cxx_int ()),
::XMLSchema::int_ const&>);
static_assert (std::is_same_v<decltype (std::declval<EscapedClass const&> ()._cxx_long_if_set ()),
::XMLSchema::long_ const*>);
static_assert (std::is_same_v<decltype (std::declval<EscapedClass const&> ()._cxx_double ()),
EscapedClass::double_container_type const&>);
static_assert (std::is_same_v<decltype (test::reader::_cxx_switch (nullptr)),
EscapedClass>);
}
29 changes: 27 additions & 2 deletions Tests/ReadOnly/readonly_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ namespace
{
};

template <typename T, typename = void>
struct has_item_iterators : std::false_type
{
};

template <typename T>
struct has_item_iterators<T, std::void_t<decltype (std::declval<T const&> ().begin_item ()),
decltype (std::declval<T const&> ().end_item ())>>
: std::true_type
{
};

template <typename T, typename = void>
struct has_item_count : std::false_type
{
};

template <typename T>
struct has_item_count<T, std::void_t<decltype (std::declval<T const&> ().count_item ())>>
: std::true_type
{
};

using ReadOnly = ReadOnlyType;

static_assert (!std::is_default_constructible_v<ReadOnly>);
Expand All @@ -37,12 +60,14 @@ namespace
static_assert (!std::is_move_assignable_v<ReadOnly>);
static_assert (!has_name_setter<ReadOnly>::value);
static_assert (!has_optionalValue_presence_accessor<ReadOnly>::value);
static_assert (!has_item_iterators<ReadOnly>::value);
static_assert (!has_item_count<ReadOnly>::value);
static_assert (std::is_same_v<ReadOnly::item_container_type,
std::list<::XMLSchema::string<char>>>);
static_assert (std::is_same_v<decltype (std::declval<ReadOnly&> ().name ()),
::XMLSchema::string<char> const&>);
static_assert (std::is_same_v<decltype (std::declval<ReadOnly&> ().optionalValue_if_set ()),
::XMLSchema::string<char> const*>);
static_assert (std::is_same_v<decltype (*std::declval<ReadOnly&> ().begin_item ()),
::XMLSchema::string<char> const&>);
static_assert (std::is_same_v<decltype (std::declval<ReadOnly&> ().item ()),
ReadOnly::item_container_type const&>);
}
23 changes: 23 additions & 0 deletions Tests/SequenceAccessorCollision/sequence_accessor_collision.mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
project (xsc_test_sequence_accessor_collision): xscdefaults {
requires += xsc
custom_only = 1
xscflags += --cxx-cpp17
xscflags += --cxx-char-type char
xscflags += --cxx-generate-traversal-types

XSC_Files {
test.xsd
}

Source_Files {
}
}

project (xsc_test_sequence_accessor_collision_generated): xscrt {
after += xsc_test_sequence_accessor_collision

Source_Files {
test.cpp
sequence_accessor_collision_api.cpp
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "test.hpp"

#include <type_traits>
#include <utility>

namespace
{
using Collision = SequenceAccessorCollision;

static_assert (std::is_same_v<decltype (std::declval<Collision&> ().value ()),
Collision::value_container_type&>);
static_assert (std::is_same_v<decltype (std::declval<Collision const&> ().value ()),
Collision::value_container_type const&>);
static_assert (std::is_same_v<decltype (std::declval<Collision const&> ().value_values ()),
::XMLSchema::string<char> const&>);
}
9 changes: 9 additions & 0 deletions Tests/SequenceAccessorCollision/test.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="SequenceAccessorCollision">
<xs:sequence>
<xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="value_values" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
1 change: 1 addition & 0 deletions Tests/Tests.mwc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace (Tests) {
Include
NoNamespace
ReadOnly
SequenceAccessorCollision
UnqualifiedImport
Validation
}
62 changes: 61 additions & 1 deletion XSC/be/CXX/Elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ fq_name (SemanticGraph::Nameable& n, string const& nss, bool mangle)
string name;

if (mangle)
{
name = id (n.name ());

// The runtime uses trailing underscores for its fundamental type names.
if (xs_ns_name (n) == L"http://www.w3.org/2001/XMLSchema" &&
(n.name () == L"double" || n.name () == L"float" || n.name () == L"int" ||
n.name () == L"long" || n.name () == L"short"))
name = n.name () + L'_';
}
else name = n.name ();

if (n.named ())
Expand Down Expand Up @@ -345,6 +353,53 @@ base_type_name (SemanticGraph::Complex& t)
return b == e ? L"::XSCRT::Type" : type_name ((**b).inheritee ());
}

string Context::
fundamental_type_name (SemanticGraph::FundamentalType& t)
{
string name (t.name ());

// The XMLSchema runtime uses trailing underscores for these fundamental types.
if (name == L"double" || name == L"float" || name == L"int" ||
name == L"long" || name == L"short")
name += L'_';

return name;
}

string Context::
sequence_accessor_name (SemanticGraph::Element& e)
{
auto conflicts = [this, &e] (string const& candidate)
{
for (auto i (e.scope ().names_begin ()), end (e.scope ().names_end ()); i != end; ++i)
{
SemanticGraph::Names& name (**i);

SemanticGraph::Element* other (
dynamic_cast<SemanticGraph::Element*> (std::addressof (name.named ())));
if (other != std::addressof (e) && id (name.name ()) == candidate)
return true;
}

return false;
};

string name (id (e.name ()));
if (!conflicts (name))
return name;

name += L"_values";
if (!conflicts (name))
return name;

name = id (e.name ()) + L"_sequence_values";
size_t suffix (2);
while (conflicts (name))
name = id (e.name ()) + L"_sequence_values_" + std::to_wstring (suffix++);

return name;
}

string Context::
type_name (SemanticGraph::Instance& i, string const& nss)
{
Expand Down Expand Up @@ -450,7 +505,12 @@ id (string const& name)
{
std::size_t const size (sizeof (keywords) / sizeof (wchar_t*));

if (std::binary_search (keywords, keywords + size, name)) return name + L'_';
if (std::binary_search (keywords, keywords + size, name))
{
if (cppmode () == CPPMODE::CPP03) return name + L'_';

return L"_cxx_" + name;
}

return name;
}
Expand Down
6 changes: 6 additions & 0 deletions XSC/be/CXX/Elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@ class Context
string
type_name (SemanticGraph::Type& t, string const& ns_suffix = L"");

string
fundamental_type_name (SemanticGraph::FundamentalType& t);

string
base_type_name (SemanticGraph::Complex& t);

string
sequence_accessor_name (SemanticGraph::Element& e);

protected:
string
fq_name (SemanticGraph::Nameable& n, string const& ns_suffix = L"", bool mangle = true);
Expand Down
66 changes: 40 additions & 26 deletions XSC/be/CXX/Header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ namespace

if (c.max () != 1)
{
string accessor_name (sequence_accessor_name (c));

// sequence
//
switch(this->cppmode_)
Expand All @@ -178,33 +180,45 @@ namespace
os << "using " << name << "_container_type = " << container << "<" << type << ">;";
break;
}
switch(this->cppmode_)
if (this->cppmode_ == CPPMODE::CPP17)
{
case CPPMODE::CPP03:
if (!this->read_only_)
os << "typedef " << name << "_container_type::iterator " << name << "_iterator;";
os << "typedef " << name << "_container_type::const_iterator " << name << "_const_iterator;";
if (!this->read_only_)
{
os << name << "_iterator begin_" << name << " ();";
os << name << "_iterator end_" << name << " ();";
}
break;
case CPPMODE::CPP11:
case CPPMODE::CPP17:
if (!this->read_only_)
os << "using " << name << "_iterator = " << name << "_container_type::iterator;";
os << "using " << name << "_const_iterator = " << name << "_container_type::const_iterator;";
if (!this->read_only_)
{
os << name << "_iterator begin_" << name << " ();";
os << name << "_iterator end_" << name << " ();";
}
break;
if (!this->read_only_)
os << name << "_container_type& " << accessor_name << " () noexcept;";
os << name << "_container_type const& " << accessor_name << " () const noexcept;";
}
else
{
switch(this->cppmode_)
{
case CPPMODE::CPP03:
if (!this->read_only_)
os << "typedef " << name << "_container_type::iterator " << name << "_iterator;";
os << "typedef " << name << "_container_type::const_iterator "
<< name << "_const_iterator;";
if (!this->read_only_)
{
os << name << "_iterator begin_" << name << " ();";
os << name << "_iterator end_" << name << " ();";
}
break;
case CPPMODE::CPP11:
if (!this->read_only_)
os << "using " << name << "_iterator = " << name << "_container_type::iterator;";
os << "using " << name << "_const_iterator = "
<< name << "_container_type::const_iterator;";
if (!this->read_only_)
{
os << name << "_iterator begin_" << name << " ();";
os << name << "_iterator end_" << name << " ();";
}
break;
case CPPMODE::CPP17:
break;
}

os << name << "_const_iterator begin_" << name << " () const;";
os << name << "_const_iterator end_" << name << " () const;";
os << name << "_const_iterator begin_" << name << " () const;";
os << name << "_const_iterator end_" << name << " () const;";
}

switch(this->cppmode_)
{
Expand All @@ -227,8 +241,8 @@ namespace
os << "void set_" << name << "_ptr (const " << string_type << "& idref);";
}

os << "size_t count_" << name << " () const"
<< (this->cppmode_ == CPPMODE::CPP17 ? " noexcept;" : ";");
if (this->cppmode_ != CPPMODE::CPP17)
os << "size_t count_" << name << " () const;";

os << std::endl
<< (this->read_only_ ? "private:" : "protected:") << std::endl;
Expand Down
Loading