Commit 225c784a authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Improved the member lookup of typedef symbols.

parent 053f9b44
......@@ -628,26 +628,37 @@ ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults,
ty = refTy->elementType();
if (NamedType *namedTy = ty->asNamedType()) {
const QList<Symbol *> classObjectCandidates =
resolveClass(namedTy, p, _context);
resolveClass.setPointerAccess(true);
QList<Symbol *> classObjectCandidates = resolveClass(namedTy, p, _context);
foreach (Symbol *classObject, classObjectCandidates) {
const QList<Result> overloads = resolveArrowOperator(p, namedTy,
classObject->asClass());
foreach (Result r, overloads) {
FullySpecifiedType ty = r.first;
Function *funTy = ty->asFunctionType();
if (! funTy)
continue;
ty = funTy->returnType();
if (ReferenceType *refTy = ty->asReferenceType())
ty = refTy->elementType();
if (PointerType *ptrTy = ty->asPointerType()) {
if (NamedType *namedTy = ptrTy->elementType()->asNamedType())
results += resolveMember(r, memberName, namedTy);
results += resolveMember(p, memberName,
control()->namedType(classObject->name()), // ### remove the call to namedType
classObject->asClass());
}
if (classObjectCandidates.isEmpty()) {
resolveClass.setPointerAccess(false);
classObjectCandidates = resolveClass(namedTy, p, _context);
foreach (Symbol *classObject, classObjectCandidates) {
const QList<Result> overloads = resolveArrowOperator(p, namedTy,
classObject->asClass());
foreach (Result r, overloads) {
FullySpecifiedType ty = r.first;
Function *funTy = ty->asFunctionType();
if (! funTy)
continue;
ty = funTy->returnType();
if (ReferenceType *refTy = ty->asReferenceType())
ty = refTy->elementType();
if (PointerType *ptrTy = ty->asPointerType()) {
if (NamedType *namedTy = ptrTy->elementType()->asNamedType())
results += resolveMember(r, memberName, namedTy);
}
}
}
}
......@@ -822,8 +833,15 @@ bool ResolveExpression::visit(PostIncrDecrAST *)
////////////////////////////////////////////////////////////////////////////////
ResolveClass::ResolveClass()
: _pointerAccess(false)
{ }
bool ResolveClass::pointerAccess() const
{ return _pointerAccess; }
void ResolveClass::setPointerAccess(bool pointerAccess)
{ _pointerAccess = pointerAccess; }
QList<Symbol *> ResolveClass::operator()(NamedType *namedTy,
ResolveExpression::Result p,
const LookupContext &context)
......@@ -864,7 +882,13 @@ QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy,
resolvedSymbols.append(klass);
} else if (candidate->isTypedef()) {
if (Declaration *decl = candidate->asDeclaration()) {
if (Class *asClass = decl->type()->asClassType()) {
if (_pointerAccess && decl->type()->isPointerType()) {
PointerType *ptrTy = decl->type()->asPointerType();
_pointerAccess = false;
const ResolveExpression::Result r(ptrTy->elementType(), decl);
resolvedSymbols += resolveClass(r, context);
_pointerAccess = true;
} else if (Class *asClass = decl->type()->asClassType()) {
// typedef struct { } Point;
// Point pt;
// pt.
......
......@@ -130,6 +130,9 @@ class CPLUSPLUS_EXPORT ResolveClass
public:
ResolveClass();
bool pointerAccess() const;
void setPointerAccess(bool pointerAccess);
QList<Symbol *> operator()(NamedType *namedTy,
ResolveExpression::Result p,
const LookupContext &context);
......@@ -147,6 +150,7 @@ private:
private:
QList<ResolveExpression::Result> _blackList;
bool _pointerAccess;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment