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 "abstractmetalang.h"
|
|
43 #include "reporthandler.h"
|
|
44 #include "jumptable.h"
|
288
|
45 #include <iostream>
|
1
|
46
|
|
47 /*******************************************************************************
|
|
48 * AbstractMetaType
|
|
49 */
|
|
50 AbstractMetaType *AbstractMetaType::copy() const
|
|
51 {
|
|
52 AbstractMetaType *cpy = new AbstractMetaType;
|
|
53
|
|
54 cpy->setTypeUsagePattern(typeUsagePattern());
|
|
55 cpy->setConstant(isConstant());
|
|
56 cpy->setReference(isReference());
|
|
57 cpy->setIndirections(indirections());
|
|
58 cpy->setInstantiations(instantiations());
|
|
59 cpy->setArrayElementCount(arrayElementCount());
|
|
60 cpy->setOriginalTypeDescription(originalTypeDescription());
|
|
61 cpy->setOriginalTemplateType(originalTemplateType() ? originalTemplateType()->copy() : 0);
|
|
62
|
|
63 cpy->setArrayElementType(arrayElementType() ? arrayElementType()->copy() : 0);
|
|
64
|
|
65 cpy->setTypeEntry(typeEntry());
|
|
66
|
|
67 return cpy;
|
|
68 }
|
|
69
|
|
70 QString AbstractMetaType::cppSignature() const
|
|
71 {
|
|
72 QString s;
|
|
73
|
|
74 if (isConstant())
|
|
75 s += "const ";
|
|
76
|
|
77 s += typeEntry()->qualifiedCppName();
|
|
78
|
|
79 if (hasInstantiationInCpp()) {
|
|
80 QList<AbstractMetaType *> types = instantiations();
|
|
81 s += "<";
|
|
82 for (int i=0; i<types.count(); ++i) {
|
|
83 if (i > 0)
|
|
84 s += ", ";
|
|
85 s += types.at(i)->cppSignature();
|
|
86 }
|
|
87 s += " >";
|
|
88 }
|
|
89
|
|
90 if (actualIndirections()) {
|
|
91 s += ' ';
|
|
92 if (indirections())
|
|
93 s += QString(indirections(), '*');
|
|
94 if (isReference())
|
|
95 s += '&';
|
|
96 }
|
|
97 return s;
|
|
98 }
|
|
99
|
|
100 /*******************************************************************************
|
|
101 * AbstractMetaArgument
|
|
102 */
|
|
103 AbstractMetaArgument *AbstractMetaArgument::copy() const
|
|
104 {
|
|
105 AbstractMetaArgument *cpy = new AbstractMetaArgument;
|
|
106 cpy->setName(AbstractMetaVariable::name());
|
|
107 cpy->setDefaultValueExpression(defaultValueExpression());
|
|
108 cpy->setType(type()->copy());
|
|
109 cpy->setArgumentIndex(argumentIndex());
|
|
110
|
|
111 return cpy;
|
|
112 }
|
|
113
|
|
114
|
|
115 QString AbstractMetaArgument::argumentName() const
|
|
116 {
|
|
117 QString n = AbstractMetaVariable::name();
|
|
118 // replace for arguments which are D keywords such as "version"
|
|
119 n = ArgumentReplace::translate(n);
|
|
120
|
|
121 if (n.isEmpty()) {
|
|
122 return QString("arg__%2").arg(m_argument_index + 1);
|
|
123 }
|
|
124 return n;
|
|
125 }
|
|
126
|
|
127
|
|
128 QString AbstractMetaArgument::indexedName() const
|
|
129 {
|
|
130 QString n = AbstractMetaVariable::name();
|
|
131 if (n.isEmpty())
|
|
132 return argumentName();
|
|
133 return QString("%1%2").arg(n).arg(m_argument_index);
|
|
134 }
|
|
135
|
|
136 QString AbstractMetaArgument::name() const
|
|
137 {
|
|
138 Q_ASSERT_X(0, "AbstractMetaArgument::name()", "use argumentName() or indexedName() instead");
|
|
139 return QString();
|
|
140 }
|
|
141
|
|
142
|
|
143 /*******************************************************************************
|
|
144 * AbstractMetaFunction
|
|
145 */
|
|
146 AbstractMetaFunction::~AbstractMetaFunction()
|
|
147 {
|
|
148 qDeleteAll(m_arguments);
|
|
149 delete m_type;
|
|
150 }
|
|
151
|
|
152 /*******************************************************************************
|
|
153 * Indicates that this function has a modification that removes it
|
|
154 */
|
|
155 bool AbstractMetaFunction::isModifiedRemoved(int types) const
|
|
156 {
|
|
157 FunctionModificationList mods = modifications(implementingClass());
|
|
158 foreach (FunctionModification mod, mods) {
|
|
159 if (!mod.isRemoveModifier())
|
|
160 continue;
|
|
161
|
|
162 if ((mod.removal & types) == types)
|
|
163 return true;
|
|
164 }
|
|
165
|
|
166 return false;
|
|
167 }
|
|
168
|
|
169 bool AbstractMetaFunction::needsCallThrough() const
|
|
170 {
|
|
171 if (ownerClass()->isInterface())
|
|
172 return false;
|
|
173 if (referenceCounts(implementingClass()).size() > 0)
|
|
174 return true;
|
|
175 if (argumentsHaveNativeId() || !isStatic())
|
|
176 return true;
|
|
177 if (JumpTableGenerator::isJumpTableActive())
|
|
178 return true;
|
|
179
|
|
180 foreach (const AbstractMetaArgument *arg, arguments()) {
|
|
181 if (arg->type()->isArray() || arg->type()->isTargetLangEnum() || arg->type()->isTargetLangFlags())
|
|
182 return true;
|
|
183 }
|
|
184
|
|
185 if (type() && (type()->isArray() || type()->isTargetLangEnum() || type()->isTargetLangFlags()))
|
|
186 return true;
|
|
187
|
|
188 for (int i=-1; i<=arguments().size(); ++i) {
|
|
189 TypeSystem::Ownership owner = this->ownership(implementingClass(), TypeSystem::TargetLangCode, i);
|
|
190 if (owner != TypeSystem::InvalidOwnership)
|
|
191 return true;
|
|
192 }
|
|
193
|
|
194 return false;
|
|
195 }
|
|
196
|
|
197 bool AbstractMetaFunction::needsSuppressUncheckedWarning() const
|
|
198 {
|
|
199 for (int i=-1; i<=arguments().size(); ++i) {
|
|
200 QList<ReferenceCount> referenceCounts = this->referenceCounts(implementingClass(), i);
|
|
201 foreach (ReferenceCount referenceCount, referenceCounts) {
|
|
202 if (referenceCount.action != ReferenceCount::Set)
|
|
203 return true;
|
|
204 }
|
|
205 }
|
|
206 return false;
|
|
207 }
|
|
208
|
|
209 QString AbstractMetaFunction::marshalledName(bool classIsOwner) const
|
|
210 {
|
|
211 QString returned = "qtd_";
|
|
212 if(classIsOwner)
|
|
213 returned += ownerClass()->name();
|
|
214 else
|
|
215 returned += declaringClass()->name();
|
|
216
|
|
217 returned += "_" + name();
|
|
218 AbstractMetaArgumentList arguments = this->arguments();
|
|
219 foreach (const AbstractMetaArgument *arg, arguments) {
|
|
220 returned += "_";
|
|
221 if (arg->type()->isNativePointer()) {
|
|
222 returned += "nativepointer" + arg->type()->name().replace("[]", "_3").replace(".", "_");
|
|
223 } else if (arg->type()->isIntegerEnum() || arg->type()->isIntegerFlags()) {
|
|
224 returned += "int";
|
|
225 } else {
|
|
226 returned += arg->type()->name().replace("[]", "_3").replace(".", "_");
|
|
227 }
|
|
228 }
|
|
229 return returned;
|
|
230 }
|
|
231
|
|
232 bool AbstractMetaFunction::operator<(const AbstractMetaFunction &other) const
|
|
233 {
|
|
234 uint result = compareTo(&other);
|
|
235 return result & NameLessThan;
|
|
236 }
|
|
237
|
|
238
|
|
239 /*!
|
|
240 Returns a mask of CompareResult describing how this function is
|
|
241 compares to another function
|
|
242 */
|
|
243 uint AbstractMetaFunction::compareTo(const AbstractMetaFunction *other) const
|
|
244 {
|
|
245 uint result = 0;
|
|
246
|
|
247 // Enclosing class...
|
|
248 if (ownerClass() == other->ownerClass()) {
|
|
249 result |= EqualImplementor;
|
|
250 }
|
|
251
|
|
252 // Attributes
|
|
253 if (attributes() == other->attributes()) {
|
|
254 result |= EqualAttributes;
|
|
255 }
|
|
256
|
|
257 // Compare types
|
|
258 AbstractMetaType *t = type();
|
|
259 AbstractMetaType *ot = other->type();
|
|
260 if ((!t && !ot) || ((t && ot && t->name() == ot->name()))) {
|
|
261 result |= EqualReturnType;
|
|
262 }
|
|
263
|
|
264 // Compare names
|
|
265 int cmp = originalName().compare(other->originalName());
|
|
266
|
|
267 if (cmp < 0) {
|
|
268 result |= NameLessThan;
|
|
269 } else if (cmp == 0) {
|
|
270 result |= EqualName;
|
|
271 }
|
|
272
|
|
273 // compare name after modification...
|
|
274 cmp = modifiedName().compare(other->modifiedName());
|
|
275 if (cmp == 0)
|
|
276 result |= EqualModifiedName;
|
|
277
|
|
278 // Compare arguments...
|
|
279 AbstractMetaArgumentList min_arguments;
|
|
280 AbstractMetaArgumentList max_arguments;
|
|
281 if (arguments().size() < other->arguments().size()) {
|
|
282 min_arguments = arguments();
|
|
283 max_arguments = other->arguments();
|
|
284 } else {
|
|
285 min_arguments = other->arguments();
|
|
286 max_arguments = arguments();
|
|
287 }
|
|
288
|
|
289 int min_count = min_arguments.size();
|
|
290 int max_count = max_arguments.size();
|
|
291 bool same = true;
|
|
292 for (int i=0; i<max_count; ++i) {
|
|
293 if (i < min_count) {
|
|
294 const AbstractMetaArgument *min_arg = min_arguments.at(i);
|
|
295 const AbstractMetaArgument *max_arg = max_arguments.at(i);
|
|
296 if (min_arg->type()->name() != max_arg->type()->name()
|
|
297 && (min_arg->defaultValueExpression().isEmpty() || max_arg->defaultValueExpression().isEmpty())) {
|
|
298 same = false;
|
|
299 break;
|
|
300 }
|
|
301 } else {
|
|
302 if (max_arguments.at(i)->defaultValueExpression().isEmpty()) {
|
|
303 same = false;
|
|
304 break;
|
|
305 }
|
|
306 }
|
|
307 }
|
|
308
|
|
309 if (same)
|
|
310 result |= min_count == max_count ? EqualArguments : EqualDefaultValueOverload;
|
|
311
|
|
312 return result;
|
|
313 }
|
|
314
|
|
315 AbstractMetaFunction *AbstractMetaFunction::copy() const
|
|
316 {
|
|
317 AbstractMetaFunction *cpy = new AbstractMetaFunction;
|
|
318 cpy->setName(name());
|
|
319 cpy->setOriginalName(originalName());
|
|
320 cpy->setOwnerClass(ownerClass());
|
|
321 cpy->setImplementingClass(implementingClass());
|
|
322 cpy->setInterfaceClass(interfaceClass());
|
|
323 cpy->setFunctionType(functionType());
|
|
324 cpy->setAttributes(attributes());
|
|
325 cpy->setDeclaringClass(declaringClass());
|
|
326 if (type())
|
|
327 cpy->setType(type()->copy());
|
|
328 cpy->setConstant(isConstant());
|
|
329 cpy->setOriginalAttributes(originalAttributes());
|
|
330
|
|
331 foreach (AbstractMetaArgument *arg, arguments())
|
|
332 cpy->addArgument(arg->copy());
|
|
333
|
|
334 Q_ASSERT((!type() && !cpy->type())
|
|
335 || (type()->instantiations() == cpy->type()->instantiations()));
|
|
336
|
|
337 return cpy;
|
|
338 }
|
|
339
|
|
340 QStringList AbstractMetaFunction::introspectionCompatibleSignatures(const QStringList &resolvedArguments) const
|
|
341 {
|
|
342 AbstractMetaArgumentList arguments = this->arguments();
|
|
343 if (arguments.size() == resolvedArguments.size()) {
|
|
344 return (QStringList() << QMetaObject::normalizedSignature((name() + "(" + resolvedArguments.join(",") + ")").toUtf8().constData()));
|
|
345 } else {
|
|
346 QStringList returned;
|
|
347
|
|
348 AbstractMetaArgument *argument = arguments.at(resolvedArguments.size());
|
|
349 QStringList minimalTypeSignature = argument->type()->minimalSignature().split("::");
|
|
350 for (int i=0; i<minimalTypeSignature.size(); ++i) {
|
|
351 returned += introspectionCompatibleSignatures(QStringList(resolvedArguments)
|
|
352 << QStringList(minimalTypeSignature.mid(minimalTypeSignature.size() - i - 1)).join("::"));
|
|
353 }
|
|
354
|
|
355 return returned;
|
|
356 }
|
|
357 }
|
|
358
|
|
359 QString AbstractMetaFunction::signature() const
|
|
360 {
|
|
361 QString s(m_original_name);
|
|
362
|
|
363 s += "(";
|
|
364
|
|
365 for (int i=0; i<m_arguments.count(); ++i) {
|
|
366 if (i > 0)
|
|
367 s += ", ";
|
|
368 AbstractMetaArgument *a = m_arguments.at(i);
|
|
369 s += a->type()->cppSignature();
|
|
370
|
|
371 // We need to have the argument names in the qdoc files
|
|
372 s += " ";
|
|
373 s += a->argumentName();
|
|
374 }
|
|
375 s += ")";
|
|
376
|
|
377 if (isConstant())
|
|
378 s += " const";
|
|
379
|
|
380 return s;
|
|
381 }
|
|
382
|
|
383 int AbstractMetaFunction::actualMinimumArgumentCount() const
|
|
384 {
|
|
385 AbstractMetaArgumentList arguments = this->arguments();
|
|
386
|
|
387 int count = 0;
|
|
388 for (int i=0; i<arguments.size(); ++i && ++count) {
|
|
389 if (argumentRemoved(i + 1)) --count;
|
|
390 else if (!arguments.at(i)->defaultValueExpression().isEmpty()) break;
|
|
391 }
|
|
392
|
|
393 return count;
|
|
394 }
|
|
395
|
|
396 // Returns reference counts for argument at idx, or all arguments if idx == -2
|
|
397 QList<ReferenceCount> AbstractMetaFunction::referenceCounts(const AbstractMetaClass *cls, int idx) const
|
|
398 {
|
|
399 QList<ReferenceCount> returned;
|
|
400
|
|
401 FunctionModificationList mods = this->modifications(cls);
|
|
402 foreach (FunctionModification mod, mods) {
|
|
403 QList<ArgumentModification> argument_mods = mod.argument_mods;
|
|
404 foreach (ArgumentModification argument_mod, argument_mods) {
|
|
405 if (argument_mod.index != idx && idx != -2)
|
|
406 continue;
|
|
407 returned += argument_mod.referenceCounts;
|
|
408 }
|
|
409 }
|
|
410
|
|
411 return returned;
|
|
412 }
|
|
413
|
|
414 QString AbstractMetaFunction::replacedDefaultExpression(const AbstractMetaClass *cls, int key) const
|
|
415 {
|
|
416 FunctionModificationList modifications = this->modifications(cls);
|
|
417 foreach (FunctionModification modification, modifications) {
|
|
418 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
419 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
420 if (argument_modification.index == key
|
|
421 && !argument_modification.replaced_default_expression.isEmpty()) {
|
|
422 return argument_modification.replaced_default_expression;
|
|
423 }
|
|
424 }
|
|
425 }
|
|
426
|
|
427 return QString();
|
|
428 }
|
|
429
|
|
430 bool AbstractMetaFunction::removedDefaultExpression(const AbstractMetaClass *cls, int key) const
|
|
431 {
|
|
432 FunctionModificationList modifications = this->modifications(cls);
|
|
433 foreach (FunctionModification modification, modifications) {
|
|
434 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
435 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
436 if (argument_modification.index == key
|
|
437 && argument_modification.removed_default_expression) {
|
|
438 return true;
|
|
439 }
|
|
440 }
|
|
441 }
|
|
442
|
|
443 return false;
|
|
444 }
|
|
445
|
|
446 bool AbstractMetaFunction::resetObjectAfterUse(int argument_idx) const
|
|
447 {
|
|
448 const AbstractMetaClass *cls = declaringClass();
|
|
449 FunctionModificationList modifications = this->modifications(cls);
|
|
450 foreach (FunctionModification modification, modifications) {
|
|
451 QList<ArgumentModification> argumentModifications = modification.argument_mods;
|
|
452 foreach (ArgumentModification argumentModification, argumentModifications) {
|
|
453 if (argumentModification.index == argument_idx && argumentModification.reset_after_use)
|
|
454 return true;
|
|
455 }
|
|
456 }
|
|
457
|
|
458 return false;
|
|
459 }
|
|
460
|
|
461 QString AbstractMetaFunction::nullPointerDefaultValue(const AbstractMetaClass *mainClass, int argument_idx) const
|
|
462 {
|
|
463 Q_ASSERT(nullPointersDisabled(mainClass, argument_idx));
|
|
464
|
|
465 const AbstractMetaClass *cls = mainClass;
|
|
466 if (cls == 0)
|
|
467 cls = implementingClass();
|
|
468
|
|
469 do {
|
|
470 FunctionModificationList modifications = this->modifications(cls);
|
|
471 foreach (FunctionModification modification, modifications) {
|
|
472 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
473 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
474 if (argument_modification.index == argument_idx
|
|
475 && argument_modification.no_null_pointers) {
|
|
476 return argument_modification.null_pointer_default_value;
|
|
477 }
|
|
478 }
|
|
479 }
|
|
480
|
|
481 cls = cls->baseClass();
|
|
482 } while (cls != 0 && mainClass == 0); // Once when mainClass != 0, or once for all base classes of implementing class
|
|
483
|
|
484 return QString();
|
|
485
|
|
486 }
|
|
487
|
|
488 bool AbstractMetaFunction::nullPointersDisabled(const AbstractMetaClass *mainClass, int argument_idx) const
|
|
489 {
|
|
490 const AbstractMetaClass *cls = mainClass;
|
|
491 if (cls == 0)
|
|
492 cls = implementingClass();
|
|
493
|
|
494 do {
|
|
495 FunctionModificationList modifications = this->modifications(cls);
|
|
496 foreach (FunctionModification modification, modifications) {
|
|
497 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
498 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
499 if (argument_modification.index == argument_idx
|
|
500 && argument_modification.no_null_pointers) {
|
|
501 return true;
|
|
502 }
|
|
503 }
|
|
504 }
|
|
505
|
|
506 cls = cls->baseClass();
|
|
507 } while (cls != 0 && mainClass == 0); // Once when mainClass != 0, or once for all base classes of implementing class
|
|
508
|
|
509 return false;
|
|
510 }
|
|
511
|
|
512 QString AbstractMetaFunction::conversionRule(TypeSystem::Language language, int key) const
|
|
513 {
|
|
514 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
515 foreach (FunctionModification modification, modifications) {
|
|
516 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
517 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
518 if (argument_modification.index != key)
|
|
519 continue;
|
|
520
|
|
521 foreach (CodeSnip snip, argument_modification.conversion_rules) {
|
|
522 if (snip.language == language && !snip.code().isEmpty())
|
|
523 return snip.code();
|
|
524 }
|
|
525 }
|
|
526 }
|
|
527
|
|
528 return QString();
|
|
529 }
|
|
530
|
|
531 QString AbstractMetaFunction::argumentReplaced(int key) const
|
|
532 {
|
|
533 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
534 foreach (FunctionModification modification, modifications) {
|
|
535 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
536 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
537 if (argument_modification.index == key && !argument_modification.replace_value.isEmpty()) {
|
|
538 return argument_modification.replace_value;
|
|
539 }
|
|
540 }
|
|
541 }
|
|
542
|
|
543 return "";
|
|
544 }
|
|
545
|
|
546 bool AbstractMetaFunction::argumentRemoved(int key) const
|
|
547 {
|
|
548 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
549 foreach (FunctionModification modification, modifications) {
|
|
550 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
551 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
552 if (argument_modification.index == key) {
|
|
553 if (argument_modification.removed) {
|
|
554 return true;
|
|
555 }
|
|
556 }
|
|
557 }
|
|
558 }
|
|
559
|
|
560 return false;
|
|
561 }
|
|
562
|
|
563 bool AbstractMetaFunction::storeResult() const
|
|
564 {
|
|
565 if (m_store_result == 2)
|
|
566 return true;
|
|
567 else
|
|
568 return false;
|
|
569 }
|
|
570
|
|
571 void AbstractMetaFunction::checkStoreResult()
|
|
572 {
|
|
573 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
574 foreach (FunctionModification modification, modifications) {
|
|
575 if (modification.store_result) {
|
|
576 m_store_result = 2;
|
|
577 return;
|
|
578 }
|
|
579 }
|
|
580
|
|
581 m_store_result = 1;
|
|
582 }
|
|
583
|
|
584 bool AbstractMetaFunction::isVirtualSlot() const
|
|
585 {
|
|
586 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
587 foreach (FunctionModification modification, modifications) {
|
|
588 if (modification.isVirtualSlot())
|
|
589 return true;
|
|
590 }
|
|
591
|
|
592 return false;
|
|
593 }
|
|
594
|
|
595 bool AbstractMetaFunction::disabledGarbageCollection(const AbstractMetaClass *cls, int key) const
|
|
596 {
|
|
597 FunctionModificationList modifications = this->modifications(cls);
|
|
598 foreach (FunctionModification modification, modifications) {
|
|
599 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
600 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
601 if (argument_modification.index != key)
|
|
602 continue;
|
|
603
|
|
604 foreach (TypeSystem::Ownership ownership, argument_modification.ownerships.values()) {
|
|
605 if (ownership == TypeSystem::CppOwnership)
|
|
606 return true;
|
|
607 }
|
|
608
|
|
609 }
|
|
610 }
|
|
611
|
|
612 return false;
|
|
613 }
|
|
614
|
|
615 bool AbstractMetaFunction::isDeprecated() const
|
|
616 {
|
|
617 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
618 foreach (FunctionModification modification, modifications) {
|
|
619 if (modification.isDeprecated())
|
|
620 return true;
|
|
621 }
|
|
622 return false;
|
|
623 }
|
|
624
|
|
625 TypeSystem::Ownership AbstractMetaFunction::ownership(const AbstractMetaClass *cls, TypeSystem::Language language, int key) const
|
|
626 {
|
|
627 FunctionModificationList modifications = this->modifications(cls);
|
|
628 foreach (FunctionModification modification, modifications) {
|
|
629 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
630 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
631 if (argument_modification.index == key)
|
|
632 return argument_modification.ownerships.value(language, TypeSystem::InvalidOwnership);
|
|
633 }
|
|
634 }
|
|
635
|
|
636 return TypeSystem::InvalidOwnership;
|
|
637 }
|
|
638
|
|
639 bool AbstractMetaFunction::isRemovedFromAllLanguages(const AbstractMetaClass *cls) const
|
|
640 {
|
|
641 return isRemovedFrom(cls, TypeSystem::All);
|
|
642 }
|
|
643
|
|
644 bool AbstractMetaFunction::isRemovedFrom(const AbstractMetaClass *cls, TypeSystem::Language language) const
|
|
645 {
|
|
646 FunctionModificationList modifications = this->modifications(cls);
|
|
647 foreach (FunctionModification modification, modifications) {
|
|
648 if ((modification.removal & language) == language)
|
|
649 return true;
|
|
650 }
|
|
651
|
|
652 return false;
|
|
653
|
|
654 }
|
|
655
|
|
656 QString AbstractMetaFunction::typeReplaced(int key) const
|
|
657 {
|
|
658 FunctionModificationList modifications = this->modifications(declaringClass());
|
|
659 foreach (FunctionModification modification, modifications) {
|
|
660 QList<ArgumentModification> argument_modifications = modification.argument_mods;
|
|
661 foreach (ArgumentModification argument_modification, argument_modifications) {
|
|
662 if (argument_modification.index == key
|
|
663 && !argument_modification.modified_type.isEmpty()) {
|
|
664 return argument_modification.modified_type;
|
|
665 }
|
|
666 }
|
|
667 }
|
|
668
|
|
669 return QString();
|
|
670 }
|
|
671
|
288
|
672 QString AbstractMetaFunction::minimalSignature(int reduce) const
|
1
|
673 {
|
288
|
674 if (!m_cached_minimal_signature.isEmpty() && !reduce)
|
1
|
675 return m_cached_minimal_signature;
|
|
676
|
|
677 QString minimalSignature = originalName() + "(";
|
|
678 AbstractMetaArgumentList arguments = this->arguments();
|
288
|
679 int argsCount = arguments.count() - reduce;
|
|
680 for (int i=0; i<argsCount; ++i) {
|
1
|
681 AbstractMetaType *t = arguments.at(i)->type();
|
|
682
|
|
683 if (i > 0)
|
|
684 minimalSignature += ",";
|
|
685
|
|
686 minimalSignature += t->minimalSignature();
|
|
687 }
|
|
688 minimalSignature += ")";
|
|
689 if (isConstant())
|
|
690 minimalSignature += "const";
|
|
691
|
|
692 minimalSignature = QMetaObject::normalizedSignature(minimalSignature.toLocal8Bit().constData());
|
288
|
693 if(!reduce)
|
|
694 m_cached_minimal_signature = minimalSignature;
|
1
|
695
|
|
696 return minimalSignature;
|
|
697 }
|
|
698
|
|
699 FunctionModificationList AbstractMetaFunction::modifications(const AbstractMetaClass *implementor) const
|
|
700 {
|
|
701 Q_ASSERT(implementor);
|
|
702 return implementor->typeEntry()->functionModifications(minimalSignature());
|
|
703 }
|
|
704
|
|
705 bool AbstractMetaFunction::hasModifications(const AbstractMetaClass *implementor) const
|
|
706 {
|
|
707 FunctionModificationList mods = modifications(implementor);
|
|
708 return mods.count() > 0;
|
|
709 }
|
|
710
|
|
711 QString AbstractMetaFunction::modifiedName() const
|
|
712 {
|
|
713 if (m_cached_modified_name.isEmpty()) {
|
|
714 FunctionModificationList mods = modifications(implementingClass());
|
|
715 foreach (FunctionModification mod, mods) {
|
|
716 if (mod.isRenameModifier()) {
|
|
717 m_cached_modified_name = mod.renamedToName;
|
|
718 break;
|
|
719 }
|
|
720 }
|
|
721 if (m_cached_modified_name.isEmpty())
|
|
722 m_cached_modified_name = name();
|
|
723 }
|
|
724 return m_cached_modified_name;
|
|
725 }
|
|
726
|
|
727 QString AbstractMetaFunction::targetLangSignature(bool minimal) const
|
|
728 {
|
|
729 QString s;
|
|
730
|
|
731 // Attributes...
|
|
732 if (!minimal) {
|
|
733 if (isPublic()) s += "public ";
|
|
734 else if (isProtected()) s += "protected ";
|
|
735 else if (isPrivate()) s += "private ";
|
|
736
|
|
737 // if (isNative()) s += "native ";
|
|
738 // else
|
|
739 if (isFinalInTargetLang()) s += "final ";
|
|
740 else if (isAbstract()) s += "abstract ";
|
|
741
|
|
742 if (isStatic()) s += "static ";
|
|
743
|
|
744 // Return type
|
|
745 if (type())
|
|
746 s += type()->fullName() + " ";
|
|
747 else
|
|
748 s += "void ";
|
|
749 }
|
|
750
|
|
751 s += name();
|
|
752 s += "(";
|
|
753
|
|
754 for (int i=0; i<m_arguments.size(); ++i) {
|
|
755 if (i != 0) {
|
|
756 s += ",";
|
|
757 if (!minimal)
|
|
758 s += QLatin1Char(' ');
|
|
759 }
|
|
760 s += m_arguments.at(i)->type()->fullName();
|
|
761
|
|
762 if (!minimal) {
|
|
763 s += " ";
|
|
764 s += m_arguments.at(i)->argumentName();
|
|
765 }
|
|
766 }
|
|
767
|
|
768 s += ")";
|
|
769
|
|
770 return s;
|
|
771 }
|
|
772
|
|
773
|
|
774 bool function_sorter(AbstractMetaFunction *a, AbstractMetaFunction *b)
|
|
775 {
|
|
776 return a->signature() < b->signature();
|
|
777 }
|
|
778
|
|
779 /*******************************************************************************
|
|
780 * AbstractMetaClass
|
|
781 */
|
|
782 AbstractMetaClass::~AbstractMetaClass()
|
|
783 {
|
|
784 qDeleteAll(m_functions);
|
|
785 qDeleteAll(m_fields);
|
|
786 }
|
|
787
|
|
788 /*AbstractMetaClass *AbstractMetaClass::copy() const
|
|
789 {
|
|
790 AbstractMetaClass *cls = new AbstractMetaClass;
|
|
791 cls->setAttributes(attributes());
|
|
792 cls->setBaseClass(baseClass());
|
|
793 cls->setTypeEntry(typeEntry());
|
|
794 foreach (AbstractMetaFunction *function, functions()) {
|
|
795 AbstractMetaFunction *copy = function->copy();
|
|
796 function->setImplementingClass(cls);
|
|
797 cls->addFunction(copy);
|
|
798 }
|
|
799 cls->setEnums(enums());
|
|
800 foreach (const AbstractMetaField *field, fields()) {
|
|
801 AbstractMetaField *copy = field->copy();
|
|
802 copy->setEnclosingClass(cls);
|
|
803 cls->addField(copy);
|
|
804 }
|
|
805 cls->setInterfaces(interfaces());
|
|
806
|
|
807 return cls;
|
|
808 }*/
|
|
809
|
|
810 /*******************************************************************************
|
|
811 * Returns true if this class is a subclass of the given class
|
|
812 */
|
|
813 bool AbstractMetaClass::inheritsFrom(const AbstractMetaClass *cls) const
|
|
814 {
|
|
815 Q_ASSERT(cls != 0);
|
|
816
|
|
817 const AbstractMetaClass *clazz = this;
|
|
818 while (clazz != 0) {
|
|
819 if (clazz == cls)
|
|
820 return true;
|
|
821
|
|
822 clazz = clazz->baseClass();
|
|
823 }
|
|
824
|
|
825 return false;
|
|
826 }
|
|
827
|
|
828 /*******************************************************************************
|
|
829 * Constructs an interface based on the functions and enums in this
|
|
830 * class and returns it...
|
|
831 */
|
|
832 AbstractMetaClass *AbstractMetaClass::extractInterface()
|
|
833 {
|
|
834 Q_ASSERT(typeEntry()->designatedInterface());
|
|
835
|
|
836 if (m_extracted_interface == 0) {
|
|
837 AbstractMetaClass *iface = new AbstractMetaClass;
|
|
838 iface->setAttributes(attributes());
|
|
839 iface->setBaseClass(0);
|
|
840 iface->setPrimaryInterfaceImplementor(this);
|
|
841
|
|
842 iface->setTypeEntry(typeEntry()->designatedInterface());
|
|
843
|
|
844 foreach (AbstractMetaFunction *function, functions()) {
|
|
845 if (!function->isConstructor())
|
|
846 iface->addFunction(function->copy());
|
|
847 }
|
|
848
|
|
849 // iface->setEnums(enums());
|
|
850 // setEnums(AbstractMetaEnumList());
|
|
851
|
|
852 foreach (const AbstractMetaField *field, fields()) {
|
|
853 if (field->isPublic()) {
|
|
854 AbstractMetaField *new_field = field->copy();
|
|
855 new_field->setEnclosingClass(iface);
|
|
856 iface->addField(new_field);
|
|
857 }
|
|
858 }
|
|
859
|
|
860 m_extracted_interface = iface;
|
|
861 addInterface(iface);
|
|
862 }
|
|
863
|
|
864 return m_extracted_interface;
|
|
865 }
|
|
866
|
|
867 /*******************************************************************************
|
|
868 * Returns a list of all the functions with a given name
|
|
869 */
|
|
870 AbstractMetaFunctionList AbstractMetaClass::queryFunctionsByName(const QString &name) const
|
|
871 {
|
|
872 AbstractMetaFunctionList returned;
|
|
873 AbstractMetaFunctionList functions = this->functions();
|
|
874 foreach (AbstractMetaFunction *function, functions) {
|
|
875 if (function->name() == name)
|
|
876 returned.append(function);
|
|
877 }
|
|
878
|
|
879 return returned;
|
|
880 }
|
|
881
|
|
882 /*******************************************************************************
|
|
883 * Returns all reference count modifications for any function in the class
|
|
884 */
|
|
885 QList<ReferenceCount> AbstractMetaClass::referenceCounts() const
|
|
886 {
|
|
887 QList<ReferenceCount> returned;
|
|
888
|
|
889 AbstractMetaFunctionList functions = this->functions();
|
|
890 foreach (AbstractMetaFunction *function, functions) {
|
|
891 returned += function->referenceCounts(this);
|
|
892 }
|
|
893
|
|
894 return returned;
|
|
895 }
|
|
896
|
|
897 /*******************************************************************************
|
|
898 * Returns a list of all the functions retrieved during parsing which should
|
|
899 * be added to the Java API.
|
|
900 */
|
|
901 AbstractMetaFunctionList AbstractMetaClass::functionsInTargetLang() const
|
|
902 {
|
|
903 int default_flags = NormalFunctions | Visible | NotRemovedFromTargetLang;
|
|
904
|
|
905 // Interfaces don't implement functions
|
|
906 default_flags |= isInterface() ? 0 : ClassImplements;
|
|
907
|
|
908 // Only public functions in final classes
|
|
909 // default_flags |= isFinal() ? WasPublic : 0;
|
|
910 int public_flags = isFinal() ? WasPublic : 0;
|
|
911
|
|
912 // Constructors
|
|
913 AbstractMetaFunctionList returned = queryFunctions(Constructors | default_flags | public_flags);
|
|
914
|
|
915 // Final functions
|
|
916 returned += queryFunctions(FinalInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);
|
|
917
|
|
918 // Virtual functions
|
|
919 returned += queryFunctions(VirtualInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);
|
|
920
|
|
921 // Static functions
|
|
922 returned += queryFunctions(StaticFunctions | default_flags | public_flags);
|
|
923
|
|
924 // Empty, private functions, since they aren't caught by the other ones
|
|
925 returned += queryFunctions(Empty | Invisible);
|
|
926
|
|
927 return returned;
|
|
928 }
|
|
929
|
|
930 AbstractMetaFunctionList AbstractMetaClass::virtualFunctions() const
|
|
931 {
|
|
932 AbstractMetaFunctionList list = functionsInShellClass();
|
|
933
|
|
934 AbstractMetaFunctionList returned;
|
|
935 foreach (AbstractMetaFunction *f, list) {
|
|
936 if (!f->isFinalInCpp() || f->isVirtualSlot())
|
|
937 returned += f;
|
|
938 }
|
|
939
|
|
940 return returned;
|
|
941 }
|
|
942
|
|
943 AbstractMetaFunctionList AbstractMetaClass::nonVirtualShellFunctions() const
|
|
944 {
|
|
945 AbstractMetaFunctionList list = functionsInShellClass();
|
|
946 AbstractMetaFunctionList returned;
|
|
947 foreach (AbstractMetaFunction *f, list) {
|
|
948 if (f->isFinalInCpp() && !f->isVirtualSlot())
|
|
949 returned += f;
|
|
950 }
|
|
951
|
|
952 return returned;
|
|
953 }
|
|
954
|
|
955 /*******************************************************************************
|
|
956 * Returns a list of all functions that should be declared and implemented in
|
|
957 * the shell class which is generated as a wrapper on top of the actual C++ class
|
|
958 */
|
|
959 AbstractMetaFunctionList AbstractMetaClass::functionsInShellClass() const
|
|
960 {
|
|
961 // Only functions and only protected and public functions
|
|
962 int default_flags = NormalFunctions | Visible | WasVisible | NotRemovedFromShell;
|
|
963
|
|
964 // All virtual functions
|
|
965 AbstractMetaFunctionList returned = queryFunctions(VirtualFunctions | default_flags);
|
|
966
|
|
967 // All functions explicitly set to be implemented by the shell class
|
|
968 // (mainly superclass functions that are hidden by other declarations)
|
|
969 returned += queryFunctions(ForcedShellFunctions | default_flags);
|
|
970
|
|
971 // All functions explicitly set to be virtual slots
|
|
972 returned += queryFunctions(VirtualSlots | default_flags);
|
|
973
|
|
974 return returned;
|
|
975 }
|
|
976
|
|
977 /*******************************************************************************
|
|
978 * Returns a list of all functions that require a public override function to
|
|
979 * be generated in the shell class. This includes all functions that were originally
|
|
980 * protected in the superclass.
|
|
981 */
|
|
982 AbstractMetaFunctionList AbstractMetaClass::publicOverrideFunctions() const
|
|
983 {
|
|
984 return queryFunctions(NormalFunctions | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang)
|
|
985 + queryFunctions(Signals | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang);
|
|
986 }
|
|
987
|
|
988 AbstractMetaFunctionList AbstractMetaClass::virtualOverrideFunctions() const
|
|
989 {
|
|
990 return queryFunctions(NormalFunctions | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell) +
|
|
991 queryFunctions(Signals | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell);
|
|
992 }
|
|
993
|
|
994 void AbstractMetaClass::sortFunctions()
|
|
995 {
|
|
996 qSort(m_functions.begin(), m_functions.end(), function_sorter);
|
|
997 }
|
|
998
|
|
999 void AbstractMetaClass::setFunctions(const AbstractMetaFunctionList &functions)
|
|
1000 {
|
|
1001 m_functions = functions;
|
|
1002
|
|
1003 // Functions must be sorted by name before next loop
|
|
1004 sortFunctions();
|
|
1005
|
|
1006 QString currentName;
|
|
1007 bool hasVirtuals = false;
|
|
1008 AbstractMetaFunctionList final_functions;
|
|
1009 foreach (AbstractMetaFunction *f, m_functions) {
|
|
1010 f->setOwnerClass(this);
|
|
1011
|
|
1012 m_has_virtual_slots |= f->isVirtualSlot();
|
|
1013 m_has_virtuals |= !f->isFinal() || f->isVirtualSlot();
|
|
1014 m_has_nonpublic |= !f->isPublic();
|
|
1015
|
|
1016 // If we have non-virtual overloads of a virtual function, we have to implement
|
|
1017 // all the overloads in the shell class to override the hiding rule
|
|
1018 if (currentName == f->name()) {
|
|
1019 hasVirtuals = hasVirtuals || !f->isFinal();
|
|
1020 if (f->isFinal())
|
|
1021 final_functions += f;
|
|
1022 } else {
|
|
1023 if (hasVirtuals && final_functions.size() > 0) {
|
|
1024 foreach (AbstractMetaFunction *final_function, final_functions) {
|
|
1025 *final_function += AbstractMetaAttributes::ForceShellImplementation;
|
|
1026
|
|
1027 QString warn = QString("hiding of function '%1' in class '%2'")
|
|
1028 .arg(final_function->name()).arg(name());
|
|
1029 ReportHandler::warning(warn);
|
|
1030 }
|
|
1031 }
|
|
1032
|
|
1033 hasVirtuals = !f->isFinal();
|
|
1034 final_functions.clear();
|
|
1035 if (f->isFinal())
|
|
1036 final_functions += f;
|
|
1037 currentName = f->name();
|
|
1038 }
|
|
1039 }
|
|
1040
|
|
1041 #ifndef QT_NO_DEBUG
|
|
1042 bool duplicate_function = false;
|
|
1043 for (int j=0; j<m_functions.size(); ++j) {
|
|
1044 FunctionModificationList mods = m_functions.at(j)->modifications(m_functions.at(j)->implementingClass());
|
|
1045
|
|
1046 bool removed = false;
|
|
1047 foreach (const FunctionModification &mod, mods) {
|
|
1048 if (mod.isRemoveModifier()) {
|
|
1049 removed = true;
|
|
1050 break ;
|
|
1051 }
|
|
1052 }
|
|
1053 if (removed)
|
|
1054 continue ;
|
|
1055
|
|
1056 for (int i=0; i<m_functions.size() - 1; ++i) {
|
|
1057 if (j == i)
|
|
1058 continue;
|
|
1059
|
|
1060 mods = m_functions.at(i)->modifications(m_functions.at(i)->implementingClass());
|
|
1061 bool removed = false;
|
|
1062 foreach (const FunctionModification &mod, mods) {
|
|
1063 if (mod.isRemoveModifier()) {
|
|
1064 removed = true;
|
|
1065 break ;
|
|
1066 }
|
|
1067 }
|
|
1068 if (removed)
|
|
1069 continue ;
|
|
1070
|
|
1071 uint cmp = m_functions.at(i)->compareTo(m_functions.at(j));
|
|
1072 if ((cmp & AbstractMetaFunction::EqualName) && (cmp & AbstractMetaFunction::EqualArguments)) {
|
|
1073 printf("%s.%s mostly equal to %s.%s\n",
|
|
1074 qPrintable(m_functions.at(i)->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1075 qPrintable(m_functions.at(i)->signature()),
|
|
1076 qPrintable(m_functions.at(j)->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1077 qPrintable(m_functions.at(j)->signature()));
|
|
1078 duplicate_function = true;
|
|
1079 }
|
|
1080 }
|
|
1081 }
|
|
1082 //Q_ASSERT(!duplicate_function);
|
|
1083 #endif
|
|
1084 }
|
|
1085
|
|
1086 bool AbstractMetaClass::hasFieldAccessors() const
|
|
1087 {
|
|
1088 foreach (const AbstractMetaField *field, fields()) {
|
|
1089 if (field->getter() || field->setter())
|
|
1090 return true;
|
|
1091 }
|
|
1092
|
|
1093 return false;
|
|
1094 }
|
|
1095
|
|
1096 bool AbstractMetaClass::hasDefaultToStringFunction() const
|
|
1097 {
|
|
1098 foreach (AbstractMetaFunction *f, queryFunctionsByName("toString")) {
|
|
1099 if (f->actualMinimumArgumentCount() == 0) {
|
|
1100 return true;
|
|
1101 }
|
|
1102
|
|
1103 }
|
|
1104 return false;
|
|
1105 }
|
|
1106
|
|
1107 void AbstractMetaClass::addFunction(AbstractMetaFunction *function)
|
|
1108 {
|
|
1109 function->setOwnerClass(this);
|
|
1110
|
|
1111 if (!function->isDestructor()) {
|
|
1112 m_functions << function;
|
|
1113 qSort(m_functions.begin(), m_functions.end(), function_sorter);
|
|
1114 }
|
|
1115
|
|
1116
|
|
1117 m_has_virtual_slots |= function->isVirtualSlot();
|
|
1118 m_has_virtuals |= !function->isFinal() || function->isVirtualSlot();
|
|
1119 m_has_nonpublic |= !function->isPublic();
|
|
1120 }
|
|
1121
|
|
1122 bool AbstractMetaClass::hasSignal(const AbstractMetaFunction *other) const
|
|
1123 {
|
|
1124 if (!other->isSignal())
|
|
1125 return false;
|
|
1126
|
|
1127 foreach (const AbstractMetaFunction *f, functions()) {
|
|
1128 if (f->isSignal() && f->compareTo(other) & AbstractMetaFunction::EqualName)
|
|
1129 return other->modifiedName() == f->modifiedName();
|
|
1130 }
|
|
1131
|
|
1132 return false;
|
|
1133 }
|
|
1134
|
|
1135
|
|
1136 QString AbstractMetaClass::name() const
|
|
1137 {
|
|
1138 return QString(m_type_entry->targetLangName()).replace("::", "_");
|
|
1139 }
|
|
1140
|
|
1141 bool AbstractMetaClass::hasFunction(const QString &str) const
|
|
1142 {
|
|
1143 foreach (const AbstractMetaFunction *f, functions())
|
|
1144 if (f->name() == str)
|
|
1145 return true;
|
|
1146 return false;
|
|
1147 }
|
|
1148
|
|
1149 /* Returns true if this class has one or more functions that are
|
|
1150 protected. If a class has protected members we need to generate a
|
|
1151 shell class with public accessors to the protected functions, so
|
|
1152 they can be called from the native functions.
|
|
1153 */
|
|
1154 bool AbstractMetaClass::hasProtectedFunctions() const {
|
|
1155 foreach (AbstractMetaFunction *func, m_functions) {
|
|
1156 if (func->isProtected())
|
|
1157 return true;
|
|
1158 }
|
|
1159 return false;
|
|
1160 }
|
|
1161
|
|
1162 bool AbstractMetaClass::generateShellClass() const
|
|
1163 {
|
|
1164 return m_force_shell_class ||
|
|
1165 (!isFinal()
|
|
1166 && (hasVirtualFunctions()
|
|
1167 || hasProtectedFunctions()
|
|
1168 || hasFieldAccessors()
|
|
1169 || typeEntry()->isObject())); // qtd2 for being more consistent
|
|
1170 }
|
|
1171
|
|
1172 QPropertySpec *AbstractMetaClass::propertySpecForRead(const QString &name) const
|
|
1173 {
|
|
1174 for (int i=0; i<m_property_specs.size(); ++i)
|
|
1175 if (name == m_property_specs.at(i)->read())
|
|
1176 return m_property_specs.at(i);
|
|
1177 return 0;
|
|
1178 }
|
|
1179
|
|
1180 QPropertySpec *AbstractMetaClass::propertySpecForWrite(const QString &name) const
|
|
1181 {
|
|
1182 for (int i=0; i<m_property_specs.size(); ++i)
|
|
1183 if (name == m_property_specs.at(i)->write())
|
|
1184 return m_property_specs.at(i);
|
|
1185 return 0;
|
|
1186 }
|
|
1187
|
|
1188 QPropertySpec *AbstractMetaClass::propertySpecForReset(const QString &name) const
|
|
1189 {
|
|
1190 for (int i=0; i<m_property_specs.size(); ++i) {
|
|
1191 if (name == m_property_specs.at(i)->reset())
|
|
1192 return m_property_specs.at(i);
|
|
1193 }
|
|
1194 return 0;
|
|
1195 }
|
|
1196
|
293
|
1197 AbstractMetaFunction* AbstractMetaClass::copyConstructor() const
|
|
1198 {
|
|
1199 AbstractMetaFunctionList ctors = queryFunctions(Constructors);
|
|
1200 for(int i = 0; i < ctors.size(); i++)
|
|
1201 {
|
|
1202 AbstractMetaFunction *ctor = ctors.at(i);
|
|
1203 if (ctor->arguments().size() > 0)
|
|
1204 if(ctor->arguments().at(0)->type()->typeEntry() == typeEntry())
|
|
1205 return ctor;
|
|
1206 }
|
1
|
1207
|
293
|
1208 return NULL;
|
|
1209 }
|
1
|
1210
|
|
1211 static bool functions_contains(const AbstractMetaFunctionList &l, const AbstractMetaFunction *func)
|
|
1212 {
|
|
1213 foreach (const AbstractMetaFunction *f, l) {
|
|
1214 if ((f->compareTo(func) & AbstractMetaFunction::PrettySimilar) == AbstractMetaFunction::PrettySimilar)
|
|
1215 return true;
|
|
1216 }
|
|
1217 return false;
|
|
1218 }
|
|
1219
|
|
1220 AbstractMetaField::AbstractMetaField() : m_getter(0), m_setter(0), m_class(0)
|
|
1221 {
|
|
1222 }
|
|
1223
|
|
1224 AbstractMetaField::~AbstractMetaField()
|
|
1225 {
|
|
1226 delete m_setter;
|
|
1227 delete m_getter;
|
|
1228 }
|
|
1229 ushort painters; // refcount
|
|
1230 AbstractMetaField *AbstractMetaField::copy() const
|
|
1231 {
|
|
1232 AbstractMetaField *returned = new AbstractMetaField;
|
|
1233 returned->setEnclosingClass(0);
|
|
1234 returned->setAttributes(attributes());
|
|
1235 returned->setName(name());
|
|
1236 returned->setType(type()->copy());
|
|
1237 returned->setOriginalAttributes(originalAttributes());
|
|
1238
|
|
1239 return returned;
|
|
1240 }
|
|
1241
|
|
1242 static QString upCaseFirst(const QString &str) {
|
|
1243 Q_ASSERT(!str.isEmpty());
|
|
1244 QString s = str;
|
|
1245 s[0] = s.at(0).toUpper();
|
|
1246 return s;
|
|
1247 }
|
|
1248
|
|
1249 static AbstractMetaFunction *createXetter(const AbstractMetaField *g, const QString &name, uint type) {
|
|
1250 AbstractMetaFunction *f = new AbstractMetaFunction;
|
|
1251
|
|
1252
|
|
1253
|
|
1254 f->setName(name);
|
|
1255 f->setOriginalName(name);
|
|
1256 f->setOwnerClass(g->enclosingClass());
|
|
1257 f->setImplementingClass(g->enclosingClass());
|
|
1258 f->setDeclaringClass(g->enclosingClass());
|
|
1259
|
|
1260 uint attr = AbstractMetaAttributes::Native
|
|
1261 | AbstractMetaAttributes::Final
|
|
1262 | type;
|
|
1263 if (g->isStatic())
|
|
1264 attr |= AbstractMetaAttributes::Static;
|
|
1265 if (g->isPublic())
|
|
1266 attr |= AbstractMetaAttributes::Public;
|
|
1267 else if (g->isProtected())
|
|
1268 attr |= AbstractMetaAttributes::Protected;
|
|
1269 else
|
|
1270 attr |= AbstractMetaAttributes::Private;
|
|
1271 f->setAttributes(attr);
|
|
1272 f->setOriginalAttributes(attr);
|
|
1273
|
|
1274 FieldModificationList mods = g->modifications();
|
|
1275 foreach (FieldModification mod, mods) {
|
|
1276 if (mod.isRenameModifier())
|
|
1277 f->setName(mod.renamedTo());
|
|
1278 if (mod.isAccessModifier()) {
|
|
1279 if (mod.isPrivate())
|
|
1280 f->setVisibility(AbstractMetaAttributes::Private);
|
|
1281 else if (mod.isProtected())
|
|
1282 f->setVisibility(AbstractMetaAttributes::Protected);
|
|
1283 else if (mod.isPublic())
|
|
1284 f->setVisibility(AbstractMetaAttributes::Public);
|
|
1285 else if (mod.isFriendly())
|
|
1286 f->setVisibility(AbstractMetaAttributes::Friendly);
|
|
1287 }
|
|
1288
|
|
1289 }
|
|
1290 return f;
|
|
1291 }
|
|
1292
|
|
1293 FieldModificationList AbstractMetaField::modifications() const
|
|
1294 {
|
|
1295 FieldModificationList mods = enclosingClass()->typeEntry()->fieldModifications();
|
|
1296 FieldModificationList returned;
|
|
1297
|
|
1298 foreach (FieldModification mod, mods) {
|
|
1299 if (mod.name == name())
|
|
1300 returned += mod;
|
|
1301 }
|
|
1302
|
|
1303 return returned;
|
|
1304 }
|
|
1305
|
|
1306 const AbstractMetaFunction *AbstractMetaField::setter() const
|
|
1307 {
|
|
1308 if (m_setter == 0) {
|
|
1309 m_setter = createXetter(this,
|
|
1310 "set" + upCaseFirst(name()),
|
|
1311 AbstractMetaAttributes::SetterFunction);
|
|
1312 AbstractMetaArgumentList arguments;
|
|
1313 AbstractMetaArgument *argument = new AbstractMetaArgument;
|
|
1314 argument->setType(type()->copy());
|
|
1315 argument->setName(name());
|
|
1316 arguments.append(argument);
|
|
1317 m_setter->setArguments(arguments);
|
|
1318 }
|
|
1319 return m_setter;
|
|
1320 }
|
|
1321
|
|
1322 const AbstractMetaFunction *AbstractMetaField::getter() const
|
|
1323 {
|
|
1324 if (m_getter == 0) {
|
|
1325 m_getter = createXetter(this,
|
|
1326 name(),
|
|
1327 AbstractMetaAttributes::GetterFunction);
|
|
1328 m_getter->setType(type());
|
|
1329 }
|
|
1330
|
|
1331 return m_getter;
|
|
1332 }
|
|
1333
|
|
1334
|
|
1335 bool AbstractMetaClass::hasConstructors() const
|
|
1336 {
|
|
1337 return queryFunctions(Constructors).size() != 0;
|
|
1338 }
|
|
1339
|
|
1340 void AbstractMetaClass::addDefaultConstructor()
|
|
1341 {
|
|
1342 AbstractMetaFunction *f = new AbstractMetaFunction;
|
|
1343 f->setName(name());
|
|
1344 f->setOwnerClass(this);
|
|
1345 f->setFunctionType(AbstractMetaFunction::ConstructorFunction);
|
|
1346 f->setArguments(AbstractMetaArgumentList());
|
|
1347 f->setDeclaringClass(this);
|
|
1348
|
|
1349 uint attr = AbstractMetaAttributes::Native;
|
|
1350 attr |= AbstractMetaAttributes::Public;
|
|
1351 attr |= AbstractMetaAttributes::Final; // qtd otherwise added constructor is virtual which in fact it is not
|
|
1352 f->setAttributes(attr);
|
|
1353 f->setImplementingClass(this);
|
|
1354 f->setOriginalAttributes(f->attributes());
|
|
1355
|
|
1356 addFunction(f);
|
|
1357 }
|
|
1358
|
|
1359 bool AbstractMetaClass::hasFunction(const AbstractMetaFunction *f) const
|
|
1360 {
|
|
1361 return functions_contains(m_functions, f);
|
|
1362 }
|
|
1363
|
|
1364 /* Goes through the list of functions and returns a list of all
|
|
1365 functions matching all of the criteria in \a query.
|
|
1366 */
|
|
1367
|
|
1368 AbstractMetaFunctionList AbstractMetaClass::queryFunctions(uint query) const
|
|
1369 {
|
|
1370 AbstractMetaFunctionList functions;
|
|
1371
|
|
1372 foreach (AbstractMetaFunction *f, m_functions) {
|
|
1373
|
|
1374 if ((query & VirtualSlots) && !f->isVirtualSlot())
|
|
1375 continue;
|
|
1376
|
|
1377 if ((query & NotRemovedFromTargetLang) && f->isRemovedFrom(f->implementingClass(), TypeSystem::TargetLangCode)) {
|
|
1378 continue;
|
|
1379 }
|
|
1380
|
|
1381 if ((query & NotRemovedFromTargetLang) && !f->isFinal() && f->isRemovedFrom(f->declaringClass(), TypeSystem::TargetLangCode)) {
|
|
1382 continue;
|
|
1383 }
|
|
1384
|
|
1385 if ((query & NotRemovedFromShell) && f->isRemovedFrom(f->implementingClass(), TypeSystem::ShellCode)) {
|
|
1386 continue;
|
|
1387 }
|
|
1388
|
|
1389 if ((query & NotRemovedFromShell) && !f->isFinal() && f->isRemovedFrom(f->declaringClass(), TypeSystem::ShellCode)) {
|
|
1390 continue;
|
|
1391 }
|
|
1392
|
|
1393 if ((query & Visible) && f->isPrivate()) {
|
|
1394 continue;
|
|
1395 }
|
|
1396
|
|
1397 if ((query & VirtualInTargetLangFunctions) && f->isFinalInTargetLang()) {
|
|
1398 continue;
|
|
1399 }
|
|
1400
|
|
1401 if ((query & Invisible) && !f->isPrivate()) {
|
|
1402 continue;
|
|
1403 }
|
|
1404
|
|
1405 if ((query & Empty) && !f->isEmptyFunction()) {
|
|
1406 continue;
|
|
1407 }
|
|
1408
|
|
1409 if ((query & WasPublic) && !f->wasPublic()) {
|
|
1410 continue;
|
|
1411 }
|
|
1412
|
|
1413 if ((query & WasVisible) && f->wasPrivate()) {
|
|
1414 continue;
|
|
1415 }
|
|
1416
|
|
1417 if ((query & WasProtected) && !f->wasProtected()) {
|
|
1418 continue;
|
|
1419 }
|
|
1420
|
|
1421 if ((query & ClassImplements) && f->ownerClass() != f->implementingClass()) {
|
|
1422 continue;
|
|
1423 }
|
|
1424
|
|
1425 if ((query & Inconsistent) && (f->isFinalInTargetLang() || !f->isFinalInCpp() || f->isStatic())) {
|
|
1426 continue;
|
|
1427 }
|
|
1428
|
|
1429 if ((query & FinalInTargetLangFunctions) && !f->isFinalInTargetLang()) {
|
|
1430 continue;
|
|
1431 }
|
|
1432
|
|
1433 if ((query & FinalInCppFunctions) && !f->isFinalInCpp()) {
|
|
1434 continue;
|
|
1435 }
|
|
1436
|
|
1437 if ((query & VirtualInCppFunctions) && f->isFinalInCpp()) {
|
|
1438 continue;
|
|
1439 }
|
|
1440
|
|
1441 if ((query & Signals) && (!f->isSignal())) {
|
|
1442 continue;
|
|
1443 }
|
|
1444
|
|
1445 if ((query & ForcedShellFunctions)
|
|
1446 && (!f->isForcedShellImplementation()
|
|
1447 || !f->isFinal())) {
|
|
1448 continue;
|
|
1449 }
|
|
1450
|
|
1451 if ((query & Constructors) && (!f->isConstructor()
|
|
1452 || f->ownerClass() != f->implementingClass())
|
|
1453 || f->isConstructor() && (query & Constructors) == 0) {
|
|
1454 continue;
|
|
1455 }
|
|
1456
|
|
1457 // Destructors are never included in the functions of a class currently
|
|
1458 /*
|
|
1459 if ((query & Destructors) && (!f->isDestructor()
|
|
1460 || f->ownerClass() != f->implementingClass())
|
|
1461 || f->isDestructor() && (query & Destructors) == 0) {
|
|
1462 continue;
|
|
1463 }*/
|
|
1464
|
|
1465 if ((query & VirtualFunctions) && (f->isFinal() || f->isSignal() || f->isStatic())) {
|
|
1466 continue;
|
|
1467 }
|
|
1468
|
|
1469 if ((query & StaticFunctions) && (!f->isStatic() || f->isSignal())) {
|
|
1470 continue;
|
|
1471 }
|
|
1472
|
|
1473 if ((query & NonStaticFunctions) && (f->isStatic())) {
|
|
1474 continue;
|
|
1475 }
|
|
1476
|
|
1477 if ((query & NonEmptyFunctions) && (f->isEmptyFunction())) {
|
|
1478 continue;
|
|
1479 }
|
|
1480
|
|
1481 if ((query & NormalFunctions) && (f->isSignal())) {
|
|
1482 continue;
|
|
1483 }
|
|
1484
|
|
1485 if ((query & AbstractFunctions) && !f->isAbstract()) {
|
|
1486 continue;
|
|
1487 }
|
|
1488
|
|
1489 functions << f;
|
|
1490 }
|
|
1491
|
|
1492 // qDebug() << "queried" << m_type_entry->qualifiedCppName() << "got" << functions.size() << "out of" << m_functions.size();
|
|
1493
|
|
1494 return functions;
|
|
1495 }
|
|
1496
|
|
1497
|
|
1498 bool AbstractMetaClass::hasInconsistentFunctions() const
|
|
1499 {
|
|
1500 return cppInconsistentFunctions().size() > 0;
|
|
1501 }
|
|
1502
|
|
1503 bool AbstractMetaClass::hasSignals() const
|
|
1504 {
|
|
1505 return cppSignalFunctions().size() > 0;
|
|
1506 }
|
|
1507
|
|
1508
|
|
1509 /**
|
|
1510 * Adds the specified interface to this class by adding all the
|
|
1511 * functions in the interface to this class.
|
|
1512 */
|
|
1513 void AbstractMetaClass::addInterface(AbstractMetaClass *interface)
|
|
1514 {
|
|
1515 Q_ASSERT(!m_interfaces.contains(interface));
|
|
1516 m_interfaces << interface;
|
|
1517
|
|
1518 if (m_extracted_interface != 0 && m_extracted_interface != interface)
|
|
1519 m_extracted_interface->addInterface(interface);
|
|
1520
|
|
1521 foreach (AbstractMetaFunction *function, interface->functions())
|
|
1522 if (!hasFunction(function) && !function->isConstructor()) {
|
|
1523 AbstractMetaFunction *cpy = function->copy();
|
|
1524 cpy->setImplementingClass(this);
|
|
1525
|
|
1526 // Setup that this function is an interface class.
|
|
1527 cpy->setInterfaceClass(interface);
|
|
1528 *cpy += AbstractMetaAttributes::InterfaceFunction;
|
|
1529
|
|
1530 // Copy the modifications in interface into the implementing classes.
|
|
1531 FunctionModificationList mods = function->modifications(interface);
|
|
1532 foreach (const FunctionModification &mod, mods) {
|
|
1533 m_type_entry->addFunctionModification(mod);
|
|
1534 }
|
|
1535
|
|
1536 // It should be mostly safe to assume that when we implement an interface
|
|
1537 // we don't "pass on" pure virtual functions to our sublcasses...
|
|
1538 // *cpy -= AbstractMetaAttributes::Abstract;
|
|
1539
|
|
1540 addFunction(cpy);
|
|
1541 }
|
|
1542 }
|
|
1543
|
|
1544
|
|
1545 void AbstractMetaClass::setInterfaces(const AbstractMetaClassList &interfaces)
|
|
1546 {
|
|
1547 m_interfaces = interfaces;
|
|
1548 }
|
|
1549
|
|
1550
|
|
1551 AbstractMetaEnum *AbstractMetaClass::findEnum(const QString &enumName)
|
|
1552 {
|
|
1553 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1554 if (e->name() == enumName)
|
|
1555 return e;
|
|
1556 }
|
|
1557
|
|
1558 if (typeEntry()->designatedInterface())
|
|
1559 return extractInterface()->findEnum(enumName);
|
|
1560
|
|
1561 return 0;
|
|
1562 }
|
|
1563
|
|
1564
|
|
1565
|
|
1566
|
|
1567 /*! Recursivly searches for the enum value named \a enumValueName in
|
|
1568 this class and its superclasses and interfaces. Values belonging to
|
|
1569 \a meta_enum are excluded from the search.
|
|
1570 */
|
|
1571 AbstractMetaEnumValue *AbstractMetaClass::findEnumValue(const QString &enumValueName, AbstractMetaEnum *meta_enum)
|
|
1572 {
|
|
1573 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1574 if (e == meta_enum)
|
|
1575 continue;
|
|
1576 foreach (AbstractMetaEnumValue *v, e->values()) {
|
|
1577 if (v->name() == enumValueName)
|
|
1578 return v;
|
|
1579 }
|
|
1580 }
|
|
1581
|
|
1582 if (typeEntry()->designatedInterface())
|
|
1583 return extractInterface()->findEnumValue(enumValueName, meta_enum);
|
|
1584
|
|
1585 if (baseClass() != 0)
|
|
1586 return baseClass()->findEnumValue(enumValueName, meta_enum);
|
|
1587
|
|
1588 return 0;
|
|
1589 }
|
|
1590
|
|
1591
|
|
1592 /*!
|
|
1593 * Searches through all of this class' enums for a value matching the
|
|
1594 * name \a enumValueName. The name is excluding the class/namespace
|
|
1595 * prefix. The function recursivly searches interfaces and baseclasses
|
|
1596 * of this class.
|
|
1597 */
|
|
1598 AbstractMetaEnum *AbstractMetaClass::findEnumForValue(const QString &enumValueName)
|
|
1599 {
|
|
1600 foreach (AbstractMetaEnum *e, m_enums) {
|
|
1601 foreach (AbstractMetaEnumValue *v, e->values()) {
|
|
1602 if (v->name() == enumValueName)
|
|
1603 return e;
|
|
1604 }
|
|
1605 }
|
|
1606
|
|
1607 if (typeEntry()->designatedInterface())
|
|
1608 return extractInterface()->findEnumForValue(enumValueName);
|
|
1609
|
|
1610 if (baseClass() != 0)
|
|
1611 return baseClass()->findEnumForValue(enumValueName);
|
|
1612
|
|
1613 return 0;
|
|
1614 }
|
|
1615
|
|
1616
|
|
1617 static void add_extra_include_for_type(AbstractMetaClass *meta_class, const AbstractMetaType *type)
|
|
1618 {
|
|
1619
|
|
1620 if (type == 0)
|
|
1621 return;
|
|
1622
|
|
1623 Q_ASSERT(meta_class != 0);
|
|
1624 const TypeEntry *entry = (type ? type->typeEntry() : 0);
|
|
1625 if (entry != 0 && entry->isComplex()) {
|
|
1626 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(entry);
|
|
1627 ComplexTypeEntry *class_entry = meta_class->typeEntry();
|
|
1628 if (class_entry != 0 && centry->include().isValid())
|
|
1629 class_entry->addExtraInclude(centry->include());
|
|
1630 }
|
|
1631
|
|
1632 if (type->hasInstantiations()) {
|
|
1633 QList<AbstractMetaType *> instantiations = type->instantiations();
|
|
1634 foreach (AbstractMetaType *instantiation, instantiations)
|
|
1635 add_extra_include_for_type(meta_class, instantiation);
|
|
1636 }
|
|
1637 }
|
|
1638
|
|
1639 static void add_extra_includes_for_function(AbstractMetaClass *meta_class, const AbstractMetaFunction *meta_function)
|
|
1640 {
|
|
1641 Q_ASSERT(meta_class != 0);
|
|
1642 Q_ASSERT(meta_function != 0);
|
|
1643 add_extra_include_for_type(meta_class, meta_function->type());
|
|
1644
|
|
1645 AbstractMetaArgumentList arguments = meta_function->arguments();
|
|
1646 foreach (AbstractMetaArgument *argument, arguments)
|
|
1647 add_extra_include_for_type(meta_class, argument->type());
|
|
1648 }
|
|
1649
|
|
1650 void AbstractMetaClass::fixFunctions()
|
|
1651 {
|
|
1652 if (m_functions_fixed)
|
|
1653 return;
|
|
1654 else
|
|
1655 m_functions_fixed = true;
|
|
1656
|
|
1657 AbstractMetaClass *super_class = baseClass();
|
|
1658 AbstractMetaFunctionList funcs = functions();
|
|
1659
|
|
1660 // printf("fix functions for %s\n", qPrintable(name()));
|
|
1661
|
|
1662 if (super_class != 0)
|
|
1663 super_class->fixFunctions();
|
|
1664 int iface_idx = 0;
|
|
1665 while (super_class || iface_idx < interfaces().size()) {
|
|
1666 // printf(" - base: %s\n", qPrintable(super_class->name()));
|
|
1667
|
|
1668 // Since we always traverse the complete hierarchy we are only
|
|
1669 // interrested in what each super class implements, not what
|
|
1670 // we may have propagated from their base classes again.
|
|
1671 AbstractMetaFunctionList super_funcs;
|
|
1672 if (super_class) {
|
|
1673
|
|
1674 // Super classes can never be final
|
|
1675 if (super_class->isFinalInTargetLang()) {
|
|
1676 ReportHandler::warning("Final class '" + super_class->name() + "' set to non-final, as it is extended by other classes");
|
|
1677 *super_class -= AbstractMetaAttributes::FinalInTargetLang;
|
|
1678 }
|
|
1679 super_funcs = super_class->queryFunctions(AbstractMetaClass::ClassImplements);
|
|
1680 } else {
|
|
1681 super_funcs = interfaces().at(iface_idx)->queryFunctions(AbstractMetaClass::NormalFunctions);
|
|
1682 }
|
|
1683
|
|
1684 QSet<AbstractMetaFunction *> funcs_to_add;
|
|
1685 for (int sfi=0; sfi<super_funcs.size(); ++sfi) {
|
|
1686 AbstractMetaFunction *sf = super_funcs.at(sfi);
|
|
1687
|
|
1688 if (sf->isRemovedFromAllLanguages(sf->implementingClass()))
|
|
1689 continue;
|
|
1690
|
|
1691 // we generally don't care about private functions, but we have to get the ones that are
|
|
1692 // virtual in case they override abstract functions.
|
|
1693 bool add = (sf->isNormal() || sf->isSignal() || sf->isEmptyFunction());
|
|
1694 for (int fi=0; fi<funcs.size(); ++fi) {
|
|
1695 AbstractMetaFunction *f = funcs.at(fi);
|
|
1696 if (f->isRemovedFromAllLanguages(f->implementingClass()))
|
|
1697 continue;
|
|
1698
|
|
1699 uint cmp = f->compareTo(sf);
|
|
1700
|
|
1701 if (cmp & AbstractMetaFunction::EqualModifiedName) {
|
|
1702 // printf(" - %s::%s similar to %s::%s %x vs %x\n",
|
|
1703 // qPrintable(sf->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1704 // qPrintable(sf->name()),
|
|
1705 // qPrintable(f->implementingClass()->typeEntry()->qualifiedCppName()),
|
|
1706 // qPrintable(f->name()),
|
|
1707 // sf->attributes(),
|
|
1708 // f->attributes());
|
|
1709
|
|
1710 add = false;
|
|
1711 if (cmp & AbstractMetaFunction::EqualArguments) {
|
|
1712
|
|
1713 // if (!(cmp & AbstractMetaFunction::EqualReturnType)) {
|
|
1714 // ReportHandler::warning(QString("%1::%2 and %3::%4 differ in retur type")
|
|
1715 // .arg(sf->implementingClass()->name())
|
|
1716 // .arg(sf->name())
|
|
1717 // .arg(f->implementingClass()->name())
|
|
1718 // .arg(f->name()));
|
|
1719 // }
|
|
1720
|
|
1721 // Same function, propegate virtual...
|
|
1722 if (!(cmp & AbstractMetaFunction::EqualAttributes)) {
|
|
1723 if (!f->isEmptyFunction()) {
|
|
1724 if (!sf->isFinalInCpp() && f->isFinalInCpp()) {
|
|
1725 *f -= AbstractMetaAttributes::FinalInCpp;
|
|
1726 // printf(" --- inherit virtual\n");
|
|
1727 }
|
|
1728 if (!sf->isFinalInTargetLang() && f->isFinalInTargetLang()) {
|
|
1729 *f -= AbstractMetaAttributes::FinalInTargetLang;
|
|
1730 // printf(" --- inherit virtual\n");
|
|
1731 }
|
|
1732 if (!f->isFinalInTargetLang() && f->isPrivate()) {
|
|
1733 f->setFunctionType(AbstractMetaFunction::EmptyFunction);
|
|
1734 f->setVisibility(AbstractMetaAttributes::Protected);
|
|
1735 *f += AbstractMetaAttributes::FinalInTargetLang;
|
|
1736 ReportHandler::warning(QString("private virtual function '%1' in '%2'")
|
|
1737 .arg(f->signature())
|
|
1738 .arg(f->implementingClass()->name()));
|
|
1739 }
|
|
1740 }
|
|
1741 }
|
|
1742
|
|
1743 if (f->visibility() != sf->visibility()) {
|
|
1744 QString warn = QString("visibility of function '%1' modified in class '%2'")
|
|
1745 .arg(f->name()).arg(name());
|
|
1746 ReportHandler::warning(warn);
|
|
1747
|
|
1748 // If new visibility is private, we can't
|
|
1749 // do anything. If it isn't, then we
|
|
1750 // prefer the parent class's visibility
|
|
1751 // setting for the function.
|
|
1752 if (!f->isPrivate() && !sf->isPrivate())
|
|
1753 f->setVisibility(sf->visibility());
|
|
1754
|
|
1755 // Private overrides of abstract functions have to go into the class or
|
|
1756 // the subclasses will not compile as non-abstract classes.
|
|
1757 // But they don't need to be implemented, since they can never be called.
|
|
1758 if (f->isPrivate() && sf->isAbstract()) {
|
|
1759 f->setFunctionType(AbstractMetaFunction::EmptyFunction);
|
|
1760 f->setVisibility(sf->visibility());
|
|
1761 *f += AbstractMetaAttributes::FinalInTargetLang;
|
|
1762 *f += AbstractMetaAttributes::FinalInCpp;
|
|
1763 }
|
|
1764 }
|
|
1765
|
|
1766 // Set the class which first declares this function, afawk
|
|
1767 f->setDeclaringClass(sf->declaringClass());
|
|
1768
|
|
1769 if (sf->isFinalInTargetLang() && !sf->isPrivate() && !f->isPrivate() && !sf->isStatic() && !f->isStatic()) {
|
|
1770 // Shadowed funcion, need to make base class
|
|
1771 // function non-virtual
|
|
1772 if (f->implementingClass() != sf->implementingClass() && f->implementingClass()->inheritsFrom(sf->implementingClass())) {
|
|
1773
|
|
1774 // Check whether the superclass method has been redefined to non-final
|
|
1775
|
|
1776 bool hasNonFinalModifier = false;
|
|
1777 bool isBaseImplPrivate = false;
|
|
1778 FunctionModificationList mods = sf->modifications(sf->implementingClass());
|
|
1779 foreach (FunctionModification mod, mods) {
|
|
1780 if (mod.isNonFinal()) {
|
|
1781 hasNonFinalModifier = true;
|
|
1782 break;
|
|
1783 } else if (mod.isPrivate()) {
|
|
1784 isBaseImplPrivate = true;
|
|
1785 break;
|
|
1786 }
|
|
1787 }
|
|
1788
|
|
1789 if (!hasNonFinalModifier && !isBaseImplPrivate) {
|
|
1790 ReportHandler::warning(QString::fromLatin1("Shadowing: %1::%2 and %3::%4; Java code will not compile")
|
|
1791 .arg(sf->implementingClass()->name())
|
|
1792 .arg(sf->signature())
|
|
1793 .arg(f->implementingClass()->name())
|
|
1794 .arg(f->signature()));
|
|
1795 }
|
|
1796 }
|
|
1797 }
|
|
1798
|
|
1799 }
|
|
1800
|
|
1801 if (cmp & AbstractMetaFunction::EqualDefaultValueOverload) {
|
|
1802 AbstractMetaArgumentList arguments;
|
|
1803 if (f->arguments().size() < sf->arguments().size())
|
|
1804 arguments = sf->arguments();
|
|
1805 else
|
|
1806 arguments = f->arguments();
|
|
1807 /* qtd
|
|
1808 for (int i=0; i<arguments.size(); ++i)
|
|
1809 arguments[i]->setDefaultValueExpression(QString());
|
|
1810 */ }
|
|
1811
|
|
1812
|
|
1813 // Otherwise we have function shadowing and we can
|
|
1814 // skip the thing...
|
|
1815 } else if (cmp & AbstractMetaFunction::EqualName && !sf->isSignal()) {
|
|
1816
|
|
1817 // In the case of function shadowing where the function name has been altered to
|
|
1818 // avoid conflict, we don't copy in the original.
|
|
1819 add = false;
|
|
1820 }
|
|
1821
|
|
1822 }
|
|
1823
|
|
1824 if (add)
|
|
1825 funcs_to_add << sf;
|
|
1826 }
|
|
1827
|
|
1828 foreach (AbstractMetaFunction *f, funcs_to_add)
|
|
1829 funcs << f->copy();
|
|
1830
|
|
1831 if (super_class)
|
|
1832 super_class = super_class->baseClass();
|
|
1833 else
|
|
1834 iface_idx++;
|
|
1835 }
|
|
1836
|
|
1837 bool hasPrivateConstructors = false;
|
|
1838 bool hasPublicConstructors = false;
|
|
1839 foreach (AbstractMetaFunction *func, funcs) {
|
|
1840 FunctionModificationList mods = func->modifications(this);
|
|
1841 foreach (const FunctionModification &mod, mods) {
|
|
1842 if (mod.isRenameModifier()) {
|
|
1843 // qDebug() << name() << func->originalName() << func << " from "
|
|
1844 // << func->implementingClass()->name() << "renamed to" << mod.renamedTo();
|
|
1845 func->setName(mod.renamedTo());
|
|
1846 }
|
|
1847 }
|
|
1848
|
|
1849 // Make sure class is abstract if one of the functions is
|
|
1850 if (func->isAbstract()) {
|
|
1851 (*this) += AbstractMetaAttributes::Abstract;
|
|
1852 (*this) -= AbstractMetaAttributes::Final;
|
|
1853 }
|
|
1854
|
|
1855 if (func->isConstructor()) {
|
|
1856 if (func->isPrivate())
|
|
1857 hasPrivateConstructors = true;
|
|
1858 else
|
|
1859 hasPublicConstructors = true;
|
|
1860 }
|
|
1861
|
|
1862
|
|
1863
|
|
1864 // Make sure that we include files for all classes that are in use
|
|
1865
|
|
1866 if (!func->isRemovedFrom(this, TypeSystem::ShellCode))
|
|
1867 add_extra_includes_for_function(this, func);
|
|
1868 }
|
|
1869
|
|
1870 if (hasPrivateConstructors && !hasPublicConstructors) {
|
|
1871 (*this) += AbstractMetaAttributes::Abstract;
|
|
1872 (*this) -= AbstractMetaAttributes::Final;
|
|
1873 }
|
|
1874
|
|
1875 foreach (AbstractMetaFunction *f1, funcs) {
|
|
1876 foreach (AbstractMetaFunction *f2, funcs) {
|
|
1877 if (f1 != f2) {
|
|
1878 uint cmp = f1->compareTo(f2);
|
|
1879 if ((cmp & AbstractMetaFunction::EqualName)
|
|
1880 && !f1->isFinalInCpp()
|
|
1881 && f2->isFinalInCpp()) {
|
|
1882 *f2 += AbstractMetaAttributes::FinalOverload;
|
|
1883 // qDebug() << f2 << f2->implementingClass()->name() << "::" << f2->name() << f2->arguments().size() << " vs " << f1 << f1->implementingClass()->name() << "::" << f1->name() << f1->arguments().size();
|
|
1884 // qDebug() << " " << f2;
|
|
1885 // AbstractMetaArgumentList f2Args = f2->arguments();
|
|
1886 // foreach (AbstractMetaArgument *a, f2Args)
|
|
1887 // qDebug() << " " << a->type()->name() << a->name();
|
|
1888 // qDebug() << " " << f1;
|
|
1889 // AbstractMetaArgumentList f1Args = f1->arguments();
|
|
1890 // foreach (AbstractMetaArgument *a, f1Args)
|
|
1891 // qDebug() << " " << a->type()->name() << a->name();
|
|
1892
|
|
1893 }
|
|
1894 }
|
|
1895 }
|
|
1896 }
|
|
1897
|
|
1898 setFunctions(funcs);
|
|
1899 }
|
|
1900
|
|
1901
|
|
1902 QString AbstractMetaType::minimalSignature() const
|
|
1903 {
|
|
1904 QString minimalSignature;
|
|
1905 if (isConstant())
|
|
1906 minimalSignature += "const ";
|
|
1907 minimalSignature += typeEntry()->qualifiedCppName();
|
|
1908 if (hasInstantiations()) {
|
|
1909 QList<AbstractMetaType *> instantiations = this->instantiations();
|
|
1910 minimalSignature += "<";
|
|
1911 for (int i=0;i<instantiations.size();++i) {
|
|
1912 if (i > 0)
|
|
1913 minimalSignature += ",";
|
|
1914 minimalSignature += instantiations.at(i)->minimalSignature();
|
|
1915 }
|
|
1916 minimalSignature += ">";
|
|
1917 }
|
|
1918
|
|
1919 if (isReference())
|
|
1920 minimalSignature += "&";
|
|
1921 for (int j=0; j<indirections(); ++j)
|
|
1922 minimalSignature += "*";
|
|
1923
|
|
1924 return minimalSignature;
|
|
1925 }
|
|
1926
|
|
1927 bool AbstractMetaType::hasNativeId() const
|
|
1928 {
|
|
1929 return (isQObject() || isValue() || isObject()) && typeEntry()->isNativeIdBased();
|
|
1930 }
|
|
1931
|
|
1932
|
|
1933 /*******************************************************************************
|
|
1934 * Other stuff...
|
|
1935 */
|
|
1936
|
|
1937
|
|
1938 AbstractMetaEnum *AbstractMetaClassList::findEnum(const EnumTypeEntry *entry) const
|
|
1939 {
|
|
1940 Q_ASSERT(entry->isEnum());
|
|
1941
|
|
1942 QString qualified_name = entry->qualifiedCppName();
|
|
1943 int pos = qualified_name.lastIndexOf("::");
|
|
1944
|
|
1945 QString enum_name;
|
|
1946 QString class_name;
|
|
1947
|
|
1948 if (pos > 0) {
|
|
1949 enum_name = qualified_name.mid(pos + 2);
|
|
1950 class_name = qualified_name.mid(0, pos);
|
|
1951 } else {
|
|
1952 enum_name = qualified_name;
|
|
1953 class_name = TypeDatabase::globalNamespaceClassName(entry);
|
|
1954 }
|
|
1955
|
|
1956 AbstractMetaClass *meta_class = findClass(class_name);
|
|
1957 if (!meta_class) {
|
|
1958 ReportHandler::warning(QString("AbstractMeta::findEnum(), unknown class '%1' in '%2'")
|
|
1959 .arg(class_name).arg(entry->qualifiedCppName()));
|
|
1960 return 0;
|
|
1961 }
|
|
1962
|
|
1963 return meta_class->findEnum(enum_name);
|
|
1964 }
|
|
1965
|
|
1966 AbstractMetaEnumValue *AbstractMetaEnumValueList::find(const QString &name) const
|
|
1967 {
|
|
1968 for (int i=0; i<size(); ++i) {
|
|
1969 if (name == at(i)->name())
|
|
1970 return at(i);
|
|
1971 }
|
|
1972 return 0;
|
|
1973 }
|
|
1974
|
|
1975 AbstractMetaEnumValue *AbstractMetaClassList::findEnumValue(const QString &name) const
|
|
1976 {
|
|
1977 QStringList lst = name.split(QLatin1String("::"));
|
|
1978
|
|
1979 Q_ASSERT_X(lst.size() == 2, "AbstractMetaClassList::findEnumValue()", "Expected qualified enum");
|
|
1980
|
|
1981
|
|
1982 QString prefixName = lst.at(0);
|
|
1983 QString enumName = lst.at(1);
|
|
1984
|
|
1985 AbstractMetaClass *cl = findClass(prefixName);
|
|
1986 if (cl)
|
|
1987 return cl->findEnumValue(enumName, 0);
|
|
1988
|
|
1989 ReportHandler::warning(QString("no matching enum '%1'").arg(name));
|
|
1990 return 0;
|
|
1991 }
|
|
1992
|
|
1993 /*!
|
|
1994 * Searches the list after a class that mathces \a name; either as
|
|
1995 * C++, Java base name or complete Java package.class name.
|
|
1996 */
|
|
1997
|
|
1998 AbstractMetaClass *AbstractMetaClassList::findClass(const QString &name) const
|
|
1999 {
|
|
2000 if (name.isEmpty())
|
|
2001 return 0;
|
|
2002
|
|
2003 foreach (AbstractMetaClass *c, *this) {
|
|
2004 if (c->qualifiedCppName() == name)
|
|
2005 return c;
|
|
2006 }
|
|
2007
|
|
2008 foreach (AbstractMetaClass *c, *this) {
|
|
2009 if (c->fullName() == name)
|
|
2010 return c;
|
|
2011 }
|
|
2012
|
|
2013 foreach (AbstractMetaClass *c, *this) {
|
|
2014 if (c->name() == name)
|
|
2015 return c;
|
|
2016 }
|
|
2017
|
|
2018 return 0;
|
|
2019 }
|
|
2020
|
|
2021 ArgumentReplace *ArgumentReplace::m_instance = 0;
|
|
2022
|
|
2023 ArgumentReplace::ArgumentReplace()
|
|
2024 {
|
|
2025 }
|
|
2026
|
|
2027 void ArgumentReplace::init()
|
|
2028 {
|
|
2029 if (m_instance)
|
|
2030 return;
|
|
2031
|
|
2032 m_instance = new ArgumentReplace();
|
|
2033 m_instance->data["version"] = "_version";
|
|
2034 m_instance->data["parent"] = "_parent";
|
|
2035 m_instance->data["delegate"] = "_delegate";
|
|
2036 m_instance->data["align"] = "_align";
|
|
2037 m_instance->data["in"] = "_in";
|
|
2038 m_instance->data["out"] = "_out";
|
|
2039 m_instance->data["scope"] = "_scope";
|
|
2040 m_instance->data["default"] = "_default";
|
39
|
2041 m_instance->data["body"] = "_body";
|
1
|
2042 }
|
|
2043
|
|
2044 QString ArgumentReplace::translate(QString arg)
|
|
2045 {
|
|
2046 if (m_instance->data.contains(arg))
|
|
2047 return m_instance->data[arg];
|
|
2048 else
|
|
2049 return arg;
|
|
2050 }
|