~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/tools/moc/moc.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the tools applications of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef MOC_H
 
30
#define MOC_H
 
31
 
 
32
#include "scanner.h"
 
33
#include <qstringlist.h>
 
34
#include <qmap.h>
 
35
#include <qpair.h>
 
36
#include <qstack.h>
 
37
#include <ctype.h>
 
38
#include <stdio.h>
 
39
 
 
40
struct EnumDef
 
41
{
 
42
    QByteArray name;
 
43
    QList<QByteArray> values;
 
44
};
 
45
 
 
46
struct ArgumentDef
 
47
{
 
48
    ArgumentDef():isDefault(false){}
 
49
    QByteArray type, rightType, normalizedType, name;
 
50
    bool isDefault;
 
51
};
 
52
 
 
53
struct FunctionDef
 
54
{
 
55
    FunctionDef(): access(Private), isConst(false), isVirtual(false), inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), isScriptable(false) {}
 
56
    QByteArray type, normalizedType;
 
57
    QByteArray tag;
 
58
    QByteArray name;
 
59
 
 
60
    QList<ArgumentDef> arguments;
 
61
 
 
62
    enum Access { Private, Protected, Public };
 
63
    Access access;
 
64
    bool isConst;
 
65
    bool isVirtual;
 
66
    bool inlineCode;
 
67
    bool wasCloned;
 
68
 
 
69
    QByteArray inPrivateClass;
 
70
    bool isCompat;
 
71
    bool isInvokable;
 
72
    bool isScriptable;
 
73
};
 
74
 
 
75
struct PropertyDef
 
76
{
 
77
    PropertyDef():gspec(ValueSpec){}
 
78
    QByteArray name, type, read, write, reset, designable, scriptable, editable, stored;
 
79
    enum Specification  { ValueSpec, ReferenceSpec, PointerSpec };
 
80
    Specification gspec;
 
81
    bool stdCppSet() const {
 
82
        QByteArray s("set");
 
83
        s += toupper(name[0]);
 
84
        s += name.mid(1);
 
85
        return (s == write);
 
86
    }
 
87
};
 
88
 
 
89
 
 
90
struct ClassInfoDef
 
91
{
 
92
    QByteArray name;
 
93
    QByteArray value;
 
94
};
 
95
 
 
96
struct ClassDef {
 
97
    ClassDef():
 
98
        hasQObject(false), hasQGadget(false){}
 
99
    QByteArray classname;
 
100
    QByteArray qualified;
 
101
    QList<QPair<QByteArray, FunctionDef::Access> > superclassList;
 
102
 
 
103
    struct Interface
 
104
    {
 
105
        inline explicit Interface(const QByteArray &_className)
 
106
            : className(_className) {}
 
107
        QByteArray className;
 
108
        QByteArray interfaceId;
 
109
    };
 
110
    QList<QList<Interface> >interfaceList;
 
111
 
 
112
    bool hasQObject;
 
113
    bool hasQGadget;
 
114
 
 
115
    QList<FunctionDef> signalList, slotList, methodList, publicList;
 
116
    QList<PropertyDef> propertyList;
 
117
    QList<ClassInfoDef> classInfoList;
 
118
    QMap<QByteArray, bool> enumDeclarations;
 
119
    QList<EnumDef> enumList;
 
120
    QMap<QByteArray, QByteArray> flagAliases;
 
121
 
 
122
    int begin;
 
123
    int end;
 
124
};
 
125
 
 
126
struct NamespaceDef {
 
127
    QByteArray name;
 
128
    int begin;
 
129
    int end;
 
130
};
 
131
 
 
132
class Moc
 
133
{
 
134
public:
 
135
    Moc()
 
136
        :index(0),
 
137
         noInclude(false),
 
138
         displayWarnings(true),
 
139
         generatedCode(false)
 
140
        {}
 
141
 
 
142
    QByteArray filename;
 
143
    QStack<QByteArray> currentFilenames;
 
144
    Symbols symbols;
 
145
 
 
146
    int index;
 
147
 
 
148
    bool noInclude;
 
149
    bool displayWarnings;
 
150
    bool generatedCode;
 
151
    QByteArray includePath;
 
152
    QList<QByteArray> includeFiles;
 
153
    QList<ClassDef> classList;
 
154
    QMap<QByteArray, QByteArray> interface2IdMap;
 
155
 
 
156
    inline bool hasNext() const { return (index < symbols.size()); }
 
157
    inline Token next() { return symbols.at(index++).token; }
 
158
    bool test(Token);
 
159
    void next(Token);
 
160
    void next(Token, const char *msg);
 
161
    bool until(Token);
 
162
    QByteArray lexemUntil(Token);
 
163
    inline void prev() {--index;}
 
164
    Token lookup(int k = 1);
 
165
    inline const Symbol &symbol_lookup(int k = 1) { return symbols.at(index-1+k);}
 
166
    inline Token token() { return symbols.at(index-1).token;}
 
167
    inline QByteArray lexem() { return symbols.at(index-1).lexem();}
 
168
    inline const Symbol &symbol() { return symbols.at(index-1);}
 
169
 
 
170
    void error(int rollback);
 
171
    void error(const char *msg = 0);
 
172
    void warning(const char * = 0);
 
173
 
 
174
    void parse();
 
175
    void generate(FILE *out);
 
176
 
 
177
    bool parseClassHead(ClassDef *def);
 
178
    inline bool inClass(const ClassDef *def) const {
 
179
        return index > def->begin && index < def->end - 1;
 
180
    }
 
181
 
 
182
    inline bool inNamespace(const NamespaceDef *def) const {
 
183
        return index > def->begin && index < def->end - 1;
 
184
    }
 
185
 
 
186
    QByteArray parseType();
 
187
 
 
188
    bool parseEnum(EnumDef *def);
 
189
 
 
190
    void parseFunction(FunctionDef *def, bool inMacro = false);
 
191
    bool parseMaybeFunction(FunctionDef *def);
 
192
 
 
193
    void parseSlots(ClassDef *def, FunctionDef::Access access);
 
194
    void parseSignals(ClassDef *def);
 
195
    void parseProperty(ClassDef *def);
 
196
    void parseEnumOrFlag(ClassDef *def, bool isFlag);
 
197
    void parseFlag(ClassDef *def);
 
198
    void parseClassInfo(ClassDef *def);
 
199
    void parseInterfaces(ClassDef *def);
 
200
    void parseDeclareInterface();
 
201
    void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access);
 
202
 
 
203
    void parseFunctionArguments(FunctionDef *def);
 
204
 
 
205
};
 
206
 
 
207
 
 
208
inline bool Moc::test(Token token)
 
209
{
 
210
    if (index < symbols.size() && symbols.at(index).token == token) {
 
211
        ++index;
 
212
        return true;
 
213
    }
 
214
    return false;
 
215
}
 
216
 
 
217
inline Token Moc::lookup(int k)
 
218
{
 
219
    const int l = index - 1 + k;
 
220
    return l < symbols.size() ? symbols.at(l).token : NOTOKEN;
 
221
}
 
222
 
 
223
inline void Moc::next(Token token)
 
224
{
 
225
    if (!test(token))
 
226
        error();
 
227
}
 
228
 
 
229
inline void Moc::next(Token token, const char *msg)
 
230
{
 
231
    if (!test(token))
 
232
        error(msg);
 
233
}
 
234
 
 
235
QByteArray normalizeType(const char *s, bool fixScope = false);
 
236
 
 
237
#endif // MOC_H