iv-phonic 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/ext/include/iv/ast-factory.h +42 -30
- data/ext/include/iv/ast-fwd.h +22 -12
- data/ext/include/iv/ast-serializer.h +26 -32
- data/ext/include/iv/ast-visitor.h +0 -2
- data/ext/include/iv/ast.h +122 -244
- data/ext/include/iv/lexer.h +1 -1
- data/ext/include/iv/parser.h +199 -193
- data/ext/iv/phonic/creator.h +0 -8
- data/ext/iv/phonic/factory.h +45 -32
- data/ext/iv/phonic/phonic.cc +0 -47
- metadata +3 -3
data/ext/include/iv/ast.h
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
#include "ast-fwd.h"
|
13
13
|
#include "ast-visitor.h"
|
14
14
|
#include "source.h"
|
15
|
+
#include "location.h"
|
15
16
|
#include "ustringpiece.h"
|
16
17
|
|
17
18
|
namespace iv {
|
@@ -29,12 +30,25 @@ namespace ast {
|
|
29
30
|
|
30
31
|
#define DECLARE_NODE_TYPE(type) \
|
31
32
|
inline const type<Factory>* As##type() const { return this; }\
|
32
|
-
inline type<Factory>* As##type() { return this; }
|
33
|
+
inline type<Factory>* As##type() { return this; }\
|
34
|
+
|
35
|
+
#define DECLARE_DERIVED_NODE_TYPE(type) \
|
36
|
+
DECLARE_NODE_TYPE(type)\
|
37
|
+
ACCEPT_VISITOR\
|
38
|
+
inline NodeType Type() const { return k##type; }
|
33
39
|
|
34
40
|
#define DECLARE_NODE_TYPE_BASE(type) \
|
35
41
|
inline virtual const type<Factory>* As##type() const { return NULL; }\
|
36
42
|
inline virtual type<Factory>* As##type() { return NULL; }
|
37
43
|
|
44
|
+
enum NodeType {
|
45
|
+
#define V(type)\
|
46
|
+
k##type,
|
47
|
+
AST_DERIVED_NODE_LIST(V)
|
48
|
+
#undef V
|
49
|
+
kNodeCount
|
50
|
+
};
|
51
|
+
|
38
52
|
template<typename Factory>
|
39
53
|
class Scope : public SpaceObject,
|
40
54
|
private Noncopyable<Scope<Factory> >::type {
|
@@ -81,64 +95,14 @@ class AstNode : public SpaceObject,
|
|
81
95
|
public:
|
82
96
|
virtual ~AstNode() = 0;
|
83
97
|
|
84
|
-
DECLARE_NODE_TYPE_BASE
|
85
|
-
DECLARE_NODE_TYPE_BASE
|
86
|
-
DECLARE_NODE_TYPE_BASE(ExpressionStatement)
|
87
|
-
DECLARE_NODE_TYPE_BASE(EmptyStatement)
|
88
|
-
DECLARE_NODE_TYPE_BASE(VariableStatement)
|
89
|
-
DECLARE_NODE_TYPE_BASE(DebuggerStatement)
|
90
|
-
DECLARE_NODE_TYPE_BASE(FunctionStatement)
|
91
|
-
DECLARE_NODE_TYPE_BASE(IfStatement)
|
92
|
-
DECLARE_NODE_TYPE_BASE(IterationStatement)
|
93
|
-
DECLARE_NODE_TYPE_BASE(DoWhileStatement)
|
94
|
-
DECLARE_NODE_TYPE_BASE(WhileStatement)
|
95
|
-
DECLARE_NODE_TYPE_BASE(ForStatement)
|
96
|
-
DECLARE_NODE_TYPE_BASE(ForInStatement)
|
97
|
-
DECLARE_NODE_TYPE_BASE(ContinueStatement)
|
98
|
-
DECLARE_NODE_TYPE_BASE(BreakStatement)
|
99
|
-
DECLARE_NODE_TYPE_BASE(ReturnStatement)
|
100
|
-
DECLARE_NODE_TYPE_BASE(WithStatement)
|
101
|
-
DECLARE_NODE_TYPE_BASE(LabelledStatement)
|
102
|
-
DECLARE_NODE_TYPE_BASE(SwitchStatement)
|
103
|
-
DECLARE_NODE_TYPE_BASE(ThrowStatement)
|
104
|
-
DECLARE_NODE_TYPE_BASE(TryStatement)
|
105
|
-
DECLARE_NODE_TYPE_BASE(BreakableStatement)
|
106
|
-
DECLARE_NODE_TYPE_BASE(NamedOnlyBreakableStatement)
|
107
|
-
DECLARE_NODE_TYPE_BASE(AnonymousBreakableStatement)
|
108
|
-
|
109
|
-
DECLARE_NODE_TYPE_BASE(Expression)
|
110
|
-
|
111
|
-
DECLARE_NODE_TYPE_BASE(Literal)
|
112
|
-
DECLARE_NODE_TYPE_BASE(ThisLiteral)
|
113
|
-
DECLARE_NODE_TYPE_BASE(NullLiteral)
|
114
|
-
DECLARE_NODE_TYPE_BASE(FalseLiteral)
|
115
|
-
DECLARE_NODE_TYPE_BASE(TrueLiteral)
|
116
|
-
DECLARE_NODE_TYPE_BASE(Undefined)
|
117
|
-
DECLARE_NODE_TYPE_BASE(NumberLiteral)
|
118
|
-
DECLARE_NODE_TYPE_BASE(StringLiteral)
|
119
|
-
DECLARE_NODE_TYPE_BASE(Directivable)
|
120
|
-
DECLARE_NODE_TYPE_BASE(Identifier)
|
121
|
-
DECLARE_NODE_TYPE_BASE(RegExpLiteral)
|
122
|
-
DECLARE_NODE_TYPE_BASE(ArrayLiteral)
|
123
|
-
DECLARE_NODE_TYPE_BASE(ObjectLiteral)
|
124
|
-
DECLARE_NODE_TYPE_BASE(FunctionLiteral)
|
125
|
-
|
126
|
-
DECLARE_NODE_TYPE_BASE(UnaryOperation)
|
127
|
-
DECLARE_NODE_TYPE_BASE(PostfixExpression)
|
128
|
-
DECLARE_NODE_TYPE_BASE(Assignment)
|
129
|
-
DECLARE_NODE_TYPE_BASE(BinaryOperation)
|
130
|
-
DECLARE_NODE_TYPE_BASE(ConditionalExpression)
|
131
|
-
DECLARE_NODE_TYPE_BASE(PropertyAccess)
|
132
|
-
DECLARE_NODE_TYPE_BASE(IdentifierAccess)
|
133
|
-
DECLARE_NODE_TYPE_BASE(IndexAccess)
|
134
|
-
DECLARE_NODE_TYPE_BASE(Call)
|
135
|
-
DECLARE_NODE_TYPE_BASE(FunctionCall)
|
136
|
-
DECLARE_NODE_TYPE_BASE(ConstructorCall)
|
98
|
+
STATEMENT_NODE_LIST(DECLARE_NODE_TYPE_BASE)
|
99
|
+
EXPRESSION_NODE_LIST(DECLARE_NODE_TYPE_BASE)
|
137
100
|
|
138
101
|
virtual void Accept(
|
139
102
|
typename AstVisitor<Factory>::type* visitor) = 0;
|
140
103
|
virtual void Accept(
|
141
104
|
typename AstVisitor<Factory>::const_type* visitor) const = 0;
|
105
|
+
virtual NodeType Type() const = 0;
|
142
106
|
};
|
143
107
|
|
144
108
|
template<typename Factory>
|
@@ -186,17 +150,7 @@ class Statement : public AstNode<Factory> {
|
|
186
150
|
template<typename Factory>
|
187
151
|
class BreakableStatement : public Statement<Factory> {
|
188
152
|
public:
|
189
|
-
typedef typename SpaceVector<Factory, Identifier<Factory>*>::type Identifiers;
|
190
|
-
BreakableStatement() : labels_(NULL) { }
|
191
|
-
void set_labels(Identifiers* labels) {
|
192
|
-
labels_ = labels;
|
193
|
-
}
|
194
|
-
Identifiers* labels() const {
|
195
|
-
return labels_;
|
196
|
-
}
|
197
153
|
DECLARE_NODE_TYPE(BreakableStatement)
|
198
|
-
protected:
|
199
|
-
Identifiers* labels_;
|
200
154
|
};
|
201
155
|
|
202
156
|
template<typename Factory>
|
@@ -225,8 +179,7 @@ class Block : public NamedOnlyBreakableStatement<Factory> {
|
|
225
179
|
inline const Statements& body() const {
|
226
180
|
return body_;
|
227
181
|
}
|
228
|
-
|
229
|
-
DECLARE_NODE_TYPE(Block)
|
182
|
+
DECLARE_DERIVED_NODE_TYPE(Block)
|
230
183
|
private:
|
231
184
|
Statements body_;
|
232
185
|
};
|
@@ -240,8 +193,7 @@ class FunctionStatement : public Statement<Factory> {
|
|
240
193
|
inline FunctionLiteral<Factory>* function() const {
|
241
194
|
return function_;
|
242
195
|
}
|
243
|
-
|
244
|
-
DECLARE_NODE_TYPE(FunctionStatement)
|
196
|
+
DECLARE_DERIVED_NODE_TYPE(FunctionStatement)
|
245
197
|
private:
|
246
198
|
FunctionLiteral<Factory>* function_;
|
247
199
|
};
|
@@ -266,15 +218,15 @@ class VariableStatement : public Statement<Factory> {
|
|
266
218
|
inline bool IsConst() const {
|
267
219
|
return is_const_;
|
268
220
|
}
|
269
|
-
|
270
|
-
DECLARE_NODE_TYPE(VariableStatement)
|
221
|
+
DECLARE_DERIVED_NODE_TYPE(VariableStatement)
|
271
222
|
private:
|
272
223
|
const bool is_const_;
|
273
224
|
Declarations decls_;
|
274
225
|
};
|
275
226
|
|
276
227
|
template<typename Factory>
|
277
|
-
class Declaration : public
|
228
|
+
class Declaration : public SpaceObject,
|
229
|
+
private Noncopyable<Declaration<Factory> >::type {
|
278
230
|
public:
|
279
231
|
Declaration(Identifier<Factory>* name, Expression<Factory>* expr)
|
280
232
|
: name_(name),
|
@@ -286,7 +238,6 @@ class Declaration : public AstNode<Factory> {
|
|
286
238
|
inline Expression<Factory>* expr() const {
|
287
239
|
return expr_;
|
288
240
|
}
|
289
|
-
ACCEPT_VISITOR
|
290
241
|
private:
|
291
242
|
Identifier<Factory>* name_;
|
292
243
|
Expression<Factory>* expr_;
|
@@ -295,26 +246,24 @@ class Declaration : public AstNode<Factory> {
|
|
295
246
|
template<typename Factory>
|
296
247
|
class EmptyStatement : public Statement<Factory> {
|
297
248
|
public:
|
298
|
-
|
299
|
-
ACCEPT_VISITOR
|
249
|
+
DECLARE_DERIVED_NODE_TYPE(EmptyStatement)
|
300
250
|
};
|
301
251
|
|
302
252
|
template<typename Factory>
|
303
253
|
class IfStatement : public Statement<Factory> {
|
304
254
|
public:
|
305
|
-
IfStatement(Expression<Factory>* cond,
|
255
|
+
IfStatement(Expression<Factory>* cond,
|
256
|
+
Statement<Factory>* then,
|
257
|
+
Statement<Factory>* elses)
|
306
258
|
: cond_(cond),
|
307
259
|
then_(then),
|
308
|
-
else_(
|
309
|
-
|
310
|
-
void SetElse(Statement<Factory>* stmt) {
|
311
|
-
else_ = stmt;
|
260
|
+
else_(elses) {
|
261
|
+
// else maybe NULL
|
312
262
|
}
|
313
263
|
inline Expression<Factory>* cond() const { return cond_; }
|
314
264
|
inline Statement<Factory>* then_statement() const { return then_; }
|
315
265
|
inline Statement<Factory>* else_statement() const { return else_; }
|
316
|
-
|
317
|
-
DECLARE_NODE_TYPE(IfStatement)
|
266
|
+
DECLARE_DERIVED_NODE_TYPE(IfStatement)
|
318
267
|
private:
|
319
268
|
Expression<Factory>* cond_;
|
320
269
|
Statement<Factory>* then_;
|
@@ -324,13 +273,10 @@ class IfStatement : public Statement<Factory> {
|
|
324
273
|
template<typename Factory>
|
325
274
|
class IterationStatement : public AnonymousBreakableStatement<Factory> {
|
326
275
|
public:
|
327
|
-
IterationStatement()
|
328
|
-
: body_(
|
276
|
+
explicit IterationStatement(Statement<Factory>* stmt)
|
277
|
+
: body_(stmt) {
|
329
278
|
}
|
330
279
|
inline Statement<Factory>* body() const { return body_; }
|
331
|
-
inline void set_body(Statement<Factory>* stmt) {
|
332
|
-
body_ = stmt;
|
333
|
-
}
|
334
280
|
DECLARE_NODE_TYPE(IterationStatement)
|
335
281
|
private:
|
336
282
|
Statement<Factory>* body_;
|
@@ -339,16 +285,12 @@ class IterationStatement : public AnonymousBreakableStatement<Factory> {
|
|
339
285
|
template<typename Factory>
|
340
286
|
class DoWhileStatement : public IterationStatement<Factory> {
|
341
287
|
public:
|
342
|
-
DoWhileStatement()
|
343
|
-
: IterationStatement<Factory>(),
|
344
|
-
cond_(
|
288
|
+
DoWhileStatement(Statement<Factory>* body, Expression<Factory>* cond)
|
289
|
+
: IterationStatement<Factory>(body),
|
290
|
+
cond_(cond) {
|
345
291
|
}
|
346
292
|
inline Expression<Factory>* cond() const { return cond_; }
|
347
|
-
|
348
|
-
cond_ = expr;
|
349
|
-
}
|
350
|
-
ACCEPT_VISITOR
|
351
|
-
DECLARE_NODE_TYPE(DoWhileStatement)
|
293
|
+
DECLARE_DERIVED_NODE_TYPE(DoWhileStatement)
|
352
294
|
private:
|
353
295
|
Expression<Factory>* cond_;
|
354
296
|
};
|
@@ -356,13 +298,12 @@ class DoWhileStatement : public IterationStatement<Factory> {
|
|
356
298
|
template<typename Factory>
|
357
299
|
class WhileStatement : public IterationStatement<Factory> {
|
358
300
|
public:
|
359
|
-
|
360
|
-
: IterationStatement<Factory>(),
|
301
|
+
WhileStatement(Statement<Factory>* body, Expression<Factory>* cond)
|
302
|
+
: IterationStatement<Factory>(body),
|
361
303
|
cond_(cond) {
|
362
304
|
}
|
363
305
|
inline Expression<Factory>* cond() const { return cond_; }
|
364
|
-
|
365
|
-
DECLARE_NODE_TYPE(WhileStatement)
|
306
|
+
DECLARE_DERIVED_NODE_TYPE(WhileStatement)
|
366
307
|
private:
|
367
308
|
Expression<Factory>* cond_;
|
368
309
|
};
|
@@ -370,20 +311,19 @@ class WhileStatement : public IterationStatement<Factory> {
|
|
370
311
|
template<typename Factory>
|
371
312
|
class ForStatement : public IterationStatement<Factory> {
|
372
313
|
public:
|
373
|
-
ForStatement(
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
314
|
+
ForStatement(Statement<Factory>* body,
|
315
|
+
Statement<Factory>* init,
|
316
|
+
Expression<Factory>* cond,
|
317
|
+
Statement<Factory>* next)
|
318
|
+
: IterationStatement<Factory>(body),
|
319
|
+
init_(init),
|
320
|
+
cond_(cond),
|
321
|
+
next_(next) {
|
322
|
+
}
|
382
323
|
inline Statement<Factory>* init() const { return init_; }
|
383
324
|
inline Expression<Factory>* cond() const { return cond_; }
|
384
325
|
inline Statement<Factory>* next() const { return next_; }
|
385
|
-
|
386
|
-
DECLARE_NODE_TYPE(ForStatement)
|
326
|
+
DECLARE_DERIVED_NODE_TYPE(ForStatement)
|
387
327
|
private:
|
388
328
|
Statement<Factory>* init_;
|
389
329
|
Expression<Factory>* cond_;
|
@@ -393,16 +333,16 @@ class ForStatement : public IterationStatement<Factory> {
|
|
393
333
|
template<typename Factory>
|
394
334
|
class ForInStatement : public IterationStatement<Factory> {
|
395
335
|
public:
|
396
|
-
ForInStatement(Statement<Factory>*
|
336
|
+
ForInStatement(Statement<Factory>* body,
|
337
|
+
Statement<Factory>* each,
|
397
338
|
Expression<Factory>* enumerable)
|
398
|
-
: IterationStatement<Factory>(),
|
339
|
+
: IterationStatement<Factory>(body),
|
399
340
|
each_(each),
|
400
341
|
enumerable_(enumerable) {
|
401
342
|
}
|
402
343
|
inline Statement<Factory>* each() const { return each_; }
|
403
344
|
inline Expression<Factory>* enumerable() const { return enumerable_; }
|
404
|
-
|
405
|
-
DECLARE_NODE_TYPE(ForInStatement)
|
345
|
+
DECLARE_DERIVED_NODE_TYPE(ForInStatement)
|
406
346
|
private:
|
407
347
|
Statement<Factory>* each_;
|
408
348
|
Expression<Factory>* enumerable_;
|
@@ -411,48 +351,41 @@ class ForInStatement : public IterationStatement<Factory> {
|
|
411
351
|
template<typename Factory>
|
412
352
|
class ContinueStatement : public Statement<Factory> {
|
413
353
|
public:
|
414
|
-
ContinueStatement(
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
label_ = label;
|
420
|
-
}
|
421
|
-
|
422
|
-
void SetTarget(IterationStatement<Factory>* target) {
|
423
|
-
target_ = target;
|
354
|
+
ContinueStatement(Identifier<Factory>* label,
|
355
|
+
IterationStatement<Factory>** target)
|
356
|
+
: label_(label),
|
357
|
+
target_(target) {
|
358
|
+
assert(target_);
|
424
359
|
}
|
425
360
|
inline Identifier<Factory>* label() const { return label_; }
|
426
|
-
inline IterationStatement<Factory>* target() const {
|
427
|
-
|
428
|
-
|
361
|
+
inline IterationStatement<Factory>* target() const {
|
362
|
+
assert(target_ && *target_);
|
363
|
+
return *target_;
|
364
|
+
}
|
365
|
+
DECLARE_DERIVED_NODE_TYPE(ContinueStatement)
|
429
366
|
private:
|
430
367
|
Identifier<Factory>* label_;
|
431
|
-
IterationStatement<Factory
|
368
|
+
IterationStatement<Factory>** target_;
|
432
369
|
};
|
433
370
|
|
434
371
|
template<typename Factory>
|
435
372
|
class BreakStatement : public Statement<Factory> {
|
436
373
|
public:
|
437
|
-
BreakStatement(
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
void SetLabel(Identifier<Factory>* label) {
|
443
|
-
label_ = label;
|
444
|
-
}
|
445
|
-
|
446
|
-
void SetTarget(BreakableStatement<Factory>* target) {
|
447
|
-
target_ = target;
|
374
|
+
BreakStatement(Identifier<Factory>* label,
|
375
|
+
BreakableStatement<Factory>** target)
|
376
|
+
: label_(label),
|
377
|
+
target_(target) {
|
378
|
+
assert(target_);
|
448
379
|
}
|
449
380
|
inline Identifier<Factory>* label() const { return label_; }
|
450
|
-
inline BreakableStatement<Factory>* target() const {
|
451
|
-
|
452
|
-
|
381
|
+
inline BreakableStatement<Factory>* target() const {
|
382
|
+
assert(target_ && *target_);
|
383
|
+
return *target_;
|
384
|
+
}
|
385
|
+
DECLARE_DERIVED_NODE_TYPE(BreakStatement)
|
453
386
|
private:
|
454
387
|
Identifier<Factory>* label_;
|
455
|
-
BreakableStatement<Factory
|
388
|
+
BreakableStatement<Factory>** target_;
|
456
389
|
};
|
457
390
|
|
458
391
|
template<typename Factory>
|
@@ -462,8 +395,7 @@ class ReturnStatement : public Statement<Factory> {
|
|
462
395
|
: expr_(expr) {
|
463
396
|
}
|
464
397
|
inline Expression<Factory>* expr() const { return expr_; }
|
465
|
-
|
466
|
-
DECLARE_NODE_TYPE(ReturnStatement)
|
398
|
+
DECLARE_DERIVED_NODE_TYPE(ReturnStatement)
|
467
399
|
private:
|
468
400
|
Expression<Factory>* expr_;
|
469
401
|
};
|
@@ -478,8 +410,7 @@ class WithStatement : public Statement<Factory> {
|
|
478
410
|
}
|
479
411
|
inline Expression<Factory>* context() const { return context_; }
|
480
412
|
inline Statement<Factory>* body() const { return body_; }
|
481
|
-
|
482
|
-
DECLARE_NODE_TYPE(WithStatement)
|
413
|
+
DECLARE_DERIVED_NODE_TYPE(WithStatement)
|
483
414
|
private:
|
484
415
|
Expression<Factory>* context_;
|
485
416
|
Statement<Factory>* body_;
|
@@ -494,31 +425,23 @@ class LabelledStatement : public Statement<Factory> {
|
|
494
425
|
}
|
495
426
|
inline Identifier<Factory>* label() const { return label_; }
|
496
427
|
inline Statement<Factory>* body() const { return body_; }
|
497
|
-
|
498
|
-
DECLARE_NODE_TYPE(LabelledStatement)
|
428
|
+
DECLARE_DERIVED_NODE_TYPE(LabelledStatement)
|
499
429
|
private:
|
500
430
|
Identifier<Factory>* label_;
|
501
431
|
Statement<Factory>* body_;
|
502
432
|
};
|
503
433
|
|
504
434
|
template<typename Factory>
|
505
|
-
class CaseClause : public
|
435
|
+
class CaseClause : public SpaceObject,
|
436
|
+
private Noncopyable<CaseClause<Factory> >::type {
|
506
437
|
public:
|
507
438
|
typedef typename SpaceVector<Factory, Statement<Factory>*>::type Statements;
|
508
|
-
explicit CaseClause(
|
509
|
-
|
439
|
+
explicit CaseClause(bool is_default,
|
440
|
+
Expression<Factory>* expr, Factory* factory)
|
441
|
+
: expr_(expr),
|
510
442
|
body_(typename Statements::allocator_type(factory)),
|
511
|
-
default_(
|
512
|
-
}
|
513
|
-
|
514
|
-
void SetExpression(Expression<Factory>* expr) {
|
515
|
-
expr_ = expr;
|
516
|
-
}
|
517
|
-
|
518
|
-
void SetDefault() {
|
519
|
-
default_ = true;
|
443
|
+
default_(is_default) {
|
520
444
|
}
|
521
|
-
|
522
445
|
void AddStatement(Statement<Factory>* stmt) {
|
523
446
|
body_.push_back(stmt);
|
524
447
|
}
|
@@ -531,7 +454,6 @@ class CaseClause : public AstNode<Factory> {
|
|
531
454
|
inline const Statements& body() const {
|
532
455
|
return body_;
|
533
456
|
}
|
534
|
-
ACCEPT_VISITOR
|
535
457
|
private:
|
536
458
|
Expression<Factory>* expr_;
|
537
459
|
Statements body_;
|
@@ -553,8 +475,7 @@ class SwitchStatement : public AnonymousBreakableStatement<Factory> {
|
|
553
475
|
}
|
554
476
|
inline Expression<Factory>* expr() const { return expr_; }
|
555
477
|
inline const CaseClauses& clauses() const { return clauses_; }
|
556
|
-
|
557
|
-
DECLARE_NODE_TYPE(SwitchStatement)
|
478
|
+
DECLARE_DERIVED_NODE_TYPE(SwitchStatement)
|
558
479
|
private:
|
559
480
|
Expression<Factory>* expr_;
|
560
481
|
CaseClauses clauses_;
|
@@ -567,8 +488,7 @@ class ThrowStatement : public Statement<Factory> {
|
|
567
488
|
: expr_(expr) {
|
568
489
|
}
|
569
490
|
inline Expression<Factory>* expr() const { return expr_; }
|
570
|
-
|
571
|
-
DECLARE_NODE_TYPE(ThrowStatement)
|
491
|
+
DECLARE_DERIVED_NODE_TYPE(ThrowStatement)
|
572
492
|
private:
|
573
493
|
Expression<Factory>* expr_;
|
574
494
|
};
|
@@ -576,27 +496,20 @@ class ThrowStatement : public Statement<Factory> {
|
|
576
496
|
template<typename Factory>
|
577
497
|
class TryStatement : public Statement<Factory> {
|
578
498
|
public:
|
579
|
-
explicit TryStatement(Block<Factory>*
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
catch_name_ = name;
|
588
|
-
catch_block_ = block;
|
589
|
-
}
|
590
|
-
|
591
|
-
void SetFinally(Block<Factory>* block) {
|
592
|
-
finally_block_ = block;
|
499
|
+
explicit TryStatement(Block<Factory>* try_block,
|
500
|
+
Identifier<Factory>* catch_name,
|
501
|
+
Block<Factory>* catch_block,
|
502
|
+
Block<Factory>* finally_block)
|
503
|
+
: body_(try_block),
|
504
|
+
catch_name_(catch_name),
|
505
|
+
catch_block_(catch_block),
|
506
|
+
finally_block_(finally_block) {
|
593
507
|
}
|
594
508
|
inline Block<Factory>* body() const { return body_; }
|
595
509
|
inline Identifier<Factory>* catch_name() const { return catch_name_; }
|
596
510
|
inline Block<Factory>* catch_block() const { return catch_block_; }
|
597
511
|
inline Block<Factory>* finally_block() const { return finally_block_; }
|
598
|
-
|
599
|
-
DECLARE_NODE_TYPE(TryStatement)
|
512
|
+
DECLARE_DERIVED_NODE_TYPE(TryStatement)
|
600
513
|
private:
|
601
514
|
Block<Factory>* body_;
|
602
515
|
Identifier<Factory>* catch_name_;
|
@@ -606,8 +519,7 @@ class TryStatement : public Statement<Factory> {
|
|
606
519
|
|
607
520
|
template<typename Factory>
|
608
521
|
class DebuggerStatement : public Statement<Factory> {
|
609
|
-
|
610
|
-
DECLARE_NODE_TYPE(DebuggerStatement)
|
522
|
+
DECLARE_DERIVED_NODE_TYPE(DebuggerStatement)
|
611
523
|
};
|
612
524
|
|
613
525
|
template<typename Factory>
|
@@ -615,8 +527,7 @@ class ExpressionStatement : public Statement<Factory> {
|
|
615
527
|
public:
|
616
528
|
explicit ExpressionStatement(Expression<Factory>* expr) : expr_(expr) { }
|
617
529
|
inline Expression<Factory>* expr() const { return expr_; }
|
618
|
-
|
619
|
-
DECLARE_NODE_TYPE(ExpressionStatement)
|
530
|
+
DECLARE_DERIVED_NODE_TYPE(ExpressionStatement)
|
620
531
|
private:
|
621
532
|
Expression<Factory>* expr_;
|
622
533
|
};
|
@@ -633,8 +544,7 @@ class Assignment : public Expression<Factory> {
|
|
633
544
|
inline Token::Type op() const { return op_; }
|
634
545
|
inline Expression<Factory>* left() const { return left_; }
|
635
546
|
inline Expression<Factory>* right() const { return right_; }
|
636
|
-
|
637
|
-
DECLARE_NODE_TYPE(Assignment)
|
547
|
+
DECLARE_DERIVED_NODE_TYPE(Assignment)
|
638
548
|
private:
|
639
549
|
Token::Type op_;
|
640
550
|
Expression<Factory>* left_;
|
@@ -653,8 +563,7 @@ class BinaryOperation : public Expression<Factory> {
|
|
653
563
|
inline Token::Type op() const { return op_; }
|
654
564
|
inline Expression<Factory>* left() const { return left_; }
|
655
565
|
inline Expression<Factory>* right() const { return right_; }
|
656
|
-
|
657
|
-
DECLARE_NODE_TYPE(BinaryOperation)
|
566
|
+
DECLARE_DERIVED_NODE_TYPE(BinaryOperation)
|
658
567
|
private:
|
659
568
|
Token::Type op_;
|
660
569
|
Expression<Factory>* left_;
|
@@ -672,8 +581,7 @@ class ConditionalExpression : public Expression<Factory> {
|
|
672
581
|
inline Expression<Factory>* cond() const { return cond_; }
|
673
582
|
inline Expression<Factory>* left() const { return left_; }
|
674
583
|
inline Expression<Factory>* right() const { return right_; }
|
675
|
-
|
676
|
-
DECLARE_NODE_TYPE(ConditionalExpression)
|
584
|
+
DECLARE_DERIVED_NODE_TYPE(ConditionalExpression)
|
677
585
|
private:
|
678
586
|
Expression<Factory>* cond_;
|
679
587
|
Expression<Factory>* left_;
|
@@ -689,8 +597,7 @@ class UnaryOperation : public Expression<Factory> {
|
|
689
597
|
}
|
690
598
|
inline Token::Type op() const { return op_; }
|
691
599
|
inline Expression<Factory>* expr() const { return expr_; }
|
692
|
-
|
693
|
-
DECLARE_NODE_TYPE(UnaryOperation)
|
600
|
+
DECLARE_DERIVED_NODE_TYPE(UnaryOperation)
|
694
601
|
private:
|
695
602
|
Token::Type op_;
|
696
603
|
Expression<Factory>* expr_;
|
@@ -705,8 +612,7 @@ class PostfixExpression : public Expression<Factory> {
|
|
705
612
|
}
|
706
613
|
inline Token::Type op() const { return op_; }
|
707
614
|
inline Expression<Factory>* expr() const { return expr_; }
|
708
|
-
|
709
|
-
DECLARE_NODE_TYPE(PostfixExpression)
|
615
|
+
DECLARE_DERIVED_NODE_TYPE(PostfixExpression)
|
710
616
|
private:
|
711
617
|
Token::Type op_;
|
712
618
|
Expression<Factory>* expr_;
|
@@ -726,8 +632,7 @@ class StringLiteral : public Literal<Factory> {
|
|
726
632
|
inline const value_type& value() const {
|
727
633
|
return value_;
|
728
634
|
}
|
729
|
-
|
730
|
-
DECLARE_NODE_TYPE(StringLiteral)
|
635
|
+
DECLARE_DERIVED_NODE_TYPE(StringLiteral)
|
731
636
|
private:
|
732
637
|
const value_type value_;
|
733
638
|
};
|
@@ -748,8 +653,7 @@ class NumberLiteral : public Literal<Factory> {
|
|
748
653
|
: value_(val) {
|
749
654
|
}
|
750
655
|
inline double value() const { return value_; }
|
751
|
-
|
752
|
-
DECLARE_NODE_TYPE(NumberLiteral)
|
656
|
+
DECLARE_DERIVED_NODE_TYPE(NumberLiteral)
|
753
657
|
private:
|
754
658
|
double value_;
|
755
659
|
};
|
@@ -758,27 +662,17 @@ template<typename Factory>
|
|
758
662
|
class Identifier : public Literal<Factory> {
|
759
663
|
public:
|
760
664
|
typedef typename SpaceUString<Factory>::type value_type;
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
}
|
766
|
-
Identifier(const std::vector<uc16>& buffer, Factory* factory)
|
767
|
-
: value_(buffer.data(),
|
768
|
-
buffer.size(),
|
769
|
-
typename value_type::allocator_type(factory)) {
|
770
|
-
}
|
771
|
-
Identifier(const std::vector<char>& buffer, Factory* factory)
|
772
|
-
: value_(buffer.begin(),
|
773
|
-
buffer.end(),
|
665
|
+
template<typename Range>
|
666
|
+
Identifier(const Range& range, Factory* factory)
|
667
|
+
: value_(range.begin(),
|
668
|
+
range.end(),
|
774
669
|
typename value_type::allocator_type(factory)) {
|
775
670
|
}
|
776
671
|
inline const value_type& value() const {
|
777
672
|
return value_;
|
778
673
|
}
|
779
674
|
inline bool IsValidLeftHandSide() const { return true; }
|
780
|
-
|
781
|
-
DECLARE_NODE_TYPE(Identifier)
|
675
|
+
DECLARE_DERIVED_NODE_TYPE(Identifier)
|
782
676
|
protected:
|
783
677
|
value_type value_;
|
784
678
|
};
|
@@ -821,36 +715,31 @@ class IdentifierKey {
|
|
821
715
|
template<typename Factory>
|
822
716
|
class ThisLiteral : public Literal<Factory> {
|
823
717
|
public:
|
824
|
-
|
825
|
-
DECLARE_NODE_TYPE(ThisLiteral)
|
718
|
+
DECLARE_DERIVED_NODE_TYPE(ThisLiteral)
|
826
719
|
};
|
827
720
|
|
828
721
|
template<typename Factory>
|
829
722
|
class NullLiteral : public Literal<Factory> {
|
830
723
|
public:
|
831
|
-
|
832
|
-
DECLARE_NODE_TYPE(NullLiteral)
|
724
|
+
DECLARE_DERIVED_NODE_TYPE(NullLiteral)
|
833
725
|
};
|
834
726
|
|
835
727
|
template<typename Factory>
|
836
728
|
class TrueLiteral : public Literal<Factory> {
|
837
729
|
public:
|
838
|
-
|
839
|
-
DECLARE_NODE_TYPE(TrueLiteral)
|
730
|
+
DECLARE_DERIVED_NODE_TYPE(TrueLiteral)
|
840
731
|
};
|
841
732
|
|
842
733
|
template<typename Factory>
|
843
734
|
class FalseLiteral : public Literal<Factory> {
|
844
735
|
public:
|
845
|
-
|
846
|
-
DECLARE_NODE_TYPE(FalseLiteral)
|
736
|
+
DECLARE_DERIVED_NODE_TYPE(FalseLiteral)
|
847
737
|
};
|
848
738
|
|
849
739
|
template<typename Factory>
|
850
740
|
class Undefined : public Literal<Factory> {
|
851
741
|
public:
|
852
|
-
|
853
|
-
DECLARE_NODE_TYPE(Undefined)
|
742
|
+
DECLARE_DERIVED_NODE_TYPE(Undefined)
|
854
743
|
};
|
855
744
|
|
856
745
|
template<typename Factory>
|
@@ -868,8 +757,7 @@ class RegExpLiteral : public Literal<Factory> {
|
|
868
757
|
}
|
869
758
|
inline const value_type& value() const { return value_; }
|
870
759
|
inline const value_type& flags() const { return flags_; }
|
871
|
-
|
872
|
-
DECLARE_NODE_TYPE(RegExpLiteral)
|
760
|
+
DECLARE_DERIVED_NODE_TYPE(RegExpLiteral)
|
873
761
|
protected:
|
874
762
|
value_type value_;
|
875
763
|
value_type flags_;
|
@@ -889,8 +777,7 @@ class ArrayLiteral : public Literal<Factory> {
|
|
889
777
|
inline const Expressions& items() const {
|
890
778
|
return items_;
|
891
779
|
}
|
892
|
-
|
893
|
-
DECLARE_NODE_TYPE(ArrayLiteral)
|
780
|
+
DECLARE_DERIVED_NODE_TYPE(ArrayLiteral)
|
894
781
|
private:
|
895
782
|
Expressions items_;
|
896
783
|
};
|
@@ -923,8 +810,7 @@ class ObjectLiteral : public Literal<Factory> {
|
|
923
810
|
inline const Properties& properties() const {
|
924
811
|
return properties_;
|
925
812
|
}
|
926
|
-
|
927
|
-
DECLARE_NODE_TYPE(ObjectLiteral)
|
813
|
+
DECLARE_DERIVED_NODE_TYPE(ObjectLiteral)
|
928
814
|
private:
|
929
815
|
inline void AddPropertyDescriptor(PropertyDescriptorType type,
|
930
816
|
Identifier<Factory>* key,
|
@@ -1008,8 +894,7 @@ class FunctionLiteral : public Literal<Factory> {
|
|
1008
894
|
void AddStatement(Statement<Factory>* stmt) {
|
1009
895
|
body_.push_back(stmt);
|
1010
896
|
}
|
1011
|
-
|
1012
|
-
DECLARE_NODE_TYPE(FunctionLiteral)
|
897
|
+
DECLARE_DERIVED_NODE_TYPE(FunctionLiteral)
|
1013
898
|
private:
|
1014
899
|
Identifier<Factory>* name_;
|
1015
900
|
DeclType type_;
|
@@ -1044,8 +929,7 @@ class IdentifierAccess : public PropertyAccess<Factory> {
|
|
1044
929
|
key_(key) {
|
1045
930
|
}
|
1046
931
|
inline Identifier<Factory>* key() const { return key_; }
|
1047
|
-
|
1048
|
-
DECLARE_NODE_TYPE(IdentifierAccess)
|
932
|
+
DECLARE_DERIVED_NODE_TYPE(IdentifierAccess)
|
1049
933
|
private:
|
1050
934
|
Identifier<Factory>* key_;
|
1051
935
|
};
|
@@ -1059,8 +943,7 @@ class IndexAccess : public PropertyAccess<Factory> {
|
|
1059
943
|
key_(key) {
|
1060
944
|
}
|
1061
945
|
inline Expression<Factory>* key() const { return key_; }
|
1062
|
-
|
1063
|
-
ACCEPT_VISITOR
|
946
|
+
DECLARE_DERIVED_NODE_TYPE(IndexAccess)
|
1064
947
|
private:
|
1065
948
|
Expression<Factory>* key_;
|
1066
949
|
};
|
@@ -1091,8 +974,7 @@ class FunctionCall : public Call<Factory> {
|
|
1091
974
|
Factory* factory)
|
1092
975
|
: Call<Factory>(target, factory) {
|
1093
976
|
}
|
1094
|
-
|
1095
|
-
DECLARE_NODE_TYPE(FunctionCall)
|
977
|
+
DECLARE_DERIVED_NODE_TYPE(FunctionCall)
|
1096
978
|
};
|
1097
979
|
|
1098
980
|
template<typename Factory>
|
@@ -1102,8 +984,7 @@ class ConstructorCall : public Call<Factory> {
|
|
1102
984
|
Factory* factory)
|
1103
985
|
: Call<Factory>(target, factory) {
|
1104
986
|
}
|
1105
|
-
|
1106
|
-
DECLARE_NODE_TYPE(ConstructorCall)
|
987
|
+
DECLARE_DERIVED_NODE_TYPE(ConstructorCall)
|
1107
988
|
};
|
1108
989
|
|
1109
990
|
} } } // namespace iv::core::ast
|
@@ -1121,7 +1002,4 @@ struct hash<iv::core::ast::IdentifierKey<Factory> >
|
|
1121
1002
|
}
|
1122
1003
|
};
|
1123
1004
|
} } // namespace std::tr1
|
1124
|
-
#undef ACCEPT_VISITOR
|
1125
|
-
#undef DECLARE_NODE_TYPE
|
1126
|
-
#undef DECLARE_NODE_TYPE_BASE
|
1127
1005
|
#endif // _IV_AST_H_
|