Instiate overloads of operator->().

This commit is contained in:
Roberto Raggi
2010-05-12 16:04:43 +02:00
parent 1f3ce81061
commit 3c6ad0d845
4 changed files with 57 additions and 30 deletions

View File

@@ -263,6 +263,11 @@ ClassOrNamespace::ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *pa
{
}
const TemplateNameId *ClassOrNamespace::templateId() const
{
return _templateId;
}
ClassOrNamespace *ClassOrNamespace::parent() const
{
return _parent;
@@ -316,36 +321,36 @@ QList<Symbol *> ClassOrNamespace::lookup(const Name *name)
QList<Symbol *> ClassOrNamespace::lookup_helper(const Name *name, bool searchInEnclosingScope)
{
QList<Symbol *> result;
if (! name)
return result;
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
if (name) {
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
ClassOrNamespace *binding = this;
if (q->isGlobal())
binding = globalNamespace();
if (q->nameCount() == 1)
return binding->find(q->unqualifiedNameId());
binding = binding->lookupClassOrNamespace(q->nameAt(0));
for (unsigned index = 1; binding && index < q->nameCount() - 1; ++index)
binding = binding->findClassOrNamespace(q->nameAt(index));
if (binding)
result = binding->find(q->unqualifiedNameId());
return result;
}
QSet<ClassOrNamespace *> processed;
ClassOrNamespace *binding = this;
if (q->isGlobal())
binding = globalNamespace();
if (q->nameCount() == 1)
return binding->find(q->unqualifiedNameId());
binding = binding->lookupClassOrNamespace(q->nameAt(0));
for (unsigned index = 1; binding && index < q->nameCount() - 1; ++index)
binding = binding->findClassOrNamespace(q->nameAt(index));
if (binding)
result = binding->find(q->unqualifiedNameId());
return result;
do {
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
binding = binding->_parent;
} while (searchInEnclosingScope && binding);
}
QSet<ClassOrNamespace *> processed;
ClassOrNamespace *binding = this;
do {
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
binding = binding->_parent;
} while (searchInEnclosingScope && binding);
return result;
}
@@ -404,7 +409,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
else if (s->name()->isQualifiedNameId())
continue; // skip qualified ids.
#if 0
#if 1
if (templateId && (s->isDeclaration() || s->isFunction())) {
FullySpecifiedType ty = GenTemplateInstance::instantiate(templateId, s, _control);
@@ -416,6 +421,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
qDebug() << "TODO: instantiate:" << oo(s->type(), s->name()) << "using:" << oo(templateId)
<< oo(ty);
#if 0
if (Declaration *decl = s->asDeclaration()) {
qDebug() << "instantiate declaration";
Declaration *d = _control->newDeclaration(0, 0);
@@ -430,6 +436,8 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
result->append(d);
continue;
}
#endif
}
#endif

View File

@@ -48,6 +48,7 @@ class CPLUSPLUS_EXPORT ClassOrNamespace
public:
ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *parent);
const TemplateNameId *templateId() const;
ClassOrNamespace *parent() const;
QList<ClassOrNamespace *> usings() const;
QList<Enum *> enums() const;

View File

@@ -603,10 +603,23 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
const OperatorNameId *arrowOp = control()->operatorNameId(OperatorNameId::ArrowOp);
foreach (Symbol *overload, binding->find(arrowOp)) {
FullySpecifiedType overloadTy = overload->type();
if (Function *funTy = overload->type()->asFunctionType()) {
FullySpecifiedType overloadTy = GenTemplateInstance::instantiate(binding->templateId(), overload, control());
Function *instantiatedFunction = overloadTy->asFunctionType();
Q_ASSERT(instantiatedFunction != 0);
if (ClassOrNamespace *retBinding = findClass(overloadTy, overload->scope()))
return retBinding;
FullySpecifiedType retTy = instantiatedFunction->returnType().simplified();
if (PointerType *ptrTy = retTy->asPointerType()) {
if (ClassOrNamespace *retBinding = findClass(ptrTy->elementType(), overload->scope()))
return retBinding;
else if (debug) {
Overview oo;
qDebug() << "no class for:" << oo(ptrTy->elementType());
}
}
}
}
}
} else if (accessOp == T_DOT) {