Mercurial > projects > qtd
annotate generator/generator.h @ 375:c429854a40c0
fix indentation and cpack
author | Eldar Insafutdinov |
---|---|
date | Fri, 09 Jul 2010 20:24:24 +0100 |
parents | 9784459f0750 |
children | d2f48c4cb3e3 |
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 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
98 enum ModuleNameType |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
99 { |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
100 ShortUpper, |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
101 LongCamel |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
102 }; |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
103 |
1 | 104 Generator(); |
105 | |
106 void setClasses(const AbstractMetaClassList &classes) { m_classes = classes; } | |
107 AbstractMetaClassList classes() const { return m_classes; } | |
108 | |
109 QString outputDirectory() const { return m_out_dir; } | |
110 void setOutputDirectory(const QString &outDir) { m_out_dir = outDir; } | |
111 virtual void generate(); | |
112 void printClasses(); | |
113 | |
114 int numGenerated() { return m_num_generated; } | |
115 int numGeneratedAndWritten() { return m_num_generated_written; } | |
116 | |
117 virtual bool shouldGenerate(const AbstractMetaClass *) const { return true; } | |
118 virtual QString subDirectoryForClass(const AbstractMetaClass *java_class) const; | |
119 virtual QString fileNameForClass(const AbstractMetaClass *java_class) const; | |
120 virtual void write(QTextStream &s, const AbstractMetaClass *java_class); | |
121 | |
122 bool hasDefaultConstructor(const AbstractMetaType *type); | |
123 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
124 // TODO: this should be a property of the generator set, not inferred from java package. |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
125 static QString packageToQtModule(QString package, ModuleNameType nameType = ShortUpper); |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
126 |
1 | 127 protected: |
128 void verifyDirectoryFor(const QFile &file); | |
129 | |
130 AbstractMetaClassList m_classes; | |
131 int m_num_generated; | |
132 int m_num_generated_written; | |
133 QString m_out_dir; | |
134 }; | |
135 | |
136 class Indentor { | |
137 public: | |
138 Indentor(): | |
139 indent(0) | |
140 {} | |
141 int indent; | |
142 }; | |
143 | |
144 class Indentation { | |
145 public: | |
146 Indentation(Indentor &indentor): | |
147 indentor(indentor) | |
148 { | |
149 indentor.indent++; | |
150 } | |
151 ~Indentation() | |
152 { | |
153 indentor.indent--; | |
154 } | |
155 | |
156 private: | |
157 Indentor &indentor; | |
158 }; | |
159 | |
160 inline QTextStream &operator <<(QTextStream &s, const Indentor &indentor) | |
161 { | |
162 for (int i=0; i<indentor.indent; ++i) | |
163 s << " "; | |
164 return s; | |
165 } | |
166 | |
167 inline QString signalExternName(const AbstractMetaClass *cls, const AbstractMetaFunction* signal) | |
168 { | |
169 return "qtd_" + cls->name() + "_" + signal->name(); | |
170 } | |
171 | |
270 | 172 enum ConversionFunction |
173 { | |
174 FromCpp, | |
175 ToCpp | |
176 }; | |
177 | |
178 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
|
179 { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
180 QString package = cls->package().replace(".", "_"); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
181 const TypeEntry *te = type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
182 |
270 | 183 QString word; |
184 if (func == FromCpp) | |
185 word = "_fromcpp_"; | |
186 else | |
187 word = "_tocpp_"; | |
188 | |
189 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
|
190 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
1
diff
changeset
|
191 |
1 | 192 bool notWrappedYet(const AbstractMetaFunction *java_function); |
193 bool isLinearContainer(const ContainerTypeEntry *type); | |
253 | 194 AbstractMetaFunctionList signalFunctions(const AbstractMetaClass *cls, bool includeBase = true); |
1 | 195 |
196 #endif // GENERATOR_H |