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