| 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/log.h" | 8 #include "vm/log.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| 11 #include "vm/parser.h" | 11 #include "vm/parser.h" |
| 12 | 12 |
| 13 #if !defined(PRODUCT) | 13 #if !defined(PRODUCT) |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 AstPrinter::AstPrinter() : indent_(0) { } | 17 AstPrinter::AstPrinter(bool log) |
| 18 : indent_(0), |
| 19 logger_(log ? Log::Current() : Log::NoOpLog()) { } |
| 18 | 20 |
| 19 | 21 |
| 20 AstPrinter::~AstPrinter() { } | 22 AstPrinter::~AstPrinter() { } |
| 21 | 23 |
| 22 | 24 |
| 23 void AstPrinter::VisitGenericAstNode(AstNode* node) { | 25 void AstPrinter::VisitGenericAstNode(AstNode* node) { |
| 24 THR_Print("(%s ", node->Name()); | 26 logger_->Print("(%s ", node->Name()); |
| 25 node->VisitChildren(this); | 27 node->VisitChildren(this); |
| 26 THR_Print(")"); | 28 logger_->Print(")"); |
| 27 } | 29 } |
| 28 | 30 |
| 29 | 31 |
| 30 void AstPrinter::VisitSequenceNode(SequenceNode* node) { | 32 void AstPrinter::VisitSequenceNode(SequenceNode* node) { |
| 31 indent_++; | 33 indent_++; |
| 32 LocalScope* scope = node->scope(); | 34 LocalScope* scope = node->scope(); |
| 33 THR_Print("(%s (scope \"%p\"", node->Name(), scope); | 35 logger_->Print("(%s (scope \"%p\"", node->Name(), scope); |
| 34 if (scope != NULL) { | 36 if (scope != NULL) { |
| 35 THR_Print(" (%s-%s) loop %d", | 37 logger_->Print(" (%s-%s) loop %d", |
| 36 scope->begin_token_pos().ToCString(), | 38 scope->begin_token_pos().ToCString(), |
| 37 scope->end_token_pos().ToCString(), | 39 scope->end_token_pos().ToCString(), |
| 38 scope->loop_level()); | 40 scope->loop_level()); |
| 39 if (scope->HasContextLevel()) { | 41 if (scope->HasContextLevel()) { |
| 40 THR_Print(" context %d captures %d", | 42 logger_->Print(" context %d captures %d", |
| 41 scope->context_level(), | 43 scope->context_level(), |
| 42 scope->num_context_variables()); | 44 scope->num_context_variables()); |
| 43 } else { | 45 } else { |
| 44 ASSERT(scope->num_context_variables() == 0); | 46 ASSERT(scope->num_context_variables() == 0); |
| 45 } | 47 } |
| 46 } | 48 } |
| 47 THR_Print(")"); | 49 logger_->Print(")"); |
| 48 for (int i = 0; i < node->length(); ++i) { | 50 for (int i = 0; i < node->length(); ++i) { |
| 49 THR_Print("\n"); | 51 logger_->Print("\n"); |
| 50 for (intptr_t p = 0; p < indent_; p++) { | 52 for (intptr_t p = 0; p < indent_; p++) { |
| 51 THR_Print(" "); | 53 logger_->Print(" "); |
| 52 } | 54 } |
| 53 node->NodeAt(i)->Visit(this); | 55 node->NodeAt(i)->Visit(this); |
| 54 } | 56 } |
| 55 THR_Print(")"); | 57 logger_->Print(")"); |
| 56 indent_--; | 58 indent_--; |
| 57 } | 59 } |
| 58 | 60 |
| 59 | 61 |
| 60 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { | 62 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { |
| 61 VisitGenericAstNode(node); | 63 VisitGenericAstNode(node); |
| 62 } | 64 } |
| 63 | 65 |
| 64 | 66 |
| 65 void AstPrinter::VisitArgumentListNode(ArgumentListNode* arguments) { | 67 void AstPrinter::VisitArgumentListNode(ArgumentListNode* arguments) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 case ReturnNode::kContinuationTarget: | 78 case ReturnNode::kContinuationTarget: |
| 77 kind = "continuation-target "; | 79 kind = "continuation-target "; |
| 78 break; | 80 break; |
| 79 case ReturnNode::kRegular: | 81 case ReturnNode::kRegular: |
| 80 kind = ""; | 82 kind = ""; |
| 81 break; | 83 break; |
| 82 default: | 84 default: |
| 83 kind = ""; | 85 kind = ""; |
| 84 UNREACHABLE(); | 86 UNREACHABLE(); |
| 85 } | 87 } |
| 86 THR_Print("(%s %s", node->Name(), kind); | 88 logger_->Print("(%s %s", node->Name(), kind); |
| 87 node->VisitChildren(this); | 89 node->VisitChildren(this); |
| 88 THR_Print(")"); | 90 logger_->Print(")"); |
| 89 } | 91 } |
| 90 | 92 |
| 91 | 93 |
| 92 void AstPrinter::VisitGenericLocalNode(AstNode* node, | 94 void AstPrinter::VisitGenericLocalNode(AstNode* node, |
| 93 const LocalVariable& var) { | 95 const LocalVariable& var) { |
| 94 THR_Print("(%s %s%s \"%s\"", | 96 logger_->Print("(%s %s%s \"%s\"", |
| 95 node->Name(), | 97 node->Name(), |
| 96 var.is_final() ? "final " : "", | 98 var.is_final() ? "final " : "", |
| 97 String::Handle(var.type().Name()).ToCString(), | 99 String::Handle(var.type().Name()).ToCString(), |
| 98 var.name().ToCString()); | 100 var.name().ToCString()); |
| 99 if (var.HasIndex()) { | 101 if (var.HasIndex()) { |
| 100 if (var.is_captured()) { | 102 if (var.is_captured()) { |
| 101 THR_Print(" (context %d %d)", var.owner()->context_level(), var.index()); | 103 logger_->Print(" (context %d %d)", |
| 104 var.owner()->context_level(), |
| 105 var.index()); |
| 102 } else { | 106 } else { |
| 103 THR_Print(" (stack %d)", var.index()); | 107 logger_->Print(" (stack %d)", var.index()); |
| 104 } | 108 } |
| 105 } | 109 } |
| 106 THR_Print(" "); | 110 logger_->Print(" "); |
| 107 node->VisitChildren(this); | 111 node->VisitChildren(this); |
| 108 THR_Print(")"); | 112 logger_->Print(")"); |
| 109 } | 113 } |
| 110 | 114 |
| 111 | 115 |
| 112 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { | 116 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { |
| 113 VisitGenericLocalNode(node, node->local()); | 117 VisitGenericLocalNode(node, node->local()); |
| 114 } | 118 } |
| 115 | 119 |
| 116 | 120 |
| 117 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { | 121 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { |
| 118 VisitGenericLocalNode(node, node->local()); | 122 VisitGenericLocalNode(node, node->local()); |
| 119 } | 123 } |
| 120 | 124 |
| 121 | 125 |
| 122 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { | 126 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { |
| 123 THR_Print("(%s %s%s \"%s\" ", | 127 logger_->Print("(%s %s%s \"%s\" ", |
| 124 node->Name(), | 128 node->Name(), |
| 125 field.is_final() ? "final " : "", | 129 field.is_final() ? "final " : "", |
| 126 String::Handle(AbstractType::Handle(field.type()).Name()). | 130 String::Handle(AbstractType::Handle(field.type()).Name()). |
| 127 ToCString(), | 131 ToCString(), |
| 128 String::Handle(field.name()).ToCString()); | 132 String::Handle(field.name()).ToCString()); |
| 129 node->VisitChildren(this); | 133 node->VisitChildren(this); |
| 130 THR_Print(")"); | 134 logger_->Print(")"); |
| 131 } | 135 } |
| 132 | 136 |
| 133 | 137 |
| 134 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { | 138 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { |
| 135 VisitGenericFieldNode(node, node->field()); | 139 VisitGenericFieldNode(node, node->field()); |
| 136 } | 140 } |
| 137 | 141 |
| 138 | 142 |
| 139 void AstPrinter::VisitStoreInstanceFieldNode(StoreInstanceFieldNode* node) { | 143 void AstPrinter::VisitStoreInstanceFieldNode(StoreInstanceFieldNode* node) { |
| 140 VisitGenericFieldNode(node, Field::ZoneHandle(node->field().Original())); | 144 VisitGenericFieldNode(node, Field::ZoneHandle(node->field().Original())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 161 } | 165 } |
| 162 | 166 |
| 163 | 167 |
| 164 void AstPrinter::VisitStringInterpolateNode(StringInterpolateNode* node) { | 168 void AstPrinter::VisitStringInterpolateNode(StringInterpolateNode* node) { |
| 165 VisitGenericAstNode(node); | 169 VisitGenericAstNode(node); |
| 166 } | 170 } |
| 167 | 171 |
| 168 | 172 |
| 169 void AstPrinter::VisitLiteralNode(LiteralNode* node) { | 173 void AstPrinter::VisitLiteralNode(LiteralNode* node) { |
| 170 const Instance& literal = node->literal(); | 174 const Instance& literal = node->literal(); |
| 171 THR_Print("(%s \"%s\")", node->Name(), literal.ToCString()); | 175 logger_->Print("(%s \"%s\")", node->Name(), literal.ToCString()); |
| 172 } | 176 } |
| 173 | 177 |
| 174 | 178 |
| 175 void AstPrinter::VisitTypeNode(TypeNode* node) { | 179 void AstPrinter::VisitTypeNode(TypeNode* node) { |
| 176 const AbstractType& type = node->type(); | 180 const AbstractType& type = node->type(); |
| 177 THR_Print("(%s \"%s\")", | 181 logger_->Print("(%s \"%s\")", |
| 178 node->Name(), | 182 node->Name(), |
| 179 String::Handle(type.Name()).ToCString()); | 183 String::Handle(type.Name()).ToCString()); |
| 180 } | 184 } |
| 181 | 185 |
| 182 | 186 |
| 183 void AstPrinter::VisitAssignableNode(AssignableNode* node) { | 187 void AstPrinter::VisitAssignableNode(AssignableNode* node) { |
| 184 const AbstractType& type = node->type(); | 188 const AbstractType& type = node->type(); |
| 185 const String& dst_name = node->dst_name(); | 189 const String& dst_name = node->dst_name(); |
| 186 THR_Print("(%s (type \"%s\") (of \"%s\") ", | 190 logger_->Print("(%s (type \"%s\") (of \"%s\") ", |
| 187 node->Name(), | 191 node->Name(), |
| 188 String::Handle(type.Name()).ToCString(), | 192 String::Handle(type.Name()).ToCString(), |
| 189 dst_name.ToCString()); | 193 dst_name.ToCString()); |
| 190 node->VisitChildren(this); | 194 node->VisitChildren(this); |
| 191 THR_Print(")"); | 195 logger_->Print(")"); |
| 192 } | 196 } |
| 193 | 197 |
| 194 | 198 |
| 195 void AstPrinter::VisitAwaitNode(AwaitNode* node) { | 199 void AstPrinter::VisitAwaitNode(AwaitNode* node) { |
| 196 THR_Print("(*****%s***** (scope \"%p\") ", node->Name(), node->scope()); | 200 logger_->Print("(*****%s***** (scope \"%p\") ", node->Name(), node->scope()); |
| 197 node->VisitChildren(this); | 201 node->VisitChildren(this); |
| 198 THR_Print(")"); | 202 logger_->Print(")"); |
| 199 } | 203 } |
| 200 | 204 |
| 201 | 205 |
| 202 void AstPrinter::VisitAwaitMarkerNode(AwaitMarkerNode* node) { | 206 void AstPrinter::VisitAwaitMarkerNode(AwaitMarkerNode* node) { |
| 203 THR_Print("(%s (async_scope \"%p\" await_scope \"%p\"))", | 207 logger_->Print("(%s (async_scope \"%p\" await_scope \"%p\"))", |
| 204 node->Name(), | 208 node->Name(), |
| 205 node->async_scope(), | 209 node->async_scope(), |
| 206 node->await_scope()); | 210 node->await_scope()); |
| 207 } | 211 } |
| 208 | 212 |
| 209 | 213 |
| 210 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { | 214 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { |
| 211 THR_Print("(*****%s***** \"%s\")", | 215 logger_->Print("(*****%s***** \"%s\")", |
| 212 node->Name(), | 216 node->Name(), |
| 213 node->primary().ToCString()); | 217 node->primary().ToCString()); |
| 214 } | 218 } |
| 215 | 219 |
| 216 | 220 |
| 217 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { | 221 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { |
| 218 THR_Print("(%s %s ", node->Name(), node->TokenName()); | 222 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 219 node->VisitChildren(this); | 223 node->VisitChildren(this); |
| 220 THR_Print(")"); | 224 logger_->Print(")"); |
| 221 } | 225 } |
| 222 | 226 |
| 223 | 227 |
| 224 void AstPrinter::VisitBinaryOpNode(BinaryOpNode* node) { | 228 void AstPrinter::VisitBinaryOpNode(BinaryOpNode* node) { |
| 225 THR_Print("(%s %s ", node->Name(), node->TokenName()); | 229 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 226 node->VisitChildren(this); | 230 node->VisitChildren(this); |
| 227 THR_Print(")"); | 231 logger_->Print(")"); |
| 228 } | 232 } |
| 229 | 233 |
| 230 | 234 |
| 231 void AstPrinter::VisitUnaryOpNode(UnaryOpNode* node) { | 235 void AstPrinter::VisitUnaryOpNode(UnaryOpNode* node) { |
| 232 THR_Print("(%s %s ", node->Name(), node->TokenName()); | 236 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 233 node->VisitChildren(this); | 237 node->VisitChildren(this); |
| 234 THR_Print(")"); | 238 logger_->Print(")"); |
| 235 } | 239 } |
| 236 | 240 |
| 237 | 241 |
| 238 void AstPrinter::VisitConditionalExprNode(ConditionalExprNode* node) { | 242 void AstPrinter::VisitConditionalExprNode(ConditionalExprNode* node) { |
| 239 VisitGenericAstNode(node); | 243 VisitGenericAstNode(node); |
| 240 } | 244 } |
| 241 | 245 |
| 242 | 246 |
| 243 void AstPrinter::VisitIfNode(IfNode* node) { | 247 void AstPrinter::VisitIfNode(IfNode* node) { |
| 244 VisitGenericAstNode(node); | 248 VisitGenericAstNode(node); |
| 245 } | 249 } |
| 246 | 250 |
| 247 | 251 |
| 248 void AstPrinter::VisitCaseNode(CaseNode* node) { | 252 void AstPrinter::VisitCaseNode(CaseNode* node) { |
| 249 THR_Print("(%s (", node->Name()); | 253 logger_->Print("(%s (", node->Name()); |
| 250 for (int i = 0; i < node->case_expressions()->length(); i++) { | 254 for (int i = 0; i < node->case_expressions()->length(); i++) { |
| 251 node->case_expressions()->NodeAt(i)->Visit(this); | 255 node->case_expressions()->NodeAt(i)->Visit(this); |
| 252 } | 256 } |
| 253 if (node->contains_default()) { | 257 if (node->contains_default()) { |
| 254 THR_Print(" default"); | 258 logger_->Print(" default"); |
| 255 } | 259 } |
| 256 THR_Print(")"); | 260 logger_->Print(")"); |
| 257 node->statements()->Visit(this); | 261 node->statements()->Visit(this); |
| 258 THR_Print(")"); | 262 logger_->Print(")"); |
| 259 } | 263 } |
| 260 | 264 |
| 261 | 265 |
| 262 void AstPrinter::VisitSwitchNode(SwitchNode* node) { | 266 void AstPrinter::VisitSwitchNode(SwitchNode* node) { |
| 263 VisitGenericAstNode(node); | 267 VisitGenericAstNode(node); |
| 264 } | 268 } |
| 265 | 269 |
| 266 | 270 |
| 267 void AstPrinter::VisitWhileNode(WhileNode* node) { | 271 void AstPrinter::VisitWhileNode(WhileNode* node) { |
| 268 VisitGenericAstNode(node); | 272 VisitGenericAstNode(node); |
| 269 } | 273 } |
| 270 | 274 |
| 271 | 275 |
| 272 void AstPrinter::VisitForNode(ForNode* node) { | 276 void AstPrinter::VisitForNode(ForNode* node) { |
| 273 // Complicated because the condition is optional and so we clearly want to | 277 // Complicated because the condition is optional and so we clearly want to |
| 274 // indicate the subparts. | 278 // indicate the subparts. |
| 275 THR_Print("(%s (init ", node->Name()); | 279 logger_->Print("(%s (init ", node->Name()); |
| 276 node->initializer()->Visit(this); | 280 node->initializer()->Visit(this); |
| 277 if (node->condition() != NULL) { | 281 if (node->condition() != NULL) { |
| 278 THR_Print(") (cond "); | 282 logger_->Print(") (cond "); |
| 279 node->condition()->Visit(this); | 283 node->condition()->Visit(this); |
| 280 } | 284 } |
| 281 THR_Print(") (update "); | 285 logger_->Print(") (update "); |
| 282 node->increment()->Visit(this); | 286 node->increment()->Visit(this); |
| 283 THR_Print(") "); | 287 logger_->Print(") "); |
| 284 node->body()->Visit(this); | 288 node->body()->Visit(this); |
| 285 THR_Print(")"); | 289 logger_->Print(")"); |
| 286 } | 290 } |
| 287 | 291 |
| 288 | 292 |
| 289 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { | 293 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { |
| 290 VisitGenericAstNode(node); | 294 VisitGenericAstNode(node); |
| 291 } | 295 } |
| 292 | 296 |
| 293 | 297 |
| 294 void AstPrinter::VisitJumpNode(JumpNode* node) { | 298 void AstPrinter::VisitJumpNode(JumpNode* node) { |
| 295 THR_Print("(%s %s %s (scope \"%p\"))", | 299 logger_->Print("(%s %s %s (scope \"%p\"))", |
| 296 node->Name(), | 300 node->Name(), |
| 297 node->TokenName(), | 301 node->TokenName(), |
| 298 node->label()->name().ToCString(), | 302 node->label()->name().ToCString(), |
| 299 node->label()->owner()); | 303 node->label()->owner()); |
| 300 } | 304 } |
| 301 | 305 |
| 302 | 306 |
| 303 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { | 307 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { |
| 304 THR_Print("(%s \"%s\" ", | 308 logger_->Print("(%s \"%s\" ", |
| 305 node->Name(), | 309 node->Name(), |
| 306 node->function_name().ToCString()); | 310 node->function_name().ToCString()); |
| 307 node->VisitChildren(this); | 311 node->VisitChildren(this); |
| 308 THR_Print(")"); | 312 logger_->Print(")"); |
| 309 } | 313 } |
| 310 | 314 |
| 311 | 315 |
| 312 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { | 316 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { |
| 313 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 317 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 314 THR_Print("(%s \"%s\" ", node->Name(), function_fullname); | 318 logger_->Print("(%s \"%s\" ", node->Name(), function_fullname); |
| 315 node->VisitChildren(this); | 319 node->VisitChildren(this); |
| 316 THR_Print(")"); | 320 logger_->Print(")"); |
| 317 } | 321 } |
| 318 | 322 |
| 319 | 323 |
| 320 void AstPrinter::VisitClosureNode(ClosureNode* node) { | 324 void AstPrinter::VisitClosureNode(ClosureNode* node) { |
| 321 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 325 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 322 THR_Print("(%s \"%s\")", node->Name(), function_fullname); | 326 logger_->Print("(%s \"%s\")", node->Name(), function_fullname); |
| 323 } | 327 } |
| 324 | 328 |
| 325 | 329 |
| 326 void AstPrinter::VisitClosureCallNode(ClosureCallNode* node) { | 330 void AstPrinter::VisitClosureCallNode(ClosureCallNode* node) { |
| 327 VisitGenericAstNode(node); | 331 VisitGenericAstNode(node); |
| 328 } | 332 } |
| 329 | 333 |
| 330 | 334 |
| 331 void AstPrinter::VisitConstructorCallNode(ConstructorCallNode* node) { | 335 void AstPrinter::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 332 const char* kind = node->constructor().IsFactory() ? "factory " : ""; | 336 const char* kind = node->constructor().IsFactory() ? "factory " : ""; |
| 333 const char* constructor_name = node->constructor().ToFullyQualifiedCString(); | 337 const char* constructor_name = node->constructor().ToFullyQualifiedCString(); |
| 334 THR_Print("(%s %s \"%s\" ", node->Name(), kind, constructor_name); | 338 logger_->Print("(%s %s \"%s\" ", node->Name(), kind, constructor_name); |
| 335 node->VisitChildren(this); | 339 node->VisitChildren(this); |
| 336 THR_Print(")"); | 340 logger_->Print(")"); |
| 337 } | 341 } |
| 338 | 342 |
| 339 | 343 |
| 340 void AstPrinter::VisitInstanceGetterNode(InstanceGetterNode* node) { | 344 void AstPrinter::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 341 THR_Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); | 345 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); |
| 342 node->VisitChildren(this); | 346 node->VisitChildren(this); |
| 343 THR_Print(")"); | 347 logger_->Print(")"); |
| 344 } | 348 } |
| 345 | 349 |
| 346 | 350 |
| 347 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { | 351 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { |
| 348 THR_Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); | 352 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); |
| 349 node->VisitChildren(this); | 353 node->VisitChildren(this); |
| 350 THR_Print(")"); | 354 logger_->Print(")"); |
| 351 } | 355 } |
| 352 | 356 |
| 353 | 357 |
| 354 void AstPrinter::VisitInitStaticFieldNode(InitStaticFieldNode* node) { | 358 void AstPrinter::VisitInitStaticFieldNode(InitStaticFieldNode* node) { |
| 355 THR_Print("(%s \"%s\")", | 359 logger_->Print("(%s \"%s\")", |
| 356 node->Name(), | 360 node->Name(), |
| 357 String::Handle(node->field().name()).ToCString()); | 361 String::Handle(node->field().name()).ToCString()); |
| 358 } | 362 } |
| 359 | 363 |
| 360 | 364 |
| 361 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { | 365 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { |
| 362 String& class_name = String::Handle(node->cls().Name()); | 366 String& class_name = String::Handle(node->cls().Name()); |
| 363 THR_Print("(%s \"%s.%s\")", | 367 logger_->Print("(%s \"%s.%s\")", |
| 364 node->Name(), | 368 node->Name(), |
| 365 class_name.ToCString(), | 369 class_name.ToCString(), |
| 366 node->field_name().ToCString()); | 370 node->field_name().ToCString()); |
| 367 } | 371 } |
| 368 | 372 |
| 369 | 373 |
| 370 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { | 374 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { |
| 371 String& class_name = String::Handle(node->cls().Name()); | 375 String& class_name = String::Handle(node->cls().Name()); |
| 372 THR_Print("(%s \"%s.%s\" ", | 376 logger_->Print("(%s \"%s.%s\" ", |
| 373 node->Name(), | 377 node->Name(), |
| 374 class_name.ToCString(), | 378 class_name.ToCString(), |
| 375 node->field_name().ToCString()); | 379 node->field_name().ToCString()); |
| 376 node->VisitChildren(this); | 380 node->VisitChildren(this); |
| 377 THR_Print(")"); | 381 logger_->Print(")"); |
| 378 } | 382 } |
| 379 | 383 |
| 380 | 384 |
| 381 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { | 385 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { |
| 382 THR_Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); | 386 logger_->Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); |
| 383 node->VisitChildren(this); | 387 node->VisitChildren(this); |
| 384 THR_Print(")"); | 388 logger_->Print(")"); |
| 385 } | 389 } |
| 386 | 390 |
| 387 | 391 |
| 388 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { | 392 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { |
| 389 THR_Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); | 393 logger_->Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); |
| 390 node->VisitChildren(this); | 394 node->VisitChildren(this); |
| 391 THR_Print(")"); | 395 logger_->Print(")"); |
| 392 } | 396 } |
| 393 | 397 |
| 394 | 398 |
| 395 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { | 399 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { |
| 396 THR_Print("(%s \"%s\" (%" Pd " args))", | 400 logger_->Print("(%s \"%s\" (%" Pd " args))", |
| 397 node->Name(), | 401 node->Name(), |
| 398 node->native_c_function_name().ToCString(), | 402 node->native_c_function_name().ToCString(), |
| 399 NativeArguments::ParameterCountForResolution(node->function())); | 403 NativeArguments::ParameterCountForResolution(node->function())); |
| 400 } | 404 } |
| 401 | 405 |
| 402 | 406 |
| 403 void AstPrinter::VisitCatchClauseNode(CatchClauseNode* node) { | 407 void AstPrinter::VisitCatchClauseNode(CatchClauseNode* node) { |
| 404 VisitGenericAstNode(node); | 408 VisitGenericAstNode(node); |
| 405 } | 409 } |
| 406 | 410 |
| 407 | 411 |
| 408 void AstPrinter::VisitTryCatchNode(TryCatchNode* node) { | 412 void AstPrinter::VisitTryCatchNode(TryCatchNode* node) { |
| 409 THR_Print("(%s ", node->Name()); | 413 logger_->Print("(%s ", node->Name()); |
| 410 node->try_block()->Visit(this); | 414 node->try_block()->Visit(this); |
| 411 node->catch_block()->Visit(this); | 415 node->catch_block()->Visit(this); |
| 412 if (node->finally_block() != NULL) { | 416 if (node->finally_block() != NULL) { |
| 413 THR_Print("(finally "); | 417 logger_->Print("(finally "); |
| 414 node->finally_block()->Visit(this); | 418 node->finally_block()->Visit(this); |
| 415 THR_Print(")"); | 419 logger_->Print(")"); |
| 416 } | 420 } |
| 417 THR_Print(")"); | 421 logger_->Print(")"); |
| 418 } | 422 } |
| 419 | 423 |
| 420 | 424 |
| 421 void AstPrinter::VisitThrowNode(ThrowNode* node) { | 425 void AstPrinter::VisitThrowNode(ThrowNode* node) { |
| 422 VisitGenericAstNode(node); | 426 VisitGenericAstNode(node); |
| 423 } | 427 } |
| 424 | 428 |
| 425 | 429 |
| 426 void AstPrinter::VisitStopNode(StopNode* node) { | 430 void AstPrinter::VisitStopNode(StopNode* node) { |
| 427 THR_Print("(%s %s)", node->Name(), node->message()); | 431 logger_->Print("(%s %s)", node->Name(), node->message()); |
| 428 } | 432 } |
| 429 | 433 |
| 430 | 434 |
| 431 void AstPrinter::VisitInlinedFinallyNode(InlinedFinallyNode* node) { | 435 void AstPrinter::VisitInlinedFinallyNode(InlinedFinallyNode* node) { |
| 432 VisitGenericAstNode(node); | 436 VisitGenericAstNode(node); |
| 433 } | 437 } |
| 434 | 438 |
| 435 | 439 |
| 436 void AstPrinter::PrintNode(AstNode* node) { | 440 void AstPrinter::PrintNode(AstNode* node) { |
| 437 ASSERT(node != NULL); | 441 ASSERT(node != NULL); |
| 438 AstPrinter ast_printer; | 442 AstPrinter ast_printer; |
| 439 node->Visit(&ast_printer); | 443 node->Visit(&ast_printer); |
| 440 THR_Print("\n"); | 444 logger_->Print("\n"); |
| 441 } | 445 } |
| 442 | 446 |
| 443 | 447 |
| 444 static void IndentN(int count) { | 448 void AstPrinter::IndentN(int count) { |
| 445 for (int i = 0; i < count; i++) { | 449 for (int i = 0; i < count; i++) { |
| 446 THR_Print(" "); | 450 logger_->Print(" "); |
| 447 } | 451 } |
| 448 } | 452 } |
| 449 | 453 |
| 450 | 454 |
| 451 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope, | 455 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope, |
| 452 LocalVariable* var, | 456 LocalVariable* var, |
| 453 int indent) { | 457 int indent) { |
| 454 ASSERT(scope != NULL); | 458 ASSERT(scope != NULL); |
| 455 ASSERT(var != NULL); | 459 ASSERT(var != NULL); |
| 456 IndentN(indent); | 460 IndentN(indent); |
| 457 THR_Print("(%s%s '%s'", | 461 logger_->Print("(%s%s '%s'", |
| 458 var->is_final() ? "final " : "", | 462 var->is_final() ? "final " : "", |
| 459 String::Handle(var->type().Name()).ToCString(), | 463 String::Handle(var->type().Name()).ToCString(), |
| 460 var->name().ToCString()); | 464 var->name().ToCString()); |
| 461 if (var->owner() != scope) { | 465 if (var->owner() != scope) { |
| 462 THR_Print(" alias"); | 466 logger_->Print(" alias"); |
| 463 } | 467 } |
| 464 if (var->HasIndex()) { | 468 if (var->HasIndex()) { |
| 465 THR_Print(" @%d", var->index()); | 469 logger_->Print(" @%d", var->index()); |
| 466 if (var->is_captured()) { | 470 if (var->is_captured()) { |
| 467 THR_Print(" ctx %d", var->owner()->context_level()); | 471 logger_->Print(" ctx %d", var->owner()->context_level()); |
| 468 } | 472 } |
| 469 } else if (var->owner()->function_level() != 0) { | 473 } else if (var->owner()->function_level() != 0) { |
| 470 THR_Print(" lev %d", var->owner()->function_level()); | 474 logger_->Print(" lev %d", var->owner()->function_level()); |
| 471 } | 475 } |
| 472 THR_Print(" valid %s-%s)\n", | 476 logger_->Print(" valid %s-%s)\n", |
| 473 var->token_pos().ToCString(), | 477 var->token_pos().ToCString(), |
| 474 scope->end_token_pos().ToCString()); | 478 scope->end_token_pos().ToCString()); |
| 475 } | 479 } |
| 476 | 480 |
| 477 | 481 |
| 478 void AstPrinter::PrintLocalScope(const LocalScope* scope, | 482 void AstPrinter::PrintLocalScope(const LocalScope* scope, |
| 479 int start_index, | 483 int start_index, |
| 480 int indent) { | 484 int indent) { |
| 481 ASSERT(scope != NULL); | 485 ASSERT(scope != NULL); |
| 482 for (int i = start_index; i < scope->num_variables(); i++) { | 486 for (int i = start_index; i < scope->num_variables(); i++) { |
| 483 LocalVariable* var = scope->VariableAt(i); | 487 LocalVariable* var = scope->VariableAt(i); |
| 484 PrintLocalScopeVariable(scope, var, indent); | 488 PrintLocalScopeVariable(scope, var, indent); |
| 485 } | 489 } |
| 486 const LocalScope* child = scope->child(); | 490 const LocalScope* child = scope->child(); |
| 487 while (child != NULL) { | 491 while (child != NULL) { |
| 488 IndentN(indent); | 492 IndentN(indent); |
| 489 THR_Print("{scope %p ", child); | 493 logger_->Print("{scope %p ", child); |
| 490 if (child->HasContextLevel()) { | 494 if (child->HasContextLevel()) { |
| 491 THR_Print("ctx %d numctxvar %d ", | 495 logger_->Print("ctx %d numctxvar %d ", |
| 492 child->context_level(), | 496 child->context_level(), |
| 493 child->num_context_variables()); | 497 child->num_context_variables()); |
| 494 } | 498 } |
| 495 THR_Print("llev %d\n", child->loop_level()); | 499 logger_->Print("llev %d\n", child->loop_level()); |
| 496 PrintLocalScope(child, 0, indent + kScopeIndent); | 500 PrintLocalScope(child, 0, indent + kScopeIndent); |
| 497 IndentN(indent); | 501 IndentN(indent); |
| 498 THR_Print("}\n"); | 502 logger_->Print("}\n"); |
| 499 child = child->sibling(); | 503 child = child->sibling(); |
| 500 } | 504 } |
| 501 } | 505 } |
| 502 | 506 |
| 503 | 507 |
| 504 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { | 508 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { |
| 505 HANDLESCOPE(parsed_function.thread()); | 509 HANDLESCOPE(parsed_function.thread()); |
| 506 const Function& function = parsed_function.function(); | 510 const Function& function = parsed_function.function(); |
| 507 SequenceNode* node_sequence = parsed_function.node_sequence(); | 511 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 508 ASSERT(node_sequence != NULL); | 512 ASSERT(node_sequence != NULL); |
| 509 const LocalScope* scope = node_sequence->scope(); | 513 const LocalScope* scope = node_sequence->scope(); |
| 510 ASSERT(scope != NULL); | 514 ASSERT(scope != NULL); |
| 511 const char* function_name = function.ToFullyQualifiedCString(); | 515 const char* function_name = function.ToFullyQualifiedCString(); |
| 512 THR_Print("Scope for function '%s'\n{scope %p ", function_name, scope); | 516 logger_->Print("Scope for function '%s'\n{scope %p ", function_name, scope); |
| 513 if (scope->HasContextLevel()) { | 517 if (scope->HasContextLevel()) { |
| 514 THR_Print("ctx %d numctxvar %d ", | 518 logger_->Print("ctx %d numctxvar %d ", |
| 515 scope->context_level(), | 519 scope->context_level(), |
| 516 scope->num_context_variables()); | 520 scope->num_context_variables()); |
| 517 } | 521 } |
| 518 THR_Print("llev %d\n", scope->loop_level()); | 522 logger_->Print("llev %d\n", scope->loop_level()); |
| 519 const int num_fixed_params = function.num_fixed_parameters(); | 523 const int num_fixed_params = function.num_fixed_parameters(); |
| 520 const int num_params = num_fixed_params + function.NumOptionalParameters(); | 524 const int num_params = num_fixed_params + function.NumOptionalParameters(); |
| 521 // Parameters must be listed first and must all appear in the top scope. | 525 // Parameters must be listed first and must all appear in the top scope. |
| 522 ASSERT(num_params <= scope->num_variables()); | 526 ASSERT(num_params <= scope->num_variables()); |
| 523 int pos = 0; // Current position of variable in scope. | 527 int pos = 0; // Current position of variable in scope. |
| 524 int indent = kScopeIndent; | 528 int indent = kScopeIndent; |
| 525 while (pos < num_params) { | 529 while (pos < num_params) { |
| 526 LocalVariable* param = scope->VariableAt(pos); | 530 LocalVariable* param = scope->VariableAt(pos); |
| 527 ASSERT(param->owner() == scope); // No aliases should precede parameters. | 531 ASSERT(param->owner() == scope); // No aliases should precede parameters. |
| 528 IndentN(indent); | 532 IndentN(indent); |
| 529 THR_Print("(param %s%s '%s'", | 533 logger_->Print("(param %s%s '%s'", |
| 530 param->is_final() ? "final " : "", | 534 param->is_final() ? "final " : "", |
| 531 String::Handle(param->type().Name()).ToCString(), | 535 String::Handle(param->type().Name()).ToCString(), |
| 532 param->name().ToCString()); | 536 param->name().ToCString()); |
| 533 // Print the default value if the parameter is optional. | 537 // Print the default value if the parameter is optional. |
| 534 if (pos >= num_fixed_params && pos < num_params) { | 538 if (pos >= num_fixed_params && pos < num_params) { |
| 535 const Instance& default_parameter_value = | 539 const Instance& default_parameter_value = |
| 536 parsed_function.DefaultParameterValueAt(pos - num_fixed_params); | 540 parsed_function.DefaultParameterValueAt(pos - num_fixed_params); |
| 537 THR_Print(" =%s", default_parameter_value.ToCString()); | 541 logger_->Print(" =%s", default_parameter_value.ToCString()); |
| 538 } | 542 } |
| 539 if (param->HasIndex()) { | 543 if (param->HasIndex()) { |
| 540 THR_Print(" @%d", param->index()); | 544 logger_->Print(" @%d", param->index()); |
| 541 if (param->is_captured()) { | 545 if (param->is_captured()) { |
| 542 THR_Print(" ctx %d", param->owner()->context_level()); | 546 logger_->Print(" ctx %d", param->owner()->context_level()); |
| 543 } | 547 } |
| 544 } | 548 } |
| 545 THR_Print(" valid %s-%s)\n", | 549 logger_->Print(" valid %s-%s)\n", |
| 546 param->token_pos().ToCString(), | 550 param->token_pos().ToCString(), |
| 547 scope->end_token_pos().ToCString()); | 551 scope->end_token_pos().ToCString()); |
| 548 pos++; | 552 pos++; |
| 549 } | 553 } |
| 550 // Visit remaining non-parameter variables and children scopes. | 554 // Visit remaining non-parameter variables and children scopes. |
| 551 PrintLocalScope(scope, pos, indent); | 555 PrintLocalScope(scope, pos, indent); |
| 552 THR_Print("}\n"); | 556 logger_->Print("}\n"); |
| 553 } | 557 } |
| 554 | 558 |
| 555 | 559 |
| 556 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { | 560 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { |
| 557 HANDLESCOPE(parsed_function.thread()); | 561 HANDLESCOPE(parsed_function.thread()); |
| 558 SequenceNode* node_sequence = parsed_function.node_sequence(); | 562 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 559 ASSERT(node_sequence != NULL); | 563 ASSERT(node_sequence != NULL); |
| 560 AstPrinter ast_printer; | |
| 561 const char* function_name = | 564 const char* function_name = |
| 562 parsed_function.function().ToFullyQualifiedCString(); | 565 parsed_function.function().ToFullyQualifiedCString(); |
| 563 THR_Print("Ast for function '%s' {\n", function_name); | 566 logger_->Print("Ast for function '%s' {\n", function_name); |
| 564 node_sequence->Visit(&ast_printer); | 567 node_sequence->Visit(this); |
| 565 THR_Print("}\n"); | 568 logger_->Print("}\n"); |
| 566 } | 569 } |
| 567 | 570 |
| 568 } // namespace dart | 571 } // namespace dart |
| 569 | 572 |
| 570 #endif // !defined(PRODUCT) | 573 #endif // !defined(PRODUCT) |
| OLD | NEW |