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
|
|
|
|
2013-04-19 13:26:47 +00:00
|
|
|
#include <cmath> // For isfinite.
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "builtins.h"
|
2013-01-21 14:53:29 +00:00
|
|
|
#include "code-stubs.h"
|
2013-05-27 13:59:20 +00:00
|
|
|
#include "contexts.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#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() {
|
2013-06-24 10:37:59 +00:00
|
|
|
return AsLiteral() != NULL && AsLiteral()->value()->IsSmi();
|
2011-10-31 11:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Expression::IsStringLiteral() {
|
2013-06-24 10:37:59 +00:00
|
|
|
return AsLiteral() != NULL && AsLiteral()->value()->IsString();
|
2010-03-11 10:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 11:11:26 +00:00
|
|
|
bool Expression::IsNullLiteral() {
|
2013-06-24 10:37:59 +00:00
|
|
|
return AsLiteral() != NULL && AsLiteral()->value()->IsNull();
|
2010-03-11 10:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 14:10:38 +00:00
|
|
|
bool Expression::IsUndefinedLiteral(Isolate* isolate) {
|
|
|
|
VariableProxy* var_proxy = AsVariableProxy();
|
|
|
|
if (var_proxy == NULL) return false;
|
|
|
|
Variable* var = var_proxy->var();
|
|
|
|
// The global identifier "undefined" is immutable. Everything
|
|
|
|
// else could be reassigned.
|
|
|
|
return var != NULL && var->location() == Variable::UNALLOCATED &&
|
|
|
|
var_proxy->name()->Equals(isolate->heap()->undefined_string());
|
2013-04-24 11:32:17 +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-07-13 09:29:43 +00:00
|
|
|
Interface* interface,
|
|
|
|
int position)
|
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.
|
2013-02-28 17:03:34 +00:00
|
|
|
ASSERT(name->IsInternalizedString());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VariableProxy::BindTo(Variable* var) {
|
|
|
|
ASSERT(var_ == NULL); // must be bound only once
|
|
|
|
ASSERT(var != NULL); // must bind
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface()));
|
2008-07-03 15:10:15 +00:00
|
|
|
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),
|
2011-07-18 17:32:41 +00:00
|
|
|
assignment_id_(GetNextId(isolate)),
|
2013-03-20 10:37:13 +00:00
|
|
|
is_monomorphic_(false),
|
2013-06-20 13:09:43 +00:00
|
|
|
is_uninitialized_(false),
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode_(STANDARD_STORE) { }
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 14:29:48 +00:00
|
|
|
bool FunctionLiteral::AllowsLazyCompilationWithoutContext() {
|
|
|
|
return scope()->AllowsLazyCompilationWithoutContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
ObjectLiteralProperty::ObjectLiteralProperty(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;
|
2013-06-24 10:37:59 +00:00
|
|
|
Object* k = *key->value();
|
2013-02-28 17:03:34 +00:00
|
|
|
if (k->IsInternalizedString() &&
|
|
|
|
isolate->heap()->proto_string()->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
ObjectLiteralProperty::ObjectLiteralProperty(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);
|
2013-04-19 13:26:47 +00:00
|
|
|
ASSERT(std::isfinite(n1->value()));
|
|
|
|
ASSERT(std::isfinite(n2->value()));
|
2011-02-02 14:02:58 +00:00
|
|
|
return n1->value() == n2->value();
|
2010-10-27 11:37:59 +00:00
|
|
|
}
|
|
|
|
|
2011-02-02 14:02:58 +00:00
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void ObjectLiteral::CalculateEmitStore(Zone* zone) {
|
|
|
|
ZoneAllocationPolicy allocator(zone);
|
|
|
|
|
|
|
|
ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity,
|
|
|
|
allocator);
|
2012-03-09 08:34:35 +00:00
|
|
|
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();
|
2013-06-24 10:37:59 +00:00
|
|
|
if (literal->value()->IsNull()) continue;
|
2012-03-09 08:34:35 +00:00
|
|
|
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.
|
2013-08-13 17:27:58 +00:00
|
|
|
if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL ||
|
|
|
|
property->kind() == ObjectLiteral::Property::COMPUTED) &&
|
2012-06-11 12:42:31 +00:00
|
|
|
table.Lookup(literal, hash, false, allocator) != NULL) {
|
2012-03-09 08:34:35 +00:00
|
|
|
property->set_emit_store(false);
|
|
|
|
} else {
|
|
|
|
// Add key to the table.
|
2012-06-11 12:42:31 +00:00
|
|
|
table.Lookup(literal, hash, true, allocator);
|
2010-10-27 11:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void TargetCollector::AddTarget(Label* target, Zone* zone) {
|
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
|
|
|
}
|
2012-06-11 12:42:31 +00:00
|
|
|
targets_.Add(target, zone);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 11:49:46 +00:00
|
|
|
void UnaryOperation::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
// TODO(olivf) If this Operation is used in a test context, then the
|
|
|
|
// expression has a ToBoolean stub and we want to collect the type
|
|
|
|
// information. However the GraphBuilder expects it to be on the instruction
|
|
|
|
// corresponding to the TestContext, therefore we have to store it here and
|
|
|
|
// not on the operand.
|
|
|
|
set_to_boolean_types(oracle->ToBooleanTypes(expression()->test_id()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BinaryOperation::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
// TODO(olivf) If this Operation is used in a test context, then the right
|
|
|
|
// hand side has a ToBoolean stub and we want to collect the type information.
|
|
|
|
// However the GraphBuilder expects it to be on the instruction corresponding
|
|
|
|
// to the TestContext, therefore we have to store it here and not on the
|
|
|
|
// right hand operand.
|
|
|
|
set_to_boolean_types(oracle->ToBooleanTypes(right()->test_id()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 11:10:05 +00:00
|
|
|
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)) {
|
2013-07-17 15:58:59 +00:00
|
|
|
*expr = left->AsUnaryOperation()->expression();
|
2013-06-24 10:37:59 +00:00
|
|
|
*check = Handle<String>::cast(right->AsLiteral()->value());
|
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
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
// Check for the pattern: void <literal> equals <expression> or
|
|
|
|
// undefined equals <expression>
|
2011-09-19 14:50:33 +00:00
|
|
|
static bool MatchLiteralCompareUndefined(Expression* left,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* right,
|
2013-07-17 14:10:38 +00:00
|
|
|
Expression** expr,
|
|
|
|
Isolate* isolate) {
|
2011-09-19 14:50:33 +00:00
|
|
|
if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) {
|
2013-04-24 11:32:17 +00:00
|
|
|
*expr = right;
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-17 14:10:38 +00:00
|
|
|
if (left->IsUndefinedLiteral(isolate) && Token::IsEqualityOp(op)) {
|
2011-09-19 14:50:33 +00:00
|
|
|
*expr = right;
|
2011-06-24 14:30:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 14:10:38 +00:00
|
|
|
bool CompareOperation::IsLiteralCompareUndefined(
|
|
|
|
Expression** expr, Isolate* isolate) {
|
|
|
|
return MatchLiteralCompareUndefined(left_, op_, right_, expr, isolate) ||
|
|
|
|
MatchLiteralCompareUndefined(right_, op_, left_, expr, isolate);
|
2011-09-19 14:50:33 +00:00
|
|
|
}
|
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
|
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
// TODO(rossberg): all RecordTypeFeedback functions should disappear
|
|
|
|
// once we use the common type field in the AST consistently.
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
void ForInStatement::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
for_in_type_ = static_cast<ForInType>(oracle->ForInType(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) {
|
|
|
|
to_boolean_types_ = oracle->ToBooleanTypes(test_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle,
|
|
|
|
Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// 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()) {
|
2013-01-21 17:54:36 +00:00
|
|
|
FunctionPrototypeStub proto_stub(Code::LOAD_IC);
|
2013-01-21 14:53:29 +00:00
|
|
|
StringLengthStub string_stub(Code::LOAD_IC, false);
|
2013-03-28 12:43:19 +00:00
|
|
|
if (oracle->LoadIsStub(this, &string_stub)) {
|
2011-01-25 15:51:10 +00:00
|
|
|
is_string_length_ = true;
|
2013-01-21 17:54:36 +00:00
|
|
|
} else if (oracle->LoadIsStub(this, &proto_stub)) {
|
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();
|
2013-06-24 10:37:59 +00:00
|
|
|
ASSERT(lit_key != NULL && lit_key->value()->IsString());
|
|
|
|
Handle<String> name = Handle<String>::cast(lit_key->value());
|
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_) {
|
2012-06-11 12:42:31 +00:00
|
|
|
receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this),
|
|
|
|
zone);
|
2013-01-08 12:01:51 +00:00
|
|
|
} else if (oracle->LoadIsPolymorphic(this)) {
|
2012-06-11 12:42:31 +00:00
|
|
|
receiver_types_.Reserve(kMaxKeyedPolymorphism, zone);
|
2012-08-06 14:13:09 +00:00
|
|
|
oracle->CollectKeyedReceiverTypes(PropertyFeedbackId(), &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle,
|
|
|
|
Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Property* prop = target()->AsProperty();
|
|
|
|
ASSERT(prop != NULL);
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId id = AssignmentFeedbackId();
|
2013-06-20 13:09:43 +00:00
|
|
|
is_uninitialized_ = oracle->StoreIsUninitialized(id);
|
|
|
|
if (is_uninitialized_) return;
|
2012-08-06 14:13:09 +00:00
|
|
|
is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id);
|
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();
|
2013-06-24 10:37:59 +00:00
|
|
|
ASSERT(lit_key != NULL && lit_key->value()->IsString());
|
|
|
|
Handle<String> name = Handle<String>::cast(lit_key->value());
|
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.
|
2012-08-06 14:13:09 +00:00
|
|
|
receiver_types_.Add(oracle->StoreMonomorphicReceiverType(id), zone);
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode_ = oracle->GetStoreMode(id);
|
2013-07-09 08:22:41 +00:00
|
|
|
} else if (oracle->StoreIsKeyedPolymorphic(id)) {
|
2012-06-11 12:42:31 +00:00
|
|
|
receiver_types_.Reserve(kMaxKeyedPolymorphism, zone);
|
2012-08-06 14:13:09 +00:00
|
|
|
oracle->CollectKeyedReceiverTypes(id, &receiver_types_);
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode_ = oracle->GetStoreMode(id);
|
2011-04-07 09:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle,
|
|
|
|
Zone* zone) {
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId id = CountStoreFeedbackId();
|
|
|
|
is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id);
|
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.
|
2012-08-06 14:13:09 +00:00
|
|
|
receiver_types_.Add(
|
|
|
|
oracle->StoreMonomorphicReceiverType(id), zone);
|
2013-07-09 08:22:41 +00:00
|
|
|
} else if (oracle->StoreIsKeyedPolymorphic(id)) {
|
2012-06-11 12:42:31 +00:00
|
|
|
receiver_types_.Reserve(kMaxKeyedPolymorphism, zone);
|
2012-08-06 14:13:09 +00:00
|
|
|
oracle->CollectKeyedReceiverTypes(id, &receiver_types_);
|
2013-07-09 08:22:41 +00:00
|
|
|
} else {
|
|
|
|
oracle->CollectPolymorphicStoreReceiverTypes(id, &receiver_types_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode_ = oracle->GetStoreMode(id);
|
2013-05-27 13:59:20 +00:00
|
|
|
type_ = oracle->IncrementType(this);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
|
2013-06-12 17:20:37 +00:00
|
|
|
compare_type_ = oracle->ClauseType(CompareId());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
2013-04-09 16:38:51 +00:00
|
|
|
// If a dictionary map is found in the prototype chain before the actual
|
|
|
|
// target, a new target can always appear. In that case, bail out.
|
|
|
|
// TODO(verwaest): Alternatively a runtime negative lookup on the normal
|
|
|
|
// receiver or prototype could be added.
|
|
|
|
if (type->is_dictionary_map()) return false;
|
2012-07-05 13:54:20 +00:00
|
|
|
type->LookupDescriptor(NULL, *name, &lookup);
|
2012-03-02 14:03:59 +00:00
|
|
|
if (lookup.IsFound()) {
|
|
|
|
switch (lookup.type()) {
|
2013-07-24 12:34:50 +00:00
|
|
|
case CONSTANT: {
|
2012-03-02 14:03:59 +00:00
|
|
|
// We surely know the target for a constant function.
|
2013-07-24 12:34:50 +00:00
|
|
|
Handle<Object> constant(lookup.GetConstantFromMap(*type),
|
|
|
|
type->GetIsolate());
|
|
|
|
if (constant->IsJSFunction()) {
|
|
|
|
target_ = Handle<JSFunction>::cast(constant);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Fall through.
|
|
|
|
}
|
2012-03-02 14:03:59 +00:00
|
|
|
case NORMAL:
|
|
|
|
case FIELD:
|
|
|
|
case CALLBACKS:
|
|
|
|
case HANDLER:
|
|
|
|
case INTERCEPTOR:
|
|
|
|
// We don't know the target.
|
|
|
|
return false;
|
2012-07-05 13:54:20 +00:00
|
|
|
case TRANSITION:
|
2012-06-25 13:10:54 +00:00
|
|
|
case NONEXISTENT:
|
|
|
|
UNREACHABLE();
|
|
|
|
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();
|
2013-06-12 15:03:44 +00:00
|
|
|
cell_ = Handle<Cell>::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);
|
2013-06-12 15:03:44 +00:00
|
|
|
cell_ = Handle<Cell>(global->GetPropertyCell(lookup));
|
2011-04-01 11:54:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
Handle<JSObject> Call::GetPrototypeForPrimitiveCheck(
|
|
|
|
CheckType check, Isolate* isolate) {
|
|
|
|
v8::internal::Context* native_context = isolate->context()->native_context();
|
|
|
|
JSFunction* function = NULL;
|
|
|
|
switch (check) {
|
|
|
|
case RECEIVER_MAP_CHECK:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
case STRING_CHECK:
|
|
|
|
function = native_context->string_function();
|
|
|
|
break;
|
|
|
|
case SYMBOL_CHECK:
|
|
|
|
function = native_context->symbol_function();
|
|
|
|
break;
|
|
|
|
case NUMBER_CHECK:
|
|
|
|
function = native_context->number_function();
|
|
|
|
break;
|
|
|
|
case BOOLEAN_CHECK:
|
|
|
|
function = native_context->boolean_function();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ASSERT(function != NULL);
|
|
|
|
return Handle<JSObject>(JSObject::cast(function->instance_prototype()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2013-06-24 10:37:59 +00:00
|
|
|
ASSERT(key != NULL && key->value()->IsString());
|
|
|
|
Handle<String> name = Handle<String>::cast(key->value());
|
2013-09-06 11:32:46 +00:00
|
|
|
check_type_ = oracle->GetCallCheckType(this);
|
2011-09-27 11:42:02 +00:00
|
|
|
receiver_types_.Clear();
|
2013-09-06 11:32:46 +00:00
|
|
|
if (check_type_ == RECEIVER_MAP_CHECK) {
|
|
|
|
oracle->CallReceiverTypes(this, name, call_kind, &receiver_types_);
|
|
|
|
is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0;
|
|
|
|
} else {
|
|
|
|
holder_ = GetPrototypeForPrimitiveCheck(check_type_, oracle->isolate());
|
|
|
|
receiver_types_.Add(handle(holder_->map()), oracle->zone());
|
|
|
|
}
|
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
|
|
|
if (is_monomorphic_) {
|
2013-09-06 11:32:46 +00:00
|
|
|
Handle<Map> map = receiver_types_.first();
|
2011-09-27 11:42:02 +00:00
|
|
|
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) {
|
2013-06-07 13:21:20 +00:00
|
|
|
allocation_info_cell_ = oracle->GetCallNewAllocationInfoCell(this);
|
2012-02-28 09:05:55 +00:00
|
|
|
is_monomorphic_ = oracle->CallNewIsMonomorphic(this);
|
|
|
|
if (is_monomorphic_) {
|
|
|
|
target_ = oracle->GetCallNewTarget(this);
|
2013-06-07 13:21:20 +00:00
|
|
|
Object* value = allocation_info_cell_->value();
|
2013-07-05 10:34:02 +00:00
|
|
|
ASSERT(!value->IsTheHole());
|
2013-07-08 10:02:16 +00:00
|
|
|
if (value->IsAllocationSite()) {
|
|
|
|
AllocationSite* site = AllocationSite::cast(value);
|
2013-07-08 15:00:12 +00:00
|
|
|
elements_kind_ = site->GetElementsKind();
|
2013-06-07 13:21:20 +00:00
|
|
|
}
|
2012-02-28 09:05:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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++) {
|
2013-08-30 10:51:37 +00:00
|
|
|
Statement* stmt = statements->at(i);
|
|
|
|
Visit(stmt);
|
|
|
|
if (stmt->IsJump()) break;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() {
|
2013-06-06 13:28:22 +00:00
|
|
|
return assertion_type() == RegExpAssertion::START_OF_INPUT;
|
2009-01-23 07:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
bool RegExpAssertion::IsAnchoredAtEnd() {
|
2013-06-06 13:28:22 +00:00
|
|
|
return assertion_type() == RegExpAssertion::END_OF_INPUT;
|
2010-10-19 14:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpUnparser V8_FINAL : public RegExpVisitor {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
2012-06-11 12:42:31 +00:00
|
|
|
explicit RegExpUnparser(Zone* zone);
|
2008-11-25 11:07:48 +00:00
|
|
|
void VisitCharacterRange(CharacterRange that);
|
2011-09-09 22:39:47 +00:00
|
|
|
SmartArrayPointer<const char> ToString() { return stream_.ToCString(); }
|
2013-08-20 11:10:24 +00:00
|
|
|
#define MAKE_CASE(Name) virtual void* Visit##Name(RegExp##Name*, \
|
|
|
|
void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
|
|
|
|
#undef MAKE_CASE
|
|
|
|
private:
|
|
|
|
StringStream* stream() { return &stream_; }
|
|
|
|
HeapStringAllocator alloc_;
|
|
|
|
StringStream stream_;
|
2012-06-11 12:42:31 +00:00
|
|
|
Zone* zone_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
RegExpUnparser::RegExpUnparser(Zone* zone) : stream_(&alloc_), zone_(zone) {
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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("[");
|
2012-06-11 12:42:31 +00:00
|
|
|
for (int i = 0; i < that->ranges(zone_)->length(); i++) {
|
2008-11-25 11:07:48 +00:00
|
|
|
if (i > 0) stream()->Add(" ");
|
2012-06-11 12:42:31 +00:00
|
|
|
VisitCharacterRange(that->ranges(zone_)->at(i));
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
stream()->Add("]");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) {
|
2013-06-06 13:28:22 +00:00
|
|
|
switch (that->assertion_type()) {
|
2008-11-25 11:07:48 +00:00
|
|
|
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) {
|
2013-08-23 11:06:16 +00:00
|
|
|
that->elements()->at(0).tree()->Accept(this, data);
|
2008-11-25 11:07:48 +00:00
|
|
|
} else {
|
|
|
|
stream()->Add("(!");
|
|
|
|
for (int i = 0; i < that->elements()->length(); i++) {
|
|
|
|
stream()->Add(" ");
|
2013-08-23 11:06:16 +00:00
|
|
|
that->elements()->at(i).tree()->Accept(this, data);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
SmartArrayPointer<const char> RegExpTree::ToString(Zone* zone) {
|
|
|
|
RegExpUnparser unparser(zone);
|
2008-11-25 11:07:48 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-08 12:18:08 +00:00
|
|
|
static int IncreaseBy(int previous, int increase) {
|
|
|
|
if (RegExpTree::kInfinity - previous < increase) {
|
|
|
|
return RegExpTree::kInfinity;
|
|
|
|
} else {
|
|
|
|
return previous + increase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-17 10:59:14 +00:00
|
|
|
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);
|
2012-05-08 12:18:08 +00:00
|
|
|
int node_min_match = node->min_match();
|
|
|
|
min_match_ = IncreaseBy(min_match_, node_min_match);
|
2008-12-17 10:59:14 +00:00
|
|
|
int node_max_match = node->max_match();
|
2012-05-08 12:18:08 +00:00
|
|
|
max_match_ = IncreaseBy(max_match_, node_max_match);
|
2008-12-17 10:59:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
2013-06-12 17:20:37 +00:00
|
|
|
compare_type_(Type::None(), isolate),
|
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
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
#define REGULAR_NODE(NodeType) \
|
2012-02-08 09:56:33 +00:00
|
|
|
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
|
|
|
|
increase_node_count(); \
|
|
|
|
}
|
2012-04-16 14:43:27 +00:00
|
|
|
#define DONT_OPTIMIZE_NODE(NodeType) \
|
|
|
|
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
|
|
|
|
increase_node_count(); \
|
2013-09-05 13:20:51 +00:00
|
|
|
set_dont_optimize_reason(k##NodeType); \
|
2012-04-16 14:43:27 +00:00
|
|
|
add_flag(kDontInline); \
|
|
|
|
add_flag(kDontSelfOptimize); \
|
|
|
|
}
|
|
|
|
#define DONT_SELFOPTIMIZE_NODE(NodeType) \
|
|
|
|
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
|
|
|
|
increase_node_count(); \
|
|
|
|
add_flag(kDontSelfOptimize); \
|
|
|
|
}
|
2012-07-09 08:59:03 +00:00
|
|
|
#define DONT_CACHE_NODE(NodeType) \
|
|
|
|
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
|
|
|
|
increase_node_count(); \
|
2013-09-05 13:20:51 +00:00
|
|
|
set_dont_optimize_reason(k##NodeType); \
|
2012-07-09 08:59:03 +00:00
|
|
|
add_flag(kDontInline); \
|
|
|
|
add_flag(kDontSelfOptimize); \
|
|
|
|
add_flag(kDontCache); \
|
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
REGULAR_NODE(VariableDeclaration)
|
|
|
|
REGULAR_NODE(FunctionDeclaration)
|
|
|
|
REGULAR_NODE(Block)
|
|
|
|
REGULAR_NODE(ExpressionStatement)
|
|
|
|
REGULAR_NODE(EmptyStatement)
|
|
|
|
REGULAR_NODE(IfStatement)
|
|
|
|
REGULAR_NODE(ContinueStatement)
|
|
|
|
REGULAR_NODE(BreakStatement)
|
|
|
|
REGULAR_NODE(ReturnStatement)
|
2012-04-18 11:58:13 +00:00
|
|
|
REGULAR_NODE(SwitchStatement)
|
2012-04-16 14:43:27 +00:00
|
|
|
REGULAR_NODE(Conditional)
|
|
|
|
REGULAR_NODE(Literal)
|
2013-03-14 15:15:37 +00:00
|
|
|
REGULAR_NODE(ArrayLiteral)
|
2012-04-16 14:43:27 +00:00
|
|
|
REGULAR_NODE(ObjectLiteral)
|
2012-06-27 11:49:37 +00:00
|
|
|
REGULAR_NODE(RegExpLiteral)
|
2013-03-14 14:29:10 +00:00
|
|
|
REGULAR_NODE(FunctionLiteral)
|
2012-04-16 14:43:27 +00:00
|
|
|
REGULAR_NODE(Assignment)
|
|
|
|
REGULAR_NODE(Throw)
|
|
|
|
REGULAR_NODE(Property)
|
|
|
|
REGULAR_NODE(UnaryOperation)
|
|
|
|
REGULAR_NODE(CountOperation)
|
|
|
|
REGULAR_NODE(BinaryOperation)
|
|
|
|
REGULAR_NODE(CompareOperation)
|
|
|
|
REGULAR_NODE(ThisFunction)
|
|
|
|
REGULAR_NODE(Call)
|
|
|
|
REGULAR_NODE(CallNew)
|
|
|
|
// In theory, for VariableProxy we'd have to add:
|
|
|
|
// if (node->var()->IsLookupSlot()) add_flag(kDontInline);
|
|
|
|
// But node->var() is usually not bound yet at VariableProxy creation time, and
|
|
|
|
// LOOKUP variables only result from constructs that cannot be inlined anyway.
|
|
|
|
REGULAR_NODE(VariableProxy)
|
|
|
|
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
// We currently do not optimize any modules.
|
2012-04-16 14:43:27 +00:00
|
|
|
DONT_OPTIMIZE_NODE(ModuleDeclaration)
|
|
|
|
DONT_OPTIMIZE_NODE(ImportDeclaration)
|
|
|
|
DONT_OPTIMIZE_NODE(ExportDeclaration)
|
|
|
|
DONT_OPTIMIZE_NODE(ModuleVariable)
|
|
|
|
DONT_OPTIMIZE_NODE(ModulePath)
|
|
|
|
DONT_OPTIMIZE_NODE(ModuleUrl)
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
DONT_OPTIMIZE_NODE(ModuleStatement)
|
2013-04-02 17:34:59 +00:00
|
|
|
DONT_OPTIMIZE_NODE(Yield)
|
2012-04-16 14:43:27 +00:00
|
|
|
DONT_OPTIMIZE_NODE(WithStatement)
|
|
|
|
DONT_OPTIMIZE_NODE(TryCatchStatement)
|
|
|
|
DONT_OPTIMIZE_NODE(TryFinallyStatement)
|
|
|
|
DONT_OPTIMIZE_NODE(DebuggerStatement)
|
|
|
|
DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral)
|
|
|
|
|
|
|
|
DONT_SELFOPTIMIZE_NODE(DoWhileStatement)
|
|
|
|
DONT_SELFOPTIMIZE_NODE(WhileStatement)
|
|
|
|
DONT_SELFOPTIMIZE_NODE(ForStatement)
|
|
|
|
DONT_SELFOPTIMIZE_NODE(ForInStatement)
|
2013-06-06 14:38:26 +00:00
|
|
|
DONT_SELFOPTIMIZE_NODE(ForOfStatement)
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2012-07-09 08:59:03 +00:00
|
|
|
DONT_CACHE_NODE(ModuleLiteral)
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
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 &&
|
2013-01-09 10:30:54 +00:00
|
|
|
(node->name()->IsOneByteEqualTo(
|
|
|
|
STATIC_ASCII_VECTOR("_ArgumentsLength")) ||
|
|
|
|
node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) {
|
2012-02-08 09:56:33 +00:00
|
|
|
// 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-04-16 14:43:27 +00:00
|
|
|
#undef REGULAR_NODE
|
|
|
|
#undef DONT_OPTIMIZE_NODE
|
|
|
|
#undef DONT_SELFOPTIMIZE_NODE
|
2012-07-09 08:59:03 +00:00
|
|
|
#undef DONT_CACHE_NODE
|
2012-04-16 14:43:27 +00:00
|
|
|
|
2012-03-09 08:34:35 +00:00
|
|
|
|
|
|
|
Handle<String> Literal::ToString() {
|
2013-06-24 10:37:59 +00:00
|
|
|
if (value_->IsString()) return Handle<String>::cast(value_);
|
|
|
|
ASSERT(value_->IsNumber());
|
2012-03-09 08:34:35 +00:00
|
|
|
char arr[100];
|
|
|
|
Vector<char> buffer(arr, ARRAY_SIZE(arr));
|
|
|
|
const char* str;
|
2013-06-24 10:37:59 +00:00
|
|
|
if (value_->IsSmi()) {
|
2012-03-09 08:34:35 +00:00
|
|
|
// Optimization only, the heap number case would subsume this.
|
2013-06-24 10:37:59 +00:00
|
|
|
OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value());
|
2012-03-09 08:34:35 +00:00
|
|
|
str = arr;
|
|
|
|
} else {
|
2013-06-24 10:37:59 +00:00
|
|
|
str = DoubleToCString(value_->Number(), buffer);
|
2012-03-09 08:34:35 +00:00
|
|
|
}
|
2013-09-02 09:27:27 +00:00
|
|
|
return isolate_->factory()->NewStringFromAscii(CStrVector(str));
|
2012-03-09 08:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|