2012-01-25 16:31:25 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "ast.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
|
|
|
|
#include <math.h> // For isfinite.
|
|
|
|
#include "builtins.h"
|
|
|
|
#include "conversions.h"
|
|
|
|
#include "hashmap.h"
|
2009-10-28 13:25:40 +00:00
|
|
|
#include "parser.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "property-details.h"
|
|
|
|
#include "property.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "scopes.h"
|
2008-11-25 11:07:48 +00:00
|
|
|
#include "string-stream.h"
|
2011-04-07 14:42:37 +00:00
|
|
|
#include "type-info.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// All the Accept member functions for each syntax tree node type.
|
|
|
|
|
2010-03-30 12:25:58 +00:00
|
|
|
#define DECL_ACCEPT(type) \
|
|
|
|
void type::Accept(AstVisitor* v) { v->Visit##type(this); }
|
2009-07-30 12:09:05 +00:00
|
|
|
AST_NODE_LIST(DECL_ACCEPT)
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef DECL_ACCEPT
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Implementation of other node functionality.
|
|
|
|
|
2011-10-31 11:11:26 +00:00
|
|
|
|
|
|
|
bool Expression::IsSmiLiteral() {
|
|
|
|
return AsLiteral() != NULL && AsLiteral()->handle()->IsSmi();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Expression::IsStringLiteral() {
|
|
|
|
return AsLiteral() != NULL && AsLiteral()->handle()->IsString();
|
2010-03-11 10:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 11:11:26 +00:00
|
|
|
bool Expression::IsNullLiteral() {
|
|
|
|
return AsLiteral() != NULL && AsLiteral()->handle()->IsNull();
|
2010-03-11 10:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 17:32:41 +00:00
|
|
|
VariableProxy::VariableProxy(Isolate* isolate, Variable* var)
|
|
|
|
: Expression(isolate),
|
|
|
|
name_(var->name()),
|
2010-09-24 07:53:59 +00:00
|
|
|
var_(NULL), // Will be set by the call to BindTo.
|
|
|
|
is_this_(var->is_this()),
|
2011-04-01 11:54:04 +00:00
|
|
|
is_trivial_(false),
|
2011-12-05 14:43:28 +00:00
|
|
|
is_lvalue_(false),
|
2012-03-08 13:03:07 +00:00
|
|
|
position_(RelocInfo::kNoPosition),
|
|
|
|
interface_(var->interface()) {
|
2010-09-24 07:53:59 +00:00
|
|
|
BindTo(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 17:32:41 +00:00
|
|
|
VariableProxy::VariableProxy(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
2008-07-03 15:10:15 +00:00
|
|
|
bool is_this,
|
2012-03-08 13:03:07 +00:00
|
|
|
int position,
|
|
|
|
Interface* interface)
|
2011-07-18 17:32:41 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
name_(name),
|
|
|
|
var_(NULL),
|
|
|
|
is_this_(is_this),
|
|
|
|
is_trivial_(false),
|
2011-12-05 14:43:28 +00:00
|
|
|
is_lvalue_(false),
|
2012-03-08 13:03:07 +00:00
|
|
|
position_(position),
|
|
|
|
interface_(interface) {
|
2011-04-01 11:54:04 +00:00
|
|
|
// Names must be canonicalized for fast equality checks.
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(name->IsSymbol());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VariableProxy::BindTo(Variable* var) {
|
|
|
|
ASSERT(var_ == NULL); // must be bound only once
|
|
|
|
ASSERT(var != NULL); // must bind
|
|
|
|
ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name()));
|
|
|
|
// Ideally CONST-ness should match. However, this is very hard to achieve
|
|
|
|
// because we don't know the exact semantics of conflicting (const and
|
|
|
|
// non-const) multiple variable declarations, const vars introduced via
|
|
|
|
// eval() etc. Const-ness and variable declarations are a complete mess
|
|
|
|
// in JS. Sigh...
|
|
|
|
var_ = var;
|
2010-03-08 13:01:24 +00:00
|
|
|
var->set_is_used(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 17:32:41 +00:00
|
|
|
Assignment::Assignment(Isolate* isolate,
|
|
|
|
Token::Value op,
|
2010-12-07 11:31:57 +00:00
|
|
|
Expression* target,
|
|
|
|
Expression* value,
|
|
|
|
int pos)
|
2011-07-18 17:32:41 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
op_(op),
|
2010-12-07 11:31:57 +00:00
|
|
|
target_(target),
|
|
|
|
value_(value),
|
|
|
|
pos_(pos),
|
2010-12-13 16:29:47 +00:00
|
|
|
binary_operation_(NULL),
|
|
|
|
compound_load_id_(kNoNumber),
|
2011-07-18 17:32:41 +00:00
|
|
|
assignment_id_(GetNextId(isolate)),
|
2010-12-07 11:31:57 +00:00
|
|
|
block_start_(false),
|
|
|
|
block_end_(false),
|
2012-02-08 09:56:33 +00:00
|
|
|
is_monomorphic_(false) { }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Token::Value Assignment::binary_op() const {
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ASSIGN_BIT_OR: return Token::BIT_OR;
|
|
|
|
case Token::ASSIGN_BIT_XOR: return Token::BIT_XOR;
|
|
|
|
case Token::ASSIGN_BIT_AND: return Token::BIT_AND;
|
|
|
|
case Token::ASSIGN_SHL: return Token::SHL;
|
|
|
|
case Token::ASSIGN_SAR: return Token::SAR;
|
|
|
|
case Token::ASSIGN_SHR: return Token::SHR;
|
|
|
|
case Token::ASSIGN_ADD: return Token::ADD;
|
|
|
|
case Token::ASSIGN_SUB: return Token::SUB;
|
|
|
|
case Token::ASSIGN_MUL: return Token::MUL;
|
|
|
|
case Token::ASSIGN_DIV: return Token::DIV;
|
|
|
|
case Token::ASSIGN_MOD: return Token::MOD;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
return Token::ILLEGAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FunctionLiteral::AllowsLazyCompilation() {
|
|
|
|
return scope()->AllowsLazyCompilation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-09 11:32:54 +00:00
|
|
|
int FunctionLiteral::start_position() const {
|
|
|
|
return scope()->start_position();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FunctionLiteral::end_position() const {
|
|
|
|
return scope()->end_position();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-24 15:17:04 +00:00
|
|
|
LanguageMode FunctionLiteral::language_mode() const {
|
|
|
|
return scope()->language_mode();
|
2011-11-09 11:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:06 +00:00
|
|
|
ObjectLiteral::Property::Property(Literal* key,
|
|
|
|
Expression* value,
|
|
|
|
Isolate* isolate) {
|
2010-10-27 11:37:59 +00:00
|
|
|
emit_store_ = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
key_ = key;
|
|
|
|
value_ = value;
|
|
|
|
Object* k = *key->handle();
|
2012-02-28 15:32:06 +00:00
|
|
|
if (k->IsSymbol() &&
|
|
|
|
isolate->heap()->Proto_symbol()->Equals(String::cast(k))) {
|
2008-07-03 15:10:15 +00:00
|
|
|
kind_ = PROTOTYPE;
|
2009-03-23 07:27:47 +00:00
|
|
|
} else if (value_->AsMaterializedLiteral() != NULL) {
|
|
|
|
kind_ = MATERIALIZED_LITERAL;
|
|
|
|
} else if (value_->AsLiteral() != NULL) {
|
|
|
|
kind_ = CONSTANT;
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2009-03-23 07:27:47 +00:00
|
|
|
kind_ = COMPUTED;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) {
|
2010-10-27 11:37:59 +00:00
|
|
|
emit_store_ = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
value_ = value;
|
|
|
|
kind_ = is_getter ? GETTER : SETTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-28 13:25:40 +00:00
|
|
|
bool ObjectLiteral::Property::IsCompileTimeValue() {
|
|
|
|
return kind_ == CONSTANT ||
|
|
|
|
(kind_ == MATERIALIZED_LITERAL &&
|
|
|
|
CompileTimeValue::IsCompileTimeValue(value_));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-27 11:37:59 +00:00
|
|
|
void ObjectLiteral::Property::set_emit_store(bool emit_store) {
|
|
|
|
emit_store_ = emit_store;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ObjectLiteral::Property::emit_store() {
|
|
|
|
return emit_store_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsEqualString(void* first, void* second) {
|
2011-01-12 09:29:20 +00:00
|
|
|
ASSERT((*reinterpret_cast<String**>(first))->IsString());
|
|
|
|
ASSERT((*reinterpret_cast<String**>(second))->IsString());
|
2010-10-27 11:37:59 +00:00
|
|
|
Handle<String> h1(reinterpret_cast<String**>(first));
|
|
|
|
Handle<String> h2(reinterpret_cast<String**>(second));
|
|
|
|
return (*h1)->Equals(*h2);
|
|
|
|
}
|
|
|
|
|
2011-02-02 14:02:58 +00:00
|
|
|
|
|
|
|
bool IsEqualNumber(void* first, void* second) {
|
|
|
|
ASSERT((*reinterpret_cast<Object**>(first))->IsNumber());
|
|
|
|
ASSERT((*reinterpret_cast<Object**>(second))->IsNumber());
|
|
|
|
|
|
|
|
Handle<Object> h1(reinterpret_cast<Object**>(first));
|
|
|
|
Handle<Object> h2(reinterpret_cast<Object**>(second));
|
|
|
|
if (h1->IsSmi()) {
|
|
|
|
return h2->IsSmi() && *h1 == *h2;
|
|
|
|
}
|
|
|
|
if (h2->IsSmi()) return false;
|
|
|
|
Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1);
|
|
|
|
Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2);
|
|
|
|
ASSERT(isfinite(n1->value()));
|
|
|
|
ASSERT(isfinite(n2->value()));
|
|
|
|
return n1->value() == n2->value();
|
2010-10-27 11:37:59 +00:00
|
|
|
}
|
|
|
|
|
2011-02-02 14:02:58 +00:00
|
|
|
|
2010-10-27 11:37:59 +00:00
|
|
|
void ObjectLiteral::CalculateEmitStore() {
|
2012-03-09 08:34:35 +00:00
|
|
|
ZoneHashMap table(Literal::Match);
|
|
|
|
for (int i = properties()->length() - 1; i >= 0; i--) {
|
|
|
|
ObjectLiteral::Property* property = properties()->at(i);
|
2010-10-27 11:37:59 +00:00
|
|
|
Literal* literal = property->key();
|
2012-03-09 08:34:35 +00:00
|
|
|
if (literal->handle()->IsNull()) continue;
|
|
|
|
uint32_t hash = literal->Hash();
|
2010-10-27 11:37:59 +00:00
|
|
|
// If the key of a computed property is in the table, do not emit
|
|
|
|
// a store for the property later.
|
2012-03-09 08:34:35 +00:00
|
|
|
if (property->kind() == ObjectLiteral::Property::COMPUTED &&
|
|
|
|
table.Lookup(literal, hash, false) != NULL) {
|
|
|
|
property->set_emit_store(false);
|
|
|
|
} else {
|
|
|
|
// Add key to the table.
|
|
|
|
table.Lookup(literal, hash, true);
|
2010-10-27 11:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-07 14:42:37 +00:00
|
|
|
void TargetCollector::AddTarget(Label* target) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Add the label to the collector, but discard duplicates.
|
2011-06-08 13:55:33 +00:00
|
|
|
int length = targets_.length();
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2011-06-08 13:55:33 +00:00
|
|
|
if (targets_[i] == target) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-06-08 13:55:33 +00:00
|
|
|
targets_.Add(target);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 11:10:05 +00:00
|
|
|
bool UnaryOperation::ResultOverwriteAllowed() {
|
|
|
|
switch (op_) {
|
|
|
|
case Token::BIT_NOT:
|
|
|
|
case Token::SUB:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BinaryOperation::ResultOverwriteAllowed() {
|
|
|
|
switch (op_) {
|
|
|
|
case Token::COMMA:
|
|
|
|
case Token::OR:
|
|
|
|
case Token::AND:
|
|
|
|
return false;
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHR:
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
static bool IsTypeof(Expression* expr) {
|
|
|
|
UnaryOperation* maybe_unary = expr->AsUnaryOperation();
|
|
|
|
return maybe_unary != NULL && maybe_unary->op() == Token::TYPEOF;
|
|
|
|
}
|
|
|
|
|
2011-06-24 14:30:10 +00:00
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
// Check for the pattern: typeof <expression> equals <string literal>.
|
|
|
|
static bool MatchLiteralCompareTypeof(Expression* left,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* right,
|
|
|
|
Expression** expr,
|
|
|
|
Handle<String>* check) {
|
|
|
|
if (IsTypeof(left) && right->IsStringLiteral() && Token::IsEqualityOp(op)) {
|
|
|
|
*expr = left->AsUnaryOperation()->expression();
|
|
|
|
*check = Handle<String>::cast(right->AsLiteral()->handle());
|
2011-06-24 14:30:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
bool CompareOperation::IsLiteralCompareTypeof(Expression** expr,
|
|
|
|
Handle<String>* check) {
|
|
|
|
return MatchLiteralCompareTypeof(left_, op_, right_, expr, check) ||
|
|
|
|
MatchLiteralCompareTypeof(right_, op_, left_, expr, check);
|
|
|
|
}
|
2011-06-24 14:30:10 +00:00
|
|
|
|
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
static bool IsVoidOfLiteral(Expression* expr) {
|
|
|
|
UnaryOperation* maybe_unary = expr->AsUnaryOperation();
|
|
|
|
return maybe_unary != NULL &&
|
|
|
|
maybe_unary->op() == Token::VOID &&
|
|
|
|
maybe_unary->expression()->AsLiteral() != NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-24 14:30:10 +00:00
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
// Check for the pattern: void <literal> equals <expression>
|
|
|
|
static bool MatchLiteralCompareUndefined(Expression* left,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* right,
|
|
|
|
Expression** expr) {
|
|
|
|
if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) {
|
|
|
|
*expr = right;
|
2011-06-24 14:30:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) {
|
|
|
|
return MatchLiteralCompareUndefined(left_, op_, right_, expr) ||
|
|
|
|
MatchLiteralCompareUndefined(right_, op_, left_, expr);
|
|
|
|
}
|
2011-09-15 09:09:40 +00:00
|
|
|
|
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
// Check for the pattern: null equals <expression>
|
|
|
|
static bool MatchLiteralCompareNull(Expression* left,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* right,
|
|
|
|
Expression** expr) {
|
|
|
|
if (left->IsNullLiteral() && Token::IsEqualityOp(op)) {
|
|
|
|
*expr = right;
|
2011-09-15 09:09:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
bool CompareOperation::IsLiteralCompareNull(Expression** expr) {
|
|
|
|
return MatchLiteralCompareNull(left_, op_, right_, expr) ||
|
|
|
|
MatchLiteralCompareNull(right_, op_, left_, expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Inlining support
|
|
|
|
|
2011-04-12 08:37:29 +00:00
|
|
|
bool Declaration::IsInlineable() const {
|
2012-02-09 13:39:26 +00:00
|
|
|
return proxy()->var()->IsStackAllocated();
|
|
|
|
}
|
|
|
|
|
2012-02-28 10:12:39 +00:00
|
|
|
bool FunctionDeclaration::IsInlineable() const {
|
|
|
|
return false;
|
2011-04-12 08:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Recording of type feedback
|
|
|
|
|
|
|
|
void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
// Record type feedback from the oracle in the AST.
|
2012-03-19 15:54:37 +00:00
|
|
|
is_uninitialized_ = oracle->LoadIsUninitialized(this);
|
|
|
|
if (is_uninitialized_) return;
|
|
|
|
|
2011-06-16 06:37:49 +00:00
|
|
|
is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this);
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Clear();
|
2010-12-07 11:31:57 +00:00
|
|
|
if (key()->IsPropertyName()) {
|
2011-03-23 13:40:07 +00:00
|
|
|
if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_ArrayLength)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
is_array_length_ = true;
|
2011-03-23 13:40:07 +00:00
|
|
|
} else if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_StringLength)) {
|
2011-01-25 15:51:10 +00:00
|
|
|
is_string_length_ = true;
|
2010-12-22 15:43:32 +00:00
|
|
|
} else if (oracle->LoadIsBuiltin(this,
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kLoadIC_FunctionPrototype)) {
|
2010-12-22 15:43:32 +00:00
|
|
|
is_function_prototype_ = true;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
|
|
|
Literal* lit_key = key()->AsLiteral();
|
|
|
|
ASSERT(lit_key != NULL && lit_key->handle()->IsString());
|
|
|
|
Handle<String> name = Handle<String>::cast(lit_key->handle());
|
2011-08-22 14:23:37 +00:00
|
|
|
oracle->LoadReceiverTypes(this, name, &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-03-23 13:40:07 +00:00
|
|
|
} else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) {
|
2011-03-14 15:36:00 +00:00
|
|
|
is_string_access_ = true;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else if (is_monomorphic_) {
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this));
|
2011-06-20 10:19:00 +00:00
|
|
|
} else if (oracle->LoadIsMegamorphicWithTypeInfo(this)) {
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Reserve(kMaxKeyedPolymorphism);
|
|
|
|
oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
Property* prop = target()->AsProperty();
|
|
|
|
ASSERT(prop != NULL);
|
2011-06-16 06:37:49 +00:00
|
|
|
is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this);
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Clear();
|
2010-12-07 11:31:57 +00:00
|
|
|
if (prop->key()->IsPropertyName()) {
|
|
|
|
Literal* lit_key = prop->key()->AsLiteral();
|
|
|
|
ASSERT(lit_key != NULL && lit_key->handle()->IsString());
|
|
|
|
Handle<String> name = Handle<String>::cast(lit_key->handle());
|
2011-08-22 14:23:37 +00:00
|
|
|
oracle->StoreReceiverTypes(this, name, &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
} else if (is_monomorphic_) {
|
2011-06-20 10:19:00 +00:00
|
|
|
// Record receiver type for monomorphic keyed stores.
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this));
|
2011-06-20 10:19:00 +00:00
|
|
|
} else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) {
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Reserve(kMaxKeyedPolymorphism);
|
|
|
|
oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_);
|
2011-04-07 09:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
2011-06-16 06:37:49 +00:00
|
|
|
is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this);
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Clear();
|
2011-04-07 09:51:25 +00:00
|
|
|
if (is_monomorphic_) {
|
2011-06-20 10:19:00 +00:00
|
|
|
// Record receiver type for monomorphic keyed stores.
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this));
|
2011-06-20 10:19:00 +00:00
|
|
|
} else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) {
|
2011-08-22 14:23:37 +00:00
|
|
|
receiver_types_.Reserve(kMaxKeyedPolymorphism);
|
|
|
|
oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
TypeInfo info = oracle->SwitchType(this);
|
|
|
|
if (info.IsSmi()) {
|
|
|
|
compare_type_ = SMI_ONLY;
|
2011-11-17 13:57:55 +00:00
|
|
|
} else if (info.IsSymbol()) {
|
|
|
|
compare_type_ = SYMBOL_ONLY;
|
|
|
|
} else if (info.IsNonSymbol()) {
|
|
|
|
compare_type_ = STRING_ONLY;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else if (info.IsNonPrimitive()) {
|
|
|
|
compare_type_ = OBJECT_ONLY;
|
|
|
|
} else {
|
|
|
|
ASSERT(compare_type_ == NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) {
|
Removed IsTransitionType predicate.
With the upcoming changes to CALLBACKS properties, a predicate on the transition
type alone doesn't make sense anymore: For CALLBACKS one has to look into the
property's value to decide, and there is even the possibility of having a an
accessor function *and* a transition in the same property.
I am not completely happy with some parts of this CL, because they contain
redundant code, but given the various representations we currently have for
property type/value pairs, I can see no easy way around that. Perhaps one can
improve this a bit in a different CL, the current diversity really, really hurts
productivity...
As a bonus, this CL includes a few minor things:
* CaseClause::RecordTypeFeedback has been cleaned up and it handles the
NULL_DESCRIPTOR case correctly now. Under some (very unlikely) circumstances,
we previously missed some opportunities for monomorphic calls. In general, it
is rather unfortunate that NULL_DESCRIPTOR "shines through", it is just a
hack for the inability to remove a descriptor entry during GC, something
callers shouldn't have to be aware of.
* DescriptorArray::CopyInsert has been cleaned up a bit, preparing it for later
CALLBACKS-related changes.
* LookupResult::Print is now more informative for CONSTANT_TRANSITION.
Review URL: https://chromiumcodereview.appspot.com/9320066
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10600 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-02-03 13:37:13 +00:00
|
|
|
// If there is an interceptor, we can't compute the target for a direct call.
|
2012-01-17 16:06:03 +00:00
|
|
|
if (type->has_named_interceptor()) return false;
|
|
|
|
|
2011-01-25 12:21:03 +00:00
|
|
|
if (check_type_ == RECEIVER_MAP_CHECK) {
|
Removed IsTransitionType predicate.
With the upcoming changes to CALLBACKS properties, a predicate on the transition
type alone doesn't make sense anymore: For CALLBACKS one has to look into the
property's value to decide, and there is even the possibility of having a an
accessor function *and* a transition in the same property.
I am not completely happy with some parts of this CL, because they contain
redundant code, but given the various representations we currently have for
property type/value pairs, I can see no easy way around that. Perhaps one can
improve this a bit in a different CL, the current diversity really, really hurts
productivity...
As a bonus, this CL includes a few minor things:
* CaseClause::RecordTypeFeedback has been cleaned up and it handles the
NULL_DESCRIPTOR case correctly now. Under some (very unlikely) circumstances,
we previously missed some opportunities for monomorphic calls. In general, it
is rather unfortunate that NULL_DESCRIPTOR "shines through", it is just a
hack for the inability to remove a descriptor entry during GC, something
callers shouldn't have to be aware of.
* DescriptorArray::CopyInsert has been cleaned up a bit, preparing it for later
CALLBACKS-related changes.
* LookupResult::Print is now more informative for CONSTANT_TRANSITION.
Review URL: https://chromiumcodereview.appspot.com/9320066
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10600 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-02-03 13:37:13 +00:00
|
|
|
// For primitive checks the holder is set up to point to the corresponding
|
|
|
|
// prototype object, i.e. one step of the algorithm below has been already
|
|
|
|
// performed. For non-primitive checks we clear it to allow computing
|
|
|
|
// targets for polymorphic calls.
|
2011-01-25 12:21:03 +00:00
|
|
|
holder_ = Handle<JSObject>::null();
|
|
|
|
}
|
Removed IsTransitionType predicate.
With the upcoming changes to CALLBACKS properties, a predicate on the transition
type alone doesn't make sense anymore: For CALLBACKS one has to look into the
property's value to decide, and there is even the possibility of having a an
accessor function *and* a transition in the same property.
I am not completely happy with some parts of this CL, because they contain
redundant code, but given the various representations we currently have for
property type/value pairs, I can see no easy way around that. Perhaps one can
improve this a bit in a different CL, the current diversity really, really hurts
productivity...
As a bonus, this CL includes a few minor things:
* CaseClause::RecordTypeFeedback has been cleaned up and it handles the
NULL_DESCRIPTOR case correctly now. Under some (very unlikely) circumstances,
we previously missed some opportunities for monomorphic calls. In general, it
is rather unfortunate that NULL_DESCRIPTOR "shines through", it is just a
hack for the inability to remove a descriptor entry during GC, something
callers shouldn't have to be aware of.
* DescriptorArray::CopyInsert has been cleaned up a bit, preparing it for later
CALLBACKS-related changes.
* LookupResult::Print is now more informative for CONSTANT_TRANSITION.
Review URL: https://chromiumcodereview.appspot.com/9320066
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10600 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-02-03 13:37:13 +00:00
|
|
|
LookupResult lookup(type->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
while (true) {
|
|
|
|
type->LookupInDescriptors(NULL, *name, &lookup);
|
2012-03-02 14:03:59 +00:00
|
|
|
if (lookup.IsFound()) {
|
|
|
|
switch (lookup.type()) {
|
|
|
|
case CONSTANT_FUNCTION:
|
|
|
|
// We surely know the target for a constant function.
|
2012-03-02 14:15:28 +00:00
|
|
|
target_ =
|
|
|
|
Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type));
|
2012-03-02 14:03:59 +00:00
|
|
|
return true;
|
|
|
|
case NORMAL:
|
|
|
|
case FIELD:
|
|
|
|
case CALLBACKS:
|
|
|
|
case HANDLER:
|
|
|
|
case INTERCEPTOR:
|
|
|
|
// We don't know the target.
|
|
|
|
return false;
|
|
|
|
case MAP_TRANSITION:
|
|
|
|
case ELEMENTS_TRANSITION:
|
|
|
|
case CONSTANT_TRANSITION:
|
|
|
|
case NULL_DESCRIPTOR:
|
|
|
|
// Perhaps something interesting is up in the prototype chain...
|
|
|
|
break;
|
Removed IsTransitionType predicate.
With the upcoming changes to CALLBACKS properties, a predicate on the transition
type alone doesn't make sense anymore: For CALLBACKS one has to look into the
property's value to decide, and there is even the possibility of having a an
accessor function *and* a transition in the same property.
I am not completely happy with some parts of this CL, because they contain
redundant code, but given the various representations we currently have for
property type/value pairs, I can see no easy way around that. Perhaps one can
improve this a bit in a different CL, the current diversity really, really hurts
productivity...
As a bonus, this CL includes a few minor things:
* CaseClause::RecordTypeFeedback has been cleaned up and it handles the
NULL_DESCRIPTOR case correctly now. Under some (very unlikely) circumstances,
we previously missed some opportunities for monomorphic calls. In general, it
is rather unfortunate that NULL_DESCRIPTOR "shines through", it is just a
hack for the inability to remove a descriptor entry during GC, something
callers shouldn't have to be aware of.
* DescriptorArray::CopyInsert has been cleaned up a bit, preparing it for later
CALLBACKS-related changes.
* LookupResult::Print is now more informative for CONSTANT_TRANSITION.
Review URL: https://chromiumcodereview.appspot.com/9320066
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10600 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-02-03 13:37:13 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
Removed IsTransitionType predicate.
With the upcoming changes to CALLBACKS properties, a predicate on the transition
type alone doesn't make sense anymore: For CALLBACKS one has to look into the
property's value to decide, and there is even the possibility of having a an
accessor function *and* a transition in the same property.
I am not completely happy with some parts of this CL, because they contain
redundant code, but given the various representations we currently have for
property type/value pairs, I can see no easy way around that. Perhaps one can
improve this a bit in a different CL, the current diversity really, really hurts
productivity...
As a bonus, this CL includes a few minor things:
* CaseClause::RecordTypeFeedback has been cleaned up and it handles the
NULL_DESCRIPTOR case correctly now. Under some (very unlikely) circumstances,
we previously missed some opportunities for monomorphic calls. In general, it
is rather unfortunate that NULL_DESCRIPTOR "shines through", it is just a
hack for the inability to remove a descriptor entry during GC, something
callers shouldn't have to be aware of.
* DescriptorArray::CopyInsert has been cleaned up a bit, preparing it for later
CALLBACKS-related changes.
* LookupResult::Print is now more informative for CONSTANT_TRANSITION.
Review URL: https://chromiumcodereview.appspot.com/9320066
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10600 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-02-03 13:37:13 +00:00
|
|
|
// If we reach the end of the prototype chain, we don't know the target.
|
|
|
|
if (!type->prototype()->IsJSObject()) return false;
|
|
|
|
// Go up the prototype chain, recording where we are currently.
|
|
|
|
holder_ = Handle<JSObject>(JSObject::cast(type->prototype()));
|
|
|
|
type = Handle<Map>(holder()->map());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Call::ComputeGlobalTarget(Handle<GlobalObject> global,
|
2011-04-01 11:54:04 +00:00
|
|
|
LookupResult* lookup) {
|
2010-12-07 11:31:57 +00:00
|
|
|
target_ = Handle<JSFunction>::null();
|
|
|
|
cell_ = Handle<JSGlobalPropertyCell>::null();
|
2012-01-23 12:01:47 +00:00
|
|
|
ASSERT(lookup->IsFound() &&
|
2011-04-01 11:54:04 +00:00
|
|
|
lookup->type() == NORMAL &&
|
|
|
|
lookup->holder() == *global);
|
|
|
|
cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(lookup));
|
|
|
|
if (cell_->value()->IsJSFunction()) {
|
|
|
|
Handle<JSFunction> candidate(JSFunction::cast(cell_->value()));
|
|
|
|
// If the function is in new space we assume it's more likely to
|
|
|
|
// change and thus prefer the general IC code.
|
2012-01-17 15:53:58 +00:00
|
|
|
if (!HEAP->InNewSpace(*candidate)) {
|
2011-04-01 11:54:04 +00:00
|
|
|
target_ = candidate;
|
|
|
|
return true;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle,
|
|
|
|
CallKind call_kind) {
|
2011-09-27 11:42:02 +00:00
|
|
|
is_monomorphic_ = oracle->CallIsMonomorphic(this);
|
2010-12-07 11:31:57 +00:00
|
|
|
Property* property = expression()->AsProperty();
|
2011-09-27 11:42:02 +00:00
|
|
|
if (property == NULL) {
|
|
|
|
// Function call. Specialize for monomorphic calls.
|
|
|
|
if (is_monomorphic_) target_ = oracle->GetCallTarget(this);
|
|
|
|
} else {
|
|
|
|
// Method call. Specialize for the receiver types seen at runtime.
|
|
|
|
Literal* key = property->key()->AsLiteral();
|
|
|
|
ASSERT(key != NULL && key->handle()->IsString());
|
|
|
|
Handle<String> name = Handle<String>::cast(key->handle());
|
|
|
|
receiver_types_.Clear();
|
|
|
|
oracle->CallReceiverTypes(this, name, call_kind, &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
#ifdef DEBUG
|
2011-09-27 11:42:02 +00:00
|
|
|
if (FLAG_enable_slow_asserts) {
|
|
|
|
int length = receiver_types_.length();
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
Handle<Map> map = receiver_types_.at(i);
|
|
|
|
ASSERT(!map.is_null() && *map != NULL);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-09-27 11:42:02 +00:00
|
|
|
check_type_ = oracle->GetCallCheckType(this);
|
|
|
|
if (is_monomorphic_) {
|
|
|
|
Handle<Map> map;
|
|
|
|
if (receiver_types_.length() > 0) {
|
|
|
|
ASSERT(check_type_ == RECEIVER_MAP_CHECK);
|
|
|
|
map = receiver_types_.at(0);
|
|
|
|
} else {
|
|
|
|
ASSERT(check_type_ != RECEIVER_MAP_CHECK);
|
|
|
|
holder_ = Handle<JSObject>(
|
|
|
|
oracle->GetPrototypeForPrimitiveCheck(check_type_));
|
|
|
|
map = Handle<Map>(holder_->map());
|
|
|
|
}
|
|
|
|
is_monomorphic_ = ComputeTarget(map, name);
|
2011-01-13 14:16:08 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
is_monomorphic_ = oracle->CallNewIsMonomorphic(this);
|
|
|
|
if (is_monomorphic_) {
|
|
|
|
target_ = oracle->GetCallNewTarget(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void CompareOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
2011-01-27 14:04:07 +00:00
|
|
|
TypeInfo info = oracle->CompareType(this);
|
|
|
|
if (info.IsSmi()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
compare_type_ = SMI_ONLY;
|
2011-01-27 14:04:07 +00:00
|
|
|
} else if (info.IsNonPrimitive()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
compare_type_ = OBJECT_ONLY;
|
|
|
|
} else {
|
|
|
|
ASSERT(compare_type_ == NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 12:11:46 +00:00
|
|
|
void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
receiver_type_ = oracle->ObjectLiteralStoreIsMonomorphic(this)
|
|
|
|
? oracle->GetObjectLiteralStoreMap(this)
|
|
|
|
: Handle<Map>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-11-27 13:55:06 +00:00
|
|
|
// Implementation of AstVisitor
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-30 12:25:58 +00:00
|
|
|
bool AstVisitor::CheckStackOverflow() {
|
|
|
|
if (stack_overflow_) return true;
|
2011-03-21 11:57:59 +00:00
|
|
|
StackLimitCheck check(isolate_);
|
2010-03-30 12:25:58 +00:00
|
|
|
if (!check.HasOverflowed()) return false;
|
|
|
|
return (stack_overflow_ = true);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-10-12 15:06:28 +00:00
|
|
|
void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) {
|
|
|
|
for (int i = 0; i < declarations->length(); i++) {
|
|
|
|
Visit(declarations->at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 13:55:06 +00:00
|
|
|
void AstVisitor::VisitStatements(ZoneList<Statement*>* statements) {
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < statements->length(); i++) {
|
|
|
|
Visit(statements->at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 13:55:06 +00:00
|
|
|
void AstVisitor::VisitExpressions(ZoneList<Expression*>* expressions) {
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < expressions->length(); i++) {
|
|
|
|
// The variable statement visiting code may pass NULL expressions
|
|
|
|
// to this code. Maybe this should be handled by introducing an
|
|
|
|
// undefined expression or literal? Revisit this code if this
|
|
|
|
// changes
|
|
|
|
Expression* expression = expressions->at(i);
|
|
|
|
if (expression != NULL) Visit(expression);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Regular expressions
|
|
|
|
|
|
|
|
#define MAKE_ACCEPT(Name) \
|
|
|
|
void* RegExp##Name::Accept(RegExpVisitor* visitor, void* data) { \
|
|
|
|
return visitor->Visit##Name(this, data); \
|
|
|
|
}
|
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ACCEPT)
|
|
|
|
#undef MAKE_ACCEPT
|
|
|
|
|
|
|
|
#define MAKE_TYPE_CASE(Name) \
|
|
|
|
RegExp##Name* RegExpTree::As##Name() { \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
bool RegExpTree::Is##Name() { return false; }
|
2008-11-26 11:29:26 +00:00
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_TYPE_CASE)
|
2008-11-25 11:07:48 +00:00
|
|
|
#undef MAKE_TYPE_CASE
|
|
|
|
|
|
|
|
#define MAKE_TYPE_CASE(Name) \
|
|
|
|
RegExp##Name* RegExp##Name::As##Name() { \
|
|
|
|
return this; \
|
|
|
|
} \
|
|
|
|
bool RegExp##Name::Is##Name() { return true; }
|
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_TYPE_CASE)
|
|
|
|
#undef MAKE_TYPE_CASE
|
|
|
|
|
|
|
|
|
2009-01-14 11:32:23 +00:00
|
|
|
static Interval ListCaptureRegisters(ZoneList<RegExpTree*>* children) {
|
|
|
|
Interval result = Interval::Empty();
|
|
|
|
for (int i = 0; i < children->length(); i++)
|
|
|
|
result = result.Union(children->at(i)->CaptureRegisters());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Interval RegExpAlternative::CaptureRegisters() {
|
|
|
|
return ListCaptureRegisters(nodes());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Interval RegExpDisjunction::CaptureRegisters() {
|
|
|
|
return ListCaptureRegisters(alternatives());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Interval RegExpLookahead::CaptureRegisters() {
|
|
|
|
return body()->CaptureRegisters();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Interval RegExpCapture::CaptureRegisters() {
|
|
|
|
Interval self(StartRegister(index()), EndRegister(index()));
|
|
|
|
return self.Union(body()->CaptureRegisters());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Interval RegExpQuantifier::CaptureRegisters() {
|
|
|
|
return body()->CaptureRegisters();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
bool RegExpAssertion::IsAnchoredAtStart() {
|
2009-01-23 07:46:44 +00:00
|
|
|
return type() == RegExpAssertion::START_OF_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
bool RegExpAssertion::IsAnchoredAtEnd() {
|
|
|
|
return type() == RegExpAssertion::END_OF_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RegExpAlternative::IsAnchoredAtStart() {
|
2009-02-03 11:43:55 +00:00
|
|
|
ZoneList<RegExpTree*>* nodes = this->nodes();
|
|
|
|
for (int i = 0; i < nodes->length(); i++) {
|
|
|
|
RegExpTree* node = nodes->at(i);
|
2010-10-19 14:00:01 +00:00
|
|
|
if (node->IsAnchoredAtStart()) { return true; }
|
|
|
|
if (node->max_match() > 0) { return false; }
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RegExpAlternative::IsAnchoredAtEnd() {
|
|
|
|
ZoneList<RegExpTree*>* nodes = this->nodes();
|
|
|
|
for (int i = nodes->length() - 1; i >= 0; i--) {
|
|
|
|
RegExpTree* node = nodes->at(i);
|
|
|
|
if (node->IsAnchoredAtEnd()) { return true; }
|
2009-02-03 11:43:55 +00:00
|
|
|
if (node->max_match() > 0) { return false; }
|
|
|
|
}
|
|
|
|
return false;
|
2009-01-23 07:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
bool RegExpDisjunction::IsAnchoredAtStart() {
|
2009-01-23 07:46:44 +00:00
|
|
|
ZoneList<RegExpTree*>* alternatives = this->alternatives();
|
|
|
|
for (int i = 0; i < alternatives->length(); i++) {
|
2010-10-19 14:00:01 +00:00
|
|
|
if (!alternatives->at(i)->IsAnchoredAtStart())
|
2009-01-23 07:46:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
bool RegExpDisjunction::IsAnchoredAtEnd() {
|
|
|
|
ZoneList<RegExpTree*>* alternatives = this->alternatives();
|
|
|
|
for (int i = 0; i < alternatives->length(); i++) {
|
|
|
|
if (!alternatives->at(i)->IsAnchoredAtEnd())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RegExpLookahead::IsAnchoredAtStart() {
|
|
|
|
return is_positive() && body()->IsAnchoredAtStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RegExpCapture::IsAnchoredAtStart() {
|
|
|
|
return body()->IsAnchoredAtStart();
|
2009-01-23 07:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
bool RegExpCapture::IsAnchoredAtEnd() {
|
|
|
|
return body()->IsAnchoredAtEnd();
|
2009-01-23 07:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
// Convert regular expression trees to a simple sexp representation.
|
|
|
|
// This representation should be different from the input grammar
|
|
|
|
// in as many cases as possible, to make it more difficult for incorrect
|
|
|
|
// parses to look as correct ones which is likely if the input and
|
|
|
|
// output formats are alike.
|
|
|
|
class RegExpUnparser: public RegExpVisitor {
|
|
|
|
public:
|
|
|
|
RegExpUnparser();
|
|
|
|
void VisitCharacterRange(CharacterRange that);
|
2011-09-09 22:39:47 +00:00
|
|
|
SmartArrayPointer<const char> ToString() { return stream_.ToCString(); }
|
2008-11-25 11:07:48 +00:00
|
|
|
#define MAKE_CASE(Name) virtual void* Visit##Name(RegExp##Name*, void* data);
|
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
|
|
|
|
#undef MAKE_CASE
|
|
|
|
private:
|
|
|
|
StringStream* stream() { return &stream_; }
|
|
|
|
HeapStringAllocator alloc_;
|
|
|
|
StringStream stream_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RegExpUnparser::RegExpUnparser() : stream_(&alloc_) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitDisjunction(RegExpDisjunction* that, void* data) {
|
|
|
|
stream()->Add("(|");
|
|
|
|
for (int i = 0; i < that->alternatives()->length(); i++) {
|
|
|
|
stream()->Add(" ");
|
|
|
|
that->alternatives()->at(i)->Accept(this, data);
|
|
|
|
}
|
|
|
|
stream()->Add(")");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitAlternative(RegExpAlternative* that, void* data) {
|
|
|
|
stream()->Add("(:");
|
|
|
|
for (int i = 0; i < that->nodes()->length(); i++) {
|
|
|
|
stream()->Add(" ");
|
|
|
|
that->nodes()->at(i)->Accept(this, data);
|
|
|
|
}
|
|
|
|
stream()->Add(")");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpUnparser::VisitCharacterRange(CharacterRange that) {
|
|
|
|
stream()->Add("%k", that.from());
|
|
|
|
if (!that.IsSingleton()) {
|
|
|
|
stream()->Add("-%k", that.to());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that,
|
|
|
|
void* data) {
|
|
|
|
if (that->is_negated())
|
|
|
|
stream()->Add("^");
|
|
|
|
stream()->Add("[");
|
|
|
|
for (int i = 0; i < that->ranges()->length(); i++) {
|
|
|
|
if (i > 0) stream()->Add(" ");
|
|
|
|
VisitCharacterRange(that->ranges()->at(i));
|
|
|
|
}
|
|
|
|
stream()->Add("]");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) {
|
|
|
|
switch (that->type()) {
|
|
|
|
case RegExpAssertion::START_OF_INPUT:
|
|
|
|
stream()->Add("@^i");
|
|
|
|
break;
|
|
|
|
case RegExpAssertion::END_OF_INPUT:
|
|
|
|
stream()->Add("@$i");
|
|
|
|
break;
|
|
|
|
case RegExpAssertion::START_OF_LINE:
|
|
|
|
stream()->Add("@^l");
|
|
|
|
break;
|
|
|
|
case RegExpAssertion::END_OF_LINE:
|
|
|
|
stream()->Add("@$l");
|
|
|
|
break;
|
|
|
|
case RegExpAssertion::BOUNDARY:
|
|
|
|
stream()->Add("@b");
|
|
|
|
break;
|
|
|
|
case RegExpAssertion::NON_BOUNDARY:
|
|
|
|
stream()->Add("@B");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitAtom(RegExpAtom* that, void* data) {
|
|
|
|
stream()->Add("'");
|
|
|
|
Vector<const uc16> chardata = that->data();
|
|
|
|
for (int i = 0; i < chardata.length(); i++) {
|
|
|
|
stream()->Add("%k", chardata[i]);
|
|
|
|
}
|
|
|
|
stream()->Add("'");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitText(RegExpText* that, void* data) {
|
|
|
|
if (that->elements()->length() == 1) {
|
|
|
|
that->elements()->at(0).data.u_atom->Accept(this, data);
|
|
|
|
} else {
|
|
|
|
stream()->Add("(!");
|
|
|
|
for (int i = 0; i < that->elements()->length(); i++) {
|
|
|
|
stream()->Add(" ");
|
|
|
|
that->elements()->at(i).data.u_atom->Accept(this, data);
|
|
|
|
}
|
|
|
|
stream()->Add(")");
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitQuantifier(RegExpQuantifier* that, void* data) {
|
|
|
|
stream()->Add("(# %i ", that->min());
|
2008-12-17 10:59:14 +00:00
|
|
|
if (that->max() == RegExpTree::kInfinity) {
|
2008-11-25 11:07:48 +00:00
|
|
|
stream()->Add("- ");
|
|
|
|
} else {
|
|
|
|
stream()->Add("%i ", that->max());
|
|
|
|
}
|
2010-01-07 19:01:23 +00:00
|
|
|
stream()->Add(that->is_greedy() ? "g " : that->is_possessive() ? "p " : "n ");
|
2008-11-25 11:07:48 +00:00
|
|
|
that->body()->Accept(this, data);
|
|
|
|
stream()->Add(")");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitCapture(RegExpCapture* that, void* data) {
|
|
|
|
stream()->Add("(^ ");
|
|
|
|
that->body()->Accept(this, data);
|
|
|
|
stream()->Add(")");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitLookahead(RegExpLookahead* that, void* data) {
|
|
|
|
stream()->Add("(-> ");
|
|
|
|
stream()->Add(that->is_positive() ? "+ " : "- ");
|
|
|
|
that->body()->Accept(this, data);
|
|
|
|
stream()->Add(")");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitBackReference(RegExpBackReference* that,
|
|
|
|
void* data) {
|
|
|
|
stream()->Add("(<- %i)", that->index());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitEmpty(RegExpEmpty* that, void* data) {
|
|
|
|
stream()->Put('%');
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-09 22:39:47 +00:00
|
|
|
SmartArrayPointer<const char> RegExpTree::ToString() {
|
2008-11-25 11:07:48 +00:00
|
|
|
RegExpUnparser unparser;
|
|
|
|
Accept(&unparser, NULL);
|
|
|
|
return unparser.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-17 10:59:14 +00:00
|
|
|
RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives)
|
|
|
|
: alternatives_(alternatives) {
|
2009-01-23 07:46:44 +00:00
|
|
|
ASSERT(alternatives->length() > 1);
|
2008-12-17 10:59:14 +00:00
|
|
|
RegExpTree* first_alternative = alternatives->at(0);
|
|
|
|
min_match_ = first_alternative->min_match();
|
|
|
|
max_match_ = first_alternative->max_match();
|
|
|
|
for (int i = 1; i < alternatives->length(); i++) {
|
|
|
|
RegExpTree* alternative = alternatives->at(i);
|
|
|
|
min_match_ = Min(min_match_, alternative->min_match());
|
|
|
|
max_match_ = Max(max_match_, alternative->max_match());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes)
|
|
|
|
: nodes_(nodes) {
|
2009-01-23 07:46:44 +00:00
|
|
|
ASSERT(nodes->length() > 1);
|
2008-12-17 10:59:14 +00:00
|
|
|
min_match_ = 0;
|
|
|
|
max_match_ = 0;
|
|
|
|
for (int i = 0; i < nodes->length(); i++) {
|
|
|
|
RegExpTree* node = nodes->at(i);
|
|
|
|
min_match_ += node->min_match();
|
|
|
|
int node_max_match = node->max_match();
|
|
|
|
if (kInfinity - max_match_ < node_max_match) {
|
|
|
|
max_match_ = kInfinity;
|
|
|
|
} else {
|
|
|
|
max_match_ += node->max_match();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 13:21:32 +00:00
|
|
|
|
2011-07-18 17:32:41 +00:00
|
|
|
CaseClause::CaseClause(Isolate* isolate,
|
|
|
|
Expression* label,
|
2010-12-07 11:31:57 +00:00
|
|
|
ZoneList<Statement*>* statements,
|
|
|
|
int pos)
|
|
|
|
: label_(label),
|
|
|
|
statements_(statements),
|
|
|
|
position_(pos),
|
2011-03-09 12:06:54 +00:00
|
|
|
compare_type_(NONE),
|
2011-07-18 17:32:41 +00:00
|
|
|
compare_id_(AstNode::GetNextId(isolate)),
|
|
|
|
entry_id_(AstNode::GetNextId(isolate)) {
|
2011-03-09 12:06:54 +00:00
|
|
|
}
|
2010-05-10 11:32:25 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
#define INCREASE_NODE_COUNT(NodeType) \
|
|
|
|
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
|
|
|
|
increase_node_count(); \
|
|
|
|
}
|
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
INCREASE_NODE_COUNT(VariableDeclaration)
|
2012-02-28 10:12:39 +00:00
|
|
|
INCREASE_NODE_COUNT(FunctionDeclaration)
|
2012-02-09 13:40:41 +00:00
|
|
|
INCREASE_NODE_COUNT(ModuleDeclaration)
|
2012-02-29 12:12:52 +00:00
|
|
|
INCREASE_NODE_COUNT(ImportDeclaration)
|
|
|
|
INCREASE_NODE_COUNT(ExportDeclaration)
|
2012-02-09 13:40:41 +00:00
|
|
|
INCREASE_NODE_COUNT(ModuleLiteral)
|
|
|
|
INCREASE_NODE_COUNT(ModuleVariable)
|
|
|
|
INCREASE_NODE_COUNT(ModulePath)
|
|
|
|
INCREASE_NODE_COUNT(ModuleUrl)
|
2012-02-08 09:56:33 +00:00
|
|
|
INCREASE_NODE_COUNT(Block)
|
|
|
|
INCREASE_NODE_COUNT(ExpressionStatement)
|
|
|
|
INCREASE_NODE_COUNT(EmptyStatement)
|
|
|
|
INCREASE_NODE_COUNT(IfStatement)
|
|
|
|
INCREASE_NODE_COUNT(ContinueStatement)
|
|
|
|
INCREASE_NODE_COUNT(BreakStatement)
|
|
|
|
INCREASE_NODE_COUNT(ReturnStatement)
|
|
|
|
INCREASE_NODE_COUNT(Conditional)
|
|
|
|
INCREASE_NODE_COUNT(Literal)
|
2012-02-14 08:57:10 +00:00
|
|
|
INCREASE_NODE_COUNT(ObjectLiteral)
|
2012-02-08 09:56:33 +00:00
|
|
|
INCREASE_NODE_COUNT(Assignment)
|
|
|
|
INCREASE_NODE_COUNT(Throw)
|
|
|
|
INCREASE_NODE_COUNT(Property)
|
|
|
|
INCREASE_NODE_COUNT(UnaryOperation)
|
|
|
|
INCREASE_NODE_COUNT(CountOperation)
|
|
|
|
INCREASE_NODE_COUNT(BinaryOperation)
|
|
|
|
INCREASE_NODE_COUNT(CompareOperation)
|
|
|
|
INCREASE_NODE_COUNT(ThisFunction)
|
2012-02-22 10:48:58 +00:00
|
|
|
INCREASE_NODE_COUNT(Call)
|
|
|
|
INCREASE_NODE_COUNT(CallNew)
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
#undef INCREASE_NODE_COUNT
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitWithStatement(WithStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontOptimize);
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitSwitchStatement(SwitchStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitDoWhileStatement(DoWhileStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontSelfOptimize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitWhileStatement(WhileStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontSelfOptimize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitForStatement(ForStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontSelfOptimize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitForInStatement(ForInStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontSelfOptimize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitTryCatchStatement(TryCatchStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontOptimize);
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitTryFinallyStatement(
|
|
|
|
TryFinallyStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontOptimize);
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitDebuggerStatement(DebuggerStatement* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontOptimize);
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-23 14:12:44 +00:00
|
|
|
void AstConstructionVisitor::VisitFunctionLiteral(FunctionLiteral* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
void AstConstructionVisitor::VisitSharedFunctionInfoLiteral(
|
|
|
|
SharedFunctionInfoLiteral* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontOptimize);
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitVariableProxy(VariableProxy* node) {
|
|
|
|
increase_node_count();
|
|
|
|
// In theory, we'd have to add:
|
|
|
|
// if(node->var()->IsLookupSlot()) { add_flag(kDontInline); }
|
|
|
|
// However, node->var() is usually not bound yet at VariableProxy creation
|
|
|
|
// time, and LOOKUP variables only result from constructs that cannot
|
|
|
|
// be inlined anyway.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitRegExpLiteral(RegExpLiteral* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontInline); // TODO(1322): Allow materialized literals.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitArrayLiteral(ArrayLiteral* node) {
|
|
|
|
increase_node_count();
|
|
|
|
add_flag(kDontInline); // TODO(1322): Allow materialized literals.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) {
|
|
|
|
increase_node_count();
|
|
|
|
if (node->is_jsruntime()) {
|
|
|
|
// Don't try to inline JS runtime calls because we don't (currently) even
|
|
|
|
// optimize them.
|
|
|
|
add_flag(kDontInline);
|
|
|
|
} else if (node->function()->intrinsic_type == Runtime::INLINE &&
|
|
|
|
(node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) ||
|
|
|
|
node->name()->IsEqualTo(CStrVector("_Arguments")))) {
|
|
|
|
// Don't inline the %_ArgumentsLength or %_Arguments because their
|
|
|
|
// implementation will not work. There is no stack frame to get them
|
|
|
|
// from.
|
|
|
|
add_flag(kDontInline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-09 08:34:35 +00:00
|
|
|
|
|
|
|
Handle<String> Literal::ToString() {
|
|
|
|
if (handle_->IsString()) return Handle<String>::cast(handle_);
|
|
|
|
ASSERT(handle_->IsNumber());
|
|
|
|
char arr[100];
|
|
|
|
Vector<char> buffer(arr, ARRAY_SIZE(arr));
|
|
|
|
const char* str;
|
|
|
|
if (handle_->IsSmi()) {
|
|
|
|
// Optimization only, the heap number case would subsume this.
|
|
|
|
OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value());
|
|
|
|
str = arr;
|
|
|
|
} else {
|
|
|
|
str = DoubleToCString(handle_->Number(), buffer);
|
|
|
|
}
|
|
|
|
return FACTORY->NewStringFromAscii(CStrVector(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|