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

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

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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 | « src/func-name-inferrer.h ('k') | src/gdb-jit.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "ast.h" 30 #include "ast.h"
31 #include "func-name-inferrer.h" 31 #include "func-name-inferrer.h"
32 #include "list-inl.h" 32 #include "list-inl.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 FuncNameInferrer::FuncNameInferrer(Isolate* isolate)
38 : isolate_(isolate),
39 entries_stack_(10),
40 names_stack_(5),
41 funcs_to_infer_(4) {
42 }
43
37 44
38 void FuncNameInferrer::PushEnclosingName(Handle<String> name) { 45 void FuncNameInferrer::PushEnclosingName(Handle<String> name) {
39 // Enclosing name is a name of a constructor function. To check 46 // Enclosing name is a name of a constructor function. To check
40 // that it is really a constructor, we check that it is not empty 47 // that it is really a constructor, we check that it is not empty
41 // and starts with a capital letter. 48 // and starts with a capital letter.
42 if (name->length() > 0 && Runtime::IsUpperCaseChar( 49 if (name->length() > 0 && Runtime::IsUpperCaseChar(
43 Isolate::Current()->runtime_state(), name->Get(0))) { 50 isolate()->runtime_state(), name->Get(0))) {
44 names_stack_.Add(name); 51 names_stack_.Add(Name(name, kEnclosingConstructorName));
45 } 52 }
46 } 53 }
47 54
48 55
49 void FuncNameInferrer::PushLiteralName(Handle<String> name) { 56 void FuncNameInferrer::PushLiteralName(Handle<String> name) {
50 if (IsOpen() && !HEAP->prototype_symbol()->Equals(*name)) { 57 if (IsOpen() && !isolate()->heap()->prototype_symbol()->Equals(*name)) {
51 names_stack_.Add(name); 58 names_stack_.Add(Name(name, kLiteralName));
52 } 59 }
53 } 60 }
54 61
55 62
56 void FuncNameInferrer::PushVariableName(Handle<String> name) { 63 void FuncNameInferrer::PushVariableName(Handle<String> name) {
57 if (IsOpen() && !HEAP->result_symbol()->Equals(*name)) { 64 if (IsOpen() && !isolate()->heap()->result_symbol()->Equals(*name)) {
58 names_stack_.Add(name); 65 names_stack_.Add(Name(name, kVariableName));
59 } 66 }
60 } 67 }
61 68
62 69
63 Handle<String> FuncNameInferrer::MakeNameFromStack() { 70 Handle<String> FuncNameInferrer::MakeNameFromStack() {
64 if (names_stack_.is_empty()) { 71 return MakeNameFromStackHelper(0, isolate()->factory()->empty_string());
65 return FACTORY->empty_string();
66 } else {
67 return MakeNameFromStackHelper(1, names_stack_.at(0));
68 }
69 } 72 }
70 73
71 74
72 Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos, 75 Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos,
73 Handle<String> prev) { 76 Handle<String> prev) {
74 if (pos >= names_stack_.length()) { 77 if (pos >= names_stack_.length()) return prev;
75 return prev; 78 if (pos < names_stack_.length() - 1 &&
79 names_stack_.at(pos).type == kVariableName &&
80 names_stack_.at(pos + 1).type == kVariableName) {
81 // Skip consecutive variable declarations.
82 return MakeNameFromStackHelper(pos + 1, prev);
76 } else { 83 } else {
77 Handle<String> curr = FACTORY->NewConsString(dot_, names_stack_.at(pos)); 84 if (prev->length() > 0) {
78 return MakeNameFromStackHelper(pos + 1, FACTORY->NewConsString(prev, curr)); 85 Factory* factory = isolate()->factory();
86 Handle<String> curr = factory->NewConsString(
87 factory->dot_symbol(), names_stack_.at(pos).name);
88 return MakeNameFromStackHelper(pos + 1,
89 factory->NewConsString(prev, curr));
90 } else {
91 return MakeNameFromStackHelper(pos + 1, names_stack_.at(pos).name);
92 }
79 } 93 }
80 } 94 }
81 95
82 96
83 void FuncNameInferrer::InferFunctionsNames() { 97 void FuncNameInferrer::InferFunctionsNames() {
84 Handle<String> func_name = MakeNameFromStack(); 98 Handle<String> func_name = MakeNameFromStack();
85 for (int i = 0; i < funcs_to_infer_.length(); ++i) { 99 for (int i = 0; i < funcs_to_infer_.length(); ++i) {
86 funcs_to_infer_[i]->set_inferred_name(func_name); 100 funcs_to_infer_[i]->set_inferred_name(func_name);
87 } 101 }
88 funcs_to_infer_.Rewind(0); 102 funcs_to_infer_.Rewind(0);
89 } 103 }
90 104
91 105
92 } } // namespace v8::internal 106 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/func-name-inferrer.h ('k') | src/gdb-jit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698