OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "usage-analyzer.h" | 32 #include "usage-analyzer.h" |
33 | 33 |
34 namespace v8 { namespace internal { | 34 namespace v8 { namespace internal { |
35 | 35 |
36 // Weight boundaries | 36 // Weight boundaries |
37 static const int MinWeight = 1; | 37 static const int MinWeight = 1; |
38 static const int MaxWeight = 1000000; | 38 static const int MaxWeight = 1000000; |
39 static const int InitialWeight = 100; | 39 static const int InitialWeight = 100; |
40 | 40 |
41 | 41 |
42 class UsageComputer: public Visitor { | 42 class UsageComputer: public AstVisitor { |
43 public: | 43 public: |
44 static bool Traverse(Node* node); | 44 static bool Traverse(Node* node); |
45 | 45 |
46 void VisitBlock(Block* node); | 46 void VisitBlock(Block* node); |
47 void VisitDeclaration(Declaration* node); | 47 void VisitDeclaration(Declaration* node); |
48 void VisitExpressionStatement(ExpressionStatement* node); | 48 void VisitExpressionStatement(ExpressionStatement* node); |
49 void VisitEmptyStatement(EmptyStatement* node); | 49 void VisitEmptyStatement(EmptyStatement* node); |
50 void VisitIfStatement(IfStatement* node); | 50 void VisitIfStatement(IfStatement* node); |
51 void VisitContinueStatement(ContinueStatement* node); | 51 void VisitContinueStatement(ContinueStatement* node); |
52 void VisitBreakStatement(BreakStatement* node); | 52 void VisitBreakStatement(BreakStatement* node); |
(...skipping 13 matching lines...) Expand all Loading... |
66 void VisitVariable(Variable* node); | 66 void VisitVariable(Variable* node); |
67 void VisitVariableProxy(VariableProxy* node); | 67 void VisitVariableProxy(VariableProxy* node); |
68 void VisitLiteral(Literal* node); | 68 void VisitLiteral(Literal* node); |
69 void VisitRegExpLiteral(RegExpLiteral* node); | 69 void VisitRegExpLiteral(RegExpLiteral* node); |
70 void VisitObjectLiteral(ObjectLiteral* node); | 70 void VisitObjectLiteral(ObjectLiteral* node); |
71 void VisitArrayLiteral(ArrayLiteral* node); | 71 void VisitArrayLiteral(ArrayLiteral* node); |
72 void VisitAssignment(Assignment* node); | 72 void VisitAssignment(Assignment* node); |
73 void VisitThrow(Throw* node); | 73 void VisitThrow(Throw* node); |
74 void VisitProperty(Property* node); | 74 void VisitProperty(Property* node); |
75 void VisitCall(Call* node); | 75 void VisitCall(Call* node); |
| 76 void VisitCallEval(CallEval* node); |
76 void VisitCallNew(CallNew* node); | 77 void VisitCallNew(CallNew* node); |
77 void VisitCallRuntime(CallRuntime* node); | 78 void VisitCallRuntime(CallRuntime* node); |
78 void VisitUnaryOperation(UnaryOperation* node); | 79 void VisitUnaryOperation(UnaryOperation* node); |
79 void VisitCountOperation(CountOperation* node); | 80 void VisitCountOperation(CountOperation* node); |
80 void VisitBinaryOperation(BinaryOperation* node); | 81 void VisitBinaryOperation(BinaryOperation* node); |
81 void VisitCompareOperation(CompareOperation* node); | 82 void VisitCompareOperation(CompareOperation* node); |
82 void VisitThisFunction(ThisFunction* node); | 83 void VisitThisFunction(ThisFunction* node); |
83 | 84 |
84 private: | 85 private: |
85 int weight_; | 86 int weight_; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 315 } |
315 } | 316 } |
316 | 317 |
317 | 318 |
318 void UsageComputer::VisitCall(Call* node) { | 319 void UsageComputer::VisitCall(Call* node) { |
319 Read(node->expression()); | 320 Read(node->expression()); |
320 ReadList(node->arguments()); | 321 ReadList(node->arguments()); |
321 } | 322 } |
322 | 323 |
323 | 324 |
| 325 void UsageComputer::VisitCallEval(CallEval* node) { |
| 326 VisitCall(node); |
| 327 } |
| 328 |
| 329 |
324 void UsageComputer::VisitCallNew(CallNew* node) { | 330 void UsageComputer::VisitCallNew(CallNew* node) { |
325 VisitCall(node); | 331 VisitCall(node); |
326 } | 332 } |
327 | 333 |
328 | 334 |
329 void UsageComputer::VisitCallRuntime(CallRuntime* node) { | 335 void UsageComputer::VisitCallRuntime(CallRuntime* node) { |
330 ReadList(node->arguments()); | 336 ReadList(node->arguments()); |
331 } | 337 } |
332 | 338 |
333 | 339 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 435 |
430 // ---------------------------------------------------------------------------- | 436 // ---------------------------------------------------------------------------- |
431 // Interface to variable usage analysis | 437 // Interface to variable usage analysis |
432 | 438 |
433 bool AnalyzeVariableUsage(FunctionLiteral* lit) { | 439 bool AnalyzeVariableUsage(FunctionLiteral* lit) { |
434 if (!FLAG_usage_computation) return true; | 440 if (!FLAG_usage_computation) return true; |
435 return UsageComputer::Traverse(lit); | 441 return UsageComputer::Traverse(lit); |
436 } | 442 } |
437 | 443 |
438 } } // namespace v8::internal | 444 } } // namespace v8::internal |
OLD | NEW |