2009-11-07 18:04:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
|
2009-11-07 19:52:10 +01:00
|
|
|
const std::string ext(".cpp");
|
2009-11-07 18:04:45 +01:00
|
|
|
|
|
|
|
static std::string str(unsigned int value)
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << value;
|
|
|
|
return ostr.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(const int argc, const char * const * const argv)
|
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (argc != 2) {
|
2009-11-07 18:04:45 +01:00
|
|
|
std::cerr << "syntax: extracttests testfile" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string testname;
|
|
|
|
unsigned int subcount = 0;
|
|
|
|
|
|
|
|
std::ifstream f(argv[1]);
|
|
|
|
std::string line;
|
2011-10-13 20:53:06 +02:00
|
|
|
while (std::getline(f, line)) {
|
2009-11-09 20:40:58 +01:00
|
|
|
{
|
|
|
|
std::string::size_type pos = line.find_first_not_of(" ");
|
2010-04-02 07:30:58 +02:00
|
|
|
if (pos > 0 && pos != std::string::npos)
|
2009-11-09 20:40:58 +01:00
|
|
|
line.erase(0, pos);
|
|
|
|
}
|
2009-11-09 20:36:13 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (line.compare(0, 5, "void ") == 0) {
|
2009-11-09 20:36:13 +01:00
|
|
|
testname = line.substr(5, line.size() - 7);
|
2009-11-07 18:04:45 +01:00
|
|
|
subcount = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (line == "}") {
|
2009-11-07 18:04:45 +01:00
|
|
|
testname = "";
|
|
|
|
subcount = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!testname.empty() && line.compare(0, 5, "check") == 0 && line.find("(\"") != std::string::npos) {
|
2009-11-07 19:52:10 +01:00
|
|
|
std::ofstream fout((testname + str(++subcount) + ext).c_str());
|
2009-11-07 18:04:45 +01:00
|
|
|
fout << "#include <string.h>" << std::endl;
|
|
|
|
fout << "#include <stdio.h>" << std::endl;
|
|
|
|
fout << "#include <stdlib.h>" << std::endl;
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer1") {
|
|
|
|
if (subcount < 6) {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "class Token\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< "{\n"
|
|
|
|
<< "public:\n"
|
|
|
|
<< " const char *str() const;\n"
|
|
|
|
<< " const Token *next() const;\n"
|
|
|
|
<< " unsigned int size() const;\n"
|
|
|
|
<< " char read () const;\n"
|
|
|
|
<< " operator bool() const;\n"
|
|
|
|
<< "};\n"
|
|
|
|
<< "static Token *tokens;\n";
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "struct A\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
"{\n"
|
|
|
|
" char b();\n"
|
|
|
|
" A *next;\n"
|
|
|
|
"};\n";
|
2009-11-09 20:40:58 +01:00
|
|
|
}
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer2") {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "class Fred\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< "{\n"
|
|
|
|
<< "public:\n"
|
|
|
|
<< " void hello() const;\n"
|
|
|
|
<< " operator bool() const;\n"
|
|
|
|
<< "};\n";
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer3") {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "struct DEF { };\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< "struct ABC : public DEF\n"
|
|
|
|
<< "{\n"
|
|
|
|
<< " int a,b,c;\n"
|
|
|
|
<< " struct ABC *next;\n"
|
|
|
|
<< "};\n"
|
|
|
|
<< "void bar(int); void f(struct ABC **);\n";
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer4") {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "void bar(int);\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< "int** f(int **p = 0);\n"
|
|
|
|
<< "extern int x;\n"
|
|
|
|
<< "struct P {\n"
|
|
|
|
<< " bool check() const;\n"
|
|
|
|
<< " P* next() const;\n"
|
|
|
|
<< "};\n";
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer5") {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "struct A {\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< " char c() const;\n"
|
|
|
|
<< " operator bool() const;\n"
|
|
|
|
<< "};\n";
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer6") {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "struct Foo {\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< " void abcd() const;\n"
|
|
|
|
<< "};\n"
|
|
|
|
<< "struct FooBar : public Foo { };\n"
|
|
|
|
<< "struct FooCar : public Foo { };\n"
|
|
|
|
<< "extern int a;\n";
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (testname == "nullpointer7") {
|
2009-11-09 20:40:58 +01:00
|
|
|
fout << "struct wxLongLong {\n"
|
2010-04-15 20:08:51 +02:00
|
|
|
<< " wxLongLong(int) { }\n"
|
|
|
|
<< " long GetValue() const;\n"
|
|
|
|
<< "};\n";
|
2009-11-09 20:36:13 +01:00
|
|
|
}
|
2009-11-09 20:40:58 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2009-11-07 18:04:45 +01:00
|
|
|
std::string::size_type pos = line.find("\"");
|
2010-04-02 07:30:58 +02:00
|
|
|
if (pos == std::string::npos)
|
2009-11-07 18:04:45 +01:00
|
|
|
break;
|
|
|
|
line.erase(0, pos + 1);
|
|
|
|
|
|
|
|
pos = line.rfind("\"");
|
2010-04-02 07:30:58 +02:00
|
|
|
if (pos == std::string::npos)
|
2009-11-07 18:04:45 +01:00
|
|
|
break;
|
|
|
|
const bool lastline(line.find(");", pos) != std::string::npos);
|
|
|
|
line.erase(pos);
|
|
|
|
|
|
|
|
pos = 0;
|
2011-10-13 20:53:06 +02:00
|
|
|
while ((pos = line.find("\\", pos)) != std::string::npos) {
|
2009-11-07 18:04:45 +01:00
|
|
|
line.erase(pos, 1);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (line[pos] == 'n')
|
2009-11-07 18:04:45 +01:00
|
|
|
line.erase(pos, 1);
|
|
|
|
else
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
fout << line << std::endl;
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (lastline)
|
2009-11-07 18:04:45 +01:00
|
|
|
break;
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (std::getline(f, line));
|
2009-11-07 18:04:45 +01:00
|
|
|
fout << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|