Mercurial > projects > qtd
annotate generator/typesystem.h @ 304:04b52676b45f signals
fixed compiling all packages
author | eldar_ins@eldar-laptop |
---|---|
date | Sun, 13 Dec 2009 06:24:55 +0500 |
parents | adae77fdc1ea |
children | 5896535a03cd |
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), | |
304 | 439 m_preferred_conversion(true), |
440 m_has_copy_constructor(false) | |
1 | 441 { |
304 | 442 } |
1 | 443 |
444 virtual ~TypeEntry() { } | |
445 | |
446 Type type() const { return m_type; } | |
447 bool isPrimitive() const { return m_type == PrimitiveType; } | |
448 bool isEnum() const { return m_type == EnumType; } | |
449 bool isFlags() const { return m_type == FlagsType; } | |
450 bool isInterface() const { return m_type == InterfaceType; } | |
451 bool isObject() const { return m_type == ObjectType; } | |
452 bool isString() const { return m_type == StringType; } | |
453 bool isChar() const { return m_type == CharType; } | |
454 bool isNamespace() const { return m_type == NamespaceType; } | |
455 bool isContainer() const { return m_type == ContainerType; } | |
456 bool isVariant() const { return m_type == VariantType; } | |
457 bool isJObjectWrapper() const { return m_type == JObjectWrapperType; } | |
458 bool isArray() const { return m_type == ArrayType; } | |
459 bool isTemplateArgument() const { return m_type == TemplateArgumentType; } | |
460 bool isVoid() const { return m_type == VoidType; } | |
461 bool isThread() const { return m_type == ThreadType; } | |
462 bool isCustom() const { return m_type == CustomType; } | |
463 bool isBasicValue() const { return m_type == BasicValueType; } | |
464 bool isTypeSystem() const { return m_type == TypeSystemType; } | |
465 | |
466 virtual bool preferredConversion() const { return m_preferred_conversion; } | |
467 virtual void setPreferredConversion(bool b) { m_preferred_conversion = b; } | |
468 | |
469 virtual QString javaQualifier() const { return QString(); } | |
470 | |
471 // The type's name in C++, fully qualified | |
472 QString name() const { return m_name; } | |
473 | |
474 uint codeGeneration() const { return m_code_generation; } | |
475 void setCodeGeneration(uint cg) { m_code_generation = cg; } | |
476 | |
477 virtual QString qualifiedCppName() const { return m_name; } | |
478 | |
479 // Its type's name in JNI | |
480 virtual QString jniName() const { return m_name; } | |
481 | |
482 // The type's name in TargetLang | |
483 virtual QString targetLangName() const { return m_name; } | |
484 | |
485 // The type to lookup when converting to TargetLang | |
486 virtual QString lookupName() const { return targetLangName(); } | |
487 | |
488 // The package | |
489 virtual QString javaPackage() const { return QString(); } | |
490 | |
491 virtual QString qualifiedTargetLangName() const { | |
492 // QString pkg = javaPackage(); | |
493 /* if (pkg.isEmpty())*/ return targetLangName(); | |
494 // return pkg + '.' + targetLangName(); | |
495 } | |
496 | |
497 virtual InterfaceTypeEntry *designatedInterface() const { return 0; } | |
498 | |
499 void setCustomConstructor(const CustomFunction &func) { m_customConstructor = func; } | |
500 CustomFunction customConstructor() const { return m_customConstructor; } | |
501 | |
502 void setCustomDestructor(const CustomFunction &func) { m_customDestructor = func; } | |
503 CustomFunction customDestructor() const { return m_customDestructor; } | |
504 | |
505 virtual bool isValue() const { return false; } | |
506 virtual bool isComplex() const { return false; } | |
507 | |
508 virtual bool isNativeIdBased() const { return false; } | |
509 | |
510 // qtd | |
511 virtual bool isStructInD() const { return false; } | |
304 | 512 bool hasPrivateCopyConstructor() const { return m_has_copy_constructor; } |
513 void setHasPrivateCopyConstructor(bool has_copy_constructor) { m_has_copy_constructor = has_copy_constructor; } | |
1 | 514 |
515 private: | |
516 QString m_name; | |
517 Type m_type; | |
518 uint m_code_generation; | |
519 CustomFunction m_customConstructor; | |
520 CustomFunction m_customDestructor; | |
521 bool m_preferred_conversion; | |
304 | 522 bool m_has_copy_constructor; |
1 | 523 }; |
524 typedef QHash<QString, QList<TypeEntry *> > TypeEntryHash; | |
525 typedef QHash<QString, TypeEntry *> SingleTypeEntryHash; | |
526 | |
527 | |
528 class TypeSystemTypeEntry : public TypeEntry | |
529 { | |
530 public: | |
531 TypeSystemTypeEntry(const QString &name) | |
532 : TypeEntry(name, TypeSystemType) | |
533 { | |
534 }; | |
535 | |
536 QList<CodeSnip> snips; | |
537 }; | |
538 | |
539 | |
540 class ThreadTypeEntry : public TypeEntry | |
541 { | |
542 public: | |
543 ThreadTypeEntry() : TypeEntry("QThread", ThreadType) { setCodeGeneration(GenerateNothing); } | |
544 | |
545 QString jniName() const { return strings_jobject; } | |
546 QString targetLangName() const { return strings_Thread; } | |
547 QString javaPackage() const { return strings_java_lang; } | |
548 }; | |
549 | |
550 class VoidTypeEntry : public TypeEntry | |
551 { | |
552 public: | |
553 VoidTypeEntry() : TypeEntry("void", VoidType) { } | |
554 }; | |
555 | |
556 class TemplateArgumentEntry : public TypeEntry | |
557 { | |
558 public: | |
559 TemplateArgumentEntry(const QString &name) | |
560 : TypeEntry(name, TemplateArgumentType), m_ordinal(0) | |
561 { | |
562 } | |
563 | |
564 int ordinal() const { return m_ordinal; } | |
565 void setOrdinal(int o) { m_ordinal = o; } | |
566 | |
567 private: | |
568 int m_ordinal; | |
569 }; | |
570 | |
571 class ArrayTypeEntry : public TypeEntry | |
572 { | |
573 public: | |
574 ArrayTypeEntry(const TypeEntry *nested_type) : TypeEntry("Array", ArrayType), m_nested_type(nested_type) | |
575 { | |
576 Q_ASSERT(m_nested_type); | |
577 } | |
578 | |
579 void setNestedTypeEntry(TypeEntry *nested) { m_nested_type = nested; } | |
580 const TypeEntry *nestedTypeEntry() const { return m_nested_type; } | |
581 | |
582 QString targetLangName() const { return m_nested_type->targetLangName() + "[]"; } | |
583 QString jniName() const | |
584 { | |
585 if (m_nested_type->isPrimitive()) | |
586 return m_nested_type->jniName() + "Array"; | |
587 else | |
588 return "jobjectArray"; | |
589 } | |
590 | |
591 private: | |
592 const TypeEntry *m_nested_type; | |
593 }; | |
594 | |
595 | |
596 class PrimitiveTypeEntry : public TypeEntry | |
597 { | |
598 public: | |
599 PrimitiveTypeEntry(const QString &name) | |
600 : TypeEntry(name, PrimitiveType), m_preferred_conversion(true), m_preferred_java_type(true) | |
601 { | |
602 } | |
603 | |
604 QString targetLangName() const { return m_java_name; } | |
605 void setTargetLangName(const QString &targetLangName) { m_java_name = targetLangName; } | |
606 | |
607 QString jniName() const { return m_jni_name; } | |
608 void setJniName(const QString &jniName) { m_jni_name = jniName; } | |
609 | |
610 QString javaObjectFullName() const { return javaObjectPackage() + "." + javaObjectName(); } | |
611 QString javaObjectName() const; | |
612 QString javaObjectPackage() const { return strings_java_lang; } | |
613 | |
614 virtual bool preferredConversion() const { return m_preferred_conversion; } | |
615 virtual void setPreferredConversion(bool b) { m_preferred_conversion = b; } | |
616 | |
617 virtual bool preferredTargetLangType() const { return m_preferred_java_type; } | |
618 virtual void setPreferredTargetLangType(bool b) { m_preferred_java_type = b; } | |
619 | |
620 private: | |
621 QString m_java_name; | |
622 QString m_jni_name; | |
623 uint m_preferred_conversion : 1; | |
624 uint m_preferred_java_type : 1; | |
625 }; | |
626 | |
627 | |
628 | |
629 | |
630 struct EnumValueRedirection | |
631 { | |
632 EnumValueRedirection(const QString &rej, const QString &us) | |
633 : rejected(rej), | |
634 used(us) | |
635 { | |
636 } | |
637 QString rejected; | |
638 QString used; | |
639 }; | |
640 | |
641 class EnumTypeEntry : public TypeEntry | |
642 { | |
643 public: | |
644 EnumTypeEntry(const QString &nspace, const QString &enumName) | |
645 : TypeEntry(nspace.isEmpty() ? enumName : nspace + QLatin1String("::") + enumName, | |
646 EnumType), | |
647 m_flags(0), | |
648 m_extensible(false) | |
649 { | |
650 m_qualifier = nspace; | |
651 m_java_name = enumName; | |
652 } | |
653 | |
654 QString javaPackage() const { return m_package_name; } | |
655 void setTargetLangPackage(const QString &package) { m_package_name = package; } | |
656 | |
657 QString targetLangName() const { return m_java_name; } | |
658 QString javaQualifier() const; | |
659 QString qualifiedTargetLangName() const { | |
660 return javaQualifier() + '_' + targetLangName(); | |
661 // return targetLangName(); | |
662 } | |
663 | |
664 QString jniName() const; | |
665 | |
666 QString qualifier() const { return m_qualifier; } | |
667 void setQualifier(const QString &q) { m_qualifier = q; } | |
668 | |
669 virtual bool preferredConversion() const { return false; } | |
670 | |
671 bool isBoundsChecked() const { return m_lower_bound.isEmpty() && m_upper_bound.isEmpty(); } | |
672 | |
673 QString upperBound() const { return m_upper_bound; } | |
674 void setUpperBound(const QString &bound) { m_upper_bound = bound; } | |
675 | |
676 QString lowerBound() const { return m_lower_bound; } | |
677 void setLowerBound(const QString &bound) { m_lower_bound = bound; } | |
678 | |
679 void setFlags(FlagsTypeEntry *flags) { m_flags = flags; } | |
680 FlagsTypeEntry *flags() const { return m_flags; } | |
681 | |
682 bool isExtensible() const { return m_extensible; } | |
683 void setExtensible(bool is) { m_extensible = is; } | |
684 | |
685 bool isEnumValueRejected(const QString &name) { return m_rejected_enums.contains(name); } | |
686 void addEnumValueRejection(const QString &name) { m_rejected_enums << name; } | |
687 QStringList enumValueRejections() const { return m_rejected_enums; } | |
688 | |
689 void addEnumValueRedirection(const QString &rejected, const QString &usedValue); | |
690 QString enumValueRedirection(const QString &value) const; | |
691 | |
692 bool forceInteger() const { return m_force_integer; } | |
693 void setForceInteger(bool force) { m_force_integer = force; } | |
694 | |
695 private: | |
696 QString m_package_name; | |
697 QString m_qualifier; | |
698 QString m_java_name; | |
699 | |
700 QString m_lower_bound; | |
701 QString m_upper_bound; | |
702 | |
703 QStringList m_rejected_enums; | |
704 QList<EnumValueRedirection> m_enum_redirections; | |
705 | |
706 FlagsTypeEntry *m_flags; | |
707 | |
708 bool m_extensible; | |
709 bool m_force_integer; | |
710 }; | |
711 | |
712 class FlagsTypeEntry : public TypeEntry | |
713 { | |
714 public: | |
715 FlagsTypeEntry(const QString &name) : TypeEntry(name, FlagsType), m_enum(0) | |
716 { | |
717 } | |
718 | |
719 QString qualifiedTargetLangName() const; | |
720 QString targetLangName() const { return m_java_name; } | |
721 QString jniName() const; | |
722 virtual bool preferredConversion() const { return false; } | |
723 | |
724 QString originalName() const { return m_original_name; } | |
725 void setOriginalName(const QString &s) { m_original_name = s; } | |
726 | |
727 QString flagsName() const { return m_java_name; } | |
728 void setFlagsName(const QString &name) { m_java_name = name; } | |
729 | |
730 bool forceInteger() const { return m_enum->forceInteger(); } | |
731 | |
732 EnumTypeEntry *originator() const { return m_enum; } | |
733 void setOriginator(EnumTypeEntry *e) { m_enum = e; } | |
734 | |
735 QString javaPackage() const { return m_enum->javaPackage(); } | |
736 QString javaQualifier() const { return m_enum->javaQualifier(); } | |
737 QString qualifier() const { return m_enum->qualifier(); } | |
738 | |
739 private: | |
740 QString m_original_name; | |
741 QString m_java_name; | |
742 EnumTypeEntry *m_enum; | |
743 }; | |
744 | |
745 | |
746 class ComplexTypeEntry : public TypeEntry | |
747 { | |
748 public: | |
749 enum TypeFlag { | |
750 ForceAbstract = 0x1, | |
751 DeleteInMainThread = 0x2, | |
752 Deprecated = 0x4 | |
753 }; | |
754 typedef QFlags<TypeFlag> TypeFlags; | |
755 | |
756 ComplexTypeEntry(const QString &name, Type t) | |
757 : TypeEntry(QString(name).replace("::", "_"), t), | |
758 m_qualified_cpp_name(name), | |
759 m_qobject(false), | |
760 m_polymorphic_base(false), | |
761 m_generic_class(false), | |
762 m_type_flags(0), | |
763 m_isStructInD(false), | |
764 m_isAbstract(false) | |
765 { | |
766 Include inc; | |
767 inc.name = "QVariant"; | |
768 inc.type = Include::IncludePath; | |
769 | |
770 addExtraInclude(inc); | |
771 } | |
772 | |
773 bool isComplex() const { return true; } | |
774 | |
775 IncludeList extraIncludes() const { return m_extra_includes; } | |
776 void setExtraIncludes(const IncludeList &includes) { m_extra_includes = includes; } | |
777 void addExtraInclude(const Include &include) | |
778 { | |
779 if (!m_includes_used.value(include.name, false)) { | |
780 m_extra_includes << include; | |
781 m_includes_used[include.name] = true; | |
782 } | |
783 } | |
784 | |
785 ComplexTypeEntry *copy() const | |
786 { | |
787 ComplexTypeEntry *centry = new ComplexTypeEntry(name(), type()); | |
788 centry->setInclude(include()); | |
789 centry->setExtraIncludes(extraIncludes()); | |
790 centry->setFunctionModifications(functionModifications()); | |
791 centry->setFieldModifications(fieldModifications()); | |
792 centry->setQObject(isQObject()); | |
793 centry->setDefaultSuperclass(defaultSuperclass()); | |
794 centry->setCodeSnips(codeSnips()); | |
795 centry->setTargetLangPackage(javaPackage()); | |
796 | |
797 return centry; | |
798 } | |
799 | |
800 void setLookupName(const QString &name) | |
801 { | |
802 m_lookup_name = name; | |
803 } | |
804 | |
805 virtual QString lookupName() const | |
806 { | |
807 return m_lookup_name.isEmpty() ? targetLangName() : m_lookup_name; | |
808 } | |
809 | |
810 QString jniName() const { return strings_jobject; } | |
811 | |
812 | |
813 Include include() const { return m_include; } | |
814 void setInclude(const Include &inc) { m_include = inc; } | |
815 | |
816 void setTypeFlags(TypeFlags flags) | |
817 { | |
818 m_type_flags = flags; | |
819 } | |
820 | |
821 TypeFlags typeFlags() const | |
822 { | |
823 return m_type_flags; | |
824 } | |
825 | |
826 CodeSnipList codeSnips() const { return m_code_snips; } | |
827 void setCodeSnips(const CodeSnipList &codeSnips) { m_code_snips = codeSnips; } | |
828 void addCodeSnip(const CodeSnip &codeSnip) { m_code_snips << codeSnip; } | |
829 | |
830 FunctionModificationList functionModifications() const { return m_function_mods; } | |
831 void setFunctionModifications(const FunctionModificationList &functionModifications) { | |
832 m_function_mods = functionModifications; | |
833 } | |
834 void addFunctionModification(const FunctionModification &functionModification) { | |
835 m_function_mods << functionModification; | |
836 } | |
837 FunctionModificationList functionModifications(const QString &signature) const; | |
838 | |
839 FieldModification fieldModification(const QString &name) const; | |
840 void setFieldModifications(const FieldModificationList &mods) { m_field_mods = mods; } | |
841 FieldModificationList fieldModifications() const { return m_field_mods; } | |
842 | |
843 QString javaPackage() const { return m_package; } | |
844 void setTargetLangPackage(const QString &package) { m_package = package; } | |
845 | |
846 bool isQObject() const { return m_qobject; } | |
847 void setQObject(bool qobject) { m_qobject = qobject; } | |
848 | |
849 QString defaultSuperclass() const { return m_default_superclass; } | |
850 void setDefaultSuperclass(const QString &sc) { m_default_superclass = sc; } | |
851 | |
852 virtual QString qualifiedCppName() const { return m_qualified_cpp_name; } | |
853 | |
854 | |
855 void setIsPolymorphicBase(bool on) | |
856 { | |
857 m_polymorphic_base = on; | |
858 } | |
859 bool isPolymorphicBase() const { return m_polymorphic_base; } | |
860 | |
861 void setPolymorphicIdValue(const QString &value) | |
862 { | |
863 m_polymorphic_id_value = value; | |
864 } | |
865 QString polymorphicIdValue() const { return m_polymorphic_id_value; } | |
866 | |
867 void setExpensePolicy(const ExpensePolicy &policy) { m_expense_policy = policy; } | |
868 const ExpensePolicy &expensePolicy() const { return m_expense_policy; } | |
869 | |
870 QString targetType() const { return m_target_type; } | |
871 void setTargetType(const QString &code) { m_target_type = code; } | |
872 | |
873 QString targetLangName() const { return m_java_name.isEmpty() | |
874 ? TypeEntry::targetLangName() | |
875 : m_java_name; | |
876 } | |
877 void setTargetLangName(const QString &name) { m_java_name = name; } | |
878 | |
879 bool isGenericClass() const { return m_generic_class; } | |
880 void setGenericClass(bool isGeneric) { m_generic_class = isGeneric; } | |
881 | |
882 QString injectedImports; | |
883 | |
884 // qtd | |
885 bool isStructInD() const { return m_isStructInD; } | |
886 void setStructInD(bool isStruct) { m_isStructInD = isStruct; } | |
887 | |
888 bool isAbstract() const { return m_isAbstract; } | |
889 void setAbstract(bool isAbstract) { m_isAbstract = isAbstract; } | |
890 | |
42 | 891 void setDepends(const QStringList &depends) {m_depends = depends; } |
892 const QStringList &depends() {return m_depends; } | |
893 | |
1 | 894 QString addedTo; |
895 QStringList includedClasses; | |
896 | |
897 | |
898 private: | |
899 IncludeList m_extra_includes; | |
900 Include m_include; | |
901 QHash<QString, bool> m_includes_used; | |
902 FunctionModificationList m_function_mods; | |
903 FieldModificationList m_field_mods; | |
904 CodeSnipList m_code_snips; | |
905 QString m_package; | |
906 QString m_default_superclass; | |
907 QString m_qualified_cpp_name; | |
908 QString m_java_name; | |
909 | |
910 uint m_qobject : 1; | |
911 uint m_polymorphic_base : 1; | |
912 uint m_generic_class : 1; | |
913 | |
914 QString m_polymorphic_id_value; | |
915 QString m_lookup_name; | |
916 QString m_target_type; | |
917 ExpensePolicy m_expense_policy; | |
918 TypeFlags m_type_flags; | |
919 | |
920 // qtd | |
921 bool m_isStructInD; | |
922 bool m_isAbstract; | |
42 | 923 QStringList m_depends; |
1 | 924 }; |
925 | |
926 class ContainerTypeEntry : public ComplexTypeEntry | |
927 { | |
928 public: | |
929 enum Type { | |
930 NoContainer, | |
931 ListContainer, | |
932 StringListContainer, | |
933 LinkedListContainer, | |
934 VectorContainer, | |
935 StackContainer, | |
936 QueueContainer, | |
937 SetContainer, | |
938 MapContainer, | |
939 MultiMapContainer, | |
940 HashContainer, | |
941 MultiHashContainer, | |
942 PairContainer, | |
943 }; | |
944 | |
945 ContainerTypeEntry(const QString &name, Type type) | |
946 : ComplexTypeEntry(name, ContainerType) | |
947 { | |
948 m_type = type; | |
949 setCodeGeneration(GenerateForSubclass); | |
950 } | |
951 | |
952 Type type() const { return m_type; } | |
953 QString targetLangName() const; | |
954 QString javaPackage() const; | |
955 QString qualifiedCppName() const; | |
956 | |
298
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
148
diff
changeset
|
957 bool isQList() const { return type() == ListContainer || type() == StringListContainer; } |
adae77fdc1ea
Native QList implementation is now used throughout QtD
eldar
parents:
148
diff
changeset
|
958 |
1 | 959 private: |
960 Type m_type; | |
961 }; | |
962 | |
963 | |
964 class NamespaceTypeEntry : public ComplexTypeEntry | |
965 { | |
966 public: | |
967 NamespaceTypeEntry(const QString &name) : ComplexTypeEntry(name, NamespaceType) { } | |
968 }; | |
969 | |
970 | |
971 class ValueTypeEntry : public ComplexTypeEntry | |
972 { | |
973 public: | |
974 ValueTypeEntry(const QString &name) : ComplexTypeEntry(name, BasicValueType) { } | |
975 | |
976 bool isValue() const { return true; } | |
977 | |
978 virtual bool isNativeIdBased() const { return true; } | |
979 | |
980 protected: | |
981 ValueTypeEntry(const QString &name, Type t) : ComplexTypeEntry(name, t) { } | |
982 }; | |
983 | |
984 | |
985 class StringTypeEntry : public ValueTypeEntry | |
986 { | |
987 public: | |
988 StringTypeEntry(const QString &name) | |
989 : ValueTypeEntry(name, StringType) | |
990 { | |
991 setCodeGeneration(GenerateNothing); | |
992 } | |
993 | |
994 QString jniName() const { return strings_jobject; } | |
995 QString targetLangName() const { return strings_String; } | |
996 QString javaPackage() const { return strings_java_lang; } | |
997 | |
998 virtual bool isNativeIdBased() const { return false; } | |
999 }; | |
1000 | |
1001 class CharTypeEntry : public ValueTypeEntry | |
1002 { | |
1003 public: | |
1004 CharTypeEntry(const QString &name) : ValueTypeEntry(name, CharType) | |
1005 { | |
1006 setCodeGeneration(GenerateNothing); | |
1007 } | |
1008 | |
1009 QString jniName() const { return strings_jchar; } | |
1010 QString targetLangName() const { return strings_char; } | |
1011 QString javaPackage() const { return QString(); } | |
1012 | |
1013 virtual bool isNativeIdBased() const { return false; } | |
1014 }; | |
1015 | |
1016 class JObjectWrapperTypeEntry: public ValueTypeEntry | |
1017 { | |
1018 public: | |
1019 JObjectWrapperTypeEntry(const QString &name) : ValueTypeEntry(name, JObjectWrapperType) { } | |
1020 | |
1021 QString jniName() const { return strings_jobject; } | |
1022 QString targetLangName() const { return strings_Object; } | |
1023 QString javaPackage() const { return strings_java_lang; } | |
1024 | |
1025 bool isNativeIdBased() const { return false; } | |
1026 }; | |
1027 | |
1028 class VariantTypeEntry: public ValueTypeEntry | |
1029 { | |
1030 public: | |
1031 VariantTypeEntry(const QString &name) : ValueTypeEntry(name, VariantType) { } | |
1032 | |
1033 QString jniName() const { return strings_jobject; } | |
1034 QString targetLangName() const { return "QVariant"; } | |
1035 QString javaPackage() const { return "qt.core"; } | |
1036 virtual bool isNativeIdBased() const { return false; } | |
1037 }; | |
1038 | |
1039 | |
1040 class InterfaceTypeEntry : public ComplexTypeEntry | |
1041 { | |
1042 public: | |
1043 InterfaceTypeEntry(const QString &name) | |
1044 : ComplexTypeEntry(name, InterfaceType) | |
1045 { | |
1046 } | |
1047 | |
1048 static QString interfaceName(const QString &name) { | |
1049 return "I" + name; | |
1050 } | |
1051 | |
1052 ObjectTypeEntry *origin() const { return m_origin; } | |
1053 void setOrigin(ObjectTypeEntry *origin) { m_origin = origin; } | |
1054 | |
1055 virtual bool isNativeIdBased() const { return true; } | |
1056 virtual QString qualifiedCppName() const { | |
1057 return ComplexTypeEntry::qualifiedCppName().right(ComplexTypeEntry::qualifiedCppName().length() - interfaceName("").length()); | |
1058 } | |
1059 | |
1060 private: | |
1061 ObjectTypeEntry *m_origin; | |
1062 }; | |
1063 | |
1064 | |
1065 class ObjectTypeEntry : public ComplexTypeEntry | |
1066 { | |
1067 public: | |
1068 ObjectTypeEntry(const QString &name) | |
1069 : ComplexTypeEntry(name, ObjectType), m_interface(0) | |
1070 { | |
1071 } | |
1072 | |
1073 InterfaceTypeEntry *designatedInterface() const { return m_interface; } | |
1074 void setDesignatedInterface(InterfaceTypeEntry *entry) { m_interface = entry; } | |
1075 | |
1076 virtual bool isNativeIdBased() const { return true; } | |
1077 | |
1078 private: | |
1079 InterfaceTypeEntry *m_interface; | |
1080 }; | |
1081 | |
1082 class CustomTypeEntry : public ComplexTypeEntry | |
1083 { | |
1084 public: | |
1085 CustomTypeEntry(const QString &name) : ComplexTypeEntry(name, CustomType) { } | |
1086 | |
1087 virtual void generateCppJavaToQt(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 virtual void generateCppQtToJava(QTextStream &s, | |
1094 const AbstractMetaType *java_type, | |
1095 const QString &env_name, | |
1096 const QString &qt_name, | |
1097 const QString &java_name) const = 0; | |
1098 }; | |
1099 | |
1100 struct TypeRejection | |
1101 { | |
1102 QString class_name; | |
1103 QString function_name; | |
1104 QString field_name; | |
1105 QString enum_name; | |
1106 }; | |
1107 | |
1108 class TypeDatabase | |
1109 { | |
1110 public: | |
1111 TypeDatabase(); | |
1112 | |
1113 static TypeDatabase *instance(); | |
1114 | |
1115 QList<Include> extraIncludes(const QString &className); | |
1116 | |
1117 inline PrimitiveTypeEntry *findPrimitiveType(const QString &name); | |
1118 inline ComplexTypeEntry *findComplexType(const QString &name); | |
1119 inline ObjectTypeEntry *findObjectType(const QString &name); | |
1120 inline NamespaceTypeEntry *findNamespaceType(const QString &name); | |
1121 ContainerTypeEntry *findContainerType(const QString &name); | |
1122 | |
1123 TypeEntry *findType(const QString &name) const { | |
1124 QList<TypeEntry *> entries = findTypes(name); | |
1125 foreach (TypeEntry *entry, entries) { | |
1126 if (entry != 0 && | |
1127 (!entry->isPrimitive() || static_cast<PrimitiveTypeEntry *>(entry)->preferredTargetLangType())) { | |
1128 return entry; | |
1129 } | |
1130 } | |
1131 return 0; | |
1132 } | |
1133 QList<TypeEntry *> findTypes(const QString &name) const { return m_entries.value(name); } | |
1134 TypeEntryHash allEntries() { return m_entries; } | |
1135 SingleTypeEntryHash entries() { | |
1136 TypeEntryHash entries = allEntries(); | |
1137 | |
1138 SingleTypeEntryHash returned; | |
1139 QList<QString> keys = entries.keys(); | |
1140 | |
1141 foreach(QString key, keys) { | |
1142 returned[key] = findType(key); | |
1143 } | |
1144 | |
1145 return returned; | |
1146 } | |
1147 | |
1148 PrimitiveTypeEntry *findTargetLangPrimitiveType(const QString &java_name); | |
1149 | |
1150 void addRejection(const QString &class_name, const QString &function_name, | |
1151 const QString &field_name, const QString &enum_name); | |
1152 bool isClassRejected(const QString &class_name); | |
1153 bool isFunctionRejected(const QString &class_name, const QString &function_name); | |
1154 bool isFieldRejected(const QString &class_name, const QString &field_name); | |
1155 bool isEnumRejected(const QString &class_name, const QString &enum_name); | |
1156 | |
1157 void addType(TypeEntry *e) { m_entries[e->qualifiedCppName()].append(e); } | |
1158 | |
1159 SingleTypeEntryHash flagsEntries() const { return m_flags_entries; } | |
1160 FlagsTypeEntry *findFlagsType(const QString &name) const; | |
1161 void addFlagsType(FlagsTypeEntry *fte) { m_flags_entries[fte->originalName()] = fte; } | |
1162 | |
1163 TemplateEntry *findTemplate(const QString &name) { return m_templates[name]; } | |
1164 void addTemplate(TemplateEntry *t) { m_templates[t->name()] = t; } | |
1165 | |
1166 void setIncludeEclipseWarnings(bool on) { m_includeEclipseWarnings = on; } | |
1167 bool includeEclipseWarnings() const { return m_includeEclipseWarnings; } | |
1168 | |
1169 void setSuppressWarnings(bool on) { m_suppressWarnings = on; } | |
1170 void addSuppressedWarning(const QString &s) | |
1171 { | |
1172 m_suppressedWarnings.append(s); | |
1173 } | |
1174 | |
1175 bool isSuppressedWarning(const QString &s) | |
1176 { | |
1177 if (!m_suppressWarnings) | |
1178 return false; | |
1179 | |
1180 foreach (const QString &_warning, m_suppressedWarnings) { | |
1181 QString warning(QString(_warning).replace("\\*", "&place_holder_for_asterisk;")); | |
1182 | |
1183 QStringList segs = warning.split("*", QString::SkipEmptyParts); | |
1184 if (segs.size() == 0) | |
1185 continue ; | |
1186 | |
1187 int i = 0; | |
1188 int pos = s.indexOf(QString(segs.at(i++)).replace("&place_holder_for_asterisk;", "*")); | |
1189 //qDebug() << "s == " << s << ", warning == " << segs; | |
1190 while (pos != -1) { | |
1191 if (i == segs.size()) | |
1192 return true; | |
1193 pos = s.indexOf(QString(segs.at(i++)).replace("&place_holder_for_asterisk;", "*"), pos); | |
1194 } | |
1195 } | |
1196 | |
1197 return false; | |
1198 } | |
1199 | |
1200 void setRebuildClasses(const QStringList &cls) { m_rebuild_classes = cls; } | |
1201 | |
1202 static QString globalNamespaceClassName(const TypeEntry *te); | |
1203 QString filename() const { return "typesystem.txt"; } | |
1204 | |
4 | 1205 bool parseFile(const QString &filename, const QString &work_dir, bool generate = true); |
1 | 1206 |
1207 private: | |
1208 uint m_suppressWarnings : 1; | |
1209 uint m_includeEclipseWarnings : 1; | |
1210 uint m_reserved : 30; | |
1211 | |
1212 TypeEntryHash m_entries; | |
1213 SingleTypeEntryHash m_flags_entries; | |
1214 TemplateEntryHash m_templates; | |
1215 QStringList m_suppressedWarnings; | |
1216 | |
1217 QList<TypeRejection> m_rejections; | |
1218 QStringList m_rebuild_classes; | |
1219 }; | |
1220 | |
1221 inline PrimitiveTypeEntry *TypeDatabase::findPrimitiveType(const QString &name) | |
1222 { | |
1223 QList<TypeEntry *> entries = findTypes(name); | |
1224 | |
1225 foreach (TypeEntry *entry, entries) { | |
1226 if (entry != 0 && entry->isPrimitive() && static_cast<PrimitiveTypeEntry *>(entry)->preferredTargetLangType()) | |
1227 return static_cast<PrimitiveTypeEntry *>(entry); | |
1228 } | |
1229 | |
1230 return 0; | |
1231 } | |
1232 | |
1233 inline ComplexTypeEntry *TypeDatabase::findComplexType(const QString &name) | |
1234 { | |
1235 TypeEntry *entry = findType(name); | |
1236 if (entry != 0 && entry->isComplex()) | |
1237 return static_cast<ComplexTypeEntry *>(entry); | |
1238 else | |
1239 return 0; | |
1240 } | |
1241 | |
1242 inline ObjectTypeEntry *TypeDatabase::findObjectType(const QString &name) | |
1243 { | |
1244 TypeEntry *entry = findType(name); | |
1245 if (entry != 0 && entry->isObject()) | |
1246 return static_cast<ObjectTypeEntry *>(entry); | |
1247 else | |
1248 return 0; | |
1249 } | |
1250 | |
1251 inline NamespaceTypeEntry *TypeDatabase::findNamespaceType(const QString &name) | |
1252 { | |
1253 TypeEntry *entry = findType(name); | |
1254 if (entry != 0 && entry->isNamespace()) | |
1255 return static_cast<NamespaceTypeEntry *>(entry); | |
1256 else | |
1257 return 0; | |
1258 } | |
1259 | |
1260 QString fixCppTypeName(const QString &name); | |
1261 | |
1262 #endif // TYPESYSTEM_H |