From 636e97c272fb1b75576b059cedba30b2c7dea0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 May 2016 13:15:20 +0200 Subject: [PATCH] ValueType: Improved debug output for nested types --- lib/symboldatabase.cpp | 12 ++++++++++-- lib/valueflow.cpp | 2 +- test/testsymboldatabase.cpp | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 15bfc2206..13a1c1cf2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4416,8 +4416,16 @@ std::string ValueType::str() const ret += " double"; else if (type == LONGDOUBLE) ret += " long double"; - else if (type == NONSTD && typeScope) - ret += ' ' + typeScope->className; + else if (type == NONSTD && typeScope) { + std::string className(typeScope->className); + const Scope *s = typeScope; + while (s->nestedIn && s->nestedIn->type != Scope::eGlobal) { + s = s->nestedIn; + if (s->type == Scope::eClass || s->type == Scope::eStruct || s->type == Scope::eNamespace) + className = s->className + "::" + className; + } + ret += ' ' + className; + } for (unsigned int p = 0; p < pointer; p++) { ret += " *"; if (constness & (2 << p)) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 213a37e3f..a81c80309 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2384,7 +2384,7 @@ const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(const Token *expr) valueFlowConstantFoldAST(expr->astOperand2()); valueFlowSetConstantValue(expr); } - return expr && expr->values.size() == 1U && expr->values.front().isKnown() ? &expr->values.front() : nullptr; + return expr && expr->values.size() == 1U && expr->values.front().isKnown() ? &expr->values.front() : nullptr; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 7a6c8bf97..66719917b 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3222,8 +3222,9 @@ private: ASSERT_EQUALS("signed int", typeOf("int x; a = x++;", "++")); ASSERT_EQUALS("AB *", typeOf("enum AB {A,B}; AB *ab; x=ab+2;", "+")); ASSERT_EQUALS("AB *", typeOf("enum AB {A,B}; enum AB *ab; x=ab+2;", "+")); - ASSERT_EQUALS("AB *", typeOf("struct AB {int A; int B;}; AB ab; x=&ab;", "&")); - ASSERT_EQUALS("AB *", typeOf("struct AB {int A; int B;}; struct AB ab; x=&ab;", "&")); + ASSERT_EQUALS("AB *", typeOf("struct AB {int a; int b;}; AB ab; x=&ab;", "&")); + ASSERT_EQUALS("AB *", typeOf("struct AB {int a; int b;}; struct AB ab; x=&ab;", "&")); + ASSERT_EQUALS("A::BC *", typeOf("namespace A { struct BC { int b; int c; }; }; struct A::BC abc; x=&abc;", "&")); // Unary arithmetic/bit operators ASSERT_EQUALS("signed int", typeOf("int x; a = -x;", "-"));