| 1516 | } |
| 1517 | |
| 1518 | RangeInRevision rangeInRevisionForUse(CXCursor cursor, CXCursorKind referencedCursorKind, CXSourceRange useRange, const QSet<unsigned int>& macroExpansionLocations) |
| 1519 | { |
| 1520 | auto range = ClangRange(useRange).toRangeInRevision(); |
| 1521 | |
| 1522 | //TODO: Fix in clang, happens for operator<<, operator<, probably more |
| 1523 | if (clang_Range_isNull(useRange)) { |
| 1524 | useRange = clang_getCursorExtent(cursor); |
| 1525 | range = ClangRange(useRange).toRangeInRevision(); |
| 1526 | } |
| 1527 | |
| 1528 | if (referencedCursorKind == CXCursor_ConversionFunction) { |
| 1529 | range.end = range.start; |
| 1530 | range.start.column--; |
| 1531 | } |
| 1532 | |
| 1533 | // For uses inside macro expansions, `useRange` is the whole macro use |
| 1534 | // from the macro identifier up to the closing parenthesis. In order not to interfere with |
| 1535 | // code navigation at the macro use location, we make it an empty range at its beginning. |
| 1536 | // also see JSON test 'macros.cpp' |
| 1537 | if (clang_getCursorKind(cursor) != CXCursor_MacroExpansion) { |
| 1538 | unsigned int expansionLocOffset; |
| 1539 | const auto useRangeStart = clang_getRangeStart(useRange); |
| 1540 | clang_getExpansionLocation(useRangeStart, nullptr, nullptr, nullptr, &expansionLocOffset); |
| 1541 | if (macroExpansionLocations.contains(expansionLocOffset)) { |
| 1542 | unsigned int fileLocOffset; |
| 1543 | clang_getFileLocation(useRangeStart, nullptr, nullptr, nullptr, &fileLocOffset); |
| 1544 | if (fileLocOffset == expansionLocOffset) { |
| 1545 | range.end = range.start; |
| 1546 | } |
| 1547 | } |
| 1548 | } else { |
| 1549 | // Workaround for wrong use range returned by clang for macro expansions |
| 1550 | const auto contents = ClangUtils::getRawContents(clang_Cursor_getTranslationUnit(cursor), useRange); |
| 1551 | const int firstOpeningParen = contents.indexOf(QLatin1Char('(')); |
| 1552 | if (firstOpeningParen != -1) { |
| 1553 | range.end.column = range.start.column + firstOpeningParen; |
| 1554 | range.end.line = range.start.line; |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | return range; |
| 1559 | } |
| 1560 | |
| 1561 | Visitor::Visitor(CXTranslationUnit tu, CXFile file, |
| 1562 | const IncludeFileContexts& includes, const bool update) |
no test coverage detected