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 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 Print("false"); | 1048 Print("false"); |
1049 } else if (object->IsUndefined()) { | 1049 } else if (object->IsUndefined()) { |
1050 Print("undefined"); | 1050 Print("undefined"); |
1051 } else if (object->IsNumber()) { | 1051 } else if (object->IsNumber()) { |
1052 Print("%g", object->Number()); | 1052 Print("%g", object->Number()); |
1053 } else if (object->IsJSObject()) { | 1053 } else if (object->IsJSObject()) { |
1054 // regular expression | 1054 // regular expression |
1055 if (object->IsJSFunction()) { | 1055 if (object->IsJSFunction()) { |
1056 Print("JS-Function"); | 1056 Print("JS-Function"); |
1057 } else if (object->IsJSArray()) { | 1057 } else if (object->IsJSArray()) { |
1058 Print("JS-array[%u]", JSArray::cast(object)->length()); | 1058 Print("JS-array[%u]", |
| 1059 Smi::cast(JSArray::cast(object)->length())->value()); |
1059 } else if (object->IsJSObject()) { | 1060 } else if (object->IsJSObject()) { |
1060 Print("JS-Object"); | 1061 Print("JS-Object"); |
1061 } else { | 1062 } else { |
1062 Print("?UNKNOWN?"); | 1063 Print("?UNKNOWN?"); |
1063 } | 1064 } |
1064 } else if (object->IsFixedArray()) { | 1065 } else if (object->IsFixedArray()) { |
1065 Print("FixedArray"); | 1066 Print("FixedArray"); |
1066 } else { | 1067 } else { |
1067 Print("<unknown literal %p>", object); | 1068 Print("<unknown literal %p>", object); |
1068 } | 1069 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 | 1139 |
1139 AstPrinter::~AstPrinter() { | 1140 AstPrinter::~AstPrinter() { |
1140 DCHECK(indent_ == 0); | 1141 DCHECK(indent_ == 0); |
1141 } | 1142 } |
1142 | 1143 |
1143 | 1144 |
1144 void AstPrinter::PrintIndented(const char* txt) { | 1145 void AstPrinter::PrintIndented(const char* txt) { |
1145 for (int i = 0; i < indent_; i++) { | 1146 for (int i = 0; i < indent_; i++) { |
1146 Print(". "); | 1147 Print(". "); |
1147 } | 1148 } |
1148 Print(txt); | 1149 Print("%s", txt); |
1149 } | 1150 } |
1150 | 1151 |
1151 | 1152 |
1152 void AstPrinter::PrintLiteralIndented(const char* info, | 1153 void AstPrinter::PrintLiteralIndented(const char* info, |
1153 Handle<Object> value, | 1154 Handle<Object> value, |
1154 bool quote) { | 1155 bool quote) { |
1155 PrintIndented(info); | 1156 PrintIndented(info); |
1156 Print(" "); | 1157 Print(" "); |
1157 PrintLiteral(value, quote); | 1158 PrintLiteral(value, quote); |
1158 Print("\n"); | 1159 Print("\n"); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 PrintIndented(buf.start()); | 1516 PrintIndented(buf.start()); |
1516 PrintLiteralIndented("PATTERN", node->pattern(), false); | 1517 PrintLiteralIndented("PATTERN", node->pattern(), false); |
1517 int i = 0; | 1518 int i = 0; |
1518 if (node->flags() & RegExp::kGlobal) buf[i++] = 'g'; | 1519 if (node->flags() & RegExp::kGlobal) buf[i++] = 'g'; |
1519 if (node->flags() & RegExp::kIgnoreCase) buf[i++] = 'i'; | 1520 if (node->flags() & RegExp::kIgnoreCase) buf[i++] = 'i'; |
1520 if (node->flags() & RegExp::kMultiline) buf[i++] = 'm'; | 1521 if (node->flags() & RegExp::kMultiline) buf[i++] = 'm'; |
1521 if (node->flags() & RegExp::kUnicode) buf[i++] = 'u'; | 1522 if (node->flags() & RegExp::kUnicode) buf[i++] = 'u'; |
1522 if (node->flags() & RegExp::kSticky) buf[i++] = 'y'; | 1523 if (node->flags() & RegExp::kSticky) buf[i++] = 'y'; |
1523 buf[i] = '\0'; | 1524 buf[i] = '\0'; |
1524 PrintIndented("FLAGS "); | 1525 PrintIndented("FLAGS "); |
1525 Print(buf.start()); | 1526 Print("%s", buf.start()); |
1526 Print("\n"); | 1527 Print("\n"); |
1527 } | 1528 } |
1528 | 1529 |
1529 | 1530 |
1530 void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { | 1531 void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { |
1531 IndentedScope indent(this, "OBJ LITERAL", node->position()); | 1532 IndentedScope indent(this, "OBJ LITERAL", node->position()); |
1532 EmbeddedVector<char, 128> buf; | 1533 EmbeddedVector<char, 128> buf; |
1533 SNPrintF(buf, "literal_index = %d\n", node->literal_index()); | 1534 SNPrintF(buf, "literal_index = %d\n", node->literal_index()); |
1534 PrintIndented(buf.start()); | 1535 PrintIndented(buf.start()); |
1535 PrintProperties(node->properties()); | 1536 PrintProperties(node->properties()); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 | 1705 |
1705 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { | 1706 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { |
1706 Visit(node->expression()); | 1707 Visit(node->expression()); |
1707 } | 1708 } |
1708 | 1709 |
1709 | 1710 |
1710 #endif // DEBUG | 1711 #endif // DEBUG |
1711 | 1712 |
1712 } // namespace internal | 1713 } // namespace internal |
1713 } // namespace v8 | 1714 } // namespace v8 |
OLD | NEW |