yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include <stdarg.h> |
| 29 | |
| 30 | #include "v8.h" |
| 31 | |
| 32 | #include "prettyprinter.h" |
| 33 | #include "scopes.h" |
| 34 | #include "platform.h" |
| 35 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 36 | namespace v8 { |
| 37 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
| 39 | #ifdef DEBUG |
| 40 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 41 | PrettyPrinter::PrettyPrinter(Isolate* isolate) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | output_ = NULL; |
| 43 | size_ = 0; |
| 44 | pos_ = 0; |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 45 | InitializeAstVisitor(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | |
| 49 | PrettyPrinter::~PrettyPrinter() { |
| 50 | DeleteArray(output_); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void PrettyPrinter::VisitBlock(Block* node) { |
| 55 | if (!node->is_initializer_block()) Print("{ "); |
| 56 | PrintStatements(node->statements()); |
| 57 | if (node->statements()->length() > 0) Print(" "); |
| 58 | if (!node->is_initializer_block()) Print("}"); |
| 59 | } |
| 60 | |
| 61 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 62 | void PrettyPrinter::VisitVariableDeclaration(VariableDeclaration* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | Print("var "); |
| 64 | PrintLiteral(node->proxy()->name(), false); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 65 | Print(";"); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void PrettyPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) { |
| 70 | Print("function "); |
| 71 | PrintLiteral(node->proxy()->name(), false); |
| 72 | Print(" = "); |
| 73 | PrintFunctionLiteral(node->fun()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 74 | Print(";"); |
| 75 | } |
| 76 | |
| 77 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 78 | void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) { |
| 79 | Print("module "); |
| 80 | PrintLiteral(node->proxy()->name(), false); |
| 81 | Print(" = "); |
| 82 | Visit(node->module()); |
| 83 | Print(";"); |
| 84 | } |
| 85 | |
| 86 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 87 | void PrettyPrinter::VisitImportDeclaration(ImportDeclaration* node) { |
| 88 | Print("import "); |
| 89 | PrintLiteral(node->proxy()->name(), false); |
| 90 | Print(" from "); |
| 91 | Visit(node->module()); |
| 92 | Print(";"); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void PrettyPrinter::VisitExportDeclaration(ExportDeclaration* node) { |
| 97 | Print("export "); |
| 98 | PrintLiteral(node->proxy()->name(), false); |
| 99 | Print(";"); |
| 100 | } |
| 101 | |
| 102 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 103 | void PrettyPrinter::VisitModuleLiteral(ModuleLiteral* node) { |
| 104 | VisitBlock(node->body()); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | void PrettyPrinter::VisitModuleVariable(ModuleVariable* node) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 109 | Visit(node->proxy()); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
| 113 | void PrettyPrinter::VisitModulePath(ModulePath* node) { |
| 114 | Visit(node->module()); |
| 115 | Print("."); |
| 116 | PrintLiteral(node->name(), false); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | void PrettyPrinter::VisitModuleUrl(ModuleUrl* node) { |
| 121 | Print("at "); |
| 122 | PrintLiteral(node->url(), true); |
| 123 | } |
| 124 | |
| 125 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 126 | void PrettyPrinter::VisitModuleStatement(ModuleStatement* node) { |
| 127 | Print("module "); |
| 128 | PrintLiteral(node->proxy()->name(), false); |
| 129 | Print(" "); |
| 130 | Visit(node->body()); |
| 131 | } |
| 132 | |
| 133 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | void PrettyPrinter::VisitExpressionStatement(ExpressionStatement* node) { |
| 135 | Visit(node->expression()); |
| 136 | Print(";"); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | void PrettyPrinter::VisitEmptyStatement(EmptyStatement* node) { |
| 141 | Print(";"); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | void PrettyPrinter::VisitIfStatement(IfStatement* node) { |
| 146 | Print("if ("); |
| 147 | Visit(node->condition()); |
| 148 | Print(") "); |
| 149 | Visit(node->then_statement()); |
| 150 | if (node->HasElseStatement()) { |
| 151 | Print(" else "); |
| 152 | Visit(node->else_statement()); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | |
| 157 | void PrettyPrinter::VisitContinueStatement(ContinueStatement* node) { |
| 158 | Print("continue"); |
| 159 | ZoneStringList* labels = node->target()->labels(); |
| 160 | if (labels != NULL) { |
| 161 | Print(" "); |
| 162 | ASSERT(labels->length() > 0); // guaranteed to have at least one entry |
| 163 | PrintLiteral(labels->at(0), false); // any label from the list is fine |
| 164 | } |
| 165 | Print(";"); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | void PrettyPrinter::VisitBreakStatement(BreakStatement* node) { |
| 170 | Print("break"); |
| 171 | ZoneStringList* labels = node->target()->labels(); |
| 172 | if (labels != NULL) { |
| 173 | Print(" "); |
| 174 | ASSERT(labels->length() > 0); // guaranteed to have at least one entry |
| 175 | PrintLiteral(labels->at(0), false); // any label from the list is fine |
| 176 | } |
| 177 | Print(";"); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | void PrettyPrinter::VisitReturnStatement(ReturnStatement* node) { |
| 182 | Print("return "); |
| 183 | Visit(node->expression()); |
| 184 | Print(";"); |
| 185 | } |
| 186 | |
| 187 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 188 | void PrettyPrinter::VisitWithStatement(WithStatement* node) { |
| 189 | Print("with ("); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | Visit(node->expression()); |
| 191 | Print(") "); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 192 | Visit(node->statement()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | void PrettyPrinter::VisitSwitchStatement(SwitchStatement* node) { |
| 197 | PrintLabels(node->labels()); |
| 198 | Print("switch ("); |
| 199 | Visit(node->tag()); |
| 200 | Print(") { "); |
| 201 | ZoneList<CaseClause*>* cases = node->cases(); |
| 202 | for (int i = 0; i < cases->length(); i++) |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 203 | Visit(cases->at(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | Print("}"); |
| 205 | } |
| 206 | |
| 207 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 208 | void PrettyPrinter::VisitCaseClause(CaseClause* clause) { |
| 209 | if (clause->is_default()) { |
| 210 | Print("default"); |
| 211 | } else { |
| 212 | Print("case "); |
| 213 | Visit(clause->label()); |
| 214 | } |
| 215 | Print(": "); |
| 216 | PrintStatements(clause->statements()); |
| 217 | if (clause->statements()->length() > 0) |
| 218 | Print(" "); |
| 219 | } |
| 220 | |
| 221 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 222 | void PrettyPrinter::VisitDoWhileStatement(DoWhileStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | PrintLabels(node->labels()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 224 | Print("do "); |
| 225 | Visit(node->body()); |
| 226 | Print(" while ("); |
| 227 | Visit(node->cond()); |
| 228 | Print(");"); |
| 229 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 231 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 232 | void PrettyPrinter::VisitWhileStatement(WhileStatement* node) { |
| 233 | PrintLabels(node->labels()); |
| 234 | Print("while ("); |
| 235 | Visit(node->cond()); |
| 236 | Print(") "); |
| 237 | Visit(node->body()); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | void PrettyPrinter::VisitForStatement(ForStatement* node) { |
| 242 | PrintLabels(node->labels()); |
| 243 | Print("for ("); |
| 244 | if (node->init() != NULL) { |
| 245 | Visit(node->init()); |
| 246 | Print(" "); |
| 247 | } else { |
| 248 | Print("; "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 250 | if (node->cond() != NULL) Visit(node->cond()); |
| 251 | Print("; "); |
| 252 | if (node->next() != NULL) { |
| 253 | Visit(node->next()); // prints extra ';', unfortunately |
| 254 | // to fix: should use Expression for next |
| 255 | } |
| 256 | Print(") "); |
| 257 | Visit(node->body()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
| 261 | void PrettyPrinter::VisitForInStatement(ForInStatement* node) { |
| 262 | PrintLabels(node->labels()); |
| 263 | Print("for ("); |
| 264 | Visit(node->each()); |
| 265 | Print(" in "); |
| 266 | Visit(node->enumerable()); |
| 267 | Print(") "); |
| 268 | Visit(node->body()); |
| 269 | } |
| 270 | |
| 271 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 272 | void PrettyPrinter::VisitForOfStatement(ForOfStatement* node) { |
| 273 | PrintLabels(node->labels()); |
| 274 | Print("for ("); |
| 275 | Visit(node->each()); |
| 276 | Print(" of "); |
| 277 | Visit(node->iterable()); |
| 278 | Print(") "); |
| 279 | Visit(node->body()); |
| 280 | } |
| 281 | |
| 282 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 283 | void PrettyPrinter::VisitTryCatchStatement(TryCatchStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 284 | Print("try "); |
| 285 | Visit(node->try_block()); |
| 286 | Print(" catch ("); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 287 | const bool quote = false; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 288 | PrintLiteral(node->variable()->name(), quote); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | Print(") "); |
| 290 | Visit(node->catch_block()); |
| 291 | } |
| 292 | |
| 293 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 294 | void PrettyPrinter::VisitTryFinallyStatement(TryFinallyStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 295 | Print("try "); |
| 296 | Visit(node->try_block()); |
| 297 | Print(" finally "); |
| 298 | Visit(node->finally_block()); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | void PrettyPrinter::VisitDebuggerStatement(DebuggerStatement* node) { |
| 303 | Print("debugger "); |
| 304 | } |
| 305 | |
| 306 | |
| 307 | void PrettyPrinter::VisitFunctionLiteral(FunctionLiteral* node) { |
| 308 | Print("("); |
| 309 | PrintFunctionLiteral(node); |
| 310 | Print(")"); |
| 311 | } |
| 312 | |
| 313 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 314 | void PrettyPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 315 | Print("("); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 316 | PrintLiteral(node->name(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | Print(")"); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | void PrettyPrinter::VisitConditional(Conditional* node) { |
| 322 | Visit(node->condition()); |
| 323 | Print(" ? "); |
| 324 | Visit(node->then_expression()); |
| 325 | Print(" : "); |
| 326 | Visit(node->else_expression()); |
| 327 | } |
| 328 | |
| 329 | |
| 330 | void PrettyPrinter::VisitLiteral(Literal* node) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 331 | PrintLiteral(node->value(), true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | |
| 335 | void PrettyPrinter::VisitRegExpLiteral(RegExpLiteral* node) { |
| 336 | Print(" RegExp("); |
| 337 | PrintLiteral(node->pattern(), false); |
| 338 | Print(","); |
| 339 | PrintLiteral(node->flags(), false); |
| 340 | Print(") "); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | void PrettyPrinter::VisitObjectLiteral(ObjectLiteral* node) { |
| 345 | Print("{ "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 346 | for (int i = 0; i < node->properties()->length(); i++) { |
| 347 | if (i != 0) Print(","); |
| 348 | ObjectLiteral::Property* property = node->properties()->at(i); |
| 349 | Print(" "); |
| 350 | Visit(property->key()); |
| 351 | Print(": "); |
| 352 | Visit(property->value()); |
| 353 | } |
| 354 | Print(" }"); |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void PrettyPrinter::VisitArrayLiteral(ArrayLiteral* node) { |
| 359 | Print("[ "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | for (int i = 0; i < node->values()->length(); i++) { |
| 361 | if (i != 0) Print(","); |
| 362 | Visit(node->values()->at(i)); |
| 363 | } |
| 364 | Print(" ]"); |
| 365 | } |
| 366 | |
| 367 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 368 | void PrettyPrinter::VisitVariableProxy(VariableProxy* node) { |
| 369 | PrintLiteral(node->name(), false); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | void PrettyPrinter::VisitAssignment(Assignment* node) { |
| 374 | Visit(node->target()); |
| 375 | Print(" %s ", Token::String(node->op())); |
| 376 | Visit(node->value()); |
| 377 | } |
| 378 | |
| 379 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 380 | void PrettyPrinter::VisitYield(Yield* node) { |
| 381 | Print("yield "); |
| 382 | Visit(node->expression()); |
| 383 | } |
| 384 | |
| 385 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 386 | void PrettyPrinter::VisitThrow(Throw* node) { |
| 387 | Print("throw "); |
| 388 | Visit(node->exception()); |
| 389 | } |
| 390 | |
| 391 | |
| 392 | void PrettyPrinter::VisitProperty(Property* node) { |
| 393 | Expression* key = node->key(); |
| 394 | Literal* literal = key->AsLiteral(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 395 | if (literal != NULL && literal->value()->IsInternalizedString()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | Print("("); |
| 397 | Visit(node->obj()); |
| 398 | Print(")."); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 399 | PrintLiteral(literal->value(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | } else { |
| 401 | Visit(node->obj()); |
| 402 | Print("["); |
| 403 | Visit(key); |
| 404 | Print("]"); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | |
| 409 | void PrettyPrinter::VisitCall(Call* node) { |
| 410 | Visit(node->expression()); |
| 411 | PrintArguments(node->arguments()); |
| 412 | } |
| 413 | |
| 414 | |
| 415 | void PrettyPrinter::VisitCallNew(CallNew* node) { |
| 416 | Print("new ("); |
| 417 | Visit(node->expression()); |
| 418 | Print(")"); |
| 419 | PrintArguments(node->arguments()); |
| 420 | } |
| 421 | |
| 422 | |
| 423 | void PrettyPrinter::VisitCallRuntime(CallRuntime* node) { |
| 424 | Print("%%"); |
| 425 | PrintLiteral(node->name(), false); |
| 426 | PrintArguments(node->arguments()); |
| 427 | } |
| 428 | |
| 429 | |
| 430 | void PrettyPrinter::VisitUnaryOperation(UnaryOperation* node) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 431 | Token::Value op = node->op(); |
| 432 | bool needsSpace = |
| 433 | op == Token::DELETE || op == Token::TYPEOF || op == Token::VOID; |
| 434 | Print("(%s%s", Token::String(op), needsSpace ? " " : ""); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 435 | Visit(node->expression()); |
| 436 | Print(")"); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | void PrettyPrinter::VisitCountOperation(CountOperation* node) { |
| 441 | Print("("); |
| 442 | if (node->is_prefix()) Print("%s", Token::String(node->op())); |
| 443 | Visit(node->expression()); |
| 444 | if (node->is_postfix()) Print("%s", Token::String(node->op())); |
| 445 | Print(")"); |
| 446 | } |
| 447 | |
| 448 | |
| 449 | void PrettyPrinter::VisitBinaryOperation(BinaryOperation* node) { |
| 450 | Print("("); |
| 451 | Visit(node->left()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 452 | Print(" %s ", Token::String(node->op())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 453 | Visit(node->right()); |
| 454 | Print(")"); |
| 455 | } |
| 456 | |
| 457 | |
| 458 | void PrettyPrinter::VisitCompareOperation(CompareOperation* node) { |
| 459 | Print("("); |
| 460 | Visit(node->left()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 461 | Print(" %s ", Token::String(node->op())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 462 | Visit(node->right()); |
| 463 | Print(")"); |
| 464 | } |
| 465 | |
| 466 | |
| 467 | void PrettyPrinter::VisitThisFunction(ThisFunction* node) { |
| 468 | Print("<this-function>"); |
| 469 | } |
| 470 | |
| 471 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 472 | const char* PrettyPrinter::Print(AstNode* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 473 | Init(); |
| 474 | Visit(node); |
| 475 | return output_; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | const char* PrettyPrinter::PrintExpression(FunctionLiteral* program) { |
| 480 | Init(); |
| 481 | ExpressionStatement* statement = |
| 482 | program->body()->at(0)->AsExpressionStatement(); |
| 483 | Visit(statement->expression()); |
| 484 | return output_; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | const char* PrettyPrinter::PrintProgram(FunctionLiteral* program) { |
| 489 | Init(); |
| 490 | PrintStatements(program->body()); |
| 491 | Print("\n"); |
| 492 | return output_; |
| 493 | } |
| 494 | |
| 495 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 496 | void PrettyPrinter::PrintOut(Isolate* isolate, AstNode* node) { |
| 497 | PrettyPrinter printer(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | PrintF("%s", printer.Print(node)); |
| 499 | } |
| 500 | |
| 501 | |
| 502 | void PrettyPrinter::Init() { |
| 503 | if (size_ == 0) { |
| 504 | ASSERT(output_ == NULL); |
| 505 | const int initial_size = 256; |
| 506 | output_ = NewArray<char>(initial_size); |
| 507 | size_ = initial_size; |
| 508 | } |
| 509 | output_[0] = '\0'; |
| 510 | pos_ = 0; |
| 511 | } |
| 512 | |
| 513 | |
| 514 | void PrettyPrinter::Print(const char* format, ...) { |
| 515 | for (;;) { |
| 516 | va_list arguments; |
| 517 | va_start(arguments, format); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 518 | int n = OS::VSNPrintF(Vector<char>(output_, size_) + pos_, |
| 519 | format, |
| 520 | arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | va_end(arguments); |
| 522 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 523 | if (n >= 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | // there was enough space - we are done |
| 525 | pos_ += n; |
| 526 | return; |
| 527 | } else { |
| 528 | // there was not enough space - allocate more and try again |
| 529 | const int slack = 32; |
| 530 | int new_size = size_ + (size_ >> 1) + slack; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | char* new_output = NewArray<char>(new_size); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 532 | OS::MemCopy(new_output, output_, pos_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | DeleteArray(output_); |
| 534 | output_ = new_output; |
| 535 | size_ = new_size; |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | |
| 541 | void PrettyPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 542 | if (statements == NULL) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | for (int i = 0; i < statements->length(); i++) { |
| 544 | if (i != 0) Print(" "); |
| 545 | Visit(statements->at(i)); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | |
| 550 | void PrettyPrinter::PrintLabels(ZoneStringList* labels) { |
| 551 | if (labels != NULL) { |
| 552 | for (int i = 0; i < labels->length(); i++) { |
| 553 | PrintLiteral(labels->at(i), false); |
| 554 | Print(": "); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | |
| 560 | void PrettyPrinter::PrintArguments(ZoneList<Expression*>* arguments) { |
| 561 | Print("("); |
| 562 | for (int i = 0; i < arguments->length(); i++) { |
| 563 | if (i != 0) Print(", "); |
| 564 | Visit(arguments->at(i)); |
| 565 | } |
| 566 | Print(")"); |
| 567 | } |
| 568 | |
| 569 | |
| 570 | void PrettyPrinter::PrintLiteral(Handle<Object> value, bool quote) { |
| 571 | Object* object = *value; |
| 572 | if (object->IsString()) { |
| 573 | String* string = String::cast(object); |
| 574 | if (quote) Print("\""); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 575 | for (int i = 0; i < string->length(); i++) { |
| 576 | Print("%c", string->Get(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | } |
| 578 | if (quote) Print("\""); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 579 | } else if (object->IsNull()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | Print("null"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 581 | } else if (object->IsTrue()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | Print("true"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 583 | } else if (object->IsFalse()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | Print("false"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 585 | } else if (object->IsUndefined()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | Print("undefined"); |
| 587 | } else if (object->IsNumber()) { |
| 588 | Print("%g", object->Number()); |
| 589 | } else if (object->IsJSObject()) { |
| 590 | // regular expression |
| 591 | if (object->IsJSFunction()) { |
| 592 | Print("JS-Function"); |
| 593 | } else if (object->IsJSArray()) { |
| 594 | Print("JS-array[%u]", JSArray::cast(object)->length()); |
| 595 | } else if (object->IsJSObject()) { |
| 596 | Print("JS-Object"); |
| 597 | } else { |
| 598 | Print("?UNKNOWN?"); |
| 599 | } |
| 600 | } else if (object->IsFixedArray()) { |
| 601 | Print("FixedArray"); |
| 602 | } else { |
| 603 | Print("<unknown literal %p>", object); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | |
| 608 | void PrettyPrinter::PrintParameters(Scope* scope) { |
| 609 | Print("("); |
| 610 | for (int i = 0; i < scope->num_parameters(); i++) { |
| 611 | if (i > 0) Print(", "); |
| 612 | PrintLiteral(scope->parameter(i)->name(), false); |
| 613 | } |
| 614 | Print(")"); |
| 615 | } |
| 616 | |
| 617 | |
| 618 | void PrettyPrinter::PrintDeclarations(ZoneList<Declaration*>* declarations) { |
| 619 | for (int i = 0; i < declarations->length(); i++) { |
| 620 | if (i > 0) Print(" "); |
| 621 | Visit(declarations->at(i)); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | |
| 626 | void PrettyPrinter::PrintFunctionLiteral(FunctionLiteral* function) { |
| 627 | Print("function "); |
| 628 | PrintLiteral(function->name(), false); |
| 629 | PrintParameters(function->scope()); |
| 630 | Print(" { "); |
| 631 | PrintDeclarations(function->scope()->declarations()); |
| 632 | PrintStatements(function->body()); |
| 633 | Print(" }"); |
| 634 | } |
| 635 | |
| 636 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | //----------------------------------------------------------------------------- |
| 638 | |
| 639 | class IndentedScope BASE_EMBEDDED { |
| 640 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 641 | IndentedScope(AstPrinter* printer, const char* txt) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 642 | : ast_printer_(printer) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | ast_printer_->PrintIndented(txt); |
| 644 | ast_printer_->Print("\n"); |
| 645 | ast_printer_->inc_indent(); |
| 646 | } |
| 647 | |
| 648 | virtual ~IndentedScope() { |
| 649 | ast_printer_->dec_indent(); |
| 650 | } |
| 651 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 653 | AstPrinter* ast_printer_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 657 | //----------------------------------------------------------------------------- |
| 658 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 659 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 660 | AstPrinter::AstPrinter(Isolate* isolate) : PrettyPrinter(isolate), indent_(0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
| 664 | AstPrinter::~AstPrinter() { |
| 665 | ASSERT(indent_ == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
| 669 | void AstPrinter::PrintIndented(const char* txt) { |
| 670 | for (int i = 0; i < indent_; i++) { |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 671 | Print(". "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 672 | } |
| 673 | Print(txt); |
| 674 | } |
| 675 | |
| 676 | |
| 677 | void AstPrinter::PrintLiteralIndented(const char* info, |
| 678 | Handle<Object> value, |
| 679 | bool quote) { |
| 680 | PrintIndented(info); |
| 681 | Print(" "); |
| 682 | PrintLiteral(value, quote); |
| 683 | Print("\n"); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | void AstPrinter::PrintLiteralWithModeIndented(const char* info, |
| 688 | Variable* var, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 689 | Handle<Object> value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 690 | if (var == NULL) { |
| 691 | PrintLiteralIndented(info, value, true); |
| 692 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 693 | EmbeddedVector<char, 256> buf; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 694 | int pos = OS::SNPrintF(buf, "%s (mode = %s", info, |
| 695 | Variable::Mode2String(var->mode())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 696 | OS::SNPrintF(buf + pos, ")"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 697 | PrintLiteralIndented(buf.start(), value, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
| 701 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 702 | void AstPrinter::PrintLabelsIndented(ZoneStringList* labels) { |
| 703 | if (labels == NULL || labels->length() == 0) return; |
| 704 | PrintIndented("LABELS "); |
| 705 | PrintLabels(labels); |
| 706 | Print("\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 710 | void AstPrinter::PrintIndentedVisit(const char* s, AstNode* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 711 | IndentedScope indent(this, s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 712 | Visit(node); |
| 713 | } |
| 714 | |
| 715 | |
| 716 | const char* AstPrinter::PrintProgram(FunctionLiteral* program) { |
| 717 | Init(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 718 | { IndentedScope indent(this, "FUNC"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | PrintLiteralIndented("NAME", program->name(), true); |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 720 | PrintLiteralIndented("INFERRED NAME", program->inferred_name(), true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | PrintParameters(program->scope()); |
| 722 | PrintDeclarations(program->scope()->declarations()); |
| 723 | PrintStatements(program->body()); |
| 724 | } |
| 725 | return Output(); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | void AstPrinter::PrintDeclarations(ZoneList<Declaration*>* declarations) { |
| 730 | if (declarations->length() > 0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 731 | IndentedScope indent(this, "DECLS"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 732 | for (int i = 0; i < declarations->length(); i++) { |
| 733 | Visit(declarations->at(i)); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | |
| 739 | void AstPrinter::PrintParameters(Scope* scope) { |
| 740 | if (scope->num_parameters() > 0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 741 | IndentedScope indent(this, "PARAMS"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | for (int i = 0; i < scope->num_parameters(); i++) { |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 743 | PrintLiteralWithModeIndented("VAR", scope->parameter(i), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 744 | scope->parameter(i)->name()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | |
| 750 | void AstPrinter::PrintStatements(ZoneList<Statement*>* statements) { |
| 751 | for (int i = 0; i < statements->length(); i++) { |
| 752 | Visit(statements->at(i)); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | |
| 757 | void AstPrinter::PrintArguments(ZoneList<Expression*>* arguments) { |
| 758 | for (int i = 0; i < arguments->length(); i++) { |
| 759 | Visit(arguments->at(i)); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 764 | void AstPrinter::VisitBlock(Block* node) { |
| 765 | const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK"; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 766 | IndentedScope indent(this, block_txt); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 767 | PrintStatements(node->statements()); |
| 768 | } |
| 769 | |
| 770 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 771 | // TODO(svenpanne) Start with IndentedScope. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 772 | void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 773 | PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()), |
| 774 | node->proxy()->var(), |
| 775 | node->proxy()->name()); |
| 776 | } |
| 777 | |
| 778 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 779 | // TODO(svenpanne) Start with IndentedScope. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 780 | void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) { |
| 781 | PrintIndented("FUNCTION "); |
| 782 | PrintLiteral(node->proxy()->name(), true); |
| 783 | Print(" = function "); |
| 784 | PrintLiteral(node->fun()->name(), false); |
| 785 | Print("\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 789 | void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) { |
| 790 | IndentedScope indent(this, "MODULE"); |
| 791 | PrintLiteralIndented("NAME", node->proxy()->name(), true); |
| 792 | Visit(node->module()); |
| 793 | } |
| 794 | |
| 795 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 796 | void AstPrinter::VisitImportDeclaration(ImportDeclaration* node) { |
| 797 | IndentedScope indent(this, "IMPORT"); |
| 798 | PrintLiteralIndented("NAME", node->proxy()->name(), true); |
| 799 | Visit(node->module()); |
| 800 | } |
| 801 | |
| 802 | |
| 803 | void AstPrinter::VisitExportDeclaration(ExportDeclaration* node) { |
| 804 | IndentedScope indent(this, "EXPORT "); |
| 805 | PrintLiteral(node->proxy()->name(), true); |
| 806 | } |
| 807 | |
| 808 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 809 | void AstPrinter::VisitModuleLiteral(ModuleLiteral* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 810 | IndentedScope indent(this, "MODULE LITERAL"); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 811 | VisitBlock(node->body()); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | void AstPrinter::VisitModuleVariable(ModuleVariable* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 816 | IndentedScope indent(this, "MODULE VARIABLE"); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 817 | Visit(node->proxy()); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | |
| 821 | void AstPrinter::VisitModulePath(ModulePath* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 822 | IndentedScope indent(this, "MODULE PATH"); |
| 823 | PrintIndentedVisit("MODULE PATH PARENT", node->module()); |
| 824 | PrintLiteralIndented("NAME", node->name(), true); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | |
| 828 | void AstPrinter::VisitModuleUrl(ModuleUrl* node) { |
| 829 | PrintLiteralIndented("URL", node->url(), true); |
| 830 | } |
| 831 | |
| 832 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 833 | void AstPrinter::VisitModuleStatement(ModuleStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 834 | IndentedScope indent(this, "MODULE STATEMENT"); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 835 | PrintLiteralIndented("NAME", node->proxy()->name(), true); |
| 836 | PrintStatements(node->body()->statements()); |
| 837 | } |
| 838 | |
| 839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 840 | void AstPrinter::VisitExpressionStatement(ExpressionStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 841 | IndentedScope indent(this, "EXPRESSION STATEMENT"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | Visit(node->expression()); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | void AstPrinter::VisitEmptyStatement(EmptyStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 847 | IndentedScope indent(this, "EMPTY"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | |
| 851 | void AstPrinter::VisitIfStatement(IfStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 852 | IndentedScope indent(this, "IF"); |
| 853 | PrintIndentedVisit("CONDITION", node->condition()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 854 | PrintIndentedVisit("THEN", node->then_statement()); |
| 855 | if (node->HasElseStatement()) { |
| 856 | PrintIndentedVisit("ELSE", node->else_statement()); |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | |
| 861 | void AstPrinter::VisitContinueStatement(ContinueStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 862 | IndentedScope indent(this, "CONTINUE"); |
| 863 | PrintLabelsIndented(node->target()->labels()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | |
| 867 | void AstPrinter::VisitBreakStatement(BreakStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 868 | IndentedScope indent(this, "BREAK"); |
| 869 | PrintLabelsIndented(node->target()->labels()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | |
| 873 | void AstPrinter::VisitReturnStatement(ReturnStatement* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 874 | IndentedScope indent(this, "RETURN"); |
| 875 | Visit(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 879 | void AstPrinter::VisitWithStatement(WithStatement* node) { |
| 880 | IndentedScope indent(this, "WITH"); |
| 881 | PrintIndentedVisit("OBJECT", node->expression()); |
| 882 | PrintIndentedVisit("BODY", node->statement()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | void AstPrinter::VisitSwitchStatement(SwitchStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 887 | IndentedScope indent(this, "SWITCH"); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 888 | PrintLabelsIndented(node->labels()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | PrintIndentedVisit("TAG", node->tag()); |
| 890 | for (int i = 0; i < node->cases()->length(); i++) { |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 891 | Visit(node->cases()->at(i)); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | |
| 896 | void AstPrinter::VisitCaseClause(CaseClause* clause) { |
| 897 | if (clause->is_default()) { |
| 898 | IndentedScope indent(this, "DEFAULT"); |
| 899 | PrintStatements(clause->statements()); |
| 900 | } else { |
| 901 | IndentedScope indent(this, "CASE"); |
| 902 | Visit(clause->label()); |
| 903 | PrintStatements(clause->statements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | |
| 907 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 908 | void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 909 | IndentedScope indent(this, "DO"); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 910 | PrintLabelsIndented(node->labels()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 911 | PrintIndentedVisit("BODY", node->body()); |
| 912 | PrintIndentedVisit("COND", node->cond()); |
| 913 | } |
| 914 | |
| 915 | |
| 916 | void AstPrinter::VisitWhileStatement(WhileStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 917 | IndentedScope indent(this, "WHILE"); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 918 | PrintLabelsIndented(node->labels()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 919 | PrintIndentedVisit("COND", node->cond()); |
| 920 | PrintIndentedVisit("BODY", node->body()); |
| 921 | } |
| 922 | |
| 923 | |
| 924 | void AstPrinter::VisitForStatement(ForStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 925 | IndentedScope indent(this, "FOR"); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 926 | PrintLabelsIndented(node->labels()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 927 | if (node->init()) PrintIndentedVisit("INIT", node->init()); |
| 928 | if (node->cond()) PrintIndentedVisit("COND", node->cond()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 929 | PrintIndentedVisit("BODY", node->body()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | if (node->next()) PrintIndentedVisit("NEXT", node->next()); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | void AstPrinter::VisitForInStatement(ForInStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 935 | IndentedScope indent(this, "FOR IN"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | PrintIndentedVisit("FOR", node->each()); |
| 937 | PrintIndentedVisit("IN", node->enumerable()); |
| 938 | PrintIndentedVisit("BODY", node->body()); |
| 939 | } |
| 940 | |
| 941 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 942 | void AstPrinter::VisitForOfStatement(ForOfStatement* node) { |
| 943 | IndentedScope indent(this, "FOR OF"); |
| 944 | PrintIndentedVisit("FOR", node->each()); |
| 945 | PrintIndentedVisit("OF", node->iterable()); |
| 946 | PrintIndentedVisit("BODY", node->body()); |
| 947 | } |
| 948 | |
| 949 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 950 | void AstPrinter::VisitTryCatchStatement(TryCatchStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 951 | IndentedScope indent(this, "TRY CATCH"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 952 | PrintIndentedVisit("TRY", node->try_block()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 953 | PrintLiteralWithModeIndented("CATCHVAR", |
| 954 | node->variable(), |
| 955 | node->variable()->name()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 956 | PrintIndentedVisit("CATCH", node->catch_block()); |
| 957 | } |
| 958 | |
| 959 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 960 | void AstPrinter::VisitTryFinallyStatement(TryFinallyStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 961 | IndentedScope indent(this, "TRY FINALLY"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 962 | PrintIndentedVisit("TRY", node->try_block()); |
| 963 | PrintIndentedVisit("FINALLY", node->finally_block()); |
| 964 | } |
| 965 | |
| 966 | |
| 967 | void AstPrinter::VisitDebuggerStatement(DebuggerStatement* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 968 | IndentedScope indent(this, "DEBUGGER"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | |
| 972 | void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 973 | IndentedScope indent(this, "FUNC LITERAL"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 974 | PrintLiteralIndented("NAME", node->name(), false); |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 975 | PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 976 | PrintParameters(node->scope()); |
| 977 | // We don't want to see the function literal in this case: it |
| 978 | // will be printed via PrintProgram when the code for it is |
| 979 | // generated. |
| 980 | // PrintStatements(node->body()); |
| 981 | } |
| 982 | |
| 983 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 984 | void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) { |
| 985 | IndentedScope indent(this, "NATIVE FUNC LITERAL"); |
| 986 | PrintLiteralIndented("NAME", node->name(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
| 990 | void AstPrinter::VisitConditional(Conditional* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 991 | IndentedScope indent(this, "CONDITIONAL"); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 992 | PrintIndentedVisit("CONDITION", node->condition()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 993 | PrintIndentedVisit("THEN", node->then_expression()); |
| 994 | PrintIndentedVisit("ELSE", node->else_expression()); |
| 995 | } |
| 996 | |
| 997 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 998 | // TODO(svenpanne) Start with IndentedScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 999 | void AstPrinter::VisitLiteral(Literal* node) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1000 | PrintLiteralIndented("LITERAL", node->value(), true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1005 | IndentedScope indent(this, "REGEXP LITERAL"); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1006 | PrintLiteralIndented("PATTERN", node->pattern(), false); |
| 1007 | PrintLiteralIndented("FLAGS", node->flags(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1012 | IndentedScope indent(this, "OBJ LITERAL"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1013 | for (int i = 0; i < node->properties()->length(); i++) { |
| 1014 | const char* prop_kind = NULL; |
| 1015 | switch (node->properties()->at(i)->kind()) { |
| 1016 | case ObjectLiteral::Property::CONSTANT: |
| 1017 | prop_kind = "PROPERTY - CONSTANT"; |
| 1018 | break; |
| 1019 | case ObjectLiteral::Property::COMPUTED: |
| 1020 | prop_kind = "PROPERTY - COMPUTED"; |
| 1021 | break; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1022 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1023 | prop_kind = "PROPERTY - MATERIALIZED_LITERAL"; |
| 1024 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1025 | case ObjectLiteral::Property::PROTOTYPE: |
| 1026 | prop_kind = "PROPERTY - PROTOTYPE"; |
| 1027 | break; |
| 1028 | case ObjectLiteral::Property::GETTER: |
| 1029 | prop_kind = "PROPERTY - GETTER"; |
| 1030 | break; |
| 1031 | case ObjectLiteral::Property::SETTER: |
| 1032 | prop_kind = "PROPERTY - SETTER"; |
| 1033 | break; |
| 1034 | default: |
| 1035 | UNREACHABLE(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1036 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1037 | IndentedScope prop(this, prop_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1038 | PrintIndentedVisit("KEY", node->properties()->at(i)->key()); |
| 1039 | PrintIndentedVisit("VALUE", node->properties()->at(i)->value()); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1045 | IndentedScope indent(this, "ARRAY LITERAL"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1046 | if (node->values()->length() > 0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1047 | IndentedScope indent(this, "VALUES"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1048 | for (int i = 0; i < node->values()->length(); i++) { |
| 1049 | Visit(node->values()->at(i)); |
| 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1055 | // TODO(svenpanne) Start with IndentedScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | void AstPrinter::VisitVariableProxy(VariableProxy* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1057 | Variable* var = node->var(); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1058 | EmbeddedVector<char, 128> buf; |
| 1059 | int pos = OS::SNPrintF(buf, "VAR PROXY"); |
| 1060 | switch (var->location()) { |
| 1061 | case Variable::UNALLOCATED: |
| 1062 | break; |
| 1063 | case Variable::PARAMETER: |
| 1064 | OS::SNPrintF(buf + pos, " parameter[%d]", var->index()); |
| 1065 | break; |
| 1066 | case Variable::LOCAL: |
| 1067 | OS::SNPrintF(buf + pos, " local[%d]", var->index()); |
| 1068 | break; |
| 1069 | case Variable::CONTEXT: |
| 1070 | OS::SNPrintF(buf + pos, " context[%d]", var->index()); |
| 1071 | break; |
| 1072 | case Variable::LOOKUP: |
| 1073 | OS::SNPrintF(buf + pos, " lookup"); |
| 1074 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1076 | PrintLiteralWithModeIndented(buf.start(), var, node->name()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | void AstPrinter::VisitAssignment(Assignment* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1081 | IndentedScope indent(this, Token::Name(node->op())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1082 | Visit(node->target()); |
| 1083 | Visit(node->value()); |
| 1084 | } |
| 1085 | |
| 1086 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1087 | void AstPrinter::VisitYield(Yield* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1088 | IndentedScope indent(this, "YIELD"); |
| 1089 | Visit(node->expression()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1093 | void AstPrinter::VisitThrow(Throw* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1094 | IndentedScope indent(this, "THROW"); |
| 1095 | Visit(node->exception()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | void AstPrinter::VisitProperty(Property* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1100 | IndentedScope indent(this, "PROPERTY"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1101 | Visit(node->obj()); |
| 1102 | Literal* literal = node->key()->AsLiteral(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1103 | if (literal != NULL && literal->value()->IsInternalizedString()) { |
| 1104 | PrintLiteralIndented("NAME", literal->value(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1105 | } else { |
| 1106 | PrintIndentedVisit("KEY", node->key()); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | |
| 1111 | void AstPrinter::VisitCall(Call* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1112 | IndentedScope indent(this, "CALL"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1113 | Visit(node->expression()); |
| 1114 | PrintArguments(node->arguments()); |
| 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | void AstPrinter::VisitCallNew(CallNew* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1119 | IndentedScope indent(this, "CALL NEW"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1120 | Visit(node->expression()); |
| 1121 | PrintArguments(node->arguments()); |
| 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | void AstPrinter::VisitCallRuntime(CallRuntime* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1126 | IndentedScope indent(this, "CALL RUNTIME"); |
| 1127 | PrintLiteralIndented("NAME", node->name(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1128 | PrintArguments(node->arguments()); |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1133 | IndentedScope indent(this, Token::Name(node->op())); |
| 1134 | Visit(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | void AstPrinter::VisitCountOperation(CountOperation* node) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1139 | EmbeddedVector<char, 128> buf; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1140 | OS::SNPrintF(buf, "%s %s", (node->is_prefix() ? "PRE" : "POST"), |
| 1141 | Token::Name(node->op())); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1142 | IndentedScope indent(this, buf.start()); |
| 1143 | Visit(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | |
| 1147 | void AstPrinter::VisitBinaryOperation(BinaryOperation* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1148 | IndentedScope indent(this, Token::Name(node->op())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1149 | Visit(node->left()); |
| 1150 | Visit(node->right()); |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | void AstPrinter::VisitCompareOperation(CompareOperation* node) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1155 | IndentedScope indent(this, Token::Name(node->op())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1156 | Visit(node->left()); |
| 1157 | Visit(node->right()); |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | void AstPrinter::VisitThisFunction(ThisFunction* node) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1162 | IndentedScope indent(this, "THIS-FUNCTION"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1165 | #endif // DEBUG |
| 1166 | |
| 1167 | } } // namespace v8::internal |