ext/iv/phonic/creator.h in iv-phonic-0.1.1 vs ext/iv/phonic/creator.h in iv-phonic-0.1.2

- old
+ new

@@ -26,11 +26,11 @@ return array; } void Visit(const Block* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Block")); + rb_hash_aset(hash, SYM("type"), SYM("Block")); VALUE array = rb_ary_new(); for (Statements::const_iterator it = stmt->body().begin(), last = stmt->body().end(); it != last; ++it) { (*it)->Accept(this); rb_ary_push(array, ret_); @@ -40,29 +40,29 @@ ret_ = hash; } void Visit(const FunctionStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("FunctionStatement")); + rb_hash_aset(hash, SYM("type"), SYM("FunctionStatement")); Visit(stmt->function()); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const FunctionDeclaration* decl) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("FunctionDeclaration")); + rb_hash_aset(hash, SYM("type"), SYM("FunctionDeclaration")); Visit(decl->function()); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, decl); ret_ = hash; } void Visit(const VariableStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("VariableStatement")); + rb_hash_aset(hash, SYM("type"), SYM("VariableStatement")); rb_hash_aset(hash, SYM("const"), stmt->IsConst() ? Qtrue : Qfalse); VALUE array = rb_ary_new(); for (Declarations::const_iterator it = stmt->decls().begin(), last = stmt->decls().end(); it != last; ++it) { Visit(*it); @@ -73,11 +73,11 @@ ret_ = hash; } void Visit(const Declaration* decl) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Declaration")); + rb_hash_aset(hash, SYM("type"), SYM("Declaration")); Visit(decl->name()); rb_hash_aset(hash, SYM("name"), ret_); if (decl->expr()) { decl->expr()->Accept(this); rb_hash_aset(hash, SYM("expr"), ret_); @@ -86,18 +86,18 @@ ret_ = hash; } void Visit(const EmptyStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("EmptyStatement")); + rb_hash_aset(hash, SYM("type"), SYM("EmptyStatement")); SetLocation(hash, stmt); ret_ = hash; } void Visit(const IfStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("IfStatement")); + rb_hash_aset(hash, SYM("type"), SYM("IfStatement")); stmt->cond()->Accept(this); rb_hash_aset(hash, SYM("cond"), ret_); stmt->then_statement()->Accept(this); rb_hash_aset(hash, SYM("then"), ret_); if (stmt->else_statement()) { @@ -108,33 +108,33 @@ ret_ = hash; } void Visit(const DoWhileStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("DoWhileStatement")); + rb_hash_aset(hash, SYM("type"), SYM("DoWhileStatement")); stmt->cond()->Accept(this); rb_hash_aset(hash, SYM("cond"), ret_); stmt->body()->Accept(this); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const WhileStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("WhileStatement")); + rb_hash_aset(hash, SYM("type"), SYM("WhileStatement")); stmt->cond()->Accept(this); rb_hash_aset(hash, SYM("cond"), ret_); stmt->body()->Accept(this); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const ForStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ForStatement")); + rb_hash_aset(hash, SYM("type"), SYM("ForStatement")); if (stmt->init()) { stmt->init()->Accept(this); rb_hash_aset(hash, SYM("init"), ret_); } if (stmt->cond()) { @@ -151,11 +151,11 @@ ret_ = hash; } void Visit(const ForInStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ForInStatement")); + rb_hash_aset(hash, SYM("type"), SYM("ForInStatement")); stmt->each()->Accept(this); rb_hash_aset(hash, SYM("each"), ret_); stmt->enumerable()->Accept(this); rb_hash_aset(hash, SYM("enum"), ret_); stmt->body()->Accept(this); @@ -164,64 +164,64 @@ ret_ = hash; } void Visit(const ContinueStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ContinueStatement")); + rb_hash_aset(hash, SYM("type"), SYM("ContinueStatement")); if (stmt->label()) { stmt->label()->Accept(this); rb_hash_aset(hash, SYM("label"), ret_); } SetLocation(hash, stmt); ret_ = hash; } void Visit(const BreakStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("BreakStatement")); + rb_hash_aset(hash, SYM("type"), SYM("BreakStatement")); if (stmt->label()) { stmt->label()->Accept(this); rb_hash_aset(hash, SYM("label"), ret_); } SetLocation(hash, stmt); ret_ = hash; } void Visit(const ReturnStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ReturnStatement")); + rb_hash_aset(hash, SYM("type"), SYM("ReturnStatement")); stmt->expr()->Accept(this); rb_hash_aset(hash, SYM("expr"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const WithStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("WithStatement")); + rb_hash_aset(hash, SYM("type"), SYM("WithStatement")); stmt->context()->Accept(this); rb_hash_aset(hash, SYM("context"), ret_); stmt->body()->Accept(this); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const LabelledStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("LabelledStatement")); + rb_hash_aset(hash, SYM("type"), SYM("LabelledStatement")); stmt->label()->Accept(this); rb_hash_aset(hash, SYM("label"), ret_); stmt->body()->Accept(this); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const SwitchStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("SwitchStatement")); + rb_hash_aset(hash, SYM("type"), SYM("SwitchStatement")); stmt->expr()->Accept(this); rb_hash_aset(hash, SYM("cond"), ret_); VALUE array = rb_ary_new(); for (CaseClauses::const_iterator it = stmt->clauses().begin(), last = stmt->clauses().end(); it != last; ++it) { @@ -233,14 +233,15 @@ ret_ = hash; } void Visit(const CaseClause* cl) { VALUE hash = rb_hash_new(); + rb_hash_aset(hash, SYM("type"), SYM("CaseClause")); if (cl->IsDefault()) { - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Default")); + rb_hash_aset(hash, SYM("kind"), SYM("Default")); } else { - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Case")); + rb_hash_aset(hash, SYM("kind"), SYM("Case")); cl->expr()->Accept(this); rb_hash_aset(hash, SYM("expr"), ret_); } VALUE stmts = rb_ary_new(); for (Statements::const_iterator st = cl->body().begin(), @@ -253,41 +254,41 @@ ret_ = hash; } void Visit(const ThrowStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ThrowStatement")); + rb_hash_aset(hash, SYM("type"), SYM("ThrowStatement")); SetLocation(hash, stmt); ret_ = hash; } void Visit(const TryStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("TryStatement")); + rb_hash_aset(hash, SYM("type"), SYM("TryStatement")); SetLocation(hash, stmt); ret_ = hash; } void Visit(const DebuggerStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("DebuggerStatement")); + rb_hash_aset(hash, SYM("type"), SYM("DebuggerStatement")); SetLocation(hash, stmt); ret_ = hash; } void Visit(const ExpressionStatement* stmt) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ExpressionStatement")); + rb_hash_aset(hash, SYM("type"), SYM("ExpressionStatement")); stmt->expr()->Accept(this); rb_hash_aset(hash, SYM("body"), ret_); SetLocation(hash, stmt); ret_ = hash; } void Visit(const Assignment* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Assignment")); + rb_hash_aset(hash, SYM("type"), SYM("Assignment")); rb_hash_aset(hash, SYM("op"), rb_str_new_cstr(core::Token::ToString(expr->op()))); expr->left()->Accept(this); rb_hash_aset(hash, SYM("left"), ret_); expr->right()->Accept(this); @@ -296,11 +297,11 @@ ret_ = hash; } void Visit(const BinaryOperation* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("BinaryOperation")); + rb_hash_aset(hash, SYM("type"), SYM("BinaryOperation")); rb_hash_aset(hash, SYM("op"), rb_str_new_cstr(core::Token::ToString(expr->op()))); expr->left()->Accept(this); rb_hash_aset(hash, SYM("left"), ret_); expr->right()->Accept(this); @@ -309,11 +310,11 @@ ret_ = hash; } void Visit(const ConditionalExpression* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ConditionalExpression")); + rb_hash_aset(hash, SYM("type"), SYM("ConditionalExpression")); expr->cond()->Accept(this); rb_hash_aset(hash, SYM("cond"), ret_); expr->left()->Accept(this); rb_hash_aset(hash, SYM("left"), ret_); expr->right()->Accept(this); @@ -322,33 +323,33 @@ ret_ = hash; } void Visit(const UnaryOperation* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("UnaryOperation")); + rb_hash_aset(hash, SYM("type"), SYM("UnaryOperation")); rb_hash_aset(hash, SYM("op"), rb_str_new_cstr(core::Token::ToString(expr->op()))); expr->expr()->Accept(this); rb_hash_aset(hash, SYM("expr"), ret_); SetLocation(hash, expr); ret_ = hash; } void Visit(const PostfixExpression* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("PostfixExpression")); + rb_hash_aset(hash, SYM("type"), SYM("PostfixExpression")); rb_hash_aset(hash, SYM("op"), rb_str_new_cstr(core::Token::ToString(expr->op()))); expr->expr()->Accept(this); rb_hash_aset(hash, SYM("expr"), ret_); SetLocation(hash, expr); ret_ = hash; } void Visit(const StringLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("StringLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("StringLiteral")); const StringLiteral::value_type& str = literal->value(); rb_hash_aset(hash, SYM("value"), Encoding::ConvertToDefaultInternal( rb_enc_str_new( reinterpret_cast<const char*>(str.data()), @@ -358,20 +359,27 @@ ret_ = hash; } void Visit(const NumberLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("NumberLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("NumberLiteral")); rb_hash_aset(hash, SYM("value"), rb_float_new(literal->value())); SetLocation(hash, literal); ret_ = hash; } void Visit(const Identifier* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Identifier")); + rb_hash_aset(hash, SYM("type"), SYM("Identifier")); const Identifier::value_type& str = literal->value(); + if (literal->type() == core::Token::IDENTIFIER) { + rb_hash_aset(hash, SYM("kind"), SYM("Identifier")); + } else if (literal->type() == core::Token::NUMBER) { + rb_hash_aset(hash, SYM("kind"), SYM("Number")); + } else { + rb_hash_aset(hash, SYM("kind"), SYM("String")); + } rb_hash_aset(hash, SYM("value"), Encoding::ConvertToDefaultInternal( rb_enc_str_new( reinterpret_cast<const char*>(str.data()), str.size()*2, @@ -380,46 +388,46 @@ ret_ = hash; } void Visit(const ThisLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ThisLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("ThisLiteral")); SetLocation(hash, literal); ret_ = hash; } void Visit(const NullLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("NullLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("NullLiteral")); SetLocation(hash, literal); ret_ = hash; } void Visit(const TrueLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("TrueLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("TrueLiteral")); SetLocation(hash, literal); ret_ = hash; } void Visit(const FalseLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("FalseLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("FalseLiteral")); SetLocation(hash, literal); ret_ = hash; } void Visit(const Undefined* literal) { // Undefined has no location VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("Undefined")); + rb_hash_aset(hash, SYM("type"), SYM("Undefined")); ret_ = hash; } void Visit(const RegExpLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("RegExpLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("RegExpLiteral")); const RegExpLiteral::value_type& content = literal->value(); rb_hash_aset(hash, SYM("value"), Encoding::ConvertToDefaultInternal( rb_enc_str_new( reinterpret_cast<const char*>(content.data()), @@ -436,11 +444,11 @@ ret_ = hash; } void Visit(const ArrayLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ArrayLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("ArrayLiteral")); VALUE array = rb_ary_new(); for (Expressions::const_iterator it = literal->items().begin(), last = literal->items().end(); it != last; ++it) { (*it)->Accept(this); rb_ary_push(array, ret_); @@ -451,32 +459,26 @@ } void Visit(const ObjectLiteral* literal) { using std::tr1::get; VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ObjectLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("ObjectLiteral")); VALUE array = rb_ary_new(); for (ObjectLiteral::Properties::const_iterator it = literal->properties().begin(), last = literal->properties().end(); it != last; ++it) { VALUE item = rb_hash_new(); switch (get<0>(*it)) { case ObjectLiteral::DATA: - rb_hash_aset(item, - SYM("type"), - rb_str_new_cstr("DataProperty")); + rb_hash_aset(item, SYM("kind"), SYM("Data")); break; case ObjectLiteral::SET: - rb_hash_aset(item, - SYM("type"), - rb_str_new_cstr("SetterProperty")); + rb_hash_aset(item, SYM("kind"), SYM("Setter")); break; case ObjectLiteral::GET: - rb_hash_aset(item, - SYM("type"), - rb_str_new_cstr("GetterProperty")); + rb_hash_aset(item, SYM("kind"), SYM("Getter")); break; } get<1>(*it)->Accept(this); rb_hash_aset(item, SYM("key"), @@ -492,11 +494,11 @@ ret_ = hash; } void Visit(const FunctionLiteral* literal) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("FunctionLiteral")); + rb_hash_aset(hash, SYM("type"), SYM("FunctionLiteral")); if (literal->name()) { Visit(literal->name()); rb_hash_aset(hash, SYM("name"), ret_); } { @@ -521,33 +523,33 @@ ret_ = hash; } void Visit(const IndexAccess* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("IndexAccess")); + rb_hash_aset(hash, SYM("type"), SYM("IndexAccess")); expr->target()->Accept(this); rb_hash_aset(hash, SYM("target"), ret_); expr->key()->Accept(this); rb_hash_aset(hash, SYM("key"), ret_); SetLocation(hash, expr); ret_ = hash; } void Visit(const IdentifierAccess* expr) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("IdentifierAccess")); + rb_hash_aset(hash, SYM("type"), SYM("IdentifierAccess")); expr->target()->Accept(this); rb_hash_aset(hash, SYM("target"), ret_); Visit(expr->key()); rb_hash_aset(hash, SYM("key"), ret_); SetLocation(hash, expr); ret_ = hash; } void Visit(const FunctionCall* call) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("FunctionCall")); + rb_hash_aset(hash, SYM("type"), SYM("FunctionCall")); call->target()->Accept(this); rb_hash_aset(hash, SYM("target"), ret_); VALUE args = rb_ary_new(); for (Expressions::const_iterator it = call->args().begin(), last = call->args().end(); it != last; ++it) { @@ -559,10 +561,10 @@ ret_ = hash; } void Visit(const ConstructorCall* call) { VALUE hash = rb_hash_new(); - rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("ConstructorCall")); + rb_hash_aset(hash, SYM("type"), SYM("ConstructorCall")); call->target()->Accept(this); rb_hash_aset(hash, SYM("target"), ret_); VALUE args = rb_ary_new(); for (Expressions::const_iterator it = call->args().begin(), last = call->args().end(); it != last; ++it) {