OSDN Git Service

0031ee1d71d951452d9755defd82c7f669812ce2
[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) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef PROFILEEVALUATOR_H
31 #define PROFILEEVALUATOR_H
32
33 #include "proitems.h"
34
35 #include <QtCore/QHash>
36 #include <QtCore/QStringList>
37 #ifdef PROEVALUATOR_THREAD_SAFE
38 # include <QtCore/QMutex>
39 # include <QtCore/QWaitCondition>
40 #endif
41
42 QT_BEGIN_NAMESPACE
43
44 struct ProFileOption;
45 class ProFileParser;
46
47 class ProFileEvaluatorHandler
48 {
49 public:
50     // qmake/project configuration error
51     virtual void configError(const QString &msg) = 0;
52     // Some error during evaluation
53     virtual void evalError(const QString &filename, int lineNo, const QString &msg) = 0;
54     // error() and message() from .pro file
55     virtual void fileMessage(const QString &msg) = 0;
56
57     enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile };
58     virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type) = 0;
59     virtual void doneWithEval(ProFile *parent) = 0;
60 };
61
62
63 class ProFileEvaluator
64 {
65     class Private;
66
67 public:
68     struct FunctionDef {
69         QString string;
70         int offset;
71     };
72
73     struct FunctionDefs {
74         QHash<ProString, FunctionDef> testFunctions;
75         QHash<ProString, FunctionDef> replaceFunctions;
76     };
77
78     enum TemplateType {
79         TT_Unknown = 0,
80         TT_Application,
81         TT_Library,
82         TT_Script,
83         TT_Subdirs
84     };
85
86     // Call this from a concurrency-free context
87     static void initialize();
88
89     ProFileEvaluator(ProFileOption *option, ProFileParser *parser, ProFileEvaluatorHandler *handler);
90     ~ProFileEvaluator();
91
92     ProFileEvaluator::TemplateType templateType() const;
93     void setCumulative(bool on); // Default is true!
94     void setOutputDir(const QString &dir); // Default is empty
95
96     // -nocache, -cache, -spec, QMAKESPEC
97     // -set persistent value
98     void setConfigCommandLineArguments(const QStringList &addUserConfigCmdArgs, const QStringList &removeUserConfigCmdArgs);
99     void setParsePreAndPostFiles(bool on); // Default is true
100
101     bool accept(ProFile *pro);
102
103     bool contains(const QString &variableName) const;
104     QString value(const QString &variableName) const;
105     QStringList values(const QString &variableName) const;
106     QStringList values(const QString &variableName, const ProFile *pro) const;
107     QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const;
108     QStringList absoluteFileValues(
109             const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
110             const ProFile *pro) const;
111     QString propertyValue(const QString &val) const;
112
113 private:
114     Private *d;
115
116     friend struct ProFileOption;
117 };
118
119 Q_DECLARE_TYPEINFO(ProFileEvaluator::FunctionDef, Q_MOVABLE_TYPE);
120
121 // This struct is from qmake, but we are not using everything.
122 struct ProFileOption
123 {
124     ProFileOption();
125     ~ProFileOption();
126
127     //simply global convenience
128     //QString libtool_ext;
129     //QString pkgcfg_ext;
130     //QString prf_ext;
131     //QString prl_ext;
132     //QString ui_ext;
133     //QStringList h_ext;
134     //QStringList cpp_ext;
135     //QString h_moc_ext;
136     //QString cpp_moc_ext;
137     //QString obj_ext;
138     //QString lex_ext;
139     //QString yacc_ext;
140     //QString h_moc_mod;
141     //QString cpp_moc_mod;
142     //QString lex_mod;
143     //QString yacc_mod;
144     QString dir_sep;
145     QString dirlist_sep;
146     QString qmakespec;
147     QString cachefile;
148     QHash<QString, QString> properties;
149
150     enum TARG_MODE { TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE, TARG_MAC9_MODE, TARG_QNX6_MODE };
151     TARG_MODE target_mode;
152     //QString pro_ext;
153     //QString res_ext;
154
155   private:
156     friend class ProFileEvaluator;
157     friend class ProFileEvaluator::Private;
158     QHash<ProString, ProStringList> base_valuemap; // Cached results of qmake.conf, .qmake.cache & default_pre.prf
159     ProFileEvaluator::FunctionDefs base_functions;
160     QStringList feature_roots;
161     QString qmakespec_name;
162 #ifdef PROEVALUATOR_THREAD_SAFE
163     QMutex mutex;
164     QWaitCondition cond;
165     bool base_inProgress;
166 #endif
167 };
168
169 QT_END_NAMESPACE
170
171 #endif // PROFILEEVALUATOR_H