yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 28 | #include "ast.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 29 | |
| 30 | #include <math.h> // For isfinite. |
| 31 | #include "builtins.h" |
| 32 | #include "conversions.h" |
| 33 | #include "hashmap.h" |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 34 | #include "parser.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 35 | #include "property-details.h" |
| 36 | #include "property.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "scopes.h" |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 38 | #include "string-stream.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 39 | #include "type-info.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 41 | namespace v8 { |
| 42 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | // ---------------------------------------------------------------------------- |
| 45 | // All the Accept member functions for each syntax tree node type. |
| 46 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 47 | #define DECL_ACCEPT(type) \ |
| 48 | void type::Accept(AstVisitor* v) { v->Visit##type(this); } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 49 | AST_NODE_LIST(DECL_ACCEPT) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | #undef DECL_ACCEPT |
| 51 | |
| 52 | |
| 53 | // ---------------------------------------------------------------------------- |
| 54 | // Implementation of other node functionality. |
| 55 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 56 | |
| 57 | bool Expression::IsSmiLiteral() { |
| 58 | return AsLiteral() != NULL && AsLiteral()->handle()->IsSmi(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 62 | bool Expression::IsStringLiteral() { |
| 63 | return AsLiteral() != NULL && AsLiteral()->handle()->IsString(); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | bool Expression::IsNullLiteral() { |
| 68 | return AsLiteral() != NULL && AsLiteral()->handle()->IsNull(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 72 | VariableProxy::VariableProxy(Isolate* isolate, Variable* var) |
| 73 | : Expression(isolate), |
| 74 | name_(var->name()), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 75 | var_(NULL), // Will be set by the call to BindTo. |
| 76 | is_this_(var->is_this()), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 77 | is_trivial_(false), |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 78 | is_lvalue_(false), |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 79 | position_(RelocInfo::kNoPosition), |
| 80 | interface_(var->interface()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 81 | BindTo(var); |
| 82 | } |
| 83 | |
| 84 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 85 | VariableProxy::VariableProxy(Isolate* isolate, |
| 86 | Handle<String> name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 87 | bool is_this, |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 88 | Interface* interface, |
| 89 | int position) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 90 | : Expression(isolate), |
| 91 | name_(name), |
| 92 | var_(NULL), |
| 93 | is_this_(is_this), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 94 | is_trivial_(false), |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 95 | is_lvalue_(false), |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 96 | position_(position), |
| 97 | interface_(interface) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 98 | // Names must be canonicalized for fast equality checks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | ASSERT(name->IsSymbol()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | void VariableProxy::BindTo(Variable* var) { |
| 104 | ASSERT(var_ == NULL); // must be bound only once |
| 105 | ASSERT(var != NULL); // must bind |
| 106 | ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name())); |
| 107 | // Ideally CONST-ness should match. However, this is very hard to achieve |
| 108 | // because we don't know the exact semantics of conflicting (const and |
| 109 | // non-const) multiple variable declarations, const vars introduced via |
| 110 | // eval() etc. Const-ness and variable declarations are a complete mess |
| 111 | // in JS. Sigh... |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | var_ = var; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 113 | var->set_is_used(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 117 | Assignment::Assignment(Isolate* isolate, |
| 118 | Token::Value op, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 119 | Expression* target, |
| 120 | Expression* value, |
| 121 | int pos) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 122 | : Expression(isolate), |
| 123 | op_(op), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 124 | target_(target), |
| 125 | value_(value), |
| 126 | pos_(pos), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 127 | binary_operation_(NULL), |
| 128 | compound_load_id_(kNoNumber), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 129 | assignment_id_(GetNextId(isolate)), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 130 | block_start_(false), |
| 131 | block_end_(false), |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 132 | is_monomorphic_(false) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 133 | |
| 134 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | Token::Value Assignment::binary_op() const { |
| 136 | switch (op_) { |
| 137 | case Token::ASSIGN_BIT_OR: return Token::BIT_OR; |
| 138 | case Token::ASSIGN_BIT_XOR: return Token::BIT_XOR; |
| 139 | case Token::ASSIGN_BIT_AND: return Token::BIT_AND; |
| 140 | case Token::ASSIGN_SHL: return Token::SHL; |
| 141 | case Token::ASSIGN_SAR: return Token::SAR; |
| 142 | case Token::ASSIGN_SHR: return Token::SHR; |
| 143 | case Token::ASSIGN_ADD: return Token::ADD; |
| 144 | case Token::ASSIGN_SUB: return Token::SUB; |
| 145 | case Token::ASSIGN_MUL: return Token::MUL; |
| 146 | case Token::ASSIGN_DIV: return Token::DIV; |
| 147 | case Token::ASSIGN_MOD: return Token::MOD; |
| 148 | default: UNREACHABLE(); |
| 149 | } |
| 150 | return Token::ILLEGAL; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | bool FunctionLiteral::AllowsLazyCompilation() { |
| 155 | return scope()->AllowsLazyCompilation(); |
| 156 | } |
| 157 | |
| 158 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 159 | bool FunctionLiteral::AllowsLazyCompilationWithoutContext() { |
| 160 | return scope()->AllowsLazyCompilationWithoutContext(); |
| 161 | } |
| 162 | |
| 163 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 164 | int FunctionLiteral::start_position() const { |
| 165 | return scope()->start_position(); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | int FunctionLiteral::end_position() const { |
| 170 | return scope()->end_position(); |
| 171 | } |
| 172 | |
| 173 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 174 | LanguageMode FunctionLiteral::language_mode() const { |
| 175 | return scope()->language_mode(); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 179 | ObjectLiteral::Property::Property(Literal* key, |
| 180 | Expression* value, |
| 181 | Isolate* isolate) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 182 | emit_store_ = true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | key_ = key; |
| 184 | value_ = value; |
| 185 | Object* k = *key->handle(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 186 | if (k->IsSymbol() && |
| 187 | isolate->heap()->Proto_symbol()->Equals(String::cast(k))) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | kind_ = PROTOTYPE; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 189 | } else if (value_->AsMaterializedLiteral() != NULL) { |
| 190 | kind_ = MATERIALIZED_LITERAL; |
| 191 | } else if (value_->AsLiteral() != NULL) { |
| 192 | kind_ = CONSTANT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | } else { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 194 | kind_ = COMPUTED; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | |
| 199 | ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 200 | emit_store_ = true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | value_ = value; |
| 202 | kind_ = is_getter ? GETTER : SETTER; |
| 203 | } |
| 204 | |
| 205 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 206 | bool ObjectLiteral::Property::IsCompileTimeValue() { |
| 207 | return kind_ == CONSTANT || |
| 208 | (kind_ == MATERIALIZED_LITERAL && |
| 209 | CompileTimeValue::IsCompileTimeValue(value_)); |
| 210 | } |
| 211 | |
| 212 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 213 | void ObjectLiteral::Property::set_emit_store(bool emit_store) { |
| 214 | emit_store_ = emit_store; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | bool ObjectLiteral::Property::emit_store() { |
| 219 | return emit_store_; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | bool IsEqualString(void* first, void* second) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 224 | ASSERT((*reinterpret_cast<String**>(first))->IsString()); |
| 225 | ASSERT((*reinterpret_cast<String**>(second))->IsString()); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 226 | Handle<String> h1(reinterpret_cast<String**>(first)); |
| 227 | Handle<String> h2(reinterpret_cast<String**>(second)); |
| 228 | return (*h1)->Equals(*h2); |
| 229 | } |
| 230 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 231 | |
| 232 | bool IsEqualNumber(void* first, void* second) { |
| 233 | ASSERT((*reinterpret_cast<Object**>(first))->IsNumber()); |
| 234 | ASSERT((*reinterpret_cast<Object**>(second))->IsNumber()); |
| 235 | |
| 236 | Handle<Object> h1(reinterpret_cast<Object**>(first)); |
| 237 | Handle<Object> h2(reinterpret_cast<Object**>(second)); |
| 238 | if (h1->IsSmi()) { |
| 239 | return h2->IsSmi() && *h1 == *h2; |
| 240 | } |
| 241 | if (h2->IsSmi()) return false; |
| 242 | Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1); |
| 243 | Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2); |
| 244 | ASSERT(isfinite(n1->value())); |
| 245 | ASSERT(isfinite(n2->value())); |
| 246 | return n1->value() == n2->value(); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 247 | } |
| 248 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 249 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 250 | void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
| 251 | ZoneAllocationPolicy allocator(zone); |
| 252 | |
| 253 | ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, |
| 254 | allocator); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 255 | for (int i = properties()->length() - 1; i >= 0; i--) { |
| 256 | ObjectLiteral::Property* property = properties()->at(i); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 257 | Literal* literal = property->key(); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 258 | if (literal->handle()->IsNull()) continue; |
| 259 | uint32_t hash = literal->Hash(); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 260 | // If the key of a computed property is in the table, do not emit |
| 261 | // a store for the property later. |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 262 | if (property->kind() == ObjectLiteral::Property::COMPUTED && |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 263 | table.Lookup(literal, hash, false, allocator) != NULL) { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 264 | property->set_emit_store(false); |
| 265 | } else { |
| 266 | // Add key to the table. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 267 | table.Lookup(literal, hash, true, allocator); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 268 | } |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
| 272 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 273 | void TargetCollector::AddTarget(Label* target, Zone* zone) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | // Add the label to the collector, but discard duplicates. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 275 | int length = targets_.length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | for (int i = 0; i < length; i++) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 277 | if (targets_[i] == target) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 279 | targets_.Add(target, zone); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 283 | bool UnaryOperation::ResultOverwriteAllowed() { |
| 284 | switch (op_) { |
| 285 | case Token::BIT_NOT: |
| 286 | case Token::SUB: |
| 287 | return true; |
| 288 | default: |
| 289 | return false; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
| 294 | bool BinaryOperation::ResultOverwriteAllowed() { |
| 295 | switch (op_) { |
| 296 | case Token::COMMA: |
| 297 | case Token::OR: |
| 298 | case Token::AND: |
| 299 | return false; |
| 300 | case Token::BIT_OR: |
| 301 | case Token::BIT_XOR: |
| 302 | case Token::BIT_AND: |
| 303 | case Token::SHL: |
| 304 | case Token::SAR: |
| 305 | case Token::SHR: |
| 306 | case Token::ADD: |
| 307 | case Token::SUB: |
| 308 | case Token::MUL: |
| 309 | case Token::DIV: |
| 310 | case Token::MOD: |
| 311 | return true; |
| 312 | default: |
| 313 | UNREACHABLE(); |
| 314 | } |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 319 | static bool IsTypeof(Expression* expr) { |
| 320 | UnaryOperation* maybe_unary = expr->AsUnaryOperation(); |
| 321 | return maybe_unary != NULL && maybe_unary->op() == Token::TYPEOF; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | // Check for the pattern: typeof <expression> equals <string literal>. |
| 326 | static bool MatchLiteralCompareTypeof(Expression* left, |
| 327 | Token::Value op, |
| 328 | Expression* right, |
| 329 | Expression** expr, |
| 330 | Handle<String>* check) { |
| 331 | if (IsTypeof(left) && right->IsStringLiteral() && Token::IsEqualityOp(op)) { |
| 332 | *expr = left->AsUnaryOperation()->expression(); |
| 333 | *check = Handle<String>::cast(right->AsLiteral()->handle()); |
| 334 | return true; |
| 335 | } |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 340 | bool CompareOperation::IsLiteralCompareTypeof(Expression** expr, |
| 341 | Handle<String>* check) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 342 | return MatchLiteralCompareTypeof(left_, op_, right_, expr, check) || |
| 343 | MatchLiteralCompareTypeof(right_, op_, left_, expr, check); |
| 344 | } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 345 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 346 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 347 | static bool IsVoidOfLiteral(Expression* expr) { |
| 348 | UnaryOperation* maybe_unary = expr->AsUnaryOperation(); |
| 349 | return maybe_unary != NULL && |
| 350 | maybe_unary->op() == Token::VOID && |
| 351 | maybe_unary->expression()->AsLiteral() != NULL; |
| 352 | } |
| 353 | |
| 354 | |
| 355 | // Check for the pattern: void <literal> equals <expression> |
| 356 | static bool MatchLiteralCompareUndefined(Expression* left, |
| 357 | Token::Value op, |
| 358 | Expression* right, |
| 359 | Expression** expr) { |
| 360 | if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { |
| 361 | *expr = right; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 362 | return true; |
| 363 | } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 364 | return false; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 369 | return MatchLiteralCompareUndefined(left_, op_, right_, expr) || |
| 370 | MatchLiteralCompareUndefined(right_, op_, left_, expr); |
| 371 | } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 372 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 373 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 374 | // Check for the pattern: null equals <expression> |
| 375 | static bool MatchLiteralCompareNull(Expression* left, |
| 376 | Token::Value op, |
| 377 | Expression* right, |
| 378 | Expression** expr) { |
| 379 | if (left->IsNullLiteral() && Token::IsEqualityOp(op)) { |
| 380 | *expr = right; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 381 | return true; |
| 382 | } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 383 | return false; |
| 384 | } |
| 385 | |
| 386 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 387 | bool CompareOperation::IsLiteralCompareNull(Expression** expr) { |
| 388 | return MatchLiteralCompareNull(left_, op_, right_, expr) || |
| 389 | MatchLiteralCompareNull(right_, op_, left_, expr); |
| 390 | } |
| 391 | |
| 392 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | // ---------------------------------------------------------------------------- |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 394 | // Inlining support |
| 395 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 396 | bool Declaration::IsInlineable() const { |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 397 | return proxy()->var()->IsStackAllocated(); |
| 398 | } |
| 399 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 400 | bool FunctionDeclaration::IsInlineable() const { |
| 401 | return false; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 405 | // ---------------------------------------------------------------------------- |
| 406 | // Recording of type feedback |
| 407 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 408 | void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 409 | Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 410 | // Record type feedback from the oracle in the AST. |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 411 | is_uninitialized_ = oracle->LoadIsUninitialized(this); |
| 412 | if (is_uninitialized_) return; |
| 413 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 414 | is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 415 | receiver_types_.Clear(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 416 | if (key()->IsPropertyName()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 417 | if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_ArrayLength)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 418 | is_array_length_ = true; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 419 | } else if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_StringLength)) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 420 | is_string_length_ = true; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 421 | } else if (oracle->LoadIsBuiltin(this, |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 422 | Builtins::kLoadIC_FunctionPrototype)) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 423 | is_function_prototype_ = true; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 424 | } else { |
| 425 | Literal* lit_key = key()->AsLiteral(); |
| 426 | ASSERT(lit_key != NULL && lit_key->handle()->IsString()); |
| 427 | Handle<String> name = Handle<String>::cast(lit_key->handle()); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 428 | oracle->LoadReceiverTypes(this, name, &receiver_types_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 429 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 430 | } else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 431 | is_string_access_ = true; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 432 | } else if (is_monomorphic_) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 433 | receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this), |
| 434 | zone); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 435 | } else if (oracle->LoadIsMegamorphicWithTypeInfo(this)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 436 | receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 437 | oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
| 441 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 442 | void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 443 | Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 444 | Property* prop = target()->AsProperty(); |
| 445 | ASSERT(prop != NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 446 | is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 447 | receiver_types_.Clear(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 448 | if (prop->key()->IsPropertyName()) { |
| 449 | Literal* lit_key = prop->key()->AsLiteral(); |
| 450 | ASSERT(lit_key != NULL && lit_key->handle()->IsString()); |
| 451 | Handle<String> name = Handle<String>::cast(lit_key->handle()); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 452 | oracle->StoreReceiverTypes(this, name, &receiver_types_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 453 | } else if (is_monomorphic_) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 454 | // Record receiver type for monomorphic keyed stores. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 455 | receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this), zone); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 456 | } else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 457 | receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 458 | oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 463 | void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 464 | Zone* zone) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 465 | is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 466 | receiver_types_.Clear(); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 467 | if (is_monomorphic_) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 468 | // Record receiver type for monomorphic keyed stores. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 469 | receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this), zone); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 470 | } else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 471 | receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 472 | oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | |
| 477 | void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 478 | TypeInfo info = oracle->SwitchType(this); |
| 479 | if (info.IsSmi()) { |
| 480 | compare_type_ = SMI_ONLY; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 481 | } else if (info.IsSymbol()) { |
| 482 | compare_type_ = SYMBOL_ONLY; |
| 483 | } else if (info.IsNonSymbol()) { |
| 484 | compare_type_ = STRING_ONLY; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 485 | } else if (info.IsNonPrimitive()) { |
| 486 | compare_type_ = OBJECT_ONLY; |
| 487 | } else { |
| 488 | ASSERT(compare_type_ == NONE); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 493 | bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 494 | // If there is an interceptor, we can't compute the target for a direct call. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 495 | if (type->has_named_interceptor()) return false; |
| 496 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 497 | if (check_type_ == RECEIVER_MAP_CHECK) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 498 | // For primitive checks the holder is set up to point to the corresponding |
| 499 | // prototype object, i.e. one step of the algorithm below has been already |
| 500 | // performed. For non-primitive checks we clear it to allow computing |
| 501 | // targets for polymorphic calls. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 502 | holder_ = Handle<JSObject>::null(); |
| 503 | } |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 504 | LookupResult lookup(type->GetIsolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 505 | while (true) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 506 | type->LookupDescriptor(NULL, *name, &lookup); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 507 | if (lookup.IsFound()) { |
| 508 | switch (lookup.type()) { |
| 509 | case CONSTANT_FUNCTION: |
| 510 | // We surely know the target for a constant function. |
| 511 | target_ = |
| 512 | Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); |
| 513 | return true; |
| 514 | case NORMAL: |
| 515 | case FIELD: |
| 516 | case CALLBACKS: |
| 517 | case HANDLER: |
| 518 | case INTERCEPTOR: |
| 519 | // We don't know the target. |
| 520 | return false; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 521 | case TRANSITION: |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 522 | case NONEXISTENT: |
| 523 | UNREACHABLE(); |
| 524 | break; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 525 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 526 | } |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 527 | // If we reach the end of the prototype chain, we don't know the target. |
| 528 | if (!type->prototype()->IsJSObject()) return false; |
| 529 | // Go up the prototype chain, recording where we are currently. |
| 530 | holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 531 | if (!holder_->HasFastProperties()) return false; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 532 | type = Handle<Map>(holder()->map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | |
| 537 | bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 538 | LookupResult* lookup) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 539 | target_ = Handle<JSFunction>::null(); |
| 540 | cell_ = Handle<JSGlobalPropertyCell>::null(); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 541 | ASSERT(lookup->IsFound() && |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 542 | lookup->type() == NORMAL && |
| 543 | lookup->holder() == *global); |
| 544 | cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(lookup)); |
| 545 | if (cell_->value()->IsJSFunction()) { |
| 546 | Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); |
| 547 | // If the function is in new space we assume it's more likely to |
| 548 | // change and thus prefer the general IC code. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 549 | if (!HEAP->InNewSpace(*candidate)) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 550 | target_ = candidate; |
| 551 | return true; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 558 | void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 559 | CallKind call_kind) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 560 | is_monomorphic_ = oracle->CallIsMonomorphic(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 561 | Property* property = expression()->AsProperty(); |
| 562 | if (property == NULL) { |
| 563 | // Function call. Specialize for monomorphic calls. |
| 564 | if (is_monomorphic_) target_ = oracle->GetCallTarget(this); |
| 565 | } else { |
| 566 | // Method call. Specialize for the receiver types seen at runtime. |
| 567 | Literal* key = property->key()->AsLiteral(); |
| 568 | ASSERT(key != NULL && key->handle()->IsString()); |
| 569 | Handle<String> name = Handle<String>::cast(key->handle()); |
| 570 | receiver_types_.Clear(); |
| 571 | oracle->CallReceiverTypes(this, name, call_kind, &receiver_types_); |
| 572 | #ifdef DEBUG |
| 573 | if (FLAG_enable_slow_asserts) { |
| 574 | int length = receiver_types_.length(); |
| 575 | for (int i = 0; i < length; i++) { |
| 576 | Handle<Map> map = receiver_types_.at(i); |
| 577 | ASSERT(!map.is_null() && *map != NULL); |
| 578 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 579 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 580 | #endif |
| 581 | check_type_ = oracle->GetCallCheckType(this); |
| 582 | if (is_monomorphic_) { |
| 583 | Handle<Map> map; |
| 584 | if (receiver_types_.length() > 0) { |
| 585 | ASSERT(check_type_ == RECEIVER_MAP_CHECK); |
| 586 | map = receiver_types_.at(0); |
| 587 | } else { |
| 588 | ASSERT(check_type_ != RECEIVER_MAP_CHECK); |
| 589 | holder_ = Handle<JSObject>( |
| 590 | oracle->GetPrototypeForPrimitiveCheck(check_type_)); |
| 591 | map = Handle<Map>(holder_->map()); |
| 592 | } |
| 593 | is_monomorphic_ = ComputeTarget(map, name); |
| 594 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
| 598 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 599 | void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 600 | is_monomorphic_ = oracle->CallNewIsMonomorphic(this); |
| 601 | if (is_monomorphic_) { |
| 602 | target_ = oracle->GetCallNewTarget(this); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 607 | void CompareOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 608 | TypeInfo info = oracle->CompareType(this); |
| 609 | if (info.IsSmi()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 610 | compare_type_ = SMI_ONLY; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 611 | } else if (info.IsNonPrimitive()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 612 | compare_type_ = OBJECT_ONLY; |
| 613 | } else { |
| 614 | ASSERT(compare_type_ == NONE); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 619 | void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 620 | receiver_type_ = oracle->ObjectLiteralStoreIsMonomorphic(this) |
| 621 | ? oracle->GetObjectLiteralStoreMap(this) |
| 622 | : Handle<Map>::null(); |
| 623 | } |
| 624 | |
| 625 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 626 | // ---------------------------------------------------------------------------- |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 627 | // Implementation of AstVisitor |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 628 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 629 | bool AstVisitor::CheckStackOverflow() { |
| 630 | if (stack_overflow_) return true; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 631 | StackLimitCheck check(isolate_); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 632 | if (!check.HasOverflowed()) return false; |
| 633 | return (stack_overflow_ = true); |
| 634 | } |
| 635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 637 | void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
| 638 | for (int i = 0; i < declarations->length(); i++) { |
| 639 | Visit(declarations->at(i)); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 644 | void AstVisitor::VisitStatements(ZoneList<Statement*>* statements) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 645 | for (int i = 0; i < statements->length(); i++) { |
| 646 | Visit(statements->at(i)); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 651 | void AstVisitor::VisitExpressions(ZoneList<Expression*>* expressions) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | for (int i = 0; i < expressions->length(); i++) { |
| 653 | // The variable statement visiting code may pass NULL expressions |
| 654 | // to this code. Maybe this should be handled by introducing an |
| 655 | // undefined expression or literal? Revisit this code if this |
| 656 | // changes |
| 657 | Expression* expression = expressions->at(i); |
| 658 | if (expression != NULL) Visit(expression); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 663 | // ---------------------------------------------------------------------------- |
| 664 | // Regular expressions |
| 665 | |
| 666 | #define MAKE_ACCEPT(Name) \ |
| 667 | void* RegExp##Name::Accept(RegExpVisitor* visitor, void* data) { \ |
| 668 | return visitor->Visit##Name(this, data); \ |
| 669 | } |
| 670 | FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ACCEPT) |
| 671 | #undef MAKE_ACCEPT |
| 672 | |
| 673 | #define MAKE_TYPE_CASE(Name) \ |
| 674 | RegExp##Name* RegExpTree::As##Name() { \ |
| 675 | return NULL; \ |
| 676 | } \ |
| 677 | bool RegExpTree::Is##Name() { return false; } |
| 678 | FOR_EACH_REG_EXP_TREE_TYPE(MAKE_TYPE_CASE) |
| 679 | #undef MAKE_TYPE_CASE |
| 680 | |
| 681 | #define MAKE_TYPE_CASE(Name) \ |
| 682 | RegExp##Name* RegExp##Name::As##Name() { \ |
| 683 | return this; \ |
| 684 | } \ |
| 685 | bool RegExp##Name::Is##Name() { return true; } |
| 686 | FOR_EACH_REG_EXP_TREE_TYPE(MAKE_TYPE_CASE) |
| 687 | #undef MAKE_TYPE_CASE |
| 688 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 689 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 690 | static Interval ListCaptureRegisters(ZoneList<RegExpTree*>* children) { |
| 691 | Interval result = Interval::Empty(); |
| 692 | for (int i = 0; i < children->length(); i++) |
| 693 | result = result.Union(children->at(i)->CaptureRegisters()); |
| 694 | return result; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | Interval RegExpAlternative::CaptureRegisters() { |
| 699 | return ListCaptureRegisters(nodes()); |
| 700 | } |
| 701 | |
| 702 | |
| 703 | Interval RegExpDisjunction::CaptureRegisters() { |
| 704 | return ListCaptureRegisters(alternatives()); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | Interval RegExpLookahead::CaptureRegisters() { |
| 709 | return body()->CaptureRegisters(); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | Interval RegExpCapture::CaptureRegisters() { |
| 714 | Interval self(StartRegister(index()), EndRegister(index())); |
| 715 | return self.Union(body()->CaptureRegisters()); |
| 716 | } |
| 717 | |
| 718 | |
| 719 | Interval RegExpQuantifier::CaptureRegisters() { |
| 720 | return body()->CaptureRegisters(); |
| 721 | } |
| 722 | |
| 723 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 724 | bool RegExpAssertion::IsAnchoredAtStart() { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 725 | return type() == RegExpAssertion::START_OF_INPUT; |
| 726 | } |
| 727 | |
| 728 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 729 | bool RegExpAssertion::IsAnchoredAtEnd() { |
| 730 | return type() == RegExpAssertion::END_OF_INPUT; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | bool RegExpAlternative::IsAnchoredAtStart() { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 735 | ZoneList<RegExpTree*>* nodes = this->nodes(); |
| 736 | for (int i = 0; i < nodes->length(); i++) { |
| 737 | RegExpTree* node = nodes->at(i); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 738 | if (node->IsAnchoredAtStart()) { return true; } |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 739 | if (node->max_match() > 0) { return false; } |
| 740 | } |
| 741 | return false; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 745 | bool RegExpAlternative::IsAnchoredAtEnd() { |
| 746 | ZoneList<RegExpTree*>* nodes = this->nodes(); |
| 747 | for (int i = nodes->length() - 1; i >= 0; i--) { |
| 748 | RegExpTree* node = nodes->at(i); |
| 749 | if (node->IsAnchoredAtEnd()) { return true; } |
| 750 | if (node->max_match() > 0) { return false; } |
| 751 | } |
| 752 | return false; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | bool RegExpDisjunction::IsAnchoredAtStart() { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 757 | ZoneList<RegExpTree*>* alternatives = this->alternatives(); |
| 758 | for (int i = 0; i < alternatives->length(); i++) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 759 | if (!alternatives->at(i)->IsAnchoredAtStart()) |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 760 | return false; |
| 761 | } |
| 762 | return true; |
| 763 | } |
| 764 | |
| 765 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 766 | bool RegExpDisjunction::IsAnchoredAtEnd() { |
| 767 | ZoneList<RegExpTree*>* alternatives = this->alternatives(); |
| 768 | for (int i = 0; i < alternatives->length(); i++) { |
| 769 | if (!alternatives->at(i)->IsAnchoredAtEnd()) |
| 770 | return false; |
| 771 | } |
| 772 | return true; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 776 | bool RegExpLookahead::IsAnchoredAtStart() { |
| 777 | return is_positive() && body()->IsAnchoredAtStart(); |
| 778 | } |
| 779 | |
| 780 | |
| 781 | bool RegExpCapture::IsAnchoredAtStart() { |
| 782 | return body()->IsAnchoredAtStart(); |
| 783 | } |
| 784 | |
| 785 | |
| 786 | bool RegExpCapture::IsAnchoredAtEnd() { |
| 787 | return body()->IsAnchoredAtEnd(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 791 | // Convert regular expression trees to a simple sexp representation. |
| 792 | // This representation should be different from the input grammar |
| 793 | // in as many cases as possible, to make it more difficult for incorrect |
| 794 | // parses to look as correct ones which is likely if the input and |
| 795 | // output formats are alike. |
| 796 | class RegExpUnparser: public RegExpVisitor { |
| 797 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 798 | explicit RegExpUnparser(Zone* zone); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 799 | void VisitCharacterRange(CharacterRange that); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 800 | SmartArrayPointer<const char> ToString() { return stream_.ToCString(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 801 | #define MAKE_CASE(Name) virtual void* Visit##Name(RegExp##Name*, void* data); |
| 802 | FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) |
| 803 | #undef MAKE_CASE |
| 804 | private: |
| 805 | StringStream* stream() { return &stream_; } |
| 806 | HeapStringAllocator alloc_; |
| 807 | StringStream stream_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 808 | Zone* zone_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 809 | }; |
| 810 | |
| 811 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 812 | RegExpUnparser::RegExpUnparser(Zone* zone) : stream_(&alloc_), zone_(zone) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | |
| 816 | void* RegExpUnparser::VisitDisjunction(RegExpDisjunction* that, void* data) { |
| 817 | stream()->Add("(|"); |
| 818 | for (int i = 0; i < that->alternatives()->length(); i++) { |
| 819 | stream()->Add(" "); |
| 820 | that->alternatives()->at(i)->Accept(this, data); |
| 821 | } |
| 822 | stream()->Add(")"); |
| 823 | return NULL; |
| 824 | } |
| 825 | |
| 826 | |
| 827 | void* RegExpUnparser::VisitAlternative(RegExpAlternative* that, void* data) { |
| 828 | stream()->Add("(:"); |
| 829 | for (int i = 0; i < that->nodes()->length(); i++) { |
| 830 | stream()->Add(" "); |
| 831 | that->nodes()->at(i)->Accept(this, data); |
| 832 | } |
| 833 | stream()->Add(")"); |
| 834 | return NULL; |
| 835 | } |
| 836 | |
| 837 | |
| 838 | void RegExpUnparser::VisitCharacterRange(CharacterRange that) { |
| 839 | stream()->Add("%k", that.from()); |
| 840 | if (!that.IsSingleton()) { |
| 841 | stream()->Add("-%k", that.to()); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | |
| 846 | |
| 847 | void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that, |
| 848 | void* data) { |
| 849 | if (that->is_negated()) |
| 850 | stream()->Add("^"); |
| 851 | stream()->Add("["); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 852 | for (int i = 0; i < that->ranges(zone_)->length(); i++) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 853 | if (i > 0) stream()->Add(" "); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 854 | VisitCharacterRange(that->ranges(zone_)->at(i)); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 855 | } |
| 856 | stream()->Add("]"); |
| 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | |
| 861 | void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) { |
| 862 | switch (that->type()) { |
| 863 | case RegExpAssertion::START_OF_INPUT: |
| 864 | stream()->Add("@^i"); |
| 865 | break; |
| 866 | case RegExpAssertion::END_OF_INPUT: |
| 867 | stream()->Add("@$i"); |
| 868 | break; |
| 869 | case RegExpAssertion::START_OF_LINE: |
| 870 | stream()->Add("@^l"); |
| 871 | break; |
| 872 | case RegExpAssertion::END_OF_LINE: |
| 873 | stream()->Add("@$l"); |
| 874 | break; |
| 875 | case RegExpAssertion::BOUNDARY: |
| 876 | stream()->Add("@b"); |
| 877 | break; |
| 878 | case RegExpAssertion::NON_BOUNDARY: |
| 879 | stream()->Add("@B"); |
| 880 | break; |
| 881 | } |
| 882 | return NULL; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | void* RegExpUnparser::VisitAtom(RegExpAtom* that, void* data) { |
| 887 | stream()->Add("'"); |
| 888 | Vector<const uc16> chardata = that->data(); |
| 889 | for (int i = 0; i < chardata.length(); i++) { |
| 890 | stream()->Add("%k", chardata[i]); |
| 891 | } |
| 892 | stream()->Add("'"); |
| 893 | return NULL; |
| 894 | } |
| 895 | |
| 896 | |
| 897 | void* RegExpUnparser::VisitText(RegExpText* that, void* data) { |
| 898 | if (that->elements()->length() == 1) { |
| 899 | that->elements()->at(0).data.u_atom->Accept(this, data); |
| 900 | } else { |
| 901 | stream()->Add("(!"); |
| 902 | for (int i = 0; i < that->elements()->length(); i++) { |
| 903 | stream()->Add(" "); |
| 904 | that->elements()->at(i).data.u_atom->Accept(this, data); |
| 905 | } |
| 906 | stream()->Add(")"); |
| 907 | } |
| 908 | return NULL; |
| 909 | } |
| 910 | |
| 911 | |
| 912 | void* RegExpUnparser::VisitQuantifier(RegExpQuantifier* that, void* data) { |
| 913 | stream()->Add("(# %i ", that->min()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 914 | if (that->max() == RegExpTree::kInfinity) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 915 | stream()->Add("- "); |
| 916 | } else { |
| 917 | stream()->Add("%i ", that->max()); |
| 918 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 919 | stream()->Add(that->is_greedy() ? "g " : that->is_possessive() ? "p " : "n "); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 920 | that->body()->Accept(this, data); |
| 921 | stream()->Add(")"); |
| 922 | return NULL; |
| 923 | } |
| 924 | |
| 925 | |
| 926 | void* RegExpUnparser::VisitCapture(RegExpCapture* that, void* data) { |
| 927 | stream()->Add("(^ "); |
| 928 | that->body()->Accept(this, data); |
| 929 | stream()->Add(")"); |
| 930 | return NULL; |
| 931 | } |
| 932 | |
| 933 | |
| 934 | void* RegExpUnparser::VisitLookahead(RegExpLookahead* that, void* data) { |
| 935 | stream()->Add("(-> "); |
| 936 | stream()->Add(that->is_positive() ? "+ " : "- "); |
| 937 | that->body()->Accept(this, data); |
| 938 | stream()->Add(")"); |
| 939 | return NULL; |
| 940 | } |
| 941 | |
| 942 | |
| 943 | void* RegExpUnparser::VisitBackReference(RegExpBackReference* that, |
| 944 | void* data) { |
| 945 | stream()->Add("(<- %i)", that->index()); |
| 946 | return NULL; |
| 947 | } |
| 948 | |
| 949 | |
| 950 | void* RegExpUnparser::VisitEmpty(RegExpEmpty* that, void* data) { |
| 951 | stream()->Put('%'); |
| 952 | return NULL; |
| 953 | } |
| 954 | |
| 955 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 956 | SmartArrayPointer<const char> RegExpTree::ToString(Zone* zone) { |
| 957 | RegExpUnparser unparser(zone); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 958 | Accept(&unparser, NULL); |
| 959 | return unparser.ToString(); |
| 960 | } |
| 961 | |
| 962 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 963 | RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) |
| 964 | : alternatives_(alternatives) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 965 | ASSERT(alternatives->length() > 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 966 | RegExpTree* first_alternative = alternatives->at(0); |
| 967 | min_match_ = first_alternative->min_match(); |
| 968 | max_match_ = first_alternative->max_match(); |
| 969 | for (int i = 1; i < alternatives->length(); i++) { |
| 970 | RegExpTree* alternative = alternatives->at(i); |
| 971 | min_match_ = Min(min_match_, alternative->min_match()); |
| 972 | max_match_ = Max(max_match_, alternative->max_match()); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 977 | static int IncreaseBy(int previous, int increase) { |
| 978 | if (RegExpTree::kInfinity - previous < increase) { |
| 979 | return RegExpTree::kInfinity; |
| 980 | } else { |
| 981 | return previous + increase; |
| 982 | } |
| 983 | } |
| 984 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 985 | RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) |
| 986 | : nodes_(nodes) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 987 | ASSERT(nodes->length() > 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 988 | min_match_ = 0; |
| 989 | max_match_ = 0; |
| 990 | for (int i = 0; i < nodes->length(); i++) { |
| 991 | RegExpTree* node = nodes->at(i); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 992 | int node_min_match = node->min_match(); |
| 993 | min_match_ = IncreaseBy(min_match_, node_min_match); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 994 | int node_max_match = node->max_match(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 995 | max_match_ = IncreaseBy(max_match_, node_max_match); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 999 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1000 | CaseClause::CaseClause(Isolate* isolate, |
| 1001 | Expression* label, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1002 | ZoneList<Statement*>* statements, |
| 1003 | int pos) |
| 1004 | : label_(label), |
| 1005 | statements_(statements), |
| 1006 | position_(pos), |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1007 | compare_type_(NONE), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1008 | compare_id_(AstNode::GetNextId(isolate)), |
| 1009 | entry_id_(AstNode::GetNextId(isolate)) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1010 | } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1011 | |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1012 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1013 | #define REGULAR_NODE(NodeType) \ |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1014 | void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1015 | increase_node_count(); \ |
| 1016 | } |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1017 | #define DONT_OPTIMIZE_NODE(NodeType) \ |
| 1018 | void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1019 | increase_node_count(); \ |
| 1020 | add_flag(kDontOptimize); \ |
| 1021 | add_flag(kDontInline); \ |
| 1022 | add_flag(kDontSelfOptimize); \ |
| 1023 | } |
| 1024 | #define DONT_INLINE_NODE(NodeType) \ |
| 1025 | void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1026 | increase_node_count(); \ |
| 1027 | add_flag(kDontInline); \ |
| 1028 | } |
| 1029 | #define DONT_SELFOPTIMIZE_NODE(NodeType) \ |
| 1030 | void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1031 | increase_node_count(); \ |
| 1032 | add_flag(kDontSelfOptimize); \ |
| 1033 | } |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1034 | #define DONT_CACHE_NODE(NodeType) \ |
| 1035 | void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1036 | increase_node_count(); \ |
| 1037 | add_flag(kDontOptimize); \ |
| 1038 | add_flag(kDontInline); \ |
| 1039 | add_flag(kDontSelfOptimize); \ |
| 1040 | add_flag(kDontCache); \ |
| 1041 | } |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1042 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1043 | REGULAR_NODE(VariableDeclaration) |
| 1044 | REGULAR_NODE(FunctionDeclaration) |
| 1045 | REGULAR_NODE(Block) |
| 1046 | REGULAR_NODE(ExpressionStatement) |
| 1047 | REGULAR_NODE(EmptyStatement) |
| 1048 | REGULAR_NODE(IfStatement) |
| 1049 | REGULAR_NODE(ContinueStatement) |
| 1050 | REGULAR_NODE(BreakStatement) |
| 1051 | REGULAR_NODE(ReturnStatement) |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1052 | REGULAR_NODE(SwitchStatement) |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1053 | REGULAR_NODE(Conditional) |
| 1054 | REGULAR_NODE(Literal) |
| 1055 | REGULAR_NODE(ObjectLiteral) |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 1056 | REGULAR_NODE(RegExpLiteral) |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1057 | REGULAR_NODE(Assignment) |
| 1058 | REGULAR_NODE(Throw) |
| 1059 | REGULAR_NODE(Property) |
| 1060 | REGULAR_NODE(UnaryOperation) |
| 1061 | REGULAR_NODE(CountOperation) |
| 1062 | REGULAR_NODE(BinaryOperation) |
| 1063 | REGULAR_NODE(CompareOperation) |
| 1064 | REGULAR_NODE(ThisFunction) |
| 1065 | REGULAR_NODE(Call) |
| 1066 | REGULAR_NODE(CallNew) |
| 1067 | // In theory, for VariableProxy we'd have to add: |
| 1068 | // if (node->var()->IsLookupSlot()) add_flag(kDontInline); |
| 1069 | // But node->var() is usually not bound yet at VariableProxy creation time, and |
| 1070 | // LOOKUP variables only result from constructs that cannot be inlined anyway. |
| 1071 | REGULAR_NODE(VariableProxy) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1072 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1073 | // We currently do not optimize any modules. Note in particular, that module |
| 1074 | // instance objects associated with ModuleLiterals are allocated during |
| 1075 | // scope resolution, and references to them are embedded into the code. |
| 1076 | // That code may hence neither be cached nor re-compiled. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1077 | DONT_OPTIMIZE_NODE(ModuleDeclaration) |
| 1078 | DONT_OPTIMIZE_NODE(ImportDeclaration) |
| 1079 | DONT_OPTIMIZE_NODE(ExportDeclaration) |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1080 | DONT_OPTIMIZE_NODE(ModuleVariable) |
| 1081 | DONT_OPTIMIZE_NODE(ModulePath) |
| 1082 | DONT_OPTIMIZE_NODE(ModuleUrl) |
| 1083 | DONT_OPTIMIZE_NODE(WithStatement) |
| 1084 | DONT_OPTIMIZE_NODE(TryCatchStatement) |
| 1085 | DONT_OPTIMIZE_NODE(TryFinallyStatement) |
| 1086 | DONT_OPTIMIZE_NODE(DebuggerStatement) |
| 1087 | DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1088 | |
mstarzinger@chromium.org | c6d9cee | 2012-07-03 10:03:19 +0000 | [diff] [blame] | 1089 | DONT_INLINE_NODE(ArrayLiteral) // TODO(1322): Allow materialized literals. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1090 | DONT_INLINE_NODE(FunctionLiteral) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1091 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1092 | DONT_SELFOPTIMIZE_NODE(DoWhileStatement) |
| 1093 | DONT_SELFOPTIMIZE_NODE(WhileStatement) |
| 1094 | DONT_SELFOPTIMIZE_NODE(ForStatement) |
| 1095 | DONT_SELFOPTIMIZE_NODE(ForInStatement) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1096 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1097 | DONT_CACHE_NODE(ModuleLiteral) |
| 1098 | |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1099 | void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
| 1100 | increase_node_count(); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1101 | if (node->is_jsruntime()) { |
| 1102 | // Don't try to inline JS runtime calls because we don't (currently) even |
| 1103 | // optimize them. |
| 1104 | add_flag(kDontInline); |
| 1105 | } else if (node->function()->intrinsic_type == Runtime::INLINE && |
| 1106 | (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) || |
| 1107 | node->name()->IsEqualTo(CStrVector("_Arguments")))) { |
| 1108 | // Don't inline the %_ArgumentsLength or %_Arguments because their |
| 1109 | // implementation will not work. There is no stack frame to get them |
| 1110 | // from. |
| 1111 | add_flag(kDontInline); |
| 1112 | } |
| 1113 | } |
| 1114 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1115 | #undef REGULAR_NODE |
| 1116 | #undef DONT_OPTIMIZE_NODE |
| 1117 | #undef DONT_INLINE_NODE |
| 1118 | #undef DONT_SELFOPTIMIZE_NODE |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1119 | #undef DONT_CACHE_NODE |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1120 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1121 | |
| 1122 | Handle<String> Literal::ToString() { |
| 1123 | if (handle_->IsString()) return Handle<String>::cast(handle_); |
| 1124 | ASSERT(handle_->IsNumber()); |
| 1125 | char arr[100]; |
| 1126 | Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 1127 | const char* str; |
| 1128 | if (handle_->IsSmi()) { |
| 1129 | // Optimization only, the heap number case would subsume this. |
| 1130 | OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
| 1131 | str = arr; |
| 1132 | } else { |
| 1133 | str = DoubleToCString(handle_->Number(), buffer); |
| 1134 | } |
| 1135 | return FACTORY->NewStringFromAscii(CStrVector(str)); |
| 1136 | } |
| 1137 | |
| 1138 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1139 | } } // namespace v8::internal |