diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp')
-rw-r--r-- | sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp index 8cf35641b..da6930476 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "clangparser.h" #include "clangutils.h" @@ -38,6 +13,8 @@ #include <QtCore/QScopedArrayPointer> #include <QtCore/QString> +using namespace Qt::StringLiterals; + namespace clang { QString SourceFileCache::getFileName(CXFile file) @@ -64,7 +41,7 @@ std::string_view SourceFileCache::getCodeSnippet(const CXCursor &cursor, if (range.first.file != range.second.file) { if (errorMessage) - *errorMessage = QStringLiteral("Range spans several files"); + *errorMessage = "Range spans several files"_L1; return std::string_view(empty, 0); } @@ -73,7 +50,7 @@ std::string_view SourceFileCache::getCodeSnippet(const CXCursor &cursor, const QString fileName = getFileName(range.first.file); if (fileName.isEmpty()) { if (errorMessage) - *errorMessage = QStringLiteral("Range has no file"); + *errorMessage = "Range has no file"_L1; return std::string_view(empty, 0); } QFile file(fileName); @@ -108,9 +85,9 @@ std::string_view SourceFileCache::getCodeSnippet(const CXCursor &cursor, BaseVisitor::BaseVisitor() = default; BaseVisitor::~BaseVisitor() = default; -bool BaseVisitor::visitLocation(const CXSourceLocation &location) const +bool BaseVisitor::visitLocation(const QString &, LocationType locationType) const { - return clang_Location_isFromMainFile(location) != 0; + return locationType != LocationType::System; } BaseVisitor::StartTokenResult BaseVisitor::cbHandleStartToken(const CXCursor &cursor) @@ -148,6 +125,34 @@ std::string_view BaseVisitor::getCodeSnippet(const CXCursor &cursor) return result; } +bool BaseVisitor::_handleVisitLocation(const CXSourceLocation &location) +{ + CXFile cxFile; // void * + unsigned line; + unsigned column; + unsigned offset; + clang_getExpansionLocation(location, &cxFile, &line, &column, &offset); + + if (cxFile == m_currentCxFile) // Same file? + return m_visitCurrent; + + const QString fileName = getFileName(cxFile); + + LocationType locationType = LocationType::Unknown; + if (!fileName.isEmpty()) { + if (clang_Location_isFromMainFile(location) != 0) + locationType = LocationType::Main; + else if (clang_Location_isInSystemHeader(location) != 0) + locationType = LocationType::System; + else + locationType = LocationType::Other; + } + + m_currentCxFile = cxFile; + m_visitCurrent = visitLocation(fileName, locationType); + return m_visitCurrent; +} + QString BaseVisitor::getCodeSnippetString(const CXCursor &cursor) { const std::string_view result = getCodeSnippet(cursor); @@ -162,7 +167,7 @@ static CXChildVisitResult auto *bv = reinterpret_cast<BaseVisitor *>(clientData); const CXSourceLocation location = clang_getCursorLocation(cursor); - if (!bv->visitLocation(location)) + if (!bv->_handleVisitLocation(location)) return CXChildVisit_Continue; const BaseVisitor::StartTokenResult startResult = bv->cbHandleStartToken(cursor); @@ -210,9 +215,9 @@ static QByteArray msgCreateTranslationUnit(const QByteArrayList &clangArgs, unsi { QByteArray result = "clang_parseTranslationUnit2(0x"; result += QByteArray::number(flags, 16); - const int count = clangArgs.size(); + const auto count = clangArgs.size(); result += ", cmd[" + QByteArray::number(count) + "]="; - for (int i = 0; i < count; ++i) { + for (qsizetype i = 0; i < count; ++i) { const QByteArray &arg = clangArgs.at(i); if (i) result += ' '; @@ -243,7 +248,9 @@ static CXTranslationUnit createTranslationUnit(CXIndex index, "-Wno-expansion-to-defined", // Workaround for warnings in Darwin stdlib, see // https://github.com/darlinghq/darling/issues/204 #endif - "-Wno-constant-logical-operand" + "-Wno-constant-logical-operand", + "-x", + "c++" // Treat .h as C++, not C }; QByteArrayList clangArgs; @@ -251,6 +258,7 @@ static CXTranslationUnit createTranslationUnit(CXIndex index, clangArgs += emulatedCompilerOptions(); clangArgs += defaultArgs; } + clangArgs += detectVulkan(); clangArgs += args; QScopedArrayPointer<const char *> argv(byteArrayListToFlatArgV(clangArgs)); qDebug().noquote().nospace() << msgCreateTranslationUnit(clangArgs, flags); @@ -302,7 +310,7 @@ bool parse(const QByteArrayList &clangArgs, bool addCompilerSupportArguments, debug.nospace(); debug << "Errors in " << QDir::toNativeSeparators(QFile::decodeName(clangArgs.constLast())) << ":\n"; - for (const Diagnostic &diagnostic : qAsConst(diagnostics)) + for (const Diagnostic &diagnostic : std::as_const(diagnostics)) debug << diagnostic << '\n'; } |