1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
** Description:
**
** The ParseManager parses and compares to different header files
** of its metadata. This can be used for checking if an Interface
** is implemented complete.
**
** How to use it:
**
** //Parse the interface header
** ParseManager* iParseManager = new ParseManager();
** iParseManager->setIncludePath(iIncludepathlist);
** iParseManager->parse(iFilelist);
**
** //Parse the header that needs to be compared against the interface header
** ParseManager* chParseManager = new ParseManager();
** chIncludepathlist << getQTIncludePath();
** chParseManager->setIncludePath(chIncludepathlist);
** chParseManager->parse(chFilelist);
**
** if(!chParseManager->checkAllMetadatas(iParseManager)){
** cout << "Folowing interface items are missing:" << endl;
** QStringList errorlist = chParseManager->getErrorMsg();
** foreach(QString msg, errorlist){
** cout << (const char *)msg.toLatin1() << endl;
** }
** return -1;
** }
** else
** cout << "Interface is full defined.";
**
**************************************************************************/
#ifndef PARSEMANAGER_H
#define PARSEMANAGER_H
#include "cplusplus/CppDocument.h"
#include "ASTfwd.h"
#include "FullySpecifiedType.h"
#include <QObject>
#include <QList>
#include <QFuture>
#include <QStringList>
#include <QFile>
namespace CppTools{
namespace Internal{
class CppPreprocessor;
}
}
namespace CPlusPlus {
class CLASSLISTITEM
{
public:
CPlusPlus::TranslationUnit* trlUnit;
ClassSpecifierAST* classspec;
};
class CLASSTREE
{
public:
CLASSLISTITEM* highestlevelclass;
QList<CLASSLISTITEM*> classlist;
};
class FUNCTIONITEM
{
public:
const CLASSLISTITEM* highestlevelclass;
CPlusPlus::TranslationUnit* trlUnit;
ClassSpecifierAST* classAst;
QStringList classWichIsNotFound;
CPlusPlus::Function* function;
bool isEqualTo(FUNCTIONITEM* cpfct, bool ignoreName = true);
FUNCTIONITEM()
{
highestlevelclass = 0;
trlUnit = 0;
classAst = 0;
function = 0;
}
};
class PROPERTYITEM
{
public:
const CLASSLISTITEM* highestlevelclass;
QStringList classWichIsNotFound;
QtPropertyDeclarationAST *ast;
CPlusPlus::TranslationUnit* trlUnit;
FullySpecifiedType type;
ExpressionAST *readAst;
FUNCTIONITEM *readFct;
ExpressionAST *writeAst;
FUNCTIONITEM *writeFct;
ExpressionAST *resetAst;
FUNCTIONITEM *resetFct;
ExpressionAST *notifyAst;
FUNCTIONITEM *notifyFct;
bool foundalldefinedfct;
bool isEqualTo(PROPERTYITEM* cpppt);
PROPERTYITEM()
{
highestlevelclass = 0;
ast = 0;
trlUnit = 0;
readAst = 0;
readFct = 0;
writeAst = 0;
writeFct = 0;
resetAst = 0;
resetFct = 0;
notifyAst = 0;
notifyFct = 0;
foundalldefinedfct = false;
}
static PROPERTYITEM *create(QtPropertyDeclarationAST *ast, const CLASSLISTITEM *clazz);
};
class QENUMITEM
{
public:
const CLASSLISTITEM* highestlevelclass;
QStringList classWichIsNotFound;
QString name;
//an item in this list will be shown like:
//EnumName.EnumItemName.Value
//ConnectionState.disconnected.0
QStringList values;
bool foundallenums;
bool isEqualTo(QENUMITEM *cpenum);
QENUMITEM()
{
highestlevelclass = 0;
values.clear();
foundallenums = true;
}
};
class ENUMITEM
{
public:
const CLASSLISTITEM* highestlevelclass;
CPlusPlus::TranslationUnit* trlUnit;
QStringList classWichIsNotFound;
EnumSpecifierAST* ast;
ENUMITEM()
{
highestlevelclass = 0;
trlUnit = 0;
ast = 0;
}
};
class QFLAGITEM
{
public:
const CLASSLISTITEM* highestlevelclass;
const Name *name;
QStringList classWichIsNotFound;
QStringList enumvalues;
bool foundallenums;
bool isEqualTo(QFLAGITEM *cpflag);
QFLAGITEM()
{
highestlevelclass = 0;
enumvalues.clear();
foundallenums = true;
}
};
class QDECLAREFLAGSITEM
{
public:
const CLASSLISTITEM* highestlevelclass;
CPlusPlus::TranslationUnit* trlUnit;
QStringList classWichIsNotFound;
QtFlagsDeclarationAST* ast;
QDECLAREFLAGSITEM()
{
highestlevelclass = 0;
trlUnit = 0;
ast = 0;
}
};
static QFile* m_resultFile = 0;
class ParseManager : public QObject
{
Q_OBJECT
public:
ParseManager();
virtual ~ParseManager();
void setIncludePath(const QStringList &includePath);
void parse(const QStringList &sourceFiles);
bool checkAllMetadatas(ParseManager* pInterfaceParserManager, QString resultfile);
CppTools::Internal::CppPreprocessor *getPreProcessor() { return pCppPreprocessor; }
QList<CLASSTREE*> CreateClassLists(bool isInterfaceHeader);
QStringList getErrorMsg() { return m_errormsgs; }
private:
void parse(CppTools::Internal::CppPreprocessor *preproc, const QStringList &files);
void Trace(QString value);
inline QString getTraceFuntionString(const FUNCTIONITEM* fctitem, const QString& classname);
void getBaseClasses(const CLASSLISTITEM* pclass
, QList<CLASSLISTITEM*> &baseclasslist
, const QList<CLASSLISTITEM*> &allclasslist
, int level
, bool isInterfaceHeader);
void getElements(QList<FUNCTIONITEM*> &functionlist
, QList<PROPERTYITEM*> &propertylist
, QList<QENUMITEM*> &qenumlist
, QList<ENUMITEM*> &enumlist
, QList<QFLAGITEM*> &qflaglist
, QList<QDECLAREFLAGSITEM*> &qdeclareflaglist
, const QList<CLASSLISTITEM*> classitems
, const CLASSLISTITEM* highestlevelclass);
//<--- for Metadata functions checks
QList<FUNCTIONITEM*> checkMetadataFunctions(const QList<QList<FUNCTIONITEM*> > &classfctlist, const QList<QList<FUNCTIONITEM*> > &iclassfctlist);
bool isMetaObjFunction(FUNCTIONITEM* fct);
QList<FUNCTIONITEM*> containsAllMetadataFunction(const QList<FUNCTIONITEM*> &classfctlist, const QList<FUNCTIONITEM*> &iclassfctlist);
QStringList getErrorMessage(FUNCTIONITEM* fct);
//--->
//<--- for Q_PROPERTY functions checks
QList<PROPERTYITEM*> checkMetadataProperties(const QList<QList<PROPERTYITEM*> > &classproplist
, const QList<QList<FUNCTIONITEM*> > &classfctlist
, const QList<QList<PROPERTYITEM*> > &iclassproplist
, const QList<QList<FUNCTIONITEM*> > &iclassfctlist);
void assignPropertyFunctions(PROPERTYITEM* prop, const QList<QList<FUNCTIONITEM*> > &fctlookuplist);
QList<PROPERTYITEM*> containsAllPropertyFunction(const QList<PROPERTYITEM*> &classproplist, const QList<PROPERTYITEM*> &iclassproplist);
QStringList getErrorMessage(PROPERTYITEM* ppt);
//--->
//<--- for Q_ENUMS checks
QList<QENUMITEM*> checkMetadataEnums(const QList<QList<QENUMITEM*> > &classqenumlist
, const QList<QList<ENUMITEM*> > &classenumlist
, const QList<QList<QENUMITEM*> > &iclassqenumlist
, const QList<QList<ENUMITEM*> > &iclassenumlist);
QStringList getEnumValueStringList(ENUMITEM *penum, QString mappedenumname = "");
void assignEnumValues(QENUMITEM* qenum, const QList<QList<ENUMITEM*> > &enumlookuplist);
QList<QENUMITEM*> containsAllEnums(const QList<QENUMITEM*> &classqenumlist, const QList<QENUMITEM*> &iclassqenumlist);
QStringList getErrorMessage(QENUMITEM* qenum);
//--->
//<--- for QFlags checks --->
QList<QFLAGITEM*> checkMetadataFlags(const QList<QList<QFLAGITEM*> > &classqflaglist
, const QList<QList<QDECLAREFLAGSITEM*> > &classqdeclareflaglist
, const QList<QList<ENUMITEM*> > &classenumlist
, const QList<QList<QFLAGITEM*> > &iclassqflaglist
, const QList<QList<QDECLAREFLAGSITEM*> > &iclassqdeclareflaglist
, const QList<QList<ENUMITEM*> > &iclassenumlist);
void assignFlagValues(QFLAGITEM* qflags, const QList<QList<QDECLAREFLAGSITEM*> > &qdeclareflagslookuplist, const QList<QList<ENUMITEM*> > &enumlookuplist);
QList<QFLAGITEM*> containsAllFlags(const QList<QFLAGITEM*> &classqflaglist, const QList<QFLAGITEM*> &iclassqflaglist);
QStringList getErrorMessage(QFLAGITEM* pfg);
//--->
private:
// cache
QStringList m_includePaths;
QStringList m_frameworkPaths;
QByteArray m_definedMacros;
CppTools::Internal::CppPreprocessor* pCppPreprocessor;
QString m_strHeaderFile;
QStringList m_errormsgs;
};
}
#endif // PARSEMANAGER_H
|