iv-phonic 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/ext/include/iv/ast.h +53 -62
- data/ext/include/iv/ast_factory.h +16 -23
- data/ext/include/iv/ast_fwd.h +6 -6
- data/ext/include/iv/ast_info.h +1 -1
- data/ext/include/iv/ast_serializer.h +35 -36
- data/ext/include/iv/ast_visitor.h +0 -1
- data/ext/include/iv/maybe.h +72 -0
- data/ext/include/iv/parser.h +64 -9
- data/ext/iv/phonic/ast_fwd.h +1 -1
- data/ext/iv/phonic/creator.h +53 -32
- data/ext/iv/phonic/factory.h +20 -30
- metadata +3 -2
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
data/ext/include/iv/ast.h
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
#include "noncopyable.h"
|
9
9
|
#include "utils.h"
|
10
10
|
#include "space.h"
|
11
|
+
#include "maybe.h"
|
11
12
|
#include "functor.h"
|
12
13
|
#include "token.h"
|
13
14
|
#include "ast_fwd.h"
|
@@ -120,6 +121,11 @@ class AstNode : public AstNodeBase<Factory> {
|
|
120
121
|
typedef typename SpaceVector<Factory, Statement<Factory>*>::type Statements;
|
121
122
|
typedef typename SpaceVector<Factory, Identifier<Factory>*>::type Identifiers;
|
122
123
|
typedef typename SpaceVector<Factory, Expression<Factory>*>::type Expressions;
|
124
|
+
typedef typename SpaceVector<Factory,
|
125
|
+
Maybe<Expression<Factory> > >::type MaybeExpressions;
|
126
|
+
typedef typename SpaceVector<Factory,
|
127
|
+
Declaration<Factory>*>::type Declarations;
|
128
|
+
typedef typename SpaceVector<Factory, CaseClause<Factory>*>::type CaseClauses;
|
123
129
|
|
124
130
|
STATEMENT_NODE_LIST(DECLARE_NODE_TYPE_BASE)
|
125
131
|
EXPRESSION_NODE_LIST(DECLARE_NODE_TYPE_BASE)
|
@@ -308,9 +314,7 @@ INHERIT(VariableStatement);
|
|
308
314
|
template<typename Factory>
|
309
315
|
class VariableStatement : public VariableStatementBase<Factory> {
|
310
316
|
public:
|
311
|
-
typedef typename
|
312
|
-
Factory,
|
313
|
-
Declaration<Factory>*>::type Declarations;
|
317
|
+
typedef typename AstNode<Factory>::Declarations Declarations;
|
314
318
|
VariableStatement(Token::Type type, Declarations* decls)
|
315
319
|
: is_const_(type == Token::CONST),
|
316
320
|
decls_(decls) { }
|
@@ -336,20 +340,21 @@ INHERIT(Declaration);
|
|
336
340
|
template<typename Factory>
|
337
341
|
class Declaration : public DeclarationBase<Factory> {
|
338
342
|
public:
|
339
|
-
Declaration(Identifier<Factory>* name,
|
343
|
+
Declaration(Identifier<Factory>* name,
|
344
|
+
Maybe<Expression<Factory> > expr)
|
340
345
|
: name_(name),
|
341
346
|
expr_(expr) {
|
342
347
|
}
|
343
348
|
inline Identifier<Factory>* name() const {
|
344
349
|
return name_;
|
345
350
|
}
|
346
|
-
inline Expression<Factory
|
351
|
+
inline Maybe<Expression<Factory> > expr() const {
|
347
352
|
return expr_;
|
348
353
|
}
|
349
354
|
DECLARE_DERIVED_NODE_TYPE(Declaration)
|
350
355
|
private:
|
351
356
|
Identifier<Factory>* name_;
|
352
|
-
Expression<Factory
|
357
|
+
Maybe<Expression<Factory> > expr_;
|
353
358
|
};
|
354
359
|
|
355
360
|
// EmptyStatement
|
@@ -377,20 +382,19 @@ class IfStatement : public IfStatementBase<Factory> {
|
|
377
382
|
public:
|
378
383
|
IfStatement(Expression<Factory>* cond,
|
379
384
|
Statement<Factory>* then,
|
380
|
-
Statement<Factory
|
385
|
+
Maybe<Statement<Factory> > elses)
|
381
386
|
: cond_(cond),
|
382
387
|
then_(then),
|
383
388
|
else_(elses) {
|
384
|
-
// else maybe NULL
|
385
389
|
}
|
386
390
|
inline Expression<Factory>* cond() const { return cond_; }
|
387
391
|
inline Statement<Factory>* then_statement() const { return then_; }
|
388
|
-
inline Statement<Factory
|
392
|
+
inline Maybe<Statement<Factory> > else_statement() const { return else_; }
|
389
393
|
DECLARE_DERIVED_NODE_TYPE(IfStatement)
|
390
394
|
private:
|
391
395
|
Expression<Factory>* cond_;
|
392
396
|
Statement<Factory>* then_;
|
393
|
-
Statement<Factory
|
397
|
+
Maybe<Statement<Factory> > else_;
|
394
398
|
};
|
395
399
|
|
396
400
|
// IterationStatement
|
@@ -461,24 +465,24 @@ template<typename Factory>
|
|
461
465
|
class ForStatement : public ForStatementBase<Factory> {
|
462
466
|
public:
|
463
467
|
ForStatement(Statement<Factory>* body,
|
464
|
-
Statement<Factory
|
465
|
-
Expression<Factory
|
466
|
-
Statement<Factory
|
468
|
+
Maybe<Statement<Factory> > init,
|
469
|
+
Maybe<Expression<Factory> > cond,
|
470
|
+
Maybe<Statement<Factory> > next)
|
467
471
|
: body_(body),
|
468
472
|
init_(init),
|
469
473
|
cond_(cond),
|
470
474
|
next_(next) {
|
471
475
|
}
|
472
476
|
inline Statement<Factory>* body() const { return body_; }
|
473
|
-
inline Statement<Factory
|
474
|
-
inline Expression<Factory
|
475
|
-
inline Statement<Factory
|
477
|
+
inline Maybe<Statement<Factory> > init() const { return init_; }
|
478
|
+
inline Maybe<Expression<Factory> > cond() const { return cond_; }
|
479
|
+
inline Maybe<Statement<Factory> > next() const { return next_; }
|
476
480
|
DECLARE_DERIVED_NODE_TYPE(ForStatement)
|
477
481
|
private:
|
478
482
|
Statement<Factory>* body_;
|
479
|
-
Statement<Factory
|
480
|
-
Expression<Factory
|
481
|
-
Statement<Factory
|
483
|
+
Maybe<Statement<Factory> > init_;
|
484
|
+
Maybe<Expression<Factory> > cond_;
|
485
|
+
Maybe<Statement<Factory> > next_;
|
482
486
|
};
|
483
487
|
|
484
488
|
// ForInStatement
|
@@ -518,20 +522,20 @@ INHERIT(ContinueStatement);
|
|
518
522
|
template<typename Factory>
|
519
523
|
class ContinueStatement : public ContinueStatementBase<Factory> {
|
520
524
|
public:
|
521
|
-
ContinueStatement(Identifier<Factory
|
525
|
+
ContinueStatement(Maybe<Identifier<Factory> > label,
|
522
526
|
IterationStatement<Factory>** target)
|
523
527
|
: label_(label),
|
524
528
|
target_(target) {
|
525
529
|
assert(target_);
|
526
530
|
}
|
527
|
-
inline Identifier<Factory
|
531
|
+
inline Maybe<Identifier<Factory> > label() const { return label_; }
|
528
532
|
inline IterationStatement<Factory>* target() const {
|
529
533
|
assert(target_ && *target_);
|
530
534
|
return *target_;
|
531
535
|
}
|
532
536
|
DECLARE_DERIVED_NODE_TYPE(ContinueStatement)
|
533
537
|
private:
|
534
|
-
Identifier<Factory
|
538
|
+
Maybe<Identifier<Factory> > label_;
|
535
539
|
IterationStatement<Factory>** target_;
|
536
540
|
};
|
537
541
|
|
@@ -545,7 +549,7 @@ INHERIT(BreakStatement);
|
|
545
549
|
template<typename Factory>
|
546
550
|
class BreakStatement : public BreakStatementBase<Factory> {
|
547
551
|
public:
|
548
|
-
BreakStatement(Identifier<Factory
|
552
|
+
BreakStatement(Maybe<Identifier<Factory> > label,
|
549
553
|
BreakableStatement<Factory>** target)
|
550
554
|
: label_(label),
|
551
555
|
target_(target) {
|
@@ -556,7 +560,7 @@ class BreakStatement : public BreakStatementBase<Factory> {
|
|
556
560
|
// if above example, target is NULL
|
557
561
|
assert(target_ || label_);
|
558
562
|
}
|
559
|
-
inline Identifier<Factory
|
563
|
+
inline Maybe<Identifier<Factory> > label() const { return label_; }
|
560
564
|
inline BreakableStatement<Factory>* target() const {
|
561
565
|
if (target_) {
|
562
566
|
assert(*target_);
|
@@ -567,7 +571,7 @@ class BreakStatement : public BreakStatementBase<Factory> {
|
|
567
571
|
}
|
568
572
|
DECLARE_DERIVED_NODE_TYPE(BreakStatement)
|
569
573
|
private:
|
570
|
-
Identifier<Factory
|
574
|
+
Maybe<Identifier<Factory> > label_;
|
571
575
|
BreakableStatement<Factory>** target_;
|
572
576
|
};
|
573
577
|
|
@@ -581,13 +585,13 @@ INHERIT(ReturnStatement);
|
|
581
585
|
template<typename Factory>
|
582
586
|
class ReturnStatement : public ReturnStatementBase<Factory> {
|
583
587
|
public:
|
584
|
-
explicit ReturnStatement(Expression<Factory
|
588
|
+
explicit ReturnStatement(Maybe<Expression<Factory> > expr)
|
585
589
|
: expr_(expr) {
|
586
590
|
}
|
587
|
-
inline Expression<Factory
|
591
|
+
inline Maybe<Expression<Factory> > expr() const { return expr_; }
|
588
592
|
DECLARE_DERIVED_NODE_TYPE(ReturnStatement)
|
589
593
|
private:
|
590
|
-
Expression<Factory
|
594
|
+
Maybe<Expression<Factory> > expr_;
|
591
595
|
};
|
592
596
|
|
593
597
|
// WithStatement
|
@@ -646,16 +650,16 @@ class CaseClause : public CaseClauseBase<Factory> {
|
|
646
650
|
public:
|
647
651
|
typedef typename AstNode<Factory>::Statements Statements;
|
648
652
|
explicit CaseClause(bool is_default,
|
649
|
-
Expression<Factory
|
653
|
+
Maybe<Expression<Factory> > expr,
|
650
654
|
Statements* body)
|
651
655
|
: expr_(expr),
|
652
656
|
body_(body),
|
653
657
|
default_(is_default) {
|
654
658
|
}
|
655
659
|
inline bool IsDefault() const {
|
656
|
-
return
|
660
|
+
return !expr_;
|
657
661
|
}
|
658
|
-
inline Expression<Factory
|
662
|
+
inline Maybe<Expression<Factory> > expr() const {
|
659
663
|
return expr_;
|
660
664
|
}
|
661
665
|
inline const Statements& body() const {
|
@@ -663,7 +667,7 @@ class CaseClause : public CaseClauseBase<Factory> {
|
|
663
667
|
}
|
664
668
|
DECLARE_DERIVED_NODE_TYPE(CaseClause)
|
665
669
|
private:
|
666
|
-
Expression<Factory
|
670
|
+
Maybe<Expression<Factory> > expr_;
|
667
671
|
Statements* body_;
|
668
672
|
bool default_;
|
669
673
|
};
|
@@ -678,7 +682,7 @@ INHERIT(SwitchStatement);
|
|
678
682
|
template<typename Factory>
|
679
683
|
class SwitchStatement : public SwitchStatementBase<Factory> {
|
680
684
|
public:
|
681
|
-
typedef typename
|
685
|
+
typedef typename AstNode<Factory>::CaseClauses CaseClauses;
|
682
686
|
SwitchStatement(Expression<Factory>* expr,
|
683
687
|
CaseClauses* clauses)
|
684
688
|
: expr_(expr),
|
@@ -722,24 +726,24 @@ template<typename Factory>
|
|
722
726
|
class TryStatement : public TryStatementBase<Factory> {
|
723
727
|
public:
|
724
728
|
explicit TryStatement(Block<Factory>* try_block,
|
725
|
-
Identifier<Factory
|
726
|
-
Block<Factory
|
727
|
-
Block<Factory
|
729
|
+
Maybe<Identifier<Factory> > catch_name,
|
730
|
+
Maybe<Block<Factory> > catch_block,
|
731
|
+
Maybe<Block<Factory> > finally_block)
|
728
732
|
: body_(try_block),
|
729
733
|
catch_name_(catch_name),
|
730
734
|
catch_block_(catch_block),
|
731
735
|
finally_block_(finally_block) {
|
732
736
|
}
|
733
737
|
inline Block<Factory>* body() const { return body_; }
|
734
|
-
inline Identifier<Factory
|
735
|
-
inline Block<Factory
|
736
|
-
inline Block<Factory
|
738
|
+
inline Maybe<Identifier<Factory> > catch_name() const { return catch_name_; }
|
739
|
+
inline Maybe<Block<Factory> > catch_block() const { return catch_block_; }
|
740
|
+
inline Maybe<Block<Factory> > finally_block() const { return finally_block_; }
|
737
741
|
DECLARE_DERIVED_NODE_TYPE(TryStatement)
|
738
742
|
private:
|
739
743
|
Block<Factory>* body_;
|
740
|
-
Identifier<Factory
|
741
|
-
Block<Factory
|
742
|
-
Block<Factory
|
744
|
+
Maybe<Identifier<Factory> > catch_name_;
|
745
|
+
Maybe<Block<Factory> > catch_block_;
|
746
|
+
Maybe<Block<Factory> > finally_block_;
|
743
747
|
};
|
744
748
|
|
745
749
|
// DebuggerStatement
|
@@ -1074,19 +1078,6 @@ class FalseLiteral : public FalseLiteralBase<Factory> {
|
|
1074
1078
|
DECLARE_DERIVED_NODE_TYPE(FalseLiteral)
|
1075
1079
|
};
|
1076
1080
|
|
1077
|
-
// Undefined
|
1078
|
-
template<typename Factory>
|
1079
|
-
class Inherit<Factory, kUndefined>
|
1080
|
-
: public Literal<Factory> {
|
1081
|
-
};
|
1082
|
-
INHERIT(Undefined);
|
1083
|
-
|
1084
|
-
template<typename Factory>
|
1085
|
-
class Undefined : public UndefinedBase<Factory> {
|
1086
|
-
public:
|
1087
|
-
DECLARE_DERIVED_NODE_TYPE(Undefined)
|
1088
|
-
};
|
1089
|
-
|
1090
1081
|
// RegExpLiteral
|
1091
1082
|
template<typename Factory>
|
1092
1083
|
class Inherit<Factory, kRegExpLiteral>
|
@@ -1127,17 +1118,17 @@ INHERIT(ArrayLiteral);
|
|
1127
1118
|
template<typename Factory>
|
1128
1119
|
class ArrayLiteral : public ArrayLiteralBase<Factory> {
|
1129
1120
|
public:
|
1130
|
-
typedef typename AstNode<Factory>::
|
1121
|
+
typedef typename AstNode<Factory>::MaybeExpressions MaybeExpressions;
|
1131
1122
|
|
1132
|
-
explicit ArrayLiteral(
|
1123
|
+
explicit ArrayLiteral(MaybeExpressions* items)
|
1133
1124
|
: items_(items) {
|
1134
1125
|
}
|
1135
|
-
inline const
|
1126
|
+
inline const MaybeExpressions& items() const {
|
1136
1127
|
return *items_;
|
1137
1128
|
}
|
1138
1129
|
DECLARE_DERIVED_NODE_TYPE(ArrayLiteral)
|
1139
1130
|
private:
|
1140
|
-
|
1131
|
+
MaybeExpressions* items_;
|
1141
1132
|
};
|
1142
1133
|
|
1143
1134
|
// ObjectLiteral
|
@@ -1208,7 +1199,7 @@ class FunctionLiteral : public FunctionLiteralBase<Factory> {
|
|
1208
1199
|
SETTER,
|
1209
1200
|
GETTER
|
1210
1201
|
};
|
1211
|
-
inline Identifier<Factory
|
1202
|
+
inline Maybe<Identifier<Factory> > name() const {
|
1212
1203
|
return name_;
|
1213
1204
|
}
|
1214
1205
|
inline DeclType type() const { return type_; }
|
@@ -1231,7 +1222,7 @@ class FunctionLiteral : public FunctionLiteralBase<Factory> {
|
|
1231
1222
|
return strict_;
|
1232
1223
|
}
|
1233
1224
|
FunctionLiteral(DeclType type,
|
1234
|
-
Identifier<Factory
|
1225
|
+
Maybe<Identifier<Factory> > name,
|
1235
1226
|
Identifiers* params,
|
1236
1227
|
Statements* body,
|
1237
1228
|
Scope<Factory>* scope,
|
@@ -1249,7 +1240,7 @@ class FunctionLiteral : public FunctionLiteralBase<Factory> {
|
|
1249
1240
|
}
|
1250
1241
|
DECLARE_DERIVED_NODE_TYPE(FunctionLiteral)
|
1251
1242
|
private:
|
1252
|
-
Identifier<Factory
|
1243
|
+
Maybe<Identifier<Factory> > name_;
|
1253
1244
|
DeclType type_;
|
1254
1245
|
Identifiers* params_;
|
1255
1246
|
Statements* body_;
|
@@ -20,7 +20,7 @@ class BasicAstFactory {
|
|
20
20
|
#define V(AST) typedef typename ast::AST<Factory> AST;
|
21
21
|
AST_NODE_LIST(V)
|
22
22
|
#undef V
|
23
|
-
#define V(
|
23
|
+
#define V(XS) typedef typename ast::AstNode<Factory>::XS XS;
|
24
24
|
AST_LIST_LIST(V)
|
25
25
|
#undef V
|
26
26
|
#define V(S) typedef typename SpaceUString<Factory>::type S;
|
@@ -28,9 +28,7 @@ class BasicAstFactory {
|
|
28
28
|
#undef V
|
29
29
|
|
30
30
|
BasicAstFactory()
|
31
|
-
:
|
32
|
-
new(static_cast<Factory*>(this))Undefined()),
|
33
|
-
empty_statement_instance_(
|
31
|
+
: empty_statement_instance_(
|
34
32
|
new(static_cast<Factory*>(this))EmptyStatement()),
|
35
33
|
debugger_statement_instance_(
|
36
34
|
new(static_cast<Factory*>(this))DebuggerStatement()),
|
@@ -88,7 +86,7 @@ class BasicAstFactory {
|
|
88
86
|
}
|
89
87
|
|
90
88
|
FunctionLiteral* NewFunctionLiteral(typename FunctionLiteral::DeclType type,
|
91
|
-
Identifier
|
89
|
+
Maybe<Identifier> name,
|
92
90
|
Identifiers* params,
|
93
91
|
Statements* body,
|
94
92
|
Scope* scope,
|
@@ -108,7 +106,7 @@ class BasicAstFactory {
|
|
108
106
|
end_block_position);
|
109
107
|
}
|
110
108
|
|
111
|
-
ArrayLiteral* NewArrayLiteral(
|
109
|
+
ArrayLiteral* NewArrayLiteral(MaybeExpressions* items,
|
112
110
|
std::size_t begin, std::size_t end) {
|
113
111
|
return new (static_cast<Factory*>(this)) ArrayLiteral(items);
|
114
112
|
}
|
@@ -146,10 +144,6 @@ class BasicAstFactory {
|
|
146
144
|
return this_instance_;
|
147
145
|
}
|
148
146
|
|
149
|
-
Undefined* NewUndefined() {
|
150
|
-
return undefined_instance_;
|
151
|
-
}
|
152
|
-
|
153
147
|
TrueLiteral* NewTrueLiteral(std::size_t begin, std::size_t end) {
|
154
148
|
return true_instance_;
|
155
149
|
}
|
@@ -192,7 +186,7 @@ class BasicAstFactory {
|
|
192
186
|
|
193
187
|
// if you want begin / end position,
|
194
188
|
// set position to Identifier / Expression and use it
|
195
|
-
Declaration* NewDeclaration(Identifier* name, Expression
|
189
|
+
Declaration* NewDeclaration(Identifier* name, Maybe<Expression> expr) {
|
196
190
|
return new (static_cast<Factory*>(this)) Declaration(name, expr);
|
197
191
|
}
|
198
192
|
|
@@ -200,7 +194,7 @@ class BasicAstFactory {
|
|
200
194
|
// set position to Statement and use it
|
201
195
|
IfStatement* NewIfStatement(Expression* cond,
|
202
196
|
Statement* then_statement,
|
203
|
-
Statement
|
197
|
+
Maybe<Statement> else_statement,
|
204
198
|
std::size_t begin) {
|
205
199
|
return new (static_cast<Factory*>(this)) IfStatement(cond,
|
206
200
|
then_statement,
|
@@ -235,9 +229,9 @@ class BasicAstFactory {
|
|
235
229
|
// if you want end position,
|
236
230
|
// set position to Statement and use it
|
237
231
|
ForStatement* NewForStatement(Statement* body,
|
238
|
-
Statement
|
239
|
-
Expression
|
240
|
-
Statement
|
232
|
+
Maybe<Statement> init,
|
233
|
+
Maybe<Expression> cond,
|
234
|
+
Maybe<Statement> next,
|
241
235
|
std::size_t begin) {
|
242
236
|
return new (static_cast<Factory*>(this)) ForStatement(body, init,
|
243
237
|
cond, next);
|
@@ -247,21 +241,21 @@ class BasicAstFactory {
|
|
247
241
|
return new (static_cast<Factory*>(this)) ExpressionStatement(expr);
|
248
242
|
}
|
249
243
|
|
250
|
-
ContinueStatement* NewContinueStatement(Identifier
|
244
|
+
ContinueStatement* NewContinueStatement(Maybe<Identifier> label,
|
251
245
|
IterationStatement** target,
|
252
246
|
std::size_t begin,
|
253
247
|
std::size_t end) {
|
254
248
|
return new (static_cast<Factory*>(this)) ContinueStatement(label, target);
|
255
249
|
}
|
256
250
|
|
257
|
-
BreakStatement* NewBreakStatement(Identifier
|
251
|
+
BreakStatement* NewBreakStatement(Maybe<Identifier> label,
|
258
252
|
BreakableStatement** target,
|
259
253
|
std::size_t begin,
|
260
254
|
std::size_t end) {
|
261
255
|
return new (static_cast<Factory*>(this)) BreakStatement(label, target);
|
262
256
|
}
|
263
257
|
|
264
|
-
ReturnStatement* NewReturnStatement(Expression
|
258
|
+
ReturnStatement* NewReturnStatement(Maybe<Expression> expr,
|
265
259
|
std::size_t begin,
|
266
260
|
std::size_t end) {
|
267
261
|
return new (static_cast<Factory*>(this)) ReturnStatement(expr);
|
@@ -281,7 +275,7 @@ class BasicAstFactory {
|
|
281
275
|
|
282
276
|
// !!! if body is empty, end_position is end.
|
283
277
|
CaseClause* NewCaseClause(bool is_default,
|
284
|
-
Expression
|
278
|
+
Maybe<Expression> expr, Statements* body,
|
285
279
|
std::size_t begin,
|
286
280
|
std::size_t end) {
|
287
281
|
return new (static_cast<Factory*>(this)) CaseClause(is_default, expr, body);
|
@@ -295,9 +289,9 @@ class BasicAstFactory {
|
|
295
289
|
// if you want end position,
|
296
290
|
// set position to Block and use it
|
297
291
|
TryStatement* NewTryStatement(Block* try_block,
|
298
|
-
Identifier
|
299
|
-
Block
|
300
|
-
Block
|
292
|
+
Maybe<Identifier> catch_name,
|
293
|
+
Maybe<Block> catch_block,
|
294
|
+
Maybe<Block> finally_block,
|
301
295
|
std::size_t begin) {
|
302
296
|
return new (static_cast<Factory*>(this)) TryStatement(try_block,
|
303
297
|
catch_name,
|
@@ -380,7 +374,6 @@ class BasicAstFactory {
|
|
380
374
|
}
|
381
375
|
|
382
376
|
private:
|
383
|
-
Undefined* undefined_instance_;
|
384
377
|
EmptyStatement* empty_statement_instance_;
|
385
378
|
DebuggerStatement* debugger_statement_instance_;
|
386
379
|
ThisLiteral* this_instance_;
|
data/ext/include/iv/ast_fwd.h
CHANGED
@@ -46,7 +46,6 @@ V(ArrayLiteral)\
|
|
46
46
|
V(ObjectLiteral)\
|
47
47
|
V(NullLiteral)\
|
48
48
|
V(ThisLiteral)\
|
49
|
-
V(Undefined)\
|
50
49
|
V(TrueLiteral)\
|
51
50
|
V(FalseLiteral)
|
52
51
|
|
@@ -90,11 +89,12 @@ STATEMENT_NODE_LIST(V)\
|
|
90
89
|
EXPRESSION_NODE_LIST(V)
|
91
90
|
|
92
91
|
#define AST_LIST_LIST(V)\
|
93
|
-
V(
|
94
|
-
V(
|
95
|
-
V(
|
96
|
-
V(
|
97
|
-
V(
|
92
|
+
V(Identifiers)\
|
93
|
+
V(Declarations)\
|
94
|
+
V(Expressions)\
|
95
|
+
V(Statements)\
|
96
|
+
V(CaseClauses)\
|
97
|
+
V(MaybeExpressions)
|
98
98
|
|
99
99
|
#define AST_STRING(V) V(SpaceUString)
|
100
100
|
|
data/ext/include/iv/ast_info.h
CHANGED
@@ -10,7 +10,7 @@ struct AstInfo {
|
|
10
10
|
#define V(AST) typedef typename AST<Factory> AST;
|
11
11
|
AST_NODE_LIST(V)
|
12
12
|
#undef V
|
13
|
-
#define V(
|
13
|
+
#define V(XS) typedef typename ast::AstNode<Factory>::XS XS;
|
14
14
|
AST_LIST_LIST(V)
|
15
15
|
#undef V
|
16
16
|
#define V(S) typedef typename SpaceUString<Factory>::type S;
|
@@ -20,10 +20,10 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
20
20
|
|
21
21
|
typedef void ReturnType;
|
22
22
|
|
23
|
-
#define V(AST) typedef typename
|
23
|
+
#define V(AST) typedef typename core::ast::AST<Factory> AST;
|
24
24
|
AST_NODE_LIST(V)
|
25
25
|
#undef V
|
26
|
-
#define V(
|
26
|
+
#define V(XS) typedef typename core::ast::AstNode<Factory>::XS XS;
|
27
27
|
AST_LIST_LIST(V)
|
28
28
|
#undef V
|
29
29
|
#define V(S) typedef typename core::SpaceUString<Factory>::type S;
|
@@ -91,8 +91,8 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
91
91
|
Append("{\"type\":\"decl\",\"name\":");
|
92
92
|
decl.name()->Accept(this);
|
93
93
|
Append(",\"exp\":");
|
94
|
-
if (decl.expr()) {
|
95
|
-
|
94
|
+
if (const Maybe<const Expression> expr = decl.expr()) {
|
95
|
+
(*expr).Accept(this);
|
96
96
|
}
|
97
97
|
Append('}');
|
98
98
|
++it;
|
@@ -112,9 +112,9 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
112
112
|
ifstmt->cond()->Accept(this);
|
113
113
|
Append(",\"body\":");
|
114
114
|
ifstmt->then_statement()->Accept(this);
|
115
|
-
if (ifstmt->else_statement()) {
|
115
|
+
if (const Maybe<const Statement> else_stmt = ifstmt->else_statement()) {
|
116
116
|
Append(",\"else\":");
|
117
|
-
|
117
|
+
(*else_stmt).Accept(this);
|
118
118
|
}
|
119
119
|
Append('}');
|
120
120
|
}
|
@@ -137,17 +137,17 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
137
137
|
|
138
138
|
void Visit(const ForStatement* forstmt) {
|
139
139
|
Append("{\"type\":\"for\"");
|
140
|
-
if (forstmt->init()
|
140
|
+
if (const Maybe<const Statement> init = forstmt->init()) {
|
141
141
|
Append(",\"init\":");
|
142
|
-
|
142
|
+
(*init).Accept(this);
|
143
143
|
}
|
144
|
-
if (forstmt->cond()
|
144
|
+
if (const Maybe<const Expression> cond = forstmt->cond()) {
|
145
145
|
Append(",\"cond\":");
|
146
|
-
|
146
|
+
(*cond).Accept(this);
|
147
147
|
}
|
148
|
-
if (forstmt->next()
|
148
|
+
if (const Maybe<const Statement> next = forstmt->next()) {
|
149
149
|
Append(",\"next\":");
|
150
|
-
|
150
|
+
(*next).Accept(this);
|
151
151
|
}
|
152
152
|
Append(",\"body\":");
|
153
153
|
forstmt->body()->Accept(this);
|
@@ -166,25 +166,28 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
166
166
|
|
167
167
|
void Visit(const ContinueStatement* continuestmt) {
|
168
168
|
Append("{\"type\":\"continue\"");
|
169
|
-
if (continuestmt->label()) {
|
169
|
+
if (const Maybe<const Identifier> label = continuestmt->label()) {
|
170
170
|
Append(",\"label\":");
|
171
|
-
|
171
|
+
(*label).Accept(this);
|
172
172
|
}
|
173
173
|
Append('}');
|
174
174
|
}
|
175
175
|
|
176
176
|
void Visit(const BreakStatement* breakstmt) {
|
177
177
|
Append("{\"type\":\"break\"");
|
178
|
-
if (breakstmt->label()) {
|
178
|
+
if (const Maybe<const Identifier> label = breakstmt->label()) {
|
179
179
|
Append(",\"label\":");
|
180
|
-
|
180
|
+
(*label).Accept(this);
|
181
181
|
}
|
182
182
|
Append('}');
|
183
183
|
}
|
184
184
|
|
185
185
|
void Visit(const ReturnStatement* returnstmt) {
|
186
|
-
Append("{\"type\":\"return\"
|
187
|
-
returnstmt->expr()
|
186
|
+
Append("{\"type\":\"return\"");
|
187
|
+
if (const Maybe<const Expression> expr = returnstmt->expr()) {
|
188
|
+
Append(",\"exp\":");
|
189
|
+
(*expr).Accept(this);
|
190
|
+
}
|
188
191
|
Append('}');
|
189
192
|
}
|
190
193
|
|
@@ -214,11 +217,11 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
214
217
|
end = switchstmt->clauses().end();
|
215
218
|
while (it != end) {
|
216
219
|
const CaseClause& clause = **it;
|
217
|
-
if (clause.
|
218
|
-
Append("{\"type\":\"default\"");
|
219
|
-
} else {
|
220
|
+
if (const Maybe<const Expression> expr = clause.expr()) {
|
220
221
|
Append("{\"type\":\"case\",\"exp\":");
|
221
|
-
|
222
|
+
(*expr).Accept(this);
|
223
|
+
} else {
|
224
|
+
Append("{\"type\":\"default\"");
|
222
225
|
}
|
223
226
|
Append(",\"body\"[");
|
224
227
|
typename Statements::const_iterator stit = clause.body().begin();
|
@@ -248,16 +251,16 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
248
251
|
void Visit(const TryStatement* trystmt) {
|
249
252
|
Append("{\"type\":\"try\",\"body\":");
|
250
253
|
trystmt->body()->Accept(this);
|
251
|
-
if (trystmt->catch_name()) {
|
254
|
+
if (const Maybe<const Identifier> ident = trystmt->catch_name()) {
|
252
255
|
Append(",\"catch\":{\"type\":\"catch\",\"name\":");
|
253
|
-
|
256
|
+
Visit(ident.Address());
|
254
257
|
Append(",\"body\":");
|
255
|
-
trystmt->catch_block()
|
258
|
+
Visit(trystmt->catch_block().Address());
|
256
259
|
Append('}');
|
257
260
|
}
|
258
|
-
if (trystmt->finally_block()) {
|
261
|
+
if (const Maybe<const Block> block = trystmt->finally_block()) {
|
259
262
|
Append(",\"finally\":{\"type\":\"finally\",\"body\":");
|
260
|
-
|
263
|
+
Visit(block.Address());
|
261
264
|
Append('}');
|
262
265
|
}
|
263
266
|
Append('}');
|
@@ -355,10 +358,6 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
355
358
|
Append("{\"type\":\"false\"}");
|
356
359
|
}
|
357
360
|
|
358
|
-
void Visit(const Undefined* literal) {
|
359
|
-
Append("{\"type\":\"undefined\"}");
|
360
|
-
}
|
361
|
-
|
362
361
|
void Visit(const RegExpLiteral* literal) {
|
363
362
|
Append("{\"type\":\"regexp\",\"value\":\"");
|
364
363
|
DecodeString(literal->value().begin(), literal->value().end());
|
@@ -369,12 +368,12 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
369
368
|
|
370
369
|
void Visit(const ArrayLiteral* literal) {
|
371
370
|
Append("{\"type\":\"array\",\"value\":[");
|
372
|
-
typename
|
373
|
-
const typename
|
371
|
+
typename MaybeExpressions::const_iterator it = literal->items().begin();
|
372
|
+
const typename MaybeExpressions::const_iterator end = literal->items().end();
|
374
373
|
bool previous_is_elision = false;
|
375
374
|
while (it != end) {
|
376
375
|
if ((*it)) {
|
377
|
-
(
|
376
|
+
(**it).Accept(this);
|
378
377
|
previous_is_elision = false;
|
379
378
|
} else {
|
380
379
|
previous_is_elision = true;
|
@@ -423,8 +422,8 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
|
|
423
422
|
|
424
423
|
void Visit(const FunctionLiteral* literal) {
|
425
424
|
Append("{\"type\":\"function\",\"name\":");
|
426
|
-
if (literal->name()) {
|
427
|
-
|
425
|
+
if (const Maybe<const Identifier> name = literal->name()) {
|
426
|
+
Visit(name.Address());
|
428
427
|
}
|
429
428
|
Append(",\"params\":[");
|
430
429
|
typename Identifiers::const_iterator it = literal->params().begin();
|