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

Side by Side Diff: src/ast.cc

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: more cleanup Created 6 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 | « src/ast.h ('k') | src/ast-string-table.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ast.h" 5 #include "ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "builtins.h" 8 #include "builtins.h"
9 #include "code-stubs.h" 9 #include "code-stubs.h"
10 #include "contexts.h" 10 #include "contexts.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 50
51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const { 51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const {
52 const VariableProxy* var_proxy = AsVariableProxy(); 52 const VariableProxy* var_proxy = AsVariableProxy();
53 if (var_proxy == NULL) return false; 53 if (var_proxy == NULL) return false;
54 Variable* var = var_proxy->var(); 54 Variable* var = var_proxy->var();
55 // The global identifier "undefined" is immutable. Everything 55 // The global identifier "undefined" is immutable. Everything
56 // else could be reassigned. 56 // else could be reassigned.
57 return var != NULL && var->location() == Variable::UNALLOCATED && 57 return var != NULL && var->location() == Variable::UNALLOCATED &&
58 String::Equals(var_proxy->name(), 58 var_proxy->raw_name()->IsOneByteEqualTo("undefined");
59 isolate->factory()->undefined_string());
60 } 59 }
61 60
62 61
63 VariableProxy::VariableProxy(Zone* zone, Variable* var, int position) 62 VariableProxy::VariableProxy(Zone* zone, Variable* var, int position)
64 : Expression(zone, position), 63 : Expression(zone, position),
65 name_(var->name()), 64 name_(var->raw_name()),
66 var_(NULL), // Will be set by the call to BindTo. 65 var_(NULL), // Will be set by the call to BindTo.
67 is_this_(var->is_this()), 66 is_this_(var->is_this()),
68 is_trivial_(false), 67 is_trivial_(false),
69 is_lvalue_(false), 68 is_lvalue_(false),
70 interface_(var->interface()) { 69 interface_(var->interface()) {
71 BindTo(var); 70 BindTo(var);
72 } 71 }
73 72
74 73
75 VariableProxy::VariableProxy(Zone* zone, 74 VariableProxy::VariableProxy(Zone* zone,
76 Handle<String> name, 75 const AstString* name,
77 bool is_this, 76 bool is_this,
78 Interface* interface, 77 Interface* interface,
79 int position) 78 int position)
80 : Expression(zone, position), 79 : Expression(zone, position),
81 name_(name), 80 name_(name),
82 var_(NULL), 81 var_(NULL),
83 is_this_(is_this), 82 is_this_(is_this),
84 is_trivial_(false), 83 is_trivial_(false),
85 is_lvalue_(false), 84 is_lvalue_(false),
86 interface_(interface) { 85 interface_(interface) {
87 // Names must be canonicalized for fast equality checks.
88 ASSERT(name->IsInternalizedString());
89 } 86 }
90 87
91 88
92 void VariableProxy::BindTo(Variable* var) { 89 void VariableProxy::BindTo(Variable* var) {
93 ASSERT(var_ == NULL); // must be bound only once 90 ASSERT(var_ == NULL); // must be bound only once
94 ASSERT(var != NULL); // must bind 91 ASSERT(var != NULL); // must bind
95 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); 92 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface()));
96 ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name())); 93 ASSERT((is_this() && var->is_this()) || name_ == var->raw_name());
97 // Ideally CONST-ness should match. However, this is very hard to achieve 94 // Ideally CONST-ness should match. However, this is very hard to achieve
98 // because we don't know the exact semantics of conflicting (const and 95 // because we don't know the exact semantics of conflicting (const and
99 // non-const) multiple variable declarations, const vars introduced via 96 // non-const) multiple variable declarations, const vars introduced via
100 // eval() etc. Const-ness and variable declarations are a complete mess 97 // eval() etc. Const-ness and variable declarations are a complete mess
101 // in JS. Sigh... 98 // in JS. Sigh...
102 var_ = var; 99 var_ = var;
103 var->set_is_used(true); 100 var->set_is_used(true);
104 } 101 }
105 102
106 103
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); 170 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
174 if (shared->start_position() == start_position()) { 171 if (shared->start_position() == start_position()) {
175 shared_info_ = Handle<SharedFunctionInfo>(shared); 172 shared_info_ = Handle<SharedFunctionInfo>(shared);
176 break; 173 break;
177 } 174 }
178 } 175 }
179 } 176 }
180 } 177 }
181 178
182 179
183 ObjectLiteralProperty::ObjectLiteralProperty( 180 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone,
184 Zone* zone, Literal* key, Expression* value) { 181 AstStringTable* string_table,
182 Literal* key, Expression* value) {
185 emit_store_ = true; 183 emit_store_ = true;
186 key_ = key; 184 key_ = key;
187 value_ = value; 185 value_ = value;
188 Handle<Object> k = key->value(); 186 if (key->raw_value()->EqualsString(string_table->proto_string())) {
189 if (k->IsInternalizedString() &&
190 String::Equals(Handle<String>::cast(k),
191 zone->isolate()->factory()->proto_string())) {
192 kind_ = PROTOTYPE; 187 kind_ = PROTOTYPE;
193 } else if (value_->AsMaterializedLiteral() != NULL) { 188 } else if (value_->AsMaterializedLiteral() != NULL) {
194 kind_ = MATERIALIZED_LITERAL; 189 kind_ = MATERIALIZED_LITERAL;
195 } else if (value_->IsLiteral()) { 190 } else if (value_->IsLiteral()) {
196 kind_ = CONSTANT; 191 kind_ = CONSTANT;
197 } else { 192 } else {
198 kind_ = COMPUTED; 193 kind_ = COMPUTED;
199 } 194 }
200 } 195 }
201 196
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 DONT_CACHE_NODE(ModuleLiteral) 1110 DONT_CACHE_NODE(ModuleLiteral)
1116 1111
1117 1112
1118 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { 1113 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) {
1119 increase_node_count(); 1114 increase_node_count();
1120 if (node->is_jsruntime()) { 1115 if (node->is_jsruntime()) {
1121 // Don't try to inline JS runtime calls because we don't (currently) even 1116 // Don't try to inline JS runtime calls because we don't (currently) even
1122 // optimize them. 1117 // optimize them.
1123 add_flag(kDontInline); 1118 add_flag(kDontInline);
1124 } else if (node->function()->intrinsic_type == Runtime::INLINE && 1119 } else if (node->function()->intrinsic_type == Runtime::INLINE &&
1125 (node->name()->IsOneByteEqualTo( 1120 (node->raw_name()->IsOneByteEqualTo("_ArgumentsLength") ||
1126 STATIC_ASCII_VECTOR("_ArgumentsLength")) || 1121 node->raw_name()->IsOneByteEqualTo("_Arguments"))) {
1127 node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) {
1128 // Don't inline the %_ArgumentsLength or %_Arguments because their 1122 // Don't inline the %_ArgumentsLength or %_Arguments because their
1129 // implementation will not work. There is no stack frame to get them 1123 // implementation will not work. There is no stack frame to get them
1130 // from. 1124 // from.
1131 add_flag(kDontInline); 1125 add_flag(kDontInline);
1132 } 1126 }
1133 } 1127 }
1134 1128
1135 #undef REGULAR_NODE 1129 #undef REGULAR_NODE
1136 #undef DONT_OPTIMIZE_NODE 1130 #undef DONT_OPTIMIZE_NODE
1137 #undef DONT_SELFOPTIMIZE_NODE 1131 #undef DONT_SELFOPTIMIZE_NODE
1138 #undef DONT_CACHE_NODE 1132 #undef DONT_CACHE_NODE
1139 1133
1140 1134
1141 Handle<String> Literal::ToString() { 1135 Handle<String> Literal::ToString() {
1142 if (value_->IsString()) return Handle<String>::cast(value_); 1136 if (value_->IsString()) return value_->AsString()->string();
1143 ASSERT(value_->IsNumber()); 1137 ASSERT(value_->IsNumber());
1144 char arr[100]; 1138 char arr[100];
1145 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 1139 Vector<char> buffer(arr, ARRAY_SIZE(arr));
1146 const char* str; 1140 const char* str;
1147 if (value_->IsSmi()) { 1141 if (value()->IsSmi()) {
1148 // Optimization only, the heap number case would subsume this. 1142 // Optimization only, the heap number case would subsume this.
1149 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); 1143 OS::SNPrintF(buffer, "%d", Smi::cast(*value())->value());
1150 str = arr; 1144 str = arr;
1151 } else { 1145 } else {
1152 str = DoubleToCString(value_->Number(), buffer); 1146 str = DoubleToCString(value()->Number(), buffer);
1153 } 1147 }
1154 return isolate_->factory()->NewStringFromAsciiChecked(str); 1148 return isolate_->factory()->NewStringFromAsciiChecked(str);
1155 } 1149 }
1156 1150
1157 1151
1158 } } // namespace v8::internal 1152 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/ast-string-table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698