Author: wyoung
Date: Tue Sep 8 06:05:23 2009
New Revision: 2577
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2577&view=rev
Log:
Added skeleton of SSQLS v2 generator (-o) to ssqlsxlat.
Added:
trunk/ssx/genv2.cpp
trunk/ssx/genv2.h
Modified:
trunk/Wishlist
trunk/lib/cmdline.cpp
trunk/lib/cmdline.h
trunk/mysql++.bkl
trunk/ssx/main.cpp
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=2577&r1=2576&r2=2577&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Tue Sep 8 06:05:23 2009
@@ -133,6 +133,9 @@
...and ssqls_stock.cc, containing implementation for same.
+ - SQL table updater/builder, -T option, taking .ssqls and
+ creating or updating the DB table to match.
+
- If using accessors, generate "std::bitset<num_fields> is_set_",
and set the appropriate bit when calling each setFoo() so we can
intuit which fields were set. Probably also need an enum:
Modified: trunk/lib/cmdline.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/cmdline.cpp?rev=2577&r1=2576&r2=2577&view=diff
==============================================================================
--- trunk/lib/cmdline.cpp (original)
+++ trunk/lib/cmdline.cpp Tue Sep 8 06:05:23 2009
@@ -269,16 +269,13 @@
pass_(""),
server_(0),
user_(0),
-input_source_(is_unknown)
+input_source_(ss_unknown),
+output_sink_(ss_unknown)
{
// Parse the command line
int ch;
while (successful() && ((ch = parse_next()) != EOF)) {
switch (ch) {
- case 'o': output_ = option_argument(); break;
- case 'p': pass_ = option_argument(); break;
- case 's': server_ = option_argument(); break;
- case 'u': user_ = option_argument(); break;
case 'i':
case 't':
case '1':
@@ -289,9 +286,26 @@
}
input_ = option_argument();
input_source_ =
- (ch == '1' ? is_ssqls1 :
- ch == 'i' ? is_ssqls2 :
- is_table);
+ (ch == '1' ? ss_ssqls1 :
+ ch == 'i' ? ss_ssqls2 :
+ ss_table);
+ break;
+
+ case 'o':
+ output_ = option_argument();
+ output_sink_ = ss_ssqls2;
+ break;
+
+ case 'p':
+ pass_ = option_argument();
+ break;
+
+ case 's':
+ server_ = option_argument();
+ break;
+
+ case 'u':
+ user_ = option_argument();
break;
default:
@@ -303,10 +317,10 @@
// Figure out whether command line makes sense, and if not, tell
// user about it.
if (successful()) {
- if (input_source_ == is_unknown) {
+ if (input_source_ == ss_unknown) {
parse_error("No input source given! Need -i, -t or
-1.");
}
- else if ((input_source_ != is_ssqls2) && !output_) {
+ else if ((input_source_ != ss_ssqls2) && !output_) {
parse_error("Need -o if you give -t or -1!");
}
}
Modified: trunk/lib/cmdline.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/cmdline.h?rev=2577&r1=2576&r2=2577&view=diff
==============================================================================
--- trunk/lib/cmdline.h (original)
+++ trunk/lib/cmdline.h Tue Sep 8 06:05:23 2009
@@ -186,11 +186,11 @@
public:
//// Public types
/// \brief Types of inputs that ssqlsxlat will accept
- enum InputSource {
- is_unknown, ///< no known input type given
yet
- is_ssqls1, ///< a C++ file containing an
SSQLS v1 declaration
- is_ssqls2, ///< an SSQLS v2 file
- is_table ///< an existing DB table schema
+ enum SourceSink {
+ ss_unknown, ///< no known input type given
yet
+ ss_ssqls1, ///< a C++ file containing an
SSQLS v1 declaration
+ ss_ssqls2, ///< an SSQLS v2 file
+ ss_table ///< an existing DB table schema
};
//// Public interface
@@ -207,7 +207,10 @@
const char* input() const { return input_; }
/// \brief The input source type
- InputSource input_source() const { return
input_source_; }
+ SourceSink input_source() const { return input_source_;
}
+
+ /// \brief The output sink (destination) type
+ SourceSink output_sink() const { return output_sink_; }
/// \brief The base name of the output file
const char* output() const { return output_; }
@@ -228,7 +231,8 @@
const char* pass_;
const char* server_;
const char* user_;
- InputSource input_source_;
+ SourceSink input_source_;
+ SourceSink output_sink_;
};
} // end namespace mysqlpp::ssqlsxlat
} // end namespace mysqlpp
Modified: trunk/mysql++.bkl
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/mysql%2B%2B.bkl?rev=2577&r1=2576&r2=2577&view=diff
==============================================================================
--- trunk/mysql++.bkl (original)
+++ trunk/mysql++.bkl Tue Sep 8 06:05:23 2009
@@ -206,6 +206,7 @@
<!-- Build rules for ssqlsxlat tool -->
<exe id="ssqlsxlat" template="programs">
+ <sources>ssx/genv2.cpp</sources>
<sources>ssx/main.cpp</sources>
<depends>ssqls2parse</depends>
<sys-lib>mysqlpp_ssqls2parse</sys-lib>
Added: trunk/ssx/genv2.cpp
URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/ssx/genv2.cpp?rev=2577&view=auto
==============================================================================
--- trunk/ssx/genv2.cpp (added)
+++ trunk/ssx/genv2.cpp Tue Sep 8 06:05:23 2009
@@ -1,0 +1,77 @@
+/***********************************************************************
+ ssx/genv2.cpp - Walks the SSQLS v2 parse result, writing back out
+ the equivalent SSQLS v2 DSL code. This is useful for testing that
+ our parser has correctly understood a given piece of code. It is
+ also something like the preprocessor mode of a C++ compiler,
+ emitting a digested version of its input.
+
+ Copyright (c) 2009 by Warren Young. Others may also hold copyrights
+ on code in this file. See the CREDITS.txt file in the top directory
+ of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#include "genv2.h"
+
+#include "parsev2.h"
+
+#include <iostream>
+#include <fstream>
+#include <typeinfo>
+
+using namespace std;
+
+//// generate_ssqls2 ///////////////////////////////////////////////////
+// 2 versions: second checks its arguments and opens the named file,
+// calling the second to actually generate the SSQLS v2 output from
+// the parse result only if we were given sane parameters.
+
+static bool
+generate_ssqls2(ofstream& ofs, const ParseV2* pparse)
+{
+ for (ParseV2::LineListIt it = pparse->begin();
+ it != pparse->end(); ++it) {
+ cout << "TRACE: write " << typeid(*it).name() << " line." <<
endl;
+ }
+
+ return true;
+}
+
+bool
+generate_ssqls2(const char* file_name, const ParseV2* pparse)
+{
+ if (pparse) {
+ ofstream ofs(file_name);
+ if (ofs) {
+ cout << "TRACE: Generating SSQLS v2 file " << file_name
<<
+ " from " << (pparse->end() -
pparse->begin()) <<
+ " line parse result." << endl;
+ return generate_ssqls2(ofs, pparse);
+ }
+ else {
+ cerr << "Failed to open " << file_name << \
+ " for writing for -o!" << endl;
+ return false;
+ }
+ }
+ else {
+ cerr << "No parse result given to -o handler!" << endl;
+ return false;
+ }
+}
Added: trunk/ssx/genv2.h
URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/ssx/genv2.h?rev=2577&view=auto
==============================================================================
--- trunk/ssx/genv2.h (added)
+++ trunk/ssx/genv2.h Tue Sep 8 06:05:23 2009
@@ -1,0 +1,33 @@
+/***********************************************************************
+ ssx/genv2.h - Mechanism for generating SSQLS v2 DSL code from
+ an SSQLS v2 parse result. Implements ssqlsxlat -o flag.
+
+ Copyright (c) 2009 by Warren Young. Others may also hold copyrights
+ on code in this file. See the CREDITS.txt file in the top directory
+ of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#if !defined(MYSQLPP_SSX_GENV2_H)
+#define MYSQLPP_SSX_GENV2_H
+
+class ParseV2;
+extern bool generate_ssqls2(const char* file_name, const ParseV2* pparse);
+
+#endif // !defined(MYSQLPP_SSX_GENV2_H)
Modified: trunk/ssx/main.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/ssx/main.cpp?rev=2577&r1=2576&r2=2577&view=diff
==============================================================================
--- trunk/ssx/main.cpp (original)
+++ trunk/ssx/main.cpp Tue Sep 8 06:05:23 2009
@@ -27,6 +27,7 @@
USA
***********************************************************************/
+#include "genv2.h"
#include "parsev2.h"
#include <cmdline.h>
@@ -41,14 +42,16 @@
// We were given the name of a putative SSQLS v2 source file; try to
// parse it.
-static int
+static ParseV2*
parse_ssqls2(const char* file_name)
{
try {
- ParseV2 p(file_name);
+ cout << "Parsing SSQLS v2 file " << file_name << "..." << endl;
+ ParseV2* pt = new ParseV2(file_name);
cout << file_name << " parsed successfully, " <<
- (p.end() - p.begin()) << " interesting lines."
<< endl;
- return 0;
+ (pt->end() - pt->begin()) << " interesting
lines." <<
+ endl;
+ return pt;
}
catch (const ParseV2::FileException& e) {
cerr << file_name << ":0" <<
@@ -64,7 +67,7 @@
": critical error in SSQLS v2 parse: " <<
e.what() << endl;
}
- return 3;
+ return 0;
}
@@ -76,9 +79,12 @@
// Parse the command line
CommandLine cmdline(argc, argv);
if (cmdline) {
+ ParseV2* ptree = 0;
+
switch (cmdline.input_source()) {
- case CommandLine::is_ssqls2:
- return parse_ssqls2(cmdline.input());
+ case CommandLine::ss_ssqls2:
+ ptree = parse_ssqls2(cmdline.input());
+ break;
default:
cerr << "Sorry, I don't yet know what to do
with input "
@@ -86,6 +92,24 @@
'!' << endl;
return 2;
}
+
+ if (ptree && (cmdline.output_sink() !=
CommandLine::ss_unknown)) {
+ switch (cmdline.output_sink()) {
+ case CommandLine::ss_ssqls2:
+ return
generate_ssqls2(cmdline.output(), ptree);
+
+ default:
+ cerr << "Sorry, I don't yet know what
to do with "
+ "sink type " <<
int(cmdline.output_sink()) <<
+ '!' << endl;
+ return 2;
+ }
+ }
+ else {
+ cerr << "Sorry, I don't know how to write C++ output
yet." <<
+ endl;
+ return 2;
+ }
}
else {
return 1;
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits