forked from qt-creator/qt-creator
C++: Fix function return type printing.
We used to print T * foo(), but our style suggests T *foo(). Change-Id: Ie3b0ce6b620785ec98aeb394f7955ce959440619 Reviewed-on: http://codereview.qt-project.org/4634 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -289,6 +289,12 @@ void TypePrettyPrinter::visit(ArrayType *type)
|
||||
acceptType(type->elementType());
|
||||
}
|
||||
|
||||
static bool endsWithPtrOrRef(const QString &type)
|
||||
{
|
||||
return type.endsWith(QLatin1Char('*'))
|
||||
|| type.endsWith(QLatin1Char('&'));
|
||||
}
|
||||
|
||||
void TypePrettyPrinter::visit(Function *type)
|
||||
{
|
||||
if (_needsParens) {
|
||||
@@ -309,7 +315,8 @@ void TypePrettyPrinter::visit(Function *type)
|
||||
if (_overview->showReturnTypes()) {
|
||||
const QString returnType = _overview->prettyType(type->returnType());
|
||||
if (!returnType.isEmpty()) {
|
||||
_text.prepend(QLatin1Char(' '));
|
||||
if (!endsWithPtrOrRef(returnType))
|
||||
_text.prepend(QLatin1Char(' '));
|
||||
_text.prepend(returnType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,14 @@ void tst_TypePrettyPrinter::basic_data()
|
||||
// simple functions
|
||||
addRow(ptr(fnTy("foo", voidTy(), intTy())), "void (*foo)(int)", "foo");
|
||||
addRow(ptr(fnTy("foo", voidTy(), ptr(voidTy()))), "void (*foo)(void *)", "foo");
|
||||
addRow(fnTy("foo", voidTy(), intTy()), "void foo(int)", "foo");
|
||||
addRow(fnTy("foo", voidTy(), ptr(voidTy())), "void foo(void *)", "foo");
|
||||
|
||||
// functions with ptr or ref returns
|
||||
addRow(ptr(fnTy("foo", ptr(voidTy()), intTy())), "void *(*foo)(int)", "foo");
|
||||
addRow(ptr(fnTy("foo", ref(voidTy()), ptr(voidTy()))), "void &(*foo)(void *)", "foo");
|
||||
addRow(fnTy("foo", ptr(voidTy()), intTy()), "void *foo(int)", "foo");
|
||||
addRow(fnTy("foo", ref(voidTy()), ptr(voidTy())), "void &foo(void *)", "foo");
|
||||
}
|
||||
|
||||
void tst_TypePrettyPrinter::basic()
|
||||
|
||||
Reference in New Issue
Block a user