ext/include/iv/ast-serializer.h in iv-phonic-0.0.1 vs ext/include/iv/ast-serializer.h in iv-phonic-0.0.2

- old
+ new

@@ -79,29 +79,26 @@ Append("\"var\",\"decls\":["); } typename Declarations::const_iterator it = var->decls().begin(); const typename Declarations::const_iterator end = var->decls().end(); while (it != end) { - (*it)->Accept(this); + const Declaration& decl = **it; + Append("{\"type\":\"decl\",\"name\":"); + decl.name()->Accept(this); + Append(",\"exp\":"); + if (decl.expr()) { + decl.expr()->Accept(this); + } + Append('}'); ++it; if (it != end) { Append(','); } } Append("]}"); } - void Visit(const Declaration* decl) { - Append("{\"type\":\"decl\",\"name\":"); - decl->name()->Accept(this); - Append(",\"exp\":"); - if (decl->expr()) { - decl->expr()->Accept(this); - } - Append('}'); - } - void Visit(const EmptyStatement* empty) { Append("{\"type\":\"empty\"}"); } void Visit(const IfStatement* ifstmt) { @@ -199,39 +196,36 @@ Append(",\"body\":"); labelledstmt->body()->Accept(this); Append('}'); } - void Visit(const CaseClause* clause) { - if (clause->IsDefault()) { - Append("{\"type\":\"default\""); - } else { - Append("{\"type\":\"case\",\"exp\":"); - clause->expr()->Accept(this); - } - Append(",\"body\"["); - typename Statements::const_iterator it = clause->body().begin(); - const typename Statements::const_iterator end = clause->body().end(); - while (it != end) { - (*it)->Accept(this); - ++it; - if (it != end) { - Append(','); - } - } - Append("]}"); - } - void Visit(const SwitchStatement* switchstmt) { Append("{\"type\":\"switch\",\"exp\":"); switchstmt->expr()->Accept(this); Append(",\"clauses\":["); typename CaseClauses::const_iterator it = switchstmt->clauses().begin(); const typename CaseClauses::const_iterator end = switchstmt->clauses().end(); while (it != end) { - (*it)->Accept(this); + const CaseClause& clause = **it; + if (clause.IsDefault()) { + Append("{\"type\":\"default\""); + } else { + Append("{\"type\":\"case\",\"exp\":"); + clause.expr()->Accept(this); + } + Append(",\"body\"["); + typename Statements::const_iterator stit = clause.body().begin(); + const typename Statements::const_iterator stend = clause.body().end(); + while (stit != stend) { + (*stit)->Accept(this); + ++stit; + if (stit != stend) { + Append(','); + } + } + Append("]}"); ++it; if (it != end) { Append(','); } }