forked from MeVisLab/pythonqt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypesystem.h
More file actions
1297 lines (1030 loc) · 37.9 KB
/
typesystem.h
File metadata and controls
1297 lines (1030 loc) · 37.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
**
** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Script Generator project on Qt Labs.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef TYPESYSTEM_H
#define TYPESYSTEM_H
#include <QtCore/QHash>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QMap>
#include <QDebug>
/* BEGIN: Qt6 compatibility. The following can removed when versions of Qt
* prior to 5.14 are no longer supported.
*/
/* QString::SkipEmptyParts was replicated in Qt::SplitBehavior in 15.4 and the
* QString original deprecated then it was removed in Qt6. This provides
* forward compatibility with Qt6 for versions of Qt prior to 15.4:
*/
#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
namespace Qt {
const QString::SplitBehavior SkipEmptyParts = QString::SkipEmptyParts;
};
#endif
/* Global endl (::endl) is used extensively in the generator .cpp files. This
* was supported by Qt until Qt6. In Qt5.14 Qt::endl was added in anticipation
* of the Qt6 change and the use of global endl could be avoided (it does not
* seem to have been explicitly deprecated). This gives backward compatibility
* for global endl in Qt6 (not Qt5, where global endl was still available).
*
* Note that 'constexpr' is available in Qt6 because Qt6 requires C++17;
* constexpr was introduced in C++11. Likewise for decltype. Qt::endl is a
* function so ::endl is a pointer to the function and the implicit conversion
* is used; this is to cause an compiler error in the future if the base type
* of Qt::endl changes.
*
* When versions of Qt older than 5.14 are no longer supported this can be
* removed however all the 'endl' references in the code will need to be
* changed to Qt::endl.
*/
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
static constexpr decltype (Qt::endl) *endl = Qt::endl;
#endif
/* END: Qt compatibility. */
class Indentor;
class AbstractMetaType;
class QTextStream;
class EnumTypeEntry;
class FlagsTypeEntry;
extern QString strings_Object;
extern QString strings_String;
extern QString strings_Thread;
extern QString strings_char;
extern QString strings_java_lang;
extern QString strings_jchar;
extern QString strings_jobject;
struct Include
{
enum IncludeType {
IncludePath,
LocalPath,
TargetLangImport
};
Include() : type(IncludePath) { }
Include(IncludeType t, const QString &nam) : type(t), name(nam) { };
bool isValid() { return !name.isEmpty(); }
IncludeType type;
QString name;
QString toString() const;
bool operator<(const Include &other) const { return name < other.name; }
};
typedef QList<Include> IncludeList;
typedef QMap<int, QString> ArgumentMap;
class TemplateInstance;
namespace TypeSystem {
enum Language {
NoLanguage = 0x0000,
TargetLangCode = 0x0001,
NativeCode = 0x0002,
ShellCode = 0x0004,
ShellDeclaration = 0x0008,
PackageInitializer = 0x0010,
DestructorFunction = 0x0020,
Constructors = 0x0040,
Interface = 0x0080,
PyWrapperCode = 0x0100,
PyWrapperDeclaration = 0x0200,
PyWrapperOperators = 0x0400,
PyShellDeclaration = 0x0800,
PyInheritShellDeclaration = 0x1000,
PyInitSource = 0x2000,
PySetWrapperFunc = 0x4000,
PyInheritShellConstructorCode = 0x8000,
// masks
All = TargetLangCode
| NativeCode
| ShellCode
| ShellDeclaration
| PackageInitializer
| Constructors
| Interface
| DestructorFunction,
JavaAndNativeCode = TargetLangCode | NativeCode,
TargetLangAndNativeCode = TargetLangCode | NativeCode
};
enum Ownership {
InvalidOwnership,
DefaultOwnership,
TargetLangOwnership,
CppOwnership,
TargetLangThisOwnership
};
//! A better normalized signature, which takes care of PODs with the same name
QByteArray normalizedSignature(const char* signature);
//! Determine version ID from version string
unsigned int qtVersionFromString(const QString& value, bool& ok);
}
struct ReferenceCount
{
ReferenceCount() : threadSafe(false), access(Public) { }
enum Action { // 0x01 - 0xff
Invalid = 0x00,
Add = 0x01,
AddAll = 0x02,
Remove = 0x04,
Set = 0x08,
Ignore = 0x10,
ActionsMask = 0xff,
Padding = 0xffffffff
};
enum Flag { // 0x100 - 0xf00
ThreadSafe = 0x100,
Static = 0x200,
DeclareVariable = 0x400,
FlagsMask = 0xf00
};
enum Access { // 0x1000 - 0xf000
Private = 0x1000,
Protected = 0x2000,
Friendly = 0x3000,
Public = 0x4000,
AccessMask = 0xf000
};
Action action;
QString variableName;
QString conditional;
QString declareVariable;
uint threadSafe : 1;
uint access;
};
class CodeSnipFragment{
private:
const QString m_code;
TemplateInstance *m_instance;
public:
CodeSnipFragment(const QString &code)
: m_code(code),
m_instance(0)
{}
CodeSnipFragment(TemplateInstance *instance)
: m_instance(instance)
{}
QString code() const;
};
class CodeSnipAbstract{
public:
QString code() const;
void addCode(const QString &code){
codeList.append(new CodeSnipFragment(code));
}
void addTemplateInstance(TemplateInstance *ti){
codeList.append(new CodeSnipFragment(ti));
}
QList<CodeSnipFragment*> codeList;
};
class CustomFunction : public CodeSnipAbstract
{
public:
CustomFunction(const QString &n = QString()) : name(n) { }
QString name;
QString param_name;
};
class TemplateEntry : public CodeSnipAbstract
{
public:
TemplateEntry(const QString &name)
: m_name(name)
{
};
QString name() const {
return m_name;
};
private:
QString m_name;
};
typedef QHash<QString, TemplateEntry *> TemplateEntryHash;
class TemplateInstance
{
public:
TemplateInstance(const QString &name)
: m_name(name)
{}
void addReplaceRule(const QString &name, const QString &value){
replaceRules[name]=value;
}
QString expandCode() const;
QString name() const {
return m_name;
}
private:
const QString m_name;
QHash<QString, QString> replaceRules;
};
class CodeSnip : public CodeSnipAbstract
{
public:
enum Position {
Beginning,
End,
AfterThis,
// QtScript
PrototypeInitialization,
ConstructorInitialization,
Constructor
};
CodeSnip() : language(TypeSystem::TargetLangCode) { }
CodeSnip(TypeSystem::Language lang) : language(lang) { }
// Very simple, easy to make code ugly if you try
QTextStream &formattedCode(QTextStream &s, Indentor &indentor) const;
TypeSystem::Language language;
Position position;
ArgumentMap argumentMap;
};
typedef QList<CodeSnip> CodeSnipList;
struct ArgumentModification
{
ArgumentModification(int idx) : removed_default_expression(false), removed(false), no_null_pointers(false), index(idx)
{}
// Should the default expression be removed?
uint removed_default_expression : 1;
uint removed : 1;
uint no_null_pointers : 1;
uint reset_after_use : 1;
// The index of this argument
int index;
// Reference count flags for this argument
QList<ReferenceCount> referenceCounts;
// The text given for the new type of the argument
QString modified_type;
QString replace_value;
// The code to be used to construct a return value when no_null_pointers is true and
// the returned value is null. If no_null_pointers is true and this string is
// empty, then the base class implementation will be used (or a default construction
// if there is no implementation)
QString null_pointer_default_value;
// The text of the new default expression of the argument
QString replaced_default_expression;
// The new definition of ownership for a specific argument
QHash<TypeSystem::Language, TypeSystem::Ownership> ownerships;
// Different conversion rules
CodeSnipList conversion_rules;
};
struct Modification {
enum Modifiers {
Private = 0x0001,
Protected = 0x0002,
Public = 0x0003,
Friendly = 0x0004,
AccessModifierMask = 0x000f,
Final = 0x0010,
NonFinal = 0x0020,
FinalMask = Final | NonFinal,
Readable = 0x0100,
Writable = 0x0200,
CodeInjection = 0x1000,
Rename = 0x2000,
Deprecated = 0x4000,
ReplaceExpression = 0x8000,
VirtualSlot = 0x10000 | NonFinal
};
Modification() : modifiers(0) { }
bool isAccessModifier() const { return modifiers & AccessModifierMask; }
Modifiers accessModifier() const { return Modifiers(modifiers & AccessModifierMask); }
bool isPrivate() const { return accessModifier() == Private; }
bool isProtected() const { return accessModifier() == Protected; }
bool isPublic() const { return accessModifier() == Public; }
bool isFriendly() const { return accessModifier() == Friendly; }
bool isFinal() const { return modifiers & Final; }
bool isNonFinal() const { return modifiers & NonFinal; }
bool isVirtualSlot() const { return (modifiers & VirtualSlot) == VirtualSlot; }
QString accessModifierString() const;
bool isDeprecated() const { return modifiers & Deprecated; }
void setRenamedTo(const QString &name) { renamedToName = name; }
QString renamedTo() const { return renamedToName; }
bool isRenameModifier() const { return modifiers & Rename; }
uint modifiers;
QString renamedToName;
};
struct FunctionModification: public Modification
{
FunctionModification() : removal(TypeSystem::NoLanguage) { }
bool isCodeInjection() const { return modifiers & CodeInjection; }
bool isRemoveModifier() const { return removal != TypeSystem::NoLanguage; }
QString toString() const;
QString signature;
QString association;
CodeSnipList snips;
TypeSystem::Language removal;
QList<ArgumentModification> argument_mods;
};
typedef QList<FunctionModification> FunctionModificationList;
struct FieldModification: public Modification
{
bool isReadable() const { return modifiers & Readable; }
bool isWritable() const { return modifiers & Writable; }
QString name;
};
typedef QList<FieldModification> FieldModificationList;
struct ExpensePolicy {
ExpensePolicy() : limit(-1) { }
int limit;
QString cost;
bool isValid() const { return limit >= 0; }
};
class InterfaceTypeEntry;
class ObjectTypeEntry;
class TypeEntry
{
public:
enum Type {
PrimitiveType,
VoidType,
FlagsType,
EnumType,
TemplateArgumentType,
ThreadType,
BasicValueType,
StringType,
ContainerType,
InterfaceType,
ObjectType,
NamespaceType,
VariantType,
JObjectWrapperType,
CharType,
ArrayType,
TypeSystemType,
CustomType,
};
enum CodeGeneration {
GenerateTargetLang = 0x0001,
GenerateCpp = 0x0002,
GenerateForSubclass = 0x0004,
GenerateNothing = 0,
GenerateAll = 0xffff,
GenerateCode = GenerateTargetLang | GenerateCpp
};
TypeEntry(const QString &name, Type t)
: m_name(name),
m_type(t),
m_code_generation(GenerateAll),
m_preferred_conversion(true)
{
};
virtual ~TypeEntry() { }
Type type() const { return m_type; }
bool isPrimitive() const { return m_type == PrimitiveType; }
bool isEnum() const { return m_type == EnumType; }
bool isFlags() const { return m_type == FlagsType; }
bool isInterface() const { return m_type == InterfaceType; }
bool isObject() const { return m_type == ObjectType; }
bool isString() const { return m_type == StringType; }
bool isChar() const { return m_type == CharType; }
bool isNamespace() const { return m_type == NamespaceType; }
bool isContainer() const { return m_type == ContainerType; }
bool isVariant() const { return m_type == VariantType; }
bool isJObjectWrapper() const { return m_type == JObjectWrapperType; }
bool isArray() const { return m_type == ArrayType; }
bool isTemplateArgument() const { return m_type == TemplateArgumentType; }
bool isVoid() const { return m_type == VoidType; }
bool isThread() const { return m_type == ThreadType; }
bool isCustom() const { return m_type == CustomType; }
bool isBasicValue() const { return m_type == BasicValueType; }
bool isTypeSystem() const { return m_type == TypeSystemType; }
virtual bool preferredConversion() const { return m_preferred_conversion; }
virtual void setPreferredConversion(bool b) { m_preferred_conversion = b; }
// The type's name in C++, fully qualified
QString name() const { return m_name; }
//! Alias names for this type (need to be fully qualified)
QStringList aliases() const { return m_aliases; }
void setAliases(const QStringList& aliases) { m_aliases = aliases; }
uint codeGeneration() const { return m_code_generation; }
void setCodeGeneration(uint cg) { m_code_generation = cg; }
virtual QString qualifiedCppName() const { return m_name; }
// Its type's name in JNI
virtual QString jniName() const { return m_name; }
// The type's name in TargetLang
virtual QString targetLangName() const { return m_name; }
// The type to lookup when converting to TargetLang
virtual QString lookupName() const { return targetLangName(); }
// The package
virtual QString javaPackage() const { return QString(); }
virtual QString qualifiedTargetLangName() const {
QString pkg = javaPackage();
if (pkg.isEmpty()) return targetLangName();
return pkg + '.' + targetLangName();
}
virtual InterfaceTypeEntry *designatedInterface() const { return 0; }
void setCustomConstructor(const CustomFunction &func) { m_customConstructor = func; }
CustomFunction customConstructor() const { return m_customConstructor; }
void setCustomDestructor(const CustomFunction &func) { m_customDestructor = func; }
CustomFunction customDestructor() const { return m_customDestructor; }
virtual bool isValue() const { return false; }
virtual bool isComplex() const { return false; }
virtual bool isNativeIdBased() const { return false; }
virtual TypeEntry* equivalentType() const { return nullptr; }
private:
QString m_name;
QStringList m_aliases;
Type m_type;
uint m_code_generation;
CustomFunction m_customConstructor;
CustomFunction m_customDestructor;
bool m_preferred_conversion;
};
typedef QHash<QString, QList<TypeEntry *> > TypeEntryHash;
typedef QHash<QString, TypeEntry *> SingleTypeEntryHash;
class TypeSystemTypeEntry : public TypeEntry
{
public:
TypeSystemTypeEntry(const QString &name)
: TypeEntry(name, TypeSystemType)
{
};
QList<CodeSnip> snips;
};
class ThreadTypeEntry : public TypeEntry
{
public:
ThreadTypeEntry() : TypeEntry("QThread", ThreadType) { setCodeGeneration(GenerateNothing); }
QString jniName() const { return strings_jobject; }
QString targetLangName() const { return strings_Thread; }
QString javaPackage() const { return strings_java_lang; }
};
class VoidTypeEntry : public TypeEntry
{
public:
VoidTypeEntry() : TypeEntry("void", VoidType) { }
};
class TemplateArgumentEntry : public TypeEntry
{
public:
TemplateArgumentEntry(const QString &name)
: TypeEntry(name, TemplateArgumentType), m_ordinal(0)
{
}
int ordinal() const { return m_ordinal; }
void setOrdinal(int o) { m_ordinal = o; }
private:
int m_ordinal;
};
class ArrayTypeEntry : public TypeEntry
{
public:
ArrayTypeEntry(const TypeEntry *nested_type) : TypeEntry("Array", ArrayType), m_nested_type(nested_type)
{
Q_ASSERT(m_nested_type);
}
void setNestedTypeEntry(TypeEntry *nested) { m_nested_type = nested; }
const TypeEntry *nestedTypeEntry() const { return m_nested_type; }
QString targetLangName() const { return m_nested_type->targetLangName() + "[]"; }
QString jniName() const
{
if (m_nested_type->isPrimitive())
return m_nested_type->jniName() + "Array";
else
return "jobjectArray";
}
private:
const TypeEntry *m_nested_type;
};
class PrimitiveTypeEntry : public TypeEntry
{
public:
PrimitiveTypeEntry(const QString &name)
: TypeEntry(name, PrimitiveType), m_preferred_conversion(true), m_preferred_java_type(true)
{
}
QString targetLangName() const { return m_java_name; }
void setTargetLangName(const QString &targetLangName) { m_java_name = targetLangName; }
QString jniName() const { return m_jni_name; }
void setJniName(const QString &jniName) { m_jni_name = jniName; }
QString javaObjectFullName() const { return javaObjectPackage() + "." + javaObjectName(); }
QString javaObjectName() const;
QString javaObjectPackage() const { return strings_java_lang; }
virtual bool preferredConversion() const { return m_preferred_conversion; }
virtual void setPreferredConversion(bool b) { m_preferred_conversion = b; }
virtual bool preferredTargetLangType() const { return m_preferred_java_type; }
virtual void setPreferredTargetLangType(bool b) { m_preferred_java_type = b; }
private:
QString m_java_name;
QString m_jni_name;
uint m_preferred_conversion : 1;
uint m_preferred_java_type : 1;
};
struct EnumValueRedirection
{
EnumValueRedirection(const QString &rej, const QString &us)
: rejected(rej),
used(us)
{
}
QString rejected;
QString used;
};
class EnumTypeEntry : public TypeEntry
{
public:
EnumTypeEntry(const QString &nspace, const QString &enumName)
: TypeEntry(nspace.isEmpty() ? enumName : nspace + QLatin1String("::") + enumName,
EnumType),
m_flags(0),
m_extensible(false),
m_force_integer(false)
{
m_qualifier = nspace;
m_java_name = enumName;
}
QString javaPackage() const { return m_package_name; }
void setTargetLangPackage(const QString &package) { m_package_name = package; }
QString targetLangName() const { return m_java_name; }
QString javaQualifier() const;
QString qualifiedTargetLangName() const {
QString pkg = javaPackage();
if (pkg.isEmpty()) return javaQualifier() + '.' + targetLangName();
return pkg + '.' + javaQualifier() + '.' + targetLangName();
}
QString jniName() const;
Include include() const { return m_include; }
void setInclude(const Include &inc) { m_include = inc; }
QString qualifier() const { return m_qualifier; }
void setQualifier(const QString &q) { m_qualifier = q; }
virtual bool preferredConversion() const { return false; }
bool isBoundsChecked() const { return m_lower_bound.isEmpty() && m_upper_bound.isEmpty(); }
QString upperBound() const { return m_upper_bound; }
void setUpperBound(const QString &bound) { m_upper_bound = bound; }
QString lowerBound() const { return m_lower_bound; }
void setLowerBound(const QString &bound) { m_lower_bound = bound; }
void setFlags(FlagsTypeEntry *flags) { m_flags = flags; }
FlagsTypeEntry *flags() const { return m_flags; }
bool isExtensible() const { return m_extensible; }
void setExtensible(bool is) { m_extensible = is; }
bool isEnumValueRejected(const QString &name) { return m_rejected_enums.contains(name); }
void addEnumValueRejection(const QString &name) { m_rejected_enums << name; }
QStringList enumValueRejections() const { return m_rejected_enums; }
bool isEnumClass() const { return m_enum_class; }
void setEnumClass(bool enum_class) { m_enum_class = enum_class; }
bool forceInteger() const { return m_force_integer; }
void setForceInteger(bool force) { m_force_integer = force; }
private:
Include m_include;
QString m_package_name;
QString m_qualifier;
QString m_java_name;
QString m_lower_bound;
QString m_upper_bound;
QStringList m_rejected_enums;
FlagsTypeEntry *m_flags;
bool m_extensible;
bool m_enum_class;
bool m_force_integer;
};
class FlagsTypeEntry : public TypeEntry
{
public:
FlagsTypeEntry(const QString &name) : TypeEntry(name, FlagsType), m_enum(0)
{
}
QString qualifiedTargetLangName() const;
QString targetLangName() const { return m_java_name; }
QString jniName() const;
virtual bool preferredConversion() const { return false; }
QString originalName() const { return m_original_name; }
void setOriginalName(const QString &s) { m_original_name = s; }
QString flagsName() const { return m_java_name; }
void setFlagsName(const QString &name) { m_java_name = name; }
bool forceInteger() const { return m_enum->forceInteger(); }
EnumTypeEntry *originator() const { return m_enum; }
void setOriginator(EnumTypeEntry *e) { m_enum = e; }
QString javaPackage() const { return m_enum->javaPackage(); }
private:
QString m_original_name;
QString m_java_name;
EnumTypeEntry *m_enum;
};
class ComplexTypeEntry : public TypeEntry
{
public:
enum TypeFlag {
NoTypeFlags = 0x0,
ForceAbstract = 0x1,
DeleteInMainThread = 0x2,
Deprecated = 0x4
};
typedef QFlags<TypeFlag> TypeFlags;
ComplexTypeEntry(const QString &name, Type t)
: TypeEntry(QString(name).replace("::", "__"), t),
m_qualified_cpp_name(name),
m_qobject(false),
m_polymorphic_base(false),
m_generic_class(false),
m_createShell(false),
m_createPromoter(false),
m_noCopy(false),
m_type_flags(TypeFlag::NoTypeFlags)
{
Include inc;
inc.name = "QVariant";
inc.type = Include::IncludePath;
addExtraInclude(inc);
}
bool isComplex() const { return true; }
IncludeList extraIncludes() const { return m_extra_includes; }
void setExtraIncludes(const IncludeList &includes) { m_extra_includes = includes; }
void addExtraInclude(const Include &include)
{
if (!m_includes_used.value(include.name, false)) {
m_extra_includes << include;
m_includes_used[include.name] = true;
}
}
ComplexTypeEntry *copy() const
{
ComplexTypeEntry *centry = new ComplexTypeEntry(name(), type());
centry->setInclude(include());
centry->setExtraIncludes(extraIncludes());
centry->setFunctionModifications(functionModifications());
centry->setFieldModifications(fieldModifications());
centry->setQObject(isQObject());
centry->setDefaultSuperclass(defaultSuperclass());
centry->setCodeSnips(codeSnips());
centry->setTargetLangPackage(javaPackage());
return centry;
}
void setLookupName(const QString &name)
{
m_lookup_name = name;
}
virtual QString lookupName() const
{
return m_lookup_name.isEmpty() ? targetLangName() : m_lookup_name;
}
QString jniName() const { return strings_jobject; }
Include include() const { return m_include; }
void setInclude(const Include &inc) { m_include = inc; }
void setTypeFlags(TypeFlags flags)
{
m_type_flags = flags;
}
TypeFlags typeFlags() const
{
return m_type_flags;
}
CodeSnipList codeSnips() const { return m_code_snips; }
void setCodeSnips(const CodeSnipList &codeSnips) { m_code_snips = codeSnips; }
void addCodeSnip(const CodeSnip &codeSnip) { m_code_snips << codeSnip; }
FunctionModificationList functionModifications() const { return m_function_mods; }
void setFunctionModifications(const FunctionModificationList &functionModifications) {
m_function_mods = functionModifications;
}
void addFunctionModification(const FunctionModification &functionModification) {
m_function_mods << functionModification;
}
FunctionModificationList functionModifications(const QString &signature) const;
FieldModification fieldModification(const QString &name) const;
void setFieldModifications(const FieldModificationList &mods) { m_field_mods = mods; }
FieldModificationList fieldModifications() const { return m_field_mods; }
QString javaPackage() const { return m_package; }
void setTargetLangPackage(const QString &package) { m_package = package; }
bool isQObject() const { return m_qobject; }
void setQObject(bool qobject) { m_qobject = qobject; }
QString defaultSuperclass() const { return m_default_superclass; }
void setDefaultSuperclass(const QString &sc) { m_default_superclass = sc; }
virtual QString qualifiedCppName() const { return m_qualified_cpp_name; }
void setIsPolymorphicBase(bool on)
{
m_polymorphic_base = on;
}
bool isPolymorphicBase() const { return m_polymorphic_base; }
void setCreateShell(bool on)
{
m_createShell = on;
}
bool shouldCreateShell() const { return m_createShell; }
void setCreatePromoter(bool on)
{
m_createPromoter = on;
}
bool shouldCreatePromoter() const { return m_createPromoter; }
void setPolymorphicIdValue(const QString &value)
{
m_polymorphic_id_value = value;
}
QString polymorphicIdValue() const { return m_polymorphic_id_value; }
void setExpensePolicy(const ExpensePolicy &policy) { m_expense_policy = policy; }
const ExpensePolicy &expensePolicy() const { return m_expense_policy; }
QString targetType() const { return m_target_type; }
void setTargetType(const QString &code) { m_target_type = code; }
QString targetLangName() const { return m_java_name.isEmpty()
? TypeEntry::targetLangName()
: m_java_name;
}
void setTargetLangName(const QString &name) { m_java_name = name; }
bool isGenericClass() const { return m_generic_class; }
void setGenericClass(bool isGeneric) { m_generic_class = isGeneric; }
bool hasNoCopy() const { return m_noCopy; }
void setNoCopy(bool noCopy) { m_noCopy = noCopy; }
private:
IncludeList m_extra_includes;
Include m_include;
QHash<QString, bool> m_includes_used;
FunctionModificationList m_function_mods;
FieldModificationList m_field_mods;
CodeSnipList m_code_snips;
QString m_package;
QString m_default_superclass;
QString m_qualified_cpp_name;
QString m_java_name;
uint m_qobject : 1;
uint m_polymorphic_base : 1;
uint m_generic_class : 1;
uint m_createShell : 1;
uint m_createPromoter : 1;
uint m_noCopy : 1;
QString m_polymorphic_id_value;
QString m_lookup_name;
QString m_target_type;
ExpensePolicy m_expense_policy;
TypeFlags m_type_flags;
};
class ContainerTypeEntry : public ComplexTypeEntry
{
public:
enum Type {
NoContainer,
ListContainer,
StringListContainer,
LinkedListContainer,
VectorContainer,
StackContainer,
QueueContainer,
SetContainer,
MapContainer,
MultiMapContainer,
HashContainer,
MultiHashContainer,
PairContainer,
};
ContainerTypeEntry(const QString &name, Type type)
: ComplexTypeEntry(name, ContainerType)
{
m_type = type;
setCodeGeneration(GenerateForSubclass);
}
Type type() const { return m_type; }
QString targetLangName() const;
QString javaPackage() const;