C++: Always assign name to LookupScope

... except the global namespace and blocks

Change-Id: I0696b4997c28b5105a000bae2a9a4fa1a56eb6d3
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-04-09 16:18:13 +03:00
committed by Orgad Shaneh
parent 8a84a7305e
commit e1393c71ab
2 changed files with 12 additions and 19 deletions

View File

@@ -530,7 +530,7 @@ public:
TemplateNameId::Compare> TemplateNameIdTable; TemplateNameId::Compare> TemplateNameIdTable;
typedef QHash<const AnonymousNameId *, LookupScopePrivate *> Anonymouses; typedef QHash<const AnonymousNameId *, LookupScopePrivate *> Anonymouses;
LookupScopePrivate *allocateChild(); LookupScopePrivate *allocateChild(const Name *name);
void flush(); void flush();
@@ -645,9 +645,9 @@ LookupScopePrivate::~LookupScopePrivate()
delete _scopeLookupCache; delete _scopeLookupCache;
} }
LookupScopePrivate *LookupScopePrivate::allocateChild() LookupScopePrivate *LookupScopePrivate::allocateChild(const Name *name)
{ {
LookupScope *e = _factory->allocLookupScope(q); LookupScope *e = _factory->allocLookupScope(q, name);
return e->d; return e->d;
} }
@@ -1125,9 +1125,7 @@ LookupScopePrivate *LookupScopePrivate::findOrCreateNestedAnonymousType(
if (cit != _anonymouses.constEnd()) { if (cit != _anonymouses.constEnd()) {
return cit.value(); return cit.value();
} else { } else {
LookupScopePrivate *newAnonymous = allocateChild(); LookupScopePrivate *newAnonymous = allocateChild(anonymousNameId);
if (Q_UNLIKELY(debug))
newAnonymous->_name = anonymousNameId;
_anonymouses[anonymousNameId] = newAnonymous; _anonymouses[anonymousNameId] = newAnonymous;
return newAnonymous; return newAnonymous;
} }
@@ -1171,9 +1169,7 @@ LookupScopePrivate *LookupScopePrivate::nestedType(
if (cit != reference->_specializations.end()) { if (cit != reference->_specializations.end()) {
return cit->second; return cit->second;
} else { } else {
LookupScopePrivate *newSpecialization = reference->allocateChild(); LookupScopePrivate *newSpecialization = reference->allocateChild(templId);
if (Q_UNLIKELY(debug))
newSpecialization->_name = templId;
reference->_specializations[templId] = newSpecialization; reference->_specializations[templId] = newSpecialization;
return newSpecialization; return newSpecialization;
} }
@@ -1238,9 +1234,7 @@ LookupScopePrivate *LookupScopePrivate::nestedType(
// construct all instantiation data. // construct all instantiation data.
if (templId) { if (templId) {
_alreadyConsideredTemplates.insert(templId); _alreadyConsideredTemplates.insert(templId);
LookupScopePrivate *instantiation = baseTemplateClassReference->allocateChild(); LookupScopePrivate *instantiation = baseTemplateClassReference->allocateChild(templId);
if (Q_UNLIKELY(debug))
instantiation->_name = templId;
while (!origin->_symbols.isEmpty() && origin->_symbols[0]->isBlock()) while (!origin->_symbols.isEmpty() && origin->_symbols[0]->isBlock())
origin = origin->_parent; origin = origin->_parent;
@@ -1441,7 +1435,7 @@ void Instantiator::instantiate(LookupScopePrivate *lookupScope,
nestedLookupScope->flush(); nestedLookupScope->flush();
if (isInstantiationNeeded(nestedLookupScope)) { if (isInstantiationNeeded(nestedLookupScope)) {
nestedInstantiation = nestedLookupScope->allocateChild(); nestedInstantiation = nestedLookupScope->allocateChild(nestedName);
nestedInstantiation->_enums.append(nestedLookupScope->_enums); nestedInstantiation->_enums.append(nestedLookupScope->_enums);
nestedInstantiation->_usings.append(nestedLookupScope->_usings); nestedInstantiation->_usings.append(nestedLookupScope->_usings);
nestedInstantiation->_instantiationOrigin = nestedLookupScope; nestedInstantiation->_instantiationOrigin = nestedLookupScope;
@@ -1565,10 +1559,8 @@ LookupScope *LookupScopePrivate::findOrCreateType(
LookupScopePrivate *e = nestedType(name, origin); LookupScopePrivate *e = nestedType(name, origin);
if (! e) { if (! e) {
e = allocateChild(); e = allocateChild(name);
e->_rootClass = clazz; e->_rootClass = clazz;
if (Q_UNLIKELY(debug))
e->_name = name;
_nestedScopes[name] = e; _nestedScopes[name] = e;
} }
@@ -1585,7 +1577,7 @@ CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snaps
, _control(QSharedPointer<Control>(new Control)) , _control(QSharedPointer<Control>(new Control))
, _expandTemplates(false) , _expandTemplates(false)
{ {
_globalNamespace = allocLookupScope(/*parent = */ 0); _globalNamespace = allocLookupScope(/*parent = */ 0, /*name = */ 0);
_currentLookupScope = _globalNamespace; _currentLookupScope = _globalNamespace;
process(thisDocument); process(thisDocument);
@@ -1645,10 +1637,11 @@ void CreateBindings::process(Symbol *symbol)
_currentLookupScope->d->addTodo(symbol); _currentLookupScope->d->addTodo(symbol);
} }
LookupScope *CreateBindings::allocLookupScope(LookupScope *parent) LookupScope *CreateBindings::allocLookupScope(LookupScope *parent, const Name *name)
{ {
LookupScope *e = new LookupScope(this, parent); LookupScope *e = new LookupScope(this, parent);
e->d->_control = control(); e->d->_control = control();
e->d->_name = name;
_entities.append(e); _entities.append(e);
return e; return e;
} }

View File

@@ -136,7 +136,7 @@ public:
/// Create an empty LookupScope binding with the given \a parent. /// Create an empty LookupScope binding with the given \a parent.
/// \internal /// \internal
LookupScope *allocLookupScope(LookupScope *parent); LookupScope *allocLookupScope(LookupScope *parent, const Name *name);
protected: protected:
using SymbolVisitor::visit; using SymbolVisitor::visit;