| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) { | 277 void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) { |
| 278 Print("[ "); | 278 Print("[ "); |
| 279 for (int i = 0; i < node->values()->length(); i++) { | 279 for (int i = 0; i < node->values()->length(); i++) { |
| 280 if (i != 0) Print(","); | 280 if (i != 0) Print(","); |
| 281 Visit(node->values()->at(i)); | 281 Visit(node->values()->at(i)); |
| 282 } | 282 } |
| 283 Print(" ]"); | 283 Print(" ]"); |
| 284 } | 284 } |
| 285 | 285 |
| 286 | 286 |
| 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) { | 287 void PrettyPrinter::VisitVariableProxy(VariableProxy* node) { |
| 310 PrintLiteral(node->name(), false); | 288 PrintLiteral(node->name(), false); |
| 311 } | 289 } |
| 312 | 290 |
| 313 | 291 |
| 314 void PrettyPrinter::VisitAssignment(Assignment* node) { | 292 void PrettyPrinter::VisitAssignment(Assignment* node) { |
| 315 Visit(node->target()); | 293 Visit(node->target()); |
| 316 Print(" %s ", Token::String(node->op())); | 294 Print(" %s ", Token::String(node->op())); |
| 317 Visit(node->value()); | 295 Visit(node->value()); |
| 318 } | 296 } |
| (...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"; | 722 const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; |
| 745 IndentedScope indent(this, block_txt); | 723 IndentedScope indent(this, block_txt); |
| 746 PrintStatements(node->statements()); | 724 PrintStatements(node->statements()); |
| 747 } | 725 } |
| 748 | 726 |
| 749 | 727 |
| 750 void AstPrinter::VisitDeclaration(Declaration* node) { | 728 void AstPrinter::VisitDeclaration(Declaration* node) { |
| 751 if (node->fun() == NULL) { | 729 if (node->fun() == NULL) { |
| 752 // var or const declarations | 730 // var or const declarations |
| 753 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), | 731 PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
| 754 node->proxy()->AsVariable(), | 732 node->proxy()->var(), |
| 755 node->proxy()->name()); | 733 node->proxy()->name()); |
| 756 } else { | 734 } else { |
| 757 // function declarations | 735 // function declarations |
| 758 PrintIndented("FUNCTION "); | 736 PrintIndented("FUNCTION "); |
| 759 PrintLiteral(node->proxy()->name(), true); | 737 PrintLiteral(node->proxy()->name(), true); |
| 760 Print(" = function "); | 738 Print(" = function "); |
| 761 PrintLiteral(node->fun()->name(), false); | 739 PrintLiteral(node->fun()->name(), false); |
| 762 Print("\n"); | 740 Print("\n"); |
| 763 } | 741 } |
| 764 } | 742 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 IndentedScope indent(this, "ARRAY LITERAL"); | 930 IndentedScope indent(this, "ARRAY LITERAL"); |
| 953 if (node->values()->length() > 0) { | 931 if (node->values()->length() > 0) { |
| 954 IndentedScope indent(this, "VALUES"); | 932 IndentedScope indent(this, "VALUES"); |
| 955 for (int i = 0; i < node->values()->length(); i++) { | 933 for (int i = 0; i < node->values()->length(); i++) { |
| 956 Visit(node->values()->at(i)); | 934 Visit(node->values()->at(i)); |
| 957 } | 935 } |
| 958 } | 936 } |
| 959 } | 937 } |
| 960 | 938 |
| 961 | 939 |
| 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) { | 940 void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
| 970 PrintLiteralWithModeIndented("VAR PROXY", node->AsVariable(), node->name()); | |
| 971 Variable* var = node->var(); | 941 Variable* var = node->var(); |
| 972 if (var != NULL && var->rewrite() != NULL) { | 942 PrintLiteralWithModeIndented("VAR PROXY", var, node->name()); |
| 973 IndentedScope indent(this); | 943 { IndentedScope indent(this); |
| 974 Visit(var->rewrite()); | 944 switch (var->location()) { |
| 945 case Variable::UNALLOCATED: |
| 946 break; |
| 947 case Variable::PARAMETER: |
| 948 Print("parameter[%d]", var->index()); |
| 949 break; |
| 950 case Variable::LOCAL: |
| 951 Print("local[%d]", var->index()); |
| 952 break; |
| 953 case Variable::CONTEXT: |
| 954 Print("context[%d]", var->index()); |
| 955 break; |
| 956 case Variable::LOOKUP: |
| 957 Print("lookup"); |
| 958 break; |
| 959 } |
| 975 } | 960 } |
| 976 } | 961 } |
| 977 | 962 |
| 978 | 963 |
| 979 void AstPrinter::VisitAssignment(Assignment* node) { | 964 void AstPrinter::VisitAssignment(Assignment* node) { |
| 980 IndentedScope indent(this, Token::Name(node->op()), node); | 965 IndentedScope indent(this, Token::Name(node->op()), node); |
| 981 Visit(node->target()); | 966 Visit(node->target()); |
| 982 Visit(node->value()); | 967 Visit(node->value()); |
| 983 } | 968 } |
| 984 | 969 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 SharedFunctionInfoLiteral* expr) { | 1265 SharedFunctionInfoLiteral* expr) { |
| 1281 TagScope tag(this, "SharedFunctionInfoLiteral"); | 1266 TagScope tag(this, "SharedFunctionInfoLiteral"); |
| 1282 } | 1267 } |
| 1283 | 1268 |
| 1284 | 1269 |
| 1285 void JsonAstBuilder::VisitConditional(Conditional* expr) { | 1270 void JsonAstBuilder::VisitConditional(Conditional* expr) { |
| 1286 TagScope tag(this, "Conditional"); | 1271 TagScope tag(this, "Conditional"); |
| 1287 } | 1272 } |
| 1288 | 1273 |
| 1289 | 1274 |
| 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) { | 1275 void JsonAstBuilder::VisitVariableProxy(VariableProxy* expr) { |
| 1314 if (expr->var()->rewrite() == NULL) { | 1276 TagScope tag(this, "Variable"); |
| 1315 TagScope tag(this, "VariableProxy"); | 1277 { |
| 1316 { | 1278 AttributesScope attributes(this); |
| 1317 AttributesScope attributes(this); | 1279 Variable* var = expr->var(); |
| 1318 AddAttribute("name", expr->name()); | 1280 AddAttribute("name", var->name()); |
| 1319 AddAttribute("mode", Variable::Mode2String(expr->var()->mode())); | 1281 switch (var->location()) { |
| 1282 case Variable::UNALLOCATED: |
| 1283 AddAttribute("location", "UNALLOCATED"); |
| 1284 break; |
| 1285 case Variable::PARAMETER: |
| 1286 AddAttribute("location", "PARAMETER"); |
| 1287 AddAttribute("index", var->index()); |
| 1288 break; |
| 1289 case Variable::LOCAL: |
| 1290 AddAttribute("location", "LOCAL"); |
| 1291 AddAttribute("index", var->index()); |
| 1292 break; |
| 1293 case Variable::CONTEXT: |
| 1294 AddAttribute("location", "CONTEXT"); |
| 1295 AddAttribute("index", var->index()); |
| 1296 break; |
| 1297 case Variable::LOOKUP: |
| 1298 AddAttribute("location", "LOOKUP"); |
| 1299 break; |
| 1320 } | 1300 } |
| 1321 } else { | |
| 1322 Visit(expr->var()->rewrite()); | |
| 1323 } | 1301 } |
| 1324 } | 1302 } |
| 1325 | 1303 |
| 1326 | 1304 |
| 1327 void JsonAstBuilder::VisitLiteral(Literal* expr) { | 1305 void JsonAstBuilder::VisitLiteral(Literal* expr) { |
| 1328 TagScope tag(this, "Literal"); | 1306 TagScope tag(this, "Literal"); |
| 1329 { | 1307 { |
| 1330 AttributesScope attributes(this); | 1308 AttributesScope attributes(this); |
| 1331 Handle<Object> handle = expr->handle(); | 1309 Handle<Object> handle = expr->handle(); |
| 1332 if (handle->IsString()) { | 1310 if (handle->IsString()) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 AddAttribute("mode", Variable::Mode2String(decl->mode())); | 1444 AddAttribute("mode", Variable::Mode2String(decl->mode())); |
| 1467 } | 1445 } |
| 1468 Visit(decl->proxy()); | 1446 Visit(decl->proxy()); |
| 1469 if (decl->fun() != NULL) Visit(decl->fun()); | 1447 if (decl->fun() != NULL) Visit(decl->fun()); |
| 1470 } | 1448 } |
| 1471 | 1449 |
| 1472 | 1450 |
| 1473 #endif // DEBUG | 1451 #endif // DEBUG |
| 1474 | 1452 |
| 1475 } } // namespace v8::internal | 1453 } } // namespace v8::internal |
| OLD | NEW |