-
Notifications
You must be signed in to change notification settings - Fork 2
/
AstGeneratorBase.h
190 lines (159 loc) · 6.36 KB
/
AstGeneratorBase.h
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
#pragma once
#ifndef AST_GENERATOR_BASE_H
#define AST_GENERATOR_BASE_H
#include <iostream>
#include <private/qqmlengine_p.h>
#include <private/qqmljsast_p.h>
#include "Location.h"
#include "parser.h"
using namespace std;
using namespace QQmlJS;
using namespace QQmlJS::AST;
struct lineColumn {
int line = 1;
int column = 0;
};
class AstGeneratorBase : protected Visitor {
public:
AstGeneratorBase(QQmlJS::Engine *engine, int level);
protected:
QQmlJS::Engine *engine;
int level;
template <typename T1, typename T2>
void print(const T1 &str, const T2 &extra) {
if (!Foobar::debug) {
return;
}
cout << string(level * 2, '-') << "> \033[1m" << str << "\033[0m";
if (extra != "") {
cout << " (" << extra << ")";
}
cout << "\n";
}
template <typename T1> void print(const T1 &str) { print(str, ""); }
string toString(const QString &str);
string toString(const Location &loc);
string toString(const QStringRef &str);
string toString(const Location &first, const Location &second);
string toString(UiQualifiedId *node);
json getLoc(const SourceLocation &loc);
json getLoc(const Location &loc);
Location mergeLocs(const SourceLocation &loc);
template <typename T1, typename T2>
json getLoc(const T1 &first, const T2 &second) {
const Location loc = mergeLocs(first, second);
return loc.toJson();
}
template <typename T, typename... Args>
json getLoc(const T &first, Args &...args) {
const Location loc = mergeLocs(first, args...);
return loc.toJson();
}
template <typename T1, typename T2>
Location mergeLocs(const T1 &t1, const T2 &t2) {
const Location first = Location(t1);
const Location second = Location(t2);
if (!first.isValid())
return second;
if (!second.isValid())
return first;
return first.mergeWith(second);
}
template <typename T1, typename T2, typename... Args>
Location mergeLocs(const T1 &first, const T2 &second, Args... args) {
if (!first.isValid() && !second.isValid())
return mergeLocs(args...);
if (!first.isValid())
return mergeLocs(second, args...);
if (!second.isValid())
return mergeLocs(first, args...);
const Location loc = mergeLocs(first, second);
return mergeLocs(loc, args...);
}
lineColumn getLineColumn(const int index);
QChar getCharAt(const int index);
int getNextPrintableCharIndex(const int startFromIndex);
bool visit(UiPragma *node) override;
bool visit(UiImport *node) override;
bool visit(UiObjectDefinition *node) override;
bool visit(UiObjectInitializer *node) override;
bool visit(UiParameterList *list) override;
bool visit(UiPublicMember *node) override;
bool visit(UiObjectBinding *node) override;
bool visit(UiScriptBinding *node) override;
bool visit(UiArrayBinding *node) override;
bool visit(UiArrayMemberList *node) override;
void throwRecursionDepthError() override;
// bool visit(ThisExpression *node) override;
// bool visit(NullExpression *node) override;
// bool visit(TrueLiteral *node) override;
// bool visit(FalseLiteral *node) override;
// bool visit(IdentifierExpression *node) override;
// bool visit(StringLiteral *node) override;
// bool visit(NumericLiteral *node) override;
// bool visit(RegExpLiteral *node) override;
// bool visit(ArrayLiteral *node) override;
// bool visit(ObjectLiteral *node) override;
// bool visit(ElementList *node) override;
// bool visit(PropertyAssignmentList *node) override;
// bool visit(NestedExpression *node) override;
// bool visit(IdentifierPropertyName *node) override;
// bool visit(StringLiteralPropertyName *node) override;
// bool visit(NumericLiteralPropertyName *node) override;
// bool visit(ArrayMemberExpression *node) override;
// bool visit(FieldMemberExpression *node) override;
// bool visit(NewMemberExpression *node) override;
// bool visit(NewExpression *node) override;
// bool visit(CallExpression *node) override;
// bool visit(PostIncrementExpression *node) override;
// bool visit(PostDecrementExpression *node) override;
// bool visit(PreIncrementExpression *node) override;
// bool visit(PreDecrementExpression *node) override;
// bool visit(DeleteExpression *node) override;
// bool visit(VoidExpression *node) override;
// bool visit(TypeOfExpression *node) override;
// bool visit(UnaryPlusExpression *node) override;
// bool visit(UnaryMinusExpression *node) override;
// bool visit(TildeExpression *node) override;
// bool visit(NotExpression *node) override;
// bool visit(BinaryExpression *node) override;
// bool visit(ConditionalExpression *node) override;
// bool visit(Block *node) override;
// bool visit(VariableStatement *node) override;
// bool visit(VariableDeclaration *node) override;
// bool visit(EmptyStatement *node) override;
// bool visit(IfStatement *node) override;
// bool visit(DoWhileStatement *node) override;
// bool visit(WhileStatement *node) override;
// bool visit(ForStatement *node) override;
// bool visit(LocalForStatement *node) override;
// bool visit(ForEachStatement *node) override;
// bool visit(LocalForEachStatement *node) override;
// bool visit(ContinueStatement *node) override;
// bool visit(BreakStatement *node) override;
// bool visit(ReturnStatement *node) override;
// bool visit(ThrowStatement *node) override;
// bool visit(WithStatement *node) override;
// bool visit(SwitchStatement *node) override;
// bool visit(CaseBlock *node) override;
// bool visit(CaseClause *node) override;
// bool visit(DefaultClause *node) override;
// bool visit(LabelledStatement *node) override;
// bool visit(TryStatement *node) override;
// bool visit(Catch *node) override;
// bool visit(Finally *node) override;
// bool visit(FunctionDeclaration *node) override;
// bool visit(FunctionExpression *node) override;
// bool visit(UiHeaderItemList *node) override;
// bool visit(UiObjectMemberList *node) override;
// bool visit(UiQualifiedId *node) override;
// bool visit(UiQualifiedPragmaId *node) override;
// bool visit(Elision *node) override;
// bool visit(ArgumentList *node) override;
// bool visit(StatementList *node) override;
// bool visit(SourceElements *node) override;
// bool visit(VariableDeclarationList *node) override;
// bool visit(CaseClauses *node) override;
// bool visit(FormalParameterList *node) override;
};
#endif // AST_GENERATOR_BASE_H