Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: src/func-name-inferrer.h

Issue 3141034: Move the function name inferrer code from the AstOptimizer to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/func-name-inferrer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/func-name-inferrer.h
===================================================================
--- src/func-name-inferrer.h (revision 5319)
+++ src/func-name-inferrer.h (working copy)
@@ -36,11 +36,12 @@
// Inference is performed in cases when an anonymous function is assigned
// to a variable or a property (see test-func-name-inference.cc for examples.)
//
-// The basic idea is that during AST traversal LHSs of expressions are
-// always visited before RHSs. Thus, during visiting the LHS, a name can be
-// collected, and during visiting the RHS, a function literal can be collected.
-// Inference is performed while leaving the assignment node.
-class FuncNameInferrer BASE_EMBEDDED {
+// The basic idea is that during parsing of LHSs of certain expressions
+// (assignments, declarations, object literals) we collect name strings,
+// and during parsing of the RHS, a function literal can be collected. After
+// parsing the RHS we can infer a name for function literals that do not have
+// a name.
+class FuncNameInferrer : public ZoneObject {
public:
FuncNameInferrer()
: entries_stack_(10),
@@ -61,12 +62,10 @@
}
// Pushes an encountered name onto names stack when in collection state.
- void PushName(Handle<String> name) {
- if (IsOpen()) {
- names_stack_.Add(name);
- }
- }
+ void PushLiteralName(Handle<String> name);
+ void PushVariableName(Handle<String> name);
+
// Adds a function to infer name for.
void AddFunction(FunctionLiteral* func_to_infer) {
if (IsOpen()) {
@@ -75,11 +74,16 @@
}
// Infers a function name and leaves names collection state.
- void InferAndLeave() {
+ void Infer() {
ASSERT(IsOpen());
if (!funcs_to_infer_.is_empty()) {
InferFunctionsNames();
}
+ }
+
+ // Infers a function name and leaves names collection state.
+ void Leave() {
+ ASSERT(IsOpen());
names_stack_.Rewind(entries_stack_.RemoveLast());
}
@@ -102,34 +106,6 @@
};
-// A wrapper class that automatically calls InferAndLeave when
-// leaving scope.
-class ScopedFuncNameInferrer BASE_EMBEDDED {
- public:
- explicit ScopedFuncNameInferrer(FuncNameInferrer* inferrer)
- : inferrer_(inferrer),
- is_entered_(false) {}
-
- ~ScopedFuncNameInferrer() {
- if (is_entered_) {
- inferrer_->InferAndLeave();
- }
- }
-
- // Triggers the wrapped inferrer into name collection state.
- void Enter() {
- inferrer_->Enter();
- is_entered_ = true;
- }
-
- private:
- FuncNameInferrer* inferrer_;
- bool is_entered_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedFuncNameInferrer);
-};
-
-
} } // namespace v8::internal
#endif // V8_FUNC_NAME_INFERRER_H_
« no previous file with comments | « no previous file | src/func-name-inferrer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698