From e3977de08eb5577222f01a9013185b036dee4564 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 5 Dec 2014 11:56:06 +0100 Subject: C++: Finish gcc's include_next support This implements the actual include_next logic and thus completes commit b934cc1 C++: pass #include_next down to CppPreprocessor::tryIncludeFile commmit 140b502 C++: Highlight argument to gcc's #include_next extension Based on https://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html Task-number: QTCREATORBUG-10225 Change-Id: I7eef7f5ea64a114f6d092304d32b72c55c2ce134 Reviewed-by: hjk Reviewed-by: Erik Verbruggen --- src/plugins/cpptools/cppsourceprocessor.cpp | 34 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/plugins/cpptools/cppsourceprocessor.cpp') diff --git a/src/plugins/cpptools/cppsourceprocessor.cpp b/src/plugins/cpptools/cppsourceprocessor.cpp index cd56dae3c9..a8ad8d254a 100644 --- a/src/plugins/cpptools/cppsourceprocessor.cpp +++ b/src/plugins/cpptools/cppsourceprocessor.cpp @@ -272,19 +272,33 @@ QString CppSourceProcessor::resolveFile_helper(const QString &fileName, IncludeT if (QFileInfo(fileName).isAbsolute()) return checkFile(fileName) ? fileName : QString(); - if (type == IncludeLocal && m_currentDoc) { - const QFileInfo currentFileInfo(m_currentDoc->fileName()); - const QString path = cleanPath(currentFileInfo.absolutePath()) + fileName; - if (checkFile(path)) - return path; - // Fall through! "16.2 Source file inclusion" from the standard states to continue - // searching as if this would be a global include. + auto headerPathsIt = m_headerPaths.begin(); + auto headerPathsEnd = m_headerPaths.end(); + if (m_currentDoc) { + if (type == IncludeLocal) { + const QFileInfo currentFileInfo(m_currentDoc->fileName()); + const QString path = cleanPath(currentFileInfo.absolutePath()) + fileName; + if (checkFile(path)) + return path; + // Fall through! "16.2 Source file inclusion" from the standard states to continue + // searching as if this would be a global include. + + } else if (type == IncludeNext) { + const QFileInfo currentFileInfo(m_currentDoc->fileName()); + const QString currentDirPath = cleanPath(currentFileInfo.dir().path()); + for (; headerPathsIt != headerPathsEnd; ++headerPathsIt) { + if (headerPathsIt->path == currentDirPath) { + ++headerPathsIt; + break; + } + } + } } - foreach (const ProjectPart::HeaderPath &headerPath, m_headerPaths) { - if (headerPath.isFrameworkPath()) + for (; headerPathsIt != headerPathsEnd; ++headerPathsIt) { + if (headerPathsIt->isFrameworkPath()) continue; - const QString path = headerPath.path + fileName; + const QString path = headerPathsIt->path + fileName; if (m_workingCopy.contains(path) || checkFile(path)) return path; } -- cgit v1.2.1