iv-phonic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.autotest +24 -0
  2. data/Manifest.txt +49 -0
  3. data/README.rdoc +32 -0
  4. data/Rakefile +54 -0
  5. data/ext/include/iv/algorithm.h +23 -0
  6. data/ext/include/iv/alloc.h +200 -0
  7. data/ext/include/iv/any.h +71 -0
  8. data/ext/include/iv/ast-factory.h +277 -0
  9. data/ext/include/iv/ast-fwd.h +92 -0
  10. data/ext/include/iv/ast-serializer.h +579 -0
  11. data/ext/include/iv/ast-visitor.h +121 -0
  12. data/ext/include/iv/ast.h +1127 -0
  13. data/ext/include/iv/chars.h +83 -0
  14. data/ext/include/iv/cmdline.h +830 -0
  15. data/ext/include/iv/conversions.h +308 -0
  16. data/ext/include/iv/dtoa.h +20 -0
  17. data/ext/include/iv/enable_if.h +18 -0
  18. data/ext/include/iv/errors.h +15 -0
  19. data/ext/include/iv/fixedcontainer.h +42 -0
  20. data/ext/include/iv/functor.h +29 -0
  21. data/ext/include/iv/lexer.h +1281 -0
  22. data/ext/include/iv/location.h +23 -0
  23. data/ext/include/iv/mt19937.h +175 -0
  24. data/ext/include/iv/noncopyable.h +30 -0
  25. data/ext/include/iv/none.h +10 -0
  26. data/ext/include/iv/parser.h +2150 -0
  27. data/ext/include/iv/source.h +27 -0
  28. data/ext/include/iv/space.h +178 -0
  29. data/ext/include/iv/static_assert.h +30 -0
  30. data/ext/include/iv/stringpiece.h +385 -0
  31. data/ext/include/iv/token.h +311 -0
  32. data/ext/include/iv/ucdata.h +58 -0
  33. data/ext/include/iv/uchar.h +8 -0
  34. data/ext/include/iv/ustring.h +28 -0
  35. data/ext/include/iv/ustringpiece.h +9 -0
  36. data/ext/include/iv/utils.h +83 -0
  37. data/ext/include/iv/xorshift.h +74 -0
  38. data/ext/iv/phonic/ast-fwd.h +21 -0
  39. data/ext/iv/phonic/ast.h +10 -0
  40. data/ext/iv/phonic/creator.h +530 -0
  41. data/ext/iv/phonic/encoding.h +110 -0
  42. data/ext/iv/phonic/extconf.rb +5 -0
  43. data/ext/iv/phonic/factory.h +247 -0
  44. data/ext/iv/phonic/parser.h +12 -0
  45. data/ext/iv/phonic/phonic.cc +69 -0
  46. data/ext/iv/phonic/rnode.h +15 -0
  47. data/ext/iv/phonic/rparser.h +48 -0
  48. data/ext/iv/phonic/source.h +146 -0
  49. data/test/test_iv_phonic.rb +32 -0
  50. metadata +159 -0
