/**************************************************************************** ** ** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 as published by the Free Software ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ****************************************************************************/ #include "clangoverviewmodel.h" #include "clangeditordocumentprocessor.h" #include "clangutils.h" #include #include #include #include using TokenContainer = ClangBackEnd::TokenInfoContainer; using TokenContainers = QVector; namespace ClangCodeModel { namespace Internal { static bool contains(const ClangBackEnd::SourceRangeContainer &range, unsigned line, unsigned column) { if (line < range.start().line() || line > range.end().line()) return false; if (line == range.start().line() && column < range.start().column()) return false; if (line == range.end().line() && column > range.end().column()) return false; return true; } static bool contains(const ClangBackEnd::SourceRangeContainer &range, const ClangBackEnd::SourceLocationContainer &location) { return contains(range, location.line(), location.column()); } void buildTree(TokenContainers::const_iterator containersBegin, TokenContainers::const_iterator containersEnd, TokenTreeItem *parent, bool isRoot = false) { for (auto it = containersBegin; it != containersEnd;) { if (!it->extraInfo().declaration) { ++it; continue; } if (it->types().mainHighlightingType == ClangBackEnd::HighlightingType::LocalVariable) { ++it; continue; } auto *item = new TokenTreeItem(*it); parent->appendChild(item); const auto &range = it->extraInfo().cursorRange; ++it; auto innerIt = it; for (; innerIt != containersEnd; ++innerIt) { if (!innerIt->extraInfo().declaration) continue; if (innerIt->types().mainHighlightingType == ClangBackEnd::HighlightingType::LocalVariable) { continue; } const auto &start = innerIt->extraInfo().cursorRange.start(); if (!contains(range, start)) { break; } } if (innerIt != it) { buildTree(it, innerIt, item); it = innerIt; } } if (isRoot) { ClangBackEnd::ExtraInfo extraInfo; if (!parent->childCount()) { extraInfo.token = Utf8String::fromString( QString(QT_TRANSLATE_NOOP("ClangCodeModel", ""))); } else { extraInfo.token = Utf8String::fromString( QString(QT_TRANSLATE_NOOP("ClangCodeModel", "