OSDN Git Service

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