@@ -0,0 +1,277 @@
1
+ #ifndef _IV_AST_FACTORY_H_
2
+ #define _IV_AST_FACTORY_H_
3
+ #include <tr1/type_traits>
4
+ #include "functor.h"
5
+ #include "ast.h"
6
+ #include "alloc.h"
7
+ #include "static_assert.h"
8
+ #include "ustringpiece.h"
9
+
10
+ namespace iv {
11
+ namespace core {
12
+ namespace ast {
13
+
14
+ template<std::size_t N, typename Factory>
15
+ class BasicAstFactory : public Space<N> {
16
+ public:
17
+ typedef BasicAstFactory<N, Factory> this_type;
18
+
19
+ #define V(AST) typedef typename ast::AST<Factory> AST;
20
+ AST_NODE_LIST(V)
21
+ #undef V
22
+ #define V(X, XS) typedef typename SpaceVector<Factory, X*>::type XS;
23
+ AST_LIST_LIST(V)
24
+ #undef V
25
+ #define V(S) typedef typename SpaceUString<Factory>::type S;
26
+ AST_STRING(V)
27
+ #undef V
28
+
29
+ BasicAstFactory()
30
+ : Space<N>(),
31
+ undefined_instance_(
32
+ new(static_cast<Factory*>(this))Undefined()),
33
+ empty_statement_instance_(
34
+ new(static_cast<Factory*>(this))EmptyStatement()),
35
+ debugger_statement_instance_(
36
+ new(static_cast<Factory*>(this))DebuggerStatement()),
37
+ this_instance_(
38
+ new(static_cast<Factory*>(this))ThisLiteral()),
39
+ null_instance_(
40
+ new(static_cast<Factory*>(this))NullLiteral()),
41
+ true_instance_(
42
+ new(static_cast<Factory*>(this))TrueLiteral()),
43
+ false_instance_(
44
+ new(static_cast<Factory*>(this))FalseLiteral()) {
45
+ typedef std::tr1::is_convertible<Factory, this_type> is_convertible_to_this;
46
+ typedef std::tr1::is_base_of<this_type, Factory> is_base_of_factory;
47
+ IV_STATIC_ASSERT(is_convertible_to_this::value ||
48
+ is_base_of_factory::value);
49
+ }
50
+
51
+ Identifier* NewIdentifier(const UStringPiece& buffer) {
52
+ 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));
64
+ }
65
+
66
+ NumberLiteral* NewNumberLiteral(const double& val) {
67
+ return new (static_cast<Factory*>(this)) NumberLiteral(val);
68
+ }
69
+
70
+ StringLiteral* NewStringLiteral(const std::vector<uc16>& buffer) {
71
+ return new (static_cast<Factory*>(this))
72
+ StringLiteral(buffer, static_cast<Factory*>(this));
73
+ }
74
+
75
+ Directivable* NewDirectivable(const std::vector<uc16>& buffer) {
76
+ return new (static_cast<Factory*>(this))
77
+ Directivable(buffer, static_cast<Factory*>(this));
78
+ }
79
+
80
+ RegExpLiteral* NewRegExpLiteral(const std::vector<uc16>& content,
81
+ const std::vector<uc16>& flags) {
82
+ return new (static_cast<Factory*>(this))
83
+ RegExpLiteral(content, flags, static_cast<Factory*>(this));
84
+ }
85
+
86
+ FunctionLiteral* NewFunctionLiteral(typename FunctionLiteral::DeclType type) {
87
+ return new (static_cast<Factory*>(this))
88
+ FunctionLiteral(type, static_cast<Factory*>(this));
89
+ }
90
+
91
+ ArrayLiteral* NewArrayLiteral() {
92
+ return new (static_cast<Factory*>(this))
93
+ ArrayLiteral(static_cast<Factory*>(this));
94
+ }
95
+
96
+ ObjectLiteral* NewObjectLiteral() {
97
+ return new (static_cast<Factory*>(this))
98
+ ObjectLiteral(static_cast<Factory*>(this));
99
+ }
100
+
101
+ Identifiers* NewLabels() {
102
+ return new (Space<N>::New(sizeof(Identifiers)))
103
+ Identifiers(
104
+ typename Identifiers::allocator_type(static_cast<Factory*>(this)));
105
+ }
106
+
107
+ NullLiteral* NewNullLiteral() {
108
+ return null_instance_;
109
+ }
110
+
111
+ EmptyStatement* NewEmptyStatement() {
112
+ return empty_statement_instance_;
113
+ }
114
+
115
+ DebuggerStatement* NewDebuggerStatement() {
116
+ return debugger_statement_instance_;
117
+ }
118
+
119
+ ThisLiteral* NewThisLiteral() {
120
+ return this_instance_;
121
+ }
122
+
123
+ Undefined* NewUndefined() {
124
+ return undefined_instance_;
125
+ }
126
+
127
+ TrueLiteral* NewTrueLiteral() {
128
+ return true_instance_;
129
+ }
130
+
131
+ FalseLiteral* NewFalseLiteral() {
132
+ return false_instance_;
133
+ }
134
+
135
+ FunctionStatement* NewFunctionStatement(FunctionLiteral* func) {
136
+ return new (static_cast<Factory*>(this)) FunctionStatement(func);
137
+ }
138
+
139
+ Block* NewBlock() {
140
+ return new (static_cast<Factory*>(this)) Block(static_cast<Factory*>(this));
141
+ }
142
+
143
+ VariableStatement* NewVariableStatement(Token::Type token) {
144
+ return new (static_cast<Factory*>(this))
145
+ VariableStatement(token, static_cast<Factory*>(this));
146
+ }
147
+
148
+ Declaration* NewDeclaration(Identifier* name, Expression* expr) {
149
+ return new (static_cast<Factory*>(this)) Declaration(name, expr);
150
+ }
151
+
152
+ IfStatement* NewIfStatement(Expression* cond, Statement* then) {
153
+ return new (static_cast<Factory*>(this)) IfStatement(cond, then);
154
+ }
155
+
156
+ DoWhileStatement* NewDoWhileStatement() {
157
+ return new (static_cast<Factory*>(this)) DoWhileStatement();
158
+ }
159
+
160
+ WhileStatement* NewWhileStatement(Expression* expr) {
161
+ return new (static_cast<Factory*>(this)) WhileStatement(expr);
162
+ }
163
+
164
+ ForInStatement* NewForInStatement(Statement* each,
165
+ Expression* enumerable) {
166
+ return new (static_cast<Factory*>(this)) ForInStatement(each, enumerable);
167
+ }
168
+
169
+ ExpressionStatement* NewExpressionStatement(Expression* expr) {
170
+ return new (static_cast<Factory*>(this)) ExpressionStatement(expr);
171
+ }
172
+
173
+ ForStatement* NewForStatement() {
174
+ return new (static_cast<Factory*>(this)) ForStatement();
175
+ }
176
+
177
+ ContinueStatement* NewContinueStatement() {
178
+ return new (static_cast<Factory*>(this)) ContinueStatement();
179
+ }
180
+
181
+ BreakStatement* NewBreakStatement() {
182
+ return new (static_cast<Factory*>(this)) BreakStatement();
183
+ }
184
+
185
+ ReturnStatement* NewReturnStatement(
186
+ Expression* expr) {
187
+ return new (static_cast<Factory*>(this)) ReturnStatement(expr);
188
+ }
189
+
190
+ WithStatement* NewWithStatement(
191
+ Expression* expr, Statement* stmt) {
192
+ return new (static_cast<Factory*>(this)) WithStatement(expr, stmt);
193
+ }
194
+
195
+ SwitchStatement* NewSwitchStatement(Expression* expr) {
196
+ return new (static_cast<Factory*>(this))
197
+ SwitchStatement(expr, static_cast<Factory*>(this));
198
+ }
199
+
200
+ CaseClause* NewCaseClause() {
201
+ return new (static_cast<Factory*>(this))
202
+ CaseClause(static_cast<Factory*>(this));
203
+ }
204
+
205
+ ThrowStatement* NewThrowStatement(Expression* expr) {
206
+ return new (static_cast<Factory*>(this)) ThrowStatement(expr);
207
+ }
208
+
209
+ TryStatement* NewTryStatement(Block* block) {
210
+ return new (static_cast<Factory*>(this)) TryStatement(block);
211
+ }
212
+
213
+ LabelledStatement* NewLabelledStatement(
214
+ Expression* expr,
215
+ Statement* stmt) {
216
+ return new (static_cast<Factory*>(this)) LabelledStatement(expr, stmt);
217
+ }
218
+
219
+ BinaryOperation* NewBinaryOperation(Token::Type op,
220
+ Expression* result, Expression* right) {
221
+ return new (static_cast<Factory*>(this)) BinaryOperation(op, result, right);
222
+ }
223
+
224
+ Assignment* NewAssignment(Token::Type op,
225
+ Expression* left,
226
+ Expression* right) {
227
+ return new (static_cast<Factory*>(this)) Assignment(op, left, right);
228
+ }
229
+
230
+ ConditionalExpression* NewConditionalExpression(Expression* cond,
231
+ Expression* left,
232
+ Expression* right) {
233
+ return new (static_cast<Factory*>(this))
234
+ ConditionalExpression(cond, left, right);
235
+ }
236
+
237
+ UnaryOperation* NewUnaryOperation(Token::Type op, Expression* expr) {
238
+ return new (static_cast<Factory*>(this)) UnaryOperation(op, expr);
239
+ }
240
+
241
+ PostfixExpression* NewPostfixExpression(
242
+ Token::Type op, Expression* expr) {
243
+ return new (static_cast<Factory*>(this)) PostfixExpression(op, expr);
244
+ }
245
+
246
+ FunctionCall* NewFunctionCall(Expression* expr) {
247
+ return new (static_cast<Factory*>(this))
248
+ FunctionCall(expr, static_cast<Factory*>(this));
249
+ }
250
+
251
+ ConstructorCall* NewConstructorCall(Expression* target) {
252
+ return new (static_cast<Factory*>(this))
253
+ ConstructorCall(target, static_cast<Factory*>(this));
254
+ }
255
+
256
+ IndexAccess* NewIndexAccess(Expression* expr,
257
+ Expression* index) {
258
+ return new (static_cast<Factory*>(this)) IndexAccess(expr, index);
259
+ }
260
+
261
+ IdentifierAccess* NewIdentifierAccess(Expression* expr,
262
+ Identifier* ident) {
263
+ return new (static_cast<Factory*>(this)) IdentifierAccess(expr, ident);
264
+ }
265
+
266
+ private:
267
+ Undefined* undefined_instance_;
268
+ EmptyStatement* empty_statement_instance_;
269
+ DebuggerStatement* debugger_statement_instance_;
270
+ ThisLiteral* this_instance_;
271
+ NullLiteral* null_instance_;
272
+ TrueLiteral* true_instance_;
273
+ FalseLiteral* false_instance_;
274
+ };
275
+
276
+ } } } // namespace iv::core::ast
277
+ #endif // _IV_AST_FACTORY_H_
@@ -0,0 +1,92 @@
1
+ #ifndef _IV_AST_FWD_H_
2
+ #define _IV_AST_FWD_H_
3
+ namespace iv {
4
+ namespace core {
5
+ namespace ast {
6
+
7
+ #define STATEMENT_NODE_LIST(V)\
8
+ V(Statement)\
9
+ V(EmptyStatement)\
10
+ V(DebuggerStatement)\
11
+ V(FunctionStatement)\
12
+ V(Block)\
13
+ V(VariableStatement)\
14
+ V(IfStatement)\
15
+ V(DoWhileStatement)\
16
+ V(WhileStatement)\
17
+ V(ForInStatement)\
18
+ V(ExpressionStatement)\
19
+ V(ForStatement)\
20
+ V(ContinueStatement)\
21
+ V(BreakStatement)\
22
+ V(ReturnStatement)\
23
+ V(WithStatement)\
24
+ V(SwitchStatement)\
25
+ V(ThrowStatement)\
26
+ V(TryStatement)\
27
+ V(LabelledStatement)\
28
+ V(BreakableStatement)\
29
+ V(NamedOnlyBreakableStatement)\
30
+ V(AnonymousBreakableStatement)\
31
+ V(IterationStatement)
32
+
33
+ #define LITERAL_NODE_LIST(V)\
34
+ V(Literal)\
35
+ V(Identifier)\
36
+ V(NumberLiteral)\
37
+ V(StringLiteral)\
38
+ V(Directivable)\
39
+ V(RegExpLiteral)\
40
+ V(FunctionLiteral)\
41
+ V(ArrayLiteral)\
42
+ V(ObjectLiteral)\
43
+ V(NullLiteral)\
44
+ V(ThisLiteral)\
45
+ V(Undefined)\
46
+ V(TrueLiteral)\
47
+ V(FalseLiteral)
48
+
49
+ #define EXPRESSION_NODE_LIST(V)\
50
+ V(Expression)\
51
+ V(IndexAccess)\
52
+ V(PropertyAccess)\
53
+ V(Call)\
54
+ V(FunctionCall)\
55
+ V(ConstructorCall)\
56
+ V(BinaryOperation)\
57
+ V(Assignment)\
58
+ V(ConditionalExpression)\
59
+ V(UnaryOperation)\
60
+ V(PostfixExpression)\
61
+ V(IdentifierAccess)\
62
+ LITERAL_NODE_LIST(V)
63
+
64
+ #define OTHER_NODE_LIST(V)\
65
+ V(AstNode)\
66
+ V(Variable)\
67
+ V(Declaration)\
68
+ V(IdentifierKey)\
69
+ V(Scope)\
70
+ V(CaseClause)
71
+
72
+ #define AST_NODE_LIST(V)\
73
+ OTHER_NODE_LIST(V)\
74
+ STATEMENT_NODE_LIST(V)\
75
+ EXPRESSION_NODE_LIST(V)
76
+
77
+ #define AST_LIST_LIST(V)\
78
+ V(Identifier, Identifiers)\
79
+ V(Declaration, Declarations)\
80
+ V(Expression, Expressions)\
81
+ V(Statement, Statements)\
82
+ V(CaseClause, CaseClauses)\
83
+
84
+ #define AST_STRING(V) V(SpaceUString)
85
+
86
+ #define V(AST)\
87
+ template<typename Factory>\
88
+ class AST;
89
+ AST_NODE_LIST(V)
90
+ #undef V
91
+ } } } // namespace iv::core::ast
92
+ #endif // _IV_AST_FWD_H_