Mercurial > projects > qtd
annotate generator/dgenerator.h @ 361:beaf4a2974d7
Autogeneration of QMetaType. First attempts at fixing qRegisterMetaType etc
author | Max Samukha <maxter@maxter.com> |
---|---|
date | Wed, 09 Jun 2010 11:08:56 +0300 |
parents | 9784459f0750 |
children | a032df77b6ab |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #ifndef DGENERATOR_H | |
43 #define DGENERATOR_H | |
44 | |
45 #include "generator.h" | |
46 #include "metajava.h" | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
110
diff
changeset
|
47 #include "cppimplgenerator.h" |
1 | 48 |
49 #include <QTextStream> | |
341
4920ef9206fe
moved enums into interfaces
Max Samukha <maxter@spambox.com>
parents:
298
diff
changeset
|
50 #include <QStack> |
1 | 51 |
52 class DocParser; | |
53 | |
54 class DGenerator : public Generator | |
55 { | |
56 Q_OBJECT | |
57 | |
58 public: | |
59 DGenerator(); | |
60 | |
61 static QString translateType(const AbstractMetaType *d_type, const AbstractMetaClass *context, Option option = NoOption); | |
62 | |
63 void writeInjectedCode(QTextStream &s, | |
64 const AbstractMetaFunction *d_function, | |
65 CodeSnip::Position position); | |
66 static void writeArgument(QTextStream &s, | |
67 const AbstractMetaFunction *d_function, | |
68 const AbstractMetaArgument *d_argument, | |
69 uint options = 0); | |
70 static QString argumentString(const AbstractMetaFunction *d_function, | |
71 const AbstractMetaArgument *d_argument, | |
72 uint options = 0); | |
341
4920ef9206fe
moved enums into interfaces
Max Samukha <maxter@spambox.com>
parents:
298
diff
changeset
|
73 void writeEnum(QTextStream &s, const AbstractMetaEnum *d_enum, bool withAliases = false); |
1 | 74 void writeIntegerEnum(QTextStream &s, const AbstractMetaEnum *d_enum); |
75 void writeSignal(QTextStream &s, const AbstractMetaFunction *d_function); | |
76 void writeFunction(QTextStream &s, const AbstractMetaFunction *d_function, | |
77 uint included_attributes = 0, uint excluded_attributes = 0); | |
78 void writeFieldAccessors(QTextStream &s, const AbstractMetaField *field); | |
79 void writeNativeField(QTextStream &s, const AbstractMetaField *field); | |
80 | |
81 void write(QTextStream &s, const AbstractMetaClass *d_class); | |
82 | |
83 void writeFunctionOverloads(QTextStream &s, const AbstractMetaFunction *d_function, | |
84 uint included_attributes, uint excluded_attributes); | |
85 void writeEnumOverload(QTextStream &s, const AbstractMetaFunction *d_function, | |
86 uint include_attributes, uint exclude_attributes); | |
87 void writeExtraFunctions(QTextStream &s, const AbstractMetaClass *d_class); | |
88 void writeToStringFunction(QTextStream &s, const AbstractMetaClass *d_class); | |
89 void writeCloneFunction(QTextStream &s, const AbstractMetaClass *d_class); | |
90 void writeFunctionAttributes(QTextStream &s, const AbstractMetaFunction *d_function, | |
91 uint included_attributes = 0, uint excluded_attributes = 0, | |
92 uint options = 0); | |
93 void writeConstructorContents(QTextStream &s, const AbstractMetaFunction *d_function); | |
94 void writeFunctionArguments(QTextStream &s, const AbstractMetaFunction *d_function, | |
95 int count = -1, uint options = 0); | |
96 void writeJavaCallThroughContents(QTextStream &s, const AbstractMetaFunction *d_function, uint attributes = 0); | |
97 void writeOwnershipForContainer(QTextStream &s, TypeSystem::Ownership ownership, AbstractMetaArgument *arg); | |
98 void writeOwnershipForContainer(QTextStream &s, TypeSystem::Ownership ownership, AbstractMetaType *type, | |
99 const QString &arg_name); | |
100 void writePrivateNativeFunction(QTextStream &s, const AbstractMetaFunction *d_function); | |
101 void writeJavaLangObjectOverrideFunctions(QTextStream &s, const AbstractMetaClass *cls); | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
292
diff
changeset
|
102 void writeReferenceCount(QTextStream &s, const ReferenceCount &refCount, const QString &argumentName, AbstractMetaType *argumentType = 0); |
1 | 103 void retrieveModifications(const AbstractMetaFunction *f, const AbstractMetaClass *d_class, |
104 uint *exclude_attributes, uint *include_attributes) const; | |
105 QString functionSignature(const AbstractMetaFunction *d_function, | |
106 uint included_attributes, | |
107 uint excluded_attributes, | |
108 Option option = NoOption, | |
109 int arg_count = -1); | |
110 void setupForFunction(const AbstractMetaFunction *d_function, | |
111 uint *included_attributes, uint *excluded_attributes) const; | |
112 | |
113 virtual QString subDirectoryForClass(const AbstractMetaClass *d_class) const | |
114 { return subDirectoryForPackage(d_class->package()); } | |
115 | |
116 virtual QString fileNameForClass(const AbstractMetaClass *d_class) const; | |
117 | |
118 bool isComparable(const AbstractMetaClass *cls) const; | |
119 | |
120 #if 0 | |
121 void write1_dot_5_enum(QTextStream &s, const AbstractMetaEnum *d_enum); | |
122 #endif | |
123 | |
124 bool shouldGenerate(const AbstractMetaClass *d_class) const { | |
125 return !d_class->typeEntry()->isContainer() && !d_class->typeEntry()->isVariant() | |
126 && (d_class->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang); | |
127 } | |
128 | |
129 QString documentationDirectory() const { return m_doc_directory; } | |
130 void setDocumentationDirectory(const QString &docDir) { m_doc_directory = docDir; } | |
131 | |
132 bool documentationEnabled() const { return m_docs_enabled; } | |
133 void setDocumentationEnabled(bool e) { m_docs_enabled = e; } | |
134 void generate(); | |
135 | |
136 inline bool nativeJumpTable() const { return m_native_jump_table; } | |
137 inline void setNativeJumpTable(bool n) { m_native_jump_table = n; } | |
138 | |
139 void writeShellVirtualFunction(QTextStream &s, const AbstractMetaFunction *function, | |
140 const AbstractMetaClass *implementor, int id); | |
355
08c1ca7975ab
obviated redundant virtual dispatch callbacks
Max Samukha <maxter@spambox.com>
parents:
341
diff
changeset
|
141 void marshalFromCppToD(QTextStream &s, const ComplexTypeEntry* ctype); |
1 | 142 |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
143 // generates output analogous to that of qtd.Core.qtdExport |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
144 static void writeDExport(QTextStream &s, QString retType, QString name, QString args, QString body); |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
145 |
1 | 146 private: |
147 QString subDirectoryForPackage(const QString &package) const { return QString(package).replace(".", "/"); } | |
148 void writeInstantiatedType(QTextStream &s, const AbstractMetaType *abstractMetaType) const; | |
149 | |
150 // qtd | |
151 void addTypeEntry(const AbstractMetaClass *d_class, const AbstractMetaFunction *function, QSet<const TypeEntry*> &typeEntries); | |
152 void fillRequiredImports(const AbstractMetaClass *d_class); | |
153 void addInstantiations(const AbstractMetaType* d_type); | |
154 void writeRequiredImports(QTextStream &s, const AbstractMetaClass *d_class); | |
155 const TypeEntry* fixedTypeEntry(const TypeEntry *type); | |
288 | 156 AbstractMetaFunctionList generatedClassFunctions(const AbstractMetaClass *d_class); |
1 | 157 |
158 void writeDestructor(QTextStream &s, const AbstractMetaClass *d_class); | |
253 | 159 void writeFlagsSetter(QTextStream &s, const AbstractMetaClass *d_class); |
1 | 160 void writeSignalHandlers(QTextStream &s, const AbstractMetaClass *d_class); |
341
4920ef9206fe
moved enums into interfaces
Max Samukha <maxter@spambox.com>
parents:
298
diff
changeset
|
161 void writeEnumAliases(QTextStream &s, const AbstractMetaEnum *d_enum); |
253 | 162 void writeSignalSignatures(QTextStream &s, const AbstractMetaClass *d_class, AbstractMetaFunctionList signal_funcs); |
288 | 163 void writeMetaMethodArguments(QTextStream &s, const AbstractMetaFunction *d_function, int reduce = -1); |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
1
diff
changeset
|
164 void writeQObjectFunctions(QTextStream &s, const AbstractMetaClass *d_class); |
288 | 165 void writeQObjectFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class); |
110 | 166 void writeConversionFunction(QTextStream &s, const AbstractMetaClass *d_class); |
292 | 167 void writeValueFreeFunctions(QTextStream &s, const AbstractMetaClass *d_class); |
168 void writeValueFunctions(QTextStream &s, const AbstractMetaClass *d_class); | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
1
diff
changeset
|
169 |
1 | 170 // void writeMarshallFunction(QTextStream &s, const AbstractMetaClass *d_class); |
171 | |
172 int m_recursive; | |
173 bool m_isRecursive; | |
341
4920ef9206fe
moved enums into interfaces
Max Samukha <maxter@spambox.com>
parents:
298
diff
changeset
|
174 QStack<const AbstractMetaClass*> m_recursionStack; |
1 | 175 QSet<const TypeEntry*> typeEntries; // imports |
176 QSet<const TypeEntry*> typeEntriesEnums; // imports for enums | |
177 QSet<QString> excludedTypes2; | |
178 | |
179 protected: | |
180 void writeImportString(QTextStream &s, const TypeEntry* typeEntry); | |
181 | |
182 QSet<QString> excludedTypes; | |
183 QString m_package_name; | |
184 QString m_doc_directory; | |
185 DocParser *m_doc_parser; | |
186 bool m_docs_enabled; | |
187 bool m_native_jump_table; | |
188 QList<const AbstractMetaFunction *> m_nativepointer_functions; | |
189 QList<const AbstractMetaFunction *> m_resettable_object_functions; | |
190 QList<const AbstractMetaFunction *> m_reference_count_candidate_functions; | |
191 }; | |
192 | |
193 class ClassFromEntry : Generator | |
194 { | |
195 Q_OBJECT | |
196 | |
197 private: | |
198 ClassFromEntry(); | |
110 | 199 void buildHash(); |
1 | 200 QHash<const TypeEntry *, AbstractMetaClass *> classFromEntry; |
201 static ClassFromEntry* m_instance; | |
202 | |
203 public: | |
204 static AbstractMetaClass* get(const TypeEntry *te); | |
110 | 205 static void print(QTextStream &s); |
206 static void construct(const AbstractMetaClassList &classes); | |
207 | |
1 | 208 }; |
209 #endif // DGENERATOR_H |