| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/ast.h" | 7 #include "src/ast.h" |
| 8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 void VisitDeclarations(ZoneList<Declaration*>* declarations); | 32 void VisitDeclarations(ZoneList<Declaration*>* declarations); |
| 33 void VisitArguments(ZoneList<Expression*>* arguments); | 33 void VisitArguments(ZoneList<Expression*>* arguments); |
| 34 void VisitObjectLiteralProperty(ObjectLiteralProperty* property); | 34 void VisitObjectLiteralProperty(ObjectLiteralProperty* property); |
| 35 | 35 |
| 36 int ReserveIdRange(int n) { | 36 int ReserveIdRange(int n) { |
| 37 int tmp = next_id_; | 37 int tmp = next_id_; |
| 38 next_id_ += n; | 38 next_id_ += n; |
| 39 return tmp; | 39 return tmp; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void IncrementNodeCount() { properties_.add_node_count(1); } | |
| 43 | |
| 44 int next_id_; | 42 int next_id_; |
| 45 AstProperties properties_; | |
| 46 | 43 |
| 47 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 44 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 48 DISALLOW_COPY_AND_ASSIGN(AstNumberingVisitor); | 45 DISALLOW_COPY_AND_ASSIGN(AstNumberingVisitor); |
| 49 }; | 46 }; |
| 50 | 47 |
| 51 | 48 |
| 52 void AstNumberingVisitor::VisitVariableDeclaration(VariableDeclaration* node) { | 49 void AstNumberingVisitor::VisitVariableDeclaration(VariableDeclaration* node) { |
| 53 IncrementNodeCount(); | |
| 54 VisitVariableProxy(node->proxy()); | 50 VisitVariableProxy(node->proxy()); |
| 55 } | 51 } |
| 56 | 52 |
| 57 | 53 |
| 58 void AstNumberingVisitor::VisitExportDeclaration(ExportDeclaration* node) { | 54 void AstNumberingVisitor::VisitExportDeclaration(ExportDeclaration* node) { |
| 59 IncrementNodeCount(); | |
| 60 VisitVariableProxy(node->proxy()); | 55 VisitVariableProxy(node->proxy()); |
| 61 } | 56 } |
| 62 | 57 |
| 63 | 58 |
| 64 void AstNumberingVisitor::VisitModuleUrl(ModuleUrl* node) { | 59 void AstNumberingVisitor::VisitModuleUrl(ModuleUrl* node) {} |
| 65 IncrementNodeCount(); | |
| 66 } | |
| 67 | 60 |
| 68 | 61 |
| 69 void AstNumberingVisitor::VisitEmptyStatement(EmptyStatement* node) { | 62 void AstNumberingVisitor::VisitEmptyStatement(EmptyStatement* node) {} |
| 70 IncrementNodeCount(); | |
| 71 } | |
| 72 | 63 |
| 73 | 64 |
| 74 void AstNumberingVisitor::VisitContinueStatement(ContinueStatement* node) { | 65 void AstNumberingVisitor::VisitContinueStatement(ContinueStatement* node) {} |
| 75 IncrementNodeCount(); | |
| 76 } | |
| 77 | 66 |
| 78 | 67 |
| 79 void AstNumberingVisitor::VisitBreakStatement(BreakStatement* node) { | 68 void AstNumberingVisitor::VisitBreakStatement(BreakStatement* node) {} |
| 80 IncrementNodeCount(); | |
| 81 } | |
| 82 | 69 |
| 83 | 70 |
| 84 void AstNumberingVisitor::VisitDebuggerStatement(DebuggerStatement* node) { | 71 void AstNumberingVisitor::VisitDebuggerStatement(DebuggerStatement* node) { |
| 85 IncrementNodeCount(); | |
| 86 node->set_base_id(ReserveIdRange(DebuggerStatement::num_ids())); | 72 node->set_base_id(ReserveIdRange(DebuggerStatement::num_ids())); |
| 87 } | 73 } |
| 88 | 74 |
| 89 | 75 |
| 90 void AstNumberingVisitor::VisitNativeFunctionLiteral( | 76 void AstNumberingVisitor::VisitNativeFunctionLiteral( |
| 91 NativeFunctionLiteral* node) { | 77 NativeFunctionLiteral* node) { |
| 92 IncrementNodeCount(); | |
| 93 node->set_base_id(ReserveIdRange(NativeFunctionLiteral::num_ids())); | 78 node->set_base_id(ReserveIdRange(NativeFunctionLiteral::num_ids())); |
| 94 } | 79 } |
| 95 | 80 |
| 96 | 81 |
| 97 void AstNumberingVisitor::VisitLiteral(Literal* node) { | 82 void AstNumberingVisitor::VisitLiteral(Literal* node) { |
| 98 IncrementNodeCount(); | |
| 99 node->set_base_id(ReserveIdRange(Literal::num_ids())); | 83 node->set_base_id(ReserveIdRange(Literal::num_ids())); |
| 100 } | 84 } |
| 101 | 85 |
| 102 | 86 |
| 103 void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) { | 87 void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) { |
| 104 IncrementNodeCount(); | |
| 105 node->set_base_id(ReserveIdRange(RegExpLiteral::num_ids())); | 88 node->set_base_id(ReserveIdRange(RegExpLiteral::num_ids())); |
| 106 } | 89 } |
| 107 | 90 |
| 108 | 91 |
| 109 void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) { | 92 void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) { |
| 110 IncrementNodeCount(); | |
| 111 node->set_base_id(ReserveIdRange(VariableProxy::num_ids())); | 93 node->set_base_id(ReserveIdRange(VariableProxy::num_ids())); |
| 112 } | 94 } |
| 113 | 95 |
| 114 | 96 |
| 115 void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) { | 97 void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) { |
| 116 IncrementNodeCount(); | |
| 117 node->set_base_id(ReserveIdRange(ThisFunction::num_ids())); | 98 node->set_base_id(ReserveIdRange(ThisFunction::num_ids())); |
| 118 } | 99 } |
| 119 | 100 |
| 120 | 101 |
| 121 void AstNumberingVisitor::VisitSuperReference(SuperReference* node) { | 102 void AstNumberingVisitor::VisitSuperReference(SuperReference* node) { |
| 122 IncrementNodeCount(); | |
| 123 node->set_base_id(ReserveIdRange(SuperReference::num_ids())); | 103 node->set_base_id(ReserveIdRange(SuperReference::num_ids())); |
| 124 Visit(node->this_var()); | 104 Visit(node->this_var()); |
| 125 } | 105 } |
| 126 | 106 |
| 127 | 107 |
| 128 void AstNumberingVisitor::VisitModuleDeclaration(ModuleDeclaration* node) { | 108 void AstNumberingVisitor::VisitModuleDeclaration(ModuleDeclaration* node) { |
| 129 IncrementNodeCount(); | |
| 130 VisitVariableProxy(node->proxy()); | 109 VisitVariableProxy(node->proxy()); |
| 131 Visit(node->module()); | 110 Visit(node->module()); |
| 132 } | 111 } |
| 133 | 112 |
| 134 | 113 |
| 135 void AstNumberingVisitor::VisitImportDeclaration(ImportDeclaration* node) { | 114 void AstNumberingVisitor::VisitImportDeclaration(ImportDeclaration* node) { |
| 136 IncrementNodeCount(); | |
| 137 VisitVariableProxy(node->proxy()); | 115 VisitVariableProxy(node->proxy()); |
| 138 Visit(node->module()); | 116 Visit(node->module()); |
| 139 } | 117 } |
| 140 | 118 |
| 141 | 119 |
| 142 void AstNumberingVisitor::VisitModuleVariable(ModuleVariable* node) { | 120 void AstNumberingVisitor::VisitModuleVariable(ModuleVariable* node) { |
| 143 IncrementNodeCount(); | |
| 144 Visit(node->proxy()); | 121 Visit(node->proxy()); |
| 145 } | 122 } |
| 146 | 123 |
| 147 | 124 |
| 148 void AstNumberingVisitor::VisitModulePath(ModulePath* node) { | 125 void AstNumberingVisitor::VisitModulePath(ModulePath* node) { |
| 149 IncrementNodeCount(); | |
| 150 Visit(node->module()); | 126 Visit(node->module()); |
| 151 } | 127 } |
| 152 | 128 |
| 153 | 129 |
| 154 void AstNumberingVisitor::VisitModuleStatement(ModuleStatement* node) { | 130 void AstNumberingVisitor::VisitModuleStatement(ModuleStatement* node) { |
| 155 IncrementNodeCount(); | |
| 156 Visit(node->body()); | 131 Visit(node->body()); |
| 157 } | 132 } |
| 158 | 133 |
| 159 | 134 |
| 160 void AstNumberingVisitor::VisitExpressionStatement(ExpressionStatement* node) { | 135 void AstNumberingVisitor::VisitExpressionStatement(ExpressionStatement* node) { |
| 161 IncrementNodeCount(); | |
| 162 Visit(node->expression()); | 136 Visit(node->expression()); |
| 163 } | 137 } |
| 164 | 138 |
| 165 | 139 |
| 166 void AstNumberingVisitor::VisitReturnStatement(ReturnStatement* node) { | 140 void AstNumberingVisitor::VisitReturnStatement(ReturnStatement* node) { |
| 167 IncrementNodeCount(); | |
| 168 Visit(node->expression()); | 141 Visit(node->expression()); |
| 169 } | 142 } |
| 170 | 143 |
| 171 | 144 |
| 172 void AstNumberingVisitor::VisitYield(Yield* node) { | 145 void AstNumberingVisitor::VisitYield(Yield* node) { |
| 173 IncrementNodeCount(); | |
| 174 node->set_base_id(ReserveIdRange(Yield::num_ids())); | 146 node->set_base_id(ReserveIdRange(Yield::num_ids())); |
| 175 Visit(node->generator_object()); | 147 Visit(node->generator_object()); |
| 176 Visit(node->expression()); | 148 Visit(node->expression()); |
| 177 } | 149 } |
| 178 | 150 |
| 179 | 151 |
| 180 void AstNumberingVisitor::VisitThrow(Throw* node) { | 152 void AstNumberingVisitor::VisitThrow(Throw* node) { |
| 181 IncrementNodeCount(); | |
| 182 node->set_base_id(ReserveIdRange(Throw::num_ids())); | 153 node->set_base_id(ReserveIdRange(Throw::num_ids())); |
| 183 Visit(node->exception()); | 154 Visit(node->exception()); |
| 184 } | 155 } |
| 185 | 156 |
| 186 | 157 |
| 187 void AstNumberingVisitor::VisitUnaryOperation(UnaryOperation* node) { | 158 void AstNumberingVisitor::VisitUnaryOperation(UnaryOperation* node) { |
| 188 IncrementNodeCount(); | |
| 189 node->set_base_id(ReserveIdRange(UnaryOperation::num_ids())); | 159 node->set_base_id(ReserveIdRange(UnaryOperation::num_ids())); |
| 190 Visit(node->expression()); | 160 Visit(node->expression()); |
| 191 } | 161 } |
| 192 | 162 |
| 193 | 163 |
| 194 void AstNumberingVisitor::VisitCountOperation(CountOperation* node) { | 164 void AstNumberingVisitor::VisitCountOperation(CountOperation* node) { |
| 195 IncrementNodeCount(); | |
| 196 node->set_base_id(ReserveIdRange(CountOperation::num_ids())); | 165 node->set_base_id(ReserveIdRange(CountOperation::num_ids())); |
| 197 Visit(node->expression()); | 166 Visit(node->expression()); |
| 198 } | 167 } |
| 199 | 168 |
| 200 | 169 |
| 201 void AstNumberingVisitor::VisitBlock(Block* node) { | 170 void AstNumberingVisitor::VisitBlock(Block* node) { |
| 202 IncrementNodeCount(); | |
| 203 node->set_base_id(ReserveIdRange(Block::num_ids())); | 171 node->set_base_id(ReserveIdRange(Block::num_ids())); |
| 204 if (node->scope() != NULL) VisitDeclarations(node->scope()->declarations()); | 172 if (node->scope() != NULL) VisitDeclarations(node->scope()->declarations()); |
| 205 VisitStatements(node->statements()); | 173 VisitStatements(node->statements()); |
| 206 } | 174 } |
| 207 | 175 |
| 208 | 176 |
| 209 void AstNumberingVisitor::VisitFunctionDeclaration(FunctionDeclaration* node) { | 177 void AstNumberingVisitor::VisitFunctionDeclaration(FunctionDeclaration* node) { |
| 210 IncrementNodeCount(); | |
| 211 VisitVariableProxy(node->proxy()); | 178 VisitVariableProxy(node->proxy()); |
| 212 VisitFunctionLiteral(node->fun()); | 179 VisitFunctionLiteral(node->fun()); |
| 213 } | 180 } |
| 214 | 181 |
| 215 | 182 |
| 216 void AstNumberingVisitor::VisitModuleLiteral(ModuleLiteral* node) { | 183 void AstNumberingVisitor::VisitModuleLiteral(ModuleLiteral* node) { |
| 217 IncrementNodeCount(); | |
| 218 VisitBlock(node->body()); | 184 VisitBlock(node->body()); |
| 219 } | 185 } |
| 220 | 186 |
| 221 | 187 |
| 222 void AstNumberingVisitor::VisitCallRuntime(CallRuntime* node) { | 188 void AstNumberingVisitor::VisitCallRuntime(CallRuntime* node) { |
| 223 IncrementNodeCount(); | |
| 224 node->set_base_id(ReserveIdRange(CallRuntime::num_ids())); | 189 node->set_base_id(ReserveIdRange(CallRuntime::num_ids())); |
| 225 VisitArguments(node->arguments()); | 190 VisitArguments(node->arguments()); |
| 226 } | 191 } |
| 227 | 192 |
| 228 | 193 |
| 229 void AstNumberingVisitor::VisitWithStatement(WithStatement* node) { | 194 void AstNumberingVisitor::VisitWithStatement(WithStatement* node) { |
| 230 IncrementNodeCount(); | |
| 231 Visit(node->expression()); | 195 Visit(node->expression()); |
| 232 Visit(node->statement()); | 196 Visit(node->statement()); |
| 233 } | 197 } |
| 234 | 198 |
| 235 | 199 |
| 236 void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) { | 200 void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) { |
| 237 IncrementNodeCount(); | |
| 238 node->set_base_id(ReserveIdRange(DoWhileStatement::num_ids())); | 201 node->set_base_id(ReserveIdRange(DoWhileStatement::num_ids())); |
| 239 Visit(node->body()); | 202 Visit(node->body()); |
| 240 Visit(node->cond()); | 203 Visit(node->cond()); |
| 241 } | 204 } |
| 242 | 205 |
| 243 | 206 |
| 244 void AstNumberingVisitor::VisitWhileStatement(WhileStatement* node) { | 207 void AstNumberingVisitor::VisitWhileStatement(WhileStatement* node) { |
| 245 IncrementNodeCount(); | |
| 246 node->set_base_id(ReserveIdRange(WhileStatement::num_ids())); | 208 node->set_base_id(ReserveIdRange(WhileStatement::num_ids())); |
| 247 Visit(node->cond()); | 209 Visit(node->cond()); |
| 248 Visit(node->body()); | 210 Visit(node->body()); |
| 249 } | 211 } |
| 250 | 212 |
| 251 | 213 |
| 252 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { | 214 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { |
| 253 IncrementNodeCount(); | |
| 254 Visit(node->try_block()); | 215 Visit(node->try_block()); |
| 255 Visit(node->catch_block()); | 216 Visit(node->catch_block()); |
| 256 } | 217 } |
| 257 | 218 |
| 258 | 219 |
| 259 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { | 220 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
| 260 IncrementNodeCount(); | |
| 261 Visit(node->try_block()); | 221 Visit(node->try_block()); |
| 262 Visit(node->finally_block()); | 222 Visit(node->finally_block()); |
| 263 } | 223 } |
| 264 | 224 |
| 265 | 225 |
| 266 void AstNumberingVisitor::VisitProperty(Property* node) { | 226 void AstNumberingVisitor::VisitProperty(Property* node) { |
| 267 IncrementNodeCount(); | |
| 268 node->set_base_id(ReserveIdRange(Property::num_ids())); | 227 node->set_base_id(ReserveIdRange(Property::num_ids())); |
| 269 Visit(node->key()); | 228 Visit(node->key()); |
| 270 Visit(node->obj()); | 229 Visit(node->obj()); |
| 271 } | 230 } |
| 272 | 231 |
| 273 | 232 |
| 274 void AstNumberingVisitor::VisitAssignment(Assignment* node) { | 233 void AstNumberingVisitor::VisitAssignment(Assignment* node) { |
| 275 IncrementNodeCount(); | |
| 276 node->set_base_id(ReserveIdRange(Assignment::num_ids())); | 234 node->set_base_id(ReserveIdRange(Assignment::num_ids())); |
| 277 if (node->is_compound()) VisitBinaryOperation(node->binary_operation()); | 235 if (node->is_compound()) VisitBinaryOperation(node->binary_operation()); |
| 278 Visit(node->target()); | 236 Visit(node->target()); |
| 279 Visit(node->value()); | 237 Visit(node->value()); |
| 280 } | 238 } |
| 281 | 239 |
| 282 | 240 |
| 283 void AstNumberingVisitor::VisitBinaryOperation(BinaryOperation* node) { | 241 void AstNumberingVisitor::VisitBinaryOperation(BinaryOperation* node) { |
| 284 IncrementNodeCount(); | |
| 285 node->set_base_id(ReserveIdRange(BinaryOperation::num_ids())); | 242 node->set_base_id(ReserveIdRange(BinaryOperation::num_ids())); |
| 286 Visit(node->left()); | 243 Visit(node->left()); |
| 287 Visit(node->right()); | 244 Visit(node->right()); |
| 288 } | 245 } |
| 289 | 246 |
| 290 | 247 |
| 291 void AstNumberingVisitor::VisitCompareOperation(CompareOperation* node) { | 248 void AstNumberingVisitor::VisitCompareOperation(CompareOperation* node) { |
| 292 IncrementNodeCount(); | |
| 293 node->set_base_id(ReserveIdRange(CompareOperation::num_ids())); | 249 node->set_base_id(ReserveIdRange(CompareOperation::num_ids())); |
| 294 Visit(node->left()); | 250 Visit(node->left()); |
| 295 Visit(node->right()); | 251 Visit(node->right()); |
| 296 } | 252 } |
| 297 | 253 |
| 298 | 254 |
| 299 void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) { | 255 void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) { |
| 300 IncrementNodeCount(); | |
| 301 node->set_base_id(ReserveIdRange(ForInStatement::num_ids())); | 256 node->set_base_id(ReserveIdRange(ForInStatement::num_ids())); |
| 302 Visit(node->each()); | 257 Visit(node->each()); |
| 303 Visit(node->enumerable()); | 258 Visit(node->enumerable()); |
| 304 Visit(node->body()); | 259 Visit(node->body()); |
| 305 } | 260 } |
| 306 | 261 |
| 307 | 262 |
| 308 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) { | 263 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) { |
| 309 IncrementNodeCount(); | |
| 310 node->set_base_id(ReserveIdRange(ForOfStatement::num_ids())); | 264 node->set_base_id(ReserveIdRange(ForOfStatement::num_ids())); |
| 311 Visit(node->assign_iterator()); | 265 Visit(node->assign_iterator()); |
| 312 Visit(node->next_result()); | 266 Visit(node->next_result()); |
| 313 Visit(node->result_done()); | 267 Visit(node->result_done()); |
| 314 Visit(node->assign_each()); | 268 Visit(node->assign_each()); |
| 315 Visit(node->body()); | 269 Visit(node->body()); |
| 316 } | 270 } |
| 317 | 271 |
| 318 | 272 |
| 319 void AstNumberingVisitor::VisitConditional(Conditional* node) { | 273 void AstNumberingVisitor::VisitConditional(Conditional* node) { |
| 320 IncrementNodeCount(); | |
| 321 node->set_base_id(ReserveIdRange(Conditional::num_ids())); | 274 node->set_base_id(ReserveIdRange(Conditional::num_ids())); |
| 322 Visit(node->condition()); | 275 Visit(node->condition()); |
| 323 Visit(node->then_expression()); | 276 Visit(node->then_expression()); |
| 324 Visit(node->else_expression()); | 277 Visit(node->else_expression()); |
| 325 } | 278 } |
| 326 | 279 |
| 327 | 280 |
| 328 void AstNumberingVisitor::VisitIfStatement(IfStatement* node) { | 281 void AstNumberingVisitor::VisitIfStatement(IfStatement* node) { |
| 329 IncrementNodeCount(); | |
| 330 node->set_base_id(ReserveIdRange(IfStatement::num_ids())); | 282 node->set_base_id(ReserveIdRange(IfStatement::num_ids())); |
| 331 Visit(node->condition()); | 283 Visit(node->condition()); |
| 332 Visit(node->then_statement()); | 284 Visit(node->then_statement()); |
| 333 if (node->HasElseStatement()) { | 285 if (node->HasElseStatement()) { |
| 334 Visit(node->else_statement()); | 286 Visit(node->else_statement()); |
| 335 } | 287 } |
| 336 } | 288 } |
| 337 | 289 |
| 338 | 290 |
| 339 void AstNumberingVisitor::VisitSwitchStatement(SwitchStatement* node) { | 291 void AstNumberingVisitor::VisitSwitchStatement(SwitchStatement* node) { |
| 340 IncrementNodeCount(); | |
| 341 node->set_base_id(ReserveIdRange(SwitchStatement::num_ids())); | 292 node->set_base_id(ReserveIdRange(SwitchStatement::num_ids())); |
| 342 Visit(node->tag()); | 293 Visit(node->tag()); |
| 343 ZoneList<CaseClause*>* cases = node->cases(); | 294 ZoneList<CaseClause*>* cases = node->cases(); |
| 344 for (int i = 0; i < cases->length(); i++) { | 295 for (int i = 0; i < cases->length(); i++) { |
| 345 VisitCaseClause(cases->at(i)); | 296 VisitCaseClause(cases->at(i)); |
| 346 } | 297 } |
| 347 } | 298 } |
| 348 | 299 |
| 349 | 300 |
| 350 void AstNumberingVisitor::VisitCaseClause(CaseClause* node) { | 301 void AstNumberingVisitor::VisitCaseClause(CaseClause* node) { |
| 351 IncrementNodeCount(); | |
| 352 node->set_base_id(ReserveIdRange(CaseClause::num_ids())); | 302 node->set_base_id(ReserveIdRange(CaseClause::num_ids())); |
| 353 if (!node->is_default()) Visit(node->label()); | 303 if (!node->is_default()) Visit(node->label()); |
| 354 VisitStatements(node->statements()); | 304 VisitStatements(node->statements()); |
| 355 } | 305 } |
| 356 | 306 |
| 357 | 307 |
| 358 void AstNumberingVisitor::VisitForStatement(ForStatement* node) { | 308 void AstNumberingVisitor::VisitForStatement(ForStatement* node) { |
| 359 IncrementNodeCount(); | |
| 360 node->set_base_id(ReserveIdRange(ForStatement::num_ids())); | 309 node->set_base_id(ReserveIdRange(ForStatement::num_ids())); |
| 361 if (node->init() != NULL) Visit(node->init()); | 310 if (node->init() != NULL) Visit(node->init()); |
| 362 if (node->cond() != NULL) Visit(node->cond()); | 311 if (node->cond() != NULL) Visit(node->cond()); |
| 363 if (node->next() != NULL) Visit(node->next()); | 312 if (node->next() != NULL) Visit(node->next()); |
| 364 Visit(node->body()); | 313 Visit(node->body()); |
| 365 } | 314 } |
| 366 | 315 |
| 367 | 316 |
| 368 void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) { | 317 void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) { |
| 369 IncrementNodeCount(); | |
| 370 node->set_base_id(ReserveIdRange(ClassLiteral::num_ids())); | 318 node->set_base_id(ReserveIdRange(ClassLiteral::num_ids())); |
| 371 if (node->extends()) Visit(node->extends()); | 319 if (node->extends()) Visit(node->extends()); |
| 372 if (node->constructor()) Visit(node->constructor()); | 320 if (node->constructor()) Visit(node->constructor()); |
| 373 for (int i = 0; i < node->properties()->length(); i++) { | 321 for (int i = 0; i < node->properties()->length(); i++) { |
| 374 VisitObjectLiteralProperty(node->properties()->at(i)); | 322 VisitObjectLiteralProperty(node->properties()->at(i)); |
| 375 } | 323 } |
| 376 } | 324 } |
| 377 | 325 |
| 378 | 326 |
| 379 void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) { | 327 void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) { |
| 380 IncrementNodeCount(); | |
| 381 node->set_base_id(ReserveIdRange(ObjectLiteral::num_ids())); | 328 node->set_base_id(ReserveIdRange(ObjectLiteral::num_ids())); |
| 382 for (int i = 0; i < node->properties()->length(); i++) { | 329 for (int i = 0; i < node->properties()->length(); i++) { |
| 383 VisitObjectLiteralProperty(node->properties()->at(i)); | 330 VisitObjectLiteralProperty(node->properties()->at(i)); |
| 384 } | 331 } |
| 385 } | 332 } |
| 386 | 333 |
| 387 | 334 |
| 388 void AstNumberingVisitor::VisitObjectLiteralProperty( | 335 void AstNumberingVisitor::VisitObjectLiteralProperty( |
| 389 ObjectLiteralProperty* node) { | 336 ObjectLiteralProperty* node) { |
| 390 Visit(node->key()); | 337 Visit(node->key()); |
| 391 Visit(node->value()); | 338 Visit(node->value()); |
| 392 } | 339 } |
| 393 | 340 |
| 394 | 341 |
| 395 void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) { | 342 void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) { |
| 396 IncrementNodeCount(); | |
| 397 node->set_base_id(ReserveIdRange(node->num_ids())); | 343 node->set_base_id(ReserveIdRange(node->num_ids())); |
| 398 for (int i = 0; i < node->values()->length(); i++) { | 344 for (int i = 0; i < node->values()->length(); i++) { |
| 399 Visit(node->values()->at(i)); | 345 Visit(node->values()->at(i)); |
| 400 } | 346 } |
| 401 } | 347 } |
| 402 | 348 |
| 403 | 349 |
| 404 void AstNumberingVisitor::VisitCall(Call* node) { | 350 void AstNumberingVisitor::VisitCall(Call* node) { |
| 405 IncrementNodeCount(); | |
| 406 node->set_base_id(ReserveIdRange(Call::num_ids())); | 351 node->set_base_id(ReserveIdRange(Call::num_ids())); |
| 407 Visit(node->expression()); | 352 Visit(node->expression()); |
| 408 VisitArguments(node->arguments()); | 353 VisitArguments(node->arguments()); |
| 409 } | 354 } |
| 410 | 355 |
| 411 | 356 |
| 412 void AstNumberingVisitor::VisitCallNew(CallNew* node) { | 357 void AstNumberingVisitor::VisitCallNew(CallNew* node) { |
| 413 IncrementNodeCount(); | |
| 414 node->set_base_id(ReserveIdRange(CallNew::num_ids())); | 358 node->set_base_id(ReserveIdRange(CallNew::num_ids())); |
| 415 Visit(node->expression()); | 359 Visit(node->expression()); |
| 416 VisitArguments(node->arguments()); | 360 VisitArguments(node->arguments()); |
| 417 } | 361 } |
| 418 | 362 |
| 419 | 363 |
| 420 void AstNumberingVisitor::VisitStatements(ZoneList<Statement*>* statements) { | 364 void AstNumberingVisitor::VisitStatements(ZoneList<Statement*>* statements) { |
| 421 if (statements == NULL) return; | 365 if (statements == NULL) return; |
| 422 for (int i = 0; i < statements->length(); i++) { | 366 for (int i = 0; i < statements->length(); i++) { |
| 423 Visit(statements->at(i)); | 367 Visit(statements->at(i)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 434 | 378 |
| 435 | 379 |
| 436 void AstNumberingVisitor::VisitArguments(ZoneList<Expression*>* arguments) { | 380 void AstNumberingVisitor::VisitArguments(ZoneList<Expression*>* arguments) { |
| 437 for (int i = 0; i < arguments->length(); i++) { | 381 for (int i = 0; i < arguments->length(); i++) { |
| 438 Visit(arguments->at(i)); | 382 Visit(arguments->at(i)); |
| 439 } | 383 } |
| 440 } | 384 } |
| 441 | 385 |
| 442 | 386 |
| 443 void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) { | 387 void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) { |
| 444 IncrementNodeCount(); | |
| 445 node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids())); | 388 node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids())); |
| 446 // We don't recurse into the declarations or body of the function literal: | 389 // We don't recurse into the declarations or body of the function literal: |
| 447 // you have to separately Renumber() each FunctionLiteral that you compile. | 390 // you have to separately Renumber() each FunctionLiteral that you compile. |
| 448 } | 391 } |
| 449 | 392 |
| 450 | 393 |
| 451 void AstNumberingVisitor::Renumber(FunctionLiteral* node) { | 394 void AstNumberingVisitor::Renumber(FunctionLiteral* node) { |
| 452 properties_.flags()->Add(*node->flags()); | |
| 453 properties_.increase_feedback_slots(node->slot_count()); | |
| 454 properties_.increase_ic_feedback_slots(node->ic_slot_count()); | |
| 455 | |
| 456 if (node->scope()->HasIllegalRedeclaration()) { | 395 if (node->scope()->HasIllegalRedeclaration()) { |
| 457 node->scope()->VisitIllegalRedeclaration(this); | 396 node->scope()->VisitIllegalRedeclaration(this); |
| 458 return; | 397 return; |
| 459 } | 398 } |
| 460 | 399 |
| 461 Scope* scope = node->scope(); | 400 Scope* scope = node->scope(); |
| 462 VisitDeclarations(scope->declarations()); | 401 VisitDeclarations(scope->declarations()); |
| 463 if (scope->is_function_scope() && scope->function() != NULL) { | 402 if (scope->is_function_scope() && scope->function() != NULL) { |
| 464 // Visit the name of the named function expression. | 403 // Visit the name of the named function expression. |
| 465 Visit(scope->function()); | 404 Visit(scope->function()); |
| 466 } | 405 } |
| 467 VisitStatements(node->body()); | 406 VisitStatements(node->body()); |
| 468 | |
| 469 node->set_ast_properties(&properties_); | |
| 470 } | 407 } |
| 471 | 408 |
| 472 | 409 |
| 473 bool AstNumbering::Renumber(FunctionLiteral* function, Zone* zone) { | 410 bool AstNumbering::Renumber(FunctionLiteral* function, Zone* zone) { |
| 474 AstNumberingVisitor visitor(zone); | 411 AstNumberingVisitor visitor(zone); |
| 475 visitor.Renumber(function); | 412 visitor.Renumber(function); |
| 476 return !visitor.HasStackOverflow(); | 413 return !visitor.HasStackOverflow(); |
| 477 } | 414 } |
| 478 } | 415 } |
| 479 } // namespace v8::internal | 416 } // namespace v8::internal |
| OLD | NEW |