Mercurial > projects > qtd
annotate generator/typesystem.h @ 282:256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author | eldar |
---|---|
date | Fri, 16 Oct 2009 02:43:59 +0000 |
parents | ae34188ddd84 |
children | 17b5e13364b7 adae77fdc1ea |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #ifndef TYPESYSTEM_H | |
43 #define TYPESYSTEM_H | |
44 | |
45 #include <QtCore/QHash> | |
46 #include <QtCore/QString> | |
47 #include <QtCore/QStringList> | |
48 #include <QtCore/QMap> | |
49 #include <QDebug> | |
50 | |
51 class Indentor; | |
52 | |
53 class AbstractMetaType; | |
54 class QTextStream; | |
55 | |
56 class EnumTypeEntry; | |
57 class FlagsTypeEntry; | |
58 | |
59 extern QString strings_Object; | |
60 extern QString strings_String; | |
61 extern QString strings_Thread; | |
62 extern QString strings_char; | |
63 extern QString strings_java_lang; | |
64 extern QString strings_jchar; | |
65 extern QString strings_jobject; | |
66 | |
67 struct Include | |
68 { | |
69 enum IncludeType { | |
70 IncludePath, | |
71 LocalPath, | |
72 TargetLangImport | |
73 }; | |
74 | |
75 Include() : type(IncludePath) { } | |
76 Include(IncludeType t, const QString &nam) : type(t), name(nam) { }; | |
77 | |
78 bool isValid() { return !name.isEmpty(); } | |
79 | |
80 IncludeType type; | |
81 QString name; | |
82 | |
83 QString toString() const; | |
84 | |
85 bool operator<(const Include &other) const { return name < other.name; } | |
86 }; | |
87 typedef QList<Include> IncludeList; | |
88 | |
89 typedef QMap<int, QString> ArgumentMap; | |
90 | |
91 class TemplateInstance; | |
92 | |
93 namespace TypeSystem { | |
94 enum Language { | |
95 NoLanguage = 0x0000, | |
96 TargetLangCode = 0x0001, | |
97 NativeCode = 0x0002, | |
14 | 98 TargetLangFreeCode = 0x0003, |
1 | 99 ShellCode = 0x0004, |
100 ShellDeclaration = 0x0008, | |
101 PackageInitializer = 0x0010, | |
102 DestructorFunction = 0x0020, | |
103 Constructors = 0x0040, | |
104 Interface = 0x0080, | |
105 | |
106 // masks | |
107 All = TargetLangCode | |
108 | NativeCode | |
109 | ShellCode | |
110 | ShellDeclaration | |
111 | PackageInitializer | |
112 | Constructors | |
113 | Interface | |
114 | DestructorFunction, | |
115 | |
116 JavaAndNativeCode = TargetLangCode | NativeCode, | |
117 TargetLangAndNativeCode = TargetLangCode | NativeCode | |
118 }; | |
119 | |
120 enum Ownership { | |
121 InvalidOwnership, | |
122 DefaultOwnership, | |
123 TargetLangOwnership, | |
124 CppOwnership | |
125 }; | |
126 }; | |
127 | |
128 struct ReferenceCount | |
129 { | |
130 ReferenceCount() : threadSafe(false), access(Public) { } | |
131 enum Action { // 0x01 - 0xff | |
132 Invalid = 0x00, | |
133 Add = 0x01, | |
134 AddAll = 0x02, | |
135 Remove = 0x04, | |
136 Set = 0x08, | |
137 Ignore = 0x10, | |
138 | |
139 ActionsMask = 0xff, | |
140 | |
141 Padding = 0xffffffff | |
142 }; | |
143 | |
144 enum Flag { // 0x100 - 0xf00 | |
145 ThreadSafe = 0x100, | |
146 Static = 0x200, | |
147 DeclareVariable = 0x400, | |
148 | |
149 FlagsMask = 0xf00 | |
150 }; | |
151 | |
152 enum Access { // 0x1000 - 0xf000 | |
153 Private = 0x1000, | |
154 Protected = 0x2000, | |
155 Friendly = 0x3000, | |
156 Public = 0x4000, | |
157 | |
158 AccessMask = 0xf000 | |
159 }; | |
160 | |
161 Action action; | |
162 QString variableName; | |
163 QString conditional; | |
164 QString declareVariable; | |
165 | |
166 uint threadSafe : 1; | |
167 | |
168 uint access; | |
169 }; | |
170 | |
171 class CodeSnipFragment{ | |
172 private: | |
173 const QString m_code; | |
174 TemplateInstance *m_instance; | |
175 | |
176 public: | |
177 CodeSnipFragment(const QString &code) | |
178 : m_code(code), | |
179 m_instance(0) | |
180 {} | |
181 | |
182 CodeSnipFragment(TemplateInstance *instance) | |
183 : m_instance(instance) | |
184 {} | |
185 | |
186 QString code() const; | |
187 }; | |
188 | |
189 class CodeSnipAbstract{ | |
190 public: | |
191 QString code() const; | |
192 | |
193 void addCode(const QString &code){ | |
194 codeList.append(new CodeSnipFragment(code)); | |
195 } | |
196 | |
197 void addTemplateInstance(TemplateInstance *ti){ | |
198 codeList.append(new CodeSnipFragment(ti)); | |
199 } | |
200 | |
201 QList<CodeSnipFragment*> codeList; | |
202 }; | |
203 | |
204 class CustomFunction : public CodeSnipAbstract | |
205 { | |
206 public: | |
207 CustomFunction(const QString &n = QString()) : name(n) { } | |
208 | |
209 QString name; | |
210 QString param_name; | |
211 }; | |
212 | |
213 class TemplateEntry : public CodeSnipAbstract | |
214 { | |
215 public: | |
216 TemplateEntry(const QString &name) | |
217 : m_name(name) | |
218 { | |
219 }; | |
220 | |
221 QString name() const { | |
222 return m_name; | |
223 }; | |
224 | |
225 private: | |
226 QString m_name; | |
227 }; | |
228 | |
229 typedef QHash<QString, TemplateEntry *> TemplateEntryHash; | |
230 | |
231 class TemplateInstance | |
232 { | |
233 public: | |
234 TemplateInstance(const QString &name) | |
235 : m_name(name) | |
236 {} | |
237 | |
238 void addReplaceRule(const QString &name, const QString &value){ | |
239 replaceRules[name]=value; | |
240 } | |
241 | |
242 QString expandCode() const; | |
243 | |
244 QString name() const { | |
245 return m_name; | |
246 } | |
247 | |
248 private: | |
249 const QString m_name; | |
250 QHash<QString, QString> replaceRules; | |
251 }; | |
252 | |
253 | |
254 class CodeSnip : public CodeSnipAbstract | |
255 { | |
256 public: | |
257 enum Position { | |
258 Beginning, | |
259 End, | |
260 AfterThis | |
261 }; | |
262 | |
263 CodeSnip() : language(TypeSystem::TargetLangCode) { } | |
264 CodeSnip(TypeSystem::Language lang) : language(lang) { } | |
265 | |
266 // Very simple, easy to make code ugly if you try | |
267 QTextStream &formattedCode(QTextStream &s, Indentor &indentor) const; | |
268 | |
269 TypeSystem::Language language; | |
270 Position position; | |
271 ArgumentMap argumentMap; | |
272 }; | |
273 typedef QList<CodeSnip> CodeSnipList; | |
274 | |
275 struct ArgumentModification | |
276 { | |
277 ArgumentModification(int idx) : removed_default_expression(false), removed(false), no_null_pointers(false), index(idx) | |
278 {} | |
279 | |
280 // Should the default expression be removed? | |
281 uint removed_default_expression : 1; | |
282 uint removed : 1; | |
283 uint no_null_pointers : 1; | |
284 uint reset_after_use : 1; | |
285 | |
286 // The index of this argument | |
287 int index; | |
288 | |
289 // Reference count flags for this argument | |
290 QList<ReferenceCount> referenceCounts; | |
291 | |
292 // The text given for the new type of the argument | |
293 QString modified_type; | |
294 | |
295 QString replace_value; | |
296 | |
297 // The code to be used to construct a return value when no_null_pointers is true and | |
298 // the returned value is null. If no_null_pointers is true and this string is | |
299 // empty, then the base class implementation will be used (or a default construction | |
300 // if there is no implementation) | |
301 QString null_pointer_default_value; | |
302 | |
303 // The text of the new default expression of the argument | |
304 QString replaced_default_expression; | |
305 | |
306 // The new definition of ownership for a specific argument | |
307 QHash<TypeSystem::Language, TypeSystem::Ownership> ownerships; | |
308 | |
309 // Different conversion rules | |
310 CodeSnipList conversion_rules; | |
311 }; | |
312 | |
313 struct Modification { | |
314 enum Modifiers { | |
315 Private = 0x0001, | |
316 Protected = 0x0002, | |
317 Public = 0x0003, | |
318 Friendly = 0x0004, | |
319 AccessModifierMask = 0x000f, | |
320 | |
321 Final = 0x0010, | |
322 NonFinal = 0x0020, | |
323 FinalMask = Final | NonFinal, | |
324 | |
325 Readable = 0x0100, | |
326 Writable = 0x0200, | |
327 | |
328 CodeInjection = 0x1000, | |
329 Rename = 0x2000, | |
330 Deprecated = 0x4000, | |
331 ReplaceExpression = 0x8000, | |
148
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
42
diff
changeset
|
332 VirtualSlot = 0x10000 | NonFinal, |
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
42
diff
changeset
|
333 AllowAsSlot = 0x00020000, |
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
42
diff
changeset
|
334 PrivateSignal = 0x00040000 |
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
42
diff
changeset
|
335 |
1 | 336 }; |
337 | |
338 Modification() : modifiers(0) { } | |
339 | |
340 bool isAccessModifier() const { return modifiers & AccessModifierMask; } | |
341 Modifiers accessModifier() const { return Modifiers(modifiers & AccessModifierMask); } | |
342 bool isPrivate() const { return accessModifier() == Private; } | |
343 bool isProtected() const { return accessModifier() == Protected; } | |
344 bool isPublic() const { return accessModifier() == Public; } | |
345 bool isFriendly() const { return accessModifier() == Friendly; } | |
346 bool isFinal() const { return modifiers & Final; } | |
347 bool isNonFinal() const { return modifiers & NonFinal; } | |
348 bool isVirtualSlot() const { return (modifiers & VirtualSlot) == VirtualSlot; } | |
148
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
42
diff
changeset
|
349 bool isAllowedAsSlot() const { return (modifiers & AllowAsSlot) == AllowAsSlot; } |
ae34188ddd84
private signals of QAbstractItemModel are now accessible
eldar
parents:
42
diff
changeset
|
350 bool isPrivateSignal() const { return (modifiers & PrivateSignal) == PrivateSignal; } |
1 | 351 QString accessModifierString() const; |
352 | |
353 bool isDeprecated() const { return modifiers & Deprecated; } | |
354 | |
355 void setRenamedTo(const QString &name) { renamedToName = name; } | |
356 QString renamedTo() const { return renamedToName; } | |
357 bool isRenameModifier() const { return modifiers & Rename; } | |
358 | |
359 uint modifiers; | |
360 QString renamedToName; | |
361 }; | |
362 | |
363 struct FunctionModification: public Modification | |
364 { | |
365 FunctionModification() : removal(TypeSystem::NoLanguage), store_result(false) { } | |
366 | |
367 bool isCodeInjection() const { return modifiers & CodeInjection; } | |
368 bool isRemoveModifier() const { return removal != TypeSystem::NoLanguage; } | |
369 | |
370 QString toString() const; | |
371 | |
372 QString signature; | |
373 QString association; | |
374 CodeSnipList snips; | |
375 TypeSystem::Language removal; | |
376 bool store_result; | |
377 | |
378 QList<ArgumentModification> argument_mods; | |
379 }; | |
380 typedef QList<FunctionModification> FunctionModificationList; | |
381 | |
382 struct FieldModification: public Modification | |
383 { | |
384 bool isReadable() const { return modifiers & Readable; } | |
385 bool isWritable() const { return modifiers & Writable; } | |
386 | |
387 QString name; | |
388 }; | |
389 typedef QList<FieldModification> FieldModificationList; | |
390 | |
391 struct ExpensePolicy { | |
392 ExpensePolicy() : limit(-1) { } | |
393 int limit; | |
394 QString cost; | |
395 bool isValid() const { return limit >= 0; } | |
396 }; | |
397 | |
398 class InterfaceTypeEntry; | |
399 class ObjectTypeEntry; | |
400 | |
401 class TypeEntry | |
402 { | |
403 public: | |
404 enum Type { | |
405 PrimitiveType, | |
406 VoidType, | |
407 FlagsType, | |
408 EnumType, | |
409 TemplateArgumentType, | |
410 ThreadType, | |
411 BasicValueType, | |
412 StringType, | |
413 ContainerType, | |
414 InterfaceType, | |
415 ObjectType, | |
416 NamespaceType, | |
417 VariantType, | |
418 JObjectWrapperType, | |
419 CharType, | |
420 ArrayType, | |
421 TypeSystemType, | |
422 CustomType, | |
423 }; | |
424 | |
425 enum CodeGeneration { | |
426 GenerateTargetLang = 0x0001, | |
427 GenerateCpp = 0x0002, | |
428 GenerateForSubclass = 0x0004, | |
429 | |
430 GenerateNothing = 0, | |
431 GenerateAll = 0xffff, | |
432 GenerateCode = GenerateTargetLang | GenerateCpp | |
433 }; | |
434 | |
435 TypeEntry(const QString &name, Type t) | |
436 : m_name(name), | |
437 m_type(t), | |
438 m_code_generation(GenerateAll), | |
439 m_preferred_conversion(true) | |
440 { | |
441 }; | |
442 | |
443 virtual ~TypeEntry() { } | |
444 | |
445 Type type() const { return m_type; } | |
446 bool isPrimitive() const { return m_type == PrimitiveType; } | |
447 bool isEnum() const { return m_type == EnumType; } | |
448 bool isFlags() const { return m_type == FlagsType; } | |
449 bool isInterface() const { return m_type == InterfaceType; } | |
450 bool isObject() const { return m_type == ObjectType; } | |
451 bool isString() const { return m_type == StringType; } | |
452 bool isChar() const { return m_type == CharType; } | |
453 bool isNamespace() const { return m_type == NamespaceType; } | |
454 bool isContainer() const { return m_type == ContainerType; } | |
455 bool isVariant() const { return m_type == VariantType; } | |
456 bool isJObjectWrapper() const { return m_type == JObjectWrapperType; } | |
457 bool isArray() const { return m_type == ArrayType; } | |
458 bool isTemplateArgument() const { return m_type == TemplateArgumentType; } | |
459 bool isVoid() const { return m_type == VoidType; } | |
460 bool isThread() const { return m_type == ThreadType; } | |
461 bool isCustom() const { return m_type == CustomType; } | |
462 bool isBasicValue() const { return m_type == BasicValueType; } | |
463 bool isTypeSystem() const { return m_type == TypeSystemType; } | |
464 | |
465 virtual bool preferredConversion() const { return m_preferred_conversion; } | |
466 virtual void setPreferredConversion(bool b) { m_preferred_conversion = b; } | |
467 | |
468 virtual QString javaQualifier() const { return QString(); } | |
469 | |
470 // The type's name in C++, fully qualified | |
471 QString name() const { return m_name; } | |
472 | |
473 uint codeGeneration() const { return m_code_generation; } | |
474 void setCodeGeneration(uint cg) { m_code_generation = cg; } | |
475 | |
476 virtual QString qualifiedCppName() const { return m_name; } | |
477 | |
478 // Its type's name in JNI | |
479 virtual QString jniName() const { return m_name; } | |
480 | |
481 // The type's name in TargetLang | |
482 virtual QString targetLangName() const { return m_name; } | |
483 | |
484 // The type to lookup when converting to TargetLang | |
485 virtual QString lookupName() const { return targetLangName(); } | |
486 | |
487 // The package | |
488 virtual QString javaPackage() const { return QString(); } | |
489 | |
490 virtual QString qualifiedTargetLangName() const { | |
491 // QString pkg = javaPackage(); | |
492 /* if (pkg.isEmpty())*/ return targetLangName(); | |
493 // return pkg + '.' + targetLangName(); | |
494 } | |
495 | |
496 virtual InterfaceTypeEntry *designatedInterface() const { return 0; } | |
497 | |
498 void setCustomConstructor(const CustomFunction &func) { m_customConstructor = func; } | |
499 CustomFunction customConstructor() const { return m_customConstructor; } | |
500 | |
501 void setCustomDestructor(const CustomFunction &func) { m_customDestructor = func; } | |
502 CustomFunction customDestructor() const { return m_customDestructor; } | |
503 | |
504 virtual bool isValue() const { return false; } | |
505 virtual bool isComplex() const { return false; } | |
506 | |
507 virtual bool isNativeIdBased() const { return false; } | |
508 | |
509 // qtd | |
510 virtual bool isStructInD() const { return false; } | |
511 | |
512 private: | |
513 QString m_name; | |
514 Type m_type; | |
515 uint m_code_generation; | |
516 CustomFunction m_customConstructor; | |
517 CustomFunction m_customDestructor; | |
518 bool m_preferred_conversion; | |
519 }; | |
520 typedef QHash<QString, QList<TypeEntry *> > TypeEntryHash; | |
521 typedef QHash<QString, TypeEntry *> SingleTypeEntryHash; | |
522 | |
523 | |
524 class TypeSystemTypeEntry : public TypeEntry | |
525 { | |
526 public: | |
527 TypeSystemTypeEntry(const QString &name) | |
528 : TypeEntry(name, TypeSystemType) | |
529 { | |
530 }; | |
531 | |
532 QList<CodeSnip> snips; | |
533 }; | |
534 | |
535 | |
536 class ThreadTypeEntry : public TypeEntry | |
537 { | |
538 public: | |
539 ThreadTypeEntry() : TypeEntry("QThread", ThreadType) { setCodeGeneration(GenerateNothing); } | |
540 | |
541 QString jniName() const { return strings_jobject; } | |
542 QString targetLangName() const { return strings_Thread; } | |
543 QString javaPackage() const { return strings_java_lang; } | |
544 }; | |
545 | |
546 class VoidTypeEntry : public TypeEntry | |
547 { | |
548 public: | |
549 VoidTypeEntry() : TypeEntry("void", VoidType) { } | |
550 }; | |
551 | |
552 class TemplateArgumentEntry : public TypeEntry | |
553 { | |
554 public: | |
555 TemplateArgumentEntry(const QString &name) | |
556 : TypeEntry(name, TemplateArgumentType), m_ordinal(0) | |
557 { | |
558 } | |
559 | |
560 int ordinal() const { return m_ordinal; } | |
561 void setOrdinal(int o) { m_ordinal = o; } | |
562 | |
563 private: | |
564 int m_ordinal; | |
565 }; | |
566 | |
567 class ArrayTypeEntry : public TypeEntry | |
568 { | |
569 public: | |
570 ArrayTypeEntry(const TypeEntry *nested_type) : TypeEntry("Array", ArrayType), m_nested_type(nested_type) | |
571 { | |
572 Q_ASSERT(m_nested_type); | |
573 } | |
574 | |
575 void setNestedTypeEntry(TypeEntry *nested) { m_nested_type = nested; } | |
576 const TypeEntry *nestedTypeEntry() const { return m_nested_type; } | |
577 | |
578 QString targetLangName() const { return m_nested_type->targetLangName() + "[]"; } | |
579 QString jniName() const | |
580 { | |
581 if (m_nested_type->isPrimitive()) | |
582 return m_nested_type->jniName() + "Array"; | |
583 else | |
584 return "jobjectArray"; | |
585 } | |
586 | |
587 private: | |
588 const TypeEntry *m_nested_type; | |
589 }; | |
590 | |
591 | |
592 class PrimitiveTypeEntry : public TypeEntry | |
593 { | |
594 public: | |
595 PrimitiveTypeEntry(const QString &name) | |
596 : TypeEntry(name, PrimitiveType), m_preferred_conversion(true), m_preferred_java_type(true) | |
597 { | |
598 } | |
599 | |
600 QString targetLangName() const { return m_java_name; } | |
601 void setTargetLangName(const QString &targetLangName) { m_java_name = targetLangName; } | |
602 | |
603 QString jniName() const { return m_jni_name; } | |
604 void setJniName(const QString &jniName) { m_jni_name = jniName; } | |
605 | |
606 QString javaObjectFullName() const { return javaObjectPackage() + "." + javaObjectName(); } | |
607 QString javaObjectName() const; | |
608 QString javaObjectPackage() const { return strings_java_lang; } | |
609 | |
610 virtual bool preferredConversion() const { return m_preferred_conversion; } | |
611 virtual void setPreferredConversion(bool b) { m_preferred_conversion = b; } | |
612 | |
613 virtual bool preferredTargetLangType() const { return m_preferred_java_type; } | |
614 virtual void setPreferredTargetLangType(bool b) { m_preferred_java_type = b; } | |
615 | |
616 private: | |
617 QString m_java_name; | |
618 QString m_jni_name; | |
619 uint m_preferred_conversion : 1; | |
620 uint m_preferred_java_type : 1; | |
621 }; | |
622 | |
623 | |
624 | |
625 | |
626 struct EnumValueRedirection | |
627 { | |
628 EnumValueRedirection(const QString &rej, const QString &us) | |
629 : rejected(rej), | |
630 used(us) | |
631 { | |
632 } | |
633 QString rejected; | |
634 QString used; | |
635 }; | |
636 | |
637 class EnumTypeEntry : public TypeEntry | |
638 { | |
639 public: | |
640 EnumTypeEntry(const QString &nspace, const QString &enumName) | |
641 : TypeEntry(nspace.isEmpty() ? enumName : nspace + QLatin1String("::") + enumName, | |
642 EnumType), | |
643 m_flags(0), | |
644 m_extensible(false) | |
645 { | |
646 m_qualifier = nspace; | |
647 m_java_name = enumName; | |
648 } | |
649 | |
650 QString javaPackage() const { return m_package_name; } | |
651 void setTargetLangPackage(const QString &package) { m_package_name = package; } | |
652 | |
653 QString targetLangName() const { return m_java_name; } | |
654 QString javaQualifier() const; | |
655 QString qualifiedTargetLangName() const { | |
656 return javaQualifier() + '_' + targetLangName(); | |
657 // return targetLangName(); | |
658 } | |
659 | |
660 QString jniName() const; | |
661 | |
662 QString qualifier() const { return m_qualifier; } | |
663 void setQualifier(const QString &q) { m_qualifier = q; } | |
664 | |
665 virtual bool preferredConversion() const { return false; } | |
666 | |
667 bool isBoundsChecked() const { return m_lower_bound.isEmpty() && m_upper_bound.isEmpty(); } | |
668 | |
669 QString upperBound() const { return m_upper_bound; } | |
670 void setUpperBound(const QString &bound) { m_upper_bound = bound; } | |
671 | |
672 QString lowerBound() const { return m_lower_bound; } | |
673 void setLowerBound(const QString &bound) { m_lower_bound = bound; } | |
674 | |
675 void setFlags(FlagsTypeEntry *flags) { m_flags = flags; } | |
676 FlagsTypeEntry *flags() const { return m_flags; } | |
677 | |
678 bool isExtensible() const { return m_extensible; } | |
679 void setExtensible(bool is) { m_extensible = is; } | |
680 | |
681 bool isEnumValueRejected(const QString &name) { return m_rejected_enums.contains(name); } | |
682 void addEnumValueRejection(const QString &name) { m_rejected_enums << name; } | |
683 QStringList enumValueRejections() const { return m_rejected_enums; } | |
684 | |
685 void addEnumValueRedirection(const QString &rejected, const QString &usedValue); | |
686 QString enumValueRedirection(const QString &value) const; | |
687 | |
688 bool forceInteger() const { return m_force_integer; } | |
689 void setForceInteger(bool force) { m_force_integer = force; } | |
690 | |
691 private: | |
692 QString m_package_name; | |
693 QString m_qualifier; | |
694 QString m_java_name; | |
695 | |
696 QString m_lower_bound; | |
697 QString m_upper_bound; | |
698 | |
699 QStringList m_rejected_enums; | |
700 QList<EnumValueRedirection> m_enum_redirections; | |
701 | |
702 FlagsTypeEntry *m_flags; | |
703 | |
704 bool m_extensible; | |
705 bool m_force_integer; | |
706 }; | |
707 | |
708 class FlagsTypeEntry : public TypeEntry | |
709 { | |
710 public: | |
711 FlagsTypeEntry(const QString &name) : TypeEntry(name, FlagsType), m_enum(0) | |
712 { | |
713 } | |
714 | |
715 QString qualifiedTargetLangName() const; | |
716 QString targetLangName() const { return m_java_name; } | |
717 QString jniName() const; | |
718 virtual bool preferredConversion() const { return false; } | |
719 | |
720 QString originalName() const { return m_original_name; } | |
721 void setOriginalName(const QString &s) { m_original_name = s; } | |
722 | |
723 QString flagsName() const { return m_java_name; } | |
724 void setFlagsName(const QString &name) { m_java_name = name; } | |
725 | |
726 bool forceInteger() const { return m_enum->forceInteger(); } | |
727 | |
728 EnumTypeEntry *originator() const { return m_enum; } | |
729 void setOriginator(EnumTypeEntry *e) { m_enum = e; } | |
730 | |
731 QString javaPackage() const { return m_enum->javaPackage(); } | |
732 QString javaQualifier() const { return m_enum->javaQualifier(); } | |
733 QString qualifier() const { return m_enum->qualifier(); } | |
734 | |
735 private: | |
736 QString m_original_name; | |
737 QString m_java_name; | |
738 EnumTypeEntry *m_enum; | |
739 }; | |
740 | |
741 | |
742 class ComplexTypeEntry : public TypeEntry | |
743 { | |
744 public: | |
745 enum TypeFlag { | |
746 ForceAbstract = 0x1, | |
747 DeleteInMainThread = 0x2, | |
748 Deprecated = 0x4 | |
749 }; | |
750 typedef QFlags<TypeFlag> TypeFlags; | |
751 | |
752 ComplexTypeEntry(const QString &name, Type t) | |
753 : TypeEntry(QString(name).replace("::", "_"), t), | |
754 m_qualified_cpp_name(name), | |
755 m_qobject(false), | |
756 m_polymorphic_base(false), | |
757 m_generic_class(false), | |
758 m_type_flags(0), | |
759 m_isStructInD(false), | |
760 m_isAbstract(false) | |
761 { | |
762 Include inc; | |
763 inc.name = "QVariant"; | |
764 inc.type = Include::IncludePath; | |
765 | |
766 addExtraInclude(inc); | |
767 } | |
768 | |
769 bool isComplex() const { return true; } | |
770 | |
771 IncludeList extraIncludes() const { return m_extra_includes; } | |
772 void setExtraIncludes(const IncludeList &includes) { m_extra_includes = includes; } | |
773 void addExtraInclude(const Include &include) | |
774 { | |
775 if (!m_includes_used.value(include.name, false)) { | |
776 m_extra_includes << include; | |
777 m_includes_used[include.name] = true; | |
778 } | |
779 } | |
780 | |
781 ComplexTypeEntry *copy() const | |
782 { | |
783 ComplexTypeEntry *centry = new ComplexTypeEntry(name(), type()); | |
784 centry->setInclude(include()); | |
785 centry->setExtraIncludes(extraIncludes()); | |
786 centry->setFunctionModifications(functionModifications()); | |
787 centry->setFieldModifications(fieldModifications()); | |
788 centry->setQObject(isQObject()); | |
789 centry->setDefaultSuperclass(defaultSuperclass()); | |
790 centry->setCodeSnips(codeSnips()); | |
791 centry->setTargetLangPackage(javaPackage()); | |
792 | |
793 return centry; | |
794 } | |
795 | |
796 void setLookupName(const QString &name) | |
797 { | |
798 m_lookup_name = name; | |
799 } | |
800 | |
801 virtual QString lookupName() const | |
802 { | |
803 return m_lookup_name.isEmpty() ? targetLangName() : m_lookup_name; | |
804 } | |
805 | |
806 QString jniName() const { return strings_jobject; } | |
807 | |
808 | |
809 Include include() const { return m_include; } | |
810 void setInclude(const Include &inc) { m_include = inc; } | |
811 | |
812 void setTypeFlags(TypeFlags flags) | |
813 { | |
814 m_type_flags = flags; | |
815 } | |
816 | |
817 TypeFlags typeFlags() const | |
818 { | |
819 return m_type_flags; | |
820 } | |
821 | |
822 CodeSnipList codeSnips() const { return m_code_snips; } | |
823 void setCodeSnips(const CodeSnipList &codeSnips) { m_code_snips = codeSnips; } | |
824 void addCodeSnip(const CodeSnip &codeSnip) { m_code_snips << codeSnip; } | |
825 | |
826 FunctionModificationList functionModifications() const { return m_function_mods; } | |
827 void setFunctionModifications(const FunctionModificationList &functionModifications) { | |
828 m_function_mods = functionModifications; | |
829 } | |
830 void addFunctionModification(const FunctionModification &functionModification) { | |
831 m_function_mods << functionModification; | |
832 } | |
833 FunctionModificationList functionModifications(const QString &signature) const; | |
834 | |
835 FieldModification fieldModification(const QString &name) const; | |
836 void setFieldModifications(const FieldModificationList &mods) { m_field_mods = mods; } | |
837 FieldModificationList fieldModifications() const { return m_field_mods; } | |
838 | |
839 QString javaPackage() const { return m_package; } | |
840 void setTargetLangPackage(const QString &package) { m_package = package; } | |
841 | |
842 bool isQObject() const { return m_qobject; } | |
843 void setQObject(bool qobject) { m_qobject = qobject; } | |
844 | |
845 QString defaultSuperclass() const { return m_default_superclass; } | |
846 void setDefaultSuperclass(const QString &sc) { m_default_superclass = sc; } | |
847 | |
848 virtual QString qualifiedCppName() const { return m_qualified_cpp_name; } | |
849 | |
850 | |
851 void setIsPolymorphicBase(bool on) | |
852 { | |
853 m_polymorphic_base = on; | |
854 } | |
855 bool isPolymorphicBase() const { return m_polymorphic_base; } | |
856 | |
857 void setPolymorphicIdValue(const QString &value) | |
858 { | |
859 m_polymorphic_id_value = value; | |
860 } | |
861 QString polymorphicIdValue() const { return m_polymorphic_id_value; } | |
862 | |
863 void setExpensePolicy(const ExpensePolicy &policy) { m_expense_policy = policy; } | |
864 const ExpensePolicy &expensePolicy() const { return m_expense_policy; } | |
865 | |
866 QString targetType() const { return m_target_type; } | |
867 void setTargetType(const QString &code) { m_target_type = code; } | |
868 | |
869 QString targetLangName() const { return m_java_name.isEmpty() | |
870 ? TypeEntry::targetLangName() | |
871 : m_java_name; | |
872 } | |
873 void setTargetLangName(const QString &name) { m_java_name = name; } | |
874 | |
875 bool isGenericClass() const { return m_generic_class; } | |
876 void setGenericClass(bool isGeneric) { m_generic_class = isGeneric; } | |
877 | |
878 QString injectedImports; | |
879 | |
880 // qtd | |
881 bool isStructInD() const { return m_isStructInD; } | |
882 void setStructInD(bool isStruct) { m_isStructInD = isStruct; } | |
883 | |
884 bool isAbstract() const { return m_isAbstract; } | |
885 void setAbstract(bool isAbstract) { m_isAbstract = isAbstract; } | |
886 | |
42 | 887 void setDepends(const QStringList &depends) {m_depends = depends; } |
888 const QStringList &depends() {return m_depends; } | |
889 | |
1 | 890 QString addedTo; |
891 QStringList includedClasses; | |
892 | |
893 | |
894 private: | |
895 IncludeList m_extra_includes; | |
896 Include m_include; | |
897 QHash<QString, bool> m_includes_used; | |
898 FunctionModificationList m_function_mods; | |
899 FieldModificationList m_field_mods; | |
900 CodeSnipList m_code_snips; | |
901 QString m_package; | |
902 QString m_default_superclass; | |
903 QString m_qualified_cpp_name; | |
904 QString m_java_name; | |
905 | |
906 uint m_qobject : 1; | |
907 uint m_polymorphic_base : 1; | |
908 uint m_generic_class : 1; | |
909 | |
910 QString m_polymorphic_id_value; | |
911 QString m_lookup_name; | |
912 QString m_target_type; | |
913 ExpensePolicy m_expense_policy; | |
914 TypeFlags m_type_flags; | |
915 | |
916 // qtd | |
917 bool m_isStructInD; | |
918 bool m_isAbstract; | |
42 | 919 QStringList m_depends; |
1 | 920 }; |
921 | |
922 class ContainerTypeEntry : public ComplexTypeEntry | |
923 { | |
924 public: | |
925 enum Type { | |
926 NoContainer, | |
927 ListContainer, | |
928 StringListContainer, | |
929 LinkedListContainer, | |
930 VectorContainer, | |
931 StackContainer, | |
932 QueueContainer, | |
933 SetContainer, | |
934 MapContainer, | |
935 MultiMapContainer, | |
936 HashContainer, | |
937 MultiHashContainer, | |
938 PairContainer, | |
939 }; | |
940 | |
941 ContainerTypeEntry(const QString &name, Type type) | |
942 : ComplexTypeEntry(name, ContainerType) | |
943 { | |
944 m_type = type; | |
945 setCodeGeneration(GenerateForSubclass); | |
946 } | |
947 | |
948 Type type() const { return m_type; } | |
949 QString targetLangName() const; | |
950 QString javaPackage() const; | |
951 QString qualifiedCppName() const; | |
952 | |
953 private: | |
954 Type m_type; | |
955 }; | |
956 | |
957 | |
958 class NamespaceTypeEntry : public ComplexTypeEntry | |
959 { | |
960 public: | |
961 NamespaceTypeEntry(const QString &name) : ComplexTypeEntry(name, NamespaceType) { } | |
962 }; | |
963 | |
964 | |
965 class ValueTypeEntry : public ComplexTypeEntry | |
966 { | |
967 public: | |
968 ValueTypeEntry(const QString &name) : ComplexTypeEntry(name, BasicValueType) { } | |
969 | |
970 bool isValue() const { return true; } | |
971 | |
972 virtual bool isNativeIdBased() const { return true; } | |
973 | |
974 protected: | |
975 ValueTypeEntry(const QString &name, Type t) : ComplexTypeEntry(name, t) { } | |
976 }; | |
977 | |
978 | |
979 class StringTypeEntry : public ValueTypeEntry | |
980 { | |
981 public: | |
982 StringTypeEntry(const QString &name) | |
983 : ValueTypeEntry(name, StringType) | |
984 { | |
985 setCodeGeneration(GenerateNothing); | |
986 } | |
987 | |
988 QString jniName() const { return strings_jobject; } | |
989 QString targetLangName() const { return strings_String; } | |
990 QString javaPackage() const { return strings_java_lang; } | |
991 | |
992 virtual bool isNativeIdBased() const { return false; } | |
993 }; | |
994 | |
995 class CharTypeEntry : public ValueTypeEntry | |
996 { | |
997 public: | |
998 CharTypeEntry(const QString &name) : ValueTypeEntry(name, CharType) | |
999 { | |
1000 setCodeGeneration(GenerateNothing); | |
1001 } | |
1002 | |
1003 QString jniName() const { return strings_jchar; } | |
1004 QString targetLangName() const { return strings_char; } | |
1005 QString javaPackage() const { return QString(); } | |
1006 | |
1007 virtual bool isNativeIdBased() const { return false; } | |
1008 }; | |
1009 | |
1010 class JObjectWrapperTypeEntry: public ValueTypeEntry | |
1011 { | |
1012 public: | |
1013 JObjectWrapperTypeEntry(const QString &name) : ValueTypeEntry(name, JObjectWrapperType) { } | |
1014 | |
1015 QString jniName() const { return strings_jobject; } | |
1016 QString targetLangName() const { return strings_Object; } | |
1017 QString javaPackage() const { return strings_java_lang; } | |
1018 | |
1019 bool isNativeIdBased() const { return false; } | |
1020 }; | |
1021 | |
1022 class VariantTypeEntry: public ValueTypeEntry | |
1023 { | |
1024 public: | |
1025 VariantTypeEntry(const QString &name) : ValueTypeEntry(name, VariantType) { } | |
1026 | |
1027 QString jniName() const { return strings_jobject; } | |
1028 QString targetLangName() const { return "QVariant"; } | |
1029 QString javaPackage() const { return "qt.core"; } | |
1030 virtual bool isNativeIdBased() const { return false; } | |
1031 }; | |
1032 | |
1033 | |
1034 class InterfaceTypeEntry : public ComplexTypeEntry | |
1035 { | |
1036 public: | |
1037 InterfaceTypeEntry(const QString &name) | |
1038 : ComplexTypeEntry(name, InterfaceType) | |
1039 { | |
1040 } | |
1041 | |
1042 static QString interfaceName(const QString &name) { | |
1043 return "I" + name; | |
1044 } | |
1045 | |
1046 ObjectTypeEntry *origin() const { return m_origin; } | |
1047 void setOrigin(ObjectTypeEntry *origin) { m_origin = origin; } | |
1048 | |
1049 virtual bool isNativeIdBased() const { return true; } | |
1050 virtual QString qualifiedCppName() const { | |
1051 return ComplexTypeEntry::qualifiedCppName().right(ComplexTypeEntry::qualifiedCppName().length() - interfaceName("").length()); | |
1052 } | |
1053 | |
1054 private: | |
1055 ObjectTypeEntry *m_origin; | |
1056 }; | |
1057 | |
1058 | |
1059 class ObjectTypeEntry : public ComplexTypeEntry | |
1060 { | |
1061 public: | |
1062 ObjectTypeEntry(const QString &name) | |
1063 : ComplexTypeEntry(name, ObjectType), m_interface(0) | |
1064 { | |
1065 } | |
1066 | |
1067 InterfaceTypeEntry *designatedInterface() const { return m_interface; } | |
1068 void setDesignatedInterface(InterfaceTypeEntry *entry) { m_interface = entry; } | |
1069 | |
1070 virtual bool isNativeIdBased() const { return true; } | |
1071 | |
1072 private: | |
1073 InterfaceTypeEntry *m_interface; | |
1074 }; | |
1075 | |
1076 class CustomTypeEntry : public ComplexTypeEntry | |
1077 { | |
1078 public: | |
1079 CustomTypeEntry(const QString &name) : ComplexTypeEntry(name, CustomType) { } | |
1080 | |
1081 virtual void generateCppJavaToQt(QTextStream &s, | |
1082 const AbstractMetaType *java_type, | |
1083 const QString &env_name, | |
1084 const QString &qt_name, | |
1085 const QString &java_name) const = 0; | |
1086 | |
1087 virtual void generateCppQtToJava(QTextStream &s, | |
1088 const AbstractMetaType *java_type, | |
1089 const QString &env_name, | |
1090 const QString &qt_name, | |
1091 const QString &java_name) const = 0; | |
1092 }; | |
1093 | |
1094 struct TypeRejection | |
1095 { | |
1096 QString class_name; | |
1097 QString function_name; | |
1098 QString field_name; | |
1099 QString enum_name; | |
1100 }; | |
1101 | |
1102 class TypeDatabase | |
1103 { | |
1104 public: | |
1105 TypeDatabase(); | |
1106 | |
1107 static TypeDatabase *instance(); | |
1108 | |
1109 QList<Include> extraIncludes(const QString &className); | |
1110 | |
1111 inline PrimitiveTypeEntry *findPrimitiveType(const QString &name); | |
1112 inline ComplexTypeEntry *findComplexType(const QString &name); | |
1113 inline ObjectTypeEntry *findObjectType(const QString &name); | |
1114 inline NamespaceTypeEntry *findNamespaceType(const QString &name); | |
1115 ContainerTypeEntry *findContainerType(const QString &name); | |
1116 | |
1117 TypeEntry *findType(const QString &name) const { | |
1118 QList<TypeEntry *> entries = findTypes(name); | |
1119 foreach (TypeEntry *entry, entries) { | |
1120 if (entry != 0 && | |
1121 (!entry->isPrimitive() || static_cast<PrimitiveTypeEntry *>(entry)->preferredTargetLangType())) { | |
1122 return entry; | |
1123 } | |
1124 } | |
1125 return 0; | |
1126 } | |
1127 QList<TypeEntry *> findTypes(const QString &name) const { return m_entries.value(name); } | |
1128 TypeEntryHash allEntries() { return m_entries; } | |
1129 SingleTypeEntryHash entries() { | |
1130 TypeEntryHash entries = allEntries(); | |
1131 | |
1132 SingleTypeEntryHash returned; | |
1133 QList<QString> keys = entries.keys(); | |
1134 | |
1135 foreach(QString key, keys) { | |
1136 returned[key] = findType(key); | |
1137 } | |
1138 | |
1139 return returned; | |
1140 } | |
1141 | |
1142 PrimitiveTypeEntry *findTargetLangPrimitiveType(const QString &java_name); | |
1143 | |
1144 void addRejection(const QString &class_name, const QString &function_name, | |
1145 const QString &field_name, const QString &enum_name); | |
1146 bool isClassRejected(const QString &class_name); | |
1147 bool isFunctionRejected(const QString &class_name, const QString &function_name); | |
1148 bool isFieldRejected(const QString &class_name, const QString &field_name); | |
1149 bool isEnumRejected(const QString &class_name, const QString &enum_name); | |
1150 | |
1151 void addType(TypeEntry *e) { m_entries[e->qualifiedCppName()].append(e); } | |
1152 | |
1153 SingleTypeEntryHash flagsEntries() const { return m_flags_entries; } | |
1154 FlagsTypeEntry *findFlagsType(const QString &name) const; | |
1155 void addFlagsType(FlagsTypeEntry *fte) { m_flags_entries[fte->originalName()] = fte; } | |
1156 | |
1157 TemplateEntry *findTemplate(const QString &name) { return m_templates[name]; } | |
1158 void addTemplate(TemplateEntry *t) { m_templates[t->name()] = t; } | |
1159 | |
1160 void setIncludeEclipseWarnings(bool on) { m_includeEclipseWarnings = on; } | |
1161 bool includeEclipseWarnings() const { return m_includeEclipseWarnings; } | |
1162 | |
1163 void setSuppressWarnings(bool on) { m_suppressWarnings = on; } | |
1164 void addSuppressedWarning(const QString &s) | |
1165 { | |
1166 m_suppressedWarnings.append(s); | |
1167 } | |
1168 | |
1169 bool isSuppressedWarning(const QString &s) | |
1170 { | |
1171 if (!m_suppressWarnings) | |
1172 return false; | |
1173 | |
1174 foreach (const QString &_warning, m_suppressedWarnings) { | |
1175 QString warning(QString(_warning).replace("\\*", "&place_holder_for_asterisk;")); | |
1176 | |
1177 QStringList segs = warning.split("*", QString::SkipEmptyParts); | |
1178 if (segs.size() == 0) | |
1179 continue ; | |
1180 | |
1181 int i = 0; | |
1182 int pos = s.indexOf(QString(segs.at(i++)).replace("&place_holder_for_asterisk;", "*")); | |
1183 //qDebug() << "s == " << s << ", warning == " << segs; | |
1184 while (pos != -1) { | |
1185 if (i == segs.size()) | |
1186 return true; | |
1187 pos = s.indexOf(QString(segs.at(i++)).replace("&place_holder_for_asterisk;", "*"), pos); | |
1188 } | |
1189 } | |
1190 | |
1191 return false; | |
1192 } | |
1193 | |
1194 void setRebuildClasses(const QStringList &cls) { m_rebuild_classes = cls; } | |
1195 | |
1196 static QString globalNamespaceClassName(const TypeEntry *te); | |
1197 QString filename() const { return "typesystem.txt"; } | |
1198 | |
4 | 1199 bool parseFile(const QString &filename, const QString &work_dir, bool generate = true); |
1 | 1200 |
1201 private: | |
1202 uint m_suppressWarnings : 1; | |
1203 uint m_includeEclipseWarnings : 1; | |
1204 uint m_reserved : 30; | |
1205 | |
1206 TypeEntryHash m_entries; | |
1207 SingleTypeEntryHash m_flags_entries; | |
1208 TemplateEntryHash m_templates; | |
1209 QStringList m_suppressedWarnings; | |
1210 | |
1211 QList<TypeRejection> m_rejections; | |
1212 QStringList m_rebuild_classes; | |
1213 }; | |
1214 | |
1215 inline PrimitiveTypeEntry *TypeDatabase::findPrimitiveType(const QString &name) | |
1216 { | |
1217 QList<TypeEntry *> entries = findTypes(name); | |
1218 | |
1219 foreach (TypeEntry *entry, entries) { | |
1220 if (entry != 0 && entry->isPrimitive() && static_cast<PrimitiveTypeEntry *>(entry)->preferredTargetLangType()) | |
1221 return static_cast<PrimitiveTypeEntry *>(entry); | |
1222 } | |
1223 | |
1224 return 0; | |
1225 } | |
1226 | |
1227 inline ComplexTypeEntry *TypeDatabase::findComplexType(const QString &name) | |
1228 { | |
1229 TypeEntry *entry = findType(name); | |
1230 if (entry != 0 && entry->isComplex()) | |
1231 return static_cast<ComplexTypeEntry *>(entry); | |
1232 else | |
1233 return 0; | |
1234 } | |
1235 | |
1236 inline ObjectTypeEntry *TypeDatabase::findObjectType(const QString &name) | |
1237 { | |
1238 TypeEntry *entry = findType(name); | |
1239 if (entry != 0 && entry->isObject()) | |
1240 return static_cast<ObjectTypeEntry *>(entry); | |
1241 else | |
1242 return 0; | |
1243 } | |
1244 | |
1245 inline NamespaceTypeEntry *TypeDatabase::findNamespaceType(const QString &name) | |
1246 { | |
1247 TypeEntry *entry = findType(name); | |
1248 if (entry != 0 && entry->isNamespace()) | |
1249 return static_cast<NamespaceTypeEntry *>(entry); | |
1250 else | |
1251 return 0; | |
1252 } | |
1253 | |
1254 QString fixCppTypeName(const QString &name); | |
1255 | |
1256 #endif // TYPESYSTEM_H |