parsemanager.h 10.3 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30 31 32 33
**
**************************************************************************/

/*
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
** 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();
con's avatar
con committed
50
*    chParseManager->setIncludePath(chIncludepathlist);
51
**    chParseManager->parse(chFilelist);
52
**
53
**    if(!chParseManager->checkAllMetadatas(iParseManager)){
Tobias Hunger's avatar
Tobias Hunger committed
54
**        cout << "Following interface items are missing:" << endl;
55 56 57 58 59 60 61 62
**        QStringList errorlist = chParseManager->getErrorMsg();
**        foreach(QString msg, errorlist){
**            cout << (const char *)msg.toLatin1() << endl;
**        }
**        return -1;
**    }
**    else
**        cout << "Interface is full defined.";
con's avatar
con committed
63
*/
64 65 66 67

#ifndef PARSEMANAGER_H
#define PARSEMANAGER_H

Erik Verbruggen's avatar
Erik Verbruggen committed
68 69 70 71
#include "cplusplus/CppDocument.h"
#include "ASTfwd.h"
#include "FullySpecifiedType.h"

72 73 74 75
#include <QObject>
#include <QList>
#include <QFuture>
#include <QStringList>
Wolfgang Beck's avatar
Wolfgang Beck committed
76
#include <QFile>
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

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);
Erik Verbruggen's avatar
Erik Verbruggen committed
107

108 109 110 111 112 113 114 115 116 117 118 119 120
        FUNCTIONITEM()
        {
            highestlevelclass = 0;
            trlUnit = 0;
            classAst = 0;
            function = 0;
        }
    };
    class PROPERTYITEM
    {
    public:
        const CLASSLISTITEM* highestlevelclass;
        QStringList classWichIsNotFound;
Erik Verbruggen's avatar
Erik Verbruggen committed
121
        QtPropertyDeclarationAST *ast;
122
        CPlusPlus::TranslationUnit* trlUnit;
Erik Verbruggen's avatar
Erik Verbruggen committed
123 124
        FullySpecifiedType type;
        ExpressionAST *readAst;
125
        FUNCTIONITEM *readFct;
Erik Verbruggen's avatar
Erik Verbruggen committed
126
        ExpressionAST *writeAst;
127
        FUNCTIONITEM *writeFct;
Erik Verbruggen's avatar
Erik Verbruggen committed
128
        ExpressionAST *resetAst;
129
        FUNCTIONITEM *resetFct;
Erik Verbruggen's avatar
Erik Verbruggen committed
130
        ExpressionAST *notifyAst;
131 132 133 134 135 136 137 138 139
        FUNCTIONITEM *notifyFct;
        bool foundalldefinedfct;

        bool isEqualTo(PROPERTYITEM* cpppt);
        PROPERTYITEM()
        {
            highestlevelclass = 0;
            ast = 0;
            trlUnit = 0;
Erik Verbruggen's avatar
Erik Verbruggen committed
140
            readAst = 0;
141
            readFct = 0;
Erik Verbruggen's avatar
Erik Verbruggen committed
142
            writeAst = 0;
143
            writeFct = 0;
Erik Verbruggen's avatar
Erik Verbruggen committed
144
            resetAst = 0;
145
            resetFct = 0;
Erik Verbruggen's avatar
Erik Verbruggen committed
146
            notifyAst = 0;
147 148 149
            notifyFct = 0;
            foundalldefinedfct = false;
        }
Erik Verbruggen's avatar
Erik Verbruggen committed
150 151

        static PROPERTYITEM *create(QtPropertyDeclarationAST *ast, const CLASSLISTITEM *clazz);
152 153 154 155 156 157 158
    };

    class QENUMITEM
    {
    public:
        const CLASSLISTITEM* highestlevelclass;
        QStringList classWichIsNotFound;
Erik Verbruggen's avatar
Erik Verbruggen committed
159
        QString name;
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
        //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;
Erik Verbruggen's avatar
Erik Verbruggen committed
195
        const Name *name;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
        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;
Erik Verbruggen's avatar
Erik Verbruggen committed
215
        QtFlagsDeclarationAST* ast;
216 217 218 219 220 221 222 223 224

        QDECLAREFLAGSITEM()
        {
            highestlevelclass = 0;
            trlUnit = 0;
            ast = 0;
        }
    };

Wolfgang Beck's avatar
Wolfgang Beck committed
225
    static QFile* m_resultFile = 0;
226 227 228 229 230 231 232 233
    class ParseManager : public QObject
    {
        Q_OBJECT
    public:
        ParseManager();
        virtual ~ParseManager();
        void setIncludePath(const QStringList &includePath);
        void parse(const QStringList &sourceFiles);
Wolfgang Beck's avatar
Wolfgang Beck committed
234
        bool checkAllMetadatas(ParseManager* pInterfaceParserManager, QString resultfile);
235
        CppTools::Internal::CppPreprocessor *getPreProcessor() { return pCppPreprocessor; }
Wolfgang Beck's avatar
Wolfgang Beck committed
236
        QList<CLASSTREE*> CreateClassLists(bool isInterfaceHeader);
237 238 239 240
        QStringList getErrorMsg() { return m_errormsgs; }

    private:
        void parse(CppTools::Internal::CppPreprocessor *preproc, const QStringList &files);
Wolfgang Beck's avatar
Wolfgang Beck committed
241 242 243 244 245 246 247
        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);
248 249 250 251 252 253 254 255 256 257 258 259 260
        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);
Wolfgang Beck's avatar
Wolfgang Beck committed
261
        QStringList getErrorMessage(FUNCTIONITEM* fct);
262 263 264 265 266 267 268 269 270
        //--->

        //<--- 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);
Wolfgang Beck's avatar
Wolfgang Beck committed
271
        QStringList getErrorMessage(PROPERTYITEM* ppt);
272 273 274 275 276 277 278 279 280 281
        //--->

        //<--- 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);
Wolfgang Beck's avatar
Wolfgang Beck committed
282
        QStringList getErrorMessage(QENUMITEM* qenum);
283 284 285 286 287 288 289 290 291 292 293
        //--->

        //<--- 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);
Wolfgang Beck's avatar
Wolfgang Beck committed
294
        QStringList getErrorMessage(QFLAGITEM* pfg);
295 296 297 298 299 300 301 302 303 304 305 306 307
        //--->

    private:
        // cache
        QStringList m_includePaths;
        QStringList m_frameworkPaths;
        QByteArray m_definedMacros;
        CppTools::Internal::CppPreprocessor* pCppPreprocessor;
        QString m_strHeaderFile;
        QStringList m_errormsgs;
    };
}
#endif // PARSEMANAGER_H