Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: src/prettyprinter.cc

Issue 561913002: Class syntax parsing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add early error checks for static prototype and get/set constructor Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/preparser.h ('K') | « src/prettyprinter.h ('k') | src/rewriter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/prettyprinter.cc
diff --git a/src/prettyprinter.cc b/src/prettyprinter.cc
index 0f5d225b650437e99d3e69ac120c8ce467a4ea86..e1af892884bb4001258d392e06454dac94486283 100644
--- a/src/prettyprinter.cc
+++ b/src/prettyprinter.cc
@@ -53,6 +53,15 @@ void PrettyPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
}
+void PrettyPrinter::VisitClassDeclaration(ClassDeclaration* node) {
+ Print("class ");
+ PrintLiteral(node->proxy()->name(), false);
+ Print(" = ");
+ PrintClassLiteral(node->classLiteral());
+ Print(";");
+}
+
+
void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
Print("module ");
PrintLiteral(node->proxy()->name(), false);
@@ -289,6 +298,13 @@ void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
}
+void PrettyPrinter::VisitClassLiteral(ClassLiteral* node) {
+ Print("(");
+ PrintClassLiteral(node);
+ Print(")");
+}
+
+
void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
Print("(");
PrintLiteral(node->name(), false);
@@ -323,16 +339,22 @@ void PrettyPrinter::VisitObjectLiteral(ObjectLiteral* node) {
Print("{ ");
for (int i = 0; i < node->properties()->length(); i++) {
if (i != 0) Print(",");
- ObjectLiteral::Property* property = node->properties()->at(i);
- Print(" ");
- Visit(property->key());
- Print(": ");
- Visit(property->value());
+ PrintObjectLiteralProperty(node->properties()->at(i));
}
Print(" }");
}
+void PrettyPrinter::PrintObjectLiteralProperty(
+ ObjectLiteralProperty* property) {
+ // TODO(arv): Better printing of methods etc.
+ Print(" ");
+ Visit(property->key());
+ Print(": ");
+ Visit(property->value());
+}
+
+
void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) {
Print("[ ");
for (int i = 0; i < node->values()->length(); i++) {
@@ -622,6 +644,21 @@ void PrettyPrinter::PrintFunctionLiteral(FunctionLiteral* function) {
}
+void PrettyPrinter::PrintClassLiteral(ClassLiteral* class_literal) {
+ Print("class ");
+ PrintLiteral(class_literal->name(), false);
+ if (class_literal->extends()) {
+ Print(" extends ");
+ Visit(class_literal->extends());
+ }
+ Print(" { ");
+ for (int i = 0; i < class_literal->properties()->length(); i++) {
+ PrintObjectLiteralProperty(class_literal->properties()->at(i));
+ }
+ Print(" }");
+}
+
+
//-----------------------------------------------------------------------------
class IndentedScope BASE_EMBEDDED {
@@ -774,6 +811,15 @@ void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
}
+void AstPrinter::VisitClassDeclaration(ClassDeclaration* node) {
+ PrintIndented("CLASS ");
+ PrintLiteral(node->proxy()->name(), true);
+ Print(" = class ");
+ PrintLiteral(node->classLiteral()->name(), false);
+ Print("\n");
+}
+
+
void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
IndentedScope indent(this, "MODULE");
PrintLiteralIndented("NAME", node->proxy()->name(), true);
@@ -969,6 +1015,12 @@ void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
}
+void AstPrinter::VisitClassLiteral(ClassLiteral* node) {
+ IndentedScope indent(this, "CLASS LITERAL");
+ PrintLiteralIndented("NAME", node->name(), false);
+}
+
+
void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
IndentedScope indent(this, "NATIVE FUNC LITERAL");
PrintLiteralIndented("NAME", node->name(), false);
« src/preparser.h ('K') | « src/prettyprinter.h ('k') | src/rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698