summaryrefslogtreecommitdiff
path: root/xsd/xsd/cxx/parser/parser-source.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'xsd/xsd/cxx/parser/parser-source.cxx')
-rw-r--r--xsd/xsd/cxx/parser/parser-source.cxx139
1 files changed, 81 insertions, 58 deletions
diff --git a/xsd/xsd/cxx/parser/parser-source.cxx b/xsd/xsd/cxx/parser/parser-source.cxx
index 99bc566..2ee5273 100644
--- a/xsd/xsd/cxx/parser/parser-source.cxx
+++ b/xsd/xsd/cxx/parser/parser-source.cxx
@@ -1,6 +1,5 @@
// file : xsd/cxx/parser/parser-source.cxx
-// 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
#include <cxx/parser/parser-source.hxx>
@@ -21,7 +20,7 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& e)
{
String const& name (ename (e));
@@ -29,7 +28,7 @@ namespace CXX
SemanticGraph::Type& base (e.inherits ().base ());
- Boolean same (ret == ret_type (base));
+ bool same (ret == ret_type (base));
if (same || ret == L"void" || polymorphic)
{
@@ -79,7 +78,7 @@ namespace CXX
if (validation)
{
- Boolean gen (!anonymous (e));
+ bool gen (!anonymous (e));
// We normally don't need to enter anonymous types into
// the inheritance map. The only exception is when an
@@ -89,16 +88,21 @@ namespace CXX
if (!gen)
{
// The first instance that this anonymous type classifies
- // is the prototype for others if any.
+ // is the prototype for others if any. If this type does
+ // not classify anything (e.g., it is a base), then we
+ // don't need to do anything.
//
- SemanticGraph::Instance& i (
- e.classifies_begin ()->instance ());
-
- if (SemanticGraph::Element* e =
- dynamic_cast<SemanticGraph::Element*> (&i))
+ if (e.classifies_begin () != e.classifies_end ())
{
- if (e->substitutes_p ())
- gen = true;
+ SemanticGraph::Instance& i (
+ e.classifies_begin ()->instance ());
+
+ if (SemanticGraph::Element* e =
+ dynamic_cast<SemanticGraph::Element*> (&i))
+ {
+ if (e->substitutes_p ())
+ gen = true;
+ }
}
}
@@ -126,7 +130,7 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& l)
{
String const& name (ename (l));
@@ -222,7 +226,7 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& u)
{
String const& name (ename (u));
@@ -277,15 +281,13 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& e)
{
if (skip (e))
return;
- Boolean poly (polymorphic && !anonymous (e.type ()));
-
- String const& inst (poly ? emember_cache (e) : emember (e));
+ bool poly (polymorphic && !anonymous (e.type ()));
os << "if (";
@@ -316,9 +318,12 @@ namespace CXX
os << ")"
<< "{";
+ String inst;
+
if (poly)
{
SemanticGraph::Type& t (e.type ());
+ inst = "p";
// For pre-computing length.
//
@@ -334,8 +339,10 @@ namespace CXX
String const& member (emember (e));
String const& member_map (emember_map (e));
- os << "if (t == 0 && this->" << member << " != 0)" << endl
- << "this->" << inst << " = this->" << member << ";"
+ os << fq_type << "* p = 0;"
+ << endl
+ << "if (t == 0 && this->" << member << " != 0)" << endl
+ << inst << " = this->" << member << ";"
<< "else"
<< "{"
<< string_type << " ts (" << fq_type <<
@@ -345,21 +352,21 @@ namespace CXX
<< "t = &ts;"
<< endl
<< "if (this->" << member << " != 0 && *t == ts)" << endl
- << "this->" << inst << " = this->" << member << ";"
+ << inst << " = this->" << member << ";"
<< "else if (this->" << member_map << " != 0)" << endl
- << "this->" << inst << " = dynamic_cast< " << fq_type <<
+ << inst << " = dynamic_cast< " << fq_type <<
"* > (" << endl
<< "this->" << member_map << "->find (*t));"
- << "else" << endl
- << "this->" << inst << " = 0;"
<< "}";
}
+ else
+ inst = L"this->" + emember (e);
os << "this->" << complex_base << "::context_.top ().parser_ = " <<
- "this->" << inst << ";"
+ inst << ";"
<< endl
- << "if (this->" << inst << ")" << endl
- << "this->" << inst << "->pre ();" // _start_element calls _pre
+ << "if (" << inst << ")" << endl
+ << inst << "->pre ();" // _start_element calls _pre
<< endl
<< "return true;"
<< "}";
@@ -376,16 +383,14 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& e)
{
if (skip (e))
return;
- Boolean poly (polymorphic && !anonymous (e.type ()));
-
+ bool poly (polymorphic && !anonymous (e.type ()));
String const& name (ename (e));
- String const& inst (poly ? emember_cache (e) : emember (e));
os << "if (";
@@ -421,18 +426,31 @@ namespace CXX
SemanticGraph::Type& type (e.type ());
String const& post (post_name (type));
+ String inst;
+
+ if (poly)
+ {
+ String const& fq_type (fq_name (type));
+ inst = "p";
- os << "if (this->" << inst << ")";
+ os << fq_type << "* p =" << endl
+ << "dynamic_cast< " << fq_type << "* > (" << endl
+ << "this->" << complex_base << "::context_.top ().parser_);"
+ << endl;
+ }
+ else
+ inst = L"this->" + emember (e);
+
+ os << "if (" << inst << ")";
if (ret_type (type) == L"void")
os << "{"
- << "this->" << inst << "->" << post << " ();"
+ << inst << "->" << post << " ();"
<< "this->" << name << " ();"
<< "}";
else
os << endl
- << "this->" << name << " (this->" << inst << "->" <<
- post << " ());"
+ << "this->" << name << " (" << inst << "->" << post << " ());"
<< endl;
os << "return true;"
@@ -449,7 +467,7 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& a)
{
String const& name (ename (a));
@@ -500,7 +518,7 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& m)
{
if (skip (m))
@@ -538,14 +556,14 @@ namespace CXX
names_attribute_ >> attribute_;
}
- virtual Void
+ virtual void
traverse (Type& c)
{
- Boolean he (has<Traversal::Element> (c));
- Boolean ha (has<Traversal::Attribute> (c));
+ bool he (has<Traversal::Element> (c));
+ bool ha (has<Traversal::Attribute> (c));
String const& ret (ret_type (c));
- Boolean same (c.inherits_p () &&
+ bool same (c.inherits_p () &&
ret == ret_type (c.inherits ().base ()));
String const& name (ename (c));
@@ -581,7 +599,7 @@ namespace CXX
if (c.inherits_p () && validation)
{
- Boolean gen (!anonymous (c));
+ bool gen (!anonymous (c));
// We normally don't need to enter anonymous types into
// the inheritance map. The only exception is when an
@@ -591,16 +609,21 @@ namespace CXX
if (!gen)
{
// The first instance that this anonymous type classifies
- // is the prototype for others if any.
+ // is the prototype for others if any. If this type does
+ // not classify anything (e.g., it is a base), then we
+ // don't need to do anything.
//
- SemanticGraph::Instance& i (
- c.classifies_begin ()->instance ());
-
- if (SemanticGraph::Element* e =
- dynamic_cast<SemanticGraph::Element*> (&i))
+ if (c.classifies_begin () != c.classifies_end ())
{
- if (e->substitutes_p ())
- gen = true;
+ SemanticGraph::Instance& i (
+ c.classifies_begin ()->instance ());
+
+ if (SemanticGraph::Element* e =
+ dynamic_cast<SemanticGraph::Element*> (&i))
+ {
+ if (e->substitutes_p ())
+ gen = true;
+ }
}
}
@@ -655,7 +678,7 @@ namespace CXX
// Don't use restriction_p here since we don't want special
// treatment of anyType.
//
- Boolean restriction (
+ bool restriction (
c.inherits_p () &&
c.inherits ().is_a<SemanticGraph::Restricts> ());
@@ -782,7 +805,7 @@ namespace CXX
{
}
- virtual Void
+ virtual void
traverse (Type& e)
{
if (e.substitutes_p ())
@@ -809,7 +832,7 @@ namespace CXX
};
}
- Void
+ void
generate_parser_source (Context& ctx)
{
if (ctx.polymorphic)
@@ -822,8 +845,8 @@ namespace CXX
else
ctx.os << endl;
- Boolean import_maps (ctx.options.value<CLI::import_maps> ());
- Boolean export_maps (ctx.options.value<CLI::export_maps> ());
+ bool import_maps (ctx.options.import_maps ());
+ bool export_maps (ctx.options.export_maps ());
if (import_maps || export_maps)
{
@@ -896,7 +919,7 @@ namespace CXX
// Emit "weak" header includes that are used in the file-per-type
// compilation model.
//
- if (ctx.options.value<CLI::generate_inline> ())
+ if (ctx.options.generate_inline ())
{
Traversal::Schema schema;
Includes includes (ctx, Includes::source);
@@ -906,7 +929,7 @@ namespace CXX
}
Traversal::Schema schema;
- Traversal::Sources sources;
+ Sources sources;
Traversal::Names schema_names;
Namespace ns (ctx);