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 #ifndef CLANGPARSINGENVIRONMENT_H
0008 #define CLANGPARSINGENVIRONMENT_H
0009 
0010 #include <util/path.h>
0011 #include <language/duchain/parsingenvironment.h>
0012 
0013 #include "clangprivateexport.h"
0014 
0015 #include "clangsettings/clangsettingsmanager.h"
0016 
0017 class KDEVCLANGPRIVATE_EXPORT ClangParsingEnvironment : public KDevelop::ParsingEnvironment
0018 {
0019 public:
0020     ~ClangParsingEnvironment() override = default;
0021     int type() const override;
0022 
0023     /**
0024      * Sets the list of project paths.
0025      *
0026      * Any include path outside these project paths is considered
0027      * to be a system include.
0028      */
0029     void setProjectPaths(const KDevelop::Path::List& projectPaths);
0030     KDevelop::Path::List projectPaths() const;
0031 
0032     /**
0033      * Add the given list of @p include paths to this environment.
0034      */
0035     void addIncludes(const KDevelop::Path::List& includes);
0036 
0037     /**
0038      * Add the given list of @p framework-directories to this environment.
0039      */
0040     void addFrameworkDirectories(const KDevelop::Path::List& frameworkDirectories);
0041 
0042     struct IncludePaths
0043     {
0044         /// This list contains all include paths outside the known projects paths.
0045         KDevelop::Path::List system;
0046         /// This list contains all include paths inside the known projects paths.
0047         KDevelop::Path::List project;
0048     };
0049     /**
0050      * Returns the list of includes, split into a list of system includes and project includes.
0051      */
0052     IncludePaths includes() const;
0053 
0054     struct FrameworkDirectories
0055     {
0056         /// This list contains all framework directories outside the known projects paths.
0057         KDevelop::Path::List system;
0058         /// This list contains all framework directories inside the known projects paths.
0059         KDevelop::Path::List project;
0060     };
0061     /**
0062      * Returns the list of framework directories, split into a list of system paths and project paths.
0063      */
0064     FrameworkDirectories frameworkDirectories() const;
0065 
0066     void addDefines(const QHash<QString, QString>& defines);
0067     QMap<QString, QString> defines() const;
0068 
0069     void setPchInclude(const KDevelop::Path& path);
0070     KDevelop::Path pchInclude() const;
0071 
0072     void setWorkingDirectory(const KDevelop::Path& path);
0073     KDevelop::Path workingDirectory() const;
0074 
0075     void setTranslationUnitUrl(const KDevelop::IndexedString& url);
0076     KDevelop::IndexedString translationUnitUrl() const;
0077 
0078     enum Quality
0079     {
0080         Unknown,
0081         Source,
0082         BuildSystem
0083     };
0084 
0085     void setQuality(Quality quality);
0086     Quality quality() const;
0087 
0088     void setParserSettings(const ParserSettings& arguments);
0089 
0090     ParserSettings parserSettings() const;
0091     void addParserArguments(const QString &parserArguments);
0092 
0093     /**
0094      * Hash all contents of this environment and return the result.
0095      *
0096      * This is useful for a quick comparison, and enough to store on-disk
0097      * to figure out if the environment changed or not.
0098      */
0099     uint hash() const;
0100 
0101     bool operator==(const ClangParsingEnvironment& other) const;
0102     bool operator!=(const ClangParsingEnvironment& other) const
0103     {
0104         return !(*this == other);
0105     }
0106 
0107 private:
0108     KDevelop::Path::List m_projectPaths;
0109     KDevelop::Path::List m_includes;
0110     KDevelop::Path::List m_frameworkDirectories;
0111     // NOTE: As elements in QHash stored in an unordered sequence, we're using QMap instead
0112     QMap<QString, QString> m_defines;
0113     KDevelop::Path m_pchInclude;
0114     KDevelop::Path m_workingDirectory;
0115     KDevelop::IndexedString m_tuUrl;
0116     Quality m_quality = Unknown;
0117     ParserSettings m_parserSettings;
0118 };
0119 
0120 #endif // CLANGPARSINGENVIRONMENT_H