OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / proparser / profileevaluator.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef PROFILEEVALUATOR_H
34 #define PROFILEEVALUATOR_H
35
36 #include "proitems.h"
37
38 #include <QtCore/QHash>
39 #include <QtCore/QStringList>
40 #ifdef PROEVALUATOR_THREAD_SAFE
41 # include <QtCore/QMutex>
42 # include <QtCore/QWaitCondition>
43 #endif
44
45 QT_BEGIN_NAMESPACE
46
47 struct ProFileOption;
48 class ProFileParser;
49
50 class ProFileEvaluatorHandler
51 {
52 public:
53     // qmake/project configuration error
54     virtual void configError(const QString &msg) = 0;
55     // Some error during evaluation
56     virtual void evalError(const QString &filename, int lineNo, const QString &msg) = 0;
57     // error() and message() from .pro file
58     virtual void fileMessage(const QString &msg) = 0;
59
60     enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile };
61     virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type) = 0;
62     virtual void doneWithEval(ProFile *parent) = 0;
63 };
64
65
66 class ProFileEvaluator
67 {
68     class Private;
69
70 public:
71     class FunctionDef {
72     public:
73         FunctionDef(ProFile *pro, int offset) : m_pro(pro), m_offset(offset) { m_pro->ref(); }
74         FunctionDef(const FunctionDef &o) : m_pro(o.m_pro), m_offset(o.m_offset) { m_pro->ref(); }
75         ~FunctionDef() { m_pro->deref(); }
76         FunctionDef &operator=(const FunctionDef &o)
77         {
78             if (this != &o) {
79                 m_pro->deref();
80                 m_pro = o.m_pro;
81                 m_pro->ref();
82                 m_offset = o.m_offset;
83             }
84             return *this;
85         }
86         ProFile *pro() const { return m_pro; }
87         const ushort *tokPtr() const { return m_pro->tokPtr() + m_offset; }
88     private:
89         ProFile *m_pro;
90         int m_offset;
91     };
92
93     struct FunctionDefs {
94         QHash<ProString, FunctionDef> testFunctions;
95         QHash<ProString, FunctionDef> replaceFunctions;
96     };
97
98     enum TemplateType {
99         TT_Unknown = 0,
100         TT_Application,
101         TT_Library,
102         TT_Script,
103         TT_Subdirs
104     };
105
106     // Call this from a concurrency-free context
107     static void initialize();
108
109     ProFileEvaluator(ProFileOption *option, ProFileParser *parser, ProFileEvaluatorHandler *handler);
110     ~ProFileEvaluator();
111
112     ProFileEvaluator::TemplateType templateType() const;
113     void setCumulative(bool on); // Default is true!
114     void setOutputDir(const QString &dir); // Default is empty
115
116     enum LoadFlag {
117         LoadProOnly = 0,
118         LoadPreFiles = 1,
119         LoadPostFiles = 2,
120         LoadAll = LoadPreFiles|LoadPostFiles
121     };
122     Q_DECLARE_FLAGS(LoadFlags, LoadFlag)
123     bool accept(ProFile *pro, LoadFlags flags = LoadAll);
124
125     bool contains(const QString &variableName) const;
126     QString value(const QString &variableName) const;
127     QStringList values(const QString &variableName) const;
128     QStringList values(const QString &variableName, const ProFile *pro) const;
129     QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const;
130     QStringList absoluteFileValues(
131             const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
132             const ProFile *pro) const;
133     QString propertyValue(const QString &val) const;
134
135 private:
136     Private *d;
137
138     friend struct ProFileOption;
139 };
140
141 Q_DECLARE_OPERATORS_FOR_FLAGS(ProFileEvaluator::LoadFlags)
142
143 // This struct is from qmake, but we are not using everything.
144 struct ProFileOption
145 {
146     ProFileOption();
147     ~ProFileOption();
148
149     //simply global convenience
150     //QString libtool_ext;
151     //QString pkgcfg_ext;
152     //QString prf_ext;
153     //QString prl_ext;
154     //QString ui_ext;
155     //QStringList h_ext;
156     //QStringList cpp_ext;
157     //QString h_moc_ext;
158     //QString cpp_moc_ext;
159     //QString obj_ext;
160     //QString lex_ext;
161     //QString yacc_ext;
162     //QString h_moc_mod;
163     //QString cpp_moc_mod;
164     //QString lex_mod;
165     //QString yacc_mod;
166     QString dir_sep;
167     QString dirlist_sep;
168     QString qmakespec;
169     QString cachefile;
170     QHash<QString, QString> properties;
171     QString sysroot;
172
173     //QString pro_ext;
174     //QString res_ext;
175
176     // -nocache, -cache, -spec, QMAKESPEC
177     // -set persistent value
178     void setCommandLineArguments(const QStringList &args);
179
180   private:
181     friend class ProFileEvaluator;
182     friend class ProFileEvaluator::Private;
183
184     void applyHostMode();
185
186     QHash<ProString, ProStringList> base_valuemap; // Cached results of qmake.conf, .qmake.cache & default_pre.prf
187     ProFileEvaluator::FunctionDefs base_functions;
188     QStringList feature_roots;
189     QString qmakespec_name;
190     QString precmds, postcmds;
191     enum HOST_MODE { HOST_UNKNOWN_MODE, HOST_UNIX_MODE, HOST_WIN_MODE, HOST_MACX_MODE };
192     HOST_MODE host_mode;
193     enum TARG_MODE { TARG_UNKNOWN_MODE, TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE,
194                      TARG_SYMBIAN_MODE };
195     TARG_MODE target_mode;
196 #ifdef PROEVALUATOR_THREAD_SAFE
197     QMutex mutex;
198     QWaitCondition cond;
199     bool base_inProgress;
200 #endif
201 };
202
203 Q_DECLARE_TYPEINFO(ProFileEvaluator::FunctionDef, Q_MOVABLE_TYPE);
204
205 QT_END_NAMESPACE
206
207 #endif // PROFILEEVALUATOR_H