Exemple #1
0
std::pair<Utf8String, Utf8String> Diagnostic::options() const
{
    CXString disableString;

    const Utf8String enableOption = ClangString(clang_getDiagnosticOption(cxDiagnostic, &disableString));
    const Utf8String disableOption = ClangString(disableString);

    return {enableOption, disableOption};
}
SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu,
                                                const Cursor &fullCursor,
                                                uint line,
                                                uint column)
{
    std::unique_ptr<Tokens> tokens(new Tokens(fullCursor));

    if (!tokens->tokenCount)
        tokens.reset(new Tokens(tu));

    if (!tokens->tokenCount)
        return SourceRangeContainer();

    QVector<CXCursor> cursors(static_cast<int>(tokens->tokenCount));
    clang_annotateTokens(tu, tokens->data, tokens->tokenCount, cursors.data());
    int tokenIndex = getTokenIndex(tu, *tokens, line, column);
    QTC_ASSERT(tokenIndex >= 0, return SourceRangeContainer());

    const Utf8String tokenSpelling = ClangString(
                clang_getTokenSpelling(tu, tokens->data[tokenIndex]));
    if (tokenSpelling.isEmpty())
        return SourceRangeContainer();

    Cursor cursor{cursors[tokenIndex]};

    if (cursor.kind() == CXCursor_InclusionDirective) {
        CXFile file = clang_getIncludedFile(cursors[tokenIndex]);
        const ClangString filename(clang_getFileName(file));
        const SourceLocation loc(tu, filename, 1, 1);
        return SourceRange(loc, loc);
    }

    // For definitions we can always find a declaration in current TU
    if (cursor.isDefinition())
        return extractMatchingTokenRange(cursor.canonical(), tokenSpelling);

    if (!cursor.isDeclaration()) {
        // This is the symbol usage
        // We want to return definition
        cursor = cursor.referenced();
        if (cursor.isNull() || !cursor.isDefinition()) {
            // We can't find definition in this TU
            return SourceRangeContainer();
        }
        return extractMatchingTokenRange(cursor, tokenSpelling);
    }

    cursor = cursor.definition();
    // If we are able to find a definition in current TU
    if (!cursor.isNull())
        return extractMatchingTokenRange(cursor, tokenSpelling);

    return SourceRangeContainer();
}
SourceLocation::SourceLocation(CXSourceLocation cxSourceLocation)
{
    CXFile cxFile;

    clang_getFileLocation(cxSourceLocation,
                          &cxFile,
                          &line_,
                          &column_,
                          &offset_);

    filePath_ = ClangString(clang_getFileName(cxFile));
}
Exemple #4
0
Utf8String Diagnostic::category() const
{
    return ClangString(clang_getDiagnosticCategoryText(cxDiagnostic));
}
Exemple #5
0
Utf8String Diagnostic::text() const
{
    return ClangString(clang_formatDiagnostic(cxDiagnostic, 0));
}
Utf8String CodeCompletionChunkConverter::chunkText(CXCompletionString completionString, uint chunkIndex)
{
    return ClangString(clang_getCompletionChunkText(completionString, chunkIndex));
}
Exemple #7
0
Utf8String Cursor::rawComment() const
{
    return ClangString(clang_Cursor_getRawCommentText(cxCursor));
}
Exemple #8
0
Utf8String Type::utf8Spelling() const
{
    return  ClangString(clang_getTypeSpelling(m_cxType));
}
Exemple #9
0
Utf8String Cursor::briefComment() const
{
    return ClangString(clang_Cursor_getBriefCommentText(cxCursor));
}
Exemple #10
0
Utf8String Cursor::displayName() const
{
    return ClangString(clang_getCursorDisplayName(cxCursor));
}
Exemple #11
0
ClangString Cursor::spelling() const
{
    return ClangString(clang_getCursorSpelling(cxCursor));
}
Exemple #12
0
Utf8String Cursor::mangling() const
{
    return ClangString(clang_Cursor_getMangling(cxCursor));
}
Exemple #13
0
Utf8String Cursor::unifiedSymbolResolution() const
{
    return ClangString(clang_getCursorUSR(cxCursor));
}