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 CHANGED
@@ -10,7 +10,7 @@ directory "ext/include/iv"
10
10
 
11
11
  HOE = Hoe.spec 'iv-phonic' do
12
12
  developer('Constellation', 'utatane.tea@gmail.com')
13
- self.version = '0.0.1'
13
+ self.version = '0.0.2'
14
14
  self.readme_file = 'README.rdoc'
15
15
  self.history_file = 'ChangeLog'
16
16
  self.extra_rdoc_files = FileList['*.rdoc']
@@ -23,7 +23,7 @@ HOE = Hoe.spec 'iv-phonic' do
23
23
  end
24
24
 
25
25
  Rake::ExtensionTask.new('phonic', HOE.spec) do |ext|
26
- ext.lib_dir = File.join('lib', 'iv', 'phonic')
26
+ ext.lib_dir = File.join('lib', 'iv')
27
27
  ext.ext_dir = File.join('ext', 'iv', 'phonic')
28
28
  ext.config_options << "--with-iv-include=#{File.join($root, 'ext', 'include')}"
29
29
  end
@@ -2,6 +2,7 @@
2
2
  #define _IV_AST_FACTORY_H_
3
3
  #include <tr1/type_traits>
4
4
  #include "functor.h"
5
+ #include "location.h"
5
6
  #include "ast.h"
6
7
  #include "alloc.h"
7
8
  #include "static_assert.h"
@@ -48,19 +49,10 @@ class BasicAstFactory : public Space<N> {
48
49
  is_base_of_factory::value);
49
50
  }
50
51
 
