1 /*
2  *  Copyright 2003 Maurizio Umberto Puxeddu <umbpux@tin.it>
3  *  Copyright 2011 Jakob Leben
4  *
5  *  This file is part of SuperCollider.
6  *
7  *  This program is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU General Public License as
9  *  published by the Free Software Foundation; either version 2 of the
10  *  License, or (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful, but
13  *  WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20  *  USA
21  *
22  */
23 
24 #pragma once
25 
26 #include <vector>
27 #include <string>
28 #include <boost/filesystem/path.hpp>
29 
30 class SC_LanguageConfig;
31 extern SC_LanguageConfig* gLanguageConfig;
32 extern const char* SCLANG_YAML_CONFIG_FILENAME;
33 
34 /**
35  * \brief Language configuration settings.
36  *
37  * \c sclang uses a global instance of this class to manage knowledge of
38  * compilation paths.
39  *
40  * \c SC_LanguageConfig also provides services for the global language
41  * configuration file and the option for warning on function inlining.
42  */
43 class SC_LanguageConfig {
44 public:
45     typedef boost::filesystem::path Path;
46     typedef std::vector<Path> DirVector;
47 
48     SC_LanguageConfig(bool standalone);
49 
includedDirectories() const50     const DirVector& includedDirectories() const { return mIncludedDirectories; }
excludedDirectories() const51     const DirVector& excludedDirectories() const { return mExcludedDirectories; }
defaultClassLibraryDirectories() const52     const DirVector& defaultClassLibraryDirectories() const { return mDefaultClassLibraryDirectories; }
53 
54     void postExcludedDirectories(void) const;
55 
56     bool pathIsExcluded(const Path&) const; // true iff the path is in mExcludedDirectories
57 
58     bool addIncludedDirectory(const Path&); // false iff the path was already in the vector
59     bool addExcludedDirectory(const Path&);
60 
61     bool removeIncludedDirectory(const Path&); // false iff there was nothing to remove
62     bool removeExcludedDirectory(const Path&);
63 
64     bool forEachIncludedDirectory(bool (*)(const Path&)) const;
65 
66     static bool readLibraryConfigYAML(const Path&, bool standalone);
67     static bool writeLibraryConfigYAML(const Path&);
68     static void freeLibraryConfig();
69     static bool defaultLibraryConfig(bool standalone);
70     static bool readLibraryConfig(bool standalone);
71 
getPostInlineWarnings()72     static bool getPostInlineWarnings() { return gPostInlineWarnings; }
setPostInlineWarnings(bool b)73     static void setPostInlineWarnings(bool b) { gPostInlineWarnings = b; }
getConfigPath()74     static const Path& getConfigPath() { return gConfigFile; }
setConfigPath(const Path & p)75     static void setConfigPath(const Path& p) { gConfigFile = p; }
76 
77 private:
78     static bool findPath(const DirVector&, const Path&);
79     static bool addPath(DirVector&, const Path&);
80     static bool removePath(DirVector&, const Path&);
81 
82     DirVector mIncludedDirectories;
83     DirVector mExcludedDirectories;
84     DirVector mDefaultClassLibraryDirectories;
85     static Path gConfigFile;
86     static bool gPostInlineWarnings;
87 };
88