| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 | 125 |
| 126 void PrettyPrinter::VisitWithStatement(WithStatement* node) { | 126 void PrettyPrinter::VisitWithStatement(WithStatement* node) { |
| 127 Print("with ("); | 127 Print("with ("); |
| 128 Visit(node->expression()); | 128 Visit(node->expression()); |
| 129 Print(") "); | 129 Print(") "); |
| 130 Visit(node->statement()); | 130 Visit(node->statement()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 | 133 |
| 134 void PrettyPrinter::VisitExitContextStatement(ExitContextStatement* node) { | |
| 135 Print("<exit context>"); | |
| 136 } | |
| 137 | |
| 138 | |
| 139 void PrettyPrinter::VisitSwitchStatement(SwitchStatement* node) { | 134 void PrettyPrinter::VisitSwitchStatement(SwitchStatement* node) { |
| 140 PrintLabels(node->labels()); | 135 PrintLabels(node->labels()); |
| 141 Print("switch ("); | 136 Print("switch ("); |
| 142 Visit(node->tag()); | 137 Visit(node->tag()); |
| 143 Print(") { "); | 138 Print(") { "); |
| 144 ZoneList<CaseClause*>* cases = node->cases(); | 139 ZoneList<CaseClause*>* cases = node->cases(); |
| 145 for (int i = 0; i < cases->length(); i++) | 140 for (int i = 0; i < cases->length(); i++) |
| 146 PrintCaseClause(cases->at(i)); | 141 PrintCaseClause(cases->at(i)); |
| 147 Print("}"); | 142 Print("}"); |
| 148 } | 143 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) { | 272 void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) { |
| 278 Print("[ "); | 273 Print("[ "); |
| 279 for (int i = 0; i < node->values()->length(); i++) { | 274 for (int i = 0; i < node->values()->length(); i++) { |
| 280 if (i != 0) Print(","); | 275 if (i != 0) Print(","); |
| 281 Visit(node->values()->at(i)); | 276 Visit(node->values()->at(i)); |
| 282 } | 277 } |
| 283 Print(" ]"); | 278 Print(" ]"); |
| 284 } | 279 } |
| 285 | 280 |
| 286 | 281 |
| 287 void PrettyPrinter::VisitSlot(Slot* node) { | |
| 288 switch (node->type()) { | |
| 289 case Slot::PARAMETER: | |
| 290 Print("parameter[%d]", node->index()); | |
| 291 break; | |
| 292 case Slot::LOCAL: | |
| 293 Print("local[%d]", node->index()); | |
| 294 break; | |
| 295 case Slot::CONTEXT: | |
| 296 Print("context[%d]", node->index()); | |
| 297 break; | |
| 298 case Slot::LOOKUP: | |
| 299 Print("lookup["); | |
| 300 PrintLiteral(node->var()->name(), false); | |
| 301 Print("]"); | |
| 302 break; | |
| 303 default: | |
| 304 UNREACHABLE(); | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 | |
| 309 void PrettyPrinter::VisitVariableProxy(VariableProxy* node) { | 282 void PrettyPrinter::VisitVariableProxy(VariableProxy* node) { |
| 310 PrintLiteral(node->name(), false); | 283 PrintLiteral(node->name(), false); |
| 311 } | 284 } |
| 312 | 285 |
| 313 | 286 |
| 314 void PrettyPrinter::VisitAssignment(Assignment* node) { | 287 void PrettyPrinter::VisitAssignment(Assignment* node) { |
| 315 Visit(node->target()); | 288 Visit(node->target()); |
| 316 Print(" %s ", Token::String(node->op())); | 289 Print(" %s ", Token::String(node->op())); |
| 317 Visit(node->value()); | 290 Visit(node->value()); |
| 318 } | 291 } |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; | 717 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; |
| 745 IndentedScope indent(this, block_txt); | 718 IndentedScope indent(this, block_txt); |
| 746 PrintStatements(node->statements()); | 719 PrintStatements(node->statements()); |
| 747 } | 720 } |
| 748 | 721 |
| 749 | 722 |
| 750 void AstPrinter::VisitDeclaration(Declaration* node) { | 723 void AstPrinter::VisitDeclaration(Declaration* node) { |
| 751 if (node->fun() == NULL) { | 724 if (node->fun() == NULL) { |
| 752 // var or const declarations | 725 // var or const declarations |
| 753 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), | 726 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
| 754 node->proxy()->AsVariable(), | 727 node->proxy()->var(), |
| 755 node->proxy()->name()); | 728 node->proxy()->name()); |
| 756 } else { | 729 } else { |
| 757 // function declarations | 730 // function declarations |
| 758 PrintIndented("FUNCTION "); | 731 PrintIndented("FUNCTION "); |
| 759 PrintLiteral(node->proxy()->name(), true); | 732 PrintLiteral(node->proxy()->name(), true); |
| 760 Print(" = function "); | 733 Print(" = function "); |
| 761 PrintLiteral(node->fun()->name(), false); | 734 PrintLiteral(node->fun()->name(), false); |
| 762 Print("\n"); | 735 Print("\n"); |
| 763 } | 736 } |
| 764 } | 737 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 } | 771 } |
| 799 | 772 |
| 800 | 773 |
| 801 void AstPrinter::VisitWithStatement(WithStatement* node) { | 774 void AstPrinter::VisitWithStatement(WithStatement* node) { |
| 802 IndentedScope indent(this, "WITH"); | 775 IndentedScope indent(this, "WITH"); |
| 803 PrintIndentedVisit("OBJECT", node->expression()); | 776 PrintIndentedVisit("OBJECT", node->expression()); |
| 804 PrintIndentedVisit("BODY", node->statement()); | 777 PrintIndentedVisit("BODY", node->statement()); |
| 805 } | 778 } |
| 806 | 779 |
| 807 | 780 |
| 808 void AstPrinter::VisitExitContextStatement(ExitContextStatement* node) { | |
| 809 PrintIndented("EXIT CONTEXT\n"); | |
| 810 } | |
| 811 | |
| 812 | |
| 813 void AstPrinter::VisitSwitchStatement(SwitchStatement* node) { | 781 void AstPrinter::VisitSwitchStatement(SwitchStatement* node) { |
| 814 IndentedScope indent(this, "SWITCH"); | 782 IndentedScope indent(this, "SWITCH"); |
| 815 PrintLabelsIndented(NULL, node->labels()); | 783 PrintLabelsIndented(NULL, node->labels()); |
| 816 PrintIndentedVisit("TAG", node->tag()); | 784 PrintIndentedVisit("TAG", node->tag()); |
| 817 for (int i = 0; i < node->cases()->length(); i++) { | 785 for (int i = 0; i < node->cases()->length(); i++) { |
| 818 PrintCaseClause(node->cases()->at(i)); | 786 PrintCaseClause(node->cases()->at(i)); |
| 819 } | 787 } |
| 820 } | 788 } |
| 821 | 789 |
| 822 | 790 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 IndentedScope indent(this, "ARRAY LITERAL"); | 920 IndentedScope indent(this, "ARRAY LITERAL"); |
| 953 if (node->values()->length() > 0) { | 921 if (node->values()->length() > 0) { |
| 954 IndentedScope indent(this, "VALUES"); | 922 IndentedScope indent(this, "VALUES"); |
| 955 for (int i = 0; i < node->values()->length(); i++) { | 923 for (int i = 0; i < node->values()->length(); i++) { |
| 956 Visit(node->values()->at(i)); | 924 Visit(node->values()->at(i)); |
| 957 } | 925 } |
| 958 } | 926 } |
| 959 } | 927 } |
| 960 | 928 |
| 961 | 929 |
| 962 void AstPrinter::VisitSlot(Slot* node) { | |
| 963 PrintIndented("SLOT "); | |
| 964 PrettyPrinter::VisitSlot(node); | |
| 965 Print("\n"); | |
| 966 } | |
| 967 | |
| 968 | |
| 969 void AstPrinter::VisitVariableProxy(VariableProxy* node) { | 930 void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
| 970 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name()); | |
| 971 Variable* var = node->var(); | 931 Variable* var = node->var(); |
| 972 if (var != NULL && var->rewrite() != NULL) { | 932 PrintLiteralWithModeIndented("VAR PROXY", var, node->name()); |
| 973 IndentedScope indent(this); | 933 { IndentedScope indent(this); |
| 974 Visit(var->rewrite()); | 934 switch (var->location()) { |
| 935 case Variable::UNALLOCATED: |
| 936 break; |
| 937 case Variable::PARAMETER: |
| 938 Print("parameter[%d]", var->index()); |
| 939 break; |
| 940 case Variable::LOCAL: |
| 941 Print("local[%d]", var->index()); |
| 942 break; |
| 943 case Variable::CONTEXT: |
| 944 Print("context[%d]", var->index()); |
| 945 break; |
| 946 case Variable::LOOKUP: |
| 947 Print("lookup"); |
| 948 break; |
| 949 } |
| 975 } | 950 } |
| 976 } | 951 } |
| 977 | 952 |
| 978 | 953 |
| 979 void AstPrinter::VisitAssignment(Assignment* node) { | 954 void AstPrinter::VisitAssignment(Assignment* node) { |
| 980 IndentedScope indent(this, Token::Name(node->op()), node); | 955 IndentedScope indent(this, Token::Name(node->op()), node); |
| 981 Visit(node->target()); | 956 Visit(node->target()); |
| 982 Visit(node->value()); | 957 Visit(node->value()); |
| 983 } | 958 } |
| 984 | 959 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 } | 1170 } |
| 1196 | 1171 |
| 1197 | 1172 |
| 1198 void JsonAstBuilder::VisitWithStatement(WithStatement* stmt) { | 1173 void JsonAstBuilder::VisitWithStatement(WithStatement* stmt) { |
| 1199 TagScope tag(this, "WithStatement"); | 1174 TagScope tag(this, "WithStatement"); |
| 1200 Visit(stmt->expression()); | 1175 Visit(stmt->expression()); |
| 1201 Visit(stmt->statement()); | 1176 Visit(stmt->statement()); |
| 1202 } | 1177 } |
| 1203 | 1178 |
| 1204 | 1179 |
| 1205 void JsonAstBuilder::VisitExitContextStatement(ExitContextStatement* stmt) { | |
| 1206 TagScope tag(this, "ExitContextStatement"); | |
| 1207 } | |
| 1208 | |
| 1209 | |
| 1210 void JsonAstBuilder::VisitSwitchStatement(SwitchStatement* stmt) { | 1180 void JsonAstBuilder::VisitSwitchStatement(SwitchStatement* stmt) { |
| 1211 TagScope tag(this, "SwitchStatement"); | 1181 TagScope tag(this, "SwitchStatement"); |
| 1212 } | 1182 } |
| 1213 | 1183 |
| 1214 | 1184 |
| 1215 void JsonAstBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { | 1185 void JsonAstBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 1216 TagScope tag(this, "DoWhileStatement"); | 1186 TagScope tag(this, "DoWhileStatement"); |
| 1217 Visit(stmt->body()); | 1187 Visit(stmt->body()); |
| 1218 Visit(stmt->cond()); | 1188 Visit(stmt->cond()); |
| 1219 } | 1189 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 SharedFunctionInfoLiteral* expr) { | 1250 SharedFunctionInfoLiteral* expr) { |
| 1281 TagScope tag(this, "SharedFunctionInfoLiteral"); | 1251 TagScope tag(this, "SharedFunctionInfoLiteral"); |
| 1282 } | 1252 } |
| 1283 | 1253 |
| 1284 | 1254 |
| 1285 void JsonAstBuilder::VisitConditional(Conditional* expr) { | 1255 void JsonAstBuilder::VisitConditional(Conditional* expr) { |
| 1286 TagScope tag(this, "Conditional"); | 1256 TagScope tag(this, "Conditional"); |
| 1287 } | 1257 } |
| 1288 | 1258 |
| 1289 | 1259 |
| 1290 void JsonAstBuilder::VisitSlot(Slot* expr) { | |
| 1291 TagScope tag(this, "Slot"); | |
| 1292 { | |
| 1293 AttributesScope attributes(this); | |
| 1294 switch (expr->type()) { | |
| 1295 case Slot::PARAMETER: | |
| 1296 AddAttribute("type", "PARAMETER"); | |
| 1297 break; | |
| 1298 case Slot::LOCAL: | |
| 1299 AddAttribute("type", "LOCAL"); | |
| 1300 break; | |
| 1301 case Slot::CONTEXT: | |
| 1302 AddAttribute("type", "CONTEXT"); | |
| 1303 break; | |
| 1304 case Slot::LOOKUP: | |
| 1305 AddAttribute("type", "LOOKUP"); | |
| 1306 break; | |
| 1307 } | |
| 1308 AddAttribute("index", expr->index()); | |
| 1309 } | |
| 1310 } | |
| 1311 | |
| 1312 | |
| 1313 void JsonAstBuilder::VisitVariableProxy(VariableProxy* expr) { | 1260 void JsonAstBuilder::VisitVariableProxy(VariableProxy* expr) { |
| 1314 if (expr->var()->rewrite() == NULL) { | 1261 TagScope tag(this, "Variable"); |
| 1315 TagScope tag(this, "VariableProxy"); | 1262 { |
| 1316 { | 1263 AttributesScope attributes(this); |
| 1317 AttributesScope attributes(this); | 1264 Variable* var = expr->var(); |
| 1318 AddAttribute("name", expr->name()); | 1265 AddAttribute("name", var->name()); |
| 1319 AddAttribute("mode", Variable::Mode2String(expr->var()->mode())); | 1266 switch (var->location()) { |
| 1267 case Variable::UNALLOCATED: |
| 1268 AddAttribute("location", "UNALLOCATED"); |
| 1269 break; |
| 1270 case Variable::PARAMETER: |
| 1271 AddAttribute("location", "PARAMETER"); |
| 1272 AddAttribute("index", var->index()); |
| 1273 break; |
| 1274 case Variable::LOCAL: |
| 1275 AddAttribute("location", "LOCAL"); |
| 1276 AddAttribute("index", var->index()); |
| 1277 break; |
| 1278 case Variable::CONTEXT: |
| 1279 AddAttribute("location", "CONTEXT"); |
| 1280 AddAttribute("index", var->index()); |
| 1281 break; |
| 1282 case Variable::LOOKUP: |
| 1283 AddAttribute("location", "LOOKUP"); |
| 1284 break; |
| 1320 } | 1285 } |
| 1321 } else { | |
| 1322 Visit(expr->var()->rewrite()); | |
| 1323 } | 1286 } |
| 1324 } | 1287 } |
| 1325 | 1288 |
| 1326 | 1289 |
| 1327 void JsonAstBuilder::VisitLiteral(Literal* expr) { | 1290 void JsonAstBuilder::VisitLiteral(Literal* expr) { |
| 1328 TagScope tag(this, "Literal"); | 1291 TagScope tag(this, "Literal"); |
| 1329 { | 1292 { |
| 1330 AttributesScope attributes(this); | 1293 AttributesScope attributes(this); |
| 1331 Handle<Object> handle = expr->handle(); | 1294 Handle<Object> handle = expr->handle(); |
| 1332 if (handle->IsString()) { | 1295 if (handle->IsString()) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 AddAttribute("mode", Variable::Mode2String(decl->mode())); | 1429 AddAttribute("mode", Variable::Mode2String(decl->mode())); |
| 1467 } | 1430 } |
| 1468 Visit(decl->proxy()); | 1431 Visit(decl->proxy()); |
| 1469 if (decl->fun() != NULL) Visit(decl->fun()); | 1432 if (decl->fun() != NULL) Visit(decl->fun()); |
| 1470 } | 1433 } |
| 1471 | 1434 |
| 1472 | 1435 |
| 1473 #endif // DEBUG | 1436 #endif // DEBUG |
| 1474 | 1437 |
| 1475 } } // namespace v8::internal | 1438 } } // namespace v8::internal |
| OLD | NEW |