Commit b84611e1 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

C++: Enable runtime lookup debug...

... by setting the environment variable QTC_LOOKUPCONTEXT_DEBUG

Change-Id: Ia46f55b2989129d5327d894734b6ea9c77c3e0ac
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 252048ef
...@@ -48,10 +48,7 @@ ...@@ -48,10 +48,7 @@
using namespace CPlusPlus; using namespace CPlusPlus;
namespace { static const bool debug = ! qgetenv("QTC_LOOKUPCONTEXT_DEBUG").isEmpty();
const bool debug = ! qgetenv("CPLUSPLUS_LOOKUPCONTEXT_DEBUG").isEmpty();
} // end of anonymous namespace
static void addNames(const Name *name, QList<const Name *> *names, bool addAllNames = false) static void addNames(const Name *name, QList<const Name *> *names, bool addAllNames = false)
{ {
...@@ -314,10 +311,10 @@ ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope, ...@@ -314,10 +311,10 @@ ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope,
} else if (Declaration *d = m->asDeclaration()) { } else if (Declaration *d = m->asDeclaration()) {
if (d->name() && d->name()->match(name->asNameId())) { if (d->name() && d->name()->match(name->asNameId())) {
if (d->isTypedef() && d->type()) { if (d->isTypedef() && d->type()) {
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug)) {
Overview oo; Overview oo;
qDebug() << "Looks like" << oo(name) << "is a typedef for" << oo(d->type()); qDebug() << "Looks like" << oo(name) << "is a typedef for" << oo(d->type());
#endif // DEBUG_LOOKUP }
if (const NamedType *namedTy = d->type()->asNamedType()) { if (const NamedType *namedTy = d->type()->asNamedType()) {
// Stop on recursive typedef declarations // Stop on recursive typedef declarations
if (typedefsBeingResolved.contains(d)) if (typedefsBeingResolved.contains(d))
...@@ -517,9 +514,7 @@ ClassOrNamespace::ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *pa ...@@ -517,9 +514,7 @@ ClassOrNamespace::ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *pa
, _templateId(0) , _templateId(0)
, _instantiationOrigin(0) , _instantiationOrigin(0)
, _rootClass(0) , _rootClass(0)
#ifdef DEBUG_LOOKUP
, _name(0) , _name(0)
#endif // DEBUG_LOOKUP
{ {
Q_ASSERT(factory); Q_ASSERT(factory);
} }
...@@ -715,11 +710,11 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope, ...@@ -715,11 +710,11 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
else if (s->name()->isQualifiedNameId()) else if (s->name()->isQualifiedNameId())
continue; // skip qualified ids. continue; // skip qualified ids.
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug)) {
Overview oo; Overview oo;
qDebug() << "Found" << id->chars() << "in" qDebug() << "Found" << id->chars() << "in"
<< (binding ? oo(binding->_name) : QString::fromLatin1("<null>")); << (binding ? oo(binding->_name) : QString::fromLatin1("<null>"));
#endif // DEBUG_LOOKUP }
LookupItem item; LookupItem item;
item.setDeclaration(s); item.setDeclaration(s);
...@@ -833,10 +828,10 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name, ...@@ -833,10 +828,10 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
bool searchInEnclosingScope, bool searchInEnclosingScope,
ClassOrNamespace *origin) ClassOrNamespace *origin)
{ {
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug)) {
Overview oo; Overview oo;
qDebug() << "Looking up" << oo(name) << "in" << oo(_name); qDebug() << "Looking up" << oo(name) << "in" << oo(_name);
#endif // DEBUG_LOOKUP }
if (const QualifiedNameId *q = name->asQualifiedNameId()) { if (const QualifiedNameId *q = name->asQualifiedNameId()) {
...@@ -878,10 +873,9 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name, ...@@ -878,10 +873,9 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
/*searchInEnclosingScope = */ true, /*searchInEnclosingScope = */ true,
origin)) origin))
return r; return r;
} else { } else if (Q_UNLIKELY(debug)) {
if (debug) qWarning() << "expected one using declaration. Number of using declarations is:"
qWarning() << "expected one using declaration. Number of using declarations is:" << _usings.size();
<< _usings.size();
} }
} }
...@@ -950,9 +944,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -950,9 +944,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
return cit.value(); return cit.value();
} else { } else {
ClassOrNamespace *newAnonymous = _factory->allocClassOrNamespace(this); ClassOrNamespace *newAnonymous = _factory->allocClassOrNamespace(this);
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
newAnonymous->_name = anonymousNameId; newAnonymous->_name = anonymousNameId;
#endif // DEBUG_LOOKUP
_anonymouses[anonymousNameId] = newAnonymous; _anonymouses[anonymousNameId] = newAnonymous;
return newAnonymous; return newAnonymous;
} }
...@@ -985,9 +978,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -985,9 +978,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
return cit->second; return cit->second;
} else { } else {
ClassOrNamespace *newSpecialization = _factory->allocClassOrNamespace(reference); ClassOrNamespace *newSpecialization = _factory->allocClassOrNamespace(reference);
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
newSpecialization->_name = templId; newSpecialization->_name = templId;
#endif // DEBUG_LOOKUP
reference->_specializations[templId] = newSpecialization; reference->_specializations[templId] = newSpecialization;
return newSpecialization; return newSpecialization;
} }
...@@ -1054,9 +1046,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -1054,9 +1046,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
if (templId) { if (templId) {
_alreadyConsideredTemplates.insert(templId); _alreadyConsideredTemplates.insert(templId);
ClassOrNamespace *instantiation = _factory->allocClassOrNamespace(baseTemplateClassReference); ClassOrNamespace *instantiation = _factory->allocClassOrNamespace(baseTemplateClassReference);
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
instantiation->_name = templId; instantiation->_name = templId;
#endif // DEBUG_LOOKUP
instantiation->_templateId = templId; instantiation->_templateId = templId;
while (!origin->_symbols.isEmpty() && origin->_symbols[0]->isBlock()) while (!origin->_symbols.isEmpty() && origin->_symbols[0]->isBlock())
...@@ -1100,22 +1091,23 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -1100,22 +1091,23 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
Symbol *clone = cloner.symbol(s, &subst); Symbol *clone = cloner.symbol(s, &subst);
clone->setEnclosingScope(s->enclosingScope()); clone->setEnclosingScope(s->enclosingScope());
instantiation->_symbols.append(clone); instantiation->_symbols.append(clone);
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug)) {
Overview oo;oo.showFunctionSignatures = true; Overview oo;
oo.showReturnTypes = true; oo.showFunctionSignatures = true;
oo.showTemplateParameters = true; oo.showReturnTypes = true;
qDebug()<<"cloned"<<oo(clone->type()); oo.showTemplateParameters = true;
if (Class *klass = s->asClass()) { qDebug() << "cloned" << oo(clone->type());
const unsigned klassMemberCount = klass->memberCount(); if (Class *klass = s->asClass()) {
for (unsigned i = 0; i < klassMemberCount; ++i){ const unsigned klassMemberCount = klass->memberCount();
Symbol *klassMemberAsSymbol = klass->memberAt(i); for (unsigned i = 0; i < klassMemberCount; ++i){
if (klassMemberAsSymbol->isTypedef()) { Symbol *klassMemberAsSymbol = klass->memberAt(i);
if (Declaration *declaration = klassMemberAsSymbol->asDeclaration()) if (klassMemberAsSymbol->isTypedef()) {
qDebug() << "Member: " << oo(declaration->type(), declaration->name()); if (Declaration *declaration = klassMemberAsSymbol->asDeclaration())
qDebug() << "Member: " << oo(declaration->type(), declaration->name());
}
} }
} }
} }
#endif // DEBUG_LOOKUP
} }
instantiateNestedClasses(reference, cloner, subst, instantiation); instantiateNestedClasses(reference, cloner, subst, instantiation);
} else { } else {
...@@ -1369,9 +1361,8 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name, ClassOrNa ...@@ -1369,9 +1361,8 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name, ClassOrNa
if (! e) { if (! e) {
e = _factory->allocClassOrNamespace(this); e = _factory->allocClassOrNamespace(this);
e->_rootClass = clazz; e->_rootClass = clazz;
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
e->_name = name; e->_name = name;
#endif // DEBUG_LOOKUP
_classOrNamespaces[name] = e; _classOrNamespaces[name] = e;
} }
......
...@@ -178,10 +178,8 @@ private: ...@@ -178,10 +178,8 @@ private:
Subst &_subst; Subst &_subst;
}; };
#ifdef DEBUG_LOOKUP
public: public:
const Name *_name; const Name *_name; // For debug
#endif // DEBUG_LOOKUP
friend class CreateBindings; friend class CreateBindings;
}; };
......
...@@ -54,6 +54,8 @@ ...@@ -54,6 +54,8 @@
using namespace CPlusPlus; using namespace CPlusPlus;
static const bool debug = ! qgetenv("QTC_LOOKUPCONTEXT_DEBUG").isEmpty();
namespace { namespace {
template <typename _Tp> template <typename _Tp>
...@@ -898,9 +900,8 @@ public: ...@@ -898,9 +900,8 @@ public:
for (NamedType *namedTy = 0; maxDepth && (namedTy = getNamedType(*type)); --maxDepth) { for (NamedType *namedTy = 0; maxDepth && (namedTy = getNamedType(*type)); --maxDepth) {
QList<LookupItem> namedTypeItems = getNamedTypeItems(namedTy->name(), *scope, _binding); QList<LookupItem> namedTypeItems = getNamedTypeItems(namedTy->name(), *scope, _binding);
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
qDebug() << "-- we have" << namedTypeItems.size() << "candidates"; qDebug() << "-- we have" << namedTypeItems.size() << "candidates";
#endif // DEBUG_LOOKUP
if (!findTypedef(namedTypeItems, type, scope, visited)) if (!findTypedef(namedTypeItems, type, scope, visited))
break; break;
...@@ -1012,11 +1013,10 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas ...@@ -1012,11 +1013,10 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
int accessOp, int accessOp,
bool *replacedDotOperator) const bool *replacedDotOperator) const
{ {
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
qDebug() << "In ResolveExpression::baseExpression with" << baseResults.size() << "results..."; qDebug() << "In ResolveExpression::baseExpression with" << baseResults.size() << "results...";
int i = 0; int i = 0;
Overview oo; Overview oo;
#endif // DEBUG_LOOKUP
TypedefsResolver typedefsResolver(_context); TypedefsResolver typedefsResolver(_context);
foreach (const LookupItem &r, baseResults) { foreach (const LookupItem &r, baseResults) {
...@@ -1026,16 +1026,15 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas ...@@ -1026,16 +1026,15 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
FullySpecifiedType originalType = ty; FullySpecifiedType originalType = ty;
Scope *scope = r.scope(); Scope *scope = r.scope();
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug)) {
qDebug("trying result #%d", ++i); qDebug("trying result #%d", ++i);
qDebug()<<"- before typedef resolving we have:"<<oo(ty); qDebug() << "- before typedef resolving we have:" << oo(ty);
#endif // DEBUG_LOOKUP }
typedefsResolver.resolve(&ty, &scope, r.binding()); typedefsResolver.resolve(&ty, &scope, r.binding());
#ifdef DEBUG_LOOKUP if (Q_UNLIKELY(debug))
qDebug()<<"- after typedef resolving:"<<oo(ty); qDebug() << "- after typedef resolving:" << oo(ty);
#endif // DEBUG_LOOKUP
if (accessOp == T_ARROW) { if (accessOp == T_ARROW) {
if (PointerType *ptrTy = ty->asPointerType()) { if (PointerType *ptrTy = ty->asPointerType()) {
......
DEFINES += NDEBUG DEFINES += NDEBUG
#DEFINES += DEBUG_LOOKUP
unix:QMAKE_CXXFLAGS_DEBUG += -O2 unix:QMAKE_CXXFLAGS_DEBUG += -O2
win32:QMAKE_CXXFLAGS_DEBUG += -O2 win32:QMAKE_CXXFLAGS_DEBUG += -O2
......
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