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.
|
|
|
|
|
|
|
|
#ifndef V8_AST_H_
|
|
|
|
#define V8_AST_H_
|
|
|
|
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "assembler.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "factory.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "isolate.h"
|
2009-10-15 15:01:36 +00:00
|
|
|
#include "jsregexp.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "list-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "runtime.h"
|
2011-08-22 14:23:37 +00:00
|
|
|
#include "small-pointer-list.h"
|
2012-07-19 18:58:23 +00:00
|
|
|
#include "smart-pointers.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "token.h"
|
2012-02-08 09:56:33 +00:00
|
|
|
#include "utils.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "variables.h"
|
2012-03-08 13:03:07 +00:00
|
|
|
#include "interface.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
#include "zone-inl.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
|
|
|
|
|
|
|
// The abstract syntax tree is an intermediate, light-weight
|
|
|
|
// representation of the parsed JavaScript code suitable for
|
|
|
|
// compilation to native code.
|
|
|
|
|
|
|
|
// Nodes are allocated in a separate zone, which allows faster
|
|
|
|
// allocation and constant-time deallocation of the entire syntax
|
|
|
|
// tree.
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Nodes of the abstract syntax tree. Only concrete classes are
|
|
|
|
// enumerated here.
|
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
#define DECLARATION_NODE_LIST(V) \
|
|
|
|
V(VariableDeclaration) \
|
2012-02-28 10:12:39 +00:00
|
|
|
V(FunctionDeclaration) \
|
2012-02-09 13:40:41 +00:00
|
|
|
V(ModuleDeclaration) \
|
2012-02-29 12:12:52 +00:00
|
|
|
V(ImportDeclaration) \
|
|
|
|
V(ExportDeclaration) \
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
#define MODULE_NODE_LIST(V) \
|
|
|
|
V(ModuleLiteral) \
|
|
|
|
V(ModuleVariable) \
|
|
|
|
V(ModulePath) \
|
|
|
|
V(ModuleUrl)
|
2012-02-09 13:39:26 +00:00
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
#define STATEMENT_NODE_LIST(V) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(Block) \
|
|
|
|
V(ExpressionStatement) \
|
|
|
|
V(EmptyStatement) \
|
|
|
|
V(IfStatement) \
|
|
|
|
V(ContinueStatement) \
|
|
|
|
V(BreakStatement) \
|
|
|
|
V(ReturnStatement) \
|
2011-08-12 10:52:49 +00:00
|
|
|
V(WithStatement) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(SwitchStatement) \
|
2009-10-12 13:14:06 +00:00
|
|
|
V(DoWhileStatement) \
|
|
|
|
V(WhileStatement) \
|
|
|
|
V(ForStatement) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(ForInStatement) \
|
2009-10-12 13:14:06 +00:00
|
|
|
V(TryCatchStatement) \
|
|
|
|
V(TryFinallyStatement) \
|
2009-07-30 11:53:29 +00:00
|
|
|
V(DebuggerStatement)
|
|
|
|
|
|
|
|
#define EXPRESSION_NODE_LIST(V) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(FunctionLiteral) \
|
2010-03-23 06:04:44 +00:00
|
|
|
V(SharedFunctionInfoLiteral) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(Conditional) \
|
|
|
|
V(VariableProxy) \
|
|
|
|
V(Literal) \
|
|
|
|
V(RegExpLiteral) \
|
|
|
|
V(ObjectLiteral) \
|
|
|
|
V(ArrayLiteral) \
|
|
|
|
V(Assignment) \
|
|
|
|
V(Throw) \
|
|
|
|
V(Property) \
|
|
|
|
V(Call) \
|
|
|
|
V(CallNew) \
|
|
|
|
V(CallRuntime) \
|
|
|
|
V(UnaryOperation) \
|
|
|
|
V(CountOperation) \
|
|
|
|
V(BinaryOperation) \
|
|
|
|
V(CompareOperation) \
|
|
|
|
V(ThisFunction)
|
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
#define AST_NODE_LIST(V) \
|
2012-02-09 13:39:26 +00:00
|
|
|
DECLARATION_NODE_LIST(V) \
|
2012-02-09 13:40:41 +00:00
|
|
|
MODULE_NODE_LIST(V) \
|
2009-07-30 11:53:29 +00:00
|
|
|
STATEMENT_NODE_LIST(V) \
|
|
|
|
EXPRESSION_NODE_LIST(V)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// Forward declarations
|
2012-02-08 09:56:33 +00:00
|
|
|
class AstConstructionVisitor;
|
|
|
|
template<class> class AstNodeFactory;
|
2012-01-25 16:31:25 +00:00
|
|
|
class AstVisitor;
|
2012-02-09 13:39:26 +00:00
|
|
|
class Declaration;
|
2012-02-09 13:40:41 +00:00
|
|
|
class Module;
|
2012-01-25 16:31:25 +00:00
|
|
|
class BreakableStatement;
|
|
|
|
class Expression;
|
|
|
|
class IterationStatement;
|
2010-12-07 11:31:57 +00:00
|
|
|
class MaterializedLiteral;
|
2012-01-25 16:31:25 +00:00
|
|
|
class Statement;
|
2010-12-07 11:31:57 +00:00
|
|
|
class TargetCollector;
|
|
|
|
class TypeFeedbackOracle;
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2012-01-25 16:31:25 +00:00
|
|
|
class RegExpAlternative;
|
|
|
|
class RegExpAssertion;
|
|
|
|
class RegExpAtom;
|
|
|
|
class RegExpBackReference;
|
|
|
|
class RegExpCapture;
|
|
|
|
class RegExpCharacterClass;
|
|
|
|
class RegExpCompiler;
|
|
|
|
class RegExpDisjunction;
|
|
|
|
class RegExpEmpty;
|
|
|
|
class RegExpLookahead;
|
|
|
|
class RegExpQuantifier;
|
|
|
|
class RegExpText;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#define DEF_FORWARD_DECLARATION(type) class type;
|
2009-07-30 12:09:05 +00:00
|
|
|
AST_NODE_LIST(DEF_FORWARD_DECLARATION)
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef DEF_FORWARD_DECLARATION
|
|
|
|
|
|
|
|
|
|
|
|
// Typedef only introduced to avoid unreadable code.
|
|
|
|
// Please do appreciate the required space in "> >".
|
|
|
|
typedef ZoneList<Handle<String> > ZoneStringList;
|
2009-08-19 07:30:20 +00:00
|
|
|
typedef ZoneList<Handle<Object> > ZoneObjectList;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
#define DECLARE_NODE_TYPE(type) \
|
|
|
|
virtual void Accept(AstVisitor* v); \
|
2012-08-29 09:33:14 +00:00
|
|
|
virtual AstNode::Type node_type() const { return AstNode::k##type; } \
|
|
|
|
template<class> friend class AstNodeFactory;
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum AstPropertiesFlag {
|
|
|
|
kDontInline,
|
|
|
|
kDontOptimize,
|
|
|
|
kDontSelfOptimize,
|
2012-07-09 08:59:03 +00:00
|
|
|
kDontSoftInline,
|
|
|
|
kDontCache
|
2012-02-08 09:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AstProperties BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
class Flags : public EnumSet<AstPropertiesFlag, int> {};
|
|
|
|
|
|
|
|
AstProperties() : node_count_(0) { }
|
|
|
|
|
|
|
|
Flags* flags() { return &flags_; }
|
|
|
|
int node_count() { return node_count_; }
|
|
|
|
void add_node_count(int count) { node_count_ += count; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Flags flags_;
|
|
|
|
int node_count_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
class AstNode: public ZoneObject {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
#define DECLARE_TYPE_ENUM(type) k##type,
|
|
|
|
enum Type {
|
|
|
|
AST_NODE_LIST(DECLARE_TYPE_ENUM)
|
|
|
|
kInvalid = -1
|
|
|
|
};
|
|
|
|
#undef DECLARE_TYPE_ENUM
|
|
|
|
|
2011-07-15 16:57:35 +00:00
|
|
|
void* operator new(size_t size, Zone* zone) {
|
2011-07-15 17:01:54 +00:00
|
|
|
return zone->New(static_cast<int>(size));
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
AstNode() { }
|
2011-07-15 16:57:35 +00:00
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
virtual ~AstNode() { }
|
2010-09-29 07:51:47 +00:00
|
|
|
|
2008-11-27 13:55:06 +00:00
|
|
|
virtual void Accept(AstVisitor* v) = 0;
|
2012-07-20 09:39:27 +00:00
|
|
|
virtual Type node_type() const = 0;
|
2010-09-29 07:51:47 +00:00
|
|
|
|
|
|
|
// Type testing & conversion functions overridden by concrete subclasses.
|
|
|
|
#define DECLARE_NODE_FUNCTIONS(type) \
|
2011-10-31 11:11:26 +00:00
|
|
|
bool Is##type() { return node_type() == AstNode::k##type; } \
|
|
|
|
type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; }
|
2010-09-29 07:51:47 +00:00
|
|
|
AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
|
|
|
|
#undef DECLARE_NODE_FUNCTIONS
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
virtual TargetCollector* AsTargetCollector() { return NULL; }
|
2008-07-03 15:10:15 +00:00
|
|
|
virtual BreakableStatement* AsBreakableStatement() { return NULL; }
|
|
|
|
virtual IterationStatement* AsIterationStatement() { return NULL; }
|
2009-03-23 07:27:47 +00:00
|
|
|
virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
protected:
|
2012-02-08 09:56:33 +00:00
|
|
|
static int GetNextId(Isolate* isolate) {
|
2011-07-18 17:32:41 +00:00
|
|
|
return ReserveIdRange(isolate, 1);
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
static int ReserveIdRange(Isolate* isolate, int n) {
|
|
|
|
int tmp = isolate->ast_node_id();
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->set_ast_node_id(tmp + n);
|
2010-12-07 11:31:57 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
// Some nodes re-use bailout IDs for type feedback.
|
|
|
|
static TypeFeedbackId reuse(BailoutId id) {
|
|
|
|
return TypeFeedbackId(id.ToInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-15 16:57:35 +00:00
|
|
|
private:
|
|
|
|
// Hidden to prevent accidental usage. It would have to load the
|
|
|
|
// current zone from the TLS.
|
|
|
|
void* operator new(size_t size);
|
|
|
|
|
2011-03-09 12:06:54 +00:00
|
|
|
friend class CaseClause; // Generates AST IDs.
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
class Statement: public AstNode {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2009-09-28 12:01:05 +00:00
|
|
|
Statement() : statement_pos_(RelocInfo::kNoPosition) {}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsEmpty() { return AsEmptyStatement() != NULL; }
|
2009-09-28 12:01:05 +00:00
|
|
|
|
|
|
|
void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
|
|
|
|
int statement_pos() const { return statement_pos_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int statement_pos_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
class SmallMapList {
|
|
|
|
public:
|
|
|
|
SmallMapList() {}
|
2012-06-11 12:42:31 +00:00
|
|
|
SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
|
2011-08-22 14:23:37 +00:00
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
|
2011-08-22 14:23:37 +00:00
|
|
|
void Clear() { list_.Clear(); }
|
2012-03-23 16:37:54 +00:00
|
|
|
void Sort() { list_.Sort(); }
|
2011-08-22 14:23:37 +00:00
|
|
|
|
|
|
|
bool is_empty() const { return list_.is_empty(); }
|
|
|
|
int length() const { return list_.length(); }
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void Add(Handle<Map> handle, Zone* zone) {
|
|
|
|
list_.Add(handle.location(), zone);
|
2011-08-22 14:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Map> at(int i) const {
|
|
|
|
return Handle<Map>(list_.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Map> first() const { return at(0); }
|
|
|
|
Handle<Map> last() const { return at(length() - 1); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// The list stores pointers to Map*, that is Map**, so it's GC safe.
|
|
|
|
SmallPointerList<Map*> list_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SmallMapList);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
class Expression: public AstNode {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-12-07 11:31:57 +00:00
|
|
|
enum Context {
|
|
|
|
// Not assigned a context yet, or else will not be visited during
|
|
|
|
// code generation.
|
|
|
|
kUninitialized,
|
|
|
|
// Evaluated for its side effects.
|
|
|
|
kEffect,
|
|
|
|
// Evaluated for its value (and side effects).
|
|
|
|
kValue,
|
|
|
|
// Evaluated for control flow (and side effects).
|
|
|
|
kTest
|
|
|
|
};
|
|
|
|
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const {
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
virtual bool IsValidLeftHandSide() { return false; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Helpers for ToBoolean conversion.
|
|
|
|
virtual bool ToBooleanIsTrue() { return false; }
|
|
|
|
virtual bool ToBooleanIsFalse() { return false; }
|
|
|
|
|
2010-01-12 08:48:26 +00:00
|
|
|
// Symbols that cannot be parsed as array indices are considered property
|
|
|
|
// names. We do not treat symbols that can be array indexes as property
|
|
|
|
// names because [] for string objects is handled only by keyed ICs.
|
|
|
|
virtual bool IsPropertyName() { return false; }
|
|
|
|
|
2010-08-25 11:10:05 +00:00
|
|
|
// True iff the result can be safely overwritten (to avoid allocation).
|
|
|
|
// False for operations that can return one of their operands.
|
|
|
|
virtual bool ResultOverwriteAllowed() { return false; }
|
|
|
|
|
2010-08-26 08:50:38 +00:00
|
|
|
// True iff the expression is a literal represented as a smi.
|
2011-10-31 11:11:26 +00:00
|
|
|
bool IsSmiLiteral();
|
2010-08-26 08:50:38 +00:00
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
// True iff the expression is a string literal.
|
2011-10-31 11:11:26 +00:00
|
|
|
bool IsStringLiteral();
|
2011-09-19 14:50:33 +00:00
|
|
|
|
|
|
|
// True iff the expression is the null literal.
|
2011-10-31 11:11:26 +00:00
|
|
|
bool IsNullLiteral();
|
2011-09-19 14:50:33 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information for assignments and properties.
|
|
|
|
virtual bool IsMonomorphic() {
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-22 14:23:37 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() {
|
2010-12-07 11:31:57 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-22 14:23:37 +00:00
|
|
|
Handle<Map> GetMonomorphicReceiverType() {
|
|
|
|
ASSERT(IsMonomorphic());
|
|
|
|
SmallMapList* types = GetReceiverTypes();
|
|
|
|
ASSERT(types != NULL && types->length() == 1);
|
|
|
|
return types->at(0);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId id() const { return id_; }
|
|
|
|
TypeFeedbackId test_id() const { return test_id_; }
|
2011-05-31 09:34:37 +00:00
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
protected:
|
|
|
|
explicit Expression(Isolate* isolate)
|
|
|
|
: id_(GetNextId(isolate)),
|
|
|
|
test_id_(GetNextId(isolate)) {}
|
|
|
|
|
2008-10-28 22:33:00 +00:00
|
|
|
private:
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId id_;
|
|
|
|
const TypeFeedbackId test_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BreakableStatement: public Statement {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
TARGET_FOR_ANONYMOUS,
|
|
|
|
TARGET_FOR_NAMED_ONLY
|
|
|
|
};
|
|
|
|
|
|
|
|
// The labels associated with this statement. May be NULL;
|
|
|
|
// if it is != NULL, guaranteed to contain at least one entry.
|
|
|
|
ZoneStringList* labels() const { return labels_; }
|
|
|
|
|
|
|
|
// Type testing & conversion.
|
|
|
|
virtual BreakableStatement* AsBreakableStatement() { return this; }
|
|
|
|
|
|
|
|
// Code generation
|
2011-04-07 14:42:37 +00:00
|
|
|
Label* break_target() { return &break_target_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Testers.
|
|
|
|
bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId EntryId() const { return entry_id_; }
|
|
|
|
BailoutId ExitId() const { return exit_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
protected:
|
2011-11-09 11:32:54 +00:00
|
|
|
BreakableStatement(Isolate* isolate, ZoneStringList* labels, Type type)
|
|
|
|
: labels_(labels),
|
|
|
|
type_(type),
|
|
|
|
entry_id_(GetNextId(isolate)),
|
|
|
|
exit_id_(GetNextId(isolate)) {
|
|
|
|
ASSERT(labels == NULL || labels->length() > 0);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ZoneStringList* labels_;
|
|
|
|
Type type_;
|
2011-04-07 14:42:37 +00:00
|
|
|
Label break_target_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId entry_id_;
|
|
|
|
const BailoutId exit_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Block: public BreakableStatement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Block)
|
2010-03-22 13:21:32 +00:00
|
|
|
|
2012-06-04 14:42:58 +00:00
|
|
|
void AddStatement(Statement* statement, Zone* zone) {
|
|
|
|
statements_.Add(statement, zone);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
ZoneList<Statement*>* statements() { return &statements_; }
|
2010-09-24 08:25:31 +00:00
|
|
|
bool is_initializer_block() const { return is_initializer_block_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
Scope* scope() const { return scope_; }
|
|
|
|
void set_scope(Scope* scope) { scope_ = scope; }
|
2011-08-11 16:29:28 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
Block(Isolate* isolate,
|
|
|
|
ZoneStringList* labels,
|
|
|
|
int capacity,
|
2012-06-11 12:42:31 +00:00
|
|
|
bool is_initializer_block,
|
|
|
|
Zone* zone)
|
2012-02-08 09:56:33 +00:00
|
|
|
: BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY),
|
2012-06-11 12:42:31 +00:00
|
|
|
statements_(capacity, zone),
|
2012-02-08 09:56:33 +00:00
|
|
|
is_initializer_block_(is_initializer_block),
|
2012-04-16 14:43:27 +00:00
|
|
|
scope_(NULL) {
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
ZoneList<Statement*> statements_;
|
|
|
|
bool is_initializer_block_;
|
2012-04-16 14:43:27 +00:00
|
|
|
Scope* scope_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-30 11:53:29 +00:00
|
|
|
class Declaration: public AstNode {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
VariableProxy* proxy() const { return proxy_; }
|
|
|
|
VariableMode mode() const { return mode_; }
|
|
|
|
Scope* scope() const { return scope_; }
|
2012-02-28 10:12:39 +00:00
|
|
|
virtual InitializationFlag initialization() const = 0;
|
2012-02-09 13:39:26 +00:00
|
|
|
virtual bool IsInlineable() const;
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
protected:
|
2011-09-01 12:31:18 +00:00
|
|
|
Declaration(VariableProxy* proxy,
|
2011-10-11 08:41:19 +00:00
|
|
|
VariableMode mode,
|
2011-09-01 12:31:18 +00:00
|
|
|
Scope* scope)
|
2008-11-26 08:03:55 +00:00
|
|
|
: proxy_(proxy),
|
|
|
|
mode_(mode),
|
2011-09-01 12:31:18 +00:00
|
|
|
scope_(scope) {
|
2012-08-29 09:19:53 +00:00
|
|
|
ASSERT(IsDeclaredVariableMode(mode));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
VariableProxy* proxy_;
|
2011-10-11 08:41:19 +00:00
|
|
|
VariableMode mode_;
|
2011-09-01 12:31:18 +00:00
|
|
|
|
|
|
|
// Nested scope from which the declaration originated.
|
|
|
|
Scope* scope_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
class VariableDeclaration: public Declaration {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(VariableDeclaration)
|
|
|
|
|
2012-02-28 10:12:39 +00:00
|
|
|
virtual InitializationFlag initialization() const {
|
|
|
|
return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
VariableDeclaration(VariableProxy* proxy,
|
|
|
|
VariableMode mode,
|
|
|
|
Scope* scope)
|
|
|
|
: Declaration(proxy, mode, scope) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
|
2012-02-28 10:12:39 +00:00
|
|
|
class FunctionDeclaration: public Declaration {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(FunctionDeclaration)
|
|
|
|
|
|
|
|
FunctionLiteral* fun() const { return fun_; }
|
|
|
|
virtual InitializationFlag initialization() const {
|
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
2012-02-09 13:39:26 +00:00
|
|
|
virtual bool IsInlineable() const;
|
|
|
|
|
|
|
|
protected:
|
2012-02-28 10:12:39 +00:00
|
|
|
FunctionDeclaration(VariableProxy* proxy,
|
2012-02-09 13:39:26 +00:00
|
|
|
VariableMode mode,
|
|
|
|
FunctionLiteral* fun,
|
|
|
|
Scope* scope)
|
|
|
|
: Declaration(proxy, mode, scope),
|
|
|
|
fun_(fun) {
|
2012-02-28 10:12:39 +00:00
|
|
|
// At the moment there are no "const functions" in JavaScript...
|
|
|
|
ASSERT(mode == VAR || mode == LET);
|
|
|
|
ASSERT(fun != NULL);
|
2012-02-09 13:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FunctionLiteral* fun_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
class ModuleDeclaration: public Declaration {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleDeclaration)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
2012-02-28 10:12:39 +00:00
|
|
|
virtual InitializationFlag initialization() const {
|
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ModuleDeclaration(VariableProxy* proxy,
|
|
|
|
Module* module,
|
|
|
|
Scope* scope)
|
|
|
|
: Declaration(proxy, LET, scope),
|
|
|
|
module_(module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module* module_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-29 12:12:52 +00:00
|
|
|
class ImportDeclaration: public Declaration {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ImportDeclaration)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
|
|
|
virtual InitializationFlag initialization() const {
|
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ImportDeclaration(VariableProxy* proxy,
|
|
|
|
Module* module,
|
|
|
|
Scope* scope)
|
|
|
|
: Declaration(proxy, LET, scope),
|
|
|
|
module_(module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module* module_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ExportDeclaration: public Declaration {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ExportDeclaration)
|
|
|
|
|
|
|
|
virtual InitializationFlag initialization() const {
|
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-07-09 08:59:03 +00:00
|
|
|
ExportDeclaration(VariableProxy* proxy, Scope* scope)
|
|
|
|
: Declaration(proxy, LET, scope) {}
|
2012-02-29 12:12:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
class Module: public AstNode {
|
2012-03-08 13:03:07 +00:00
|
|
|
public:
|
|
|
|
Interface* interface() const { return interface_; }
|
2012-07-09 08:59:03 +00:00
|
|
|
Block* body() const { return body_; }
|
2012-03-08 13:03:07 +00:00
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
protected:
|
2012-07-09 08:59:03 +00:00
|
|
|
explicit Module(Zone* zone)
|
|
|
|
: interface_(Interface::NewModule(zone)),
|
|
|
|
body_(NULL) {}
|
|
|
|
explicit Module(Interface* interface, Block* body = NULL)
|
|
|
|
: interface_(interface),
|
|
|
|
body_(body) {}
|
2012-03-08 13:03:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Interface* interface_;
|
2012-07-09 08:59:03 +00:00
|
|
|
Block* body_;
|
2012-02-09 13:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleLiteral: public Module {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleLiteral)
|
|
|
|
|
|
|
|
protected:
|
2012-07-09 08:59:03 +00:00
|
|
|
ModuleLiteral(Block* body, Interface* interface) : Module(interface, body) {}
|
2012-02-09 13:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleVariable: public Module {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleVariable)
|
|
|
|
|
2012-02-20 14:02:59 +00:00
|
|
|
VariableProxy* proxy() const { return proxy_; }
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
protected:
|
2012-03-08 13:03:07 +00:00
|
|
|
inline explicit ModuleVariable(VariableProxy* proxy);
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
private:
|
2012-02-20 14:02:59 +00:00
|
|
|
VariableProxy* proxy_;
|
2012-02-09 13:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ModulePath: public Module {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModulePath)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
|
|
|
Handle<String> name() const { return name_; }
|
|
|
|
|
|
|
|
protected:
|
2012-06-11 12:42:31 +00:00
|
|
|
ModulePath(Module* module, Handle<String> name, Zone* zone)
|
|
|
|
: Module(zone),
|
|
|
|
module_(module),
|
2012-02-09 13:40:41 +00:00
|
|
|
name_(name) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module* module_;
|
|
|
|
Handle<String> name_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleUrl: public Module {
|
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleUrl)
|
|
|
|
|
|
|
|
Handle<String> url() const { return url_; }
|
|
|
|
|
|
|
|
protected:
|
2012-06-11 12:42:31 +00:00
|
|
|
ModuleUrl(Handle<String> url, Zone* zone)
|
|
|
|
: Module(zone), url_(url) {
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<String> url_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
class IterationStatement: public BreakableStatement {
|
|
|
|
public:
|
|
|
|
// Type testing & conversion.
|
|
|
|
virtual IterationStatement* AsIterationStatement() { return this; }
|
|
|
|
|
|
|
|
Statement* body() const { return body_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId OsrEntryId() const { return osr_entry_id_; }
|
|
|
|
virtual BailoutId ContinueId() const = 0;
|
|
|
|
virtual BailoutId StackCheckId() const = 0;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Code generation
|
2011-04-07 14:42:37 +00:00
|
|
|
Label* continue_target() { return &continue_target_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
protected:
|
2011-11-09 11:32:54 +00:00
|
|
|
IterationStatement(Isolate* isolate, ZoneStringList* labels)
|
|
|
|
: BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
|
|
|
|
body_(NULL),
|
|
|
|
osr_entry_id_(GetNextId(isolate)) {
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
void Initialize(Statement* body) {
|
|
|
|
body_ = body;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Statement* body_;
|
2011-04-07 14:42:37 +00:00
|
|
|
Label continue_target_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId osr_entry_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
class DoWhileStatement: public IterationStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(DoWhileStatement)
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void Initialize(Expression* cond, Statement* body) {
|
|
|
|
IterationStatement::Initialize(body);
|
|
|
|
cond_ = cond;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
Expression* cond() const { return cond_; }
|
|
|
|
|
2009-11-16 21:59:31 +00:00
|
|
|
// Position where condition expression starts. We need it to make
|
|
|
|
// the loop's condition a breakable location.
|
|
|
|
int condition_position() { return condition_position_; }
|
|
|
|
void set_condition_position(int pos) { condition_position_ = pos; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
virtual BailoutId ContinueId() const { return continue_id_; }
|
|
|
|
virtual BailoutId StackCheckId() const { return back_edge_id_; }
|
|
|
|
BailoutId BackEdgeId() const { return back_edge_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
DoWhileStatement(Isolate* isolate, ZoneStringList* labels)
|
|
|
|
: IterationStatement(isolate, labels),
|
|
|
|
cond_(NULL),
|
|
|
|
condition_position_(-1),
|
|
|
|
continue_id_(GetNextId(isolate)),
|
|
|
|
back_edge_id_(GetNextId(isolate)) {
|
|
|
|
}
|
2011-04-12 08:37:29 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
private:
|
|
|
|
Expression* cond_;
|
2009-11-16 21:59:31 +00:00
|
|
|
int condition_position_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId continue_id_;
|
|
|
|
const BailoutId back_edge_id_;
|
2009-10-12 13:14:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class WhileStatement: public IterationStatement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(WhileStatement)
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void Initialize(Expression* cond, Statement* body) {
|
|
|
|
IterationStatement::Initialize(body);
|
|
|
|
cond_ = cond;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expression* cond() const { return cond_; }
|
|
|
|
bool may_have_function_literal() const {
|
|
|
|
return may_have_function_literal_;
|
|
|
|
}
|
2010-08-24 07:26:49 +00:00
|
|
|
void set_may_have_function_literal(bool value) {
|
|
|
|
may_have_function_literal_ = value;
|
|
|
|
}
|
2009-10-12 13:14:06 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
virtual BailoutId ContinueId() const { return EntryId(); }
|
|
|
|
virtual BailoutId StackCheckId() const { return body_id_; }
|
|
|
|
BailoutId BodyId() const { return body_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
WhileStatement(Isolate* isolate, ZoneStringList* labels)
|
|
|
|
: IterationStatement(isolate, labels),
|
|
|
|
cond_(NULL),
|
|
|
|
may_have_function_literal_(true),
|
|
|
|
body_id_(GetNextId(isolate)) {
|
|
|
|
}
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
private:
|
|
|
|
Expression* cond_;
|
|
|
|
// True if there is a function literal subexpression in the condition.
|
|
|
|
bool may_have_function_literal_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId body_id_;
|
2009-10-12 13:14:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ForStatement: public IterationStatement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ForStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
void Initialize(Statement* init,
|
|
|
|
Expression* cond,
|
|
|
|
Statement* next,
|
|
|
|
Statement* body) {
|
|
|
|
IterationStatement::Initialize(body);
|
|
|
|
init_ = init;
|
|
|
|
cond_ = cond;
|
|
|
|
next_ = next;
|
|
|
|
}
|
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
Statement* init() const { return init_; }
|
|
|
|
Expression* cond() const { return cond_; }
|
|
|
|
Statement* next() const { return next_; }
|
2010-08-24 07:26:49 +00:00
|
|
|
|
2009-03-24 14:25:22 +00:00
|
|
|
bool may_have_function_literal() const {
|
|
|
|
return may_have_function_literal_;
|
|
|
|
}
|
2010-08-24 07:26:49 +00:00
|
|
|
void set_may_have_function_literal(bool value) {
|
|
|
|
may_have_function_literal_ = value;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
virtual BailoutId ContinueId() const { return continue_id_; }
|
|
|
|
virtual BailoutId StackCheckId() const { return body_id_; }
|
|
|
|
BailoutId BodyId() const { return body_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-03-11 10:28:40 +00:00
|
|
|
bool is_fast_smi_loop() { return loop_variable_ != NULL; }
|
|
|
|
Variable* loop_variable() { return loop_variable_; }
|
|
|
|
void set_loop_variable(Variable* var) { loop_variable_ = var; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ForStatement(Isolate* isolate, ZoneStringList* labels)
|
|
|
|
: IterationStatement(isolate, labels),
|
|
|
|
init_(NULL),
|
|
|
|
cond_(NULL),
|
|
|
|
next_(NULL),
|
|
|
|
may_have_function_literal_(true),
|
|
|
|
loop_variable_(NULL),
|
|
|
|
continue_id_(GetNextId(isolate)),
|
|
|
|
body_id_(GetNextId(isolate)) {
|
|
|
|
}
|
2010-03-11 10:28:40 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Statement* init_;
|
|
|
|
Expression* cond_;
|
|
|
|
Statement* next_;
|
2009-03-12 15:44:05 +00:00
|
|
|
// True if there is a function literal subexpression in the condition.
|
2009-03-24 14:25:22 +00:00
|
|
|
bool may_have_function_literal_;
|
2010-03-11 10:28:40 +00:00
|
|
|
Variable* loop_variable_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId continue_id_;
|
|
|
|
const BailoutId body_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ForInStatement: public IterationStatement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ForInStatement)
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Initialize(Expression* each, Expression* enumerable, Statement* body) {
|
|
|
|
IterationStatement::Initialize(body);
|
|
|
|
each_ = each;
|
|
|
|
enumerable_ = enumerable;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expression* each() const { return each_; }
|
|
|
|
Expression* enumerable() const { return enumerable_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
virtual BailoutId ContinueId() const { return EntryId(); }
|
|
|
|
virtual BailoutId StackCheckId() const { return body_id_; }
|
|
|
|
BailoutId BodyId() const { return body_id_; }
|
|
|
|
BailoutId PrepareId() const { return prepare_id_; }
|
|
|
|
|
|
|
|
TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
ForInStatement(Isolate* isolate, ZoneStringList* labels)
|
|
|
|
: IterationStatement(isolate, labels),
|
|
|
|
each_(NULL),
|
|
|
|
enumerable_(NULL),
|
2012-02-22 12:47:42 +00:00
|
|
|
body_id_(GetNextId(isolate)),
|
|
|
|
prepare_id_(GetNextId(isolate)) {
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* each_;
|
|
|
|
Expression* enumerable_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId body_id_;
|
|
|
|
const BailoutId prepare_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ExpressionStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ExpressionStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
void set_expression(Expression* e) { expression_ = e; }
|
2010-12-07 11:31:57 +00:00
|
|
|
Expression* expression() const { return expression_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
explicit ExpressionStatement(Expression* expression)
|
|
|
|
: expression_(expression) { }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ContinueStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ContinueStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
IterationStatement* target() const { return target_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit ContinueStatement(IterationStatement* target)
|
|
|
|
: target_(target) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
IterationStatement* target_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BreakStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(BreakStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
BreakableStatement* target() const { return target_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit BreakStatement(BreakableStatement* target)
|
|
|
|
: target_(target) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BreakableStatement* target_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ReturnStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ReturnStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Expression* expression() const { return expression_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit ReturnStatement(Expression* expression)
|
|
|
|
: expression_(expression) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
class WithStatement: public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2011-08-12 10:52:49 +00:00
|
|
|
DECLARE_NODE_TYPE(WithStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
Expression* expression() const { return expression_; }
|
2011-08-12 10:52:49 +00:00
|
|
|
Statement* statement() const { return statement_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
WithStatement(Expression* expression, Statement* statement)
|
|
|
|
: expression_(expression),
|
|
|
|
statement_(statement) { }
|
2008-12-18 11:28:13 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
2011-08-12 10:52:49 +00:00
|
|
|
Statement* statement_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CaseClause: public ZoneObject {
|
|
|
|
public:
|
2011-07-18 17:32:41 +00:00
|
|
|
CaseClause(Isolate* isolate,
|
|
|
|
Expression* label,
|
|
|
|
ZoneList<Statement*>* statements,
|
|
|
|
int pos);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
bool is_default() const { return label_ == NULL; }
|
|
|
|
Expression* label() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
CHECK(!is_default());
|
|
|
|
return label_;
|
|
|
|
}
|
2011-04-07 14:42:37 +00:00
|
|
|
Label* body_target() { return &body_target_; }
|
2010-09-24 08:25:31 +00:00
|
|
|
ZoneList<Statement*>* statements() const { return statements_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-04-07 09:51:25 +00:00
|
|
|
int position() const { return position_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
void set_position(int pos) { position_ = pos; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId EntryId() const { return entry_id_; }
|
2011-03-09 12:06:54 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information.
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId CompareId() { return compare_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
|
|
|
|
bool IsSmiCompare() { return compare_type_ == SMI_ONLY; }
|
2011-11-17 13:57:55 +00:00
|
|
|
bool IsSymbolCompare() { return compare_type_ == SYMBOL_ONLY; }
|
|
|
|
bool IsStringCompare() { return compare_type_ == STRING_ONLY; }
|
2010-12-07 11:31:57 +00:00
|
|
|
bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* label_;
|
2011-04-07 14:42:37 +00:00
|
|
|
Label body_target_;
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Statement*>* statements_;
|
2010-12-07 11:31:57 +00:00
|
|
|
int position_;
|
2011-11-17 13:57:55 +00:00
|
|
|
enum CompareTypeFeedback {
|
|
|
|
NONE,
|
|
|
|
SMI_ONLY,
|
|
|
|
SYMBOL_ONLY,
|
|
|
|
STRING_ONLY,
|
|
|
|
OBJECT_ONLY
|
|
|
|
};
|
2010-12-07 11:31:57 +00:00
|
|
|
CompareTypeFeedback compare_type_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const TypeFeedbackId compare_id_;
|
|
|
|
const BailoutId entry_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SwitchStatement: public BreakableStatement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(SwitchStatement)
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
|
|
|
|
tag_ = tag;
|
|
|
|
cases_ = cases;
|
|
|
|
}
|
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
Expression* tag() const { return tag_; }
|
|
|
|
ZoneList<CaseClause*>* cases() const { return cases_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SwitchStatement(Isolate* isolate, ZoneStringList* labels)
|
|
|
|
: BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
|
|
|
|
tag_(NULL),
|
|
|
|
cases_(NULL) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Expression* tag_;
|
|
|
|
ZoneList<CaseClause*>* cases_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If-statements always have non-null references to their then- and
|
|
|
|
// else-parts. When parsing if-statements with no explicit else-part,
|
|
|
|
// the parser implicitly creates an empty statement. Use the
|
|
|
|
// HasThenStatement() and HasElseStatement() functions to check if a
|
|
|
|
// given if-statement has a then- or an else-part containing code.
|
|
|
|
class IfStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(IfStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
|
|
|
|
bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
|
|
|
|
|
|
|
|
Expression* condition() const { return condition_; }
|
|
|
|
Statement* then_statement() const { return then_statement_; }
|
|
|
|
Statement* else_statement() const { return else_statement_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId IfId() const { return if_id_; }
|
|
|
|
BailoutId ThenId() const { return then_id_; }
|
|
|
|
BailoutId ElseId() const { return else_id_; }
|
2010-12-16 13:13:36 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
IfStatement(Isolate* isolate,
|
|
|
|
Expression* condition,
|
|
|
|
Statement* then_statement,
|
|
|
|
Statement* else_statement)
|
|
|
|
: condition_(condition),
|
|
|
|
then_statement_(then_statement),
|
|
|
|
else_statement_(else_statement),
|
|
|
|
if_id_(GetNextId(isolate)),
|
|
|
|
then_id_(GetNextId(isolate)),
|
|
|
|
else_id_(GetNextId(isolate)) {
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* condition_;
|
|
|
|
Statement* then_statement_;
|
|
|
|
Statement* else_statement_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId if_id_;
|
|
|
|
const BailoutId then_id_;
|
|
|
|
const BailoutId else_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// NOTE: TargetCollectors are represented as nodes to fit in the target
|
2008-07-03 15:10:15 +00:00
|
|
|
// stack in the compiler; this should probably be reworked.
|
2009-07-30 11:53:29 +00:00
|
|
|
class TargetCollector: public AstNode {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-06-11 12:42:31 +00:00
|
|
|
explicit TargetCollector(Zone* zone) : targets_(0, zone) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// Adds a jump target to the collector. The collector stores a pointer not
|
|
|
|
// a copy of the target to make binding work, so make sure not to pass in
|
|
|
|
// references to something on the stack.
|
2012-06-11 12:42:31 +00:00
|
|
|
void AddTarget(Label* target, Zone* zone);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// Virtual behaviour. TargetCollectors are never part of the AST.
|
2008-11-27 13:55:06 +00:00
|
|
|
virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
|
2012-07-20 09:39:27 +00:00
|
|
|
virtual Type node_type() const { return kInvalid; }
|
2009-02-27 13:00:32 +00:00
|
|
|
virtual TargetCollector* AsTargetCollector() { return this; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-06-08 13:55:33 +00:00
|
|
|
ZoneList<Label*>* targets() { return &targets_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2011-06-08 13:55:33 +00:00
|
|
|
ZoneList<Label*> targets_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TryStatement: public Statement {
|
|
|
|
public:
|
2011-04-07 14:42:37 +00:00
|
|
|
void set_escaping_targets(ZoneList<Label*>* targets) {
|
2009-02-27 13:00:32 +00:00
|
|
|
escaping_targets_ = targets;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
int index() const { return index_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
Block* try_block() const { return try_block_; }
|
2011-04-07 14:42:37 +00:00
|
|
|
ZoneList<Label*>* escaping_targets() const { return escaping_targets_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
TryStatement(int index, Block* try_block)
|
|
|
|
: index_(index),
|
|
|
|
try_block_(try_block),
|
|
|
|
escaping_targets_(NULL) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2011-11-11 13:48:14 +00:00
|
|
|
// Unique (per-function) index of this handler. This is not an AST ID.
|
|
|
|
int index_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Block* try_block_;
|
2011-04-07 14:42:37 +00:00
|
|
|
ZoneList<Label*>* escaping_targets_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
class TryCatchStatement: public TryStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(TryCatchStatement)
|
|
|
|
|
|
|
|
Scope* scope() { return scope_; }
|
|
|
|
Variable* variable() { return variable_; }
|
|
|
|
Block* catch_block() const { return catch_block_; }
|
|
|
|
|
|
|
|
protected:
|
2011-11-11 13:48:14 +00:00
|
|
|
TryCatchStatement(int index,
|
|
|
|
Block* try_block,
|
2011-06-30 14:37:55 +00:00
|
|
|
Scope* scope,
|
|
|
|
Variable* variable,
|
|
|
|
Block* catch_block)
|
2011-11-11 13:48:14 +00:00
|
|
|
: TryStatement(index, try_block),
|
2011-06-30 14:37:55 +00:00
|
|
|
scope_(scope),
|
|
|
|
variable_(variable),
|
2008-07-03 15:10:15 +00:00
|
|
|
catch_block_(catch_block) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-06-30 14:37:55 +00:00
|
|
|
Scope* scope_;
|
|
|
|
Variable* variable_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Block* catch_block_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
class TryFinallyStatement: public TryStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(TryFinallyStatement)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Block* finally_block() const { return finally_block_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
TryFinallyStatement(int index, Block* try_block, Block* finally_block)
|
|
|
|
: TryStatement(index, try_block),
|
|
|
|
finally_block_(finally_block) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Block* finally_block_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DebuggerStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(DebuggerStatement)
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
DebuggerStatement() {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class EmptyStatement: public Statement {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(EmptyStatement)
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
EmptyStatement() {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Literal: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Literal)
|
|
|
|
|
2010-01-12 08:48:26 +00:00
|
|
|
virtual bool IsPropertyName() {
|
|
|
|
if (handle_->IsSymbol()) {
|
|
|
|
uint32_t ignored;
|
|
|
|
return !String::cast(*handle_)->AsArrayIndex(&ignored);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<String> AsPropertyName() {
|
|
|
|
ASSERT(IsPropertyName());
|
|
|
|
return Handle<String>::cast(handle_);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ToBooleanIsTrue() { return handle_->ToBoolean()->IsTrue(); }
|
|
|
|
virtual bool ToBooleanIsFalse() { return handle_->ToBoolean()->IsFalse(); }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Identity testers.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool IsNull() const {
|
|
|
|
ASSERT(!handle_.is_null());
|
|
|
|
return handle_->IsNull();
|
|
|
|
}
|
|
|
|
bool IsTrue() const {
|
|
|
|
ASSERT(!handle_.is_null());
|
|
|
|
return handle_->IsTrue();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsFalse() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(!handle_.is_null());
|
|
|
|
return handle_->IsFalse();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Object> handle() const { return handle_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2012-03-09 08:34:35 +00:00
|
|
|
// Support for using Literal as a HashMap key. NOTE: Currently, this works
|
|
|
|
// only for string and number literals!
|
|
|
|
uint32_t Hash() { return ToString()->Hash(); }
|
|
|
|
|
|
|
|
static bool Match(void* literal1, void* literal2) {
|
|
|
|
Handle<String> s1 = static_cast<Literal*>(literal1)->ToString();
|
|
|
|
Handle<String> s2 = static_cast<Literal*>(literal2)->ToString();
|
|
|
|
return s1->Equals(*s2);
|
|
|
|
}
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
Literal(Isolate* isolate, Handle<Object> handle)
|
|
|
|
: Expression(isolate),
|
|
|
|
handle_(handle) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2012-03-09 08:34:35 +00:00
|
|
|
Handle<String> ToString();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> handle_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Base class for literals that needs space in the corresponding JSFunction.
|
|
|
|
class MaterializedLiteral: public Expression {
|
|
|
|
public:
|
2009-03-23 07:27:47 +00:00
|
|
|
virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
int literal_index() { return literal_index_; }
|
2009-03-23 07:27:47 +00:00
|
|
|
|
|
|
|
// A materialized literal is simple if the values consist of only
|
|
|
|
// constants and simple object and array literals.
|
|
|
|
bool is_simple() const { return is_simple_; }
|
|
|
|
|
|
|
|
int depth() const { return depth_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MaterializedLiteral(Isolate* isolate,
|
|
|
|
int literal_index,
|
|
|
|
bool is_simple,
|
|
|
|
int depth)
|
|
|
|
: Expression(isolate),
|
|
|
|
literal_index_(literal_index),
|
|
|
|
is_simple_(is_simple),
|
|
|
|
depth_(depth) {}
|
2009-03-23 07:27:47 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
int literal_index_;
|
2009-03-23 07:27:47 +00:00
|
|
|
bool is_simple_;
|
|
|
|
int depth_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// An object literal has a boilerplate object that is used
|
|
|
|
// for minimizing the work when constructing it at runtime.
|
|
|
|
class ObjectLiteral: public MaterializedLiteral {
|
|
|
|
public:
|
|
|
|
// Property is used for passing information
|
|
|
|
// about an object literal's properties from the parser
|
|
|
|
// to the code generator.
|
|
|
|
class Property: public ZoneObject {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
2009-03-23 07:27:47 +00:00
|
|
|
CONSTANT, // Property with constant value (compile time).
|
|
|
|
COMPUTED, // Property with computed value (execution time).
|
|
|
|
MATERIALIZED_LITERAL, // Property value is a materialized literal.
|
|
|
|
GETTER, SETTER, // Property is an accessor function.
|
|
|
|
PROTOTYPE // Property is __proto__.
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2012-02-28 15:32:06 +00:00
|
|
|
Property(Literal* key, Expression* value, Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Literal* key() { return key_; }
|
|
|
|
Expression* value() { return value_; }
|
|
|
|
Kind kind() { return kind_; }
|
|
|
|
|
2012-03-13 12:11:46 +00:00
|
|
|
// Type feedback information.
|
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
|
2012-07-10 09:15:03 +00:00
|
|
|
bool IsMonomorphic() { return !receiver_type_.is_null(); }
|
2012-03-13 12:11:46 +00:00
|
|
|
Handle<Map> GetReceiverType() { return receiver_type_; }
|
|
|
|
|
2009-10-28 13:25:40 +00:00
|
|
|
bool IsCompileTimeValue();
|
|
|
|
|
2010-10-27 11:37:59 +00:00
|
|
|
void set_emit_store(bool emit_store);
|
|
|
|
bool emit_store();
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
template<class> friend class AstNodeFactory;
|
|
|
|
|
|
|
|
Property(bool is_getter, FunctionLiteral* value);
|
|
|
|
void set_key(Literal* key) { key_ = key; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Literal* key_;
|
|
|
|
Expression* value_;
|
|
|
|
Kind kind_;
|
2010-10-27 11:37:59 +00:00
|
|
|
bool emit_store_;
|
2012-03-13 12:11:46 +00:00
|
|
|
Handle<Map> receiver_type_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ObjectLiteral)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Handle<FixedArray> constant_properties() const {
|
|
|
|
return constant_properties_;
|
|
|
|
}
|
|
|
|
ZoneList<Property*>* properties() const { return properties_; }
|
|
|
|
|
2010-03-11 10:34:29 +00:00
|
|
|
bool fast_elements() const { return fast_elements_; }
|
|
|
|
|
2011-03-21 12:25:31 +00:00
|
|
|
bool has_function() { return has_function_; }
|
2010-10-27 11:37:59 +00:00
|
|
|
|
|
|
|
// Mark all computed expressions that are bound to a key that
|
|
|
|
// is shadowed by a later occurrence of the same key. For the
|
|
|
|
// marked expressions, no store code is emitted.
|
2012-06-11 12:42:31 +00:00
|
|
|
void CalculateEmitStore(Zone* zone);
|
2010-10-27 11:37:59 +00:00
|
|
|
|
2011-03-21 12:25:31 +00:00
|
|
|
enum Flags {
|
|
|
|
kNoFlags = 0,
|
|
|
|
kFastElements = 1,
|
|
|
|
kHasFunction = 1 << 1
|
|
|
|
};
|
|
|
|
|
2012-03-15 07:13:46 +00:00
|
|
|
struct Accessors: public ZoneObject {
|
|
|
|
Accessors() : getter(NULL), setter(NULL) { }
|
|
|
|
Expression* getter;
|
|
|
|
Expression* setter;
|
|
|
|
};
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
ObjectLiteral(Isolate* isolate,
|
|
|
|
Handle<FixedArray> constant_properties,
|
|
|
|
ZoneList<Property*>* properties,
|
|
|
|
int literal_index,
|
|
|
|
bool is_simple,
|
|
|
|
bool fast_elements,
|
|
|
|
int depth,
|
|
|
|
bool has_function)
|
|
|
|
: MaterializedLiteral(isolate, literal_index, is_simple, depth),
|
|
|
|
constant_properties_(constant_properties),
|
|
|
|
properties_(properties),
|
|
|
|
fast_elements_(fast_elements),
|
|
|
|
has_function_(has_function) {}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Handle<FixedArray> constant_properties_;
|
|
|
|
ZoneList<Property*>* properties_;
|
2010-03-11 10:34:29 +00:00
|
|
|
bool fast_elements_;
|
2011-03-21 12:25:31 +00:00
|
|
|
bool has_function_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Node for capturing a regexp literal.
|
|
|
|
class RegExpLiteral: public MaterializedLiteral {
|
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(RegExpLiteral)
|
|
|
|
|
|
|
|
Handle<String> pattern() const { return pattern_; }
|
|
|
|
Handle<String> flags() const { return flags_; }
|
|
|
|
|
|
|
|
protected:
|
2011-07-18 17:32:41 +00:00
|
|
|
RegExpLiteral(Isolate* isolate,
|
|
|
|
Handle<String> pattern,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> flags,
|
|
|
|
int literal_index)
|
2011-07-18 17:32:41 +00:00
|
|
|
: MaterializedLiteral(isolate, literal_index, false, 1),
|
2008-07-03 15:10:15 +00:00
|
|
|
pattern_(pattern),
|
|
|
|
flags_(flags) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<String> pattern_;
|
|
|
|
Handle<String> flags_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// An array literal has a literals object that is used
|
2009-01-02 12:23:17 +00:00
|
|
|
// for minimizing the work when constructing it at runtime.
|
2009-03-23 07:27:47 +00:00
|
|
|
class ArrayLiteral: public MaterializedLiteral {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(ArrayLiteral)
|
|
|
|
|
|
|
|
Handle<FixedArray> constant_elements() const { return constant_elements_; }
|
|
|
|
ZoneList<Expression*>* values() const { return values_; }
|
|
|
|
|
|
|
|
// Return an AST id for an element that is used in simulate instructions.
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId GetIdForElement(int i) {
|
|
|
|
return BailoutId(first_element_id_.ToInt() + i);
|
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2011-07-18 17:32:41 +00:00
|
|
|
ArrayLiteral(Isolate* isolate,
|
|
|
|
Handle<FixedArray> constant_elements,
|
2009-03-23 07:27:47 +00:00
|
|
|
ZoneList<Expression*>* values,
|
|
|
|
int literal_index,
|
|
|
|
bool is_simple,
|
|
|
|
int depth)
|
2011-07-18 17:32:41 +00:00
|
|
|
: MaterializedLiteral(isolate, literal_index, is_simple, depth),
|
2009-12-22 12:41:45 +00:00
|
|
|
constant_elements_(constant_elements),
|
2010-12-07 11:31:57 +00:00
|
|
|
values_(values),
|
2011-07-18 17:32:41 +00:00
|
|
|
first_element_id_(ReserveIdRange(isolate, values->length())) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2009-12-22 12:41:45 +00:00
|
|
|
Handle<FixedArray> constant_elements_;
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Expression*>* values_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId first_element_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class VariableProxy: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(VariableProxy)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
virtual bool IsValidLeftHandSide() {
|
|
|
|
return var_ == NULL ? true : var_->IsValidLeftHandSide();
|
|
|
|
}
|
2009-06-24 08:01:38 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsVariable(Handle<String> n) {
|
|
|
|
return !is_this() && name().is_identical_to(n);
|
|
|
|
}
|
|
|
|
|
2011-09-07 11:02:31 +00:00
|
|
|
bool IsArguments() { return var_ != NULL && var_->is_arguments(); }
|
2009-06-24 08:01:38 +00:00
|
|
|
|
2011-12-05 14:43:28 +00:00
|
|
|
bool IsLValue() {
|
|
|
|
return is_lvalue_;
|
|
|
|
}
|
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
Handle<String> name() const { return name_; }
|
|
|
|
Variable* var() const { return var_; }
|
|
|
|
bool is_this() const { return is_this_; }
|
2011-04-01 11:54:04 +00:00
|
|
|
int position() const { return position_; }
|
2012-03-08 13:03:07 +00:00
|
|
|
Interface* interface() const { return interface_; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-24 07:26:49 +00:00
|
|
|
void MarkAsTrivial() { is_trivial_ = true; }
|
2011-12-05 14:43:28 +00:00
|
|
|
void MarkAsLValue() { is_lvalue_ = true; }
|
2010-03-16 10:54:02 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Bind this proxy to the variable var.
|
|
|
|
void BindTo(Variable* var);
|
|
|
|
|
|
|
|
protected:
|
2012-02-08 09:56:33 +00:00
|
|
|
VariableProxy(Isolate* isolate, Variable* var);
|
|
|
|
|
|
|
|
VariableProxy(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
|
|
|
bool is_this,
|
2012-07-13 09:29:43 +00:00
|
|
|
Interface* interface,
|
|
|
|
int position);
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> name_;
|
|
|
|
Variable* var_; // resolved variable, or NULL
|
|
|
|
bool is_this_;
|
2010-03-11 10:28:40 +00:00
|
|
|
bool is_trivial_;
|
2011-12-05 14:43:28 +00:00
|
|
|
// True if this variable proxy is being used in an assignment
|
|
|
|
// or with a increment/decrement operator.
|
|
|
|
bool is_lvalue_;
|
2011-04-01 11:54:04 +00:00
|
|
|
int position_;
|
2012-03-08 13:03:07 +00:00
|
|
|
Interface* interface_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Property: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Property)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
virtual bool IsValidLeftHandSide() { return true; }
|
|
|
|
|
|
|
|
Expression* obj() const { return obj_; }
|
|
|
|
Expression* key() const { return key_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-07 14:06:25 +00:00
|
|
|
BailoutId LoadId() const { return load_id_; }
|
2012-07-30 10:42:21 +00:00
|
|
|
|
2011-01-25 15:51:10 +00:00
|
|
|
bool IsStringLength() const { return is_string_length_; }
|
2011-03-14 15:36:00 +00:00
|
|
|
bool IsStringAccess() const { return is_string_access_; }
|
2010-12-22 15:43:32 +00:00
|
|
|
bool IsFunctionPrototype() const { return is_function_prototype_; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information.
|
2012-06-11 12:42:31 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
virtual bool IsMonomorphic() { return is_monomorphic_; }
|
2011-08-22 14:23:37 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
|
2011-10-31 11:11:26 +00:00
|
|
|
bool IsArrayLength() { return is_array_length_; }
|
2012-03-19 15:54:37 +00:00
|
|
|
bool IsUninitialized() { return is_uninitialized_; }
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId PropertyFeedbackId() { return reuse(id()); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
Property(Isolate* isolate,
|
|
|
|
Expression* obj,
|
|
|
|
Expression* key,
|
|
|
|
int pos)
|
|
|
|
: Expression(isolate),
|
|
|
|
obj_(obj),
|
|
|
|
key_(key),
|
|
|
|
pos_(pos),
|
2012-08-07 14:06:25 +00:00
|
|
|
load_id_(GetNextId(isolate)),
|
2012-02-08 09:56:33 +00:00
|
|
|
is_monomorphic_(false),
|
2012-03-19 15:54:37 +00:00
|
|
|
is_uninitialized_(false),
|
2012-02-08 09:56:33 +00:00
|
|
|
is_array_length_(false),
|
|
|
|
is_string_length_(false),
|
|
|
|
is_string_access_(false),
|
|
|
|
is_function_prototype_(false) { }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* obj_;
|
|
|
|
Expression* key_;
|
|
|
|
int pos_;
|
2012-08-07 14:06:25 +00:00
|
|
|
const BailoutId load_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2011-01-25 15:51:10 +00:00
|
|
|
bool is_monomorphic_ : 1;
|
2012-03-19 15:54:37 +00:00
|
|
|
bool is_uninitialized_ : 1;
|
2011-01-25 15:51:10 +00:00
|
|
|
bool is_array_length_ : 1;
|
|
|
|
bool is_string_length_ : 1;
|
2011-03-14 15:36:00 +00:00
|
|
|
bool is_string_access_ : 1;
|
2011-01-25 15:51:10 +00:00
|
|
|
bool is_function_prototype_ : 1;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Call: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Call)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Expression* expression() const { return expression_; }
|
|
|
|
ZoneList<Expression*>* arguments() const { return arguments_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
// Type feedback information.
|
|
|
|
TypeFeedbackId CallFeedbackId() const { return reuse(id()); }
|
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle, CallKind call_kind);
|
2011-08-22 14:23:37 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
virtual bool IsMonomorphic() { return is_monomorphic_; }
|
2011-01-13 14:16:08 +00:00
|
|
|
CheckType check_type() const { return check_type_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSFunction> target() { return target_; }
|
2012-07-06 08:34:48 +00:00
|
|
|
|
|
|
|
// A cache for the holder, set as a side effect of computing the target of the
|
|
|
|
// call. Note that it contains the null handle when the receiver is the same
|
|
|
|
// as the holder!
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSObject> holder() { return holder_; }
|
2012-07-06 08:34:48 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSGlobalPropertyCell> cell() { return cell_; }
|
|
|
|
|
|
|
|
bool ComputeTarget(Handle<Map> type, Handle<String> name);
|
2011-04-01 11:54:04 +00:00
|
|
|
bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId ReturnId() const { return return_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Used to assert that the FullCodeGenerator records the return site.
|
|
|
|
bool return_is_recorded_;
|
|
|
|
#endif
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
Call(Isolate* isolate,
|
|
|
|
Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos)
|
|
|
|
: Expression(isolate),
|
|
|
|
expression_(expression),
|
|
|
|
arguments_(arguments),
|
|
|
|
pos_(pos),
|
|
|
|
is_monomorphic_(false),
|
|
|
|
check_type_(RECEIVER_MAP_CHECK),
|
|
|
|
return_id_(GetNextId(isolate)) { }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
ZoneList<Expression*>* arguments_;
|
|
|
|
int pos_;
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool is_monomorphic_;
|
2011-01-13 14:16:08 +00:00
|
|
|
CheckType check_type_;
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSFunction> target_;
|
|
|
|
Handle<JSObject> holder_;
|
|
|
|
Handle<JSGlobalPropertyCell> cell_;
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId return_id_;
|
2011-03-18 20:35:07 +00:00
|
|
|
};
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2009-09-30 09:49:36 +00:00
|
|
|
class CallNew: public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(CallNew)
|
|
|
|
|
|
|
|
Expression* expression() const { return expression_; }
|
|
|
|
ZoneList<Expression*>* arguments() const { return arguments_; }
|
|
|
|
virtual int position() const { return pos_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
// Type feedback information.
|
|
|
|
TypeFeedbackId CallNewFeedbackId() const { return reuse(id()); }
|
2012-02-28 09:05:55 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
|
|
|
|
virtual bool IsMonomorphic() { return is_monomorphic_; }
|
|
|
|
Handle<JSFunction> target() { return target_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId ReturnId() const { return return_id_; }
|
2012-02-28 09:05:55 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2011-07-18 17:32:41 +00:00
|
|
|
CallNew(Isolate* isolate,
|
|
|
|
Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos)
|
|
|
|
: Expression(isolate),
|
|
|
|
expression_(expression),
|
|
|
|
arguments_(arguments),
|
2012-02-28 09:05:55 +00:00
|
|
|
pos_(pos),
|
|
|
|
is_monomorphic_(false),
|
|
|
|
return_id_(GetNextId(isolate)) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-30 09:49:36 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
ZoneList<Expression*>* arguments_;
|
|
|
|
int pos_;
|
2012-02-28 09:05:55 +00:00
|
|
|
|
|
|
|
bool is_monomorphic_;
|
|
|
|
Handle<JSFunction> target_;
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId return_id_;
|
2008-11-27 13:55:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// The CallRuntime class does not represent any official JavaScript
|
|
|
|
// language construct. Instead it is used to call a C or JS function
|
|
|
|
// with a set of arguments. This is used from the builtins that are
|
|
|
|
// implemented in JavaScript (see "v8natives.js").
|
|
|
|
class CallRuntime: public Expression {
|
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(CallRuntime)
|
|
|
|
|
|
|
|
Handle<String> name() const { return name_; }
|
|
|
|
const Runtime::Function* function() const { return function_; }
|
|
|
|
ZoneList<Expression*>* arguments() const { return arguments_; }
|
|
|
|
bool is_jsruntime() const { return function_ == NULL; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId CallRuntimeFeedbackId() const { return reuse(id()); }
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2011-07-18 17:32:41 +00:00
|
|
|
CallRuntime(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
2011-03-18 20:35:07 +00:00
|
|
|
const Runtime::Function* function,
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Expression*>* arguments)
|
2011-07-18 17:32:41 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
name_(name),
|
|
|
|
function_(function),
|
|
|
|
arguments_(arguments) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<String> name_;
|
2011-03-18 20:35:07 +00:00
|
|
|
const Runtime::Function* function_;
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Expression*>* arguments_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class UnaryOperation: public Expression {
|
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(UnaryOperation)
|
|
|
|
|
|
|
|
virtual bool ResultOverwriteAllowed();
|
|
|
|
|
|
|
|
Token::Value op() const { return op_; }
|
|
|
|
Expression* expression() const { return expression_; }
|
|
|
|
virtual int position() const { return pos_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId MaterializeTrueId() { return materialize_true_id_; }
|
|
|
|
BailoutId MaterializeFalseId() { return materialize_false_id_; }
|
|
|
|
|
|
|
|
TypeFeedbackId UnaryOperationFeedbackId() const { return reuse(id()); }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2011-07-18 17:32:41 +00:00
|
|
|
UnaryOperation(Isolate* isolate,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* expression,
|
|
|
|
int pos)
|
2011-11-02 16:53:32 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
op_(op),
|
|
|
|
expression_(expression),
|
|
|
|
pos_(pos),
|
2012-07-20 09:39:27 +00:00
|
|
|
materialize_true_id_(GetNextId(isolate)),
|
|
|
|
materialize_false_id_(GetNextId(isolate)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(Token::IsUnaryOp(op));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Token::Value op_;
|
|
|
|
Expression* expression_;
|
2011-04-28 17:49:55 +00:00
|
|
|
int pos_;
|
2011-11-02 16:53:32 +00:00
|
|
|
|
|
|
|
// For unary not (Token::NOT), the AST ids where true and false will
|
|
|
|
// actually be materialized, respectively.
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId materialize_true_id_;
|
|
|
|
const BailoutId materialize_false_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BinaryOperation: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(BinaryOperation)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-29 07:51:47 +00:00
|
|
|
virtual bool ResultOverwriteAllowed();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Token::Value op() const { return op_; }
|
|
|
|
Expression* left() const { return left_; }
|
|
|
|
Expression* right() const { return right_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId RightId() const { return right_id_; }
|
|
|
|
|
|
|
|
TypeFeedbackId BinaryOperationFeedbackId() const { return reuse(id()); }
|
2010-12-16 13:13:36 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
BinaryOperation(Isolate* isolate,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos)
|
2012-07-20 09:39:27 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
op_(op),
|
|
|
|
left_(left),
|
|
|
|
right_(right),
|
|
|
|
pos_(pos),
|
|
|
|
right_id_(GetNextId(isolate)) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ASSERT(Token::IsBinaryOp(op));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Token::Value op_;
|
|
|
|
Expression* left_;
|
|
|
|
Expression* right_;
|
2010-08-24 13:51:23 +00:00
|
|
|
int pos_;
|
2012-07-20 09:39:27 +00:00
|
|
|
// The short-circuit logical operations need an AST ID for their
|
2010-12-16 13:13:36 +00:00
|
|
|
// right-hand subexpression.
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId right_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-24 12:56:45 +00:00
|
|
|
class CountOperation: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(CountOperation)
|
2010-03-11 10:28:40 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool is_prefix() const { return is_prefix_; }
|
|
|
|
bool is_postfix() const { return !is_prefix_; }
|
2010-08-24 12:56:45 +00:00
|
|
|
|
2011-04-07 07:56:43 +00:00
|
|
|
Token::Value op() const { return op_; }
|
2010-01-14 17:22:59 +00:00
|
|
|
Token::Value binary_op() {
|
2010-08-24 12:56:45 +00:00
|
|
|
return (op() == Token::INC) ? Token::ADD : Token::SUB;
|
2010-01-14 17:22:59 +00:00
|
|
|
}
|
2010-08-24 12:56:45 +00:00
|
|
|
|
2011-04-07 07:56:43 +00:00
|
|
|
Expression* expression() const { return expression_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
virtual void MarkAsStatement() { is_prefix_ = true; }
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* znoe);
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual bool IsMonomorphic() { return is_monomorphic_; }
|
2011-08-22 14:23:37 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId AssignmentId() const { return assignment_id_; }
|
|
|
|
|
2012-08-07 14:06:25 +00:00
|
|
|
TypeFeedbackId CountBinOpFeedbackId() const { return count_id_; }
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId CountStoreFeedbackId() const { return reuse(id()); }
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
CountOperation(Isolate* isolate,
|
|
|
|
Token::Value op,
|
|
|
|
bool is_prefix,
|
|
|
|
Expression* expr,
|
|
|
|
int pos)
|
|
|
|
: Expression(isolate),
|
|
|
|
op_(op),
|
|
|
|
is_prefix_(is_prefix),
|
|
|
|
expression_(expr),
|
|
|
|
pos_(pos),
|
|
|
|
assignment_id_(GetNextId(isolate)),
|
|
|
|
count_id_(GetNextId(isolate)) {}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-04-07 07:56:43 +00:00
|
|
|
Token::Value op_;
|
2008-07-03 15:10:15 +00:00
|
|
|
bool is_prefix_;
|
2011-04-07 09:51:25 +00:00
|
|
|
bool is_monomorphic_;
|
2011-04-07 07:56:43 +00:00
|
|
|
Expression* expression_;
|
2010-08-24 13:51:23 +00:00
|
|
|
int pos_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId assignment_id_;
|
2012-08-07 14:06:25 +00:00
|
|
|
const TypeFeedbackId count_id_;
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CompareOperation: public Expression {
|
2012-02-08 09:56:33 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(CompareOperation)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Token::Value op() const { return op_; }
|
|
|
|
Expression* left() const { return left_; }
|
|
|
|
Expression* right() const { return right_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information.
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId CompareOperationFeedbackId() const { return reuse(id()); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-06-24 14:30:10 +00:00
|
|
|
// Match special cases.
|
|
|
|
bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
|
|
|
|
bool IsLiteralCompareUndefined(Expression** expr);
|
2011-09-15 09:09:40 +00:00
|
|
|
bool IsLiteralCompareNull(Expression** expr);
|
2011-06-24 14:30:10 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
CompareOperation(Isolate* isolate,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos)
|
|
|
|
: Expression(isolate),
|
|
|
|
op_(op),
|
|
|
|
left_(left),
|
|
|
|
right_(right),
|
2012-11-14 15:59:45 +00:00
|
|
|
pos_(pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ASSERT(Token::IsCompareOp(op));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Token::Value op_;
|
|
|
|
Expression* left_;
|
|
|
|
Expression* right_;
|
2010-08-24 13:51:23 +00:00
|
|
|
int pos_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Conditional: public Expression {
|
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(Conditional)
|
|
|
|
|
|
|
|
Expression* condition() const { return condition_; }
|
|
|
|
Expression* then_expression() const { return then_expression_; }
|
|
|
|
Expression* else_expression() const { return else_expression_; }
|
|
|
|
|
|
|
|
int then_expression_position() const { return then_expression_position_; }
|
|
|
|
int else_expression_position() const { return else_expression_position_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId ThenId() const { return then_id_; }
|
|
|
|
BailoutId ElseId() const { return else_id_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2011-07-18 17:32:41 +00:00
|
|
|
Conditional(Isolate* isolate,
|
|
|
|
Expression* condition,
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* then_expression,
|
2010-06-08 12:04:49 +00:00
|
|
|
Expression* else_expression,
|
|
|
|
int then_expression_position,
|
|
|
|
int else_expression_position)
|
2011-07-18 17:32:41 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
condition_(condition),
|
2008-07-03 15:10:15 +00:00
|
|
|
then_expression_(then_expression),
|
2010-06-08 12:04:49 +00:00
|
|
|
else_expression_(else_expression),
|
|
|
|
then_expression_position_(then_expression_position),
|
2010-12-16 13:13:36 +00:00
|
|
|
else_expression_position_(else_expression_position),
|
2011-07-18 17:32:41 +00:00
|
|
|
then_id_(GetNextId(isolate)),
|
2012-02-08 09:56:33 +00:00
|
|
|
else_id_(GetNextId(isolate)) { }
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* condition_;
|
|
|
|
Expression* then_expression_;
|
|
|
|
Expression* else_expression_;
|
2010-06-08 12:04:49 +00:00
|
|
|
int then_expression_position_;
|
|
|
|
int else_expression_position_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId then_id_;
|
|
|
|
const BailoutId else_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Assignment: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Assignment)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-11 10:28:40 +00:00
|
|
|
Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Token::Value binary_op() const;
|
|
|
|
|
|
|
|
Token::Value op() const { return op_; }
|
|
|
|
Expression* target() const { return target_; }
|
|
|
|
Expression* value() const { return value_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
BinaryOperation* binary_operation() const { return binary_operation_; }
|
|
|
|
|
2009-12-11 16:09:16 +00:00
|
|
|
// This check relies on the definition order of token in token.h.
|
|
|
|
bool is_compound() const { return op() > Token::ASSIGN; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId AssignmentId() const { return assignment_id_; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information.
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId AssignmentFeedbackId() { return reuse(id()); }
|
2012-06-11 12:42:31 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
virtual bool IsMonomorphic() { return is_monomorphic_; }
|
2011-08-22 14:23:37 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
|
|
|
Assignment(Isolate* isolate,
|
|
|
|
Token::Value op,
|
|
|
|
Expression* target,
|
|
|
|
Expression* value,
|
|
|
|
int pos);
|
|
|
|
|
|
|
|
template<class Visitor>
|
|
|
|
void Init(Isolate* isolate, AstNodeFactory<Visitor>* factory) {
|
|
|
|
ASSERT(Token::IsAssignmentOp(op_));
|
|
|
|
if (is_compound()) {
|
|
|
|
binary_operation_ =
|
|
|
|
factory->NewBinaryOperation(binary_op(), target_, value_, pos_ + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Token::Value op_;
|
|
|
|
Expression* target_;
|
|
|
|
Expression* value_;
|
|
|
|
int pos_;
|
2010-12-07 11:31:57 +00:00
|
|
|
BinaryOperation* binary_operation_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId assignment_id_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
bool is_monomorphic_;
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Throw: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Throw)
|
Add a predicate IsPrimitive to AST Expression nodes.
IsPrimitive reflects that an expression's value is known statically to
be one of the ECMA-262-3 JS types other than Object (e.g., Undefined,
Null, Boolean, String, or Number).
The type conversions ToPrimitive, ToNumber, ToInteger, ToInt32,
ToUInt32, ToUint16, ToString, or ToObject cannot invoke user code for
primitive input values. ToObject throws a TypeError if its input is
Undefined or Null.
Review URL: http://codereview.chromium.org/912002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4116 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-03-12 13:10:42 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* exception() const { return exception_; }
|
2011-04-07 09:51:25 +00:00
|
|
|
virtual int position() const { return pos_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Throw(Isolate* isolate, Expression* exception, int pos)
|
|
|
|
: Expression(isolate), exception_(exception), pos_(pos) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Expression* exception_;
|
|
|
|
int pos_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionLiteral: public Expression {
|
|
|
|
public:
|
2011-08-09 12:43:08 +00:00
|
|
|
enum Type {
|
|
|
|
ANONYMOUS_EXPRESSION,
|
|
|
|
NAMED_EXPRESSION,
|
|
|
|
DECLARATION
|
|
|
|
};
|
|
|
|
|
2012-02-14 14:14:51 +00:00
|
|
|
enum ParameterFlag {
|
|
|
|
kNoDuplicateParameters = 0,
|
|
|
|
kHasDuplicateParameters = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum IsFunctionFlag {
|
|
|
|
kGlobalOrEval,
|
|
|
|
kIsFunction
|
|
|
|
};
|
|
|
|
|
2012-08-07 14:47:36 +00:00
|
|
|
enum IsParenthesizedFlag {
|
|
|
|
kIsParenthesized,
|
|
|
|
kNotParenthesized
|
|
|
|
};
|
|
|
|
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(FunctionLiteral)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
Handle<String> name() const { return name_; }
|
|
|
|
Scope* scope() const { return scope_; }
|
|
|
|
ZoneList<Statement*>* body() const { return body_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
void set_function_token_position(int pos) { function_token_position_ = pos; }
|
|
|
|
int function_token_position() const { return function_token_position_; }
|
2011-10-21 10:26:59 +00:00
|
|
|
int start_position() const;
|
|
|
|
int end_position() const;
|
2012-02-14 14:14:51 +00:00
|
|
|
int SourceSize() const { return end_position() - start_position(); }
|
2011-11-09 13:54:26 +00:00
|
|
|
bool is_expression() const { return IsExpression::decode(bitfield_); }
|
|
|
|
bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
|
2011-11-24 15:17:04 +00:00
|
|
|
bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; }
|
|
|
|
LanguageMode language_mode() const;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
int materialized_literal_count() { return materialized_literal_count_; }
|
|
|
|
int expected_property_count() { return expected_property_count_; }
|
2011-11-11 13:48:14 +00:00
|
|
|
int handler_count() { return handler_count_; }
|
2009-08-19 07:30:20 +00:00
|
|
|
bool has_only_simple_this_property_assignments() {
|
2011-11-09 13:54:26 +00:00
|
|
|
return HasOnlySimpleThisPropertyAssignments::decode(bitfield_);
|
2009-08-19 07:30:20 +00:00
|
|
|
}
|
|
|
|
Handle<FixedArray> this_property_assignments() {
|
|
|
|
return this_property_assignments_;
|
|
|
|
}
|
2011-11-09 13:54:26 +00:00
|
|
|
int parameter_count() { return parameter_count_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
bool AllowsLazyCompilation();
|
2012-06-19 14:29:48 +00:00
|
|
|
bool AllowsLazyCompilationWithoutContext();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
Handle<String> debug_name() const {
|
|
|
|
if (name_->length() > 0) return name_;
|
|
|
|
return inferred_name();
|
|
|
|
}
|
|
|
|
|
2010-09-24 08:25:31 +00:00
|
|
|
Handle<String> inferred_name() const { return inferred_name_; }
|
2009-04-14 00:51:59 +00:00
|
|
|
void set_inferred_name(Handle<String> inferred_name) {
|
|
|
|
inferred_name_ = inferred_name;
|
|
|
|
}
|
|
|
|
|
2011-11-09 13:54:26 +00:00
|
|
|
bool pretenure() { return Pretenure::decode(bitfield_); }
|
|
|
|
void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
|
2010-11-22 09:57:21 +00:00
|
|
|
|
2011-11-09 13:54:26 +00:00
|
|
|
bool has_duplicate_parameters() {
|
|
|
|
return HasDuplicateParameters::decode(bitfield_);
|
|
|
|
}
|
2011-06-16 14:12:58 +00:00
|
|
|
|
2012-02-14 14:14:51 +00:00
|
|
|
bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
|
|
|
|
|
2012-08-16 11:54:48 +00:00
|
|
|
// This is used as a heuristic on when to eagerly compile a function
|
|
|
|
// literal. We consider the following constructs as hints that the
|
|
|
|
// function will be called immediately:
|
|
|
|
// - (function() { ... })();
|
|
|
|
// - var x = function() { ... }();
|
2012-08-07 14:47:36 +00:00
|
|
|
bool is_parenthesized() {
|
|
|
|
return IsParenthesized::decode(bitfield_) == kIsParenthesized;
|
|
|
|
}
|
2012-08-16 11:54:48 +00:00
|
|
|
void set_parenthesized() {
|
|
|
|
bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
|
|
|
|
}
|
2012-08-07 14:47:36 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
int ast_node_count() { return ast_properties_.node_count(); }
|
|
|
|
AstProperties::Flags* flags() { return ast_properties_.flags(); }
|
|
|
|
void set_ast_properties(AstProperties* ast_properties) {
|
|
|
|
ast_properties_ = *ast_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FunctionLiteral(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
|
|
|
Scope* scope,
|
|
|
|
ZoneList<Statement*>* body,
|
|
|
|
int materialized_literal_count,
|
|
|
|
int expected_property_count,
|
|
|
|
int handler_count,
|
|
|
|
bool has_only_simple_this_property_assignments,
|
|
|
|
Handle<FixedArray> this_property_assignments,
|
|
|
|
int parameter_count,
|
|
|
|
Type type,
|
2012-02-14 14:14:51 +00:00
|
|
|
ParameterFlag has_duplicate_parameters,
|
2012-08-07 14:47:36 +00:00
|
|
|
IsFunctionFlag is_function,
|
|
|
|
IsParenthesizedFlag is_parenthesized)
|
2012-02-08 09:56:33 +00:00
|
|
|
: Expression(isolate),
|
|
|
|
name_(name),
|
|
|
|
scope_(scope),
|
|
|
|
body_(body),
|
|
|
|
this_property_assignments_(this_property_assignments),
|
|
|
|
inferred_name_(isolate->factory()->empty_string()),
|
|
|
|
materialized_literal_count_(materialized_literal_count),
|
|
|
|
expected_property_count_(expected_property_count),
|
|
|
|
handler_count_(handler_count),
|
|
|
|
parameter_count_(parameter_count),
|
|
|
|
function_token_position_(RelocInfo::kNoPosition) {
|
|
|
|
bitfield_ =
|
|
|
|
HasOnlySimpleThisPropertyAssignments::encode(
|
|
|
|
has_only_simple_this_property_assignments) |
|
|
|
|
IsExpression::encode(type != DECLARATION) |
|
|
|
|
IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) |
|
|
|
|
Pretenure::encode(false) |
|
2012-02-14 14:14:51 +00:00
|
|
|
HasDuplicateParameters::encode(has_duplicate_parameters) |
|
2012-08-07 14:47:36 +00:00
|
|
|
IsFunction::encode(is_function) |
|
|
|
|
IsParenthesized::encode(is_parenthesized);
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Handle<String> name_;
|
|
|
|
Scope* scope_;
|
|
|
|
ZoneList<Statement*>* body_;
|
2011-11-09 13:54:26 +00:00
|
|
|
Handle<FixedArray> this_property_assignments_;
|
|
|
|
Handle<String> inferred_name_;
|
2012-02-08 09:56:33 +00:00
|
|
|
AstProperties ast_properties_;
|
2011-11-09 13:54:26 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
int materialized_literal_count_;
|
|
|
|
int expected_property_count_;
|
2011-11-11 13:48:14 +00:00
|
|
|
int handler_count_;
|
2011-11-09 13:54:26 +00:00
|
|
|
int parameter_count_;
|
2008-07-03 15:10:15 +00:00
|
|
|
int function_token_position_;
|
2011-11-09 13:54:26 +00:00
|
|
|
|
|
|
|
unsigned bitfield_;
|
|
|
|
class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {};
|
|
|
|
class IsExpression: public BitField<bool, 1, 1> {};
|
|
|
|
class IsAnonymous: public BitField<bool, 2, 1> {};
|
|
|
|
class Pretenure: public BitField<bool, 3, 1> {};
|
2012-02-14 14:14:51 +00:00
|
|
|
class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {};
|
|
|
|
class IsFunction: public BitField<IsFunctionFlag, 5, 1> {};
|
2012-08-07 14:47:36 +00:00
|
|
|
class IsParenthesized: public BitField<IsParenthesizedFlag, 6, 1> {};
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
class SharedFunctionInfoLiteral: public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_function_info() const {
|
|
|
|
return shared_function_info_;
|
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SharedFunctionInfoLiteral(
|
|
|
|
Isolate* isolate,
|
|
|
|
Handle<SharedFunctionInfo> shared_function_info)
|
|
|
|
: Expression(isolate),
|
|
|
|
shared_function_info_(shared_function_info) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_function_info_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ThisFunction: public Expression {
|
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ThisFunction)
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit ThisFunction(Isolate* isolate): Expression(isolate) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2012-02-10 08:35:57 +00:00
|
|
|
#undef DECLARE_NODE_TYPE
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Regular expressions
|
|
|
|
|
|
|
|
|
2009-01-14 11:32:23 +00:00
|
|
|
class RegExpVisitor BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
virtual ~RegExpVisitor() { }
|
|
|
|
#define MAKE_CASE(Name) \
|
|
|
|
virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
|
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
|
|
|
|
#undef MAKE_CASE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
class RegExpTree: public ZoneObject {
|
|
|
|
public:
|
2008-12-17 12:08:27 +00:00
|
|
|
static const int kInfinity = kMaxInt;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual ~RegExpTree() { }
|
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success) = 0;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual bool IsTextElement() { return false; }
|
2010-10-19 14:00:01 +00:00
|
|
|
virtual bool IsAnchoredAtStart() { return false; }
|
|
|
|
virtual bool IsAnchoredAtEnd() { return false; }
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() = 0;
|
|
|
|
virtual int max_match() = 0;
|
2009-01-14 11:32:23 +00:00
|
|
|
// Returns the interval of registers used for captures within this
|
|
|
|
// expression.
|
|
|
|
virtual Interval CaptureRegisters() { return Interval::Empty(); }
|
2012-06-11 12:42:31 +00:00
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone);
|
|
|
|
SmartArrayPointer<const char> ToString(Zone* zone);
|
2008-11-25 11:07:48 +00:00
|
|
|
#define MAKE_ASTYPE(Name) \
|
|
|
|
virtual RegExp##Name* As##Name(); \
|
|
|
|
virtual bool Is##Name();
|
|
|
|
FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
|
|
|
|
#undef MAKE_ASTYPE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpDisjunction: public RegExpTree {
|
|
|
|
public:
|
2008-12-17 10:59:14 +00:00
|
|
|
explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpDisjunction* AsDisjunction();
|
2009-01-14 11:32:23 +00:00
|
|
|
virtual Interval CaptureRegisters();
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual bool IsDisjunction();
|
2010-10-19 14:00:01 +00:00
|
|
|
virtual bool IsAnchoredAtStart();
|
|
|
|
virtual bool IsAnchoredAtEnd();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return min_match_; }
|
|
|
|
virtual int max_match() { return max_match_; }
|
2008-11-25 11:07:48 +00:00
|
|
|
ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
|
|
|
|
private:
|
|
|
|
ZoneList<RegExpTree*>* alternatives_;
|
2008-12-17 10:59:14 +00:00
|
|
|
int min_match_;
|
|
|
|
int max_match_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpAlternative: public RegExpTree {
|
|
|
|
public:
|
2008-12-17 10:59:14 +00:00
|
|
|
explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpAlternative* AsAlternative();
|
2009-01-14 11:32:23 +00:00
|
|
|
virtual Interval CaptureRegisters();
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual bool IsAlternative();
|
2010-10-19 14:00:01 +00:00
|
|
|
virtual bool IsAnchoredAtStart();
|
|
|
|
virtual bool IsAnchoredAtEnd();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return min_match_; }
|
|
|
|
virtual int max_match() { return max_match_; }
|
2008-11-25 11:07:48 +00:00
|
|
|
ZoneList<RegExpTree*>* nodes() { return nodes_; }
|
|
|
|
private:
|
|
|
|
ZoneList<RegExpTree*>* nodes_;
|
2008-12-17 10:59:14 +00:00
|
|
|
int min_match_;
|
|
|
|
int max_match_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpAssertion: public RegExpTree {
|
|
|
|
public:
|
|
|
|
enum Type {
|
2008-11-26 08:03:55 +00:00
|
|
|
START_OF_LINE,
|
|
|
|
START_OF_INPUT,
|
|
|
|
END_OF_LINE,
|
|
|
|
END_OF_INPUT,
|
|
|
|
BOUNDARY,
|
|
|
|
NON_BOUNDARY
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
explicit RegExpAssertion(Type type) : type_(type) { }
|
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpAssertion* AsAssertion();
|
|
|
|
virtual bool IsAssertion();
|
2010-10-19 14:00:01 +00:00
|
|
|
virtual bool IsAnchoredAtStart();
|
|
|
|
virtual bool IsAnchoredAtEnd();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return 0; }
|
|
|
|
virtual int max_match() { return 0; }
|
2008-11-25 11:07:48 +00:00
|
|
|
Type type() { return type_; }
|
|
|
|
private:
|
|
|
|
Type type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-02 12:23:17 +00:00
|
|
|
class CharacterSet BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
explicit CharacterSet(uc16 standard_set_type)
|
|
|
|
: ranges_(NULL),
|
|
|
|
standard_set_type_(standard_set_type) {}
|
|
|
|
explicit CharacterSet(ZoneList<CharacterRange>* ranges)
|
|
|
|
: ranges_(ranges),
|
|
|
|
standard_set_type_(0) {}
|
2012-06-11 12:42:31 +00:00
|
|
|
ZoneList<CharacterRange>* ranges(Zone* zone);
|
2009-01-02 12:23:17 +00:00
|
|
|
uc16 standard_set_type() { return standard_set_type_; }
|
|
|
|
void set_standard_set_type(uc16 special_set_type) {
|
|
|
|
standard_set_type_ = special_set_type;
|
|
|
|
}
|
|
|
|
bool is_standard() { return standard_set_type_ != 0; }
|
2010-01-07 19:01:23 +00:00
|
|
|
void Canonicalize();
|
2009-01-02 12:23:17 +00:00
|
|
|
private:
|
|
|
|
ZoneList<CharacterRange>* ranges_;
|
|
|
|
// If non-zero, the value represents a standard set (e.g., all whitespace
|
|
|
|
// characters) without having to expand the ranges.
|
|
|
|
uc16 standard_set_type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
class RegExpCharacterClass: public RegExpTree {
|
|
|
|
public:
|
|
|
|
RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
|
2009-01-02 12:23:17 +00:00
|
|
|
: set_(ranges),
|
2008-11-26 08:03:55 +00:00
|
|
|
is_negated_(is_negated) { }
|
2008-11-25 11:07:48 +00:00
|
|
|
explicit RegExpCharacterClass(uc16 type)
|
2009-01-02 12:23:17 +00:00
|
|
|
: set_(type),
|
|
|
|
is_negated_(false) { }
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpCharacterClass* AsCharacterClass();
|
|
|
|
virtual bool IsCharacterClass();
|
|
|
|
virtual bool IsTextElement() { return true; }
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return 1; }
|
|
|
|
virtual int max_match() { return 1; }
|
2012-06-11 12:42:31 +00:00
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone);
|
2009-01-02 12:23:17 +00:00
|
|
|
CharacterSet character_set() { return set_; }
|
|
|
|
// TODO(lrn): Remove need for complex version if is_standard that
|
|
|
|
// recognizes a mangled standard set and just do { return set_.is_special(); }
|
2012-06-11 12:42:31 +00:00
|
|
|
bool is_standard(Zone* zone);
|
2009-01-02 12:23:17 +00:00
|
|
|
// Returns a value representing the standard character set if is_standard()
|
|
|
|
// returns true.
|
|
|
|
// Currently used values are:
|
|
|
|
// s : unicode whitespace
|
|
|
|
// S : unicode non-whitespace
|
|
|
|
// w : ASCII word character (digit, letter, underscore)
|
|
|
|
// W : non-ASCII word character
|
|
|
|
// d : ASCII digit
|
|
|
|
// D : non-ASCII digit
|
2009-01-19 18:56:47 +00:00
|
|
|
// . : non-unicode non-newline
|
2009-01-02 12:23:17 +00:00
|
|
|
// * : All characters
|
|
|
|
uc16 standard_type() { return set_.standard_set_type(); }
|
2012-06-11 12:42:31 +00:00
|
|
|
ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
|
2008-11-25 11:07:48 +00:00
|
|
|
bool is_negated() { return is_negated_; }
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
private:
|
2009-01-02 12:23:17 +00:00
|
|
|
CharacterSet set_;
|
2008-11-25 11:07:48 +00:00
|
|
|
bool is_negated_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpAtom: public RegExpTree {
|
|
|
|
public:
|
|
|
|
explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
|
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpAtom* AsAtom();
|
|
|
|
virtual bool IsAtom();
|
|
|
|
virtual bool IsTextElement() { return true; }
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return data_.length(); }
|
|
|
|
virtual int max_match() { return data_.length(); }
|
2012-06-11 12:42:31 +00:00
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone);
|
2008-11-25 11:07:48 +00:00
|
|
|
Vector<const uc16> data() { return data_; }
|
2008-12-17 10:59:14 +00:00
|
|
|
int length() { return data_.length(); }
|
2008-11-25 11:07:48 +00:00
|
|
|
private:
|
|
|
|
Vector<const uc16> data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-12-17 10:59:14 +00:00
|
|
|
class RegExpText: public RegExpTree {
|
|
|
|
public:
|
2012-06-11 12:42:31 +00:00
|
|
|
explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
|
|
|
RegExpNode* on_success);
|
|
|
|
virtual RegExpText* AsText();
|
|
|
|
virtual bool IsText();
|
|
|
|
virtual bool IsTextElement() { return true; }
|
|
|
|
virtual int min_match() { return length_; }
|
|
|
|
virtual int max_match() { return length_; }
|
2012-06-11 12:42:31 +00:00
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone);
|
|
|
|
void AddElement(TextElement elm, Zone* zone) {
|
|
|
|
elements_.Add(elm, zone);
|
2008-12-17 10:59:14 +00:00
|
|
|
length_ += elm.length();
|
2010-09-02 10:18:44 +00:00
|
|
|
}
|
2008-12-17 10:59:14 +00:00
|
|
|
ZoneList<TextElement>* elements() { return &elements_; }
|
|
|
|
private:
|
|
|
|
ZoneList<TextElement> elements_;
|
|
|
|
int length_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
class RegExpQuantifier: public RegExpTree {
|
|
|
|
public:
|
2010-01-07 19:01:23 +00:00
|
|
|
enum Type { GREEDY, NON_GREEDY, POSSESSIVE };
|
|
|
|
RegExpQuantifier(int min, int max, Type type, RegExpTree* body)
|
|
|
|
: body_(body),
|
|
|
|
min_(min),
|
2008-11-26 08:03:55 +00:00
|
|
|
max_(max),
|
2010-01-07 19:01:23 +00:00
|
|
|
min_match_(min * body->min_match()),
|
2011-06-17 08:01:12 +00:00
|
|
|
type_(type) {
|
2008-12-17 10:59:14 +00:00
|
|
|
if (max > 0 && body->max_match() > kInfinity / max) {
|
|
|
|
max_match_ = kInfinity;
|
|
|
|
} else {
|
|
|
|
max_match_ = max * body->max_match();
|
|
|
|
}
|
|
|
|
}
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
static RegExpNode* ToNode(int min,
|
|
|
|
int max,
|
|
|
|
bool is_greedy,
|
|
|
|
RegExpTree* body,
|
|
|
|
RegExpCompiler* compiler,
|
2009-02-03 11:43:55 +00:00
|
|
|
RegExpNode* on_success,
|
|
|
|
bool not_at_start = false);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpQuantifier* AsQuantifier();
|
2009-01-14 11:32:23 +00:00
|
|
|
virtual Interval CaptureRegisters();
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual bool IsQuantifier();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return min_match_; }
|
|
|
|
virtual int max_match() { return max_match_; }
|
2008-11-25 11:07:48 +00:00
|
|
|
int min() { return min_; }
|
|
|
|
int max() { return max_; }
|
2010-01-07 19:01:23 +00:00
|
|
|
bool is_possessive() { return type_ == POSSESSIVE; }
|
|
|
|
bool is_non_greedy() { return type_ == NON_GREEDY; }
|
|
|
|
bool is_greedy() { return type_ == GREEDY; }
|
2008-11-25 11:07:48 +00:00
|
|
|
RegExpTree* body() { return body_; }
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
private:
|
2010-01-07 19:01:23 +00:00
|
|
|
RegExpTree* body_;
|
2008-11-25 11:07:48 +00:00
|
|
|
int min_;
|
|
|
|
int max_;
|
2008-12-17 10:59:14 +00:00
|
|
|
int min_match_;
|
|
|
|
int max_match_;
|
2010-01-07 19:01:23 +00:00
|
|
|
Type type_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpCapture: public RegExpTree {
|
|
|
|
public:
|
|
|
|
explicit RegExpCapture(RegExpTree* body, int index)
|
2009-07-03 08:18:35 +00:00
|
|
|
: body_(body), index_(index) { }
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
static RegExpNode* ToNode(RegExpTree* body,
|
|
|
|
int index,
|
|
|
|
RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpCapture* AsCapture();
|
2010-10-19 14:00:01 +00:00
|
|
|
virtual bool IsAnchoredAtStart();
|
|
|
|
virtual bool IsAnchoredAtEnd();
|
2009-01-14 11:32:23 +00:00
|
|
|
virtual Interval CaptureRegisters();
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual bool IsCapture();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return body_->min_match(); }
|
|
|
|
virtual int max_match() { return body_->max_match(); }
|
2008-11-25 11:07:48 +00:00
|
|
|
RegExpTree* body() { return body_; }
|
|
|
|
int index() { return index_; }
|
|
|
|
static int StartRegister(int index) { return index * 2; }
|
|
|
|
static int EndRegister(int index) { return index * 2 + 1; }
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
private:
|
|
|
|
RegExpTree* body_;
|
|
|
|
int index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpLookahead: public RegExpTree {
|
|
|
|
public:
|
2009-01-26 14:38:17 +00:00
|
|
|
RegExpLookahead(RegExpTree* body,
|
|
|
|
bool is_positive,
|
|
|
|
int capture_count,
|
|
|
|
int capture_from)
|
2008-11-26 08:03:55 +00:00
|
|
|
: body_(body),
|
2009-01-26 14:38:17 +00:00
|
|
|
is_positive_(is_positive),
|
|
|
|
capture_count_(capture_count),
|
|
|
|
capture_from_(capture_from) { }
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpLookahead* AsLookahead();
|
2009-01-14 11:32:23 +00:00
|
|
|
virtual Interval CaptureRegisters();
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual bool IsLookahead();
|
2010-10-19 14:00:01 +00:00
|
|
|
virtual bool IsAnchoredAtStart();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return 0; }
|
|
|
|
virtual int max_match() { return 0; }
|
2008-11-25 11:07:48 +00:00
|
|
|
RegExpTree* body() { return body_; }
|
|
|
|
bool is_positive() { return is_positive_; }
|
2009-01-26 14:38:17 +00:00
|
|
|
int capture_count() { return capture_count_; }
|
|
|
|
int capture_from() { return capture_from_; }
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
private:
|
|
|
|
RegExpTree* body_;
|
|
|
|
bool is_positive_;
|
2009-01-26 14:38:17 +00:00
|
|
|
int capture_count_;
|
|
|
|
int capture_from_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpBackReference: public RegExpTree {
|
|
|
|
public:
|
|
|
|
explicit RegExpBackReference(RegExpCapture* capture)
|
2008-11-26 08:03:55 +00:00
|
|
|
: capture_(capture) { }
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpBackReference* AsBackReference();
|
|
|
|
virtual bool IsBackReference();
|
2009-01-14 11:32:23 +00:00
|
|
|
virtual int min_match() { return 0; }
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int max_match() { return capture_->max_match(); }
|
2008-11-25 11:07:48 +00:00
|
|
|
int index() { return capture_->index(); }
|
|
|
|
RegExpCapture* capture() { return capture_; }
|
|
|
|
private:
|
|
|
|
RegExpCapture* capture_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegExpEmpty: public RegExpTree {
|
|
|
|
public:
|
|
|
|
RegExpEmpty() { }
|
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data);
|
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2008-12-08 09:22:12 +00:00
|
|
|
RegExpNode* on_success);
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpEmpty* AsEmpty();
|
|
|
|
virtual bool IsEmpty();
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual int min_match() { return 0; }
|
|
|
|
virtual int max_match() { return 0; }
|
2011-11-18 08:59:33 +00:00
|
|
|
static RegExpEmpty* GetInstance() {
|
|
|
|
static RegExpEmpty* instance = ::new RegExpEmpty();
|
|
|
|
return instance;
|
|
|
|
}
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-08 13:03:07 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Out-of-line inline constructors (to side-step cyclic dependencies).
|
|
|
|
|
|
|
|
inline ModuleVariable::ModuleVariable(VariableProxy* proxy)
|
|
|
|
: Module(proxy->interface()),
|
|
|
|
proxy_(proxy) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Basic visitor
|
|
|
|
// - leaf node visitors are abstract.
|
|
|
|
|
2008-11-27 13:55:06 +00:00
|
|
|
class AstVisitor BASE_EMBEDDED {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2011-03-21 11:57:59 +00:00
|
|
|
AstVisitor() : isolate_(Isolate::Current()), stack_overflow_(false) { }
|
2008-11-27 13:55:06 +00:00
|
|
|
virtual ~AstVisitor() { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-30 12:25:58 +00:00
|
|
|
// Stack overflow check and dynamic dispatch.
|
|
|
|
void Visit(AstNode* node) { if (!CheckStackOverflow()) node->Accept(this); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-30 12:25:58 +00:00
|
|
|
// Iteration left-to-right.
|
2009-10-12 15:06:28 +00:00
|
|
|
virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
|
2008-07-03 15:10:15 +00:00
|
|
|
virtual void VisitStatements(ZoneList<Statement*>* statements);
|
|
|
|
virtual void VisitExpressions(ZoneList<Expression*>* expressions);
|
|
|
|
|
|
|
|
// Stack overflow tracking support.
|
|
|
|
bool HasStackOverflow() const { return stack_overflow_; }
|
2010-03-30 12:25:58 +00:00
|
|
|
bool CheckStackOverflow();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
// If a stack-overflow exception is encountered when visiting a
|
|
|
|
// node, calling SetStackOverflow will make sure that the visitor
|
|
|
|
// bails out without visiting more nodes.
|
|
|
|
void SetStackOverflow() { stack_overflow_ = true; }
|
2010-12-07 11:31:57 +00:00
|
|
|
void ClearStackOverflow() { stack_overflow_ = false; }
|
|
|
|
|
|
|
|
// Individual AST nodes.
|
2008-07-03 15:10:15 +00:00
|
|
|
#define DEF_VISIT(type) \
|
|
|
|
virtual void Visit##type(type* node) = 0;
|
2009-07-30 12:09:05 +00:00
|
|
|
AST_NODE_LIST(DEF_VISIT)
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef DEF_VISIT
|
|
|
|
|
2011-03-21 11:57:59 +00:00
|
|
|
protected:
|
|
|
|
Isolate* isolate() { return isolate_; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-03-21 11:57:59 +00:00
|
|
|
Isolate* isolate_;
|
2008-07-03 15:10:15 +00:00
|
|
|
bool stack_overflow_;
|
|
|
|
};
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Construction time visitor.
|
|
|
|
|
|
|
|
class AstConstructionVisitor BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
AstConstructionVisitor() { }
|
|
|
|
|
|
|
|
AstProperties* ast_properties() { return &properties_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
template<class> friend class AstNodeFactory;
|
|
|
|
|
|
|
|
// Node visitors.
|
|
|
|
#define DEF_VISIT(type) \
|
|
|
|
void Visit##type(type* node);
|
|
|
|
AST_NODE_LIST(DEF_VISIT)
|
|
|
|
#undef DEF_VISIT
|
|
|
|
|
|
|
|
void increase_node_count() { properties_.add_node_count(1); }
|
|
|
|
void add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); }
|
|
|
|
|
|
|
|
AstProperties properties_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AstNullVisitor BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
// Node visitors.
|
|
|
|
#define DEF_VISIT(type) \
|
|
|
|
void Visit##type(type* node) {}
|
|
|
|
AST_NODE_LIST(DEF_VISIT)
|
|
|
|
#undef DEF_VISIT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// AstNode factory
|
|
|
|
|
|
|
|
template<class Visitor>
|
|
|
|
class AstNodeFactory BASE_EMBEDDED {
|
|
|
|
public:
|
2012-06-20 08:58:41 +00:00
|
|
|
AstNodeFactory(Isolate* isolate, Zone* zone)
|
2012-02-08 09:56:33 +00:00
|
|
|
: isolate_(isolate),
|
2012-06-20 08:58:41 +00:00
|
|
|
zone_(zone) { }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
Visitor* visitor() { return &visitor_; }
|
|
|
|
|
|
|
|
#define VISIT_AND_RETURN(NodeType, node) \
|
|
|
|
visitor_.Visit##NodeType((node)); \
|
|
|
|
return node;
|
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
|
|
|
|
VariableMode mode,
|
|
|
|
Scope* scope) {
|
|
|
|
VariableDeclaration* decl =
|
2012-02-28 10:12:39 +00:00
|
|
|
new(zone_) VariableDeclaration(proxy, mode, scope);
|
2012-02-09 13:39:26 +00:00
|
|
|
VISIT_AND_RETURN(VariableDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2012-02-28 10:12:39 +00:00
|
|
|
FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
|
|
|
|
VariableMode mode,
|
|
|
|
FunctionLiteral* fun,
|
|
|
|
Scope* scope) {
|
|
|
|
FunctionDeclaration* decl =
|
|
|
|
new(zone_) FunctionDeclaration(proxy, mode, fun, scope);
|
|
|
|
VISIT_AND_RETURN(FunctionDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
|
|
|
|
Module* module,
|
|
|
|
Scope* scope) {
|
|
|
|
ModuleDeclaration* decl =
|
|
|
|
new(zone_) ModuleDeclaration(proxy, module, scope);
|
|
|
|
VISIT_AND_RETURN(ModuleDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2012-02-29 12:12:52 +00:00
|
|
|
ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
|
|
|
|
Module* module,
|
|
|
|
Scope* scope) {
|
|
|
|
ImportDeclaration* decl =
|
|
|
|
new(zone_) ImportDeclaration(proxy, module, scope);
|
|
|
|
VISIT_AND_RETURN(ImportDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
|
|
|
ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
|
|
|
|
Scope* scope) {
|
|
|
|
ExportDeclaration* decl =
|
|
|
|
new(zone_) ExportDeclaration(proxy, scope);
|
|
|
|
VISIT_AND_RETURN(ExportDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2012-03-08 13:03:07 +00:00
|
|
|
ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface) {
|
|
|
|
ModuleLiteral* module = new(zone_) ModuleLiteral(body, interface);
|
2012-02-09 13:40:41 +00:00
|
|
|
VISIT_AND_RETURN(ModuleLiteral, module)
|
|
|
|
}
|
|
|
|
|
2012-02-20 14:02:59 +00:00
|
|
|
ModuleVariable* NewModuleVariable(VariableProxy* proxy) {
|
|
|
|
ModuleVariable* module = new(zone_) ModuleVariable(proxy);
|
|
|
|
VISIT_AND_RETURN(ModuleVariable, module)
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModulePath* NewModulePath(Module* origin, Handle<String> name) {
|
2012-06-11 12:42:31 +00:00
|
|
|
ModulePath* module = new(zone_) ModulePath(origin, name, zone_);
|
2012-02-20 14:02:59 +00:00
|
|
|
VISIT_AND_RETURN(ModulePath, module)
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModuleUrl* NewModuleUrl(Handle<String> url) {
|
2012-06-11 12:42:31 +00:00
|
|
|
ModuleUrl* module = new(zone_) ModuleUrl(url, zone_);
|
2012-02-20 14:02:59 +00:00
|
|
|
VISIT_AND_RETURN(ModuleUrl, module)
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
Block* NewBlock(ZoneStringList* labels,
|
|
|
|
int capacity,
|
2012-06-20 08:58:41 +00:00
|
|
|
bool is_initializer_block) {
|
2012-02-08 09:56:33 +00:00
|
|
|
Block* block = new(zone_) Block(
|
2012-06-20 08:58:41 +00:00
|
|
|
isolate_, labels, capacity, is_initializer_block, zone_);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Block, block)
|
|
|
|
}
|
|
|
|
|
|
|
|
#define STATEMENT_WITH_LABELS(NodeType) \
|
|
|
|
NodeType* New##NodeType(ZoneStringList* labels) { \
|
|
|
|
NodeType* stmt = new(zone_) NodeType(isolate_, labels); \
|
|
|
|
VISIT_AND_RETURN(NodeType, stmt); \
|
|
|
|
}
|
|
|
|
STATEMENT_WITH_LABELS(DoWhileStatement)
|
|
|
|
STATEMENT_WITH_LABELS(WhileStatement)
|
|
|
|
STATEMENT_WITH_LABELS(ForStatement)
|
|
|
|
STATEMENT_WITH_LABELS(ForInStatement)
|
|
|
|
STATEMENT_WITH_LABELS(SwitchStatement)
|
|
|
|
#undef STATEMENT_WITH_LABELS
|
|
|
|
|
|
|
|
ExpressionStatement* NewExpressionStatement(Expression* expression) {
|
|
|
|
ExpressionStatement* stmt = new(zone_) ExpressionStatement(expression);
|
|
|
|
VISIT_AND_RETURN(ExpressionStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
ContinueStatement* NewContinueStatement(IterationStatement* target) {
|
|
|
|
ContinueStatement* stmt = new(zone_) ContinueStatement(target);
|
|
|
|
VISIT_AND_RETURN(ContinueStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakStatement* NewBreakStatement(BreakableStatement* target) {
|
|
|
|
BreakStatement* stmt = new(zone_) BreakStatement(target);
|
|
|
|
VISIT_AND_RETURN(BreakStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnStatement* NewReturnStatement(Expression* expression) {
|
|
|
|
ReturnStatement* stmt = new(zone_) ReturnStatement(expression);
|
|
|
|
VISIT_AND_RETURN(ReturnStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
WithStatement* NewWithStatement(Expression* expression,
|
|
|
|
Statement* statement) {
|
|
|
|
WithStatement* stmt = new(zone_) WithStatement(expression, statement);
|
|
|
|
VISIT_AND_RETURN(WithStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
IfStatement* NewIfStatement(Expression* condition,
|
|
|
|
Statement* then_statement,
|
|
|
|
Statement* else_statement) {
|
|
|
|
IfStatement* stmt = new(zone_) IfStatement(
|
|
|
|
isolate_, condition, then_statement, else_statement);
|
|
|
|
VISIT_AND_RETURN(IfStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
TryCatchStatement* NewTryCatchStatement(int index,
|
|
|
|
Block* try_block,
|
|
|
|
Scope* scope,
|
|
|
|
Variable* variable,
|
|
|
|
Block* catch_block) {
|
|
|
|
TryCatchStatement* stmt = new(zone_) TryCatchStatement(
|
|
|
|
index, try_block, scope, variable, catch_block);
|
|
|
|
VISIT_AND_RETURN(TryCatchStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
TryFinallyStatement* NewTryFinallyStatement(int index,
|
|
|
|
Block* try_block,
|
|
|
|
Block* finally_block) {
|
|
|
|
TryFinallyStatement* stmt =
|
|
|
|
new(zone_) TryFinallyStatement(index, try_block, finally_block);
|
|
|
|
VISIT_AND_RETURN(TryFinallyStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
DebuggerStatement* NewDebuggerStatement() {
|
|
|
|
DebuggerStatement* stmt = new(zone_) DebuggerStatement();
|
|
|
|
VISIT_AND_RETURN(DebuggerStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyStatement* NewEmptyStatement() {
|
|
|
|
return new(zone_) EmptyStatement();
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewLiteral(Handle<Object> handle) {
|
|
|
|
Literal* lit = new(zone_) Literal(isolate_, handle);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewNumberLiteral(double number) {
|
|
|
|
return NewLiteral(isolate_->factory()->NewNumber(number, TENURED));
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectLiteral* NewObjectLiteral(
|
|
|
|
Handle<FixedArray> constant_properties,
|
|
|
|
ZoneList<ObjectLiteral::Property*>* properties,
|
|
|
|
int literal_index,
|
|
|
|
bool is_simple,
|
|
|
|
bool fast_elements,
|
|
|
|
int depth,
|
|
|
|
bool has_function) {
|
|
|
|
ObjectLiteral* lit = new(zone_) ObjectLiteral(
|
|
|
|
isolate_, constant_properties, properties, literal_index,
|
|
|
|
is_simple, fast_elements, depth, has_function);
|
|
|
|
VISIT_AND_RETURN(ObjectLiteral, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
|
|
|
|
FunctionLiteral* value) {
|
|
|
|
ObjectLiteral::Property* prop =
|
|
|
|
new(zone_) ObjectLiteral::Property(is_getter, value);
|
|
|
|
prop->set_key(NewLiteral(value->name()));
|
|
|
|
return prop; // Not an AST node, will not be visited.
|
|
|
|
}
|
|
|
|
|
|
|
|
RegExpLiteral* NewRegExpLiteral(Handle<String> pattern,
|
|
|
|
Handle<String> flags,
|
|
|
|
int literal_index) {
|
|
|
|
RegExpLiteral* lit =
|
|
|
|
new(zone_) RegExpLiteral(isolate_, pattern, flags, literal_index);
|
|
|
|
VISIT_AND_RETURN(RegExpLiteral, lit);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayLiteral* NewArrayLiteral(Handle<FixedArray> constant_elements,
|
|
|
|
ZoneList<Expression*>* values,
|
|
|
|
int literal_index,
|
|
|
|
bool is_simple,
|
|
|
|
int depth) {
|
|
|
|
ArrayLiteral* lit = new(zone_) ArrayLiteral(
|
|
|
|
isolate_, constant_elements, values, literal_index, is_simple, depth);
|
|
|
|
VISIT_AND_RETURN(ArrayLiteral, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableProxy* NewVariableProxy(Variable* var) {
|
|
|
|
VariableProxy* proxy = new(zone_) VariableProxy(isolate_, var);
|
|
|
|
VISIT_AND_RETURN(VariableProxy, proxy)
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableProxy* NewVariableProxy(Handle<String> name,
|
|
|
|
bool is_this,
|
2012-07-13 09:29:43 +00:00
|
|
|
Interface* interface = Interface::NewValue(),
|
|
|
|
int position = RelocInfo::kNoPosition) {
|
2012-02-08 09:56:33 +00:00
|
|
|
VariableProxy* proxy =
|
2012-07-13 09:29:43 +00:00
|
|
|
new(zone_) VariableProxy(isolate_, name, is_this, interface, position);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(VariableProxy, proxy)
|
|
|
|
}
|
|
|
|
|
|
|
|
Property* NewProperty(Expression* obj, Expression* key, int pos) {
|
|
|
|
Property* prop = new(zone_) Property(isolate_, obj, key, pos);
|
|
|
|
VISIT_AND_RETURN(Property, prop)
|
|
|
|
}
|
|
|
|
|
|
|
|
Call* NewCall(Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos) {
|
|
|
|
Call* call = new(zone_) Call(isolate_, expression, arguments, pos);
|
|
|
|
VISIT_AND_RETURN(Call, call)
|
|
|
|
}
|
|
|
|
|
|
|
|
CallNew* NewCallNew(Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos) {
|
|
|
|
CallNew* call = new(zone_) CallNew(isolate_, expression, arguments, pos);
|
|
|
|
VISIT_AND_RETURN(CallNew, call)
|
|
|
|
}
|
|
|
|
|
|
|
|
CallRuntime* NewCallRuntime(Handle<String> name,
|
|
|
|
const Runtime::Function* function,
|
|
|
|
ZoneList<Expression*>* arguments) {
|
|
|
|
CallRuntime* call =
|
|
|
|
new(zone_) CallRuntime(isolate_, name, function, arguments);
|
|
|
|
VISIT_AND_RETURN(CallRuntime, call)
|
|
|
|
}
|
|
|
|
|
|
|
|
UnaryOperation* NewUnaryOperation(Token::Value op,
|
|
|
|
Expression* expression,
|
|
|
|
int pos) {
|
|
|
|
UnaryOperation* node =
|
|
|
|
new(zone_) UnaryOperation(isolate_, op, expression, pos);
|
|
|
|
VISIT_AND_RETURN(UnaryOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryOperation* NewBinaryOperation(Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos) {
|
|
|
|
BinaryOperation* node =
|
|
|
|
new(zone_) BinaryOperation(isolate_, op, left, right, pos);
|
|
|
|
VISIT_AND_RETURN(BinaryOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
CountOperation* NewCountOperation(Token::Value op,
|
|
|
|
bool is_prefix,
|
|
|
|
Expression* expr,
|
|
|
|
int pos) {
|
|
|
|
CountOperation* node =
|
|
|
|
new(zone_) CountOperation(isolate_, op, is_prefix, expr, pos);
|
|
|
|
VISIT_AND_RETURN(CountOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
CompareOperation* NewCompareOperation(Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos) {
|
|
|
|
CompareOperation* node =
|
|
|
|
new(zone_) CompareOperation(isolate_, op, left, right, pos);
|
|
|
|
VISIT_AND_RETURN(CompareOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
Conditional* NewConditional(Expression* condition,
|
|
|
|
Expression* then_expression,
|
|
|
|
Expression* else_expression,
|
|
|
|
int then_expression_position,
|
|
|
|
int else_expression_position) {
|
|
|
|
Conditional* cond = new(zone_) Conditional(
|
|
|
|
isolate_, condition, then_expression, else_expression,
|
|
|
|
then_expression_position, else_expression_position);
|
|
|
|
VISIT_AND_RETURN(Conditional, cond)
|
|
|
|
}
|
|
|
|
|
|
|
|
Assignment* NewAssignment(Token::Value op,
|
|
|
|
Expression* target,
|
|
|
|
Expression* value,
|
|
|
|
int pos) {
|
|
|
|
Assignment* assign =
|
|
|
|
new(zone_) Assignment(isolate_, op, target, value, pos);
|
|
|
|
assign->Init(isolate_, this);
|
|
|
|
VISIT_AND_RETURN(Assignment, assign)
|
|
|
|
}
|
|
|
|
|
|
|
|
Throw* NewThrow(Expression* exception, int pos) {
|
|
|
|
Throw* t = new(zone_) Throw(isolate_, exception, pos);
|
|
|
|
VISIT_AND_RETURN(Throw, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionLiteral* NewFunctionLiteral(
|
|
|
|
Handle<String> name,
|
|
|
|
Scope* scope,
|
|
|
|
ZoneList<Statement*>* body,
|
|
|
|
int materialized_literal_count,
|
|
|
|
int expected_property_count,
|
|
|
|
int handler_count,
|
|
|
|
bool has_only_simple_this_property_assignments,
|
|
|
|
Handle<FixedArray> this_property_assignments,
|
|
|
|
int parameter_count,
|
2012-02-14 14:14:51 +00:00
|
|
|
FunctionLiteral::ParameterFlag has_duplicate_parameters,
|
2012-02-08 09:56:33 +00:00
|
|
|
FunctionLiteral::Type type,
|
2012-08-07 14:47:36 +00:00
|
|
|
FunctionLiteral::IsFunctionFlag is_function,
|
|
|
|
FunctionLiteral::IsParenthesizedFlag is_parenthesized) {
|
2012-02-08 09:56:33 +00:00
|
|
|
FunctionLiteral* lit = new(zone_) FunctionLiteral(
|
|
|
|
isolate_, name, scope, body,
|
|
|
|
materialized_literal_count, expected_property_count, handler_count,
|
|
|
|
has_only_simple_this_property_assignments, this_property_assignments,
|
2012-08-07 14:47:36 +00:00
|
|
|
parameter_count, type, has_duplicate_parameters, is_function,
|
|
|
|
is_parenthesized);
|
2012-02-14 14:14:51 +00:00
|
|
|
// Top-level literal doesn't count for the AST's properties.
|
|
|
|
if (is_function == FunctionLiteral::kIsFunction) {
|
2012-02-08 09:56:33 +00:00
|
|
|
visitor_.VisitFunctionLiteral(lit);
|
|
|
|
}
|
|
|
|
return lit;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral(
|
|
|
|
Handle<SharedFunctionInfo> shared_function_info) {
|
|
|
|
SharedFunctionInfoLiteral* lit =
|
|
|
|
new(zone_) SharedFunctionInfoLiteral(isolate_, shared_function_info);
|
|
|
|
VISIT_AND_RETURN(SharedFunctionInfoLiteral, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
ThisFunction* NewThisFunction() {
|
|
|
|
ThisFunction* fun = new(zone_) ThisFunction(isolate_);
|
|
|
|
VISIT_AND_RETURN(ThisFunction, fun)
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VISIT_AND_RETURN
|
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
Zone* zone_;
|
|
|
|
Visitor visitor_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_AST_H_
|