aboutsummaryrefslogtreecommitdiff
path: root/xsd/cxx/parser/characters-validation-source.cxx
blob: 6c4cb5f003ce2779b5d172ffe33864a2a8cb49a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// file      : xsd/cxx/parser/characters-validation-source.cxx
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <cxx/parser/characters-validation-source.hxx>

#include <xsd-frontend/semantic-graph.hxx>
#include <xsd-frontend/traversal.hxx>

namespace CXX
{
  namespace Parser
  {
    namespace
    {
      //
      //
      struct Complex: Traversal::Complex, Context
      {
        Complex (Context& c)
            : Context (c)
        {
        }

        virtual void
        traverse (Type& c)
        {
          if (!c.mixed_p ())
            return;

          String const& name (ename (c));

          os <<"// Character validation functions for " << name << "." << endl
             <<"//" << endl;

            // _characters_impl
            //
          os << "bool " << name << "::" << endl
             << "_characters_impl (const " << string_type << "& s)"
             << "{"
             << "this->_any_characters (s);"
             << "return true;"
             << "}";
        }
      };
    }

    void
    generate_characters_validation_source (Context& ctx)
    {
      //@@ Most of the time there is no mixed content type so
      //   we generate an empty namespace which looks ugly. Will
      //   need to implement smart namespace to handle this at
      //   some point.
      //
      Traversal::Schema schema;

      Sources sources;
      Traversal::Names schema_names;

      Namespace ns (ctx);
      Traversal::Names names;

      schema >> sources >> schema;
      schema >> schema_names >> ns >> names;

      Complex complex (ctx);

      names >> complex;

      schema.dispatch (ctx.schema_root);
    }
  }
}