| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/ast_printer.h" | 5 #include "vm/ast_printer.h" |
| 6 | 6 |
| 7 #include "vm/handles.h" | 7 #include "vm/handles.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/os.h" | 9 #include "vm/os.h" |
| 10 #include "vm/parser.h" | 10 #include "vm/parser.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 AstPrinter::AstPrinter() { } | 14 AstPrinter::AstPrinter() { } |
| 15 | 15 |
| 16 | 16 |
| 17 AstPrinter::~AstPrinter() { } | 17 AstPrinter::~AstPrinter() { } |
| 18 | 18 |
| 19 | 19 |
| 20 void AstPrinter::VisitGenericAstNode(AstNode* node) { | 20 void AstPrinter::VisitGenericAstNode(AstNode* node) { |
| 21 OS::Print("(%s ", node->Name()); | 21 OS::Print("(%s ", node->PrettyName()); |
| 22 node->VisitChildren(this); | 22 node->VisitChildren(this); |
| 23 OS::Print(")"); | 23 OS::Print(")"); |
| 24 } | 24 } |
| 25 | 25 |
| 26 | 26 |
| 27 void AstPrinter::VisitSequenceNode(SequenceNode* node_sequence) { | 27 void AstPrinter::VisitSequenceNode(SequenceNode* node_sequence) { |
| 28 // TODO(regis): Make the output more readable by indenting the nested | 28 // TODO(regis): Make the output more readable by indenting the nested |
| 29 // sequences. This could be achieved using a AstPrinterContext similar to the | 29 // sequences. This could be achieved using a AstPrinterContext similar to the |
| 30 // CodeGeneratorContext. | 30 // CodeGeneratorContext. |
| 31 ASSERT(node_sequence != NULL); | 31 ASSERT(node_sequence != NULL); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 | 49 |
| 50 | 50 |
| 51 void AstPrinter::VisitReturnNode(ReturnNode* node) { | 51 void AstPrinter::VisitReturnNode(ReturnNode* node) { |
| 52 VisitGenericAstNode(node); | 52 VisitGenericAstNode(node); |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 void AstPrinter::VisitGenericLocalNode(AstNode* node, | 56 void AstPrinter::VisitGenericLocalNode(AstNode* node, |
| 57 const LocalVariable& var) { | 57 const LocalVariable& var) { |
| 58 OS::Print("(%s %s%s '%s'", | 58 OS::Print("(%s %s%s '%s'", |
| 59 node->Name(), | 59 node->PrettyName(), |
| 60 var.is_final() ? "final " : "", | 60 var.is_final() ? "final " : "", |
| 61 String::Handle(var.type().Name()).ToCString(), | 61 String::Handle(var.type().Name()).ToCString(), |
| 62 var.name().ToCString()); | 62 var.name().ToCString()); |
| 63 if (var.HasIndex()) { | 63 if (var.HasIndex()) { |
| 64 OS::Print(" @%d", var.index()); | 64 OS::Print(" @%d", var.index()); |
| 65 if (var.is_captured()) { | 65 if (var.is_captured()) { |
| 66 OS::Print(" ctx %d", var.owner()->context_level()); | 66 OS::Print(" ctx %d", var.owner()->context_level()); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 node->VisitChildren(this); | 69 node->VisitChildren(this); |
| 70 OS::Print(")"); | 70 OS::Print(")"); |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { | 74 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { |
| 75 VisitGenericLocalNode(node, node->local()); | 75 VisitGenericLocalNode(node, node->local()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { | 79 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { |
| 80 VisitGenericLocalNode(node, node->local()); | 80 VisitGenericLocalNode(node, node->local()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { | 84 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { |
| 85 OS::Print("(%s %s%s '%s' ", | 85 OS::Print("(%s %s%s '%s' ", |
| 86 node->Name(), | 86 node->PrettyName(), |
| 87 field.is_final() ? "final " : "", | 87 field.is_final() ? "final " : "", |
| 88 String::Handle(AbstractType::Handle(field.type()).Name()). | 88 String::Handle(AbstractType::Handle(field.type()).Name()). |
| 89 ToCString(), | 89 ToCString(), |
| 90 String::Handle(field.name()).ToCString()); | 90 String::Handle(field.name()).ToCString()); |
| 91 node->VisitChildren(this); | 91 node->VisitChildren(this); |
| 92 OS::Print(")"); | 92 OS::Print(")"); |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { | 96 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 node->expr()->Visit(this); | 140 node->expr()->Visit(this); |
| 141 const AbstractType& type = node->type(); | 141 const AbstractType& type = node->type(); |
| 142 const String& dst_name = node->dst_name(); | 142 const String& dst_name = node->dst_name(); |
| 143 OS::Print(" to type '%s' of '%s')", | 143 OS::Print(" to type '%s' of '%s')", |
| 144 String::Handle(type.Name()).ToCString(), | 144 String::Handle(type.Name()).ToCString(), |
| 145 dst_name.ToCString()); | 145 dst_name.ToCString()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { | 149 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { |
| 150 OS::Print("***** PRIMARY NODE IN AST ***** (%s '%s')", | 150 OS::Print("***** PRIMARY NODE IN AST ***** (primary '%s')", |
| 151 node->Name(), node->primary().ToCString()); | 151 node->primary().ToCString()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { | 155 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { |
| 156 if (node->kind() == Token::kAS) { | 156 if (node->kind() == Token::kAS) { |
| 157 OS::Print("(as "); | 157 OS::Print("(as "); |
| 158 node->VisitChildren(this); | 158 node->VisitChildren(this); |
| 159 OS::Print(")"); | 159 OS::Print(")"); |
| 160 } else { | 160 } else { |
| 161 VisitGenericAstNode(node); | 161 VisitGenericAstNode(node); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 void AstPrinter::VisitBinaryOpNode(BinaryOpNode* node) { | 166 void AstPrinter::VisitBinaryOpNode(BinaryOpNode* node) { |
| 167 VisitGenericAstNode(node); | 167 VisitGenericAstNode(node); |
| 168 } | 168 } |
| 169 | 169 |
| 170 | 170 |
| 171 void AstPrinter::VisitBinaryOpWithMask32Node(BinaryOpWithMask32Node* node) { | 171 void AstPrinter::VisitBinaryOpWithMask32Node(BinaryOpWithMask32Node* node) { |
| 172 OS::Print("(%s ", node->Name()); | 172 OS::Print("(%s %s", node->PrettyName(), node->TokenName()); |
| 173 node->VisitChildren(this); | 173 node->VisitChildren(this); |
| 174 OS::Print(" & 0x%" Px64 "", node->mask32()); | 174 OS::Print(" & 0x%" Px64 "", node->mask32()); |
| 175 OS::Print(")"); | 175 OS::Print(")"); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 void AstPrinter::VisitUnaryOpNode(UnaryOpNode* node) { | 179 void AstPrinter::VisitUnaryOpNode(UnaryOpNode* node) { |
| 180 VisitGenericAstNode(node); | 180 VisitGenericAstNode(node); |
| 181 } | 181 } |
| 182 | 182 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { | 247 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { |
| 248 OS::Print("(do "); | 248 OS::Print("(do "); |
| 249 node->body()->Visit(this); | 249 node->body()->Visit(this); |
| 250 OS::Print(" while "); | 250 OS::Print(" while "); |
| 251 node->condition()->Visit(this); | 251 node->condition()->Visit(this); |
| 252 OS::Print(")"); | 252 OS::Print(")"); |
| 253 } | 253 } |
| 254 | 254 |
| 255 | 255 |
| 256 void AstPrinter::VisitJumpNode(JumpNode* node) { | 256 void AstPrinter::VisitJumpNode(JumpNode* node) { |
| 257 OS::Print("(%s %s in scope %p)", | 257 OS::Print("(%s %s %s in scope %p)", |
| 258 node->Name(), | 258 node->PrettyName(), |
| 259 node->TokenName(), |
| 259 node->label()->name().ToCString(), | 260 node->label()->name().ToCString(), |
| 260 node->label()->owner()); | 261 node->label()->owner()); |
| 261 } | 262 } |
| 262 | 263 |
| 263 | 264 |
| 264 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { | 265 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { |
| 265 OS::Print("(%s '%s'(", node->Name(), node->function_name().ToCString()); | 266 OS::Print("(%s '%s'(", node->PrettyName(), node->function_name().ToCString()); |
| 266 node->VisitChildren(this); | 267 node->VisitChildren(this); |
| 267 OS::Print("))"); | 268 OS::Print("))"); |
| 268 } | 269 } |
| 269 | 270 |
| 270 | 271 |
| 271 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { | 272 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { |
| 272 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 273 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 273 OS::Print("(%s '%s'(", node->Name(), function_fullname); | 274 OS::Print("(%s '%s'(", node->PrettyName(), function_fullname); |
| 274 node->VisitChildren(this); | 275 node->VisitChildren(this); |
| 275 OS::Print("))"); | 276 OS::Print("))"); |
| 276 } | 277 } |
| 277 | 278 |
| 278 | 279 |
| 279 void AstPrinter::VisitClosureNode(ClosureNode* node) { | 280 void AstPrinter::VisitClosureNode(ClosureNode* node) { |
| 280 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 281 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 281 OS::Print("(%s '%s')", node->Name(), function_fullname); | 282 OS::Print("(%s '%s')", node->PrettyName(), function_fullname); |
| 282 } | 283 } |
| 283 | 284 |
| 284 | 285 |
| 285 void AstPrinter::VisitClosureCallNode(ClosureCallNode* node) { | 286 void AstPrinter::VisitClosureCallNode(ClosureCallNode* node) { |
| 286 VisitGenericAstNode(node); | 287 VisitGenericAstNode(node); |
| 287 } | 288 } |
| 288 | 289 |
| 289 | 290 |
| 290 void AstPrinter::VisitConstructorCallNode(ConstructorCallNode* node) { | 291 void AstPrinter::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 291 const char* kind = node->constructor().IsFactory() ? "factory " : ""; | 292 const char* kind = node->constructor().IsFactory() ? "factory " : ""; |
| 292 const char* constructor_name = node->constructor().ToFullyQualifiedCString(); | 293 const char* constructor_name = node->constructor().ToFullyQualifiedCString(); |
| 293 OS::Print("(%s %s'%s' ((this)", node->Name(), kind, constructor_name); | 294 OS::Print("(%s %s'%s' ((this)", node->PrettyName(), kind, constructor_name); |
| 294 node->VisitChildren(this); | 295 node->VisitChildren(this); |
| 295 OS::Print("))"); | 296 OS::Print("))"); |
| 296 } | 297 } |
| 297 | 298 |
| 298 | 299 |
| 299 void AstPrinter::VisitInstanceGetterNode(InstanceGetterNode* node) { | 300 void AstPrinter::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 300 OS::Print("(%s 'get %s'(", node->Name(), node->field_name().ToCString()); | 301 OS::Print("(%s 'get %s'(", |
| 302 node->PrettyName(), |
| 303 node->field_name().ToCString()); |
| 301 node->VisitChildren(this); | 304 node->VisitChildren(this); |
| 302 OS::Print("))"); | 305 OS::Print("))"); |
| 303 } | 306 } |
| 304 | 307 |
| 305 | 308 |
| 306 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { | 309 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { |
| 307 OS::Print("(%s 'set %s'(", node->Name(), node->field_name().ToCString()); | 310 OS::Print("(%s 'set %s'(", |
| 311 node->PrettyName(), |
| 312 node->field_name().ToCString()); |
| 308 node->VisitChildren(this); | 313 node->VisitChildren(this); |
| 309 OS::Print("))"); | 314 OS::Print("))"); |
| 310 } | 315 } |
| 311 | 316 |
| 312 | 317 |
| 313 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { | 318 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { |
| 314 String& class_name = String::Handle(node->cls().Name()); | 319 String& class_name = String::Handle(node->cls().Name()); |
| 315 OS::Print("(%s '%s.%s'(", | 320 OS::Print("(%s '%s.%s'(", |
| 316 node->Name(), | 321 node->PrettyName(), |
| 317 class_name.ToCString(), | 322 class_name.ToCString(), |
| 318 node->field_name().ToCString()); | 323 node->field_name().ToCString()); |
| 319 OS::Print("))"); | 324 OS::Print("))"); |
| 320 } | 325 } |
| 321 | 326 |
| 322 | 327 |
| 323 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { | 328 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { |
| 324 String& class_name = String::Handle(node->cls().Name()); | 329 String& class_name = String::Handle(node->cls().Name()); |
| 325 OS::Print("(%s '%s.%s'(", | 330 OS::Print("(%s '%s.%s'(", |
| 326 node->Name(), class_name.ToCString(), node->field_name().ToCString()); | 331 node->PrettyName(), |
| 332 class_name.ToCString(), |
| 333 node->field_name().ToCString()); |
| 327 node->VisitChildren(this); | 334 node->VisitChildren(this); |
| 328 OS::Print("))"); | 335 OS::Print("))"); |
| 329 } | 336 } |
| 330 | 337 |
| 331 | 338 |
| 332 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { | 339 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { |
| 333 OS::Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); | 340 OS::Print("(%s%s ", node->PrettyName(), node->IsSuperLoad() ? " super" : ""); |
| 334 node->VisitChildren(this); | 341 node->VisitChildren(this); |
| 335 OS::Print(")"); | 342 OS::Print(")"); |
| 336 } | 343 } |
| 337 | 344 |
| 338 | 345 |
| 339 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { | 346 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { |
| 340 OS::Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); | 347 OS::Print("(%s%s ", node->PrettyName(), node->IsSuperStore() ? " super" : ""); |
| 341 node->VisitChildren(this); | 348 node->VisitChildren(this); |
| 342 OS::Print(")"); | 349 OS::Print(")"); |
| 343 } | 350 } |
| 344 | 351 |
| 345 | 352 |
| 346 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { | 353 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { |
| 347 OS::Print("(native_c call '%s'(%d args))", | 354 OS::Print("(native_c call '%s'(%d args))", |
| 348 node->native_c_function_name().ToCString(), | 355 node->native_c_function_name().ToCString(), |
| 349 NativeArguments::ParameterCountForResolution(node->function())); | 356 NativeArguments::ParameterCountForResolution(node->function())); |
| 350 } | 357 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 ASSERT(node_sequence != NULL); | 504 ASSERT(node_sequence != NULL); |
| 498 AstPrinter ast_printer; | 505 AstPrinter ast_printer; |
| 499 const char* function_name = | 506 const char* function_name = |
| 500 parsed_function.function().ToFullyQualifiedCString(); | 507 parsed_function.function().ToFullyQualifiedCString(); |
| 501 OS::Print("Ast for function '%s' {\n", function_name); | 508 OS::Print("Ast for function '%s' {\n", function_name); |
| 502 node_sequence->Visit(&ast_printer); | 509 node_sequence->Visit(&ast_printer); |
| 503 OS::Print("}\n"); | 510 OS::Print("}\n"); |
| 504 } | 511 } |
| 505 | 512 |
| 506 } // namespace dart | 513 } // namespace dart |
| OLD | NEW |