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