1
/*
2
 * This file is part of the API Extractor project.
3
 *
4
 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
 *
6
 * Contact: PySide team <contact@pyside.org>
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * version 2 as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 * 02110-1301 USA
21
 *
22
 */
23
24
#ifndef TYPESYSTEM_H
25
#define TYPESYSTEM_H
26
27
#include <QtCore/QHash>
28
#include <QtCore/QString>
29
#include <QtCore/QStringList>
30
#include <QtCore/QMap>
31
#include <QtCore/QDebug>
32
#include "apiextractormacros.h"
33
#include "include.h"
34
35
//Used to identify the conversion rule to avoid break API
36
#define TARGET_CONVERSION_RULE_FLAG "0"
37
#define NATIVE_CONVERSION_RULE_FLAG "1"
38
39
class Indentor;
40
41
class AbstractMetaType;
42
class QTextStream;
43
44
class EnumTypeEntry;
45
class FlagsTypeEntry;
46
47
typedef QMap<int, QString> ArgumentMap;
48
49
class TemplateInstance;
50
51
namespace TypeSystem
52
{
53
enum Language {
54
    NoLanguage          = 0x0000,
55
    TargetLangCode      = 0x0001,
56
    NativeCode          = 0x0002,
57
    ShellCode           = 0x0004,
58
    ShellDeclaration    = 0x0008,
59
    PackageInitializer  = 0x0010,
60
    DestructorFunction  = 0x0020,
61
    Constructors        = 0x0040,
62
    Interface           = 0x0080,
63
64
    // masks
65
    All                 = TargetLangCode
66
    | NativeCode
67
    | ShellCode
68
    | ShellDeclaration
69
    | PackageInitializer
70
    | Constructors
71
    | Interface
72
    | DestructorFunction,
73
74
    TargetLangAndNativeCode   = TargetLangCode | NativeCode
75
};
76
77
enum Ownership {
78
    InvalidOwnership,
79
    DefaultOwnership,
80
    TargetLangOwnership,
81
    CppOwnership
82
};
83
};
84
85
struct APIEXTRACTOR_API ReferenceCount
86
{
87
    ReferenceCount()  {}
88
    enum Action { // 0x01 - 0xff
89
        Invalid     = 0x00,
90
        Add         = 0x01,
91
        AddAll      = 0x02,
92
        Remove      = 0x04,
93
        Set         = 0x08,
94
        Ignore      = 0x10,
95
96
        ActionsMask = 0xff,
97
98
        Padding     = 0xffffffff
99
    };
100
101
    Action action;
102
    QString varName;
103
};
104
105
struct APIEXTRACTOR_API ArgumentOwner
106
{
107
    enum Action {
108
        Invalid     = 0x00,
109
        Add         = 0x01,
110
        Remove      = 0x02
111
    };
112
    enum {
113
        InvalidIndex = -2,
114
        ThisIndex = -1,
115
        ReturnIndex = 0,
116
        FirstArgumentIndex = 1
117
    };
118
    ArgumentOwner() : action(ArgumentOwner::Invalid), index(ArgumentOwner::InvalidIndex) {}
119
120
    Action action;
121
    int index;
122
};
123
124
class APIEXTRACTOR_API CodeSnipFragment
125
{
126
private:
127
    QString m_code;
128
    TemplateInstance *m_instance;
129
130
public:
131
    CodeSnipFragment(const QString &code)
132
        : m_code(code),
133
          m_instance(0) {}
134
135
    CodeSnipFragment(TemplateInstance *instance)
136
        : m_instance(instance) {}
137
138
    QString code() const;
139
};
140
141
class APIEXTRACTOR_API CodeSnipAbstract
142
{
143
public:
144
    QString code() const;
145
146
    void addCode(const QString &code)
147
    {
148
        codeList.append(CodeSnipFragment(code));
149
    }
150
151
    void addTemplateInstance(TemplateInstance *ti)
152
    {
153
        codeList.append(CodeSnipFragment(ti));
154
    }
155
156
    QList<CodeSnipFragment> codeList;
157
};
158
159
class APIEXTRACTOR_API CustomFunction : public CodeSnipAbstract
160
{
161
public:
162
    CustomFunction(const QString &n = QString()) : name(n) { }
163
164
    QString name;
165
    QString paramName;
166
};
167
168
class APIEXTRACTOR_API TemplateEntry : public CodeSnipAbstract
169
{
170
public:
171
    TemplateEntry(const QString &name, double vr)
172
            : m_name(name), m_version(vr)
173
    {
174
    };
175
176
    QString name() const
177
    {
178
        return m_name;
179
    };
180
181
    double version() const
182
    {
183
        return m_version;
184
    }
185
186
private:
187
    QString m_name;
188
    double m_version;
189
};
190
191
typedef QHash<QString, TemplateEntry *> TemplateEntryHash;
192
193
class APIEXTRACTOR_API TemplateInstance
194
{
195
public:
196
    TemplateInstance(const QString &name, double vr)
197
            : m_name(name), m_version(vr) {}
198
199
    void addReplaceRule(const QString &name, const QString &value)
200
    {
201
        replaceRules[name] = value;
202
    }
203
204
    QString expandCode() const;
205
206
    QString name() const
207
    {
208
        return m_name;
209
    }
210
211
    double version() const
212
    {
213
        return m_version;
214
    }
215
216
private:
217
    const QString m_name;
218
    double m_version;
219
    QHash<QString, QString> replaceRules;
220
};
221
222
223
class APIEXTRACTOR_API CodeSnip : public CodeSnipAbstract
224
{
225
public:
226
    enum Position {
227
        Beginning,
228
        End,
229
        AfterThis,
230
        // QtScript
231
        Declaration,
232
        PrototypeInitialization,
233
        ConstructorInitialization,
234
        Constructor,
235
        Any
236
    };
237
238
    CodeSnip(double vr) : language(TypeSystem::TargetLangCode), version(vr) { }
239
    CodeSnip(double vr, TypeSystem::Language lang) : language(lang), version(vr) { }
240
241
    TypeSystem::Language language;
242
    Position position;
243
    ArgumentMap argumentMap;
244
    double version;
245
};
246
typedef QList<CodeSnip> CodeSnipList;
247
248
struct APIEXTRACTOR_API ArgumentModification
249
{
250
    ArgumentModification(int idx, double vr)
251
            : removedDefaultExpression(false), removed(false),
252
              noNullPointers(false), index(idx), version(vr) {}
253
254
    // Should the default expression be removed?
255
    uint removedDefaultExpression : 1;
256
    uint removed : 1;
257
    uint noNullPointers : 1;
258
    uint resetAfterUse : 1;
259
260
    // The index of this argument
261
    int index;
262
263
    // Reference count flags for this argument
264
    QList<ReferenceCount> referenceCounts;
265
266
    // The text given for the new type of the argument
267
    QString modified_type;
268
269
    QString replace_value;
270
271
    // The code to be used to construct a return value when noNullPointers is true and
272
    // the returned value is null. If noNullPointers is true and this string is
273
    // empty, then the base class implementation will be used (or a default construction
274
    // if there is no implementation)
275
    QString nullPointerDefaultValue;
276
277
    // The text of the new default expression of the argument
278
    QString replacedDefaultExpression;
279
280
    // The new definition of ownership for a specific argument
281
    QHash<TypeSystem::Language, TypeSystem::Ownership> ownerships;
282
283
    // Different conversion rules
284
    CodeSnipList conversion_rules;
285
286
    //QObject parent(owner) of this argument
287
    ArgumentOwner owner;
288
289
    //Api version
290
    double version;
291
292
    //New name
293
    QString renamed_to;
294
};
295
296
struct APIEXTRACTOR_API Modification
297
{
298
    enum Modifiers {
299
        Private =               0x0001,
300
        Protected =             0x0002,
301
        Public =                0x0003,
302
        Friendly =              0x0004,
303
        AccessModifierMask =    0x000f,
304
305
        Final =                 0x0010,
306
        NonFinal =              0x0020,
307
        FinalMask =             Final | NonFinal,
308
309
        Readable =              0x0100,
310
        Writable =              0x0200,
311
312
        CodeInjection =         0x1000,
313
        Rename =                0x2000,
314
        Deprecated =            0x4000,
315
        ReplaceExpression =     0x8000,
316
        VirtualSlot =          0x10000 | NonFinal
317
    };
318
319
    Modification() : modifiers(0), removal(TypeSystem::NoLanguage) { }
320
321
    bool isAccessModifier() const
322
    {
323
        return modifiers & AccessModifierMask;
324
    }
325
    Modifiers accessModifier() const
326
    {
327
        return Modifiers(modifiers & AccessModifierMask);
328
    }
329
    bool isPrivate() const
330
    {
331
        return accessModifier() == Private;
332
    }
333
    bool isProtected() const
334
    {
335
        return accessModifier() == Protected;
336
    }
337
    bool isPublic() const
338
    {
339
        return accessModifier() == Public;
340
    }
341
    bool isFriendly() const
342
    {
343
        return accessModifier() == Friendly;
344
    }
345
    bool isFinal() const
346
    {
347
        return modifiers & Final;
348
    }
349
    bool isNonFinal() const
350
    {
351
        return modifiers & NonFinal;
352
    }
353
    bool isVirtualSlot() const
354
    {
355
        return (modifiers & VirtualSlot) == VirtualSlot;
356
    }
357
    QString accessModifierString() const;
358
359
    bool isDeprecated() const
360
    {
361
        return modifiers & Deprecated;
362
    }
363
364
    void setRenamedTo(const QString &name)
365
    {
366
        renamedToName = name;
367
    }
368
    QString renamedTo() const
369
    {
370
        return renamedToName;
371
    }
372
    bool isRenameModifier() const
373
    {
374
        return modifiers & Rename;
375
    }
376
377
    bool isRemoveModifier() const
378
    {
379
        return removal != TypeSystem::NoLanguage;
380
    }
381
382
    uint modifiers;
383
    QString renamedToName;
384
    TypeSystem::Language removal;
385
};
386
387
struct APIEXTRACTOR_API FunctionModification: public Modification
388
{
389
    FunctionModification(double vr) : m_thread(false), m_allowThread(false), m_version(vr) {}
390
391
    bool isCodeInjection() const
392
    {
393
        return modifiers & CodeInjection;
394
    }
395
    void setIsThread(bool flag)
396
    {
397
        m_thread = flag;
398
    }
399
    bool isThread() const
400
    {
401
        return m_thread;
402
    }
403
    bool allowThread() const
404
    {
405
        return m_allowThread;
406
    }
407
    void setAllowThread(bool allow)
408
    {
409
        m_allowThread = allow;
410
    }
411
    double version() const
412
    {
413
        return m_version;
414
    }
415
416
    bool operator!=(const FunctionModification& other) const;
417
    bool operator==(const FunctionModification& other) const;
418
419
420
    QString toString() const;
421
422
    QString signature;
423
    QString association;
424
    CodeSnipList snips;
425
426
    QList<ArgumentModification> argument_mods;
427
428
private:
429
    FunctionModification() {}
430
431
    bool m_thread;
432
    bool m_allowThread;
433
    double m_version;
434
435
436
};
437
typedef QList<FunctionModification> FunctionModificationList;
438
439
struct APIEXTRACTOR_API FieldModification: public Modification
440
{
441
    bool isReadable() const
442
    {
443
        return modifiers & Readable;
444
    }
445
    bool isWritable() const
446
    {
447
        return modifiers & Writable;
448
    }
449
450
    QString name;
451
};
452
453
typedef QList<FieldModification> FieldModificationList;
454
455
/**
456
*   \internal
457
*   Struct used to store information about functions added by the typesystem.
458
*   This info will be used later to create a fake AbstractMetaFunction which
459
*   will be inserted into the right AbstractMetaClass.
460
*/
461
struct APIEXTRACTOR_API AddedFunction
462
{
463
    /// Function access types.
464
    enum Access {
465
        Protected = 0x1,
466
        Public =    0x2
467
    };
468
469
    /**
470
    *   \internal
471
    *   Internal struct used to store information about arguments and return type of the
472
    *   functions added by the type system. This information is later used to create
473
    *   AbstractMetaType and AbstractMetaArgument for the AbstractMetaFunctions.
474
    */
475
    struct TypeInfo {
476
        TypeInfo() : isConstant(false), indirections(0), isReference(false) {}
477
        QString name;
478
        bool isConstant;
479
        int indirections;
480
        bool isReference;
481
        QString defaultValue;
482
    };
483
484
    /// Creates a new AddedFunction with a signature and a return type.
485
    AddedFunction(QString signature, QString returnType, double vr);
486
487
    /// Returns the function name.
488
    QString name() const
489
    {
490
        return m_name;
491
    }
492
493
    /// Set the function access type.
494
    void setAccess(Access access)
495
    {
496
        m_access = access;
497
    }
498
499
    /// Returns the function access type.
500
    Access access() const
501
    {
502
        return m_access;
503
    }
504
505
    /// Returns the function return type.
506
    TypeInfo returnType() const
507
    {
508
        return m_returnType;
509
    }
510
511
    /// Returns a list of argument type infos.
512
    QList<TypeInfo> arguments() const
513
    {
514
        return m_arguments;
515
    }
516
517
    /// Returns true if this is a constant method.
518
    bool isConstant() const
519
    {
520
        return m_isConst;
521
    }
522
523
    /// Set this method static.
524
    void setStatic(bool value)
525
    {
526
        m_isStatic = value;
527
    }
528
529
    /// Returns true if this is a static method.
530
    bool isStatic() const
531
    {
532
        return m_isStatic;
533
    }
534
535
    double version() const
536
    {
537
        return m_version;
538
    }
539
private:
540
    QString m_name;
541
    Access m_access;
542
    QList<TypeInfo> m_arguments;
543
    TypeInfo m_returnType;
544
    bool m_isConst;
545
    bool m_isStatic;
546
    double m_version;
547
};
548
typedef QList<AddedFunction> AddedFunctionList;
549
550
struct APIEXTRACTOR_API ExpensePolicy
551
{
552
    ExpensePolicy() : limit(-1) {}
553
    int limit;
554
    QString cost;
555
    bool isValid() const
556
    {
557
        return limit >= 0;
558
    }
559
};
560
561
class InterfaceTypeEntry;
562
class ObjectTypeEntry;
563
564
class APIEXTRACTOR_API DocModification
565
{
566
public:
567
    enum Mode {
568
        Append,
569
        Prepend,
570
        Replace,
571
        XPathReplace
572
    };
573
574
    DocModification(const QString& xpath, const QString& signature, double vr)
575
            : format(TypeSystem::NativeCode), m_mode(XPathReplace),
576
              m_xpath(xpath), m_signature(signature), m_version(vr) {}
577
    DocModification(Mode mode, const QString& signature, double vr)
578
            : m_mode(mode), m_signature(signature), m_version(vr) {}
579
580
    void setCode(const QString& code)
581
    {
582
        m_code = code;
583
    }
584
    QString code() const
585
    {
586
        return m_code;
587
    }
588
    QString xpath() const
589
    {
590
        return m_xpath;
591
    }
592
    QString signature() const
593
    {
594
        return m_signature;
595
    }
596
    Mode mode() const
597
    {
598
        return m_mode;
599
    }
600
    double version() const
601
    {
602
        return m_version;
603
    }
604
605
    TypeSystem::Language format;
606
607
private:
608
    Mode m_mode;
609
    QString m_code;
610
    QString m_xpath;
611
    QString m_signature;
612
    double m_version;
613
};
614
615
typedef QList<DocModification> DocModificationList;
616
617
class CustomConversion;
618
619
class APIEXTRACTOR_API TypeEntry
620
{
621
public:
622
    enum Type {
623
        PrimitiveType,
624
        VoidType,
625
        VarargsType,
626
        FlagsType,
627
        EnumType,
628
        EnumValue,
629
        TemplateArgumentType,
630
        ThreadType,
631
        BasicValueType,
632
        StringType,
633
        ContainerType,
634
        InterfaceType,
635
        ObjectType,
636
        NamespaceType,
637
        VariantType,
638
        JObjectWrapperType,
639
        CharType,
640
        ArrayType,
641
        TypeSystemType,
642
        CustomType,
643
        TargetLangType,
644
        FunctionType
645
    };
646
647
    enum CodeGeneration {
648
        GenerateTargetLang      = 0x0001,
649
        GenerateCpp             = 0x0002,
650
        GenerateForSubclass     = 0x0004,
651
652
        GenerateNothing         = 0,
653
        GenerateAll             = 0xffff,
654
        GenerateCode            = GenerateTargetLang | GenerateCpp
655
    };
656
657
    TypeEntry(const QString &name, Type t, double vr)
658
            : m_name(name),
659
              m_type(t),
660
              m_codeGeneration(GenerateAll),
661
              m_preferredConversion(true),
662
              m_stream(false),
663
              m_version(vr)
664
    {
665
    };
666
667
    virtual ~TypeEntry();
668
669
    Type type() const
670
    {
671
        return m_type;
672
    }
673
    bool isPrimitive() const
674
    {
675
        return m_type == PrimitiveType;
676
    }
677
    bool isEnum() const
678
    {
679
        return m_type == EnumType;
680
    }
681
    bool isFlags() const
682
    {
683
        return m_type == FlagsType;
684
    }
685
    bool isInterface() const
686
    {
687
        return m_type == InterfaceType;
688
    }
689
    bool isObject() const
690
    {
691
        return m_type == ObjectType;
692
    }
693
    bool isString() const
694
    {
695
        return m_type == StringType;
696
    }
697
    bool isChar() const
698
    {
699
        return m_type == CharType;
700
    }
701
    bool isNamespace() const
702
    {
703
        return m_type == NamespaceType;
704
    }
705
    bool isContainer() const
706
    {
707
        return m_type == ContainerType;
708
    }
709
    bool isVariant() const
710
    {
711
        return m_type == VariantType;
712
    }
713
    bool isJObjectWrapper() const
714
    {
715
        return m_type == JObjectWrapperType;
716
    }
717
    bool isArray() const
718
    {
719
        return m_type == ArrayType;
720
    }
721
    bool isTemplateArgument() const
722
    {
723
        return m_type == TemplateArgumentType;
724
    }
725
    bool isVoid() const
726
    {
727
        return m_type == VoidType;
728
    }
729
    bool isVarargs() const
730
    {
731
        return m_type == VarargsType;
732
    }
733
    bool isThread() const
734
    {
735
        return m_type == ThreadType;
736
    }
737
    bool isCustom() const
738
    {
739
        return m_type == CustomType;
740
    }
741
    bool isBasicValue() const
742
    {
743
        return m_type == BasicValueType;
744
    }
745
    bool isTypeSystem() const
746
    {
747
        return m_type == TypeSystemType;
748
    }
749
    bool isFunction() const
750
    {
751
        return m_type == FunctionType;
752
    }
753
    bool isEnumValue() const
754
    {
755
        return m_type == EnumValue;
756
    }
757
758
    virtual bool preferredConversion() const
759
    {
760
        return m_preferredConversion;
761
    }
762
    virtual void setPreferredConversion(bool b)
763
    {
764
        m_preferredConversion = b;
765
    }
766
767
    bool stream() const
768
    {
769
        return m_stream;
770
    }
771
772
    void setStream(bool b)
773
    {
774
        m_stream = b;
775
    }
776
777
    // The type's name in C++, fully qualified
778
    QString name() const
779
    {
780
        return m_name;
781
    }
782
783
    uint codeGeneration() const
784
    {
785
        return m_codeGeneration;
786
    }
787
    void setCodeGeneration(uint cg)
788
    {
789
        m_codeGeneration = cg;
790
    }
791
792
    // Returns true if code must be generated for this entry,
793
    // it will return false in case of types coming from typesystems
794
    // included for reference only.
795
    // NOTE: 'GenerateForSubclass' means 'generate="no"'
796
    //       on 'load-typesystem' tag
797
    inline bool generateCode() const
798
    {
799
        return m_codeGeneration != TypeEntry::GenerateForSubclass
800
               && m_codeGeneration != TypeEntry::GenerateNothing;
801
    }
802
803
    virtual QString qualifiedCppName() const
804
    {
805
        return m_name;
806
    }
807
808
    /**
809
     *   Its type's name in target language API
810
     *   The target language API name represents how this type is
811
     *   referred on low level code for the target language.
812
     *   Examples: for Java this would be a JNI name, for Python
813
     *   it should represent the CPython type name.
814
     *   /return string representing the target language API name
815
     *   for this type entry
816
     */
817
    virtual QString targetLangApiName() const
818
    {
819
        return m_name;
820
    }
821
822
    // The type's name in TargetLang
823
    virtual QString targetLangName() const
824
    {
825
        return m_name;
826
    }
827
828
    // The type to lookup when converting to TargetLang
829
    virtual QString lookupName() const
830
    {
831
        return targetLangName();
832
    }
833
834
    // The package
835
    virtual QString targetLangPackage() const
836
    {
837
        return QString();
838
    }
839
840
    virtual QString qualifiedTargetLangName() const
841
    {
842
        QString pkg = targetLangPackage();
843
        if (pkg.isEmpty())
844
            return targetLangName();
845
        return pkg + '.' + targetLangName();
846
    }
847
848
    virtual InterfaceTypeEntry *designatedInterface() const
849
    {
850
        return 0;
851
    }
852
853
    void setCustomConstructor(const CustomFunction &func)
854
    {
855
        m_customConstructor = func;
856
    }
857
    CustomFunction customConstructor() const
858
    {
859
        return m_customConstructor;
860
    }
861
862
    void setCustomDestructor(const CustomFunction &func)
863
    {
864
        m_customDestructor = func;
865
    }
866
    CustomFunction customDestructor() const
867
    {
868
        return m_customDestructor;
869
    }
870
871
    virtual bool isValue() const
872
    {
873
        return false;
874
    }
875
    virtual bool isComplex() const
876
    {
877
        return false;
878
    }
879
880
    virtual bool isNativeIdBased() const
881
    {
882
        return false;
883
    }
884
885
    CodeSnipList codeSnips() const;
886
    void setCodeSnips(const CodeSnipList &codeSnips)
887
    {
888
        m_codeSnips = codeSnips;
889
    }
890
    void addCodeSnip(const CodeSnip &codeSnip)
891
    {
892
        m_codeSnips << codeSnip;
893
    }
894
895
    void setDocModification(const DocModificationList& docMods)
896
    {
897
        m_docModifications << docMods;
898
    }
899
    DocModificationList docModifications() const
900
    {
901
        return m_docModifications;
902
    }
903
904
    IncludeList extraIncludes() const
905
    {
906
        return m_extraIncludes;
907
    }
908
    void setExtraIncludes(const IncludeList &includes)
909
    {
910
        m_extraIncludes = includes;
911
    }
912
    void addExtraInclude(const Include &include)
913
    {
914
        if (!m_includesUsed.value(include.name(), false)) {
915
            m_extraIncludes << include;
916
            m_includesUsed[include.name()] = true;
917
        }
918
    }
919
920
    Include include() const
921
    {
922
        return m_include;
923
    }
924
    void setInclude(const Include &inc)
925
    {
926
        m_include = inc;
927
    }
928
929
    // Replace conversionRule arg to CodeSnip in future version
930
    /// Set the type convertion rule
931
    void setConversionRule(const QString& conversionRule)
932
    {
933
        m_conversionRule = conversionRule;
934
    }
935
936
    /// Returns the type convertion rule
937
    QString conversionRule() const
938
    {
939
        //skip conversions flag
940
        return m_conversionRule.mid(1);
941
    }
942
943
    /// Returns true if there are any conversiton rule for this type, false otherwise.
944
    bool hasConversionRule() const
945
    {
946
        return !m_conversionRule.isEmpty();
947
    }
948
949
    double version() const
950
    {
951
        return m_version;
952
    }
953
954
    /// TODO-CONVERTER: mark as deprecated
955
    bool hasNativeConversionRule() const
956
    {
957
        return m_conversionRule.startsWith(NATIVE_CONVERSION_RULE_FLAG);
958
    }
959
960
    /// TODO-CONVERTER: mark as deprecated
961
    bool hasTargetConversionRule() const
962
    {
963
        return m_conversionRule.startsWith(TARGET_CONVERSION_RULE_FLAG);
964
    }
965
966
    bool isCppPrimitive() const;
967
968
    bool hasCustomConversion() const;
969
    void setCustomConversion(CustomConversion* customConversion);
970
    CustomConversion* customConversion() const;
971
private:
972
    QString m_name;
973
    Type m_type;
974
    uint m_codeGeneration;
975
    CustomFunction m_customConstructor;
976
    CustomFunction m_customDestructor;
977
    bool m_preferredConversion;
978
    CodeSnipList m_codeSnips;
979
    DocModificationList m_docModifications;
980
    IncludeList m_extraIncludes;
981
    Include m_include;
982
    QHash<QString, bool> m_includesUsed;
983
    QString m_conversionRule;
984
    bool m_stream;
985
    double m_version;
986
};
987
typedef QHash<QString, QList<TypeEntry *> > TypeEntryHash;
988
typedef QHash<QString, TypeEntry *> SingleTypeEntryHash;
989
990
991
class APIEXTRACTOR_API TypeSystemTypeEntry : public TypeEntry
992
{
993
public:
994
    TypeSystemTypeEntry(const QString &name, double vr)
995
            : TypeEntry(name, TypeSystemType, vr)
996
    {
997
    };
998
};
999
1000
class APIEXTRACTOR_API VoidTypeEntry : public TypeEntry
1001
{
1002
public:
1003
    VoidTypeEntry() : TypeEntry("void", VoidType, 0) { }
1004
};
1005
1006
class APIEXTRACTOR_API VarargsTypeEntry : public TypeEntry
1007
{
1008
public:
1009
    VarargsTypeEntry() : TypeEntry("...", VarargsType, 0) { }
1010
};
1011
1012
class APIEXTRACTOR_API TemplateArgumentEntry : public TypeEntry
1013
{
1014
public:
1015
    TemplateArgumentEntry(const QString &name, double vr)
1016
            : TypeEntry(name, TemplateArgumentType, vr), m_ordinal(0)
1017
    {
1018
    }
1019
1020
    int ordinal() const
1021
    {
1022
        return m_ordinal;
1023
    }
1024
    void setOrdinal(int o)
1025
    {
1026
        m_ordinal = o;
1027
    }
1028
1029
private:
1030
    int m_ordinal;
1031
};
1032
1033
class APIEXTRACTOR_API ArrayTypeEntry : public TypeEntry
1034
{
1035
public:
1036
    ArrayTypeEntry(const TypeEntry *nested_type, double vr)
1037
            : TypeEntry("Array", ArrayType, vr), m_nestedType(nested_type)
1038
    {
1039
        Q_ASSERT(m_nestedType);
1040
    }
1041
1042
    void setNestedTypeEntry(TypeEntry *nested)
1043
    {
1044
        m_nestedType = nested;
1045
    }
1046
    const TypeEntry *nestedTypeEntry() const
1047
    {
1048
        return m_nestedType;
1049
    }
1050
1051
    QString targetLangName() const
1052
    {
1053
        return m_nestedType->targetLangName() + "[]";
1054
    }
1055
    QString targetLangApiName() const
1056
    {
1057
        if (m_nestedType->isPrimitive())
1058
            return m_nestedType->targetLangApiName() + "Array";
1059
        else
1060
            return "jobjectArray";
1061
    }
1062
1063
private:
1064
    const TypeEntry *m_nestedType;
1065
};
1066
1067
1068
class APIEXTRACTOR_API PrimitiveTypeEntry : public TypeEntry
1069
{
1070
public:
1071
    PrimitiveTypeEntry(const QString &name, double vr)
1072
            : TypeEntry(name, PrimitiveType, vr),
1073
              m_preferredConversion(true),
1074
              m_preferredTargetLangType(true),
1075
              m_aliasedTypeEntry(0)
1076
    {
1077
    }
1078
1079
    QString targetLangName() const
1080
    {
1081
        return m_targetLangName;
1082
    }
1083
    void setTargetLangName(const QString &targetLangName)
1084
    {
1085
        m_targetLangName  = targetLangName;
1086
    }
1087
1088
    QString targetLangApiName() const
1089
    {
1090
        return m_targetLangApiName;
1091
    }
1092
    void setTargetLangApiName(const QString &targetLangApiName)
1093
    {
1094
        m_targetLangApiName = targetLangApiName;
1095
    }
1096
1097
    QString defaultConstructor() const
1098
    {
1099
        return m_defaultConstructor;
1100
    }
1101
    void setDefaultConstructor(const QString& defaultConstructor)
1102
    {
1103
        m_defaultConstructor = defaultConstructor;
1104
    }
1105
    bool hasDefaultConstructor() const
1106
    {
1107
        return !m_defaultConstructor.isEmpty();
1108
    }
1109
1110
    /**
1111
     *   The PrimitiveTypeEntry pointed by this type entry if it
1112
     *   represents an alias (i.e. a typedef).
1113
     *   /return the type pointed by the alias, or a null pointer
1114
     *   if the current object is not an alias
1115
     */
1116
    PrimitiveTypeEntry* aliasedTypeEntry() const { return m_aliasedTypeEntry; }
1117
1118
    /**
1119
     *   Defines type aliased by this entry.
1120
     *   /param aliasedTypeEntry type aliased by this entry
1121
     */
1122
    void setAliasedTypeEntry(PrimitiveTypeEntry* aliasedTypeEntry)
1123
    {
1124
        m_aliasedTypeEntry = aliasedTypeEntry;
1125
    }
1126
1127
    /**
1128
     *   Finds the most basic primitive type that the typedef represents,
1129
     *   i.e. a type that is not an alias.
1130
     *   /return the most basic non-aliased primitive type represented
1131
     *   by this typedef
1132
     */
1133
    PrimitiveTypeEntry* basicAliasedTypeEntry() const;
1134
1135
    virtual bool preferredConversion() const
1136
    {
1137
        return m_preferredConversion;
1138
    }
1139
    virtual void setPreferredConversion(bool b)
1140
    {
1141
        m_preferredConversion = b;
1142
    }
1143
1144
    virtual bool preferredTargetLangType() const
1145
    {
1146
        return m_preferredTargetLangType;
1147
    }
1148
    virtual void setPreferredTargetLangType(bool b)
1149
    {
1150
        m_preferredTargetLangType = b;
1151
    }
1152
1153
    void setTargetLangPackage(const QString& package);
1154
    QString targetLangPackage() const;
1155
private:
1156
    QString m_targetLangName;
1157
    QString m_targetLangApiName;
1158
    QString m_defaultConstructor;
1159
    uint m_preferredConversion : 1;
1160
    uint m_preferredTargetLangType : 1;
1161
    PrimitiveTypeEntry* m_aliasedTypeEntry;
1162
};
1163
1164
typedef QList<const PrimitiveTypeEntry*> PrimitiveTypeEntryList;
1165
1166
struct APIEXTRACTOR_API EnumValueRedirection
1167
{
1168
    EnumValueRedirection(const QString &rej, const QString &us)
1169
            : rejected(rej),
1170
            used(us)
1171
    {
1172
    }
1173
    QString rejected;
1174
    QString used;
1175
};
1176
1177
class APIEXTRACTOR_API EnumTypeEntry : public TypeEntry
1178
{
1179
public:
1180
    EnumTypeEntry(const QString &nspace, const QString &enumName, double vr)
1181
            : TypeEntry(nspace.isEmpty() ? enumName : nspace + QLatin1String("::") + enumName,
1182
                        EnumType, vr),
1183
            m_flags(0),
1184
            m_extensible(false)
1185
    {
1186
        m_qualifier = nspace;
1187
        m_targetLangName = enumName;
1188
    }
1189
1190
    QString targetLangPackage() const
1191
    {
1192
        return m_packageName;
1193
    }
1194
    void setTargetLangPackage(const QString &package)
1195
    {
1196
        m_packageName = package;
1197
    }
1198
1199
    QString targetLangName() const
1200
    {
1201
        return m_targetLangName;
1202
    }
1203
    QString targetLangQualifier() const;
1204
    QString qualifiedTargetLangName() const
1205
    {
1206
        QString qualifiedName;
1207
        QString pkg = targetLangPackage();
1208
        QString qualifier = targetLangQualifier();
1209
1210
        if (!pkg.isEmpty())
1211
            qualifiedName += pkg + '.';
1212
        if (!qualifier.isEmpty())
1213
            qualifiedName += qualifier + '.';
1214
        qualifiedName += targetLangName();
1215
1216
        return qualifiedName;
1217
    }
1218
1219
    QString targetLangApiName() const;
1220
1221
    QString qualifier() const
1222
    {
1223
        return m_qualifier;
1224
    }
1225
    void setQualifier(const QString &q)
1226
    {
1227
        m_qualifier = q;
1228
    }
1229
1230
    virtual bool preferredConversion() const
1231
    {
1232
        return false;
1233
    }
1234
1235
    bool isBoundsChecked() const
1236
    {
1237
        return m_lowerBound.isEmpty() && m_upperBound.isEmpty();
1238
    }
1239
1240
    QString upperBound() const
1241
    {
1242
        return m_upperBound;
1243
    }
1244
    void setUpperBound(const QString &bound)
1245
    {
1246
        m_upperBound = bound;
1247
    }
1248
1249
    QString lowerBound() const
1250
    {
1251
        return m_lowerBound;
1252
    }
1253
    void setLowerBound(const QString &bound)
1254
    {
1255
        m_lowerBound = bound;
1256
    }
1257
1258
    void setFlags(FlagsTypeEntry *flags)
1259
    {
1260
        m_flags = flags;
1261
    }
1262
    FlagsTypeEntry *flags() const
1263
    {
1264
        return m_flags;
1265
    }
1266
1267
    bool isExtensible() const
1268
    {
1269
        return m_extensible;
1270
    }
1271
    void setExtensible(bool is)
1272
    {
1273
        m_extensible = is;
1274
    }
1275
1276
    bool isEnumValueRejected(const QString &name)
1277
    {
1278
        return m_rejectedEnums.contains(name);
1279
    }
1280
    void addEnumValueRejection(const QString &name)
1281
    {
1282
        m_rejectedEnums << name;
1283
    }
1284
    QStringList enumValueRejections() const
1285
    {
1286
        return m_rejectedEnums;
1287
    }
1288
1289
    void addEnumValueRedirection(const QString &rejected, const QString &usedValue);
1290
    QString enumValueRedirection(const QString &value) const;
1291
1292
    bool forceInteger() const
1293
    {
1294
        return m_forceInteger;
1295
    }
1296
    void setForceInteger(bool force)
1297
    {
1298
        m_forceInteger = force;
1299
    }
1300
1301
    bool isAnonymous() const
1302
    {
1303
        return m_anonymous;
1304
    }
1305
    void setAnonymous(bool anonymous)
1306
    {
1307
        m_anonymous = anonymous;
1308
    }
1309
1310
private:
1311
    QString m_packageName;
1312
    QString m_qualifier;
1313
    QString m_targetLangName;
1314
1315
    QString m_lowerBound;
1316
    QString m_upperBound;
1317
1318
    QStringList m_rejectedEnums;
1319
    QList<EnumValueRedirection> m_enumRedirections;
1320
1321
    FlagsTypeEntry *m_flags;
1322
1323
    bool m_extensible;
1324
    bool m_forceInteger;
1325
    bool m_anonymous;
1326
};
1327
1328
class APIEXTRACTOR_API EnumValueTypeEntry : public TypeEntry
1329
{
1330
public:
1331
    EnumValueTypeEntry(const QString& name, const QString& value, const EnumTypeEntry* enclosingEnum, double vr)
1332
        : TypeEntry(name, TypeEntry::EnumValue, vr), m_value(value), m_enclosingEnum(enclosingEnum)
1333
    {
1334
    }
1335
1336
    QString value() const { return m_value; }
1337
    const EnumTypeEntry* enclosingEnum() const { return m_enclosingEnum; }
1338
private:
1339
    QString m_value;
1340
    const EnumTypeEntry* m_enclosingEnum;
1341
};
1342
1343
class APIEXTRACTOR_API FlagsTypeEntry : public TypeEntry
1344
{
1345
public:
1346
    FlagsTypeEntry(const QString &name, double vr) : TypeEntry(name, FlagsType, vr), m_enum(0)
1347
    {
1348
    }
1349
1350
    QString qualifiedTargetLangName() const;
1351
    QString targetLangName() const
1352
    {
1353
        return m_targetLangName;
1354
    }
1355
    QString targetLangApiName() const;
1356
    virtual bool preferredConversion() const
1357
    {
1358
        return false;
1359
    }
1360
1361
    QString originalName() const
1362
    {
1363
        return m_originalName;
1364
    }
1365
    void setOriginalName(const QString &s)
1366
    {
1367
        m_originalName = s;
1368
    }
1369
1370
    QString flagsName() const
1371
    {
1372
        return m_targetLangName;
1373
    }
1374
    void setFlagsName(const QString &name)
1375
    {
1376
        m_targetLangName = name;
1377
    }
1378
1379
    bool forceInteger() const
1380
    {
1381
        return m_enum->forceInteger();
1382
    }
1383
1384
    EnumTypeEntry *originator() const
1385
    {
1386
        return m_enum;
1387
    }
1388
    void setOriginator(EnumTypeEntry *e)
1389
    {
1390
        m_enum = e;
1391
    }
1392
1393
    QString targetLangPackage() const
1394
    {
1395
        return m_enum->targetLangPackage();
1396
    }
1397
1398
private:
1399
    QString m_originalName;
1400
    QString m_targetLangName;
1401
    EnumTypeEntry *m_enum;
1402
};
1403
1404
1405
class APIEXTRACTOR_API ComplexTypeEntry : public TypeEntry
1406
{
1407
public:
1408
    enum TypeFlag {
1409
        ForceAbstract      = 0x1,
1410
        DeleteInMainThread = 0x2,
1411
        Deprecated         = 0x4
1412
    };
1413
    typedef QFlags<TypeFlag> TypeFlags;
1414
1415
    enum CopyableFlag {
1416
        CopyableSet,
1417
        NonCopyableSet,
1418
        Unknown
1419
    };
1420
1421
    ComplexTypeEntry(const QString &name, Type t, double vr)
1422
            : TypeEntry(QString(name).replace(".*::", ""), t, vr),
1423
            m_qualifiedCppName(name),
1424
            m_qobject(false),
1425
            m_polymorphicBase(false),
1426
            m_genericClass(false),
1427
            m_typeFlags(0),
1428
            m_copyableFlag(Unknown),
1429
            m_hashFunction(""),
1430
            m_baseContainerType(0)
1431
    {
1432
    }
1433
1434
    bool isComplex() const
1435
    {
1436
        return true;
1437
    }
1438
1439
    ComplexTypeEntry *copy() const
1440
    {
1441
        ComplexTypeEntry *centry = new ComplexTypeEntry(name(), type(), version());
1442
        centry->setInclude(include());
1443
        centry->setExtraIncludes(extraIncludes());
1444
        centry->setAddedFunctions(addedFunctions());
1445
        centry->setFunctionModifications(functionModifications());
1446
        centry->setFieldModifications(fieldModifications());
1447
        centry->setQObject(isQObject());
1448
        centry->setDefaultSuperclass(defaultSuperclass());
1449
        centry->setCodeSnips(codeSnips());
1450
        centry->setTargetLangPackage(targetLangPackage());
1451
        centry->setBaseContainerType(baseContainerType());
1452
        centry->setDefaultConstructor(defaultConstructor());
1453
1454
        return centry;
1455
    }
1456
1457
    void setLookupName(const QString &name)
1458
    {
1459
        m_lookupName = name;
1460
    }
1461
1462
    virtual QString lookupName() const
1463
    {
1464
        return m_lookupName.isEmpty() ? targetLangName() : m_lookupName;
1465
    }
1466
1467
    QString targetLangApiName() const;
1468
1469
    void setTypeFlags(TypeFlags flags)
1470
    {
1471
        m_typeFlags = flags;
1472
    }
1473
1474
    TypeFlags typeFlags() const
1475
    {
1476
        return m_typeFlags;
1477
    }
1478
1479
    FunctionModificationList functionModifications() const
1480
    {
1481
        return m_functionMods;
1482
    }
1483
    void setFunctionModifications(const FunctionModificationList &functionModifications)
1484
    {
1485
        m_functionMods = functionModifications;
1486
    }
1487
    void addFunctionModification(const FunctionModification &functionModification)
1488
    {
1489
        m_functionMods << functionModification;
1490
    }
1491
    FunctionModificationList functionModifications(const QString &signature) const;
1492
1493
    AddedFunctionList addedFunctions() const
1494
    {
1495
        return m_addedFunctions;
1496
    }
1497
    void setAddedFunctions(const AddedFunctionList &addedFunctions)
1498
    {
1499
        m_addedFunctions = addedFunctions;
1500
    }
1501
    void addNewFunction(const AddedFunction &addedFunction)
1502
    {
1503
        m_addedFunctions << addedFunction;
1504
    }
1505
1506
    FieldModification fieldModification(const QString &name) const;
1507
    void setFieldModifications(const FieldModificationList &mods)
1508
    {
1509
        m_fieldMods = mods;
1510
    }
1511
    FieldModificationList fieldModifications() const
1512
    {
1513
        return m_fieldMods;
1514
    }
1515
1516
    QString targetLangPackage() const
1517
    {
1518
        return m_package;
1519
    }
1520
    void setTargetLangPackage(const QString &package)
1521
    {
1522
        m_package = package;
1523
    }
1524
1525
    bool isQObject() const
1526
    {
1527
        return m_qobject;
1528
    }
1529
    void setQObject(bool qobject)
1530
    {
1531
        m_qobject = qobject;
1532
    }
1533
1534
    QString defaultSuperclass() const
1535
    {
1536
        return m_defaultSuperclass;
1537
    }
1538
    void setDefaultSuperclass(const QString &sc)
1539
    {
1540
        m_defaultSuperclass = sc;
1541
    }
1542
1543
    virtual QString qualifiedCppName() const
1544
    {
1545
        return m_qualifiedCppName;
1546
    }
1547
1548
1549
    void setIsPolymorphicBase(bool on)
1550
    {
1551
        m_polymorphicBase = on;
1552
    }
1553
    bool isPolymorphicBase() const
1554
    {
1555
        return m_polymorphicBase;
1556
    }
1557
1558
    void setPolymorphicIdValue(const QString &value)
1559
    {
1560
        m_polymorphicIdValue = value;
1561
    }
1562
    QString polymorphicIdValue() const
1563
    {
1564
        return m_polymorphicIdValue;
1565
    }
1566
1567
    void setHeldType(const QString &value)
1568
    {
1569
        m_heldTypeValue = value;
1570
    }
1571
    QString heldTypeValue() const
1572
    {
1573
        return m_heldTypeValue;
1574
    }
1575
1576
1577
    void setExpensePolicy(const ExpensePolicy &policy)
1578
    {
1579
        m_expensePolicy = policy;
1580
    }
1581
    const ExpensePolicy &expensePolicy() const
1582
    {
1583
        return m_expensePolicy;
1584
    }
1585
1586
    QString targetType() const
1587
    {
1588
        return m_targetType;
1589
    }
1590
    void setTargetType(const QString &code)
1591
    {
1592
        m_targetType = code;
1593
    }
1594
1595
    QString targetLangName() const
1596
    {
1597
        return m_targetLangName.isEmpty()
1598
               ? TypeEntry::targetLangName()
1599
               : m_targetLangName;
1600
    }
1601
    void setTargetLangName(const QString &name)
1602
    {
1603
        m_targetLangName = name;
1604
    }
1605
1606
    bool isGenericClass() const
1607
    {
1608
        return m_genericClass;
1609
    }
1610
    void setGenericClass(bool isGeneric)
1611
    {
1612
        m_genericClass = isGeneric;
1613
    }
1614
1615
    CopyableFlag copyable() const
1616
    {
1617
        return m_copyableFlag;
1618
    }
1619
    void setCopyable(CopyableFlag flag)
1620
    {
1621
        m_copyableFlag = flag;
1622
    }
1623
1624
    QString hashFunction() const
1625
    {
1626
        return m_hashFunction;
1627
    }
1628
    void setHashFunction(QString hashFunction)
1629
    {
1630
        m_hashFunction = hashFunction;
1631
    }
1632
1633
    void setBaseContainerType(const ComplexTypeEntry *baseContainer)
1634
    {
1635
        m_baseContainerType = baseContainer;
1636
    }
1637
1638
    const ComplexTypeEntry* baseContainerType() const
1639
    {
1640
        return m_baseContainerType;
1641
    }
1642
1643
    QString defaultConstructor() const;
1644
    void setDefaultConstructor(const QString& defaultConstructor);
1645
    bool hasDefaultConstructor() const;
1646
1647
private:
1648
    AddedFunctionList m_addedFunctions;
1649
    FunctionModificationList m_functionMods;
1650
    FieldModificationList m_fieldMods;
1651
    QString m_package;
1652
    QString m_defaultSuperclass;
1653
    QString m_qualifiedCppName;
1654
    QString m_targetLangName;
1655
1656
    uint m_qobject : 1;
1657
    uint m_polymorphicBase : 1;
1658
    uint m_genericClass : 1;
1659
1660
    QString m_polymorphicIdValue;
1661
    QString m_heldTypeValue;
1662
    QString m_lookupName;
1663
    QString m_targetType;
1664
    ExpensePolicy m_expensePolicy;
1665
    TypeFlags m_typeFlags;
1666
    CopyableFlag m_copyableFlag;
1667
    QString m_hashFunction;
1668
1669
    const ComplexTypeEntry* m_baseContainerType;
1670
};
1671
1672
class APIEXTRACTOR_API ContainerTypeEntry : public ComplexTypeEntry
1673
{
1674
public:
1675
    enum Type {
1676
        NoContainer,
1677
        ListContainer,
1678
        StringListContainer,
1679
        LinkedListContainer,
1680
        VectorContainer,
1681
        StackContainer,
1682
        QueueContainer,
1683
        SetContainer,
1684
        MapContainer,
1685
        MultiMapContainer,
1686
        HashContainer,
1687
        MultiHashContainer,
1688
        PairContainer,
1689
    };
1690
1691
    ContainerTypeEntry(const QString &name, Type type, double vr)
1692
        : ComplexTypeEntry(name, ContainerType, vr), m_type(type)
1693
    {
1694
        setCodeGeneration(GenerateForSubclass);
1695
    }
1696
1697
    Type type() const
1698
    {
1699
        return m_type;
1700
    }
1701
1702
    QString typeName() const;
1703
    QString targetLangName() const;
1704
    QString targetLangPackage() const;
1705
    QString qualifiedCppName() const;
1706
1707
    static Type containerTypeFromString(QString typeName)
1708
    {
1709
        static QHash<QString, Type> m_stringToContainerType;
1710
        if (m_stringToContainerType.isEmpty()) {
1711
            m_stringToContainerType["list"] = ListContainer;
1712
            m_stringToContainerType["string-list"] = StringListContainer;
1713
            m_stringToContainerType["linked-list"] = LinkedListContainer;
1714
            m_stringToContainerType["vector"] = VectorContainer;
1715
            m_stringToContainerType["stack"] = StackContainer;
1716
            m_stringToContainerType["queue"] = QueueContainer;
1717
            m_stringToContainerType["set"] = SetContainer;
1718
            m_stringToContainerType["map"] = MapContainer;
1719
            m_stringToContainerType["multi-map"] = MultiMapContainer;
1720
            m_stringToContainerType["hash"] = HashContainer;
1721
            m_stringToContainerType["multi-hash"] = MultiHashContainer;
1722
            m_stringToContainerType["pair"] = PairContainer;
1723
        }
1724
        return m_stringToContainerType.value(typeName, NoContainer);
1725
    }
1726
1727
private:
1728
    Type m_type;
1729
};
1730
1731
typedef QList<const ContainerTypeEntry*> ContainerTypeEntryList;
1732
1733
class APIEXTRACTOR_API NamespaceTypeEntry : public ComplexTypeEntry
1734
{
1735
public:
1736
    NamespaceTypeEntry(const QString &name, double vr) : ComplexTypeEntry(name, NamespaceType, vr) { }
1737
};
1738
1739
1740
class APIEXTRACTOR_API ValueTypeEntry : public ComplexTypeEntry
1741
{
1742
public:
1743
    ValueTypeEntry(const QString &name, double vr) : ComplexTypeEntry(name, BasicValueType, vr) { }
1744
1745
    bool isValue() const
1746
    {
1747
        return true;
1748
    }
1749
1750
    virtual bool isNativeIdBased() const
1751
    {
1752
        return true;
1753
    }
1754
1755
protected:
1756
    ValueTypeEntry(const QString &name, Type t, double vr) : ComplexTypeEntry(name, t, vr) { }
1757
};
1758
1759
1760
class APIEXTRACTOR_API StringTypeEntry : public ValueTypeEntry
1761
{
1762
public:
1763
    StringTypeEntry(const QString &name, double vr)
1764
            : ValueTypeEntry(name, StringType, vr)
1765
    {
1766
        setCodeGeneration(GenerateNothing);
1767
    }
1768
1769
    QString targetLangApiName() const;
1770
    QString targetLangName() const;
1771
    QString targetLangPackage() const;
1772
1773
    virtual bool isNativeIdBased() const
1774
    {
1775
        return false;
1776
    }
1777
};
1778
1779
class APIEXTRACTOR_API CharTypeEntry : public ValueTypeEntry
1780
{
1781
public:
1782
    CharTypeEntry(const QString &name, double vr) : ValueTypeEntry(name, CharType, vr)
1783
    {
1784
        setCodeGeneration(GenerateNothing);
1785
    }
1786
1787
    QString targetLangApiName() const;
1788
    QString targetLangName() const;
1789
    QString targetLangPackage() const
1790
    {
1791
        return QString();
1792
    }
1793
1794
    virtual bool isNativeIdBased() const
1795
    {
1796
        return false;
1797
    }
1798
};
1799
1800
class APIEXTRACTOR_API VariantTypeEntry: public ValueTypeEntry
1801
{
1802
public:
1803
    VariantTypeEntry(const QString &name, double vr) : ValueTypeEntry(name, VariantType, vr) { }
1804
1805
    QString targetLangApiName() const;
1806
    QString targetLangName() const;
1807
    QString targetLangPackage() const;
1808
1809
    virtual bool isNativeIdBased() const
1810
    {
1811
        return false;
1812
    }
1813
};
1814
1815
1816
class APIEXTRACTOR_API InterfaceTypeEntry : public ComplexTypeEntry
1817
{
1818
public:
1819
    InterfaceTypeEntry(const QString &name, double vr)
1820
            : ComplexTypeEntry(name, InterfaceType, vr) {}
1821
1822
    static QString interfaceName(const QString &name)
1823
    {
1824
        return name + "Interface";
1825
    }
1826
1827
    ObjectTypeEntry *origin() const
1828
    {
1829
        return m_origin;
1830
    }
1831
    void setOrigin(ObjectTypeEntry *origin)
1832
    {
1833
        m_origin = origin;
1834
    }
1835
1836
    virtual bool isNativeIdBased() const
1837
    {
1838
        return true;
1839
    }
1840
    virtual QString qualifiedCppName() const
1841
    {
1842
        return ComplexTypeEntry::qualifiedCppName().left(ComplexTypeEntry::qualifiedCppName().length() - interfaceName("").length());
1843
    }
1844
1845
private:
1846
    ObjectTypeEntry *m_origin;
1847
};
1848
1849
1850
class APIEXTRACTOR_API FunctionTypeEntry : public TypeEntry
1851
{
1852
public:
1853
    FunctionTypeEntry(const QString& name, const QString& signature, double vr)
1854
            : TypeEntry(name, FunctionType, vr)
1855
    {
1856
        addSignature(signature);
1857
    }
1858
    void addSignature(const QString& signature)
1859
    {
1860
        m_signatures << signature;
1861
    }
1862
1863
    QStringList signatures() const
1864
    {
1865
        return m_signatures;
1866
    }
1867
1868
    bool hasSignature(const QString& signature) const
1869
    {
1870
        return m_signatures.contains(signature);
1871
    }
1872
private:
1873
    QStringList m_signatures;
1874
};
1875
1876
class APIEXTRACTOR_API ObjectTypeEntry : public ComplexTypeEntry
1877
{
1878
public:
1879
    ObjectTypeEntry(const QString &name, double vr)
1880
            : ComplexTypeEntry(name, ObjectType, vr), m_interface(0) {}
1881
1882
    InterfaceTypeEntry *designatedInterface() const
1883
    {
1884
        return m_interface;
1885
    }
1886
    void setDesignatedInterface(InterfaceTypeEntry *entry)
1887
    {
1888
        m_interface = entry;
1889
    }
1890
1891
    virtual bool isNativeIdBased() const
1892
    {
1893
        return true;
1894
    }
1895
1896
private:
1897
    InterfaceTypeEntry *m_interface;
1898
};
1899
1900
struct APIEXTRACTOR_API TypeRejection
1901
{
1902
    QString class_name;
1903
    QString function_name;
1904
    QString field_name;
1905
    QString enum_name;
1906
};
1907
1908
APIEXTRACTOR_API QString fixCppTypeName(const QString &name);
1909
1910
class APIEXTRACTOR_API CustomConversion
1911
{
1912
public:
1913
    CustomConversion(TypeEntry* ownerType);
1914
    ~CustomConversion();
1915
1916
    const TypeEntry* ownerType() const;
1917
    QString nativeToTargetConversion() const;
1918
    void setNativeToTargetConversion(const QString& nativeToTargetConversion);
1919
1920
    class APIEXTRACTOR_API TargetToNativeConversion
1921
    {
1922
    public:
1923
        TargetToNativeConversion(const QString& sourceTypeName,
1924
                                 const QString& sourceTypeCheck,
1925
                                 const QString& conversion = QString());
1926
        ~TargetToNativeConversion();
1927
1928
        const TypeEntry* sourceType() const;
1929
        void setSourceType(const TypeEntry* sourceType);
1930
        bool isCustomType() const;
1931
        QString sourceTypeName() const;
1932
        QString sourceTypeCheck() const;
1933
        QString conversion() const;
1934
        void setConversion(const QString& conversion);
1935
    private:
1936
        struct TargetToNativeConversionPrivate;
1937
        TargetToNativeConversionPrivate* m_d;
1938
    };
1939
1940
    /**
1941
     *  Returns true if the target to C++ custom conversions should
1942
     *  replace the original existing ones, and false if the custom
1943
     *  conversions should be added to the original.
1944
     */
1945
    bool replaceOriginalTargetToNativeConversions() const;
1946
    void setReplaceOriginalTargetToNativeConversions(bool replaceOriginalTargetToNativeConversions);
1947
1948
    typedef QList<TargetToNativeConversion*> TargetToNativeConversions;
1949
    bool hasTargetToNativeConversions() const;
1950
    TargetToNativeConversions& targetToNativeConversions();
1951
    const TargetToNativeConversions& targetToNativeConversions() const;
1952
    void addTargetToNativeConversion(const QString& sourceTypeName,
1953
                                     const QString& sourceTypeCheck,
1954
                                     const QString& conversion = QString());
1955
private:
1956
    struct CustomConversionPrivate;
1957
    CustomConversionPrivate* m_d;
1958
};
1959
1960
#endif // TYPESYSTEM_H