V8 Project
func-name-inferrer.h
Go to the documentation of this file.
1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_FUNC_NAME_INFERRER_H_
6 #define V8_FUNC_NAME_INFERRER_H_
7 
8 #include "src/handles.h"
9 #include "src/zone.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 class AstRawString;
15 class AstString;
16 class AstValueFactory;
17 class FunctionLiteral;
18 
19 // FuncNameInferrer is a stateful class that is used to perform name
20 // inference for anonymous functions during static analysis of source code.
21 // Inference is performed in cases when an anonymous function is assigned
22 // to a variable or a property (see test-func-name-inference.cc for examples.)
23 //
24 // The basic idea is that during parsing of LHSs of certain expressions
25 // (assignments, declarations, object literals) we collect name strings,
26 // and during parsing of the RHS, a function literal can be collected. After
27 // parsing the RHS we can infer a name for function literals that do not have
28 // a name.
29 class FuncNameInferrer : public ZoneObject {
30  public:
31  FuncNameInferrer(AstValueFactory* ast_value_factory, Zone* zone);
32 
33  // Returns whether we have entered name collection state.
34  bool IsOpen() const { return !entries_stack_.is_empty(); }
35 
36  // Pushes an enclosing the name of enclosing function onto names stack.
37  void PushEnclosingName(const AstRawString* name);
38 
39  // Enters name collection state.
40  void Enter() {
41  entries_stack_.Add(names_stack_.length(), zone());
42  }
43 
44  // Pushes an encountered name onto names stack when in collection state.
45  void PushLiteralName(const AstRawString* name);
46 
47  void PushVariableName(const AstRawString* name);
48 
49  // Adds a function to infer name for.
50  void AddFunction(FunctionLiteral* func_to_infer) {
51  if (IsOpen()) {
52  funcs_to_infer_.Add(func_to_infer, zone());
53  }
54  }
55 
57  if (IsOpen() && !funcs_to_infer_.is_empty()) {
58  funcs_to_infer_.RemoveLast();
59  }
60  }
61 
62  // Infers a function name and leaves names collection state.
63  void Infer() {
64  DCHECK(IsOpen());
65  if (!funcs_to_infer_.is_empty()) {
67  }
68  }
69 
70  // Leaves names collection state.
71  void Leave() {
72  DCHECK(IsOpen());
73  names_stack_.Rewind(entries_stack_.RemoveLast());
74  if (entries_stack_.is_empty())
75  funcs_to_infer_.Clear();
76  }
77 
78  private:
79  enum NameType {
83  };
84  struct Name {
88  };
89 
90  Zone* zone() const { return zone_; }
91 
92  // Constructs a full name in dotted notation from gathered names.
94 
95  // A helper function for MakeNameFromStack.
96  const AstString* MakeNameFromStackHelper(int pos,
97  const AstString* prev);
98 
99  // Performs name inferring for added functions.
100  void InferFunctionsNames();
101 
107 
109 };
110 
111 
112 } } // namespace v8::internal
113 
114 #endif // V8_FUNC_NAME_INFERRER_H_
const AstString * MakeNameFromStackHelper(int pos, const AstString *prev)
void PushVariableName(const AstRawString *name)
void AddFunction(FunctionLiteral *func_to_infer)
void PushEnclosingName(const AstRawString *name)
ZoneList< FunctionLiteral * > funcs_to_infer_
DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer)
void PushLiteralName(const AstRawString *name)
FuncNameInferrer(AstValueFactory *ast_value_factory, Zone *zone)
const AstString * MakeNameFromStack()
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
Definition: list-inl.h:17
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
#define DCHECK(condition)
Definition: logging.h:205
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
Name(const AstRawString *name, NameType type)