Skip to content

Commit bc30f50

Browse files
committed
Merge pull request #732 from Dmitry-Me/extractDuplicateCode
Extract duplicate code
2 parents 4a3c61f + 166e2a2 commit bc30f50

1 file changed

Lines changed: 25 additions & 36 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,29 @@ void SymbolDatabase::printXml(std::ostream &out) const
25282528

25292529
//---------------------------------------------------------------------------
25302530

2531+
static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase* symbolDatabase, const Scope* scope, const Token* typeTok)
2532+
{
2533+
const Type* argType = symbolDatabase->findVariableType(scope, typeTok);
2534+
if (argType)
2535+
return argType;
2536+
2537+
// look for variable type in any using namespace in this scope or above
2538+
while (scope) {
2539+
for (std::list<Scope::UsingInfo>::const_iterator ui = scope->usingList.begin();
2540+
ui != scope->usingList.end(); ++ui) {
2541+
if (ui->scope) {
2542+
argType = symbolDatabase->findVariableType(ui->scope, typeTok);
2543+
if (argType)
2544+
return argType;
2545+
}
2546+
}
2547+
scope = scope->nestedIn;
2548+
}
2549+
return nullptr;
2550+
}
2551+
2552+
//---------------------------------------------------------------------------
2553+
25312554
void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope)
25322555
{
25332556
// check for non-empty argument list "( ... )"
@@ -2587,24 +2610,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
25872610

25882611
const ::Type *argType = nullptr;
25892612
if (!typeTok->isStandardType()) {
2590-
argType = symbolDatabase->findVariableType(scope, typeTok);
2591-
if (!argType) {
2592-
// look for variable type in any using namespace in this scope or above
2593-
const Scope *currentScope = scope;
2594-
while (currentScope) {
2595-
for (std::list<Scope::UsingInfo>::const_iterator ui = currentScope->usingList.begin();
2596-
ui != currentScope->usingList.end(); ++ui) {
2597-
if (ui->scope) {
2598-
argType = symbolDatabase->findVariableType(ui->scope, typeTok);
2599-
if (argType)
2600-
break;
2601-
}
2602-
}
2603-
if (argType)
2604-
break;
2605-
currentScope = currentScope->nestedIn;
2606-
}
2607-
}
2613+
argType = findVariableTypeIncludingUsedNamespaces(symbolDatabase, scope, typeTok);
26082614
}
26092615

26102616
// skip default values
@@ -2956,24 +2962,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con
29562962
const Type *vType = nullptr;
29572963

29582964
if (typetok) {
2959-
vType = check->findVariableType(this, typetok);
2960-
if (!vType) {
2961-
// look for variable type in any using namespace in this scope or above
2962-
const Scope *parent = this;
2963-
while (parent) {
2964-
for (std::list<Scope::UsingInfo>::const_iterator ui = parent->usingList.begin();
2965-
ui != parent->usingList.end(); ++ui) {
2966-
if (ui->scope) {
2967-
vType = check->findVariableType(ui->scope, typetok);
2968-
if (vType)
2969-
break;
2970-
}
2971-
}
2972-
if (vType)
2973-
break;
2974-
parent = parent->nestedIn;
2975-
}
2976-
}
2965+
vType = findVariableTypeIncludingUsedNamespaces(check, this, typetok);
29772966
}
29782967

29792968
addVariable(vartok, typestart, vartok->previous(), varaccess, vType, this, lib);

0 commit comments

Comments
 (0)