CppEditor: Support decl/def switch for conversion operators

Fixes: QTCREATORBUG-21168
Change-Id: I515fe146a679e007c96fa8d23f1457dadf07db3c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-11-18 18:04:21 +01:00
parent b0dd6b748f
commit d3fafcde0f
7 changed files with 81 additions and 12 deletions

View File

@@ -579,6 +579,15 @@ const OperatorNameId *Control::findOperatorNameId(OperatorNameId::Kind operatorI
return &*i;
}
const ConversionNameId *Control::findConversionNameId(const FullySpecifiedType &type) const
{
for (const ConversionNameId &id : d->conversionNameIds) {
if (type.match(id.type()))
return &id;
}
return nullptr;
}
const Identifier *Control::findIdentifier(const char *chars, int size) const
{ return d->identifiers.findLiteral(chars, size); }

View File

@@ -186,6 +186,7 @@ public:
const Identifier *cpp11Final() const;
const OperatorNameId *findOperatorNameId(OperatorNameId::Kind operatorId) const;
const ConversionNameId *findConversionNameId(const FullySpecifiedType &type) const;
const Identifier *findIdentifier(const char *chars, int size) const;
const Identifier *identifier(const char *chars, int size);

View File

@@ -71,6 +71,7 @@ public:
Symbol *lookat(const Identifier *id) const;
Symbol *lookat(OperatorNameId::Kind operatorId) const;
Symbol *lookat(const ConversionNameId *convId) const;
private:
/// Returns the hash value for the given Symbol.
@@ -181,6 +182,23 @@ Symbol *SymbolTable::lookat(OperatorNameId::Kind operatorId) const
return symbol;
}
Symbol *SymbolTable::lookat(const ConversionNameId *convId) const
{
if (!_hash)
return nullptr;
Symbol *symbol = _hash[0]; // See Symbol::HashCode
for (; symbol; symbol = symbol->_next) {
if (const Name *identity = symbol->unqualifiedName()) {
if (const ConversionNameId * const id = identity->asConversionNameId()) {
if (id->type().match(convId->type()))
break;
}
}
}
return symbol;
}
void SymbolTable::rehash()
{
_hashSize <<= 1;
@@ -281,6 +299,9 @@ Symbol *Scope::find(const Identifier *id) const
Symbol *Scope::find(OperatorNameId::Kind operatorId) const
{ return _members ? _members->lookat(operatorId) : nullptr; }
Symbol *Scope::find(const ConversionNameId *conv) const
{ return _members ? _members->lookat(conv) : nullptr; }
/// Set the start offset of the scope
int Scope::startOffset() const
{ return _startOffset; }

View File

@@ -55,6 +55,7 @@ public:
Symbol *find(const Identifier *id) const;
Symbol *find(OperatorNameId::Kind operatorId) const;
Symbol *find(const ConversionNameId *conv) const;
/// Set the start offset of the scope
int startOffset() const;