MCPcopy Create free account
hub / github.com/KDAB/codebrowser / handleInvokeMethod

Method handleInvokeMethod

generator/qtsupport.cpp:266–292  ·  view source on GitHub ↗

* Very similar to handleSignalOrSlot, but does not handle the fact that the string might be in a macro * and does the string contains the method name and not the full signature * \a obj is an expression to a type of an QObject (or pointer to) that is the sender or the receiver * \a method is an expression of type char* * * TODO: handle overloads */

Source from the content-addressed store, hash-verified

264 * TODO: handle overloads
265 */
266void QtSupport::handleInvokeMethod(clang::Expr* obj, clang::Expr* method)
267{
268 if (!obj || !method) return;
269 obj = obj->IgnoreImpCasts();
270 method = method->IgnoreImpCasts();
271 auto objType = obj->getType().getTypePtrOrNull();
272 if (!objType) return;
273 const clang::CXXRecordDecl* objClass = objType->getPointeeCXXRecordDecl();
274 if (!objClass) return;
275
276 const clang::StringLiteral *methodLiteral = clang::dyn_cast<clang::StringLiteral>(method);
277 if (!methodLiteral) return;
278 if (methodLiteral->getCharByteWidth() != 1) return;
279
280 auto methodName = methodLiteral->getString();
281 if (methodName.empty()) return;
282
283 // Try to find the method which match this name in the given class or bases.
284 auto candidates = lookUpCandidates(objClass, methodName);
285 if (candidates.size() != 1)
286 return;
287 // FIXME: overloads resolution using the Q_ARG
288
289 auto used = candidates.front();
290 clang::SourceRange range = methodLiteral->getSourceRange();
291 annotator.registerUse(used, range, Annotator::Call, currentContext, Annotator::Use_Address);
292}
293
294void QtSupport::visitCallExpr(clang::CallExpr* e)
295{

Callers

nothing calls this directly

Calls 3

lookUpCandidatesFunction · 0.85
registerUseMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected