summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-10-21 14:56:42 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-10-21 14:56:42 +0200
commitf4b95586c534d2be2103f5e20d24e8a01b33b723 (patch)
tree0be4864a1358e19b9c8a076f1818a106e1b35475
parent1253c55d5609a96a8a0318ac102029f618578d08 (diff)
downloadqt-creator-f4b95586c534d2be2103f5e20d24e8a01b33b723.tar.gz
Removed obsoleted code.
-rw-r--r--tests/manual/cplusplus/main.cpp192
-rwxr-xr-xtests/manual/cplusplus/test-pretty-printer3
-rwxr-xr-xtests/manual/cplusplus/test-rewriter3
3 files changed, 4 insertions, 194 deletions
diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp
index cc69cb1681..1fcf76ce18 100644
--- a/tests/manual/cplusplus/main.cpp
+++ b/tests/manual/cplusplus/main.cpp
@@ -33,7 +33,6 @@
#include <Scope.h>
#include <Semantic.h>
#include <TranslationUnit.h>
-#include <PrettyPrinter.h>
#include <Literals.h>
#include <Symbols.h>
#include <Names.h>
@@ -52,171 +51,7 @@
#include <iostream>
#include <sstream>
-CPLUSPLUS_USE_NAMESPACE
-
-class Rewrite
-{
- QMultiMap<unsigned, QByteArray> _insertBefore;
- QMultiMap<unsigned, QByteArray> _insertAfter;
- QSet<unsigned> _removed;
-
-public:
- void remove(unsigned index)
- { remove(index, index + 1); }
-
- void remove(unsigned first, unsigned last)
- {
- Q_ASSERT(first < last);
-
- for (; first != last; ++first)
- _removed.insert(first);
- }
-
- void insertTextBefore(unsigned index, const QByteArray &text)
- { _insertBefore.insert(index, text); }
-
- void insertTextAfter(unsigned index, const QByteArray &text)
- { _insertAfter.insert(index, text); }
-
- void rewrite(const TranslationUnit *unit,
- const QByteArray &contents,
- QByteArray *out)
- {
- _source = contents;
- const char *source = contents.constData();
- unsigned previousTokenEndPosition = 0;
- for (unsigned i = 0; i < unit->tokenCount(); ++i) {
- const Token &tk = unit->tokenAt(i);
-
- if (previousTokenEndPosition != tk.begin()) {
- Q_ASSERT(previousTokenEndPosition < tk.begin());
- out->append(source + previousTokenEndPosition,
- tk.begin() - previousTokenEndPosition);
- }
-
- QMultiMap<unsigned, QByteArray>::const_iterator it;
-
- it = _insertBefore.constFind(i);
- for (; it != _insertBefore.constEnd() && it.key() == i; ++it) {
- out->append(it.value());
- }
-
- if (! _removed.contains(i))
- out->append(source + tk.begin(), tk.f.length);
-
- it = _insertAfter.constFind(i);
- for (; it != _insertAfter.constEnd() && it.key() == i; ++it) {
- out->append(it.value());
- }
-
- previousTokenEndPosition = tk.end();
- }
- }
-
-protected:
- QByteArray _source;
-};
-
-class SimpleRefactor: protected ASTVisitor, Rewrite {
-public:
- SimpleRefactor(Control *control)
- : ASTVisitor(control)
- { }
-
- void operator()(const TranslationUnit *unit,
- const QByteArray &source,
- QByteArray *out)
- {
- accept(unit->ast());
- rewrite(unit, source, out);
- }
-
-protected:
- bool isEnumOrTypedefEnum(SpecifierAST *spec) {
- if (! spec)
- return false;
- if (SimpleSpecifierAST *simpleSpec = spec->asSimpleSpecifier()) {
- if (tokenKind(simpleSpec->specifier_token) == T_TYPEDEF)
- return isEnumOrTypedefEnum(spec->next);
- }
- return spec->asEnumSpecifier() != 0;
- }
- virtual bool visit(SimpleDeclarationAST *ast) {
- if (isEnumOrTypedefEnum(ast->decl_specifier_seq)) {
- //remove(ast->firstToken(), ast->lastToken());
- insertTextBefore(ast->firstToken(), "/* #REF# removed ");
- insertTextAfter(ast->lastToken() - 1, "*/");
- return true;
- }
- return true;
- }
-
- virtual bool visit(AccessDeclarationAST *ast)
- {
- if (tokenKind(ast->access_specifier_token) == T_PRIVATE) {
- // change visibility from `private' to `public'.
- remove(ast->access_specifier_token);
- insertTextAfter(ast->access_specifier_token, "public /* #REF# private->public */");
- }
- return true;
- }
-
- virtual bool visit(FunctionDefinitionAST *ast)
- {
- bool isInline = false;
- for (SpecifierAST *spec = ast->decl_specifier_seq; spec; spec = spec->next) {
- if (SimpleSpecifierAST *simpleSpec = spec->asSimpleSpecifier()) {
- if (tokenKind(simpleSpec->specifier_token) == T_INLINE) {
- isInline = true;
- break;
- }
- }
- }
-
- // force the `inline' specifier.
- if (! isInline)
- insertTextBefore(ast->firstToken(), "inline /* #REF# made inline */ ");
-
- return true;
- }
-
- virtual bool visit(ClassSpecifierAST *ast)
- {
- // export/import the class using the macro MY_EXPORT.
- if (ast->name)
- insertTextBefore(ast->name->firstToken(), "MY_EXPORT ");
-
- // add QObject to the base clause.
- if (ast->colon_token)
- insertTextAfter(ast->colon_token, " public QObject,");
- else if (ast->lbrace_token)
- insertTextBefore(ast->lbrace_token, ": public QObject ");
-
- // mark the class as Q_OBJECT.
- if (ast->lbrace_token)
- insertTextAfter(ast->lbrace_token, " Q_OBJECT\n");
-
- for (DeclarationListAST *it = ast->member_specifiers; it; it = it->next) {
- accept(it->declaration);
- }
-
- return false;
- }
-
- virtual bool visit(CppCastExpressionAST *ast)
- {
- // Replace the C++ cast expression (e.g. static_cast<foo>(a)) with
- // the one generated by the pretty printer.
- std::ostringstream o;
- PrettyPrinter pp(control(), o);
- pp(ast, _source);
- remove(ast->firstToken(), ast->lastToken());
- const std::string str = o.str();
- insertTextBefore(ast->firstToken(), str.c_str());
- insertTextBefore(ast->firstToken(), "/* #REF# beautiful cast */ ");
- return false;
- }
-};
+using namespace CPlusPlus;
class CloneCG: protected ASTVisitor
{
@@ -513,15 +348,8 @@ int main(int argc, char *argv[])
const QString appName = args.first();
args.removeFirst();
- bool test_rewriter = false;
- bool test_pretty_printer = false;
-
- foreach (QString arg, args) {
- if (arg == QLatin1String("--test-rewriter"))
- test_rewriter = true;
- else if (arg == QLatin1String("--test-pretty-printer"))
- test_pretty_printer = true;
- else if (arg == QLatin1String("--help")) {
+ foreach (const QString &arg, args) {
+ if (arg == QLatin1String("--help")) {
const QFileInfo appInfo(appName);
const QByteArray appFileName = QFile::encodeName(appInfo.fileName());
@@ -530,6 +358,7 @@ int main(int argc, char *argv[])
" --test-rewriter Test the tree rewriter\n"
" --test-pretty-printer Test the pretty printer\n",
appFileName.constData());
+
return EXIT_SUCCESS;
}
}
@@ -558,18 +387,5 @@ int main(int argc, char *argv[])
sem.check(decl->declaration, globalNamespace->members());
}
- // test the rewriter
- if (test_rewriter) {
- QByteArray out;
- SimpleRefactor refactor(&control);
- refactor(&unit, source, &out);
- printf("%s\n", out.constData());
- } else if (test_pretty_printer) {
- MemoryPool pool2;
- TranslationUnitAST *other = unit.ast()->clone(&pool2)->asTranslationUnit();
- PrettyPrinter pp(&control, std::cout);
- pp(other, source);
- }
-
return EXIT_SUCCESS;
}
diff --git a/tests/manual/cplusplus/test-pretty-printer b/tests/manual/cplusplus/test-pretty-printer
deleted file mode 100755
index 7403721300..0000000000
--- a/tests/manual/cplusplus/test-pretty-printer
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-me=$(dirname $0)
-${CPP-gcc} -xc++ -E -include $me/conf.c++ $* | $me/cplusplus0 --test-pretty-printer
diff --git a/tests/manual/cplusplus/test-rewriter b/tests/manual/cplusplus/test-rewriter
deleted file mode 100755
index c0494257c8..0000000000
--- a/tests/manual/cplusplus/test-rewriter
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-me=$(dirname $0)
-${CPP-gcc} -xc++ -E -include $me/conf.c++ $* | $me/cplusplus0 --test-rewriter