File indexing completed on 2024-05-12 04:39:11
0001 /* 0002 SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "clangparsingenvironment.h" 0008 0009 using namespace KDevelop; 0010 0011 int ClangParsingEnvironment::type() const 0012 { 0013 return CppParsingEnvironment; 0014 } 0015 0016 void ClangParsingEnvironment::setProjectPaths(const Path::List& projectPaths) 0017 { 0018 m_projectPaths = projectPaths; 0019 } 0020 0021 Path::List ClangParsingEnvironment::projectPaths() const 0022 { 0023 return m_projectPaths; 0024 } 0025 0026 void ClangParsingEnvironment::addIncludes(const Path::List& includes) 0027 { 0028 m_includes += includes; 0029 } 0030 0031 void ClangParsingEnvironment::addFrameworkDirectories(const KDevelop::Path::List& frameworkDirectories) 0032 { 0033 m_frameworkDirectories += frameworkDirectories; 0034 } 0035 0036 template <typename PathType> 0037 static PathType appendPaths(const KDevelop::Path::List &paths, const KDevelop::Path::List &projectPaths) 0038 { 0039 PathType ret; 0040 ret.project.reserve(paths.size()); 0041 ret.system.reserve(paths.size()); 0042 for (const auto& path : paths) { 0043 bool inProject = false; 0044 for (const auto& project : projectPaths) { 0045 if (project.isParentOf(path) || project == path) { 0046 inProject = true; 0047 break; 0048 } 0049 } 0050 if (inProject) { 0051 ret.project.append(path); 0052 } else { 0053 ret.system.append(path); 0054 } 0055 } 0056 return ret; 0057 } 0058 0059 ClangParsingEnvironment::IncludePaths ClangParsingEnvironment::includes() const 0060 { 0061 return appendPaths<IncludePaths>(m_includes, m_projectPaths); 0062 } 0063 0064 ClangParsingEnvironment::FrameworkDirectories ClangParsingEnvironment::frameworkDirectories() const 0065 { 0066 return appendPaths<FrameworkDirectories>(m_frameworkDirectories, m_projectPaths); 0067 } 0068 0069 void ClangParsingEnvironment::addDefines(const QHash<QString, QString>& defines) 0070 { 0071 for (auto it = defines.constBegin(); it != defines.constEnd(); ++it) { 0072 m_defines[it.key()] = it.value(); 0073 } 0074 } 0075 0076 QMap<QString, QString> ClangParsingEnvironment::defines() const 0077 { 0078 return m_defines; 0079 } 0080 0081 void ClangParsingEnvironment::setPchInclude(const Path& path) 0082 { 0083 m_pchInclude = path; 0084 } 0085 0086 Path ClangParsingEnvironment::pchInclude() const 0087 { 0088 return m_pchInclude; 0089 } 0090 0091 void ClangParsingEnvironment::setWorkingDirectory(const Path& path) 0092 { 0093 m_workingDirectory = path; 0094 } 0095 0096 Path ClangParsingEnvironment::workingDirectory() const 0097 { 0098 return m_workingDirectory; 0099 } 0100 0101 void ClangParsingEnvironment::setTranslationUnitUrl(const IndexedString& url) 0102 { 0103 m_tuUrl = url; 0104 } 0105 0106 IndexedString ClangParsingEnvironment::translationUnitUrl() const 0107 { 0108 return m_tuUrl; 0109 } 0110 0111 void ClangParsingEnvironment::setQuality(Quality quality) 0112 { 0113 m_quality = quality; 0114 } 0115 0116 ClangParsingEnvironment::Quality ClangParsingEnvironment::quality() const 0117 { 0118 return m_quality; 0119 } 0120 0121 uint ClangParsingEnvironment::hash() const 0122 { 0123 KDevHash hash; 0124 hash << m_defines.size(); 0125 0126 for (auto it = m_defines.constBegin(); it != m_defines.constEnd(); ++it) { 0127 hash << qHash(it.key()) << qHash(it.value()); 0128 } 0129 0130 hash << m_includes.size(); 0131 for (const auto& include : m_includes) { 0132 hash << qHash(include); 0133 } 0134 0135 hash << m_frameworkDirectories.size(); 0136 for (const auto& fwDir : m_frameworkDirectories) { 0137 hash << qHash(fwDir); 0138 } 0139 0140 hash << qHash(m_pchInclude); 0141 hash << qHash(m_parserSettings.parserOptions); 0142 return hash; 0143 } 0144 0145 bool ClangParsingEnvironment::operator==(const ClangParsingEnvironment& other) const 0146 { 0147 return m_defines == other.m_defines 0148 && m_includes == other.m_includes 0149 && m_frameworkDirectories == other.m_frameworkDirectories 0150 && m_pchInclude == other.m_pchInclude 0151 && m_quality == other.m_quality 0152 && m_tuUrl == other.m_tuUrl 0153 && m_parserSettings == other.m_parserSettings; 0154 } 0155 0156 void ClangParsingEnvironment::setParserSettings(const ParserSettings& parserSettings) 0157 { 0158 m_parserSettings = parserSettings; 0159 } 0160 0161 ParserSettings ClangParsingEnvironment::parserSettings() const 0162 { 0163 return m_parserSettings; 0164 } 0165 0166 void ClangParsingEnvironment::addParserArguments(const QString& parserArguments) 0167 { 0168 m_parserSettings.parserOptions += QLatin1Char(' ') + parserArguments; 0169 } 0170