| OLD | NEW |
| 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 "src/ast/prettyprinter.h" | 5 #include "src/ast/prettyprinter.h" |
| 6 | 6 |
| 7 #include <stdarg.h> | 7 #include <stdarg.h> |
| 8 | 8 |
| 9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 // PrintStatements(node->body()); | 890 // PrintStatements(node->body()); |
| 891 } | 891 } |
| 892 | 892 |
| 893 | 893 |
| 894 void AstPrinter::VisitClassLiteral(ClassLiteral* node) { | 894 void AstPrinter::VisitClassLiteral(ClassLiteral* node) { |
| 895 IndentedScope indent(this, "CLASS LITERAL", node->position()); | 895 IndentedScope indent(this, "CLASS LITERAL", node->position()); |
| 896 PrintLiteralIndented("NAME", node->constructor()->name(), false); | 896 PrintLiteralIndented("NAME", node->constructor()->name(), false); |
| 897 if (node->extends() != nullptr) { | 897 if (node->extends() != nullptr) { |
| 898 PrintIndentedVisit("EXTENDS", node->extends()); | 898 PrintIndentedVisit("EXTENDS", node->extends()); |
| 899 } | 899 } |
| 900 PrintProperties(node->properties()); | 900 PrintClassProperties(node->properties()); |
| 901 } | 901 } |
| 902 | 902 |
| 903 | 903 void AstPrinter::PrintClassProperties( |
| 904 void AstPrinter::PrintProperties( | 904 ZoneList<ClassLiteral::Property*>* properties) { |
| 905 ZoneList<ObjectLiteral::Property*>* properties) { | |
| 906 for (int i = 0; i < properties->length(); i++) { | 905 for (int i = 0; i < properties->length(); i++) { |
| 907 ObjectLiteral::Property* property = properties->at(i); | 906 ClassLiteral::Property* property = properties->at(i); |
| 908 const char* prop_kind = nullptr; | 907 const char* prop_kind = nullptr; |
| 909 switch (property->kind()) { | 908 switch (property->kind()) { |
| 910 case ObjectLiteral::Property::CONSTANT: | 909 case ClassLiteral::Property::METHOD: |
| 911 prop_kind = "CONSTANT"; | 910 prop_kind = "METHOD"; |
| 912 break; | 911 break; |
| 913 case ObjectLiteral::Property::COMPUTED: | 912 case ClassLiteral::Property::GETTER: |
| 914 prop_kind = "COMPUTED"; | |
| 915 break; | |
| 916 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
| 917 prop_kind = "MATERIALIZED_LITERAL"; | |
| 918 break; | |
| 919 case ObjectLiteral::Property::PROTOTYPE: | |
| 920 prop_kind = "PROTOTYPE"; | |
| 921 break; | |
| 922 case ObjectLiteral::Property::GETTER: | |
| 923 prop_kind = "GETTER"; | 913 prop_kind = "GETTER"; |
| 924 break; | 914 break; |
| 925 case ObjectLiteral::Property::SETTER: | 915 case ClassLiteral::Property::SETTER: |
| 926 prop_kind = "SETTER"; | 916 prop_kind = "SETTER"; |
| 927 break; | 917 break; |
| 928 } | 918 } |
| 929 EmbeddedVector<char, 128> buf; | 919 EmbeddedVector<char, 128> buf; |
| 930 SNPrintF(buf, "PROPERTY%s - %s", property->is_static() ? " - STATIC" : "", | 920 SNPrintF(buf, "PROPERTY%s - %s", property->is_static() ? " - STATIC" : "", |
| 931 prop_kind); | 921 prop_kind); |
| 932 IndentedScope prop(this, buf.start()); | 922 IndentedScope prop(this, buf.start()); |
| 933 PrintIndentedVisit("KEY", properties->at(i)->key()); | 923 PrintIndentedVisit("KEY", properties->at(i)->key()); |
| 934 PrintIndentedVisit("VALUE", properties->at(i)->value()); | 924 PrintIndentedVisit("VALUE", properties->at(i)->value()); |
| 935 } | 925 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 Print("%s", buf.start()); | 969 Print("%s", buf.start()); |
| 980 Print("\n"); | 970 Print("\n"); |
| 981 } | 971 } |
| 982 | 972 |
| 983 | 973 |
| 984 void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { | 974 void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { |
| 985 IndentedScope indent(this, "OBJ LITERAL", node->position()); | 975 IndentedScope indent(this, "OBJ LITERAL", node->position()); |
| 986 EmbeddedVector<char, 128> buf; | 976 EmbeddedVector<char, 128> buf; |
| 987 SNPrintF(buf, "literal_index = %d\n", node->literal_index()); | 977 SNPrintF(buf, "literal_index = %d\n", node->literal_index()); |
| 988 PrintIndented(buf.start()); | 978 PrintIndented(buf.start()); |
| 989 PrintProperties(node->properties()); | 979 PrintObjectProperties(node->properties()); |
| 980 } |
| 981 |
| 982 void AstPrinter::PrintObjectProperties( |
| 983 ZoneList<ObjectLiteral::Property*>* properties) { |
| 984 for (int i = 0; i < properties->length(); i++) { |
| 985 ObjectLiteral::Property* property = properties->at(i); |
| 986 const char* prop_kind = nullptr; |
| 987 switch (property->kind()) { |
| 988 case ObjectLiteral::Property::CONSTANT: |
| 989 prop_kind = "CONSTANT"; |
| 990 break; |
| 991 case ObjectLiteral::Property::COMPUTED: |
| 992 prop_kind = "COMPUTED"; |
| 993 break; |
| 994 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 995 prop_kind = "MATERIALIZED_LITERAL"; |
| 996 break; |
| 997 case ObjectLiteral::Property::PROTOTYPE: |
| 998 prop_kind = "PROTOTYPE"; |
| 999 break; |
| 1000 case ObjectLiteral::Property::GETTER: |
| 1001 prop_kind = "GETTER"; |
| 1002 break; |
| 1003 case ObjectLiteral::Property::SETTER: |
| 1004 prop_kind = "SETTER"; |
| 1005 break; |
| 1006 } |
| 1007 EmbeddedVector<char, 128> buf; |
| 1008 SNPrintF(buf, "PROPERTY - %s", prop_kind); |
| 1009 IndentedScope prop(this, buf.start()); |
| 1010 PrintIndentedVisit("KEY", properties->at(i)->key()); |
| 1011 PrintIndentedVisit("VALUE", properties->at(i)->value()); |
| 1012 } |
| 990 } | 1013 } |
| 991 | 1014 |
| 992 | 1015 |
| 993 void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) { | 1016 void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) { |
| 994 IndentedScope indent(this, "ARRAY LITERAL", node->position()); | 1017 IndentedScope indent(this, "ARRAY LITERAL", node->position()); |
| 995 | 1018 |
| 996 EmbeddedVector<char, 128> buf; | 1019 EmbeddedVector<char, 128> buf; |
| 997 SNPrintF(buf, "literal_index = %d\n", node->literal_index()); | 1020 SNPrintF(buf, "literal_index = %d\n", node->literal_index()); |
| 998 PrintIndented(buf.start()); | 1021 PrintIndented(buf.start()); |
| 999 if (node->values()->length() > 0) { | 1022 if (node->values()->length() > 0) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 | 1183 |
| 1161 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { | 1184 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { |
| 1162 Visit(node->expression()); | 1185 Visit(node->expression()); |
| 1163 } | 1186 } |
| 1164 | 1187 |
| 1165 | 1188 |
| 1166 #endif // DEBUG | 1189 #endif // DEBUG |
| 1167 | 1190 |
| 1168 } // namespace internal | 1191 } // namespace internal |
| 1169 } // namespace v8 | 1192 } // namespace v8 |
| OLD | NEW |