forked from qt-creator/qt-creator
Get rid off QPair<FullySpecifiedType, Symbol *>. Use LookupItem intead.
This commit is contained in:
@@ -269,16 +269,13 @@ void FindUsages::checkExpression(unsigned startToken, unsigned endToken)
|
|||||||
getTokenStartPosition(startToken, &line, &column);
|
getTokenStartPosition(startToken, &line, &column);
|
||||||
Symbol *lastVisibleSymbol = _doc->findSymbolAt(line, column);
|
Symbol *lastVisibleSymbol = _doc->findSymbolAt(line, column);
|
||||||
|
|
||||||
const QList<TypeOfExpression::Result> results =
|
const QList<LookupItem> results = typeofExpression(expression, _doc, lastVisibleSymbol,
|
||||||
typeofExpression(expression, _doc, lastVisibleSymbol,
|
|
||||||
TypeOfExpression::Preprocess);
|
TypeOfExpression::Preprocess);
|
||||||
|
|
||||||
QList<Symbol *> candidates;
|
QList<Symbol *> candidates;
|
||||||
|
|
||||||
foreach (TypeOfExpression::Result r, results) {
|
foreach (const LookupItem &r, results) {
|
||||||
FullySpecifiedType ty = r.first;
|
Symbol *lastVisibleSymbol = r.lastVisibleSymbol();
|
||||||
Symbol *lastVisibleSymbol = r.second;
|
|
||||||
|
|
||||||
candidates.append(lastVisibleSymbol);
|
candidates.append(lastVisibleSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,13 @@
|
|||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
|
uint qHash(const CPlusPlus::LookupItem &key)
|
||||||
|
{
|
||||||
|
const uint h1 = qHash(key.type().type());
|
||||||
|
const uint h2 = qHash(key.lastVisibleSymbol());
|
||||||
|
return ((h1 << 16) | (h1 >> 16)) ^ h2;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
// LookupContext
|
// LookupContext
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@@ -348,8 +355,8 @@ QList<Scope *> LookupContext::buildVisibleScopes()
|
|||||||
return scopes;
|
return scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Scope *> LookupContext::visibleScopes(const QPair<FullySpecifiedType, Symbol *> &result) const
|
QList<Scope *> LookupContext::visibleScopes(const LookupItem &result) const
|
||||||
{ return visibleScopes(result.second); }
|
{ return visibleScopes(result.lastVisibleSymbol()); }
|
||||||
|
|
||||||
QList<Scope *> LookupContext::visibleScopes(Symbol *symbol) const
|
QList<Scope *> LookupContext::visibleScopes(Symbol *symbol) const
|
||||||
{
|
{
|
||||||
@@ -696,14 +703,13 @@ Symbol *LookupContext::canonicalSymbol(const QList<Symbol *> &candidates,
|
|||||||
return canonicalSymbol(candidates.first(), globalNamespaceBinding);
|
return canonicalSymbol(candidates.first(), globalNamespaceBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
Symbol *LookupContext::canonicalSymbol(const QList<QPair<FullySpecifiedType, Symbol *> > &results,
|
Symbol *LookupContext::canonicalSymbol(const QList<LookupItem> &results,
|
||||||
NamespaceBinding *globalNamespaceBinding)
|
NamespaceBinding *globalNamespaceBinding)
|
||||||
{
|
{
|
||||||
QList<Symbol *> candidates;
|
QList<Symbol *> candidates;
|
||||||
QPair<FullySpecifiedType, Symbol *> result;
|
|
||||||
|
|
||||||
foreach (result, results)
|
foreach (const LookupItem &result, results)
|
||||||
candidates.append(result.second); // ### not exacly.
|
candidates.append(result.lastVisibleSymbol()); // ### not exacly.
|
||||||
|
|
||||||
return canonicalSymbol(candidates, globalNamespaceBinding);
|
return canonicalSymbol(candidates, globalNamespaceBinding);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,41 @@
|
|||||||
#define CPLUSPLUS_LOOKUPCONTEXT_H
|
#define CPLUSPLUS_LOOKUPCONTEXT_H
|
||||||
|
|
||||||
#include "CppDocument.h"
|
#include "CppDocument.h"
|
||||||
#include <QPair>
|
#include <FullySpecifiedType.h>
|
||||||
|
|
||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
|
|
||||||
|
class CPLUSPLUS_EXPORT LookupItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LookupItem()
|
||||||
|
: _lastVisibleSymbol(0) {}
|
||||||
|
|
||||||
|
LookupItem(const FullySpecifiedType &type, Symbol *lastVisibleSymbol)
|
||||||
|
: _type(type), _lastVisibleSymbol(lastVisibleSymbol) {}
|
||||||
|
|
||||||
|
FullySpecifiedType type() const { return _type; }
|
||||||
|
void setType(const FullySpecifiedType &type) { _type = type; }
|
||||||
|
|
||||||
|
Symbol *lastVisibleSymbol() const { return _lastVisibleSymbol; }
|
||||||
|
void setLastVisibleSymbol(Symbol *symbol) { _lastVisibleSymbol = symbol; }
|
||||||
|
|
||||||
|
bool operator == (const LookupItem &other) const
|
||||||
|
{
|
||||||
|
if (_type == other._type)
|
||||||
|
return _lastVisibleSymbol == other._lastVisibleSymbol;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator != (const LookupItem &result) const
|
||||||
|
{ return ! operator == (result); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
FullySpecifiedType _type;
|
||||||
|
Symbol *_lastVisibleSymbol;
|
||||||
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT LookupContext
|
class CPLUSPLUS_EXPORT LookupContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -60,7 +91,7 @@ public:
|
|||||||
static Symbol *canonicalSymbol(Symbol *symbol,
|
static Symbol *canonicalSymbol(Symbol *symbol,
|
||||||
NamespaceBinding *globalNamespaceBinding);
|
NamespaceBinding *globalNamespaceBinding);
|
||||||
|
|
||||||
static Symbol *canonicalSymbol(const QList<QPair<FullySpecifiedType, Symbol *> > &candidates,
|
static Symbol *canonicalSymbol(const QList<LookupItem> &candidates,
|
||||||
NamespaceBinding *globalNamespaceBinding);
|
NamespaceBinding *globalNamespaceBinding);
|
||||||
|
|
||||||
QList<Symbol *> resolve(Name *name) const
|
QList<Symbol *> resolve(Name *name) const
|
||||||
@@ -113,7 +144,7 @@ public:
|
|||||||
{ return _visibleScopes; }
|
{ return _visibleScopes; }
|
||||||
|
|
||||||
QList<Scope *> visibleScopes(Symbol *symbol) const;
|
QList<Scope *> visibleScopes(Symbol *symbol) const;
|
||||||
QList<Scope *> visibleScopes(const QPair<FullySpecifiedType, Symbol *> &result) const;
|
QList<Scope *> visibleScopes(const LookupItem &result) const;
|
||||||
|
|
||||||
QList<Scope *> expand(const QList<Scope *> &scopes) const;
|
QList<Scope *> expand(const QList<Scope *> &scopes) const;
|
||||||
|
|
||||||
@@ -199,4 +230,8 @@ private:
|
|||||||
|
|
||||||
} // end of namespace CPlusPlus
|
} // end of namespace CPlusPlus
|
||||||
|
|
||||||
|
|
||||||
|
uint qHash(const CPlusPlus::LookupItem &result);
|
||||||
|
|
||||||
|
|
||||||
#endif // CPLUSPLUS_LOOKUPCONTEXT_H
|
#endif // CPLUSPLUS_LOOKUPCONTEXT_H
|
||||||
|
|||||||
@@ -80,42 +80,42 @@ ResolveExpression::ResolveExpression(const LookupContext &context)
|
|||||||
ResolveExpression::~ResolveExpression()
|
ResolveExpression::~ResolveExpression()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QList<ResolveExpression::Result> ResolveExpression::operator()(ExpressionAST *ast)
|
QList<LookupItem> ResolveExpression::operator()(ExpressionAST *ast)
|
||||||
{
|
{
|
||||||
const QList<Result> previousResults = switchResults(QList<Result>());
|
const QList<LookupItem> previousResults = switchResults(QList<LookupItem>());
|
||||||
accept(ast);
|
accept(ast);
|
||||||
return removeDuplicates(switchResults(previousResults));
|
return removeDuplicates(switchResults(previousResults));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ResolveExpression::Result>
|
QList<LookupItem>
|
||||||
ResolveExpression::switchResults(const QList<ResolveExpression::Result> &results)
|
ResolveExpression::switchResults(const QList<LookupItem> &results)
|
||||||
{
|
{
|
||||||
const QList<Result> previousResults = _results;
|
const QList<LookupItem> previousResults = _results;
|
||||||
_results = results;
|
_results = results;
|
||||||
return previousResults;
|
return previousResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolveExpression::addResults(const QList<Result> &results)
|
void ResolveExpression::addResults(const QList<LookupItem> &results)
|
||||||
{
|
{
|
||||||
foreach (const Result r, results)
|
foreach (const LookupItem r, results)
|
||||||
addResult(r);
|
addResult(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolveExpression::addResult(const FullySpecifiedType &ty, Symbol *symbol)
|
void ResolveExpression::addResult(const FullySpecifiedType &ty, Symbol *symbol)
|
||||||
{ return addResult(Result(ty, symbol)); }
|
{ return addResult(LookupItem(ty, symbol)); }
|
||||||
|
|
||||||
void ResolveExpression::addResult(const Result &r)
|
void ResolveExpression::addResult(const LookupItem &r)
|
||||||
{
|
{
|
||||||
Result p = r;
|
LookupItem p = r;
|
||||||
|
|
||||||
if (! p.second)
|
if (! p.lastVisibleSymbol())
|
||||||
p.second = _context.symbol();
|
p.setLastVisibleSymbol(_context.symbol());
|
||||||
|
|
||||||
if (! _results.contains(p))
|
if (! _results.contains(p))
|
||||||
_results.append(p);
|
_results.append(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Scope *> ResolveExpression::visibleScopes(const Result &result) const
|
QList<Scope *> ResolveExpression::visibleScopes(const LookupItem &result) const
|
||||||
{ return _context.visibleScopes(result); }
|
{ return _context.visibleScopes(result); }
|
||||||
|
|
||||||
bool ResolveExpression::visit(BinaryExpressionAST *ast)
|
bool ResolveExpression::visit(BinaryExpressionAST *ast)
|
||||||
@@ -323,18 +323,20 @@ bool ResolveExpression::visit(UnaryExpressionAST *ast)
|
|||||||
accept(ast->expression);
|
accept(ast->expression);
|
||||||
unsigned unaryOp = tokenKind(ast->unary_op_token);
|
unsigned unaryOp = tokenKind(ast->unary_op_token);
|
||||||
if (unaryOp == T_AMPER) {
|
if (unaryOp == T_AMPER) {
|
||||||
QMutableListIterator<Result > it(_results);
|
QMutableListIterator<LookupItem > it(_results);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Result p = it.next();
|
LookupItem p = it.next();
|
||||||
p.first.setType(control()->pointerType(p.first));
|
FullySpecifiedType ty = p.type();
|
||||||
|
ty.setType(control()->pointerType(ty));
|
||||||
|
p.setType(ty);
|
||||||
it.setValue(p);
|
it.setValue(p);
|
||||||
}
|
}
|
||||||
} else if (unaryOp == T_STAR) {
|
} else if (unaryOp == T_STAR) {
|
||||||
QMutableListIterator<Result > it(_results);
|
QMutableListIterator<LookupItem > it(_results);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Result p = it.next();
|
LookupItem p = it.next();
|
||||||
if (PointerType *ptrTy = p.first->asPointerType()) {
|
if (PointerType *ptrTy = p.type()->asPointerType()) {
|
||||||
p.first = ptrTy->elementType();
|
p.setType(ptrTy->elementType());
|
||||||
it.setValue(p);
|
it.setValue(p);
|
||||||
} else {
|
} else {
|
||||||
it.remove();
|
it.remove();
|
||||||
@@ -359,7 +361,7 @@ bool ResolveExpression::visit(QualifiedNameAST *ast)
|
|||||||
foreach (Symbol *symbol, symbols) {
|
foreach (Symbol *symbol, symbols) {
|
||||||
if (symbol->isTypedef()) {
|
if (symbol->isTypedef()) {
|
||||||
if (NamedType *namedTy = symbol->type()->asNamedType()) {
|
if (NamedType *namedTy = symbol->type()->asNamedType()) {
|
||||||
const Result r(namedTy, symbol);
|
const LookupItem r(namedTy, symbol);
|
||||||
const QList<Symbol *> resolvedClasses =
|
const QList<Symbol *> resolvedClasses =
|
||||||
resolveClass(namedTy->name(), r, _context);
|
resolveClass(namedTy->name(), r, _context);
|
||||||
if (resolvedClasses.count()) {
|
if (resolvedClasses.count()) {
|
||||||
@@ -437,7 +439,7 @@ bool ResolveExpression::visit(CallAST *ast)
|
|||||||
{
|
{
|
||||||
ResolveClass resolveClass;
|
ResolveClass resolveClass;
|
||||||
|
|
||||||
const QList<Result> baseResults = _results;
|
const QList<LookupItem> baseResults = _results;
|
||||||
_results.clear();
|
_results.clear();
|
||||||
|
|
||||||
// Compute the types of the actual arguments.
|
// Compute the types of the actual arguments.
|
||||||
@@ -451,18 +453,18 @@ bool ResolveExpression::visit(CallAST *ast)
|
|||||||
|
|
||||||
Name *functionCallOp = control()->operatorNameId(OperatorNameId::FunctionCallOp);
|
Name *functionCallOp = control()->operatorNameId(OperatorNameId::FunctionCallOp);
|
||||||
|
|
||||||
foreach (const Result &result, baseResults) {
|
foreach (const LookupItem &result, baseResults) {
|
||||||
FullySpecifiedType ty = result.first.simplified();
|
FullySpecifiedType ty = result.type().simplified();
|
||||||
Symbol *lastVisibleSymbol = result.second;
|
Symbol *lastVisibleSymbol = result.lastVisibleSymbol();
|
||||||
|
|
||||||
if (NamedType *namedTy = ty->asNamedType()) {
|
if (NamedType *namedTy = ty->asNamedType()) {
|
||||||
const QList<Symbol *> classObjectCandidates = resolveClass(namedTy->name(), result, _context);
|
const QList<Symbol *> classObjectCandidates = resolveClass(namedTy->name(), result, _context);
|
||||||
|
|
||||||
foreach (Symbol *classObject, classObjectCandidates) {
|
foreach (Symbol *classObject, classObjectCandidates) {
|
||||||
const QList<Result> overloads = resolveMember(functionCallOp, classObject->asClass(), namedTy->name());
|
const QList<LookupItem> overloads = resolveMember(functionCallOp, classObject->asClass(), namedTy->name());
|
||||||
|
|
||||||
foreach (const Result &o, overloads) {
|
foreach (const LookupItem &o, overloads) {
|
||||||
FullySpecifiedType overloadTy = o.first.simplified();
|
FullySpecifiedType overloadTy = o.type().simplified();
|
||||||
|
|
||||||
if (Function *funTy = overloadTy->asFunctionType()) {
|
if (Function *funTy = overloadTy->asFunctionType()) {
|
||||||
if (maybeValidPrototype(funTy, actualArgumentCount))
|
if (maybeValidPrototype(funTy, actualArgumentCount))
|
||||||
@@ -487,17 +489,17 @@ bool ResolveExpression::visit(CallAST *ast)
|
|||||||
|
|
||||||
bool ResolveExpression::visit(ArrayAccessAST *ast)
|
bool ResolveExpression::visit(ArrayAccessAST *ast)
|
||||||
{
|
{
|
||||||
const QList<Result> baseResults = _results;
|
const QList<LookupItem> baseResults = _results;
|
||||||
_results.clear();
|
_results.clear();
|
||||||
|
|
||||||
const QList<Result> indexResults = operator()(ast->expression);
|
const QList<LookupItem> indexResults = operator()(ast->expression);
|
||||||
ResolveClass resolveClass;
|
ResolveClass resolveClass;
|
||||||
|
|
||||||
Name *arrayAccessOp = control()->operatorNameId(OperatorNameId::ArrayAccessOp);
|
Name *arrayAccessOp = control()->operatorNameId(OperatorNameId::ArrayAccessOp);
|
||||||
|
|
||||||
foreach (const Result &result, baseResults) {
|
foreach (const LookupItem &result, baseResults) {
|
||||||
FullySpecifiedType ty = result.first.simplified();
|
FullySpecifiedType ty = result.type().simplified();
|
||||||
Symbol *contextSymbol = result.second;
|
Symbol *contextSymbol = result.lastVisibleSymbol();
|
||||||
|
|
||||||
if (PointerType *ptrTy = ty->asPointerType()) {
|
if (PointerType *ptrTy = ty->asPointerType()) {
|
||||||
addResult(ptrTy->elementType().simplified(), contextSymbol);
|
addResult(ptrTy->elementType().simplified(), contextSymbol);
|
||||||
@@ -512,11 +514,11 @@ bool ResolveExpression::visit(ArrayAccessAST *ast)
|
|||||||
foreach (Symbol *classObject, classObjectCandidates) {
|
foreach (Symbol *classObject, classObjectCandidates) {
|
||||||
Q_ASSERT(classObject->isClass());
|
Q_ASSERT(classObject->isClass());
|
||||||
|
|
||||||
const QList<Result> overloads =
|
const QList<LookupItem> overloads =
|
||||||
resolveMember(arrayAccessOp, classObject->asClass(), namedTy->name());
|
resolveMember(arrayAccessOp, classObject->asClass(), namedTy->name());
|
||||||
|
|
||||||
foreach (Result r, overloads) {
|
foreach (LookupItem r, overloads) {
|
||||||
FullySpecifiedType ty = r.first.simplified();
|
FullySpecifiedType ty = r.type().simplified();
|
||||||
if (Function *funTy = ty->asFunctionType()) {
|
if (Function *funTy = ty->asFunctionType()) {
|
||||||
ty = funTy->returnType().simplified();
|
ty = funTy->returnType().simplified();
|
||||||
addResult(ty, funTy);
|
addResult(ty, funTy);
|
||||||
@@ -532,7 +534,7 @@ bool ResolveExpression::visit(MemberAccessAST *ast)
|
|||||||
{
|
{
|
||||||
// The candidate types for the base expression are stored in
|
// The candidate types for the base expression are stored in
|
||||||
// _results.
|
// _results.
|
||||||
QList<Result> baseResults = _results;
|
QList<LookupItem> baseResults = _results;
|
||||||
|
|
||||||
// Evaluate the expression-id that follows the access operator.
|
// Evaluate the expression-id that follows the access operator.
|
||||||
Name *memberName = 0;
|
Name *memberName = 0;
|
||||||
@@ -547,18 +549,18 @@ bool ResolveExpression::visit(MemberAccessAST *ast)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ResolveExpression::Result>
|
QList<LookupItem>
|
||||||
ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int accessOp,
|
ResolveExpression::resolveBaseExpression(const QList<LookupItem> &baseResults, int accessOp,
|
||||||
bool *replacedDotOperator) const
|
bool *replacedDotOperator) const
|
||||||
{
|
{
|
||||||
QList<Result> results;
|
QList<LookupItem> results;
|
||||||
|
|
||||||
if (baseResults.isEmpty())
|
if (baseResults.isEmpty())
|
||||||
return results;
|
return results;
|
||||||
|
|
||||||
Result result = baseResults.first();
|
LookupItem result = baseResults.first();
|
||||||
FullySpecifiedType ty = result.first.simplified();
|
FullySpecifiedType ty = result.type().simplified();
|
||||||
Symbol *lastVisibleSymbol = result.second;
|
Symbol *lastVisibleSymbol = result.lastVisibleSymbol();
|
||||||
|
|
||||||
if (Function *funTy = ty->asFunctionType()) {
|
if (Function *funTy = ty->asFunctionType()) {
|
||||||
if (funTy->isAmbiguous())
|
if (funTy->isAmbiguous())
|
||||||
@@ -568,7 +570,7 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
if (accessOp == T_ARROW) {
|
if (accessOp == T_ARROW) {
|
||||||
if (lastVisibleSymbol && ty->isClassType() && ! lastVisibleSymbol->isClass()) {
|
if (lastVisibleSymbol && ty->isClassType() && ! lastVisibleSymbol->isClass()) {
|
||||||
// ### remove ! lastVisibleSymbol->isClass() from the condition.
|
// ### remove ! lastVisibleSymbol->isClass() from the condition.
|
||||||
results.append(Result(ty, lastVisibleSymbol));
|
results.append(LookupItem(ty, lastVisibleSymbol));
|
||||||
|
|
||||||
} else if (NamedType *namedTy = ty->asNamedType()) {
|
} else if (NamedType *namedTy = ty->asNamedType()) {
|
||||||
// ### This code is pretty slow.
|
// ### This code is pretty slow.
|
||||||
@@ -577,14 +579,14 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
foreach (Symbol *candidate, candidates) {
|
foreach (Symbol *candidate, candidates) {
|
||||||
if (candidate->isTypedef()) {
|
if (candidate->isTypedef()) {
|
||||||
FullySpecifiedType declTy = candidate->type().simplified();
|
FullySpecifiedType declTy = candidate->type().simplified();
|
||||||
const ResolveExpression::Result r(declTy, candidate);
|
const LookupItem r(declTy, candidate);
|
||||||
|
|
||||||
// update the result
|
// update the result
|
||||||
result = r;
|
result = r;
|
||||||
|
|
||||||
// refresh the cached ty and lastVisibileSymbol.
|
// refresh the cached ty and lastVisibileSymbol.
|
||||||
ty = result.first.simplified();
|
ty = result.type().simplified();
|
||||||
lastVisibleSymbol = result.second;
|
lastVisibleSymbol = result.lastVisibleSymbol();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,12 +598,12 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
const QList<Symbol *> candidates = resolveClass(namedTy->name(), result, _context);
|
const QList<Symbol *> candidates = resolveClass(namedTy->name(), result, _context);
|
||||||
|
|
||||||
foreach (Symbol *classObject, candidates) {
|
foreach (Symbol *classObject, candidates) {
|
||||||
const QList<Result> overloads = resolveMember(arrowAccessOp, classObject->asClass(),
|
const QList<LookupItem> overloads = resolveMember(arrowAccessOp, classObject->asClass(),
|
||||||
namedTy->name());
|
namedTy->name());
|
||||||
|
|
||||||
foreach (const Result &r, overloads) {
|
foreach (const LookupItem &r, overloads) {
|
||||||
FullySpecifiedType typeOfOverloadFunction = r.first.simplified();
|
FullySpecifiedType typeOfOverloadFunction = r.type().simplified();
|
||||||
Symbol *lastVisibleSymbol = r.second;
|
Symbol *lastVisibleSymbol = r.lastVisibleSymbol();
|
||||||
Function *funTy = typeOfOverloadFunction->asFunctionType();
|
Function *funTy = typeOfOverloadFunction->asFunctionType();
|
||||||
if (! funTy)
|
if (! funTy)
|
||||||
continue;
|
continue;
|
||||||
@@ -612,7 +614,7 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
FullySpecifiedType elementTy = ptrTy->elementType().simplified();
|
FullySpecifiedType elementTy = ptrTy->elementType().simplified();
|
||||||
|
|
||||||
if (elementTy->isNamedType())
|
if (elementTy->isNamedType())
|
||||||
results.append(Result(elementTy, lastVisibleSymbol));
|
results.append(LookupItem(elementTy, lastVisibleSymbol));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -620,7 +622,7 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
FullySpecifiedType elementTy = ptrTy->elementType().simplified();
|
FullySpecifiedType elementTy = ptrTy->elementType().simplified();
|
||||||
|
|
||||||
if (elementTy->isNamedType() || elementTy->isClassType())
|
if (elementTy->isNamedType() || elementTy->isClassType())
|
||||||
results.append(Result(elementTy, lastVisibleSymbol));
|
results.append(LookupItem(elementTy, lastVisibleSymbol));
|
||||||
}
|
}
|
||||||
} else if (accessOp == T_DOT) {
|
} else if (accessOp == T_DOT) {
|
||||||
if (replacedDotOperator) {
|
if (replacedDotOperator) {
|
||||||
@@ -643,14 +645,14 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results.append(Result(ty, lastVisibleSymbol));
|
results.append(LookupItem(ty, lastVisibleSymbol));
|
||||||
|
|
||||||
} else if (Function *fun = ty->asFunctionType()) {
|
} else if (Function *fun = ty->asFunctionType()) {
|
||||||
Scope *funScope = fun->scope();
|
Scope *funScope = fun->scope();
|
||||||
|
|
||||||
if (funScope && (funScope->isBlockScope() || funScope->isNamespaceScope())) {
|
if (funScope && (funScope->isBlockScope() || funScope->isNamespaceScope())) {
|
||||||
FullySpecifiedType retTy = fun->returnType().simplified();
|
FullySpecifiedType retTy = fun->returnType().simplified();
|
||||||
results.append(Result(retTy, lastVisibleSymbol));
|
results.append(LookupItem(retTy, lastVisibleSymbol));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -658,18 +660,18 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
|||||||
return removeDuplicates(results);
|
return removeDuplicates(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ResolveExpression::Result>
|
QList<LookupItem>
|
||||||
ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults,
|
ResolveExpression::resolveMemberExpression(const QList<LookupItem> &baseResults,
|
||||||
unsigned accessOp,
|
unsigned accessOp,
|
||||||
Name *memberName,
|
Name *memberName,
|
||||||
bool *replacedDotOperator) const
|
bool *replacedDotOperator) const
|
||||||
{
|
{
|
||||||
ResolveClass resolveClass;
|
ResolveClass resolveClass;
|
||||||
QList<Result> results;
|
QList<LookupItem> results;
|
||||||
|
|
||||||
const QList<Result> classObjectResults = resolveBaseExpression(baseResults, accessOp, replacedDotOperator);
|
const QList<LookupItem> classObjectResults = resolveBaseExpression(baseResults, accessOp, replacedDotOperator);
|
||||||
foreach (const Result &r, classObjectResults) {
|
foreach (const LookupItem &r, classObjectResults) {
|
||||||
FullySpecifiedType ty = r.first;
|
FullySpecifiedType ty = r.type();
|
||||||
|
|
||||||
if (Class *klass = ty->asClassType())
|
if (Class *klass = ty->asClassType())
|
||||||
results += resolveMember(memberName, klass);
|
results += resolveMember(memberName, klass);
|
||||||
@@ -688,11 +690,11 @@ ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults,
|
|||||||
return removeDuplicates(results);
|
return removeDuplicates(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ResolveExpression::Result>
|
QList<LookupItem>
|
||||||
ResolveExpression::resolveMember(Name *memberName, Class *klass,
|
ResolveExpression::resolveMember(Name *memberName, Class *klass,
|
||||||
Name *className) const
|
Name *className) const
|
||||||
{
|
{
|
||||||
QList<Result> results;
|
QList<LookupItem> results;
|
||||||
|
|
||||||
if (! className)
|
if (! className)
|
||||||
className = klass->name();
|
className = klass->name();
|
||||||
@@ -731,17 +733,17 @@ ResolveExpression::resolveMember(Name *memberName, Class *klass,
|
|||||||
ty = inst(candidate);
|
ty = inst(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
results.append(Result(ty, candidate));
|
results.append(LookupItem(ty, candidate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return removeDuplicates(results);
|
return removeDuplicates(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<ResolveExpression::Result>
|
QList<LookupItem>
|
||||||
ResolveExpression::resolveMember(Name *memberName, ObjCClass *klass) const
|
ResolveExpression::resolveMember(Name *memberName, ObjCClass *klass) const
|
||||||
{
|
{
|
||||||
QList<Result> results;
|
QList<LookupItem> results;
|
||||||
|
|
||||||
if (!memberName || !klass)
|
if (!memberName || !klass)
|
||||||
return results;
|
return results;
|
||||||
@@ -754,7 +756,7 @@ ResolveExpression::resolveMember(Name *memberName, ObjCClass *klass) const
|
|||||||
foreach (Symbol *candidate, candidates) {
|
foreach (Symbol *candidate, candidates) {
|
||||||
FullySpecifiedType ty = candidate->type();
|
FullySpecifiedType ty = candidate->type();
|
||||||
|
|
||||||
results.append(Result(ty, candidate));
|
results.append(LookupItem(ty, candidate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return removeDuplicates(results);
|
return removeDuplicates(results);
|
||||||
@@ -767,11 +769,11 @@ bool ResolveExpression::visit(PostIncrDecrAST *)
|
|||||||
|
|
||||||
bool ResolveExpression::visit(ObjCMessageExpressionAST *ast)
|
bool ResolveExpression::visit(ObjCMessageExpressionAST *ast)
|
||||||
{
|
{
|
||||||
QList<Result> receiverResults = operator()(ast->receiver_expression);
|
QList<LookupItem> receiverResults = operator()(ast->receiver_expression);
|
||||||
|
|
||||||
if (!receiverResults.isEmpty()) {
|
if (!receiverResults.isEmpty()) {
|
||||||
Result result = receiverResults.first();
|
LookupItem result = receiverResults.first();
|
||||||
FullySpecifiedType ty = result.first.simplified();
|
FullySpecifiedType ty = result.type().simplified();
|
||||||
Name *klassName = 0;
|
Name *klassName = 0;
|
||||||
|
|
||||||
if (const ObjCClass *classTy = ty->asObjCClassType()) {
|
if (const ObjCClass *classTy = ty->asObjCClassType()) {
|
||||||
@@ -804,17 +806,17 @@ ResolveClass::ResolveClass()
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
QList<Symbol *> ResolveClass::operator()(Name *name,
|
QList<Symbol *> ResolveClass::operator()(Name *name,
|
||||||
const ResolveExpression::Result &p,
|
const LookupItem &p,
|
||||||
const LookupContext &context)
|
const LookupContext &context)
|
||||||
{
|
{
|
||||||
const QList<ResolveExpression::Result> previousBlackList = _blackList;
|
const QList<LookupItem> previousBlackList = _blackList;
|
||||||
const QList<Symbol *> symbols = resolveClass(name, p, context);
|
const QList<Symbol *> symbols = resolveClass(name, p, context);
|
||||||
_blackList = previousBlackList;
|
_blackList = previousBlackList;
|
||||||
return symbols;
|
return symbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Symbol *> ResolveClass::resolveClass(Name *name,
|
QList<Symbol *> ResolveClass::resolveClass(Name *name,
|
||||||
const ResolveExpression::Result &p,
|
const LookupItem &p,
|
||||||
const LookupContext &context)
|
const LookupContext &context)
|
||||||
{
|
{
|
||||||
QList<Symbol *> resolvedSymbols;
|
QList<Symbol *> resolvedSymbols;
|
||||||
@@ -845,7 +847,7 @@ QList<Symbol *> ResolveClass::resolveClass(Name *name,
|
|||||||
// b.
|
// b.
|
||||||
FullySpecifiedType declType = decl->type().simplified();
|
FullySpecifiedType declType = decl->type().simplified();
|
||||||
if (NamedType *namedTy = declType->asNamedType()) {
|
if (NamedType *namedTy = declType->asNamedType()) {
|
||||||
const ResolveExpression::Result r(declType, decl);
|
const LookupItem r(declType, decl);
|
||||||
resolvedSymbols += resolveClass(namedTy->name(), r, context);
|
resolvedSymbols += resolveClass(namedTy->name(), r, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -857,7 +859,7 @@ QList<Symbol *> ResolveClass::resolveClass(Name *name,
|
|||||||
if (funTy->scope() && (funTy->scope()->isBlockScope() || funTy->scope()->isNamespaceScope())) {
|
if (funTy->scope() && (funTy->scope()->isBlockScope() || funTy->scope()->isNamespaceScope())) {
|
||||||
FullySpecifiedType retTy = funTy->returnType().simplified();
|
FullySpecifiedType retTy = funTy->returnType().simplified();
|
||||||
if (NamedType *namedTy = retTy->asNamedType()) {
|
if (NamedType *namedTy = retTy->asNamedType()) {
|
||||||
const ResolveExpression::Result r(retTy, decl);
|
const LookupItem r(retTy, decl);
|
||||||
resolvedSymbols += resolveClass(namedTy->name(), r, context);
|
resolvedSymbols += resolveClass(namedTy->name(), r, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -872,7 +874,7 @@ ResolveObjCClass::ResolveObjCClass()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
QList<Symbol *> ResolveObjCClass::operator ()(Name *name,
|
QList<Symbol *> ResolveObjCClass::operator ()(Name *name,
|
||||||
const ResolveExpression::Result &p,
|
const LookupItem &p,
|
||||||
const LookupContext &context)
|
const LookupContext &context)
|
||||||
{
|
{
|
||||||
QList<Symbol *> resolvedSymbols;
|
QList<Symbol *> resolvedSymbols;
|
||||||
|
|||||||
@@ -40,35 +40,32 @@ namespace CPlusPlus {
|
|||||||
|
|
||||||
class CPLUSPLUS_EXPORT ResolveExpression: protected ASTVisitor
|
class CPLUSPLUS_EXPORT ResolveExpression: protected ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
typedef QPair<FullySpecifiedType, Symbol *> Result;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ResolveExpression(const LookupContext &context);
|
ResolveExpression(const LookupContext &context);
|
||||||
virtual ~ResolveExpression();
|
virtual ~ResolveExpression();
|
||||||
|
|
||||||
QList<Result> operator()(ExpressionAST *ast);
|
QList<LookupItem> operator()(ExpressionAST *ast);
|
||||||
|
|
||||||
QList<Result> resolveMemberExpression(const QList<Result> &baseResults,
|
QList<LookupItem> resolveMemberExpression(const QList<LookupItem> &baseResults,
|
||||||
unsigned accessOp,
|
unsigned accessOp,
|
||||||
Name *memberName,
|
Name *memberName,
|
||||||
bool *replacedDotOperator = 0) const;
|
bool *replacedDotOperator = 0) const;
|
||||||
|
|
||||||
QList<Result> resolveBaseExpression(const QList<Result> &baseResults,
|
QList<LookupItem> resolveBaseExpression(const QList<LookupItem> &baseResults,
|
||||||
int accessOp,
|
int accessOp,
|
||||||
bool *replacedDotOperator = 0) const;
|
bool *replacedDotOperator = 0) const;
|
||||||
|
|
||||||
QList<Result> resolveMember(Name *memberName, Class *klass,
|
QList<LookupItem> resolveMember(Name *memberName, Class *klass,
|
||||||
Name *className = 0) const;
|
Name *className = 0) const;
|
||||||
|
|
||||||
QList<Result> resolveMember(Name *memberName, ObjCClass *klass) const;
|
QList<LookupItem> resolveMember(Name *memberName, ObjCClass *klass) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QList<Result> switchResults(const QList<Result> &symbols);
|
QList<LookupItem> switchResults(const QList<LookupItem> &symbols);
|
||||||
|
|
||||||
void addResult(const FullySpecifiedType &ty, Symbol *symbol = 0);
|
void addResult(const FullySpecifiedType &ty, Symbol *symbol = 0);
|
||||||
void addResult(const Result &result);
|
void addResult(const LookupItem &result);
|
||||||
void addResults(const QList<Result> &results);
|
void addResults(const QList<LookupItem> &results);
|
||||||
|
|
||||||
bool maybeValidPrototype(Function *funTy, unsigned actualArgumentCount) const;
|
bool maybeValidPrototype(Function *funTy, unsigned actualArgumentCount) const;
|
||||||
|
|
||||||
@@ -114,12 +111,12 @@ protected:
|
|||||||
// Objective-C expressions
|
// Objective-C expressions
|
||||||
virtual bool visit(ObjCMessageExpressionAST *ast);
|
virtual bool visit(ObjCMessageExpressionAST *ast);
|
||||||
|
|
||||||
QList<Scope *> visibleScopes(const Result &result) const;
|
QList<Scope *> visibleScopes(const LookupItem &result) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LookupContext _context;
|
LookupContext _context;
|
||||||
Semantic sem;
|
Semantic sem;
|
||||||
QList<Result> _results;
|
QList<LookupItem> _results;
|
||||||
Symbol *_declSymbol;
|
Symbol *_declSymbol;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,16 +126,16 @@ public:
|
|||||||
ResolveClass();
|
ResolveClass();
|
||||||
|
|
||||||
QList<Symbol *> operator()(Name *name,
|
QList<Symbol *> operator()(Name *name,
|
||||||
const ResolveExpression::Result &p,
|
const LookupItem &p,
|
||||||
const LookupContext &context);
|
const LookupContext &context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Symbol *> resolveClass(Name *name,
|
QList<Symbol *> resolveClass(Name *name,
|
||||||
const ResolveExpression::Result &p,
|
const LookupItem &p,
|
||||||
const LookupContext &context);
|
const LookupContext &context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ResolveExpression::Result> _blackList;
|
QList<LookupItem> _blackList;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT ResolveObjCClass
|
class CPLUSPLUS_EXPORT ResolveObjCClass
|
||||||
@@ -147,7 +144,7 @@ public:
|
|||||||
ResolveObjCClass();
|
ResolveObjCClass();
|
||||||
|
|
||||||
QList<Symbol *> operator()(Name *name,
|
QList<Symbol *> operator()(Name *name,
|
||||||
const ResolveExpression::Result &p,
|
const LookupItem &p,
|
||||||
const LookupContext &context);
|
const LookupContext &context);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void TypeOfExpression::setSnapshot(const Snapshot &documents)
|
|||||||
m_lookupContext = LookupContext();
|
m_lookupContext = LookupContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TypeOfExpression::Result> TypeOfExpression::operator()(const QString &expression,
|
QList<LookupItem> TypeOfExpression::operator()(const QString &expression,
|
||||||
Document::Ptr document,
|
Document::Ptr document,
|
||||||
Symbol *lastVisibleSymbol,
|
Symbol *lastVisibleSymbol,
|
||||||
PreprocessMode mode)
|
PreprocessMode mode)
|
||||||
|
|||||||
@@ -44,9 +44,6 @@ class Macro;
|
|||||||
|
|
||||||
class CPLUSPLUS_EXPORT TypeOfExpression
|
class CPLUSPLUS_EXPORT TypeOfExpression
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
typedef QPair<FullySpecifiedType, Symbol *> Result;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TypeOfExpression();
|
TypeOfExpression();
|
||||||
|
|
||||||
@@ -78,7 +75,7 @@ public:
|
|||||||
* @param document The document the expression is part of.
|
* @param document The document the expression is part of.
|
||||||
* @param lastVisibleSymbol The last visible symbol in the document.
|
* @param lastVisibleSymbol The last visible symbol in the document.
|
||||||
*/
|
*/
|
||||||
QList<Result> operator()(const QString &expression, Document::Ptr document,
|
QList<LookupItem> operator()(const QString &expression, Document::Ptr document,
|
||||||
Symbol *lastVisibleSymbol,
|
Symbol *lastVisibleSymbol,
|
||||||
PreprocessMode mode = NoPreprocess);
|
PreprocessMode mode = NoPreprocess);
|
||||||
|
|
||||||
|
|||||||
@@ -745,12 +745,13 @@ CPlusPlus::Symbol *CPPEditor::findCanonicalSymbol(const QTextCursor &cursor,
|
|||||||
|
|
||||||
Symbol *lastVisibleSymbol = doc->findSymbolAt(line, col);
|
Symbol *lastVisibleSymbol = doc->findSymbolAt(line, col);
|
||||||
|
|
||||||
const QList<TypeOfExpression::Result> results = typeOfExpression(code, doc,
|
const QList<LookupItem> results = typeOfExpression(code, doc,
|
||||||
lastVisibleSymbol,
|
lastVisibleSymbol,
|
||||||
TypeOfExpression::Preprocess);
|
TypeOfExpression::Preprocess);
|
||||||
|
|
||||||
NamespaceBindingPtr glo = bind(doc, snapshot);
|
NamespaceBindingPtr glo = bind(doc, snapshot);
|
||||||
Symbol *canonicalSymbol = LookupContext::canonicalSymbol(results, glo.data());
|
Symbol *canonicalSymbol = LookupContext::canonicalSymbol(results, glo.data());
|
||||||
|
|
||||||
return canonicalSymbol;
|
return canonicalSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1079,7 +1080,7 @@ void CPPEditor::switchDeclarationDefinition()
|
|||||||
if (f) {
|
if (f) {
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.setSnapshot(m_modelManager->snapshot());
|
typeOfExpression.setSnapshot(m_modelManager->snapshot());
|
||||||
QList<TypeOfExpression::Result> resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol);
|
QList<LookupItem> resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol);
|
||||||
const LookupContext &context = typeOfExpression.lookupContext();
|
const LookupContext &context = typeOfExpression.lookupContext();
|
||||||
|
|
||||||
QualifiedNameId *q = qualifiedNameIdForSymbol(f, context);
|
QualifiedNameId *q = qualifiedNameIdForSymbol(f, context);
|
||||||
@@ -1164,46 +1165,47 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
const QString expression = expressionUnderCursor(tc);
|
const QString expression = expressionUnderCursor(tc);
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.setSnapshot(snapshot);
|
typeOfExpression.setSnapshot(snapshot);
|
||||||
QList<TypeOfExpression::Result> resolvedSymbols =
|
QList<LookupItem> resolvedSymbols =
|
||||||
typeOfExpression(expression, doc, lastSymbol);
|
typeOfExpression(expression, doc, lastSymbol);
|
||||||
|
|
||||||
if (!resolvedSymbols.isEmpty()) {
|
if (!resolvedSymbols.isEmpty()) {
|
||||||
TypeOfExpression::Result result = resolvedSymbols.first();
|
LookupItem result = resolvedSymbols.first();
|
||||||
|
const FullySpecifiedType ty = result.type().simplified();
|
||||||
|
|
||||||
if (result.first->isForwardClassDeclarationType()) {
|
if (ty->isForwardClassDeclarationType()) {
|
||||||
while (! resolvedSymbols.isEmpty()) {
|
while (! resolvedSymbols.isEmpty()) {
|
||||||
TypeOfExpression::Result r = resolvedSymbols.takeFirst();
|
LookupItem r = resolvedSymbols.takeFirst();
|
||||||
|
|
||||||
if (! r.first->isForwardClassDeclarationType()) {
|
if (! r.type()->isForwardClassDeclarationType()) {
|
||||||
result = r;
|
result = r;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.first->isObjCForwardClassDeclarationType()) {
|
if (ty->isObjCForwardClassDeclarationType()) {
|
||||||
while (! resolvedSymbols.isEmpty()) {
|
while (! resolvedSymbols.isEmpty()) {
|
||||||
TypeOfExpression::Result r = resolvedSymbols.takeFirst();
|
LookupItem r = resolvedSymbols.takeFirst();
|
||||||
|
|
||||||
if (! r.first->isObjCForwardClassDeclarationType()) {
|
if (! r.type()->isObjCForwardClassDeclarationType()) {
|
||||||
result = r;
|
result = r;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.first->isObjCForwardProtocolDeclarationType()) {
|
if (ty->isObjCForwardProtocolDeclarationType()) {
|
||||||
while (! resolvedSymbols.isEmpty()) {
|
while (! resolvedSymbols.isEmpty()) {
|
||||||
TypeOfExpression::Result r = resolvedSymbols.takeFirst();
|
LookupItem r = resolvedSymbols.takeFirst();
|
||||||
|
|
||||||
if (! r.first->isObjCForwardProtocolDeclarationType()) {
|
if (! r.type()->isObjCForwardProtocolDeclarationType()) {
|
||||||
result = r;
|
result = r;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Symbol *symbol = result.second) {
|
if (Symbol *symbol = result.lastVisibleSymbol()) {
|
||||||
Symbol *def = 0;
|
Symbol *def = 0;
|
||||||
if (resolveTarget && !lastSymbol->isFunction())
|
if (resolveTarget && !lastSymbol->isFunction())
|
||||||
def = findDefinition(symbol);
|
def = findDefinition(symbol);
|
||||||
|
|||||||
@@ -323,14 +323,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
|||||||
ExpressionUnderCursor expressionUnderCursor;
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
const QString expression = expressionUnderCursor(tc);
|
const QString expression = expressionUnderCursor(tc);
|
||||||
|
|
||||||
const QList<TypeOfExpression::Result> types =
|
const QList<LookupItem> types = typeOfExpression(expression, doc, lastSymbol);
|
||||||
typeOfExpression(expression, doc, lastSymbol);
|
|
||||||
|
|
||||||
if (!types.isEmpty()) {
|
if (!types.isEmpty()) {
|
||||||
const TypeOfExpression::Result result = types.first();
|
const LookupItem result = types.first();
|
||||||
|
|
||||||
FullySpecifiedType firstType = result.first; // result of `type of expression'.
|
FullySpecifiedType firstType = result.type(); // result of `type of expression'.
|
||||||
Symbol *lookupSymbol = result.second; // lookup symbol
|
Symbol *lookupSymbol = result.lastVisibleSymbol(); // lookup symbol
|
||||||
|
|
||||||
Symbol *resolvedSymbol = lookupSymbol;
|
Symbol *resolvedSymbol = lookupSymbol;
|
||||||
Name *resolvedName = lookupSymbol ? lookupSymbol->name() : 0;
|
Name *resolvedName = lookupSymbol ? lookupSymbol->name() : 0;
|
||||||
@@ -349,7 +348,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
|||||||
m_helpId = buildHelpId(resolvedSymbol, resolvedName);
|
m_helpId = buildHelpId(resolvedSymbol, resolvedName);
|
||||||
|
|
||||||
if (m_toolTip.isEmpty()) {
|
if (m_toolTip.isEmpty()) {
|
||||||
Symbol *symbol = result.second;
|
Symbol *symbol = result.lastVisibleSymbol();
|
||||||
if (resolvedSymbol)
|
if (resolvedSymbol)
|
||||||
symbol = resolvedSymbol;
|
symbol = resolvedSymbol;
|
||||||
|
|
||||||
|
|||||||
@@ -789,7 +789,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
Symbol *lastVisibleSymbol = thisDocument->findSymbolAt(line, column);
|
Symbol *lastVisibleSymbol = thisDocument->findSymbolAt(line, column);
|
||||||
typeOfExpression.setSnapshot(m_manager->snapshot());
|
typeOfExpression.setSnapshot(m_manager->snapshot());
|
||||||
|
|
||||||
QList<TypeOfExpression::Result> resolvedTypes = typeOfExpression(expression, thisDocument, lastVisibleSymbol,
|
QList<LookupItem> resolvedTypes = typeOfExpression(expression, thisDocument, lastVisibleSymbol,
|
||||||
TypeOfExpression::Preprocess);
|
TypeOfExpression::Preprocess);
|
||||||
LookupContext context = typeOfExpression.lookupContext();
|
LookupContext context = typeOfExpression.lookupContext();
|
||||||
|
|
||||||
@@ -852,14 +852,14 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
const QString baseExpression = expressionUnderCursor(tc);
|
const QString baseExpression = expressionUnderCursor(tc);
|
||||||
|
|
||||||
// Resolve the type of this expression
|
// Resolve the type of this expression
|
||||||
const QList<TypeOfExpression::Result> results =
|
const QList<LookupItem> results =
|
||||||
typeOfExpression(baseExpression, thisDocument,
|
typeOfExpression(baseExpression, thisDocument,
|
||||||
lastVisibleSymbol,
|
lastVisibleSymbol,
|
||||||
TypeOfExpression::Preprocess);
|
TypeOfExpression::Preprocess);
|
||||||
|
|
||||||
// If it's a class, add completions for the constructors
|
// If it's a class, add completions for the constructors
|
||||||
foreach (const TypeOfExpression::Result &result, results) {
|
foreach (const LookupItem &result, results) {
|
||||||
if (result.first->isClassType()) {
|
if (result.type()->isClassType()) {
|
||||||
if (completeConstructorOrFunction(results, context, endOfExpression, true))
|
if (completeConstructorOrFunction(results, context, endOfExpression, true))
|
||||||
return m_startPosition;
|
return m_startPosition;
|
||||||
break;
|
break;
|
||||||
@@ -872,14 +872,14 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpression::Result> &results,
|
bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results,
|
||||||
const LookupContext &context,
|
const LookupContext &context,
|
||||||
int endOfExpression, bool toolTipOnly)
|
int endOfExpression, bool toolTipOnly)
|
||||||
{
|
{
|
||||||
QList<Function *> functions;
|
QList<Function *> functions;
|
||||||
|
|
||||||
foreach (const TypeOfExpression::Result &result, results) {
|
foreach (const LookupItem &result, results) {
|
||||||
FullySpecifiedType exprTy = result.first.simplified();
|
FullySpecifiedType exprTy = result.type().simplified();
|
||||||
|
|
||||||
if (Class *klass = exprTy->asClassType()) {
|
if (Class *klass = exprTy->asClassType()) {
|
||||||
Name *className = klass->name();
|
Name *className = klass->name();
|
||||||
@@ -909,8 +909,8 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (functions.isEmpty()) {
|
if (functions.isEmpty()) {
|
||||||
foreach (const TypeOfExpression::Result &result, results) {
|
foreach (const LookupItem &result, results) {
|
||||||
FullySpecifiedType ty = result.first.simplified();
|
FullySpecifiedType ty = result.type().simplified();
|
||||||
|
|
||||||
if (Function *fun = ty->asFunctionType()) {
|
if (Function *fun = ty->asFunctionType()) {
|
||||||
|
|
||||||
@@ -939,20 +939,20 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
|
|||||||
ResolveClass resolveClass;
|
ResolveClass resolveClass;
|
||||||
Name *functionCallOp = context.control()->operatorNameId(OperatorNameId::FunctionCallOp);
|
Name *functionCallOp = context.control()->operatorNameId(OperatorNameId::FunctionCallOp);
|
||||||
|
|
||||||
foreach (const TypeOfExpression::Result &result, results) {
|
foreach (const LookupItem &result, results) {
|
||||||
FullySpecifiedType ty = result.first.simplified();
|
FullySpecifiedType ty = result.type().simplified();
|
||||||
|
|
||||||
if (NamedType *namedTy = ty->asNamedType()) {
|
if (NamedType *namedTy = ty->asNamedType()) {
|
||||||
const QList<Symbol *> classObjectCandidates = resolveClass(namedTy->name(), result, context);
|
const QList<Symbol *> classObjectCandidates = resolveClass(namedTy->name(), result, context);
|
||||||
|
|
||||||
foreach (Symbol *classObjectCandidate, classObjectCandidates) {
|
foreach (Symbol *classObjectCandidate, classObjectCandidates) {
|
||||||
if (Class *klass = classObjectCandidate->asClass()) {
|
if (Class *klass = classObjectCandidate->asClass()) {
|
||||||
const QList<TypeOfExpression::Result> overloads =
|
const QList<LookupItem> overloads =
|
||||||
resolveExpression.resolveMember(functionCallOp, klass,
|
resolveExpression.resolveMember(functionCallOp, klass,
|
||||||
namedTy->name());
|
namedTy->name());
|
||||||
|
|
||||||
foreach (const TypeOfExpression::Result &overloadResult, overloads) {
|
foreach (const LookupItem &overloadResult, overloads) {
|
||||||
FullySpecifiedType overloadTy = overloadResult.first.simplified();
|
FullySpecifiedType overloadTy = overloadResult.type().simplified();
|
||||||
|
|
||||||
if (Function *funTy = overloadTy->asFunctionType())
|
if (Function *funTy = overloadTy->asFunctionType())
|
||||||
functions.append(funTy);
|
functions.append(funTy);
|
||||||
@@ -1060,7 +1060,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &baseResults,
|
bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults,
|
||||||
const LookupContext &context)
|
const LookupContext &context)
|
||||||
{
|
{
|
||||||
if (baseResults.isEmpty())
|
if (baseResults.isEmpty())
|
||||||
@@ -1070,14 +1070,14 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &ba
|
|||||||
ResolveClass resolveClass;
|
ResolveClass resolveClass;
|
||||||
|
|
||||||
bool replacedDotOperator = false;
|
bool replacedDotOperator = false;
|
||||||
const QList<TypeOfExpression::Result> classObjectResults =
|
const QList<LookupItem> classObjectResults =
|
||||||
resolveExpression.resolveBaseExpression(baseResults,
|
resolveExpression.resolveBaseExpression(baseResults,
|
||||||
m_completionOperator,
|
m_completionOperator,
|
||||||
&replacedDotOperator);
|
&replacedDotOperator);
|
||||||
|
|
||||||
QList<Symbol *> classObjectCandidates;
|
QList<Symbol *> classObjectCandidates;
|
||||||
foreach (const TypeOfExpression::Result &r, classObjectResults) {
|
foreach (const LookupItem &r, classObjectResults) {
|
||||||
FullySpecifiedType ty = r.first.simplified();
|
FullySpecifiedType ty = r.type().simplified();
|
||||||
|
|
||||||
if (Class *klass = ty->asClassType())
|
if (Class *klass = ty->asClassType())
|
||||||
classObjectCandidates.append(klass);
|
classObjectCandidates.append(klass);
|
||||||
@@ -1108,13 +1108,13 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &ba
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeScope(const QList<TypeOfExpression::Result> &results,
|
bool CppCodeCompletion::completeScope(const QList<LookupItem> &results,
|
||||||
const LookupContext &context)
|
const LookupContext &context)
|
||||||
{
|
{
|
||||||
QList<Symbol *> classes, namespaces;
|
QList<Symbol *> classes, namespaces;
|
||||||
|
|
||||||
foreach (TypeOfExpression::Result result, results) {
|
foreach (LookupItem result, results) {
|
||||||
FullySpecifiedType ty = result.first;
|
FullySpecifiedType ty = result.type();
|
||||||
|
|
||||||
if (Class *classTy = ty->asClassType())
|
if (Class *classTy = ty->asClassType())
|
||||||
classes.append(classTy);
|
classes.append(classTy);
|
||||||
@@ -1305,7 +1305,7 @@ void CppCodeCompletion::completeClass(const QList<Symbol *> &candidates,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeQtMethod(const QList<TypeOfExpression::Result> &results,
|
bool CppCodeCompletion::completeQtMethod(const QList<LookupItem> &results,
|
||||||
const LookupContext &context,
|
const LookupContext &context,
|
||||||
bool wantSignals)
|
bool wantSignals)
|
||||||
{
|
{
|
||||||
@@ -1321,8 +1321,8 @@ bool CppCodeCompletion::completeQtMethod(const QList<TypeOfExpression::Result> &
|
|||||||
o.setShowFunctionSignatures(true);
|
o.setShowFunctionSignatures(true);
|
||||||
|
|
||||||
QSet<QString> signatures;
|
QSet<QString> signatures;
|
||||||
foreach (const TypeOfExpression::Result &p, results) {
|
foreach (const LookupItem &p, results) {
|
||||||
FullySpecifiedType ty = p.first.simplified();
|
FullySpecifiedType ty = p.type().simplified();
|
||||||
|
|
||||||
if (PointerType *ptrTy = ty->asPointerType())
|
if (PointerType *ptrTy = ty->asPointerType())
|
||||||
ty = ptrTy->elementType().simplified();
|
ty = ptrTy->elementType().simplified();
|
||||||
|
|||||||
@@ -95,14 +95,14 @@ private:
|
|||||||
|
|
||||||
bool completeInclude(const QTextCursor &cursor);
|
bool completeInclude(const QTextCursor &cursor);
|
||||||
|
|
||||||
bool completeConstructorOrFunction(const QList<CPlusPlus::TypeOfExpression::Result> &,
|
bool completeConstructorOrFunction(const QList<CPlusPlus::LookupItem> &,
|
||||||
const CPlusPlus::LookupContext &,
|
const CPlusPlus::LookupContext &,
|
||||||
int endOfExpression, bool toolTipOnly);
|
int endOfExpression, bool toolTipOnly);
|
||||||
|
|
||||||
bool completeMember(const QList<CPlusPlus::TypeOfExpression::Result> &,
|
bool completeMember(const QList<CPlusPlus::LookupItem> &,
|
||||||
const CPlusPlus::LookupContext &context);
|
const CPlusPlus::LookupContext &context);
|
||||||
|
|
||||||
bool completeScope(const QList<CPlusPlus::TypeOfExpression::Result> &,
|
bool completeScope(const QList<CPlusPlus::LookupItem> &,
|
||||||
const CPlusPlus::LookupContext &context);
|
const CPlusPlus::LookupContext &context);
|
||||||
|
|
||||||
void completeNamespace(const QList<CPlusPlus::Symbol *> &candidates,
|
void completeNamespace(const QList<CPlusPlus::Symbol *> &candidates,
|
||||||
@@ -114,15 +114,15 @@ private:
|
|||||||
|
|
||||||
bool completeConstructors(CPlusPlus::Class *klass);
|
bool completeConstructors(CPlusPlus::Class *klass);
|
||||||
|
|
||||||
bool completeQtMethod(const QList<CPlusPlus::TypeOfExpression::Result> &,
|
bool completeQtMethod(const QList<CPlusPlus::LookupItem> &,
|
||||||
const CPlusPlus::LookupContext &context,
|
const CPlusPlus::LookupContext &context,
|
||||||
bool wantSignals);
|
bool wantSignals);
|
||||||
|
|
||||||
bool completeSignal(const QList<CPlusPlus::TypeOfExpression::Result> &results,
|
bool completeSignal(const QList<CPlusPlus::LookupItem> &results,
|
||||||
const CPlusPlus::LookupContext &context)
|
const CPlusPlus::LookupContext &context)
|
||||||
{ return completeQtMethod(results, context, true); }
|
{ return completeQtMethod(results, context, true); }
|
||||||
|
|
||||||
bool completeSlot(const QList<CPlusPlus::TypeOfExpression::Result> &results,
|
bool completeSlot(const QList<CPlusPlus::LookupItem> &results,
|
||||||
const CPlusPlus::LookupContext &context)
|
const CPlusPlus::LookupContext &context)
|
||||||
{ return completeQtMethod(results, context, false); }
|
{ return completeQtMethod(results, context, false); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user