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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdarg.h> 5 #include <stdarg.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/ast-value-factory.h" 9 #include "src/ast-value-factory.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 void PrettyPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) { 47 void PrettyPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
48 Print("function "); 48 Print("function ");
49 PrintLiteral(node->proxy()->name(), false); 49 PrintLiteral(node->proxy()->name(), false);
50 Print(" = "); 50 Print(" = ");
51 PrintFunctionLiteral(node->fun()); 51 PrintFunctionLiteral(node->fun());
52 Print(";"); 52 Print(";");
53 } 53 }
54 54
55 55
56 void PrettyPrinter::VisitClassDeclaration(ClassDeclaration* node) {
57 Print("class ");
58 PrintLiteral(node->proxy()->name(), false);
59 Print(" = ");
60 PrintClassLiteral(node->classLiteral());
61 Print(";");
62 }
63
64
56 void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) { 65 void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
57 Print("module "); 66 Print("module ");
58 PrintLiteral(node->proxy()->name(), false); 67 PrintLiteral(node->proxy()->name(), false);
59 Print(" = "); 68 Print(" = ");
60 Visit(node->module()); 69 Visit(node->module());
61 Print(";"); 70 Print(";");
62 } 71 }
63 72
64 73
65 void PrettyPrinter::VisitImportDeclaration(ImportDeclaration* node) { 74 void PrettyPrinter::VisitImportDeclaration(ImportDeclaration* node) {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 291 }
283 292
284 293
285 void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) { 294 void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
286 Print("("); 295 Print("(");
287 PrintFunctionLiteral(node); 296 PrintFunctionLiteral(node);
288 Print(")"); 297 Print(")");
289 } 298 }
290 299
291 300
301 void PrettyPrinter::VisitClassLiteral(ClassLiteral* node) {
302 Print("(");
303 PrintClassLiteral(node);
304 Print(")");
305 }
306
307
292 void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { 308 void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
293 Print("("); 309 Print("(");
294 PrintLiteral(node->name(), false); 310 PrintLiteral(node->name(), false);
295 Print(")"); 311 Print(")");
296 } 312 }
297 313
298 314
299 void PrettyPrinter::VisitConditional(Conditional* node) { 315 void PrettyPrinter::VisitConditional(Conditional* node) {
300 Visit(node->condition()); 316 Visit(node->condition());
301 Print(" ? "); 317 Print(" ? ");
(...skipping 14 matching lines...) Expand all
316 Print(","); 332 Print(",");
317 PrintLiteral(node->flags(), false); 333 PrintLiteral(node->flags(), false);
318 Print(") "); 334 Print(") ");
319 } 335 }
320 336
321 337
322 void PrettyPrinter::VisitObjectLiteral(ObjectLiteral* node) { 338 void PrettyPrinter::VisitObjectLiteral(ObjectLiteral* node) {
323 Print("{ "); 339 Print("{ ");
324 for (int i = 0; i < node->properties()->length(); i++) { 340 for (int i = 0; i < node->properties()->length(); i++) {
325 if (i != 0) Print(","); 341 if (i != 0) Print(",");
326 ObjectLiteral::Property* property = node->properties()->at(i); 342 PrintObjectLiteralProperty(node->properties()->at(i));
327 Print(" ");
328 Visit(property->key());
329 Print(": ");
330 Visit(property->value());
331 } 343 }
332 Print(" }"); 344 Print(" }");
333 } 345 }
334 346
335 347
348 void PrettyPrinter::PrintObjectLiteralProperty(
349 ObjectLiteralProperty* property) {
350 // TODO(arv): Better printing of methods etc.
351 Print(" ");
352 Visit(property->key());
353 Print(": ");
354 Visit(property->value());
355 }
356
357
336 void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) { 358 void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) {
337 Print("[ "); 359 Print("[ ");
338 for (int i = 0; i < node->values()->length(); i++) { 360 for (int i = 0; i < node->values()->length(); i++) {
339 if (i != 0) Print(","); 361 if (i != 0) Print(",");
340 Visit(node->values()->at(i)); 362 Visit(node->values()->at(i));
341 } 363 }
342 Print(" ]"); 364 Print(" ]");
343 } 365 }
344 366
345 367
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 Print("function "); 637 Print("function ");
616 PrintLiteral(function->name(), false); 638 PrintLiteral(function->name(), false);
617 PrintParameters(function->scope()); 639 PrintParameters(function->scope());
618 Print(" { "); 640 Print(" { ");
619 PrintDeclarations(function->scope()->declarations()); 641 PrintDeclarations(function->scope()->declarations());
620 PrintStatements(function->body()); 642 PrintStatements(function->body());
621 Print(" }"); 643 Print(" }");
622 } 644 }
623 645
624 646
647 void PrettyPrinter::PrintClassLiteral(ClassLiteral* class_literal) {
648 Print("class ");
649 PrintLiteral(class_literal->name(), false);
650 if (class_literal->extends()) {
651 Print(" extends ");
652 Visit(class_literal->extends());
653 }
654 Print(" { ");
655 for (int i = 0; i < class_literal->properties()->length(); i++) {
656 PrintObjectLiteralProperty(class_literal->properties()->at(i));
657 }
658 Print(" }");
659 }
660
661
625 //----------------------------------------------------------------------------- 662 //-----------------------------------------------------------------------------
626 663
627 class IndentedScope BASE_EMBEDDED { 664 class IndentedScope BASE_EMBEDDED {
628 public: 665 public:
629 IndentedScope(AstPrinter* printer, const char* txt) 666 IndentedScope(AstPrinter* printer, const char* txt)
630 : ast_printer_(printer) { 667 : ast_printer_(printer) {
631 ast_printer_->PrintIndented(txt); 668 ast_printer_->PrintIndented(txt);
632 ast_printer_->Print("\n"); 669 ast_printer_->Print("\n");
633 ast_printer_->inc_indent(); 670 ast_printer_->inc_indent();
634 } 671 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // TODO(svenpanne) Start with IndentedScope. 804 // TODO(svenpanne) Start with IndentedScope.
768 void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) { 805 void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
769 PrintIndented("FUNCTION "); 806 PrintIndented("FUNCTION ");
770 PrintLiteral(node->proxy()->name(), true); 807 PrintLiteral(node->proxy()->name(), true);
771 Print(" = function "); 808 Print(" = function ");
772 PrintLiteral(node->fun()->name(), false); 809 PrintLiteral(node->fun()->name(), false);
773 Print("\n"); 810 Print("\n");
774 } 811 }
775 812
776 813
814 void AstPrinter::VisitClassDeclaration(ClassDeclaration* node) {
815 PrintIndented("CLASS ");
816 PrintLiteral(node->proxy()->name(), true);
817 Print(" = class ");
818 PrintLiteral(node->classLiteral()->name(), false);
819 Print("\n");
820 }
821
822
777 void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) { 823 void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
778 IndentedScope indent(this, "MODULE"); 824 IndentedScope indent(this, "MODULE");
779 PrintLiteralIndented("NAME", node->proxy()->name(), true); 825 PrintLiteralIndented("NAME", node->proxy()->name(), true);
780 Visit(node->module()); 826 Visit(node->module());
781 } 827 }
782 828
783 829
784 void AstPrinter::VisitImportDeclaration(ImportDeclaration* node) { 830 void AstPrinter::VisitImportDeclaration(ImportDeclaration* node) {
785 IndentedScope indent(this, "IMPORT"); 831 IndentedScope indent(this, "IMPORT");
786 PrintLiteralIndented("NAME", node->proxy()->name(), true); 832 PrintLiteralIndented("NAME", node->proxy()->name(), true);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 PrintLiteralIndented("NAME", node->name(), false); 1008 PrintLiteralIndented("NAME", node->name(), false);
963 PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false); 1009 PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false);
964 PrintParameters(node->scope()); 1010 PrintParameters(node->scope());
965 // We don't want to see the function literal in this case: it 1011 // We don't want to see the function literal in this case: it
966 // will be printed via PrintProgram when the code for it is 1012 // will be printed via PrintProgram when the code for it is
967 // generated. 1013 // generated.
968 // PrintStatements(node->body()); 1014 // PrintStatements(node->body());
969 } 1015 }
970 1016
971 1017
1018 void AstPrinter::VisitClassLiteral(ClassLiteral* node) {
1019 IndentedScope indent(this, "CLASS LITERAL");
1020 PrintLiteralIndented("NAME", node->name(), false);
1021 }
1022
1023
972 void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { 1024 void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
973 IndentedScope indent(this, "NATIVE FUNC LITERAL"); 1025 IndentedScope indent(this, "NATIVE FUNC LITERAL");
974 PrintLiteralIndented("NAME", node->name(), false); 1026 PrintLiteralIndented("NAME", node->name(), false);
975 } 1027 }
976 1028
977 1029
978 void AstPrinter::VisitConditional(Conditional* node) { 1030 void AstPrinter::VisitConditional(Conditional* node) {
979 IndentedScope indent(this, "CONDITIONAL"); 1031 IndentedScope indent(this, "CONDITIONAL");
980 PrintIndentedVisit("CONDITION", node->condition()); 1032 PrintIndentedVisit("CONDITION", node->condition());
981 PrintIndentedVisit("THEN", node->then_expression()); 1033 PrintIndentedVisit("THEN", node->then_expression());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 } 1203 }
1152 1204
1153 1205
1154 void AstPrinter::VisitSuperReference(SuperReference* node) { 1206 void AstPrinter::VisitSuperReference(SuperReference* node) {
1155 IndentedScope indent(this, "SUPER-REFERENCE"); 1207 IndentedScope indent(this, "SUPER-REFERENCE");
1156 } 1208 }
1157 1209
1158 #endif // DEBUG 1210 #endif // DEBUG
1159 1211
1160 } } // namespace v8::internal 1212 } } // namespace v8::internal
OLDNEW
« 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