1
/*
2
 * This file is part of the API Extractor project.
3
 *
4
 * Copyright (C) 2009-2010 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
#ifndef TYPESYSTEM_P_H
24
#define TYPESYSTEM_P_H
25
26
#include <QStack>
27
#include <QXmlDefaultHandler>
28
#include "typesystem.h"
29
30
class TypeDatabase;
31
class StackElement
32
{
33
    public:
34
        enum ElementType {
35
            None = 0x0,
36
37
            // Type tags (0x1, ... , 0xff)
38
            ObjectTypeEntry             = 0x1,
39
            ValueTypeEntry              = 0x2,
40
            InterfaceTypeEntry          = 0x3,
41
            NamespaceTypeEntry          = 0x4,
42
            ComplexTypeEntryMask        = 0x7,
43
44
            // Non-complex type tags (0x8, 0x9, ... , 0xf)
45
            PrimitiveTypeEntry          = 0x8,
46
            EnumTypeEntry               = 0x9,
47
            ContainerTypeEntry          = 0xa,
48
            FunctionTypeEntry           = 0xb,
49
            CustomTypeEntry             = 0xc,
50
            TypeEntryMask               = 0xf,
51
52
            // Documentation tags
53
            InjectDocumentation         = 0x10,
54
            ModifyDocumentation         = 0x20,
55
            DocumentationMask           = 0xf0,
56
57
            // Simple tags (0x100, 0x200, ... , 0xf00)
58
            ExtraIncludes               = 0x0100,
59
            Include                     = 0x0200,
60
            ModifyFunction              = 0x0300,
61
            ModifyField                 = 0x0400,
62
            Root                        = 0x0500,
63
            CustomMetaConstructor       = 0x0600,
64
            CustomMetaDestructor        = 0x0700,
65
            ArgumentMap                 = 0x0800,
66
            SuppressedWarning           = 0x0900,
67
            Rejection                   = 0x0a00,
68
            LoadTypesystem              = 0x0b00,
69
            RejectEnumValue             = 0x0c00,
70
            Template                    = 0x0d00,
71
            TemplateInstanceEnum        = 0x0e00,
72
            Replace                     = 0x0f00,
73
            AddFunction                 = 0x1000,
74
            NativeToTarget              = 0x1100,
75
            TargetToNative              = 0x1200,
76
            AddConversion               = 0x1300,
77
            SimpleMask                  = 0x3f00,
78
79
            // Code snip tags (0x1000, 0x2000, ... , 0xf000)
80
            InjectCode                  = 0x4000,
81
            InjectCodeInFunction        = 0x8000,
82
            CodeSnipMask                = 0xc000,
83
84
            // Function modifier tags (0x010000, 0x020000, ... , 0xf00000)
85
            Access                      = 0x010000,
86
            Removal                     = 0x020000,
87
            Rename                      = 0x040000,
88
            ModifyArgument              = 0x080000,
89
            Thread                      = 0x100000,
90
            FunctionModifiers           = 0xff0000,
91
92
            // Argument modifier tags (0x01000000 ... 0xf0000000)
93
            ConversionRule              = 0x01000000,
94
            ReplaceType                 = 0x02000000,
95
            ReplaceDefaultExpression    = 0x04000000,
96
            RemoveArgument              = 0x08000000,
97
            DefineOwnership             = 0x10000000,
98
            RemoveDefaultExpression     = 0x20000000,
99
            NoNullPointers              = 0x40000000,
100
            ReferenceCount              = 0x80000000,
101
            ParentOwner                 = 0x90000000,
102
            ArgumentModifiers           = 0xff000000
103
        };
104
105
        StackElement(StackElement *p) : entry(0), type(None), parent(p) { }
106
107
        TypeEntry* entry;
108
        ElementType type;
109
        StackElement *parent;
110
111
        union {
112
            TemplateInstance* templateInstance;
113
            TemplateEntry* templateEntry;
114
            CustomFunction* customFunction;
115
        } value;
116
};
117
118
struct StackElementContext
119
{
120
    CodeSnipList codeSnips;
121
    AddedFunctionList addedFunctions;
122
    FunctionModificationList functionMods;
123
    FieldModificationList fieldMods;
124
    DocModificationList docModifications;
125
};
126
127
class Handler : public QXmlDefaultHandler
128
{
129
public:
130
    Handler(TypeDatabase* database, bool generate);
131
132
    bool startElement(const QString& namespaceURI, const QString& localName,
133
                      const QString& qName, const QXmlAttributes& atts);
134
    bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName);
135
136
    QString errorString() const
137
    {
138
        return m_error;
139
    }
140
141
    bool error(const QXmlParseException &exception);
142
    bool fatalError(const QXmlParseException &exception);
143
    bool warning(const QXmlParseException &exception);
144
145
    bool characters(const QString &ch);
146
147
private:
148
    void fetchAttributeValues(const QString &name, const QXmlAttributes &atts,
149
                              QHash<QString, QString> *acceptedAttributes);
150
151
    bool importFileElement(const QXmlAttributes &atts);
152
    bool convertBoolean(const QString &, const QString &, bool);
153
154
    TypeDatabase* m_database;
155
    StackElement* m_current;
156
    StackElement* m_currentDroppedEntry;
157
    int m_currentDroppedEntryDepth;
158
    int m_ignoreDepth;
159
    QString m_defaultPackage;
160
    QString m_defaultSuperclass;
161
    QString m_error;
162
    TypeEntry::CodeGeneration m_generate;
163
164
    EnumTypeEntry* m_currentEnum;
165
    QStack<StackElementContext*> m_contextStack;
166
167
    QHash<QString, StackElement::ElementType> tagNames;
168
    QString m_currentSignature;
169
};
170
171
#endif