iv-phonic 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/ext/include/iv/ast.h +27 -39
- data/ext/include/iv/ast_factory.h +148 -51
- data/ext/include/iv/ast_fwd.h +8 -4
- data/ext/include/iv/ast_serializer.h +9 -0
- data/ext/include/iv/ast_visitor.h +3 -0
- data/ext/include/iv/lexer.h +37 -4
- data/ext/include/iv/parser.h +219 -109
- data/ext/iv/phonic/ast_fwd.h +6 -0
- data/ext/iv/phonic/creator.h +83 -24
- data/ext/iv/phonic/factory.h +258 -104
- data/test/test_iv_phonic.rb +8 -1
- metadata +2 -2
data/Rakefile
CHANGED
data/ext/include/iv/ast.h
CHANGED
@@ -61,7 +61,8 @@ class type##Base\
|
|
61
61
|
}
|
62
62
|
|
63
63
|
template<typename Factory>
|
64
|
-
class Scope :
|
64
|
+
class Scope : public SpaceObject,
|
65
|
+
private Noncopyable<Scope<Factory> >::type {
|
65
66
|
public:
|
66
67
|
typedef std::pair<Identifier<Factory>*, bool> Variable;
|
67
68
|
typedef typename SpaceVector<Factory, Variable>::type Variables;
|
@@ -328,8 +329,7 @@ class VariableStatement : public VariableStatementBase<Factory> {
|
|
328
329
|
// Declaration
|
329
330
|
template<typename Factory>
|
330
331
|
class Inherit<Factory, kDeclaration>
|
331
|
-
: public
|
332
|
-
private Noncopyable<Inherit<Factory, kDeclaration> >::type {
|
332
|
+
: public AstNode<Factory> {
|
333
333
|
};
|
334
334
|
INHERIT(Declaration);
|
335
335
|
|
@@ -346,6 +346,7 @@ class Declaration : public DeclarationBase<Factory> {
|
|
346
346
|
inline Expression<Factory>* expr() const {
|
347
347
|
return expr_;
|
348
348
|
}
|
349
|
+
DECLARE_DERIVED_NODE_TYPE(Declaration)
|
349
350
|
private:
|
350
351
|
Identifier<Factory>* name_;
|
351
352
|
Expression<Factory>* expr_;
|
@@ -636,9 +637,7 @@ class LabelledStatement : public LabelledStatementBase<Factory> {
|
|
636
637
|
|
637
638
|
// CaseClause
|
638
639
|
template<typename Factory>
|
639
|
-
class Inherit<Factory, kCaseClause>
|
640
|
-
: public SpaceObject,
|
641
|
-
private Noncopyable<Inherit<Factory, kCaseClause> >::type {
|
640
|
+
class Inherit<Factory, kCaseClause> : public AstNode<Factory> {
|
642
641
|
};
|
643
642
|
INHERIT(CaseClause);
|
644
643
|
|
@@ -662,6 +661,7 @@ class CaseClause : public CaseClauseBase<Factory> {
|
|
662
661
|
inline const Statements& body() const {
|
663
662
|
return *body_;
|
664
663
|
}
|
664
|
+
DECLARE_DERIVED_NODE_TYPE(CaseClause)
|
665
665
|
private:
|
666
666
|
Expression<Factory>* expr_;
|
667
667
|
Statements* body_;
|
@@ -1208,28 +1208,18 @@ class FunctionLiteral : public FunctionLiteralBase<Factory> {
|
|
1208
1208
|
SETTER,
|
1209
1209
|
GETTER
|
1210
1210
|
};
|
1211
|
-
inline void SetName(Identifier<Factory>* name) { name_ = name; }
|
1212
1211
|
inline Identifier<Factory>* name() const {
|
1213
1212
|
return name_;
|
1214
1213
|
}
|
1215
1214
|
inline DeclType type() const { return type_; }
|
1216
1215
|
inline const Identifiers& params() const {
|
1217
|
-
return params_;
|
1216
|
+
return *params_;
|
1218
1217
|
}
|
1219
1218
|
inline const Statements& body() const {
|
1220
|
-
return body_;
|
1221
|
-
}
|
1222
|
-
inline Scope<Factory>* scope() {
|
1223
|
-
return &scope_;
|
1219
|
+
return *body_;
|
1224
1220
|
}
|
1225
1221
|
inline const Scope<Factory>& scope() const {
|
1226
|
-
return scope_;
|
1227
|
-
}
|
1228
|
-
inline void set_start_position(std::size_t start) {
|
1229
|
-
start_position_ = start;
|
1230
|
-
}
|
1231
|
-
inline void set_end_position(std::size_t end) {
|
1232
|
-
end_position_ = end;
|
1222
|
+
return *scope_;
|
1233
1223
|
}
|
1234
1224
|
inline std::size_t start_position() const {
|
1235
1225
|
return start_position_;
|
@@ -1240,32 +1230,30 @@ class FunctionLiteral : public FunctionLiteralBase<Factory> {
|
|
1240
1230
|
inline bool strict() const {
|
1241
1231
|
return strict_;
|
1242
1232
|
}
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1233
|
+
FunctionLiteral(DeclType type,
|
1234
|
+
Identifier<Factory>* name,
|
1235
|
+
Identifiers* params,
|
1236
|
+
Statements* body,
|
1237
|
+
Scope<Factory>* scope,
|
1238
|
+
bool strict,
|
1239
|
+
std::size_t start_position,
|
1240
|
+
std::size_t end_position)
|
1241
|
+
: name_(name),
|
1248
1242
|
type_(type),
|
1249
|
-
params_(
|
1250
|
-
body_(
|
1251
|
-
scope_(
|
1252
|
-
strict_(
|
1253
|
-
|
1254
|
-
|
1255
|
-
void AddParameter(Identifier<Factory>* param) {
|
1256
|
-
params_.push_back(param);
|
1257
|
-
}
|
1258
|
-
|
1259
|
-
void AddStatement(Statement<Factory>* stmt) {
|
1260
|
-
body_.push_back(stmt);
|
1243
|
+
params_(params),
|
1244
|
+
body_(body),
|
1245
|
+
scope_(scope),
|
1246
|
+
strict_(strict),
|
1247
|
+
start_position_(start_position),
|
1248
|
+
end_position_(end_position) {
|
1261
1249
|
}
|
1262
1250
|
DECLARE_DERIVED_NODE_TYPE(FunctionLiteral)
|
1263
1251
|
private:
|
1264
1252
|
Identifier<Factory>* name_;
|
1265
1253
|
DeclType type_;
|
1266
|
-
Identifiers params_;
|
1267
|
-
Statements body_;
|
1268
|
-
Scope<Factory
|
1254
|
+
Identifiers* params_;
|
1255
|
+
Statements* body_;
|
1256
|
+
Scope<Factory>* scope_;
|
1269
1257
|
bool strict_;
|
1270
1258
|
std::size_t start_position_;
|
1271
1259
|
std::size_t end_position_;
|
@@ -49,42 +49,73 @@ class BasicAstFactory {
|
|
49
49
|
}
|
50
50
|
|
51
51
|
template<typename Range>
|
52
|
-
Identifier* NewIdentifier(const Range& range
|
52
|
+
Identifier* NewIdentifier(const Range& range,
|
53
|
+
std::size_t begin,
|
54
|
+
std::size_t end) {
|
53
55
|
return new (static_cast<Factory*>(this))
|
54
56
|
Identifier(range, static_cast<Factory*>(this));
|
55
57
|
}
|
56
58
|
|
57
|
-
NumberLiteral*
|
59
|
+
NumberLiteral* NewReducedNumberLiteral(const double& val) {
|
58
60
|
return new (static_cast<Factory*>(this)) NumberLiteral(val);
|
59
61
|
}
|
60
62
|
|
61
|
-
|
63
|
+
NumberLiteral* NewNumberLiteral(const double& val,
|
64
|
+
std::size_t begin, std::size_t end) {
|
65
|
+
return new (static_cast<Factory*>(this)) NumberLiteral(val);
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
StringLiteral* NewStringLiteral(const std::vector<uc16>& buffer,
|
70
|
+
std::size_t begin, std::size_t end) {
|
62
71
|
return new (static_cast<Factory*>(this))
|
63
72
|
StringLiteral(buffer, static_cast<Factory*>(this));
|
64
73
|
}
|
65
74
|
|
66
|
-
Directivable* NewDirectivable(const std::vector<uc16>& buffer
|
75
|
+
Directivable* NewDirectivable(const std::vector<uc16>& buffer,
|
76
|
+
std::size_t begin, std::size_t end) {
|
67
77
|
return new (static_cast<Factory*>(this))
|
68
78
|
Directivable(buffer, static_cast<Factory*>(this));
|
69
79
|
}
|
70
80
|
|
71
81
|
RegExpLiteral* NewRegExpLiteral(const std::vector<uc16>& content,
|
72
|
-
const std::vector<uc16>& flags
|
82
|
+
const std::vector<uc16>& flags,
|
83
|
+
std::size_t begin,
|
84
|
+
std::size_t end) {
|
73
85
|
return new (static_cast<Factory*>(this))
|
74
86
|
RegExpLiteral(content, flags, static_cast<Factory*>(this));
|
75
87
|
}
|
76
88
|
|
77
|
-
FunctionLiteral* NewFunctionLiteral(typename FunctionLiteral::DeclType type
|
89
|
+
FunctionLiteral* NewFunctionLiteral(typename FunctionLiteral::DeclType type,
|
90
|
+
Identifier* name,
|
91
|
+
Identifiers* params,
|
92
|
+
Statements* body,
|
93
|
+
Scope* scope,
|
94
|
+
bool strict,
|
95
|
+
std::size_t begin_block_position,
|
96
|
+
std::size_t end_block_position,
|
97
|
+
std::size_t begin,
|
98
|
+
std::size_t end) {
|
78
99
|
return new (static_cast<Factory*>(this))
|
79
|
-
FunctionLiteral(type,
|
80
|
-
|
81
|
-
|
82
|
-
|
100
|
+
FunctionLiteral(type,
|
101
|
+
name,
|
102
|
+
params,
|
103
|
+
body,
|
104
|
+
scope,
|
105
|
+
strict,
|
106
|
+
begin_block_position,
|
107
|
+
end_block_position);
|
108
|
+
}
|
109
|
+
|
110
|
+
ArrayLiteral* NewArrayLiteral(Expressions* items,
|
111
|
+
std::size_t begin, std::size_t end) {
|
83
112
|
return new (static_cast<Factory*>(this)) ArrayLiteral(items);
|
84
113
|
}
|
85
114
|
|
86
115
|
ObjectLiteral*
|
87
|
-
NewObjectLiteral(typename ObjectLiteral::Properties* properties
|
116
|
+
NewObjectLiteral(typename ObjectLiteral::Properties* properties,
|
117
|
+
std::size_t begin,
|
118
|
+
std::size_t end) {
|
88
119
|
return new (static_cast<Factory*>(this)) ObjectLiteral(properties);
|
89
120
|
}
|
90
121
|
|
@@ -100,19 +131,17 @@ class BasicAstFactory {
|
|
100
131
|
Vector(typename Vector::allocator_type(static_cast<Factory*>(this)));
|
101
132
|
}
|
102
133
|
|
103
|
-
|
104
|
-
return
|
105
|
-
|
106
|
-
|
107
|
-
EmptyStatement* NewEmptyStatement() {
|
108
|
-
return empty_statement_instance_;
|
134
|
+
Scope* NewScope(typename FunctionLiteral::DeclType type) {
|
135
|
+
return new (static_cast<Factory*>(this))
|
136
|
+
Scope(static_cast<Factory*>(this), type == FunctionLiteral::GLOBAL);
|
109
137
|
}
|
110
138
|
|
111
|
-
|
112
|
-
|
139
|
+
NullLiteral* NewNullLiteral(std::size_t begin,
|
140
|
+
std::size_t end) {
|
141
|
+
return null_instance_;
|
113
142
|
}
|
114
143
|
|
115
|
-
ThisLiteral* NewThisLiteral() {
|
144
|
+
ThisLiteral* NewThisLiteral(std::size_t begin, std::size_t end) {
|
116
145
|
return this_instance_;
|
117
146
|
}
|
118
147
|
|
@@ -120,133 +149,184 @@ class BasicAstFactory {
|
|
120
149
|
return undefined_instance_;
|
121
150
|
}
|
122
151
|
|
123
|
-
TrueLiteral* NewTrueLiteral() {
|
152
|
+
TrueLiteral* NewTrueLiteral(std::size_t begin, std::size_t end) {
|
124
153
|
return true_instance_;
|
125
154
|
}
|
126
155
|
|
127
|
-
FalseLiteral* NewFalseLiteral() {
|
156
|
+
FalseLiteral* NewFalseLiteral(std::size_t begin, std::size_t end) {
|
128
157
|
return false_instance_;
|
129
158
|
}
|
130
159
|
|
160
|
+
EmptyStatement* NewEmptyStatement(std::size_t begin, std::size_t end) {
|
161
|
+
return empty_statement_instance_;
|
162
|
+
}
|
163
|
+
|
164
|
+
DebuggerStatement* NewDebuggerStatement(std::size_t begin, std::size_t end) {
|
165
|
+
return debugger_statement_instance_;
|
166
|
+
}
|
167
|
+
|
168
|
+
// if you want begin / end position,
|
169
|
+
// set position to FunctionLiteral in NewFunctionLiteral and use it
|
131
170
|
FunctionStatement* NewFunctionStatement(FunctionLiteral* func) {
|
132
171
|
return new (static_cast<Factory*>(this)) FunctionStatement(func);
|
133
172
|
}
|
134
173
|
|
174
|
+
// if you want begin / end position,
|
175
|
+
// set position to FunctionLiteral in NewFunctionLiteral and use it
|
135
176
|
FunctionDeclaration* NewFunctionDeclaration(FunctionLiteral* func) {
|
136
177
|
return new (static_cast<Factory*>(this)) FunctionDeclaration(func);
|
137
178
|
}
|
138
179
|
|
139
|
-
Block* NewBlock(Statements* body) {
|
180
|
+
Block* NewBlock(Statements* body, std::size_t begin, std::size_t end) {
|
140
181
|
return new (static_cast<Factory*>(this)) Block(body);
|
141
182
|
}
|
142
183
|
|
143
184
|
VariableStatement* NewVariableStatement(Token::Type token,
|
144
|
-
Declarations* decls
|
185
|
+
Declarations* decls,
|
186
|
+
std::size_t begin,
|
187
|
+
std::size_t end) {
|
145
188
|
return new (static_cast<Factory*>(this))
|
146
189
|
VariableStatement(token, decls);
|
147
190
|
}
|
148
191
|
|
192
|
+
// if you want begin / end position,
|
193
|
+
// set position to Identifier / Expression and use it
|
149
194
|
Declaration* NewDeclaration(Identifier* name, Expression* expr) {
|
150
195
|
return new (static_cast<Factory*>(this)) Declaration(name, expr);
|
151
196
|
}
|
152
197
|
|
198
|
+
// if you want end position,
|
199
|
+
// set position to Statement and use it
|
153
200
|
IfStatement* NewIfStatement(Expression* cond,
|
154
201
|
Statement* then_statement,
|
155
|
-
Statement* else_statement
|
202
|
+
Statement* else_statement,
|
203
|
+
std::size_t begin) {
|
156
204
|
return new (static_cast<Factory*>(this)) IfStatement(cond,
|
157
205
|
then_statement,
|
158
206
|
else_statement);
|
159
207
|
}
|
160
208
|
|
161
209
|
DoWhileStatement* NewDoWhileStatement(Statement* body,
|
162
|
-
Expression* cond
|
210
|
+
Expression* cond,
|
211
|
+
std::size_t begin,
|
212
|
+
std::size_t end) {
|
163
213
|
return new (static_cast<Factory*>(this)) DoWhileStatement(body, cond);
|
164
214
|
}
|
165
215
|
|
216
|
+
// if you want end position,
|
217
|
+
// set position to Statement and use it
|
166
218
|
WhileStatement* NewWhileStatement(Statement* body,
|
167
|
-
Expression* cond
|
219
|
+
Expression* cond,
|
220
|
+
std::size_t begin) {
|
168
221
|
return new (static_cast<Factory*>(this)) WhileStatement(body, cond);
|
169
222
|
}
|
170
223
|
|
224
|
+
// if you want end position,
|
225
|
+
// set position to Statement and use it
|
171
226
|
ForInStatement* NewForInStatement(Statement* body,
|
172
227
|
Statement* each,
|
173
|
-
Expression* enumerable
|
228
|
+
Expression* enumerable,
|
229
|
+
std::size_t begin) {
|
174
230
|
return new (static_cast<Factory*>(this)) ForInStatement(body,
|
175
231
|
each, enumerable);
|
176
232
|
}
|
177
233
|
|
178
|
-
|
179
|
-
|
180
|
-
}
|
181
|
-
|
234
|
+
// if you want end position,
|
235
|
+
// set position to Statement and use it
|
182
236
|
ForStatement* NewForStatement(Statement* body,
|
183
237
|
Statement* init,
|
184
238
|
Expression* cond,
|
185
|
-
Statement* next
|
239
|
+
Statement* next,
|
240
|
+
std::size_t begin) {
|
186
241
|
return new (static_cast<Factory*>(this)) ForStatement(body, init,
|
187
242
|
cond, next);
|
188
243
|
}
|
189
244
|
|
245
|
+
ExpressionStatement* NewExpressionStatement(Expression* expr, std::size_t end) {
|
246
|
+
return new (static_cast<Factory*>(this)) ExpressionStatement(expr);
|
247
|
+
}
|
248
|
+
|
190
249
|
ContinueStatement* NewContinueStatement(Identifier* label,
|
191
|
-
IterationStatement** target
|
250
|
+
IterationStatement** target,
|
251
|
+
std::size_t begin,
|
252
|
+
std::size_t end) {
|
192
253
|
return new (static_cast<Factory*>(this)) ContinueStatement(label, target);
|
193
254
|
}
|
194
255
|
|
195
256
|
BreakStatement* NewBreakStatement(Identifier* label,
|
196
|
-
BreakableStatement** target
|
257
|
+
BreakableStatement** target,
|
258
|
+
std::size_t begin,
|
259
|
+
std::size_t end) {
|
197
260
|
return new (static_cast<Factory*>(this)) BreakStatement(label, target);
|
198
261
|
}
|
199
262
|
|
200
|
-
ReturnStatement* NewReturnStatement(
|
201
|
-
|
263
|
+
ReturnStatement* NewReturnStatement(Expression* expr,
|
264
|
+
std::size_t begin,
|
265
|
+
std::size_t end) {
|
202
266
|
return new (static_cast<Factory*>(this)) ReturnStatement(expr);
|
203
267
|
}
|
204
268
|
|
205
|
-
|
206
|
-
|
269
|
+
// if you want end position,
|
270
|
+
// set position to Expression and use it
|
271
|
+
WithStatement* NewWithStatement(Expression* expr,
|
272
|
+
Statement* stmt, std::size_t begin) {
|
207
273
|
return new (static_cast<Factory*>(this)) WithStatement(expr, stmt);
|
208
274
|
}
|
209
275
|
|
210
|
-
SwitchStatement* NewSwitchStatement(Expression* expr, CaseClauses* clauses
|
276
|
+
SwitchStatement* NewSwitchStatement(Expression* expr, CaseClauses* clauses,
|
277
|
+
std::size_t begin, std::size_t end) {
|
211
278
|
return new (static_cast<Factory*>(this)) SwitchStatement(expr, clauses);
|
212
279
|
}
|
213
280
|
|
281
|
+
// !!! if body is empty, end_position is end.
|
214
282
|
CaseClause* NewCaseClause(bool is_default,
|
215
|
-
Expression* expr, Statements* body
|
283
|
+
Expression* expr, Statements* body,
|
284
|
+
std::size_t begin,
|
285
|
+
std::size_t end) {
|
216
286
|
return new (static_cast<Factory*>(this)) CaseClause(is_default, expr, body);
|
217
287
|
}
|
218
288
|
|
219
|
-
ThrowStatement* NewThrowStatement(Expression* expr
|
289
|
+
ThrowStatement* NewThrowStatement(Expression* expr,
|
290
|
+
std::size_t begin, std::size_t end) {
|
220
291
|
return new (static_cast<Factory*>(this)) ThrowStatement(expr);
|
221
292
|
}
|
222
293
|
|
294
|
+
// if you want end position,
|
295
|
+
// set position to Block and use it
|
223
296
|
TryStatement* NewTryStatement(Block* try_block,
|
224
297
|
Identifier* catch_name,
|
225
298
|
Block* catch_block,
|
226
|
-
Block* finally_block
|
299
|
+
Block* finally_block,
|
300
|
+
std::size_t begin) {
|
227
301
|
return new (static_cast<Factory*>(this)) TryStatement(try_block,
|
228
302
|
catch_name,
|
229
303
|
catch_block,
|
230
304
|
finally_block);
|
231
305
|
}
|
232
306
|
|
233
|
-
|
234
|
-
|
235
|
-
|
307
|
+
// if you want begin / end position,
|
308
|
+
// set position to Expression and use it
|
309
|
+
LabelledStatement* NewLabelledStatement(Expression* expr, Statement* stmt) {
|
236
310
|
return new (static_cast<Factory*>(this)) LabelledStatement(expr, stmt);
|
237
311
|
}
|
238
312
|
|
313
|
+
// if you want begin / end position,
|
314
|
+
// set position to Expression and use it
|
239
315
|
BinaryOperation* NewBinaryOperation(Token::Type op,
|
240
316
|
Expression* result, Expression* right) {
|
241
317
|
return new (static_cast<Factory*>(this)) BinaryOperation(op, result, right);
|
242
318
|
}
|
243
319
|
|
320
|
+
// if you want begin / end position,
|
321
|
+
// set position to Expression and use it
|
244
322
|
Assignment* NewAssignment(Token::Type op,
|
245
323
|
Expression* left,
|
246
324
|
Expression* right) {
|
247
325
|
return new (static_cast<Factory*>(this)) Assignment(op, left, right);
|
248
326
|
}
|
249
327
|
|
328
|
+
// if you want begin / end position,
|
329
|
+
// set position to Expression and use it
|
250
330
|
ConditionalExpression* NewConditionalExpression(Expression* cond,
|
251
331
|
Expression* left,
|
252
332
|
Expression* right) {
|
@@ -254,28 +334,45 @@ class BasicAstFactory {
|
|
254
334
|
ConditionalExpression(cond, left, right);
|
255
335
|
}
|
256
336
|
|
257
|
-
|
337
|
+
// if you want end position,
|
338
|
+
// set position to Expression and use it
|
339
|
+
UnaryOperation* NewUnaryOperation(Token::Type op,
|
340
|
+
Expression* expr, std::size_t begin) {
|
258
341
|
return new (static_cast<Factory*>(this)) UnaryOperation(op, expr);
|
259
342
|
}
|
260
343
|
|
261
|
-
|
262
|
-
|
344
|
+
// if you want begin position,
|
345
|
+
// set position to Expression and use it
|
346
|
+
PostfixExpression* NewPostfixExpression(Token::Type op,
|
347
|
+
Expression* expr, std::size_t end) {
|
263
348
|
return new (static_cast<Factory*>(this)) PostfixExpression(op, expr);
|
264
349
|
}
|
265
350
|
|
266
|
-
|
351
|
+
// if you want begin position,
|
352
|
+
// set position to Expression and use it
|
353
|
+
FunctionCall* NewFunctionCall(Expression* expr,
|
354
|
+
Expressions* args, std::size_t end) {
|
267
355
|
return new (static_cast<Factory*>(this)) FunctionCall(expr, args);
|
268
356
|
}
|
269
357
|
|
270
|
-
|
358
|
+
// if you want begin position,
|
359
|
+
// set position to Expression and use it
|
360
|
+
// !!! CAUTION !!!
|
361
|
+
// if not right paren (like new Array), end is 0
|
362
|
+
ConstructorCall* NewConstructorCall(Expression* target,
|
363
|
+
Expressions* args, std::size_t end) {
|
271
364
|
return new (static_cast<Factory*>(this)) ConstructorCall(target, args);
|
272
365
|
}
|
273
366
|
|
367
|
+
// if you want begin / end position,
|
368
|
+
// set position to Expression / Identifier and use it
|
274
369
|
IndexAccess* NewIndexAccess(Expression* expr,
|
275
370
|
Expression* index) {
|
276
371
|
return new (static_cast<Factory*>(this)) IndexAccess(expr, index);
|
277
372
|
}
|
278
373
|
|
374
|
+
// if you want begin / end position,
|
375
|
+
// set position to Expression / Identifier and use it
|
279
376
|
IdentifierAccess* NewIdentifierAccess(Expression* expr,
|
280
377
|
Identifier* ident) {
|
281
378
|
return new (static_cast<Factory*>(this)) IdentifierAccess(expr, ident);
|
data/ext/include/iv/ast_fwd.h
CHANGED
@@ -68,17 +68,21 @@ V(PropertyAccess)\
|
|
68
68
|
V(Call)\
|
69
69
|
EXPRESSION_DERIVED_NODE_LIST(V)
|
70
70
|
|
71
|
+
#define OTHER_DERIVED_NODE_LIST(V)\
|
72
|
+
V(Declaration)\
|
73
|
+
V(CaseClause)
|
74
|
+
|
71
75
|
#define OTHER_NODE_LIST(V)\
|
72
76
|
V(AstNode)\
|
73
|
-
V(Declaration)\
|
74
77
|
V(Scope)\
|
75
|
-
V(CaseClause)\
|
76
78
|
V(Variable)\
|
77
|
-
V(IdentifierKey)
|
79
|
+
V(IdentifierKey)\
|
80
|
+
OTHER_DERIVED_NODE_LIST(V)
|
78
81
|
|
79
82
|
#define AST_DERIVED_NODE_LIST(V)\
|
80
83
|
STATEMENT_DERIVED_NODE_LIST(V)\
|
81
|
-
EXPRESSION_DERIVED_NODE_LIST(V)
|
84
|
+
EXPRESSION_DERIVED_NODE_LIST(V)\
|
85
|
+
OTHER_DERIVED_NODE_LIST(V)
|
82
86
|
|
83
87
|
#define AST_NODE_LIST(V)\
|
84
88
|
OTHER_NODE_LIST(V)\
|
@@ -501,6 +501,15 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
501
501
|
Append("]}");
|
502
502
|
}
|
503
503
|
|
504
|
+
|
505
|
+
void Visit(const CaseClause* dummy) {
|
506
|
+
UNREACHABLE();
|
507
|
+
}
|
508
|
+
|
509
|
+
void Visit(const Declaration* dummy) {
|
510
|
+
UNREACHABLE();
|
511
|
+
}
|
512
|
+
|
504
513
|
private:
|
505
514
|
template <class Iter>
|
506
515
|
void DecodeString(Iter it, const Iter last) {
|
@@ -81,6 +81,9 @@ class BasicAstVisitor
|
|
81
81
|
virtual void Visit(typename add<IndexAccess<Factory> >::type prop) = 0; //NOLINT
|
82
82
|
virtual void Visit(typename add<FunctionCall<Factory> >::type call) = 0; //NOLINT
|
83
83
|
virtual void Visit(typename add<ConstructorCall<Factory> >::type call) = 0; //NOLINT
|
84
|
+
|
85
|
+
virtual void Visit(typename add<Declaration<Factory> >::type func) = 0; //NOLINT
|
86
|
+
virtual void Visit(typename add<CaseClause<Factory> >::type func) = 0; //NOLINT
|
84
87
|
protected:
|
85
88
|
template<typename T>
|
86
89
|
class Acceptor {
|
data/ext/include/iv/lexer.h
CHANGED
@@ -38,6 +38,7 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
38
38
|
has_line_terminator_before_next_(false),
|
39
39
|
has_shebang_(false),
|
40
40
|
line_number_(1),
|
41
|
+
previous_location_(),
|
41
42
|
location_() {
|
42
43
|
Initialize();
|
43
44
|
}
|
@@ -46,6 +47,7 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
46
47
|
typename Token::Type Next(bool strict) {
|
47
48
|
typename Token::Type token;
|
48
49
|
has_line_terminator_before_next_ = false;
|
50
|
+
StorePreviousLocation();
|
49
51
|
do {
|
50
52
|
while (Chars::IsWhiteSpace(c_)) {
|
51
53
|
// white space
|
@@ -356,7 +358,11 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
356
358
|
break;
|
357
359
|
}
|
358
360
|
} while (token == Token::NOT_FOUND);
|
359
|
-
|
361
|
+
if (c_ == -1) {
|
362
|
+
location_.set_end_position(pos());
|
363
|
+
} else {
|
364
|
+
location_.set_end_position(pos() - 1);
|
365
|
+
}
|
360
366
|
return token;
|
361
367
|
}
|
362
368
|
|
@@ -418,6 +424,14 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
418
424
|
return location_.end_position();
|
419
425
|
}
|
420
426
|
|
427
|
+
inline std::size_t previous_begin_position() const {
|
428
|
+
return previous_location_.begin_position();
|
429
|
+
}
|
430
|
+
|
431
|
+
inline std::size_t previous_end_position() const {
|
432
|
+
return previous_location_.end_position();
|
433
|
+
}
|
434
|
+
|
421
435
|
bool ScanRegExpLiteral(bool contains_eq) {
|
422
436
|
// location begin_position is the same with DIV
|
423
437
|
// so, no need to set
|
@@ -471,7 +485,11 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
471
485
|
Record16Advance();
|
472
486
|
}
|
473
487
|
}
|
474
|
-
|
488
|
+
if (c_ == -1) {
|
489
|
+
location_.set_end_position(pos());
|
490
|
+
} else {
|
491
|
+
location_.set_end_position(pos() - 1);
|
492
|
+
}
|
475
493
|
return true;
|
476
494
|
}
|
477
495
|
|
@@ -493,6 +511,10 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
493
511
|
swap(location_, Location());
|
494
512
|
}
|
495
513
|
|
514
|
+
inline void StorePreviousLocation() {
|
515
|
+
previous_location_ = location_;
|
516
|
+
}
|
517
|
+
|
496
518
|
inline void Advance() {
|
497
519
|
if (pos_ == end_) {
|
498
520
|
c_ = -1;
|
@@ -500,18 +522,28 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
500
522
|
c_ = source_->Get(pos_++);
|
501
523
|
}
|
502
524
|
}
|
525
|
+
|
503
526
|
inline void Record8() {
|
504
527
|
buffer8_.push_back(static_cast<char>(c_));
|
505
528
|
}
|
529
|
+
|
506
530
|
inline void Record8(const int ch) {
|
507
531
|
buffer8_.push_back(static_cast<char>(ch));
|
508
532
|
}
|
509
|
-
|
510
|
-
inline void Record16(
|
533
|
+
|
534
|
+
inline void Record16() {
|
535
|
+
buffer16_.push_back(c_);
|
536
|
+
}
|
537
|
+
|
538
|
+
inline void Record16(const int ch) {
|
539
|
+
buffer16_.push_back(ch);
|
540
|
+
}
|
541
|
+
|
511
542
|
inline void Record8Advance() {
|
512
543
|
Record8();
|
513
544
|
Advance();
|
514
545
|
}
|
546
|
+
|
515
547
|
inline void Record16Advance() {
|
516
548
|
Record16();
|
517
549
|
Advance();
|
@@ -879,6 +911,7 @@ class Lexer: private Noncopyable<Lexer<Source> >::type {
|
|
879
911
|
bool has_shebang_;
|
880
912
|
int c_;
|
881
913
|
std::size_t line_number_;
|
914
|
+
Location previous_location_;
|
882
915
|
Location location_;
|
883
916
|
};
|
884
917
|
|