summaryrefslogtreecommitdiff
path: root/xsd/xsd/cxx/tree/generator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'xsd/xsd/cxx/tree/generator.cxx')
-rw-r--r--xsd/xsd/cxx/tree/generator.cxx183
1 files changed, 112 insertions, 71 deletions
diff --git a/xsd/xsd/cxx/tree/generator.cxx b/xsd/xsd/cxx/tree/generator.cxx
index 5601f4e..9782b4d 100644
--- a/xsd/xsd/cxx/tree/generator.cxx
+++ b/xsd/xsd/cxx/tree/generator.cxx
@@ -54,6 +54,8 @@ using namespace XSDFrontend::SemanticGraph;
//
//
+typedef std::wostream WideOutputStream;
+
typedef std::wifstream WideInputFileStream;
typedef std::wofstream WideOutputFileStream;
@@ -80,19 +82,19 @@ namespace CXX
"// along with this program; if not, write to the Free Software\n"
"// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
"//\n"
- "// In addition, as a special exception, Code Synthesis Tools CC gives\n"
- "// permission to link this program with the Xerces-C++ library (or with\n"
- "// modified versions of Xerces-C++ that use the same license as Xerces-C++),\n"
- "// and distribute linked combinations including the two. You must obey\n"
- "// the GNU General Public License version 2 in all respects for all of\n"
- "// the code used other than Xerces-C++. If you modify this copy of the\n"
- "// program, you may extend this exception to your version of the program,\n"
- "// but you are not obligated to do so. If you do not wish to do so, delete\n"
- "// this exception statement from your version.\n"
+ "// In addition, as a special exception, Code Synthesis gives permission\n"
+ "// to link this program with the Xerces-C++ library (or with modified\n"
+ "// versions of Xerces-C++ that use the same license as Xerces-C++), and\n"
+ "// distribute linked combinations including the two. You must obey the GNU\n"
+ "// General Public License version 2 in all respects for all of the code\n"
+ "// used other than Xerces-C++. If you modify this copy of the program, you\n"
+ "// may extend this exception to your version of the program, but you are\n"
+ "// not obligated to do so. If you do not wish to do so, delete this\n"
+ "// exception statement from your version.\n"
"//\n"
- "// Furthermore, Code Synthesis Tools CC makes a special exception for\n"
- "// the Free/Libre and Open Source Software (FLOSS) which is described\n"
- "// in the accompanying FLOSSE file.\n"
+ "// Furthermore, Code Synthesis makes a special exception for the Free/Libre\n"
+ "// and Open Source Software (FLOSS) which is described in the accompanying\n"
+ "// FLOSSE file.\n"
"//\n\n";
char const copyright_proprietary[] =
@@ -101,8 +103,7 @@ namespace CXX
"// This program was generated by CodeSynthesis XSD, an XML Schema\n"
"// to C++ data binding compiler, in the Proprietary License mode.\n"
"// You should have received a proprietary license from Code Synthesis\n"
- "// Tools CC prior to generating this code. See the license text for\n"
- "// conditions.\n"
+ "// prior to generating this code. See the license text for conditions.\n"
"//\n\n";
}
@@ -232,7 +233,7 @@ namespace CXX
throw Failed ();
}
- bool gen_cxx (!ops.generate_dep_only ());
+ bool gen_cxx (!ops.generate_dep_only () && !ops.file_list_only ());
// Process ordered types.
//
@@ -345,9 +346,13 @@ namespace CXX
? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + fwd_suffix + "#"
: ops.fwd_regex ());
- Regex dep_expr (ops.dep_regex ().empty ()
- ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + dep_suffix + "#"
- : ops.dep_regex ());
+ // @@ This will blow up if --dep-file value contains backslashes (e.g.,
+ // it's a Windows path).
+ //
+ Regex dep_expr (
+ ops.dep_regex_specified () ? ops.dep_regex () :
+ ops.dep_file_specified () ? "#.+#" + ops.dep_file () + "#" :
+ "#^(.+?)(\\.[^./\\\\]+)?$#$1" + dep_suffix + "#");
if (header && !hxx_expr.match (name))
{
@@ -397,7 +402,7 @@ namespace CXX
Path hxx_path (hxx_name);
Path ixx_path (ixx_name);
Path fwd_path (fwd_name);
- Path dep_path (dep_name);
+ Path dep_path (dep_name != "-" ? dep_name : NarrowString ());
Paths cxx_paths;
if (source)
@@ -458,10 +463,11 @@ namespace CXX
if (!out_dir.empty ())
{
- hxx_path = out_dir / hxx_path;
- ixx_path = out_dir / ixx_path;
- fwd_path = out_dir / fwd_path;
- dep_path = out_dir / dep_path;
+ if (!hxx_path.empty ()) hxx_path = out_dir / hxx_path;
+ if (!ixx_path.empty ()) ixx_path = out_dir / ixx_path;
+ if (!fwd_path.empty ()) fwd_path = out_dir / fwd_path;
+ if (!dep_path.empty () &&
+ !dep_path.absolute ()) dep_path = out_dir / dep_path;
for (Paths::iterator i (cxx_paths.begin ());
i != cxx_paths.end (); ++i)
@@ -473,93 +479,116 @@ namespace CXX
WideOutputFileStream hxx;
WideOutputFileStream ixx;
WideOutputFileStream fwd;
- WideOutputFileStream dep;
+ WideOutputFileStream depf; // See dep below.
WideOutputFileStreams cxx;
// DEP
//
if (gen_dep)
{
- dep.open (dep_path.string ().c_str (), ios_base::out);
-
- if (!dep.is_open ())
+ if (!dep_path.empty ())
{
- wcerr << dep_path << ": error: unable to open in write mode" << endl;
- throw Failed ();
+ depf.open (dep_path.string ().c_str (), ios_base::out);
+
+ if (!depf.is_open ())
+ {
+ wcerr << dep_path << ": error: unable to open in write mode"
+ << endl;
+ throw Failed ();
+ }
+
+ unlinks.add (dep_path);
}
- unlinks.add (dep_path);
- file_list.push_back (dep_path.string ());
+ // Note: not adding to file_list.
}
+ WideOutputStream& dep (gen_dep && !dep_path.empty () ? depf : wcout);
+
// FWD
//
- if (gen_cxx && forward)
+ if (forward)
{
- fwd.open (fwd_path.string ().c_str (), ios_base::out);
-
- if (!fwd.is_open ())
+ if (gen_cxx)
{
- wcerr << fwd_path << ": error: unable to open in write mode" << endl;
- throw Failed ();
+ fwd.open (fwd_path.string ().c_str (), ios_base::out);
+
+ if (!fwd.is_open ())
+ {
+ wcerr << fwd_path << ": error: unable to open in write mode" << endl;
+ throw Failed ();
+ }
+
+ unlinks.add (fwd_path);
}
- unlinks.add (fwd_path);
file_list.push_back (fwd_path.string ());
}
// HXX
//
- if (gen_cxx && header)
+ if (header)
{
- hxx.open (hxx_path.string ().c_str (), ios_base::out);
-
- if (!hxx.is_open ())
+ if (gen_cxx)
{
- wcerr << hxx_path << ": error: unable to open in write mode" << endl;
- throw Failed ();
+ hxx.open (hxx_path.string ().c_str (), ios_base::out);
+
+ if (!hxx.is_open ())
+ {
+ wcerr << hxx_path << ": error: unable to open in write mode" << endl;
+ throw Failed ();
+ }
+
+ unlinks.add (hxx_path);
}
- unlinks.add (hxx_path);
file_list.push_back (hxx_path.string ());
}
// IXX
//
- if (gen_cxx && inline_)
+ if (inline_)
{
- ixx.open (ixx_path.string ().c_str (), ios_base::out);
-
- if (!ixx.is_open ())
+ if (gen_cxx)
{
- wcerr << ixx_path << ": error: unable to open in write mode" << endl;
- throw Failed ();
+ ixx.open (ixx_path.string ().c_str (), ios_base::out);
+
+ if (!ixx.is_open ())
+ {
+ wcerr << ixx_path << ": error: unable to open in write mode" << endl;
+ throw Failed ();
+ }
+
+ unlinks.add (ixx_path);
}
- unlinks.add (ixx_path);
file_list.push_back (ixx_path.string ());
}
// CXX
//
- if (gen_cxx && source)
+ if (source)
{
for (Paths::iterator i (cxx_paths.begin ());
i != cxx_paths.end (); ++i)
{
- shared_ptr<WideOutputFileStream> s (
- new (shared) WideOutputFileStream (
- i->string ().c_str (), ios_base::out));
-
- if (!s->is_open ())
+ if (gen_cxx)
{
- wcerr << *i << ": error: unable to open in write mode" << endl;
- throw Failed ();
+ shared_ptr<WideOutputFileStream> s (
+ new (shared) WideOutputFileStream (
+ i->string ().c_str (), ios_base::out));
+
+ if (!s->is_open ())
+ {
+ wcerr << *i << ": error: unable to open in write mode" << endl;
+ throw Failed ();
+ }
+
+ cxx.push_back (s);
+ unlinks.add (*i);
}
- unlinks.add (*i);
file_list.push_back (i->string ());
- cxx.push_back (s);
}
}
@@ -668,7 +697,8 @@ namespace CXX
i != cxx_paths.end (); ++i)
target += " \\\n" + i->string ();
- target += " \\\n" + dep_path.string ();
+ if (!dep_path.empty ())
+ target += " \\\n" + dep_path.string ();
}
dep << target.c_str () << ':';
@@ -928,19 +958,16 @@ namespace CXX
}
}
- if (inline_)
- {
- hxx << "#ifndef XSD_DONT_INCLUDE_INLINE" << endl
- << "#include " << ctx.process_include_path (ixx_name) << endl
- << "#endif // XSD_DONT_INCLUDE_INLINE" << endl
- << endl;
- }
-
hxx << "#include <xsd/cxx/post.hxx>" << endl
<< endl;
// Copy epilogue.
//
+ // Note that it goes before the inline file in case it defines
+ // something (such as a custom type) which is needed by this file.
+ // And if something in the epilogue needs something from the inline
+ // file, then it should be the inline rather than header epilogue.
+ //
hxx << "// Begin epilogue." << endl
<< "//" << endl;
@@ -951,6 +978,14 @@ namespace CXX
<< "// End epilogue." << endl
<< endl;
+ if (inline_)
+ {
+ hxx << "#ifndef XSD_DONT_INCLUDE_INLINE" << endl
+ << "#include " << ctx.process_include_path (ixx_name) << endl
+ << "#endif // XSD_DONT_INCLUDE_INLINE" << endl
+ << endl;
+ }
+
hxx << "#endif // " << guard << endl;
if (show_sloc)
@@ -999,6 +1034,9 @@ namespace CXX
<< "// End prologue." << endl
<< endl;
+ ixx << "#include <xsd/cxx/pre.hxx>" << endl
+ << endl;
+
// Generate.
//
{
@@ -1006,6 +1044,9 @@ namespace CXX
generate_tree_inline (ctx, 1, 0);
}
+ ixx << "#include <xsd/cxx/post.hxx>" << endl
+ << endl;
+
// Copy epilogue.
//
ixx << "// Begin epilogue." << endl