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