parsemanager.h 10.2 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
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 29 30 31
**
**************************************************************************/

/*
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
** 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
48
*    chParseManager->setIncludePath(chIncludepathlist);
49
**    chParseManager->parse(chFilelist);
50
**
51
**    if(!chParseManager->checkAllMetadatas(iParseManager)){
Tobias Hunger's avatar
Tobias Hunger committed
52
**        cout << "Following interface items are missing:" << endl;
53 54 55 56 57 58 59 60
**        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
61
*/
62 63 64 65

#ifndef PARSEMANAGER_H
#define PARSEMANAGER_H

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

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

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
105

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

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

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

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

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

Wolfgang Beck's avatar
Wolfgang Beck committed
223
    static QFile* m_resultFile = 0;
224 225 226 227 228 229 230 231
    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
232
        bool checkAllMetadatas(ParseManager* pInterfaceParserManager, QString resultfile);
233
        CppTools::Internal::CppPreprocessor *getPreProcessor() { return pCppPreprocessor; }
Wolfgang Beck's avatar
Wolfgang Beck committed
234
        QList<CLASSTREE*> CreateClassLists(bool isInterfaceHeader);
235 236 237 238
        QStringList getErrorMsg() { return m_errormsgs; }

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

        //<--- 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
269
        QStringList getErrorMessage(PROPERTYITEM* ppt);
270 271 272 273 274 275 276 277 278 279
        //--->

        //<--- 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
280
        QStringList getErrorMessage(QENUMITEM* qenum);
281 282 283 284 285 286 287 288 289 290 291
        //--->

        //<--- 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
292
        QStringList getErrorMessage(QFLAGITEM* pfg);
293 294 295 296 297 298 299 300 301 302 303 304 305
        //--->

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