forked from qt-creator/qt-creator
Use const names.
This commit is contained in:
@@ -477,7 +477,7 @@ protected:
|
||||
|
||||
class FindFunctionDefinitions: protected SymbolVisitor
|
||||
{
|
||||
Name *_declarationName;
|
||||
const Name *_declarationName;
|
||||
QList<Function *> *_functions;
|
||||
|
||||
public:
|
||||
@@ -486,7 +486,7 @@ public:
|
||||
_functions(0)
|
||||
{ }
|
||||
|
||||
void operator()(Name *declarationName, Scope *globals,
|
||||
void operator()(const Name *declarationName, Scope *globals,
|
||||
QList<Function *> *functions)
|
||||
{
|
||||
_declarationName = declarationName;
|
||||
@@ -502,8 +502,8 @@ protected:
|
||||
|
||||
virtual bool visit(Function *function)
|
||||
{
|
||||
Name *name = function->name();
|
||||
if (QualifiedNameId *q = name->asQualifiedNameId())
|
||||
const Name *name = function->name();
|
||||
if (const QualifiedNameId *q = name->asQualifiedNameId())
|
||||
name = q->unqualifiedNameId();
|
||||
|
||||
if (_declarationName->isEqualTo(name))
|
||||
@@ -515,19 +515,19 @@ protected:
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
static QualifiedNameId *qualifiedNameIdForSymbol(Symbol *s, const LookupContext &context)
|
||||
static const QualifiedNameId *qualifiedNameIdForSymbol(Symbol *s, const LookupContext &context)
|
||||
{
|
||||
Name *symbolName = s->name();
|
||||
const Name *symbolName = s->name();
|
||||
if (! symbolName)
|
||||
return 0; // nothing to do.
|
||||
|
||||
QVector<Name *> names;
|
||||
QVector<const Name *> names;
|
||||
|
||||
for (Scope *scope = s->scope(); scope; scope = scope->enclosingScope()) {
|
||||
if (scope->isClassScope() || scope->isNamespaceScope()) {
|
||||
if (scope->owner() && scope->owner()->name()) {
|
||||
Name *ownerName = scope->owner()->name();
|
||||
if (QualifiedNameId *q = ownerName->asQualifiedNameId()) {
|
||||
const Name *ownerName = scope->owner()->name();
|
||||
if (const QualifiedNameId *q = ownerName->asQualifiedNameId()) {
|
||||
for (unsigned i = 0; i < q->nameCount(); ++i) {
|
||||
names.prepend(q->nameAt(i));
|
||||
}
|
||||
@@ -538,7 +538,7 @@ static QualifiedNameId *qualifiedNameIdForSymbol(Symbol *s, const LookupContext
|
||||
}
|
||||
}
|
||||
|
||||
if (QualifiedNameId *q = symbolName->asQualifiedNameId()) {
|
||||
if (const QualifiedNameId *q = symbolName->asQualifiedNameId()) {
|
||||
for (unsigned i = 0; i < q->nameCount(); ++i) {
|
||||
names.append(q->nameAt(i));
|
||||
}
|
||||
@@ -1021,27 +1021,28 @@ void CPPEditor::updateUsesNow()
|
||||
semanticRehighlight();
|
||||
}
|
||||
|
||||
static bool isCompatible(Name *name, Name *otherName)
|
||||
static bool isCompatible(const Name *name, const Name *otherName)
|
||||
{
|
||||
if (NameId *nameId = name->asNameId()) {
|
||||
if (TemplateNameId *otherTemplId = otherName->asTemplateNameId())
|
||||
if (const NameId *nameId = name->asNameId()) {
|
||||
if (const TemplateNameId *otherTemplId = otherName->asTemplateNameId())
|
||||
return nameId->identifier()->isEqualTo(otherTemplId->identifier());
|
||||
} else if (TemplateNameId *templId = name->asTemplateNameId()) {
|
||||
if (NameId *otherNameId = otherName->asNameId())
|
||||
} else if (const TemplateNameId *templId = name->asTemplateNameId()) {
|
||||
if (const NameId *otherNameId = otherName->asNameId())
|
||||
return templId->identifier()->isEqualTo(otherNameId->identifier());
|
||||
}
|
||||
|
||||
return name->isEqualTo(otherName);
|
||||
}
|
||||
|
||||
static bool isCompatible(Function *definition, Symbol *declaration, QualifiedNameId *declarationName)
|
||||
static bool isCompatible(Function *definition, Symbol *declaration,
|
||||
const QualifiedNameId *declarationName)
|
||||
{
|
||||
Function *declTy = declaration->type()->asFunctionType();
|
||||
if (! declTy)
|
||||
return false;
|
||||
|
||||
Name *definitionName = definition->name();
|
||||
if (QualifiedNameId *q = definitionName->asQualifiedNameId()) {
|
||||
const Name *definitionName = definition->name();
|
||||
if (const QualifiedNameId *q = definitionName->asQualifiedNameId()) {
|
||||
if (! isCompatible(q->unqualifiedNameId(), declaration->name()))
|
||||
return false;
|
||||
else if (q->nameCount() > declarationName->nameCount())
|
||||
@@ -1061,8 +1062,8 @@ static bool isCompatible(Function *definition, Symbol *declaration, QualifiedNam
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i != q->nameCount(); ++i) {
|
||||
Name *n = q->nameAt(q->nameCount() - i - 1);
|
||||
Name *m = declarationName->nameAt(declarationName->nameCount() - i - 1);
|
||||
const Name *n = q->nameAt(q->nameCount() - i - 1);
|
||||
const Name *m = declarationName->nameAt(declarationName->nameCount() - i - 1);
|
||||
if (! isCompatible(n, m))
|
||||
return false;
|
||||
}
|
||||
@@ -1105,7 +1106,7 @@ void CPPEditor::switchDeclarationDefinition()
|
||||
QList<LookupItem> resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol);
|
||||
const LookupContext &context = typeOfExpression.lookupContext();
|
||||
|
||||
QualifiedNameId *q = qualifiedNameIdForSymbol(f, context);
|
||||
const QualifiedNameId *q = qualifiedNameIdForSymbol(f, context);
|
||||
QList<Symbol *> symbols = context.resolve(q);
|
||||
|
||||
Symbol *declaration = 0;
|
||||
@@ -1278,11 +1279,11 @@ Symbol *CPPEditor::findDefinition(Symbol *symbol)
|
||||
if (! funTy)
|
||||
return 0; // symbol does not have function type.
|
||||
|
||||
Name *name = symbol->name();
|
||||
const Name *name = symbol->name();
|
||||
if (! name)
|
||||
return 0; // skip anonymous functions!
|
||||
|
||||
if (QualifiedNameId *q = name->asQualifiedNameId())
|
||||
if (const QualifiedNameId *q = name->asQualifiedNameId())
|
||||
name = q->unqualifiedNameId();
|
||||
|
||||
// map from file names to function definitions.
|
||||
|
||||
@@ -138,7 +138,7 @@ void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint
|
||||
}
|
||||
}
|
||||
|
||||
static QString buildHelpId(Symbol *symbol, Name *name)
|
||||
static QString buildHelpId(Symbol *symbol, const Name *name)
|
||||
{
|
||||
Scope *scope = 0;
|
||||
|
||||
@@ -161,13 +161,13 @@ static QString buildHelpId(Symbol *symbol, Name *name)
|
||||
Symbol *owner = scope->owner();
|
||||
|
||||
if (owner && owner->name() && ! scope->isEnumScope()) {
|
||||
Name *name = owner->name();
|
||||
const Name *name = owner->name();
|
||||
const Identifier *id = 0;
|
||||
|
||||
if (NameId *nameId = name->asNameId())
|
||||
if (const NameId *nameId = name->asNameId())
|
||||
id = nameId->identifier();
|
||||
|
||||
else if (TemplateNameId *nameId = name->asTemplateNameId())
|
||||
else if (const TemplateNameId *nameId = name->asTemplateNameId())
|
||||
id = nameId->identifier();
|
||||
|
||||
if (id)
|
||||
@@ -182,7 +182,7 @@ static QString buildHelpId(Symbol *symbol, Name *name)
|
||||
static FullySpecifiedType resolve(const FullySpecifiedType &ty,
|
||||
const LookupContext &context,
|
||||
Symbol **resolvedSymbol,
|
||||
Name **resolvedName)
|
||||
const Name **resolvedName)
|
||||
{
|
||||
Control *control = context.control();
|
||||
|
||||
@@ -334,7 +334,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
||||
Symbol *lookupSymbol = result.lastVisibleSymbol(); // lookup symbol
|
||||
|
||||
Symbol *resolvedSymbol = lookupSymbol;
|
||||
Name *resolvedName = lookupSymbol ? lookupSymbol->name() : 0;
|
||||
const Name *resolvedName = lookupSymbol ? lookupSymbol->name() : 0;
|
||||
firstType = resolve(firstType, typeOfExpression.lookupContext(),
|
||||
&resolvedSymbol, &resolvedName);
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ protected:
|
||||
return previousItem;
|
||||
}
|
||||
|
||||
TextEditor::CompletionItem newCompletionItem(Name *name)
|
||||
TextEditor::CompletionItem newCompletionItem(const Name *name)
|
||||
{
|
||||
TextEditor::CompletionItem item(_collector);
|
||||
item.text = overview.prettyName(name);
|
||||
@@ -200,25 +200,25 @@ protected:
|
||||
return item;
|
||||
}
|
||||
|
||||
virtual void visit(NameId *name)
|
||||
virtual void visit(const NameId *name)
|
||||
{ _item = newCompletionItem(name); }
|
||||
|
||||
virtual void visit(TemplateNameId *name)
|
||||
virtual void visit(const TemplateNameId *name)
|
||||
{
|
||||
_item = newCompletionItem(name);
|
||||
_item.text = QLatin1String(name->identifier()->chars());
|
||||
}
|
||||
|
||||
virtual void visit(DestructorNameId *name)
|
||||
virtual void visit(const DestructorNameId *name)
|
||||
{ _item = newCompletionItem(name); }
|
||||
|
||||
virtual void visit(OperatorNameId *name)
|
||||
virtual void visit(const OperatorNameId *name)
|
||||
{ _item = newCompletionItem(name); }
|
||||
|
||||
virtual void visit(ConversionNameId *name)
|
||||
virtual void visit(const ConversionNameId *name)
|
||||
{ _item = newCompletionItem(name); }
|
||||
|
||||
virtual void visit(QualifiedNameId *name)
|
||||
virtual void visit(const QualifiedNameId *name)
|
||||
{ _item = newCompletionItem(name->unqualifiedNameId()); }
|
||||
};
|
||||
|
||||
@@ -890,13 +890,13 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r
|
||||
FullySpecifiedType exprTy = result.type().simplified();
|
||||
|
||||
if (Class *klass = exprTy->asClassType()) {
|
||||
Name *className = klass->name();
|
||||
const Name *className = klass->name();
|
||||
if (! className)
|
||||
continue; // nothing to do for anonymoous classes.
|
||||
|
||||
for (unsigned i = 0; i < klass->memberCount(); ++i) {
|
||||
Symbol *member = klass->memberAt(i);
|
||||
Name *memberName = member->name();
|
||||
const Name *memberName = member->name();
|
||||
|
||||
if (! memberName)
|
||||
continue; // skip anonymous member.
|
||||
@@ -945,7 +945,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r
|
||||
if (functions.isEmpty()) {
|
||||
ResolveExpression resolveExpression(context);
|
||||
ResolveClass resolveClass;
|
||||
Name *functionCallOp = context.control()->operatorNameId(OperatorNameId::FunctionCallOp);
|
||||
const Name *functionCallOp = context.control()->operatorNameId(OperatorNameId::FunctionCallOp);
|
||||
|
||||
foreach (const LookupItem &result, results) {
|
||||
FullySpecifiedType ty = result.type().simplified();
|
||||
@@ -1092,7 +1092,7 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults,
|
||||
classObjectCandidates.append(klass);
|
||||
|
||||
else if (NamedType *namedTy = ty->asNamedType()) {
|
||||
Name *className = namedTy->name();
|
||||
const Name *className = namedTy->name();
|
||||
const QList<Symbol *> classes = resolveClass(className, r, context);
|
||||
|
||||
foreach (Symbol *c, classes) {
|
||||
|
||||
@@ -95,8 +95,8 @@ bool SearchSymbols::visit(Function *symbol)
|
||||
return false;
|
||||
|
||||
QString extraScope;
|
||||
if (Name *name = symbol->name()) {
|
||||
if (QualifiedNameId *nameId = name->asQualifiedNameId()) {
|
||||
if (const Name *name = symbol->name()) {
|
||||
if (const QualifiedNameId *nameId = name->asQualifiedNameId()) {
|
||||
if (nameId->nameCount() > 1) {
|
||||
extraScope = overview.prettyName(nameId->nameAt(nameId->nameCount() - 2));
|
||||
}
|
||||
|
||||
@@ -251,8 +251,8 @@ static bool isCompatible(const Function *definition, const Symbol *declaration,
|
||||
if (! declTy)
|
||||
return false;
|
||||
|
||||
Name *definitionName = definition->name();
|
||||
if (QualifiedNameId *q = definitionName->asQualifiedNameId()) {
|
||||
const Name *definitionName = definition->name();
|
||||
if (const QualifiedNameId *q = definitionName->asQualifiedNameId()) {
|
||||
if (! isCompatible(q->unqualifiedNameId(), declaration->name()))
|
||||
return false;
|
||||
else if (q->nameCount() > declarationName->nameCount())
|
||||
@@ -272,8 +272,8 @@ static bool isCompatible(const Function *definition, const Symbol *declaration,
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i != q->nameCount(); ++i) {
|
||||
Name *n = q->nameAt(q->nameCount() - i - 1);
|
||||
Name *m = declarationName->nameAt(declarationName->nameCount() - i - 1);
|
||||
const Name *n = q->nameAt(q->nameCount() - i - 1);
|
||||
const Name *m = declarationName->nameAt(declarationName->nameCount() - i - 1);
|
||||
if (! isCompatible(n, m))
|
||||
return false;
|
||||
}
|
||||
@@ -291,13 +291,13 @@ static Document::Ptr findDefinition(const Function *functionDeclaration, int *li
|
||||
if (!cppModelManager)
|
||||
return Document::Ptr();
|
||||
|
||||
QVector<Name *> qualifiedName;
|
||||
QVector<const Name *> qualifiedName;
|
||||
Scope *scope = functionDeclaration->scope();
|
||||
for (; scope; scope = scope->enclosingScope()) {
|
||||
if (scope->isClassScope() || scope->isNamespaceScope()) {
|
||||
if (scope->owner() && scope->owner()->name()) {
|
||||
Name *scopeOwnerName = scope->owner()->name();
|
||||
if (QualifiedNameId *q = scopeOwnerName->asQualifiedNameId()) {
|
||||
const Name *scopeOwnerName = scope->owner()->name();
|
||||
if (const QualifiedNameId *q = scopeOwnerName->asQualifiedNameId()) {
|
||||
for (unsigned i = 0; i < q->nameCount(); ++i) {
|
||||
qualifiedName.prepend(q->nameAt(i));
|
||||
|
||||
@@ -312,7 +312,7 @@ static Document::Ptr findDefinition(const Function *functionDeclaration, int *li
|
||||
qualifiedName.append(functionDeclaration->name());
|
||||
|
||||
Control control;
|
||||
QualifiedNameId *q = control.qualifiedNameId(&qualifiedName[0], qualifiedName.size());
|
||||
const QualifiedNameId *q = control.qualifiedNameId(&qualifiedName[0], qualifiedName.size());
|
||||
LookupContext context(&control);
|
||||
const Snapshot documents = cppModelManager->snapshot();
|
||||
foreach (Document::Ptr doc, documents) {
|
||||
@@ -321,13 +321,13 @@ static Document::Ptr findDefinition(const Function *functionDeclaration, int *li
|
||||
visibleScopes = context.expand(visibleScopes);
|
||||
foreach (Scope *visibleScope, visibleScopes) {
|
||||
Symbol *symbol = 0;
|
||||
if (NameId *nameId = q->unqualifiedNameId()->asNameId())
|
||||
if (const NameId *nameId = q->unqualifiedNameId()->asNameId())
|
||||
symbol = visibleScope->lookat(nameId->identifier());
|
||||
else if (DestructorNameId *dtorId = q->unqualifiedNameId()->asDestructorNameId())
|
||||
else if (const DestructorNameId *dtorId = q->unqualifiedNameId()->asDestructorNameId())
|
||||
symbol = visibleScope->lookat(dtorId->identifier());
|
||||
else if (TemplateNameId *templNameId = q->unqualifiedNameId()->asTemplateNameId())
|
||||
else if (const TemplateNameId *templNameId = q->unqualifiedNameId()->asTemplateNameId())
|
||||
symbol = visibleScope->lookat(templNameId->identifier());
|
||||
else if (OperatorNameId *opId = q->unqualifiedNameId()->asOperatorNameId())
|
||||
else if (const OperatorNameId *opId = q->unqualifiedNameId()->asOperatorNameId())
|
||||
symbol = visibleScope->lookat(opId->kind());
|
||||
// ### cast operators
|
||||
for (; symbol; symbol = symbol->next()) {
|
||||
|
||||
Reference in New Issue
Block a user