summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-05-11 17:00:29 +0200
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-05-11 17:03:51 +0200
commit581dca0ad9b508cc3e44a4c9bb3cff40db0d2b0a (patch)
treecca39152125225c8aac6f564498adcfaeee3ea7b /tests
parentecc2b25ddcdf3567907643df8d1b7a3512a58392 (diff)
downloadqt-creator-581dca0ad9b508cc3e44a4c9bb3cff40db0d2b0a.tar.gz
Rewrote PrettyPrinter to output the document exactly as it was before
This means at the moment the PrettyPrinter isn't doing anything useful, but the idea is that from here we can improve it to adapt the code to a certain style. Reviewed-by: Roberto Raggi
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/cplusplus/main.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp
index 3953256f7c..6395d70e4f 100644
--- a/tests/manual/cplusplus/main.cpp
+++ b/tests/manual/cplusplus/main.cpp
@@ -73,8 +73,9 @@ public:
void rewrite(const TranslationUnit *unit,
const QByteArray &contents,
- QByteArray *out) const
+ QByteArray *out)
{
+ _source = contents;
const char *source = contents.constData();
unsigned previousTokenEndPosition = 0;
for (unsigned i = 0; i < unit->tokenCount(); ++i) {
@@ -104,6 +105,9 @@ public:
previousTokenEndPosition = tk.end();
}
}
+
+protected:
+ QByteArray _source;
};
class SimpleRefactor: protected ASTVisitor, Rewrite {
@@ -192,12 +196,13 @@ protected:
return false;
}
- virtual bool visit(CppCastExpressionAST *ast) {
+ 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);
+ pp(ast, _source);
remove(ast->firstToken(), ast->lastToken());
const std::string str = o.str();
insertTextBefore(ast->firstToken(), str.c_str());
@@ -267,7 +272,7 @@ int main(int argc, char *argv[])
printf("%s\n", out.constData());
} else if (test_pretty_printer) {
PrettyPrinter pp(&control, std::cout);
- pp(unit.ast());
+ pp(unit.ast(), source);
}
return EXIT_SUCCESS;
}