[Qt-creator] How to match function invocation and definition?
dydx
549088764 at qq.com
Tue Nov 5 06:26:50 CET 2013
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20131105/d79bbd95/attachment.html>
More information about the Qt-creator
mailing list