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