51
- Identifier* NewIdentifier(const UStringPiece& buffer) {
52
+ template<typename Range>
53
+ Identifier* NewIdentifier(const Range& range) {
52
54
  return new (static_cast<Factory*>(this))
53
- Identifier(buffer, static_cast<Factory*>(this));
54
- }
55
-
56
- Identifier* NewIdentifier(const std::vector<uc16>& buffer) {
57
- return new (static_cast<Factory*>(this))
58
- Identifier(buffer, static_cast<Factory*>(this));
59
- }
60
-
61
- Identifier* NewIdentifier(const std::vector<char>& buffer) {
62
- return new (static_cast<Factory*>(this))
63
- Identifier(buffer, static_cast<Factory*>(this));
55
+ Identifier(range, static_cast<Factory*>(this));
64
56
  }
65
57
 
66
58
  NumberLiteral* NewNumberLiteral(const double& val) {
@@ -149,37 +141,51 @@ class BasicAstFactory : public Space<N> {
149
141
  return new (static_cast<Factory*>(this)) Declaration(name, expr);
150
142
  }
151
143
 
152
- IfStatement* NewIfStatement(Expression* cond, Statement* then) {
153
- return new (static_cast<Factory*>(this)) IfStatement(cond, then);
144
+ IfStatement* NewIfStatement(Expression* cond,
145
+ Statement* then_statement,
146
+ Statement* else_statement) {
147
+ return new (static_cast<Factory*>(this)) IfStatement(cond,
148
+ then_statement,
149
+ else_statement);
154
150
  }
155
151
 
156
- DoWhileStatement* NewDoWhileStatement() {
157
- return new (static_cast<Factory*>(this)) DoWhileStatement();
152
+ DoWhileStatement* NewDoWhileStatement(Statement* body,
153
+ Expression* cond) {
154
+ return new (static_cast<Factory*>(this)) DoWhileStatement(body, cond);
158
155
  }
159
156
 
160
- WhileStatement* NewWhileStatement(Expression* expr) {
161
- return new (static_cast<Factory*>(this)) WhileStatement(expr);
157
+ WhileStatement* NewWhileStatement(Statement* body,
158
+ Expression* cond) {
159
+ return new (static_cast<Factory*>(this)) WhileStatement(body, cond);
162
160
  }
163
161
 
164
- ForInStatement* NewForInStatement(Statement* each,
162
+ ForInStatement* NewForInStatement(Statement* body,
163
+ Statement* each,
165
164
  Expression* enumerable) {
166
- return new (static_cast<Factory*>(this)) ForInStatement(each, enumerable);
165
+ return new (static_cast<Factory*>(this)) ForInStatement(body,
166
+ each, enumerable);
167
167
  }
168
168
 
169
169
  ExpressionStatement* NewExpressionStatement(Expression* expr) {
170
170
  return new (static_cast<Factory*>(this)) ExpressionStatement(expr);
171
171
  }
172
172
 
173
- ForStatement* NewForStatement() {
174
- return new (static_cast<Factory*>(this)) ForStatement();
173
+ ForStatement* NewForStatement(Statement* body,
174
+ Statement* init,
175
+ Expression* cond,
176
+ Statement* next) {
177
+ return new (static_cast<Factory*>(this)) ForStatement(body, init,
178
+ cond, next);
175
179
  }
176
180
 
177
- ContinueStatement* NewContinueStatement() {
178
- return new (static_cast<Factory*>(this)) ContinueStatement();
181
+ ContinueStatement* NewContinueStatement(Identifier* label,
182
+ IterationStatement** target) {
183
+ return new (static_cast<Factory*>(this)) ContinueStatement(label, target);
179
184
  }
180
185
 
181
- BreakStatement* NewBreakStatement() {
182
- return new (static_cast<Factory*>(this)) BreakStatement();
186
+ BreakStatement* NewBreakStatement(Identifier* label,
187
+ BreakableStatement** target) {
188
+ return new (static_cast<Factory*>(this)) BreakStatement(label, target);
183
189
  }
184
190
 
185
191
  ReturnStatement* NewReturnStatement(
@@ -197,17 +203,23 @@ class BasicAstFactory : public Space<N> {
197
203
  SwitchStatement(expr, static_cast<Factory*>(this));
198
204
  }
199
205
 
200
- CaseClause* NewCaseClause() {
206
+ CaseClause* NewCaseClause(bool is_default, Expression* expr) {
201
207
  return new (static_cast<Factory*>(this))
202
- CaseClause(static_cast<Factory*>(this));
208
+ CaseClause(is_default, expr, static_cast<Factory*>(this));
203
209
  }
204
210
 
205
211
  ThrowStatement* NewThrowStatement(Expression* expr) {
206
212
  return new (static_cast<Factory*>(this)) ThrowStatement(expr);
207
213
  }
208
214
 
209
- TryStatement* NewTryStatement(Block* block) {
210
- return new (static_cast<Factory*>(this)) TryStatement(block);
215
+ TryStatement* NewTryStatement(Block* try_block,
216
+ Identifier* catch_name,
217
+ Block* catch_block,
218
+ Block* finally_block) {
219
+ return new (static_cast<Factory*>(this)) TryStatement(try_block,
220
+ catch_name,
221
+ catch_block,
222
+ finally_block);
211
223
  }
212
224
 
213
225
  LabelledStatement* NewLabelledStatement(
@@ -4,8 +4,7 @@ namespace iv {
4
4
  namespace core {
5
5
  namespace ast {
6
6
 
7
- #define STATEMENT_NODE_LIST(V)\
8
- V(Statement)\
7
+ #define STATEMENT_DERIVED_NODE_LIST(V)\
9
8
  V(EmptyStatement)\
10
9
  V(DebuggerStatement)\
11
10
  V(FunctionStatement)\
@@ -25,10 +24,14 @@ V(SwitchStatement)\
25
24
  V(ThrowStatement)\
26
25
  V(TryStatement)\
27
26
  V(LabelledStatement)\
27
+
28
+ #define STATEMENT_NODE_LIST(V)\
29
+ V(Statement)\
30
+ V(IterationStatement)\
28
31
  V(BreakableStatement)\
29
32
  V(NamedOnlyBreakableStatement)\
30
33
  V(AnonymousBreakableStatement)\
31
- V(IterationStatement)
34
+ STATEMENT_DERIVED_NODE_LIST(V)
32
35
 
33
36
  #define LITERAL_NODE_LIST(V)\
34
37
  V(Literal)\
@@ -46,11 +49,7 @@ V(Undefined)\
46
49
  V(TrueLiteral)\
47
50
  V(FalseLiteral)
48
51
 
49
- #define EXPRESSION_NODE_LIST(V)\
50
- V(Expression)\
51
- V(IndexAccess)\
52
- V(PropertyAccess)\
53
- V(Call)\
52
+ #define EXPRESSION_DERIVED_NODE_LIST(V)\
54
53
  V(FunctionCall)\
55
54
  V(ConstructorCall)\
56
55
  V(BinaryOperation)\
@@ -59,15 +58,26 @@ V(ConditionalExpression)\
59
58
  V(UnaryOperation)\
60
59
  V(PostfixExpression)\
61
60
  V(IdentifierAccess)\
61
+ V(IndexAccess)\
62
62
  LITERAL_NODE_LIST(V)
63
63
 
64
+ #define EXPRESSION_NODE_LIST(V)\
65
+ V(Expression)\
66
+ V(PropertyAccess)\
67
+ V(Call)\
68
+ EXPRESSION_DERIVED_NODE_LIST(V)
69
+
64
70
  #define OTHER_NODE_LIST(V)\
65
71
  V(AstNode)\
66
- V(Variable)\
67
72
  V(Declaration)\
68
- V(IdentifierKey)\
69
73
  V(Scope)\
70
- V(CaseClause)
74
+ V(CaseClause)\
75
+ V(Variable)\
76
+ V(IdentifierKey)
77
+
78
+ #define AST_DERIVED_NODE_LIST(V)\
79
+ STATEMENT_DERIVED_NODE_LIST(V)\
80
+ EXPRESSION_DERIVED_NODE_LIST(V)
71
81
 
72
82
  #define AST_NODE_LIST(V)\
73
83
  OTHER_NODE_LIST(V)\
@@ -79,7 +89,7 @@ V(Identifier, Identifiers)\
79
89
  V(Declaration, Declarations)\
80
90
  V(Expression, Expressions)\
81
91
  V(Statement, Statements)\
82
- V(CaseClause, CaseClauses)\
92
+ V(CaseClause, CaseClauses)
83
93
 
84
94
  #define AST_STRING(V) V(SpaceUString)
85
95
 
@@ -81,7 +81,14 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
81
81
  typename Declarations::const_iterator it = var->decls().begin();
82
82
  const typename Declarations::const_iterator end = var->decls().end();
83
83
  while (it != end) {
84
- (*it)->Accept(this);
84
+ const Declaration& decl = **it;
85
+ Append("{\"type\":\"decl\",\"name\":");
86
+ decl.name()->Accept(this);
87
+ Append(",\"exp\":");
88
+ if (decl.expr()) {
89
+ decl.expr()->Accept(this);
90
+ }
91
+ Append('}');
85
92
  ++it;
86
93
  if (it != end) {
87
94
  Append(',');
@@ -90,16 +97,6 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
90
97
  Append("]}");
91
98
  }
92
99
 
93
- void Visit(const Declaration* decl) {
94
- Append("{\"type\":\"decl\",\"name\":");
95
- decl->name()->Accept(this);
96
- Append(",\"exp\":");
97
- if (decl->expr()) {
98
- decl->expr()->Accept(this);
99
- }
100
- Append('}');
101
- }
102
-
103
100
  void Visit(const EmptyStatement* empty) {
104
101
  Append("{\"type\":\"empty\"}");
105
102
  }
@@ -201,26 +198,6 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
201
198
  Append('}');
202
199
  }
203
200
 
204
- void Visit(const CaseClause* clause) {
205
- if (clause->IsDefault()) {
206
- Append("{\"type\":\"default\"");
207
- } else {
208
- Append("{\"type\":\"case\",\"exp\":");
209
- clause->expr()->Accept(this);
210
- }
211
- Append(",\"body\"[");
212
- typename Statements::const_iterator it = clause->body().begin();
213
- const typename Statements::const_iterator end = clause->body().end();
214
- while (it != end) {
215
- (*it)->Accept(this);
216
- ++it;
217
- if (it != end) {
218
- Append(',');
219
- }
220
- }
221
- Append("]}");
222
- }
223
-
224
201
  void Visit(const SwitchStatement* switchstmt) {
225
202
  Append("{\"type\":\"switch\",\"exp\":");
226
203
  switchstmt->expr()->Accept(this);
@@ -230,7 +207,24 @@ class AstSerializer: public AstVisitor<Factory>::const_type {
230
207
  const typename CaseClauses::const_iterator
231
208
  end = switchstmt->clauses().end();
232
209
  while (it != end) {
233
- (*it)->Accept(this);
210
+ const CaseClause& clause = **it;
211
+ if (clause.IsDefault()) {
212
+ Append("{\"type\":\"default\"");
213
+ } else {
214
+ Append("{\"type\":\"case\",\"exp\":");
215
+ clause.expr()->Accept(this);
216
+ }
217
+ Append(",\"body\"[");
218
+ typename Statements::const_iterator stit = clause.body().begin();
219
+ const typename Statements::const_iterator stend = clause.body().end();
220
+ while (stit != stend) {
221
+ (*stit)->Accept(this);
222
+ ++stit;
223
+ if (stit != stend) {
224
+ Append(',');
225
+ }
226
+ }
227
+ Append("]}");
234
228
  ++it;
235
229
  if (it != end) {
236
230
  Append(',');
@@ -40,7 +40,6 @@ class BasicAstVisitor
40
40
  virtual void Visit(typename add<Block<Factory> >::type block) = 0; //NOLINT
41
41
  virtual void Visit(typename add<FunctionStatement<Factory> >::type func) = 0; //NOLINT
42
42
  virtual void Visit(typename add<VariableStatement<Factory> >::type var) = 0; //NOLINT
43
- virtual void Visit(typename add<Declaration<Factory> >::type decl) = 0; //NOLINT
44
43
  virtual void Visit(typename add<EmptyStatement<Factory> >::type empty) = 0; //NOLINT
45
44
  virtual void Visit(typename add<IfStatement<Factory> >::type ifstmt) = 0; //NOLINT
46
45
  virtual void Visit(typename add<DoWhileStatement<Factory> >::type dowhile) = 0; //NOLINT
@@ -52,7 +51,6 @@ class BasicAstVisitor
52
51
  virtual void Visit(typename add<ReturnStatement<Factory> >::type returnstmt) = 0; //NOLINT
53
52
  virtual void Visit(typename add<WithStatement<Factory> >::type withstmt) = 0; //NOLINT
54
53
  virtual void Visit(typename add<LabelledStatement<Factory> >::type labelledstmt) = 0; //NOLINT
55
- virtual void Visit(typename add<CaseClause<Factory> >::type clause) = 0; //NOLINT
56
54
  virtual void Visit(typename add<SwitchStatement<Factory> >::type switchstmt) = 0; //NOLINT
57
55
  virtual void Visit(typename add<ThrowStatement<Factory> >::type throwstmt) = 0; //NOLINT
58
56
  virtual void Visit(typename add<TryStatement<Factory> >::type trystmt) = 0; //NOLINT