Mercurial > projects > qtd
annotate generator/generator.cpp @ 105:3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
author | eldar |
---|---|
date | Sun, 31 May 2009 01:38:39 +0000 |
parents | cf8a415f3f32 |
children | ae34188ddd84 |
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 #include "generator.h" | |
43 #include "reporthandler.h" | |
44 #include "fileout.h" | |
45 | |
46 #include <QDir> | |
47 #include <QFile> | |
48 #include <QFileInfo> | |
49 | |
50 Generator::Generator() | |
51 { | |
52 m_num_generated = 0; | |
53 m_num_generated_written = 0; | |
54 m_out_dir = "."; | |
55 } | |
56 | |
57 void Generator::generate() | |
58 { | |
59 if (m_classes.size() == 0) { | |
60 ReportHandler::warning(QString("%1: no java classes, skipping") | |
61 .arg(metaObject()->className())); | |
62 return; | |
63 } | |
64 | |
65 | |
66 foreach (AbstractMetaClass *cls, m_classes) { | |
67 if (!shouldGenerate(cls)) | |
68 continue; | |
69 | |
70 QString fileName = fileNameForClass(cls); | |
71 ReportHandler::debugSparse(QString("generating: %1").arg(fileName)); | |
72 | |
73 FileOut fileOut(outputDirectory() + "/" + subDirectoryForClass(cls) + "/" + fileName); | |
74 write(fileOut.stream, cls); | |
75 | |
76 if( fileOut.done() ) | |
77 ++m_num_generated_written; | |
78 ++m_num_generated; | |
79 } | |
80 } | |
81 | |
82 | |
83 void Generator::printClasses() | |
84 { | |
85 QTextStream s(stdout); | |
86 | |
87 AbstractMetaClassList classes = m_classes; | |
88 qSort(classes); | |
89 | |
90 foreach (AbstractMetaClass *cls, classes) { | |
91 if (!shouldGenerate(cls)) | |
92 continue; | |
93 write(s, cls); | |
94 s << endl << endl; | |
95 } | |
96 } | |
97 | |
98 void Generator::verifyDirectoryFor(const QFile &file) | |
99 { | |
100 QDir dir = QFileInfo(file).dir(); | |
101 if (!dir.exists()) { | |
102 if (!dir.mkpath(dir.absolutePath())) | |
103 ReportHandler::warning(QString("unable to create directory '%1'") | |
104 .arg(dir.absolutePath())); | |
105 } | |
106 } | |
107 | |
108 QString Generator::subDirectoryForClass(const AbstractMetaClass *) const | |
109 { | |
110 Q_ASSERT(false); | |
111 return QString(); | |
112 } | |
113 | |
114 QString Generator::fileNameForClass(const AbstractMetaClass *) const | |
115 { | |
116 Q_ASSERT(false); | |
117 return QString(); | |
118 } | |
119 | |
120 void Generator::write(QTextStream &, const AbstractMetaClass *) | |
121 { | |
122 Q_ASSERT(false); | |
123 } | |
124 | |
125 bool Generator::hasDefaultConstructor(const AbstractMetaType *type) | |
126 { | |
127 QString full_name = type->typeEntry()->qualifiedTargetLangName(); | |
128 QString class_name = type->typeEntry()->targetLangName(); | |
129 | |
130 foreach (const AbstractMetaClass *java_class, m_classes) { | |
131 if (java_class->typeEntry()->qualifiedTargetLangName() == full_name) { | |
132 AbstractMetaFunctionList functions = java_class->functions(); | |
133 foreach (const AbstractMetaFunction *function, functions) { | |
134 if (function->arguments().size() == 0 && function->name() == class_name) | |
135 return true; | |
136 } | |
137 return false; | |
138 } | |
139 } | |
140 return false; | |
141 } | |
142 | |
143 bool isLinearContainer(const ContainerTypeEntry *type) | |
144 { | |
145 if (type->type() == ContainerTypeEntry::ListContainer | |
146 || type->type() == ContainerTypeEntry::VectorContainer | |
147 || type->type() == ContainerTypeEntry::StringListContainer | |
148 || type->type() == ContainerTypeEntry::LinkedListContainer | |
149 || type->type() == ContainerTypeEntry::StackContainer | |
150 || type->type() == ContainerTypeEntry::SetContainer | |
151 || type->type() == ContainerTypeEntry::QueueContainer) | |
152 return true; | |
153 else | |
154 return false; | |
155 } | |
156 | |
157 bool skipType(const AbstractMetaType *d_type) | |
158 { | |
159 if (d_type->isContainer()) { | |
160 const ContainerTypeEntry* c_entry = static_cast<const ContainerTypeEntry*>(d_type->typeEntry()); | |
161 if (c_entry->type() == ContainerTypeEntry::MapContainer || | |
162 c_entry->type() == ContainerTypeEntry::MultiMapContainer || | |
163 c_entry->type() == ContainerTypeEntry::MapContainer || | |
33
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
1
diff
changeset
|
164 c_entry->type() == ContainerTypeEntry::MultiHashContainer || |
cf8a415f3f32
gui package is fully wrapped now. lots of fixes in the generator
eldar
parents:
1
diff
changeset
|
165 c_entry->type() == ContainerTypeEntry::SetContainer) |
1 | 166 return true; |
167 | |
168 QList<AbstractMetaType *> args = d_type->instantiations(); | |
169 | |
170 if (args.size() != 1 || args.at(0)->isContainer()) // not QVector or QList | |
171 return true; | |
172 } | |
173 | |
174 return d_type->isThread() || d_type->isTargetLangChar(); | |
175 } | |
176 | |
177 bool notWrappedYet(const AbstractMetaFunction *java_function) | |
178 { | |
179 AbstractMetaType *d_type = java_function->type(); | |
180 if (d_type) | |
181 { | |
182 if(skipType(d_type)) | |
183 return true; | |
184 } | |
185 | |
186 AbstractMetaArgumentList arguments = java_function->arguments(); | |
187 foreach (const AbstractMetaArgument *argument, arguments) { | |
188 if (!java_function->argumentRemoved(argument->argumentIndex() + 1)) | |
189 if (skipType(argument->type())) | |
190 return true; | |
191 } | |
192 | |
193 return false; | |
194 } | |
195 | |
196 AbstractMetaFunctionList signalFunctions(const AbstractMetaClass *cls) | |
197 { | |
198 AbstractMetaFunctionList r; | |
199 if (cls->generateShellClass()) | |
200 { | |
201 AbstractMetaClass *base = cls->baseClass(); | |
202 if (base) | |
203 r += signalFunctions(base); | |
204 | |
205 foreach (AbstractMetaFunction *f, cls->functions()) | |
206 { | |
207 if (!f->isSignal() | |
208 || cls != f->implementingClass() | |
209 || notWrappedYet(f) | |
210 || f->isPrivate() | |
211 || f->isModifiedRemoved(TypeSystem::TargetLangCode)) | |
212 continue; | |
213 | |
214 r.append(f); | |
215 } | |
216 } | |
217 return r; | |
218 } |