From 38d1b064e8b846504a8b334a49c8590f08715509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 Dec 2012 08:32:43 +0100 Subject: [PATCH] Symbol database: Add support for unnamed array arguments to functions (#4444) --- lib/symboldatabase.cpp | 12 ++++++++++-- test/testsymboldatabase.cpp | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 6b147fa32..eb865f279 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -969,8 +969,16 @@ void Variable::evaluate() setFlag(fIsClass, !_start->isStandardType() && !isPointer() && !isReference()); if (_access == Argument) { tok = _name; - if (!tok) - tok = _end; // Argument without name + if (!tok) { + // Argument without name + tok = _end; + // back up to start of array dimensions + while (tok && tok->str() == "]") + tok = tok->link()->previous(); + // add array dimensions if present + if (tok->next()->str() == "[") + setFlag(fIsArray, arrayDimensions(_dimensions, tok->next())); + } if (!tok) return; tok = tok->next(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a468ea325..35c200201 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -119,6 +119,7 @@ private: TEST_CASE(functionArgs1); TEST_CASE(functionArgs2); TEST_CASE(functionArgs3); + TEST_CASE(functionArgs4); TEST_CASE(namespaces1); TEST_CASE(namespaces2); @@ -908,6 +909,23 @@ private: ASSERT_EQUALS("i", a->nameToken()->str()); } + void functionArgs4() { + GET_SYMBOL_DB("void f1(char [10], struct foo [10]);"); + ASSERT_EQUALS(true, db->scopeList.front().functionList.size() == 1UL); + const Function *func = &db->scopeList.front().functionList.front(); + ASSERT_EQUALS(true, func && func->argumentList.size() == 2UL); + if (func && func->argumentList.size() == 2UL) { + const Variable *first = &func->argumentList.front(); + ASSERT_EQUALS(0UL, first->name().size()); + ASSERT_EQUALS(1UL, first->dimensions().size()); + ASSERT_EQUALS(10UL, first->dimension(0)); + const Variable *second = &func->argumentList.back(); + ASSERT_EQUALS(0UL, second->name().size()); + ASSERT_EQUALS(1UL, second->dimensions().size()); + ASSERT_EQUALS(10UL, second->dimension(0)); + } + } + void namespaces1() { GET_SYMBOL_DB("namespace fred {\n" " namespace barney {\n"