Commit 0c167570 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

C++: Remember the class a ClassOrNamespace is based on



Change-Id: I0d333ff9489e46c4fa1923d70ca950f67ffa3f44
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 03270ad3
......@@ -529,6 +529,7 @@ ClassOrNamespace::ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *pa
, _scopeLookupCache(0)
, _templateId(0)
, _instantiationOrigin(0)
, _rootClass(0)
#ifdef DEBUG_LOOKUP
, _name(0)
#endif // DEBUG_LOOKUP
......@@ -1067,6 +1068,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
instantiation->_enums.append(reference->unscopedEnums());
instantiation->_usings.append(reference->usings());
instantiation->_rootClass = reference->rootClass();
// It gets a bit complicated if the reference is actually a class template because we
// now must worry about dependent names in base classes.
if (Template *templateSpecialization = referenceClass->enclosingTemplate()) {
......@@ -1347,7 +1350,8 @@ void ClassOrNamespace::addNestedType(const Name *alias, ClassOrNamespace *e)
_classOrNamespaces[alias] = e;
}
ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name, ClassOrNamespace *origin)
ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name, ClassOrNamespace *origin,
Class *clazz)
{
if (! name)
return this;
......@@ -1356,15 +1360,16 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name, ClassOrNa
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
if (! q->base())
return globalNamespace()->findOrCreateType(q->name(), origin);
return globalNamespace()->findOrCreateType(q->name(), origin, clazz);
return findOrCreateType(q->base(), origin)->findOrCreateType(q->name(), origin);
return findOrCreateType(q->base(), origin)->findOrCreateType(q->name(), origin, clazz);
} else if (name->isNameId() || name->isTemplateNameId() || name->isAnonymousNameId()) {
ClassOrNamespace *e = nestedType(name, origin);
if (! e) {
e = _factory->allocClassOrNamespace(this);
e->_rootClass = clazz;
#ifdef DEBUG_LOOKUP
e->_name = name;
#endif // DEBUG_LOOKUP
......@@ -1470,7 +1475,8 @@ void CreateBindings::process(Document::Ptr doc)
ClassOrNamespace *CreateBindings::enterClassOrNamespaceBinding(Symbol *symbol)
{
ClassOrNamespace *entity = _currentClassOrNamespace->findOrCreateType(symbol->name());
ClassOrNamespace *entity = _currentClassOrNamespace->findOrCreateType(symbol->name(), 0,
symbol->asClass());
entity->addSymbol(symbol);
return switchCurrentClassOrNamespace(entity);
......@@ -1478,7 +1484,8 @@ ClassOrNamespace *CreateBindings::enterClassOrNamespaceBinding(Symbol *symbol)
ClassOrNamespace *CreateBindings::enterGlobalClassOrNamespace(Symbol *symbol)
{
ClassOrNamespace *entity = _globalNamespace->findOrCreateType(symbol->name());
ClassOrNamespace *entity = _globalNamespace->findOrCreateType(symbol->name(), 0,
symbol->asClass());
entity->addSymbol(symbol);
return switchCurrentClassOrNamespace(entity);
......@@ -1516,7 +1523,7 @@ bool CreateBindings::visit(Class *klass)
binding = _currentClassOrNamespace->lookupType(klass->name());
if (! binding)
binding = _currentClassOrNamespace->findOrCreateType(klass->name());
binding = _currentClassOrNamespace->findOrCreateType(klass->name(), 0, klass);
_currentClassOrNamespace = binding;
_currentClassOrNamespace->addSymbol(klass);
......@@ -1568,7 +1575,8 @@ bool CreateBindings::visit(Declaration *decl)
}
} else if (Class *klass = ty->asClassType()) {
if (const Identifier *nameId = decl->name()->asNameId()) {
ClassOrNamespace *binding = _currentClassOrNamespace->findOrCreateType(nameId);
ClassOrNamespace *binding
= _currentClassOrNamespace->findOrCreateType(nameId, 0, klass);
binding->addSymbol(klass);
}
}
......
......@@ -87,6 +87,9 @@ public:
Symbol *lookupInScope(const QList<const Name *> &fullName);
/// The class this ClassOrNamespace is based on.
Class *rootClass() const { return _rootClass; }
private:
typedef std::map<const Name *, ClassOrNamespace *, Name::Compare> Table;
typedef std::map<const TemplateNameId *, ClassOrNamespace *, TemplateNameId::Compare> TemplateNameIdTable;
......@@ -95,7 +98,8 @@ private:
void flush();
/// \internal
ClassOrNamespace *findOrCreateType(const Name *name, ClassOrNamespace *origin = 0);
ClassOrNamespace *findOrCreateType(const Name *name, ClassOrNamespace *origin = 0,
Class *clazz = 0);
void addTodo(Symbol *symbol);
void addSymbol(Symbol *symbol);
......@@ -145,6 +149,8 @@ private:
AlreadyConsideredClassContainer<Class> _alreadyConsideredClasses;
AlreadyConsideredClassContainer<TemplateNameId> _alreadyConsideredTemplates;
Class *_rootClass;
class NestedClassInstantiator
{
public:
......
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