Commit f0ac751f authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Completion for typedef of pointer to struct.

parent c7ac64e7
......@@ -32,13 +32,15 @@
***************************************************************************/
#include "LookupContext.h"
#include "ResolveExpression.h"
#include "Overview.h"
#include <CoreTypes.h>
#include <Symbols.h>
#include <Literals.h>
#include <Names.h>
#include <Scope.h>
#include <Control.h>
#include <cplusplus/Overview.h>
#include <QtDebug>
......
......@@ -427,7 +427,7 @@ bool ResolveExpression::visit(UnaryExpressionAST *ast)
bool ResolveExpression::visit(QualifiedNameAST *ast)
{
ResolveClass symbolsForDotAcces;
ResolveClass resolveClass;
Scope dummy;
Name *name = sem.check(ast, &dummy);
......@@ -437,7 +437,8 @@ bool ResolveExpression::visit(QualifiedNameAST *ast)
if (NamedType *namedTy = symbol->type()->asNamedType()) {
LookupContext symbolContext(symbol, _context);
const Result r(namedTy, symbol);
const QList<Symbol *> resolvedClasses = symbolsForDotAcces(r, _context);
const QList<Symbol *> resolvedClasses =
resolveClass(r, _context);
if (resolvedClasses.count()) {
foreach (Symbol *s, resolvedClasses) {
addResult(s->type(), s);
......@@ -555,8 +556,8 @@ bool ResolveExpression::visit(ArrayAccessAST *ast)
symbolsForDotAcccess(p, _context);
foreach (Symbol *classObject, classObjectCandidates) {
const QList<Result> overloads = resolveArrayOperator(p, namedTy,
classObject->asClass());
const QList<Result> overloads =
resolveArrayOperator(p, namedTy, classObject->asClass());
foreach (Result r, overloads) {
FullySpecifiedType ty = r.first;
Function *funTy = ty->asFunction();
......@@ -803,8 +804,8 @@ ResolveClass::ResolveClass()
{ }
QList<Symbol *> ResolveClass::operator()(NamedType *namedTy,
ResolveExpression::Result p,
const LookupContext &context)
ResolveExpression::Result p,
const LookupContext &context)
{
const QList<ResolveExpression::Result> previousBlackList = _blackList;
const QList<Symbol *> symbols = resolveClass(namedTy, p, context);
......@@ -813,7 +814,7 @@ QList<Symbol *> ResolveClass::operator()(NamedType *namedTy,
}
QList<Symbol *> ResolveClass::operator()(ResolveExpression::Result p,
const LookupContext &context)
const LookupContext &context)
{
const QList<ResolveExpression::Result> previousBlackList = _blackList;
const QList<Symbol *> symbols = resolveClass(p, context);
......@@ -822,8 +823,8 @@ QList<Symbol *> ResolveClass::operator()(ResolveExpression::Result p,
}
QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy,
ResolveExpression::Result p,
const LookupContext &context)
ResolveExpression::Result p,
const LookupContext &context)
{
QList<Symbol *> resolvedSymbols;
......@@ -871,7 +872,7 @@ QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy,
}
QList<Symbol *> ResolveClass::resolveClass(ResolveExpression::Result p,
const LookupContext &context)
const LookupContext &context)
{
FullySpecifiedType ty = p.first;
......
......@@ -581,24 +581,36 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
if (results.isEmpty())
return false;
const TypeOfExpression::Result p = results.first();
TypeOfExpression::Result result = results.first();
QList<Symbol *> classObjectCandidates;
if (m_completionOperator == T_ARROW) {
FullySpecifiedType ty = p.first;
FullySpecifiedType ty = result.first;
if (ReferenceType *refTy = ty->asReferenceType())
ty = refTy->elementType();
if (NamedType *namedTy = ty->asNamedType()) {
// ### This code is pretty slow.
const QList<Symbol *> candidates = context.resolve(namedTy->name());
foreach (Symbol *candidate, candidates) {
if (candidate->isTypedef()) {
ty = candidate->type();
const ResolveExpression::Result r(ty, candidate);
result = r;
break;
}
}
}
if (NamedType *namedTy = ty->asNamedType()) {
ResolveExpression resolveExpression(context);
ResolveClass resolveClass;
const QList<Symbol *> candidates = resolveClass(namedTy, p, context);
const QList<Symbol *> candidates = resolveClass(result, context);
foreach (Symbol *classObject, candidates) {
const QList<TypeOfExpression::Result> overloads =
resolveExpression.resolveArrowOperator(p, namedTy,
resolveExpression.resolveArrowOperator(result, namedTy,
classObject->asClass());
foreach (TypeOfExpression::Result r, overloads) {
......@@ -615,7 +627,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
if (PointerType *ptrTy = ty->asPointerType()) {
if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) {
const QList<Symbol *> classes =
resolveClass(namedTy, p, context);
resolveClass(namedTy, result, context);
foreach (Symbol *c, classes) {
if (! classObjectCandidates.contains(c))
......@@ -629,17 +641,22 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) {
ResolveClass resolveClass;
const QList<Symbol *> classes = resolveClass(namedTy, p,
context);
const QList<Symbol *> classes = resolveClass(namedTy, result,
context);
foreach (Symbol *c, classes) {
if (! classObjectCandidates.contains(c))
classObjectCandidates.append(c);
}
} else if (Class *classTy = ptrTy->elementType()->asClass()) {
// typedef struct { int x } *Ptr;
// Ptr p;
// p->
classObjectCandidates.append(classTy);
}
}
} else if (m_completionOperator == T_DOT) {
FullySpecifiedType ty = p.first;
FullySpecifiedType ty = result.first;
if (ReferenceType *refTy = ty->asReferenceType())
ty = refTy->elementType();
......@@ -663,7 +680,8 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
if (namedTy) {
ResolveClass resolveClass;
const QList<Symbol *> symbols = resolveClass(namedTy, p, context);
const QList<Symbol *> symbols = resolveClass(namedTy, result,
context);
foreach (Symbol *symbol, symbols) {
if (classObjectCandidates.contains(symbol))
continue;
......
Supports Markdown
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