Thanks for Nikolai Kosjar's reply in my last e-mail. Now I can get a function's 
declaration when it is invoked. Here's my code.

bool RefVisitor::visit(CallAST *ast)                                      // my 
ASTVisitor
{
    // get candidate types
    CPlusPlus::TypeOfExpression toe;
    toe.init(this->_doc,this->_snapshot);
    toe.setExpandTemplates(true);
    const QList<LookupItem> resolvedSymbols = 
toe.reference(ast,this->_doc,this->_currentScope);

    if (!resolvedSymbols.isEmpty()) 
    {
        LookupItem result = skipForwardDeclarations(resolvedSymbols);

        // find best candidates
        foreach (const LookupItem &r, resolvedSymbols)
        {
            if (Symbol *d = r.declaration()) 
            {
                if (d->isDeclaration() || d->isFunction()) 
                    result = r;
            }
        }
    
        // get complete declarations, stored in cmpDecl
        // following code is adapted from constructor of CppDeclarableElement, 
which is used to get tooltip info.
        QString cmpDecl;
        if (Symbol *d = result.declaration()) 
        {
            Overview overview;
            overview.showArgumentNames = true;
            overview.showReturnTypes = true;
            QString name = overview.prettyName(d->name());
            QString qn;
            if (d->enclosingScope()->isClass() ||
                d->enclosingScope()->isNamespace() ||
                d->enclosingScope()->isEnum()) 
                    qn = 
overview.prettyName(LookupContext::fullyQualifiedName(d));
            else
                cmpDecl = Overview().prettyType(d->type(),qn);
        }

   [Here is some original ast traverse code...]
}

Now I can get a declaration string for a function from cmpDecl.  I think this 
can be used to match the declarations in the .h files, but may not be the best 
idea. So here I want to ask for some other solutions.

(1)As I was told previously, I can get the function/class list by the following 
code:
    CppTools::Internal::CppLocatorData*locD = 
(CppTools::Internal::CppLocatorData*) 
ExtensionSystem::PluginManager::getObjectByClassName("CppTools::Internal::CppLocatorData");
    QList<CppTools::ModelItemInfo>f = locD->functions();
    QList<CppTools::ModelItemInfo>c = locD->classes();

So how to search a specific declaration in the list ?

(2) I also note that the FullySpecifiedType have == operator, will this help me?

Thanks a lot.
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/qt-creator

Reply via email to