File: Parser.h

package info (click to toggle)
qevercloud 3.0.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 932 kB
  • ctags: 666
  • sloc: cpp: 4,690; yacc: 486; makefile: 42
file content (220 lines) | stat: -rw-r--r-- 5,626 bytes parent folder | download | duplicates (3)
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
#ifndef QEVERCLOUD_GENERATOR_PARSER_H
#define QEVERCLOUD_GENERATOR_PARSER_H

#include <QObject>
#include "thrift_lemon.h"
#include "Lexer.h"
#include <QtDebug>
#include <QString>
#include <QStringList>
#include <QSharedPointer>

typedef QString Term;

class Parser : public QObject
{
    Q_OBJECT
public:
    explicit Parser(QObject *parent = 0);
    ~Parser();

    void feed(Lexer::TerminalSymbolType type, QString value);
    void setFile(QString file) {file_ = file; if(!files_.contains(file)) files_ << file;}
    void complete();


    struct Namespace {
        QString file;
        QString scope;
        QString name;
    };
    struct Include {
        QString file;
        QString name;
    };

    class Type {
    public:
        virtual ~Type() = 0;
    };

    class VoidType: public Type {
    public:
        ~VoidType() override {}
    };

    class BaseType: public Type {
    public:
        QString basetype;
        ~BaseType() override {}
    };

    class IdentifierType: public Type {
    public:
        QString identifier;
        ~IdentifierType() override {}
    };

    class MapType: public Type {
    public:
        QSharedPointer<Type> keyType;
        QSharedPointer<Type> valueType;
        ~MapType() override {}
    };

    class SetType: public Type {
    public:
        QSharedPointer<Type> valueType;
        ~SetType() override {}
    };

    class ListType: public Type {
    public:
        QSharedPointer<Type> valueType;
        ~ListType() override {}
    };

    struct TypeDefinition {
        QString file;
        QString name;
        QString docComment;
        QSharedPointer<Type> type;
    };

    class ConstValue {
    public:
        virtual ~ConstValue() = 0;
    };

    class LiteralValue: public ConstValue {
    public:
        QString value;
    };

    class IntegerValue: public LiteralValue {
    public:
        ~IntegerValue() override {}
    };

    class DoubleValue: public LiteralValue {
    public:
        ~DoubleValue() override {}
    };

    class StringValue: public LiteralValue {
    public:
        ~StringValue() override {}
    };

    class IdentifierValue: public LiteralValue {
    public:
        ~IdentifierValue() override {}
    };

    class ListValue: public ConstValue {
    public:
        QList<QSharedPointer<ConstValue>> values;
        ~ListValue() override {}
    };

    class MapValue: public ConstValue {
    public:
        QList<QPair<QSharedPointer<ConstValue>,QSharedPointer<ConstValue>>> values;
        ~MapValue() override {}
    };

    struct Field {
        int id;
        enum class RequiredFlag {Default, Optional, Required} required;
        QSharedPointer<Type> type;
        QString name;
        QSharedPointer<ConstValue> initializer;
    };
    struct Structure {
        QString file;
        QString name;
        QString docComment;
        QList<Field> fields;
        QMap<QString, QString> fieldComments;
        void parseStuctComment(QString rawComment);
    };

    struct Enumeration {
        QString file;
        QString name;
        QString docComment;
        QList<QPair<QString, QString>> values;
    };

    struct Function {
        bool isOneway;
        QSharedPointer<Type> type;
        QString name;
        QList<Field> params;
        QList<Field> throws;
        QString docComment;
    };
    struct Service {
        QString file;
        QString name;
        QString extends;
        QString docComment;
        QList<Function> functions;
    };

    struct Constant {
        QString file;
        QSharedPointer<Type> type;
        QString name;
        QSharedPointer<ConstValue> value;
        QString docComment;
    };

    QStringList files() {return files_;}
    QList<Namespace> namespaces() {return namespaces_;}
    QList<Include> includes() {return includes_;}
    QList<TypeDefinition> typedefs() {return typedefs_;}
    QList<Structure> structures() {return structures_;}
    QList<Enumeration> enumerations() {return enumerations_;}
    QList<Structure> exceptions() {return exceptions_;}
    QList<Service> services() {return services_;}
    QList<Constant> constants() {return constants_;}
    QList<Structure> unions() {return unions_;}

    bool isError() {return isError_;}
    QString errorMessage() {return errorMessage_;}

    void setErrorFlag(QString errorMessage) {isError_ = true; errorMessage_ = errorMessage;}

    void addTypedef(QString name, QSharedPointer<Type> type, QString docComment);
    void addNamespace(QString scope, QString name);
    void addConst(QSharedPointer<Type> type, QString name, QSharedPointer<ConstValue> value, QString docComment);
    void addInclude(QString name);
    void addStructure(QString name, QList<Field> fields, QString docComment);
    void addUnion(QString name, QList<Field> fields);
    void addException(QString name, QList<Field> fields, QString docComment);
    void addService(QString name, QString extends, QList<Function> functions, QString docComment);
    void addEnumeration(QString name, QList<QPair<QString, QString>> values, QString docComment);
private:
    void* parser;
    bool isError_;
    QString file_;
    QStringList files_;
    QString errorMessage_;

    QList<Namespace> namespaces_;
    QList<Include> includes_;
    QList<TypeDefinition> typedefs_;
    QList<Structure> structures_;
    QList<Enumeration> enumerations_;
    QList<Structure> exceptions_;
    QList<Service> services_;
    QList<Constant> constants_;
    QList<Structure> unions_;

};

inline Parser::Type::~Type() {}
inline Parser::ConstValue::~ConstValue() {}

#endif // QEVERCLOUD_GENERATOR_PARSER_H