Mercurial > projects > qtd
annotate generator/generator.h @ 282:256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author | eldar |
---|---|
date | Fri, 16 Oct 2009 02:43:59 +0000 |
parents | 49bfc86ff583 |
children | 9784459f0750 |
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 GENERATOR_H | |
43 #define GENERATOR_H | |
44 | |
45 #include "metajava.h" | |
46 #include "typesystem.h" | |
47 | |
48 #include "codemodel.h" | |
49 | |
50 #include <QObject> | |
51 #include <QFile> | |
52 | |
53 extern bool cpp_shared; | |
54 extern bool dPhobos; | |
55 extern int dVersion; | |
56 | |
57 class Generator : public QObject | |
58 { | |
59 Q_OBJECT | |
60 | |
61 Q_PROPERTY(QString outputDirectory READ outputDirectory WRITE setOutputDirectory); | |
62 | |
63 public: | |
64 enum Option { | |
65 NoOption = 0x00000000, | |
66 BoxedPrimitive = 0x00000001, | |
67 ExcludeConst = 0x00000002, | |
68 ExcludeReference = 0x00000004, | |
69 UseNativeIds = 0x00000008, | |
70 | |
71 EnumAsInts = 0x00000010, | |
72 SkipName = 0x00000020, | |
73 NoCasts = 0x00000040, | |
74 SkipReturnType = 0x00000080, | |
75 OriginalName = 0x00000100, | |
76 ShowStatic = 0x00000200, | |
77 UnderscoreSpaces = 0x00000400, | |
78 ForceEnumCast = 0x00000800, | |
79 ArrayAsPointer = 0x00001000, | |
80 VirtualCall = 0x00002000, | |
81 SkipTemplateParameters = 0x00004000, | |
82 SkipAttributes = 0x00008000, | |
83 OriginalTypeDescription = 0x00010000, | |
84 SkipRemovedArguments = 0x00020000, | |
85 IncludeDefaultExpression = 0x00040000, | |
86 NoReturnStatement = 0x00080000, | |
87 NoBlockedSlot = 0x00100000, | |
88 NormalizeAndFixTypeSignature = 0x00200000, | |
89 SuperCall = 0x00400000, | |
90 GlobalRefJObject = 0x00800000, | |
91 ExternC = 0x01000000, | |
92 VirtualDispatch = 0x02000000, | |
93 ForcePointer = 0x10000000, | |
94 | |
95 ForceValueType = ExcludeReference | ExcludeConst | |
96 }; | |
97 | |
98 Generator(); | |
99 | |
100 void setClasses(const AbstractMetaClassList &classes) { m_classes = classes; } | |
101 AbstractMetaClassList classes() const { return m_classes; } | |
102 | |
103 QString outputDirectory() const { return m_out_dir; } | |
104 void setOutputDirectory(const QString &outDir) { m_out_dir = outDir; } | |
105 virtual void generate(); | |
106 void printClasses(); | |
107 | |
108 int numGenerated() { return m_num_generated; } | |
109 int numGeneratedAndWritten() { return m_num_generated_written; } | |
110 | |
111 virtual bool shouldGenerate(const AbstractMetaClass *) const { return true; } | |
112 virtual QString subDirectoryForClass(const AbstractMetaClass *java_class) const; | |
113 virtual QString fileNameForClass(const AbstractMetaClass *java_class) const; | |
114 virtual void write(QTextStream &s, const AbstractMetaClass *java_class); | |
115 | |
116 bool hasDefaultConstructor(const AbstractMetaType *type); | |
117 | |
118 protected: | |
119 void verifyDirectoryFor(const QFile &file); | |
120 | |
121 AbstractMetaClassList m_classes; | |
122 int m_num_generated; | |
123 int m_num_generated_written; | |
124 QString m_out_dir; | |
125 }; | |
126 | |
127 class Indentor { | |
128 public: | |
129 Indentor(): | |
130 indent(0) | |
131 {} | |
132 int indent; | |
133 }; | |
134 | |
135 class Indentation { | |
136 public: | |
137 Indentation(Indentor &indentor): | |
138 indentor(indentor) | |
139 { | |
140 indentor.indent++; | |
141 } | |
142 ~Indentation() | |
143 { | |
144 indentor.indent--; | |
145 } | |
146 | |
147 private: | |
148 Indentor &indentor; | |
149 }; | |
150 | |
151 inline QTextStream &operator <<(QTextStream &s, const Indentor &indentor) | |
152 { | |
153 for (int i=0; i<indentor.indent; ++i) | |
154 s << " "; | |
155 return s; | |
156 } | |
157 | |
158 inline QString signalExternName(const AbstractMetaClass *cls, const AbstractMetaFunction* signal) | |
159 { | |
160 return "qtd_" + cls->name() + "_" + signal->name(); | |
161 } | |
162 | |
270 | 163 enum ConversionFunction |
164 { | |
165 FromCpp, | |
166 ToCpp | |
167 }; | |
168 | |
169 inline QString cppContainerConversionName(const AbstractMetaClass *cls, const AbstractMetaType *type, ConversionFunction func) | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
170 { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
171 QString package = cls->package().replace(".", "_"); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
172 const TypeEntry *te = type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
173 |
270 | 174 QString word; |
175 if (func == FromCpp) | |
176 word = "_fromcpp_"; | |
177 else | |
178 word = "_tocpp_"; | |
179 | |
180 return "qtd_" + package + "_" + te->targetLangName() + word + type->typeEntry()->qualifiedCppName(); | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
181 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
182 |
1 | 183 bool notWrappedYet(const AbstractMetaFunction *java_function); |
184 bool isLinearContainer(const ContainerTypeEntry *type); | |
253 | 185 AbstractMetaFunctionList signalFunctions(const AbstractMetaClass *cls, bool includeBase = true); |
1 | 186 |
187 #endif // GENERATOR_H |