Symbol database: Add support for unnamed array arguments to functions (#4444)

This commit is contained in:
Daniel Marjamäki 2012-12-29 08:32:43 +01:00
parent 07d118dee5
commit 38d1b064e8
2 changed files with 28 additions and 2 deletions

View File

@ -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();

View File

@ -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"