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

Side by Side Diff: src/func-name-inferrer.h

Issue 7206015: Fix issue 1354: Bad function name inference. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/func-name-inferrer.cc » ('j') | src/func-name-inferrer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 25 matching lines...) Expand all
36 // Inference is performed in cases when an anonymous function is assigned 36 // Inference is performed in cases when an anonymous function is assigned
37 // to a variable or a property (see test-func-name-inference.cc for examples.) 37 // to a variable or a property (see test-func-name-inference.cc for examples.)
38 // 38 //
39 // The basic idea is that during parsing of LHSs of certain expressions 39 // The basic idea is that during parsing of LHSs of certain expressions
40 // (assignments, declarations, object literals) we collect name strings, 40 // (assignments, declarations, object literals) we collect name strings,
41 // and during parsing of the RHS, a function literal can be collected. After 41 // and during parsing of the RHS, a function literal can be collected. After
42 // parsing the RHS we can infer a name for function literals that do not have 42 // parsing the RHS we can infer a name for function literals that do not have
43 // a name. 43 // a name.
44 class FuncNameInferrer : public ZoneObject { 44 class FuncNameInferrer : public ZoneObject {
45 public: 45 public:
46 FuncNameInferrer() 46 FuncNameInferrer();
47 : entries_stack_(10),
48 names_stack_(5),
49 funcs_to_infer_(4),
50 dot_(FACTORY->NewStringFromAscii(CStrVector("."))) {
51 }
52 47
53 // Returns whether we have entered name collection state. 48 // Returns whether we have entered name collection state.
54 bool IsOpen() const { return !entries_stack_.is_empty(); } 49 bool IsOpen() const { return !entries_stack_.is_empty(); }
55 50
56 // Pushes an enclosing the name of enclosing function onto names stack. 51 // Pushes an enclosing the name of enclosing function onto names stack.
57 void PushEnclosingName(Handle<String> name); 52 void PushEnclosingName(Handle<String> name);
58 53
59 // Enters name collection state. 54 // Enters name collection state.
60 void Enter() { 55 void Enter() {
61 entries_stack_.Add(names_stack_.length()); 56 entries_stack_.Add(names_stack_.length());
(...skipping 12 matching lines...) Expand all
74 } 69 }
75 70
76 // Infers a function name and leaves names collection state. 71 // Infers a function name and leaves names collection state.
77 void Infer() { 72 void Infer() {
78 ASSERT(IsOpen()); 73 ASSERT(IsOpen());
79 if (!funcs_to_infer_.is_empty()) { 74 if (!funcs_to_infer_.is_empty()) {
80 InferFunctionsNames(); 75 InferFunctionsNames();
81 } 76 }
82 } 77 }
83 78
84 // Infers a function name and leaves names collection state. 79 // Infers a function name and leaves names collection state.
Vitaly Repeshko 2011/06/22 13:21:30 The comment should be fixed.
mnaganov (inactive) 2011/06/22 20:21:08 Done.
85 void Leave() { 80 void Leave() {
86 ASSERT(IsOpen()); 81 ASSERT(IsOpen());
87 names_stack_.Rewind(entries_stack_.RemoveLast()); 82 names_stack_.Rewind(entries_stack_.RemoveLast());
88 } 83 }
89 84
85 Handle<String> anonymous_function() { return anonymous_function_; }
86
87 static const char* const kAnonymousFunctionName;
88
90 private: 89 private:
90 enum NameType {
91 kEnclosingConstructorName,
92 kLiteralName,
93 kVariableName
94 };
95 struct Name {
96 Name(Handle<String> name, NameType type) : name(name), type(type) { }
97 Handle<String> name;
98 NameType type;
99 };
100
91 // Constructs a full name in dotted notation from gathered names. 101 // Constructs a full name in dotted notation from gathered names.
92 Handle<String> MakeNameFromStack(); 102 Handle<String> MakeNameFromStack();
93 103
94 // A helper function for MakeNameFromStack. 104 // A helper function for MakeNameFromStack.
95 Handle<String> MakeNameFromStackHelper(int pos, Handle<String> prev); 105 Handle<String> MakeNameFromStackHelper(int pos, Handle<String> prev);
96 106
97 // Performs name inferring for added functions. 107 // Performs name inferring for added functions.
98 void InferFunctionsNames(); 108 void InferFunctionsNames();
99 109
100 ZoneList<int> entries_stack_; 110 ZoneList<int> entries_stack_;
101 ZoneList<Handle<String> > names_stack_; 111 ZoneList<Name> names_stack_;
102 ZoneList<FunctionLiteral*> funcs_to_infer_; 112 ZoneList<FunctionLiteral*> funcs_to_infer_;
103 Handle<String> dot_; 113 Handle<String> dot_;
Vitaly Repeshko 2011/06/22 13:21:30 Function name inference is an integral part of the
mnaganov (inactive) 2011/06/22 20:21:08 Done.
114 Handle<String> anonymous_function_;
104 115
105 DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer); 116 DISALLOW_COPY_AND_ASSIGN(FuncNameInferrer);
106 }; 117 };
107 118
108 119
109 } } // namespace v8::internal 120 } } // namespace v8::internal
110 121
111 #endif // V8_FUNC_NAME_INFERRER_H_ 122 #endif // V8_FUNC_NAME_INFERRER_H_
OLDNEW
« no previous file with comments | « no previous file | src/func-name-inferrer.cc » ('j') | src/func-name-inferrer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698