2012-01-25 16:31:25 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_AST_H_
|
|
|
|
#define V8_AST_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2012-01-25 16:31:25 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/assembler.h"
|
2014-06-24 14:03:24 +00:00
|
|
|
#include "src/ast-value-factory.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/feedback-slots.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/interface.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/jsregexp.h"
|
|
|
|
#include "src/list-inl.h"
|
2014-07-07 09:57:29 +00:00
|
|
|
#include "src/ostreams.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/runtime.h"
|
|
|
|
#include "src/small-pointer-list.h"
|
|
|
|
#include "src/smart-pointers.h"
|
|
|
|
#include "src/token.h"
|
|
|
|
#include "src/types.h"
|
|
|
|
#include "src/utils.h"
|
|
|
|
#include "src/variables.h"
|
|
|
|
#include "src/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) \
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
V(ModuleStatement) \
|
2008-07-03 15:10:15 +00:00
|
|
|
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) \
|
2013-06-06 14:38:26 +00:00
|
|
|
V(ForOfStatement) \
|
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) \
|
2013-10-01 09:47:37 +00:00
|
|
|
V(NativeFunctionLiteral) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(Conditional) \
|
|
|
|
V(VariableProxy) \
|
|
|
|
V(Literal) \
|
|
|
|
V(RegExpLiteral) \
|
|
|
|
V(ObjectLiteral) \
|
|
|
|
V(ArrayLiteral) \
|
|
|
|
V(Assignment) \
|
2013-04-02 17:34:59 +00:00
|
|
|
V(Yield) \
|
2008-07-03 15:10:15 +00:00
|
|
|
V(Throw) \
|
|
|
|
V(Property) \
|
|
|
|
V(Call) \
|
|
|
|
V(CallNew) \
|
|
|
|
V(CallRuntime) \
|
|
|
|
V(UnaryOperation) \
|
|
|
|
V(CountOperation) \
|
|
|
|
V(BinaryOperation) \
|
|
|
|
V(CompareOperation) \
|
2013-12-18 11:44:38 +00:00
|
|
|
V(ThisFunction) \
|
2013-10-14 11:06:15 +00:00
|
|
|
V(CaseClause)
|
|
|
|
|
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) \
|
2013-12-18 11:44:38 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
#define DECLARE_NODE_TYPE(type) \
|
|
|
|
virtual void Accept(AstVisitor* v) V8_OVERRIDE; \
|
|
|
|
virtual AstNode::NodeType node_type() const V8_FINAL V8_OVERRIDE { \
|
|
|
|
return AstNode::k##type; \
|
|
|
|
} \
|
2012-08-29 09:33:14 +00:00
|
|
|
template<class> friend class AstNodeFactory;
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum AstPropertiesFlag {
|
|
|
|
kDontSelfOptimize,
|
2012-07-09 08:59:03 +00:00
|
|
|
kDontSoftInline,
|
|
|
|
kDontCache
|
2012-02-08 09:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class AstProperties V8_FINAL BASE_EMBEDDED {
|
2012-02-08 09:56:33 +00:00
|
|
|
public:
|
|
|
|
class Flags : public EnumSet<AstPropertiesFlag, int> {};
|
|
|
|
|
2014-04-30 10:51:01 +00:00
|
|
|
AstProperties() : node_count_(0), feedback_slots_(0) {}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
Flags* flags() { return &flags_; }
|
|
|
|
int node_count() { return node_count_; }
|
|
|
|
void add_node_count(int count) { node_count_ += count; }
|
|
|
|
|
2014-04-30 10:51:01 +00:00
|
|
|
int feedback_slots() const { return feedback_slots_; }
|
|
|
|
void increase_feedback_slots(int count) {
|
|
|
|
feedback_slots_ += count;
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
private:
|
|
|
|
Flags flags_;
|
|
|
|
int node_count_;
|
2014-04-30 10:51:01 +00:00
|
|
|
int feedback_slots_;
|
2012-02-08 09:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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,
|
2013-06-06 13:28:22 +00:00
|
|
|
enum NodeType {
|
2010-09-29 07:51:47 +00:00
|
|
|
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
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
explicit AstNode(int position): position_(position) {}
|
2013-08-20 11:10:24 +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;
|
2013-06-06 13:28:22 +00:00
|
|
|
virtual NodeType node_type() const = 0;
|
2013-10-14 09:24:58 +00:00
|
|
|
int position() const { return position_; }
|
2010-09-29 07:51:47 +00:00
|
|
|
|
|
|
|
// Type testing & conversion functions overridden by concrete subclasses.
|
2014-04-02 11:03:05 +00:00
|
|
|
#define DECLARE_NODE_FUNCTIONS(type) \
|
|
|
|
bool Is##type() const { return node_type() == AstNode::k##type; } \
|
|
|
|
type* As##type() { \
|
|
|
|
return Is##type() ? reinterpret_cast<type*>(this) : NULL; \
|
|
|
|
} \
|
|
|
|
const type* As##type() const { \
|
|
|
|
return Is##type() ? reinterpret_cast<const 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:
|
2014-01-21 16:22:52 +00:00
|
|
|
static int GetNextId(Zone* zone) {
|
|
|
|
return ReserveIdRange(zone, 1);
|
2011-07-18 17:32:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
static int ReserveIdRange(Zone* zone, int n) {
|
|
|
|
int tmp = zone->isolate()->ast_node_id();
|
|
|
|
zone->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.
|
2013-10-14 09:24:58 +00:00
|
|
|
|
|
|
|
int position_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Statement : public AstNode {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit Statement(Zone* zone, int position) : AstNode(position) {}
|
2009-09-28 12:01:05 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsEmpty() { return AsEmptyStatement() != NULL; }
|
2013-08-06 12:57:23 +00:00
|
|
|
virtual bool IsJump() const { return false; }
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class SmallMapList V8_FINAL {
|
2011-08-22 14:23:37 +00:00
|
|
|
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(); }
|
|
|
|
|
2013-05-02 15:40:07 +00:00
|
|
|
void AddMapIfMissing(Handle<Map> map, Zone* zone) {
|
2014-04-28 05:47:43 +00:00
|
|
|
if (!Map::CurrentMapForDeprecated(map).ToHandle(&map)) return;
|
2013-05-02 15:40:07 +00:00
|
|
|
for (int i = 0; i < length(); ++i) {
|
|
|
|
if (at(i).is_identical_to(map)) return;
|
|
|
|
}
|
|
|
|
Add(map, zone);
|
|
|
|
}
|
|
|
|
|
2013-09-06 11:32:46 +00:00
|
|
|
void FilterForPossibleTransitions(Map* root_map) {
|
|
|
|
for (int i = list_.length() - 1; i >= 0; i--) {
|
|
|
|
if (at(i)->FindRootMap() != root_map) {
|
|
|
|
list_.RemoveElement(list_.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +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
|
|
|
|
};
|
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool IsValidReferenceExpression() const { return false; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Helpers for ToBoolean conversion.
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool ToBooleanIsTrue() const { return false; }
|
|
|
|
virtual bool ToBooleanIsFalse() const { return false; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
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.
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool IsPropertyName() const { return false; }
|
2010-01-12 08:48:26 +00:00
|
|
|
|
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.
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool ResultOverwriteAllowed() const { return false; }
|
2010-08-25 11:10:05 +00:00
|
|
|
|
2010-08-26 08:50:38 +00:00
|
|
|
// True iff the expression is a literal represented as a smi.
|
2014-04-02 11:03:05 +00:00
|
|
|
bool IsSmiLiteral() const;
|
2010-08-26 08:50:38 +00:00
|
|
|
|
2011-09-19 14:50:33 +00:00
|
|
|
// True iff the expression is a string literal.
|
2014-04-02 11:03:05 +00:00
|
|
|
bool IsStringLiteral() const;
|
2011-09-19 14:50:33 +00:00
|
|
|
|
|
|
|
// True iff the expression is the null literal.
|
2014-04-02 11:03:05 +00:00
|
|
|
bool IsNullLiteral() const;
|
2011-09-19 14:50:33 +00:00
|
|
|
|
2013-07-17 14:10:38 +00:00
|
|
|
// True if we can prove that the expression is the undefined literal.
|
2014-04-02 11:03:05 +00:00
|
|
|
bool IsUndefinedLiteral(Isolate* isolate) const;
|
2013-04-24 11:32:17 +00:00
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
// Expression type bounds
|
2014-04-02 11:03:05 +00:00
|
|
|
Bounds bounds() const { return bounds_; }
|
2013-07-11 11:47:05 +00:00
|
|
|
void set_bounds(Bounds bounds) { bounds_ = bounds; }
|
2013-06-06 13:28:22 +00:00
|
|
|
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
// Whether the expression is parenthesized
|
|
|
|
unsigned parenthesization_level() const { return parenthesization_level_; }
|
|
|
|
bool is_parenthesized() const { return parenthesization_level_ > 0; }
|
|
|
|
void increase_parenthesization_level() { ++parenthesization_level_; }
|
|
|
|
|
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;
|
|
|
|
}
|
2013-03-20 10:37:13 +00:00
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() {
|
|
|
|
UNREACHABLE();
|
|
|
|
return STANDARD_STORE;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
// TODO(rossberg): this should move to its own AST node eventually.
|
2013-06-25 11:49:46 +00:00
|
|
|
virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
|
2013-05-27 13:59:20 +00:00
|
|
|
byte to_boolean_types() const { return to_boolean_types_; }
|
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
Expression(Zone* zone, int pos)
|
2013-10-14 09:24:58 +00:00
|
|
|
: AstNode(pos),
|
2014-06-24 14:03:24 +00:00
|
|
|
zone_(zone),
|
2014-01-21 16:22:52 +00:00
|
|
|
bounds_(Bounds::Unbounded(zone)),
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
parenthesization_level_(0),
|
2014-01-21 16:22:52 +00:00
|
|
|
id_(GetNextId(zone)),
|
|
|
|
test_id_(GetNextId(zone)) {}
|
2013-06-25 11:49:46 +00:00
|
|
|
void set_to_boolean_types(byte types) { to_boolean_types_ = types; }
|
2012-02-09 13:40:41 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Zone* zone_;
|
|
|
|
|
2008-10-28 22:33:00 +00:00
|
|
|
private:
|
2013-07-11 11:47:05 +00:00
|
|
|
Bounds bounds_;
|
2013-05-27 13:59:20 +00:00
|
|
|
byte to_boolean_types_;
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
unsigned parenthesization_level_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId id_;
|
|
|
|
const TypeFeedbackId test_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class BreakableStatement : public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-06-06 13:28:22 +00:00
|
|
|
enum BreakableType {
|
2008-07-03 15:10:15 +00:00
|
|
|
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.
|
2014-06-24 14:03:24 +00:00
|
|
|
ZoneList<const AstRawString*>* labels() const { return labels_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Type testing & conversion.
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual BreakableStatement* AsBreakableStatement() V8_FINAL V8_OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// 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.
|
2013-06-06 13:28:22 +00:00
|
|
|
bool is_target_for_anonymous() const {
|
|
|
|
return breakable_type_ == TARGET_FOR_ANONYMOUS;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
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:
|
2013-06-06 13:28:22 +00:00
|
|
|
BreakableStatement(
|
2014-06-24 14:03:24 +00:00
|
|
|
Zone* zone, ZoneList<const AstRawString*>* labels,
|
2013-10-14 09:24:58 +00:00
|
|
|
BreakableType breakable_type, int position)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Statement(zone, position),
|
2013-10-14 09:24:58 +00:00
|
|
|
labels_(labels),
|
2013-06-06 13:28:22 +00:00
|
|
|
breakable_type_(breakable_type),
|
2014-01-21 16:22:52 +00:00
|
|
|
entry_id_(GetNextId(zone)),
|
|
|
|
exit_id_(GetNextId(zone)) {
|
2011-11-09 11:32:54 +00:00
|
|
|
ASSERT(labels == NULL || labels->length() > 0);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-24 14:03:24 +00:00
|
|
|
ZoneList<const AstRawString*>* labels_;
|
2013-06-06 13:28:22 +00:00
|
|
|
BreakableType breakable_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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Block V8_FINAL : public BreakableStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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
|
|
|
|
2014-06-05 07:33:01 +00:00
|
|
|
BailoutId DeclsId() const { return decls_id_; }
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual bool IsJump() const V8_OVERRIDE {
|
2013-08-06 12:57:23 +00:00
|
|
|
return !statements_.is_empty() && statements_.last()->IsJump()
|
|
|
|
&& labels() == NULL; // Good enough as an approximation...
|
|
|
|
}
|
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
Block(Zone* zone,
|
2014-06-24 14:03:24 +00:00
|
|
|
ZoneList<const AstRawString*>* labels,
|
2012-02-08 09:56:33 +00:00
|
|
|
int capacity,
|
2012-06-11 12:42:31 +00:00
|
|
|
bool is_initializer_block,
|
2014-01-21 16:22:52 +00:00
|
|
|
int pos)
|
|
|
|
: BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
|
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),
|
2014-06-05 07:33:01 +00:00
|
|
|
decls_id_(GetNextId(zone)),
|
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_;
|
2014-06-05 07:33:01 +00:00
|
|
|
const BailoutId decls_id_;
|
2012-04-16 14:43:27 +00:00
|
|
|
Scope* scope_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +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:
|
2014-01-21 16:22:52 +00:00
|
|
|
Declaration(Zone* zone,
|
|
|
|
VariableProxy* proxy,
|
2011-10-11 08:41:19 +00:00
|
|
|
VariableMode mode,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos)
|
|
|
|
: AstNode(pos),
|
|
|
|
proxy_(proxy),
|
2008-11-26 08:03:55 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class VariableDeclaration V8_FINAL : public Declaration {
|
2012-02-09 13:39:26 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(VariableDeclaration)
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual InitializationFlag initialization() const V8_OVERRIDE {
|
2012-02-28 10:12:39 +00:00
|
|
|
return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
VariableDeclaration(Zone* zone,
|
|
|
|
VariableProxy* proxy,
|
2012-02-28 10:12:39 +00:00
|
|
|
VariableMode mode,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Declaration(zone, proxy, mode, scope, pos) {
|
2012-02-28 10:12:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-09 13:39:26 +00:00
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class FunctionDeclaration V8_FINAL : public Declaration {
|
2012-02-28 10:12:39 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(FunctionDeclaration)
|
|
|
|
|
|
|
|
FunctionLiteral* fun() const { return fun_; }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual InitializationFlag initialization() const V8_OVERRIDE {
|
2012-02-28 10:12:39 +00:00
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual bool IsInlineable() const V8_OVERRIDE;
|
2012-02-09 13:39:26 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
FunctionDeclaration(Zone* zone,
|
|
|
|
VariableProxy* proxy,
|
2012-02-09 13:39:26 +00:00
|
|
|
VariableMode mode,
|
|
|
|
FunctionLiteral* fun,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Declaration(zone, proxy, mode, scope, pos),
|
2012-02-09 13:39:26 +00:00
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ModuleDeclaration V8_FINAL : public Declaration {
|
2012-02-09 13:40:41 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleDeclaration)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual InitializationFlag initialization() const V8_OVERRIDE {
|
2012-02-28 10:12:39 +00:00
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleDeclaration(Zone* zone,
|
|
|
|
VariableProxy* proxy,
|
2012-02-09 13:40:41 +00:00
|
|
|
Module* module,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Declaration(zone, proxy, MODULE, scope, pos),
|
2012-02-09 13:40:41 +00:00
|
|
|
module_(module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module* module_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ImportDeclaration V8_FINAL : public Declaration {
|
2012-02-29 12:12:52 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ImportDeclaration)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual InitializationFlag initialization() const V8_OVERRIDE {
|
2012-02-29 12:12:52 +00:00
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ImportDeclaration(Zone* zone,
|
|
|
|
VariableProxy* proxy,
|
2012-02-29 12:12:52 +00:00
|
|
|
Module* module,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Declaration(zone, proxy, LET, scope, pos),
|
2012-02-29 12:12:52 +00:00
|
|
|
module_(module) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module* module_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ExportDeclaration V8_FINAL : public Declaration {
|
2012-02-29 12:12:52 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ExportDeclaration)
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual InitializationFlag initialization() const V8_OVERRIDE {
|
2012-02-29 12:12:52 +00:00
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ExportDeclaration(Zone* zone, VariableProxy* proxy, Scope* scope, int pos)
|
|
|
|
: Declaration(zone, proxy, LET, scope, pos) {}
|
2012-02-29 12:12:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +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:
|
2013-10-14 09:24:58 +00:00
|
|
|
Module(Zone* zone, int pos)
|
|
|
|
: AstNode(pos),
|
|
|
|
interface_(Interface::NewModule(zone)),
|
2012-07-09 08:59:03 +00:00
|
|
|
body_(NULL) {}
|
2014-01-21 16:22:52 +00:00
|
|
|
Module(Zone* zone, Interface* interface, int pos, Block* body = NULL)
|
2013-10-14 09:24:58 +00:00
|
|
|
: AstNode(pos),
|
|
|
|
interface_(interface),
|
2012-07-09 08:59:03 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ModuleLiteral V8_FINAL : public Module {
|
2012-02-09 13:40:41 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleLiteral)
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleLiteral(Zone* zone, Block* body, Interface* interface, int pos)
|
|
|
|
: Module(zone, interface, pos, body) {}
|
2012-02-09 13:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ModuleVariable V8_FINAL : public Module {
|
2012-02-09 13:40:41 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
inline ModuleVariable(Zone* zone, VariableProxy* proxy, int pos);
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ModulePath V8_FINAL : public Module {
|
2012-02-09 13:40:41 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModulePath)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> name() const { return name_->string(); }
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
ModulePath(Zone* zone, Module* module, const AstRawString* name, int pos)
|
|
|
|
: Module(zone, pos), module_(module), name_(name) {}
|
2012-02-09 13:40:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Module* module_;
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name_;
|
2012-02-09 13:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ModuleUrl V8_FINAL : public Module {
|
2012-02-09 13:40:41 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleUrl)
|
|
|
|
|
|
|
|
Handle<String> url() const { return url_; }
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleUrl(Zone* zone, Handle<String> url, int pos)
|
2013-10-14 09:24:58 +00:00
|
|
|
: Module(zone, pos), url_(url) {
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<String> url_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ModuleStatement V8_FINAL : public Statement {
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleStatement)
|
|
|
|
|
|
|
|
VariableProxy* proxy() const { return proxy_; }
|
|
|
|
Block* body() const { return body_; }
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleStatement(Zone* zone, VariableProxy* proxy, Block* body, int pos)
|
|
|
|
: Statement(zone, pos),
|
2013-10-14 09:24:58 +00:00
|
|
|
proxy_(proxy),
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
body_(body) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
VariableProxy* proxy_;
|
|
|
|
Block* body_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class IterationStatement : public BreakableStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
|
|
|
// Type testing & conversion.
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual IterationStatement* AsIterationStatement() V8_FINAL V8_OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
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:
|
2014-06-24 14:03:24 +00:00
|
|
|
IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
|
2011-11-09 11:32:54 +00:00
|
|
|
body_(NULL),
|
2014-01-21 16:22:52 +00:00
|
|
|
osr_entry_id_(GetNextId(zone)) {
|
2011-11-09 11:32:54 +00:00
|
|
|
}
|
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_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId osr_entry_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class DoWhileStatement V8_FINAL : 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_; }
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; }
|
|
|
|
virtual BailoutId StackCheckId() const V8_OVERRIDE { return back_edge_id_; }
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId BackEdgeId() const { return back_edge_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: IterationStatement(zone, labels, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
cond_(NULL),
|
2014-01-21 16:22:52 +00:00
|
|
|
continue_id_(GetNextId(zone)),
|
|
|
|
back_edge_id_(GetNextId(zone)) {
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
2011-04-12 08:37:29 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
private:
|
|
|
|
Expression* cond_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class WhileStatement V8_FINAL : public IterationStatement {
|
2009-10-12 13:14:06 +00:00
|
|
|
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
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); }
|
|
|
|
virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId BodyId() const { return body_id_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: IterationStatement(zone, labels, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
cond_(NULL),
|
|
|
|
may_have_function_literal_(true),
|
2014-01-21 16:22:52 +00:00
|
|
|
body_id_(GetNextId(zone)) {
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
private:
|
|
|
|
Expression* cond_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
// True if there is a function literal subexpression in the condition.
|
|
|
|
bool may_have_function_literal_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId body_id_;
|
2009-10-12 13:14:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ForStatement V8_FINAL : public IterationStatement {
|
2009-10-12 13:14:06 +00:00
|
|
|
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
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; }
|
|
|
|
virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
|
2012-08-06 14:13:09 +00:00
|
|
|
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:
|
2014-06-24 14:03:24 +00:00
|
|
|
ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: IterationStatement(zone, labels, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
init_(NULL),
|
|
|
|
cond_(NULL),
|
|
|
|
next_(NULL),
|
|
|
|
may_have_function_literal_(true),
|
|
|
|
loop_variable_(NULL),
|
2014-01-21 16:22:52 +00:00
|
|
|
continue_id_(GetNextId(zone)),
|
|
|
|
body_id_(GetNextId(zone)) {
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
2010-03-11 10:28:40 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Statement* init_;
|
|
|
|
Expression* cond_;
|
|
|
|
Statement* next_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
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_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId continue_id_;
|
|
|
|
const BailoutId body_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ForEachStatement : public IterationStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-06-06 14:38:26 +00:00
|
|
|
enum VisitMode {
|
|
|
|
ENUMERATE, // for (each in subject) body;
|
|
|
|
ITERATE // for (each of subject) body;
|
|
|
|
};
|
2010-09-29 07:51:47 +00:00
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
void Initialize(Expression* each, Expression* subject, Statement* body) {
|
2008-07-03 15:10:15 +00:00
|
|
|
IterationStatement::Initialize(body);
|
|
|
|
each_ = each;
|
2013-06-06 14:38:26 +00:00
|
|
|
subject_ = subject;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Expression* each() const { return each_; }
|
2013-06-06 14:38:26 +00:00
|
|
|
Expression* subject() const { return subject_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* each_;
|
2013-06-06 14:38:26 +00:00
|
|
|
Expression* subject_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
class ForInStatement V8_FINAL : public ForEachStatement,
|
|
|
|
public FeedbackSlotInterface {
|
2013-06-06 14:38:26 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ForInStatement)
|
|
|
|
|
|
|
|
Expression* enumerable() const {
|
|
|
|
return subject();
|
|
|
|
}
|
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
// Type feedback information.
|
2014-04-30 10:51:01 +00:00
|
|
|
virtual int ComputeFeedbackSlotCount() { return 1; }
|
2014-02-10 21:38:17 +00:00
|
|
|
virtual void SetFirstFeedbackSlot(int slot) { for_in_feedback_slot_ = slot; }
|
|
|
|
|
|
|
|
int ForInFeedbackSlot() {
|
|
|
|
ASSERT(for_in_feedback_slot_ != kInvalidFeedbackSlot);
|
|
|
|
return for_in_feedback_slot_;
|
|
|
|
}
|
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
|
|
|
|
ForInType for_in_type() const { return for_in_type_; }
|
2013-11-28 13:16:51 +00:00
|
|
|
void set_for_in_type(ForInType type) { for_in_type_ = type; }
|
2013-06-06 14:38:26 +00:00
|
|
|
|
2013-06-07 11:12:21 +00:00
|
|
|
BailoutId BodyId() const { return body_id_; }
|
|
|
|
BailoutId PrepareId() const { return prepare_id_; }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); }
|
|
|
|
virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
|
2013-06-07 11:12:21 +00:00
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: ForEachStatement(zone, labels, pos),
|
2013-06-07 11:12:21 +00:00
|
|
|
for_in_type_(SLOW_FOR_IN),
|
2014-02-10 21:38:17 +00:00
|
|
|
for_in_feedback_slot_(kInvalidFeedbackSlot),
|
2014-01-21 16:22:52 +00:00
|
|
|
body_id_(GetNextId(zone)),
|
|
|
|
prepare_id_(GetNextId(zone)) {
|
2013-06-06 14:38:26 +00:00
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
ForInType for_in_type_;
|
2014-02-10 21:38:17 +00:00
|
|
|
int for_in_feedback_slot_;
|
2013-06-07 11:12:21 +00:00
|
|
|
const BailoutId body_id_;
|
|
|
|
const BailoutId prepare_id_;
|
2013-06-06 14:38:26 +00:00
|
|
|
};
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ForOfStatement V8_FINAL : public ForEachStatement {
|
2013-06-06 14:38:26 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ForOfStatement)
|
|
|
|
|
2013-06-07 11:12:21 +00:00
|
|
|
void Initialize(Expression* each,
|
|
|
|
Expression* subject,
|
|
|
|
Statement* body,
|
2014-06-12 17:31:54 +00:00
|
|
|
Expression* assign_iterable,
|
2013-06-07 11:12:21 +00:00
|
|
|
Expression* assign_iterator,
|
|
|
|
Expression* next_result,
|
|
|
|
Expression* result_done,
|
|
|
|
Expression* assign_each) {
|
|
|
|
ForEachStatement::Initialize(each, subject, body);
|
2014-06-12 17:31:54 +00:00
|
|
|
assign_iterable_ = assign_iterable;
|
2013-06-07 11:12:21 +00:00
|
|
|
assign_iterator_ = assign_iterator;
|
|
|
|
next_result_ = next_result;
|
|
|
|
result_done_ = result_done;
|
|
|
|
assign_each_ = assign_each;
|
|
|
|
}
|
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
Expression* iterable() const {
|
|
|
|
return subject();
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:31:54 +00:00
|
|
|
// var iterable = subject;
|
|
|
|
Expression* assign_iterable() const {
|
|
|
|
return assign_iterable_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// var iterator = iterable[Symbol.iterator]();
|
2013-06-07 11:12:21 +00:00
|
|
|
Expression* assign_iterator() const {
|
|
|
|
return assign_iterator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// var result = iterator.next();
|
|
|
|
Expression* next_result() const {
|
|
|
|
return next_result_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// result.done
|
|
|
|
Expression* result_done() const {
|
|
|
|
return result_done_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// each = result.value
|
|
|
|
Expression* assign_each() const {
|
|
|
|
return assign_each_;
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); }
|
|
|
|
virtual BailoutId StackCheckId() const V8_OVERRIDE { return BackEdgeId(); }
|
2013-06-07 11:12:21 +00:00
|
|
|
|
|
|
|
BailoutId BackEdgeId() const { return back_edge_id_; }
|
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: ForEachStatement(zone, labels, pos),
|
2013-06-07 11:12:21 +00:00
|
|
|
assign_iterator_(NULL),
|
|
|
|
next_result_(NULL),
|
|
|
|
result_done_(NULL),
|
|
|
|
assign_each_(NULL),
|
2014-01-21 16:22:52 +00:00
|
|
|
back_edge_id_(GetNextId(zone)) {
|
2013-06-06 14:38:26 +00:00
|
|
|
}
|
2013-06-07 11:12:21 +00:00
|
|
|
|
2014-06-12 17:31:54 +00:00
|
|
|
Expression* assign_iterable_;
|
2013-06-07 11:12:21 +00:00
|
|
|
Expression* assign_iterator_;
|
|
|
|
Expression* next_result_;
|
|
|
|
Expression* result_done_;
|
|
|
|
Expression* assign_each_;
|
|
|
|
const BailoutId back_edge_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ExpressionStatement V8_FINAL : public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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_; }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual bool IsJump() const V8_OVERRIDE { return expression_->IsThrow(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ExpressionStatement(Zone* zone, Expression* expression, int pos)
|
|
|
|
: Statement(zone, pos), expression_(expression) { }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class JumpStatement : public Statement {
|
2013-08-06 12:57:23 +00:00
|
|
|
public:
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual bool IsJump() const V8_FINAL V8_OVERRIDE { return true; }
|
2013-08-06 12:57:23 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {}
|
2013-08-06 12:57:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ContinueStatement V8_FINAL : public JumpStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
|
|
|
|
: JumpStatement(zone, pos), target_(target) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
IterationStatement* target_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class BreakStatement V8_FINAL : public JumpStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
|
|
|
|
: JumpStatement(zone, pos), target_(target) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BreakableStatement* target_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ReturnStatement V8_FINAL : public JumpStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
|
|
|
|
: JumpStatement(zone, pos), expression_(expression) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class WithStatement V8_FINAL : 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
|
|
|
|
2013-04-26 11:55:22 +00:00
|
|
|
Scope* scope() { return scope_; }
|
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:
|
2013-10-14 09:24:58 +00:00
|
|
|
WithStatement(
|
2014-01-21 16:22:52 +00:00
|
|
|
Zone* zone, Scope* scope,
|
|
|
|
Expression* expression, Statement* statement, int pos)
|
|
|
|
: Statement(zone, pos),
|
2013-10-14 09:24:58 +00:00
|
|
|
scope_(scope),
|
2013-04-26 11:55:22 +00:00
|
|
|
expression_(expression),
|
2012-02-08 09:56:33 +00:00
|
|
|
statement_(statement) { }
|
2008-12-18 11:28:13 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2013-04-26 11:55:22 +00:00
|
|
|
Scope* scope_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* expression_;
|
2011-08-12 10:52:49 +00:00
|
|
|
Statement* statement_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-12-18 11:44:38 +00:00
|
|
|
class CaseClause V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-10-14 11:06:15 +00:00
|
|
|
DECLARE_NODE_TYPE(CaseClause)
|
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
|
|
|
|
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_; }
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* compare_type() { return compare_type_; }
|
|
|
|
void set_compare_type(Type* type) { compare_type_ = type; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-01-21 16:22:52 +00:00
|
|
|
CaseClause(Zone* zone,
|
2013-10-14 11:06:15 +00:00
|
|
|
Expression* label,
|
|
|
|
ZoneList<Statement*>* statements,
|
|
|
|
int pos);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* label_;
|
2011-04-07 14:42:37 +00:00
|
|
|
Label body_target_;
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Statement*>* statements_;
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* compare_type_;
|
2013-06-12 17:20:37 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
const TypeFeedbackId compare_id_;
|
|
|
|
const BailoutId entry_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class SwitchStatement V8_FINAL : public BreakableStatement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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:
|
2014-06-24 14:03:24 +00:00
|
|
|
SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
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.
|
2013-08-20 11:10:24 +00:00
|
|
|
class IfStatement V8_FINAL : public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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_; }
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual bool IsJump() const V8_OVERRIDE {
|
2013-08-06 12:57:23 +00:00
|
|
|
return HasThenStatement() && then_statement()->IsJump()
|
|
|
|
&& HasElseStatement() && else_statement()->IsJump();
|
|
|
|
}
|
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
IfStatement(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Expression* condition,
|
|
|
|
Statement* then_statement,
|
2013-10-14 09:24:58 +00:00
|
|
|
Statement* else_statement,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Statement(zone, pos),
|
2013-10-14 09:24:58 +00:00
|
|
|
condition_(condition),
|
2012-02-08 09:56:33 +00:00
|
|
|
then_statement_(then_statement),
|
|
|
|
else_statement_(else_statement),
|
2014-01-21 16:22:52 +00:00
|
|
|
if_id_(GetNextId(zone)),
|
|
|
|
then_id_(GetNextId(zone)),
|
|
|
|
else_id_(GetNextId(zone)) {
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2013-08-20 11:10:24 +00:00
|
|
|
class TargetCollector V8_FINAL : public AstNode {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-10-14 09:24:58 +00:00
|
|
|
explicit TargetCollector(Zone* zone)
|
|
|
|
: AstNode(RelocInfo::kNoPosition), 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.
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void Accept(AstVisitor* v) V8_OVERRIDE { UNREACHABLE(); }
|
|
|
|
virtual NodeType node_type() const V8_OVERRIDE { return kInvalid; }
|
|
|
|
virtual TargetCollector* AsTargetCollector() V8_OVERRIDE { 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class TryStatement : public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
TryStatement(Zone* zone, int index, Block* try_block, int pos)
|
|
|
|
: Statement(zone, pos),
|
2013-10-14 09:24:58 +00:00
|
|
|
index_(index),
|
2012-02-08 09:56:33 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class TryCatchStatement V8_FINAL : 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:
|
2014-01-21 16:22:52 +00:00
|
|
|
TryCatchStatement(Zone* zone,
|
|
|
|
int index,
|
2011-11-11 13:48:14 +00:00
|
|
|
Block* try_block,
|
2011-06-30 14:37:55 +00:00
|
|
|
Scope* scope,
|
|
|
|
Variable* variable,
|
2013-10-14 09:24:58 +00:00
|
|
|
Block* catch_block,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: TryStatement(zone, index, try_block, pos),
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class TryFinallyStatement V8_FINAL : 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:
|
2013-10-14 09:24:58 +00:00
|
|
|
TryFinallyStatement(
|
2014-01-21 16:22:52 +00:00
|
|
|
Zone* zone, int index, Block* try_block, Block* finally_block, int pos)
|
|
|
|
: TryStatement(zone, index, try_block, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
finally_block_(finally_block) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Block* finally_block_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class DebuggerStatement V8_FINAL : public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(DebuggerStatement)
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit DebuggerStatement(Zone* zone, int pos): Statement(zone, pos) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class EmptyStatement V8_FINAL : public Statement {
|
2008-07-03 15:10:15 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Literal V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Literal)
|
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool IsPropertyName() const V8_OVERRIDE {
|
2014-06-24 14:03:24 +00:00
|
|
|
return value_->IsPropertyName();
|
2010-01-12 08:48:26 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<String> AsPropertyName() {
|
|
|
|
ASSERT(IsPropertyName());
|
2014-06-24 14:03:24 +00:00
|
|
|
return Handle<String>::cast(value());
|
|
|
|
}
|
|
|
|
|
|
|
|
const AstRawString* AsRawPropertyName() {
|
|
|
|
ASSERT(IsPropertyName());
|
|
|
|
return value_->AsString();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool ToBooleanIsTrue() const V8_OVERRIDE {
|
2014-06-24 14:03:24 +00:00
|
|
|
return value()->BooleanValue();
|
2013-08-20 11:10:24 +00:00
|
|
|
}
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool ToBooleanIsFalse() const V8_OVERRIDE {
|
2014-06-24 14:03:24 +00:00
|
|
|
return !value()->BooleanValue();
|
2013-08-20 11:10:24 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<Object> value() const { return value_->value(); }
|
|
|
|
const AstValue* raw_value() const { return value_; }
|
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();
|
2014-04-11 07:27:25 +00:00
|
|
|
return String::Equals(s1, s2);
|
2012-03-09 08:34:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
Literal(Zone* zone, const AstValue* value, int position)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, position),
|
2013-09-02 09:27:27 +00:00
|
|
|
value_(value),
|
2014-01-21 16:22:52 +00:00
|
|
|
isolate_(zone->isolate()) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2012-03-09 08:34:35 +00:00
|
|
|
Handle<String> ToString();
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstValue* value_;
|
2013-09-02 09:27:27 +00:00
|
|
|
// TODO(dcarney): remove. this is only needed for Match and Hash.
|
|
|
|
Isolate* isolate_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Base class for literals that needs space in the corresponding JSFunction.
|
2013-08-20 11:10:24 +00:00
|
|
|
class MaterializedLiteral : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
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
|
|
|
|
2013-11-20 14:17:47 +00:00
|
|
|
int depth() const {
|
|
|
|
// only callable after initialization.
|
|
|
|
ASSERT(depth_ >= 1);
|
|
|
|
return depth_;
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
MaterializedLiteral(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
int literal_index,
|
2013-10-14 09:24:58 +00:00
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
literal_index_(literal_index),
|
2013-11-20 14:17:47 +00:00
|
|
|
is_simple_(false),
|
|
|
|
depth_(0) {}
|
2013-11-07 12:08:37 +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_; }
|
|
|
|
void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
|
|
|
|
friend class CompileTimeValue;
|
|
|
|
|
2013-11-20 14:17:47 +00:00
|
|
|
void set_depth(int depth) {
|
|
|
|
ASSERT(depth >= 1);
|
|
|
|
depth_ = depth;
|
|
|
|
}
|
|
|
|
|
2013-11-07 12:08:37 +00:00
|
|
|
// Populate the constant properties/elements fixed array.
|
2013-11-20 14:17:47 +00:00
|
|
|
void BuildConstants(Isolate* isolate);
|
2013-11-07 12:08:37 +00:00
|
|
|
friend class ArrayLiteral;
|
|
|
|
friend class ObjectLiteral;
|
|
|
|
|
|
|
|
// If the expression is a literal, return the literal value;
|
|
|
|
// if the expression is a materialized literal and is simple return a
|
|
|
|
// compile time value as encoded by CompileTimeValue::GetValue().
|
|
|
|
// Otherwise, return undefined literal as the placeholder
|
|
|
|
// in the object literal boilerplate.
|
|
|
|
Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
|
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_;
|
2013-11-20 14:17:47 +00:00
|
|
|
int depth_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
// Property is used for passing information
|
|
|
|
// about an object literal's properties from the parser
|
|
|
|
// to the code generator.
|
2013-08-20 11:10:24 +00:00
|
|
|
class ObjectLiteralProperty V8_FINAL : public ZoneObject {
|
2013-05-27 13:59:20 +00:00
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
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__.
|
|
|
|
};
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
ObjectLiteralProperty(Zone* zone, AstValueFactory* ast_value_factory,
|
|
|
|
Literal* key, Expression* value);
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
Literal* key() { return key_; }
|
|
|
|
Expression* value() { return value_; }
|
|
|
|
Kind kind() { return kind_; }
|
|
|
|
|
|
|
|
// Type feedback information.
|
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
|
|
|
|
bool IsMonomorphic() { return !receiver_type_.is_null(); }
|
|
|
|
Handle<Map> GetReceiverType() { return receiver_type_; }
|
|
|
|
|
|
|
|
bool IsCompileTimeValue();
|
|
|
|
|
|
|
|
void set_emit_store(bool emit_store);
|
|
|
|
bool emit_store();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
template<class> friend class AstNodeFactory;
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value);
|
2013-05-27 13:59:20 +00:00
|
|
|
void set_key(Literal* key) { key_ = key; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Literal* key_;
|
|
|
|
Expression* value_;
|
|
|
|
Kind kind_;
|
|
|
|
bool emit_store_;
|
|
|
|
Handle<Map> receiver_type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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.
|
2013-08-20 11:10:24 +00:00
|
|
|
class ObjectLiteral V8_FINAL : public MaterializedLiteral {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-05-27 13:59:20 +00:00
|
|
|
typedef ObjectLiteralProperty Property;
|
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_; }
|
2013-05-08 15:02:08 +00:00
|
|
|
bool may_store_doubles() const { return may_store_doubles_; }
|
|
|
|
bool has_function() const { return has_function_; }
|
2010-10-27 11:37:59 +00:00
|
|
|
|
2013-11-07 12:08:37 +00:00
|
|
|
// Decide if a property should be in the object boilerplate.
|
|
|
|
static bool IsBoilerplateProperty(Property* property);
|
|
|
|
|
|
|
|
// Populate the constant properties fixed array.
|
2013-11-20 14:17:47 +00:00
|
|
|
void BuildConstantProperties(Isolate* isolate);
|
2013-11-07 12:08:37 +00:00
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
ObjectLiteral(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
ZoneList<Property*>* properties,
|
|
|
|
int literal_index,
|
2013-11-07 12:08:37 +00:00
|
|
|
int boilerplate_properties,
|
2013-10-14 09:24:58 +00:00
|
|
|
bool has_function,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: MaterializedLiteral(zone, literal_index, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
properties_(properties),
|
2013-11-07 12:08:37 +00:00
|
|
|
boilerplate_properties_(boilerplate_properties),
|
|
|
|
fast_elements_(false),
|
|
|
|
may_store_doubles_(false),
|
2012-02-08 09:56:33 +00:00
|
|
|
has_function_(has_function) {}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Handle<FixedArray> constant_properties_;
|
|
|
|
ZoneList<Property*>* properties_;
|
2013-11-07 12:08:37 +00:00
|
|
|
int boilerplate_properties_;
|
2010-03-11 10:34:29 +00:00
|
|
|
bool fast_elements_;
|
2013-05-08 15:02:08 +00:00
|
|
|
bool may_store_doubles_;
|
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.
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpLiteral V8_FINAL : public MaterializedLiteral {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(RegExpLiteral)
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> pattern() const { return pattern_->string(); }
|
|
|
|
Handle<String> flags() const { return flags_->string(); }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
RegExpLiteral(Zone* zone,
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* pattern,
|
|
|
|
const AstRawString* flags,
|
2013-10-14 09:24:58 +00:00
|
|
|
int literal_index,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: MaterializedLiteral(zone, literal_index, pos),
|
2008-07-03 15:10:15 +00:00
|
|
|
pattern_(pattern),
|
2013-11-20 14:17:47 +00:00
|
|
|
flags_(flags) {
|
|
|
|
set_depth(1);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* pattern_;
|
|
|
|
const AstRawString* flags_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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.
|
2013-08-20 11:10:24 +00:00
|
|
|
class ArrayLiteral V8_FINAL : 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
|
|
|
|
2013-11-07 12:08:37 +00:00
|
|
|
// Populate the constant elements fixed array.
|
2013-11-20 14:17:47 +00:00
|
|
|
void BuildConstantElements(Isolate* isolate);
|
2013-11-07 12:08:37 +00:00
|
|
|
|
2013-11-25 12:41:27 +00:00
|
|
|
enum Flags {
|
|
|
|
kNoFlags = 0,
|
|
|
|
kShallowElements = 1,
|
|
|
|
kDisableMementos = 1 << 1
|
|
|
|
};
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
ArrayLiteral(Zone* zone,
|
2009-03-23 07:27:47 +00:00
|
|
|
ZoneList<Expression*>* values,
|
|
|
|
int literal_index,
|
2013-10-14 09:24:58 +00:00
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: MaterializedLiteral(zone, literal_index, pos),
|
2010-12-07 11:31:57 +00:00
|
|
|
values_(values),
|
2014-01-21 16:22:52 +00:00
|
|
|
first_element_id_(ReserveIdRange(zone, 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class VariableProxy V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(VariableProxy)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool IsValidReferenceExpression() const V8_OVERRIDE {
|
|
|
|
return var_ == NULL ? true : var_->IsValidReference();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-06-24 08:01:38 +00:00
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
bool IsArguments() const { return var_ != NULL && var_->is_arguments(); }
|
2009-06-24 08:01:38 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> name() const { return name_->string(); }
|
|
|
|
const AstRawString* raw_name() const { return name_; }
|
2010-09-24 08:25:31 +00:00
|
|
|
Variable* var() const { return var_; }
|
|
|
|
bool is_this() const { return is_this_; }
|
2012-03-08 13:03:07 +00:00
|
|
|
Interface* interface() const { return interface_; }
|
|
|
|
|
2014-06-26 11:59:42 +00:00
|
|
|
bool is_assigned() const { return is_assigned_; }
|
|
|
|
void set_is_assigned() { is_assigned_ = true; }
|
2010-03-16 10:54:02 +00:00
|
|
|
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
// Bind this proxy to the variable var. Interfaces must match.
|
2008-07-03 15:10:15 +00:00
|
|
|
void BindTo(Variable* var);
|
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
VariableProxy(Zone* zone, Variable* var, int position);
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
VariableProxy(Zone* zone,
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name,
|
2012-02-08 09:56:33 +00:00
|
|
|
bool is_this,
|
2012-07-13 09:29:43 +00:00
|
|
|
Interface* interface,
|
|
|
|
int position);
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Variable* var_; // resolved variable, or NULL
|
|
|
|
bool is_this_;
|
2014-06-26 11:59:42 +00:00
|
|
|
bool is_assigned_;
|
2012-03-08 13:03:07 +00:00
|
|
|
Interface* interface_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Property V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(Property)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool IsValidReferenceExpression() const V8_OVERRIDE { return true; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Expression* obj() const { return obj_; }
|
|
|
|
Expression* key() const { return key_; }
|
|
|
|
|
2012-08-07 14:06:25 +00:00
|
|
|
BailoutId LoadId() const { return load_id_; }
|
2012-07-30 10:42:21 +00:00
|
|
|
|
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.
|
2013-12-12 14:57:00 +00:00
|
|
|
virtual bool IsMonomorphic() V8_OVERRIDE {
|
|
|
|
return receiver_types_.length() == 1;
|
|
|
|
}
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE {
|
|
|
|
return &receiver_types_;
|
|
|
|
}
|
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() V8_OVERRIDE {
|
2013-03-20 10:37:13 +00:00
|
|
|
return STANDARD_STORE;
|
|
|
|
}
|
2014-02-05 15:44:20 +00:00
|
|
|
bool IsUninitialized() { return !is_for_call_ && is_uninitialized_; }
|
2013-10-23 10:41:21 +00:00
|
|
|
bool HasNoTypeInformation() {
|
2014-01-31 16:52:17 +00:00
|
|
|
return is_uninitialized_;
|
2013-10-23 10:41:21 +00:00
|
|
|
}
|
2013-11-28 15:25:38 +00:00
|
|
|
void set_is_uninitialized(bool b) { is_uninitialized_ = b; }
|
|
|
|
void set_is_string_access(bool b) { is_string_access_ = b; }
|
|
|
|
void set_is_function_prototype(bool b) { is_function_prototype_ = b; }
|
2014-01-31 16:52:17 +00:00
|
|
|
void mark_for_call() { is_for_call_ = true; }
|
|
|
|
bool IsForCall() { return is_for_call_; }
|
2013-11-28 15:25:38 +00:00
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
Property(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Expression* obj,
|
|
|
|
Expression* key,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
obj_(obj),
|
|
|
|
key_(key),
|
2014-01-21 16:22:52 +00:00
|
|
|
load_id_(GetNextId(zone)),
|
2014-01-31 16:52:17 +00:00
|
|
|
is_for_call_(false),
|
2012-03-19 15:54:37 +00:00
|
|
|
is_uninitialized_(false),
|
2012-02-08 09:56:33 +00:00
|
|
|
is_string_access_(false),
|
|
|
|
is_function_prototype_(false) { }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* obj_;
|
|
|
|
Expression* key_;
|
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_;
|
2014-01-31 16:52:17 +00:00
|
|
|
bool is_for_call_ : 1;
|
2012-03-19 15:54:37 +00:00
|
|
|
bool is_uninitialized_ : 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
class Call V8_FINAL : public Expression, public FeedbackSlotInterface {
|
2008-07-03 15:10:15 +00:00
|
|
|
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_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
// Type feedback information.
|
2014-04-30 10:51:01 +00:00
|
|
|
virtual int ComputeFeedbackSlotCount() { return 1; }
|
2014-02-10 21:38:17 +00:00
|
|
|
virtual void SetFirstFeedbackSlot(int slot) {
|
|
|
|
call_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasCallFeedbackSlot() const {
|
|
|
|
return call_feedback_slot_ != kInvalidFeedbackSlot;
|
|
|
|
}
|
|
|
|
int CallFeedbackSlot() const { return call_feedback_slot_; }
|
2013-03-12 17:01:03 +00:00
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE {
|
|
|
|
if (expression()->IsProperty()) {
|
|
|
|
return expression()->AsProperty()->GetReceiverTypes();
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-03-12 17:01:03 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
virtual bool IsMonomorphic() V8_OVERRIDE {
|
|
|
|
if (expression()->IsProperty()) {
|
|
|
|
return expression()->AsProperty()->IsMonomorphic();
|
|
|
|
}
|
|
|
|
return !target_.is_null();
|
2013-03-12 17:01:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 13:59:24 +00:00
|
|
|
bool global_call() const {
|
|
|
|
VariableProxy* proxy = expression_->AsVariableProxy();
|
|
|
|
return proxy != NULL && proxy->var()->IsUnallocated();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool known_global_function() const {
|
|
|
|
return global_call() && !target_.is_null();
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSFunction> target() { return target_; }
|
2012-07-06 08:34:48 +00:00
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> cell() { return cell_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-05-26 13:59:24 +00:00
|
|
|
Handle<AllocationSite> allocation_site() { return allocation_site_; }
|
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
void set_target(Handle<JSFunction> target) { target_ = target; }
|
2014-05-26 13:59:24 +00:00
|
|
|
void set_allocation_site(Handle<AllocationSite> site) {
|
|
|
|
allocation_site_ = site;
|
|
|
|
}
|
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
|
|
|
|
2014-01-17 14:08:50 +00:00
|
|
|
enum CallType {
|
|
|
|
POSSIBLY_EVAL_CALL,
|
|
|
|
GLOBAL_CALL,
|
|
|
|
LOOKUP_SLOT_CALL,
|
|
|
|
PROPERTY_CALL,
|
|
|
|
OTHER_CALL
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helpers to determine how to handle the call.
|
|
|
|
CallType GetCallType(Isolate* isolate) const;
|
2014-04-30 10:51:01 +00:00
|
|
|
bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
|
2014-01-17 14:08:50 +00:00
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
Call(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
expression_(expression),
|
|
|
|
arguments_(arguments),
|
2014-02-10 21:38:17 +00:00
|
|
|
call_feedback_slot_(kInvalidFeedbackSlot),
|
2014-01-31 16:52:17 +00:00
|
|
|
return_id_(GetNextId(zone)) {
|
|
|
|
if (expression->IsProperty()) {
|
|
|
|
expression->AsProperty()->mark_for_call();
|
|
|
|
}
|
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
ZoneList<Expression*>* arguments_;
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSFunction> target_;
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> cell_;
|
2014-05-26 13:59:24 +00:00
|
|
|
Handle<AllocationSite> allocation_site_;
|
2014-02-10 21:38:17 +00:00
|
|
|
int call_feedback_slot_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
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
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
class CallNew V8_FINAL : public Expression, public FeedbackSlotInterface {
|
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_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
// Type feedback information.
|
2014-04-30 10:51:01 +00:00
|
|
|
virtual int ComputeFeedbackSlotCount() {
|
2014-03-19 13:39:09 +00:00
|
|
|
return FLAG_pretenuring_call_new ? 2 : 1;
|
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
virtual void SetFirstFeedbackSlot(int slot) {
|
|
|
|
callnew_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CallNewFeedbackSlot() {
|
|
|
|
ASSERT(callnew_feedback_slot_ != kInvalidFeedbackSlot);
|
|
|
|
return callnew_feedback_slot_;
|
|
|
|
}
|
2014-03-19 13:39:09 +00:00
|
|
|
int AllocationSiteFeedbackSlot() {
|
|
|
|
ASSERT(callnew_feedback_slot_ != kInvalidFeedbackSlot);
|
|
|
|
ASSERT(FLAG_pretenuring_call_new);
|
|
|
|
return callnew_feedback_slot_ + 1;
|
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; }
|
2013-05-27 13:59:20 +00:00
|
|
|
Handle<JSFunction> target() const { return target_; }
|
|
|
|
ElementsKind elements_kind() const { return elements_kind_; }
|
2014-01-20 09:48:05 +00:00
|
|
|
Handle<AllocationSite> allocation_site() const {
|
|
|
|
return allocation_site_;
|
2013-06-07 13:21:20 +00:00
|
|
|
}
|
2012-02-28 09:05:55 +00:00
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
static int feedback_slots() { return 1; }
|
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
CallNew(Zone* zone,
|
2011-07-18 17:32:41 +00:00
|
|
|
Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2011-07-18 17:32:41 +00:00
|
|
|
expression_(expression),
|
|
|
|
arguments_(arguments),
|
2012-02-28 09:05:55 +00:00
|
|
|
is_monomorphic_(false),
|
2013-05-27 13:59:20 +00:00
|
|
|
elements_kind_(GetInitialFastElementsKind()),
|
2014-02-10 21:38:17 +00:00
|
|
|
callnew_feedback_slot_(kInvalidFeedbackSlot),
|
2014-01-21 16:22:52 +00:00
|
|
|
return_id_(GetNextId(zone)) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-30 09:49:36 +00:00
|
|
|
private:
|
|
|
|
Expression* expression_;
|
|
|
|
ZoneList<Expression*>* arguments_;
|
2012-02-28 09:05:55 +00:00
|
|
|
|
|
|
|
bool is_monomorphic_;
|
|
|
|
Handle<JSFunction> target_;
|
2013-05-27 13:59:20 +00:00
|
|
|
ElementsKind elements_kind_;
|
2014-01-20 09:48:05 +00:00
|
|
|
Handle<AllocationSite> allocation_site_;
|
2014-02-10 21:38:17 +00:00
|
|
|
int callnew_feedback_slot_;
|
2012-02-28 09:05:55 +00:00
|
|
|
|
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").
|
2013-08-20 11:10:24 +00:00
|
|
|
class CallRuntime V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(CallRuntime)
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> name() const { return raw_name_->string(); }
|
|
|
|
const AstRawString* raw_name() const { return raw_name_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
CallRuntime(Zone* zone,
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name,
|
2011-03-18 20:35:07 +00:00
|
|
|
const Runtime::Function* function,
|
2013-10-14 09:24:58 +00:00
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2014-06-24 14:03:24 +00:00
|
|
|
raw_name_(name),
|
2011-07-18 17:32:41 +00:00
|
|
|
function_(function),
|
|
|
|
arguments_(arguments) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* raw_name_;
|
2011-03-18 20:35:07 +00:00
|
|
|
const Runtime::Function* function_;
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Expression*>* arguments_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class UnaryOperation V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(UnaryOperation)
|
|
|
|
|
|
|
|
Token::Value op() const { return op_; }
|
|
|
|
Expression* expression() const { return expression_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId MaterializeTrueId() { return materialize_true_id_; }
|
|
|
|
BailoutId MaterializeFalseId() { return materialize_false_id_; }
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void RecordToBooleanTypeFeedback(
|
|
|
|
TypeFeedbackOracle* oracle) V8_OVERRIDE;
|
2013-06-25 11:49:46 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
UnaryOperation(Zone* zone,
|
2011-07-18 17:32:41 +00:00
|
|
|
Token::Value op,
|
|
|
|
Expression* expression,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2011-11-02 16:53:32 +00:00
|
|
|
op_(op),
|
|
|
|
expression_(expression),
|
2014-01-21 16:22:52 +00:00
|
|
|
materialize_true_id_(GetNextId(zone)),
|
|
|
|
materialize_false_id_(GetNextId(zone)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(Token::IsUnaryOp(op));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Token::Value op_;
|
|
|
|
Expression* expression_;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class BinaryOperation V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(BinaryOperation)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
virtual bool ResultOverwriteAllowed() const V8_OVERRIDE;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Token::Value op() const { return op_; }
|
|
|
|
Expression* left() const { return left_; }
|
|
|
|
Expression* right() const { return right_; }
|
2014-01-02 15:31:27 +00:00
|
|
|
Handle<AllocationSite> allocation_site() const { return allocation_site_; }
|
|
|
|
void set_allocation_site(Handle<AllocationSite> allocation_site) {
|
|
|
|
allocation_site_ = allocation_site;
|
|
|
|
}
|
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()); }
|
2013-12-04 09:27:48 +00:00
|
|
|
Maybe<int> fixed_right_arg() const { return fixed_right_arg_; }
|
|
|
|
void set_fixed_right_arg(Maybe<int> arg) { fixed_right_arg_ = arg; }
|
2010-12-16 13:13:36 +00:00
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void RecordToBooleanTypeFeedback(
|
|
|
|
TypeFeedbackOracle* oracle) V8_OVERRIDE;
|
2013-06-25 11:49:46 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
BinaryOperation(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2012-07-20 09:39:27 +00:00
|
|
|
op_(op),
|
|
|
|
left_(left),
|
|
|
|
right_(right),
|
2014-01-21 16:22:52 +00:00
|
|
|
right_id_(GetNextId(zone)) {
|
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_;
|
2014-01-02 15:31:27 +00:00
|
|
|
Handle<AllocationSite> allocation_site_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2013-12-04 09:27:48 +00:00
|
|
|
// TODO(rossberg): the fixed arg should probably be represented as a Constant
|
|
|
|
// type for the RHS.
|
|
|
|
Maybe<int> fixed_right_arg_;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class CountOperation V8_FINAL : public Expression {
|
2010-08-24 12:56:45 +00:00
|
|
|
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_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-12-12 14:57:00 +00:00
|
|
|
virtual bool IsMonomorphic() V8_OVERRIDE {
|
|
|
|
return receiver_types_.length() == 1;
|
|
|
|
}
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE {
|
|
|
|
return &receiver_types_;
|
|
|
|
}
|
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() V8_OVERRIDE {
|
2013-03-20 10:37:13 +00:00
|
|
|
return store_mode_;
|
|
|
|
}
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* type() const { return type_; }
|
2013-11-28 13:16:51 +00:00
|
|
|
void set_store_mode(KeyedAccessStoreMode mode) { store_mode_ = mode; }
|
2014-01-21 16:22:52 +00:00
|
|
|
void set_type(Type* type) { type_ = type; }
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
CountOperation(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Token::Value op,
|
|
|
|
bool is_prefix,
|
|
|
|
Expression* expr,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
op_(op),
|
|
|
|
is_prefix_(is_prefix),
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode_(STANDARD_STORE),
|
2012-02-08 09:56:33 +00:00
|
|
|
expression_(expr),
|
2014-01-21 16:22:52 +00:00
|
|
|
assignment_id_(GetNextId(zone)),
|
|
|
|
count_id_(GetNextId(zone)) {}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-04-07 07:56:43 +00:00
|
|
|
Token::Value op_;
|
2013-03-20 10:37:13 +00:00
|
|
|
bool is_prefix_ : 1;
|
2013-04-09 16:26:30 +00:00
|
|
|
KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed,
|
|
|
|
// must have extra bit.
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* type_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2011-04-07 07:56:43 +00:00
|
|
|
Expression* expression_;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class CompareOperation V8_FINAL : 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_; }
|
|
|
|
|
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()); }
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* combined_type() const { return combined_type_; }
|
|
|
|
void set_combined_type(Type* type) { combined_type_ = type; }
|
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);
|
2013-07-17 14:10:38 +00:00
|
|
|
bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
CompareOperation(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
op_(op),
|
|
|
|
left_(left),
|
|
|
|
right_(right),
|
2014-01-21 16:22:52 +00:00
|
|
|
combined_type_(Type::None(zone)) {
|
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_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* combined_type_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Conditional V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
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_; }
|
|
|
|
|
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:
|
2014-01-21 16:22:52 +00:00
|
|
|
Conditional(Zone* zone,
|
2011-07-18 17:32:41 +00:00
|
|
|
Expression* condition,
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* then_expression,
|
2010-06-08 12:04:49 +00:00
|
|
|
Expression* else_expression,
|
2013-10-14 09:24:58 +00:00
|
|
|
int position)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, position),
|
2011-07-18 17:32:41 +00:00
|
|
|
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),
|
2014-01-21 16:22:52 +00:00
|
|
|
then_id_(GetNextId(zone)),
|
|
|
|
else_id_(GetNextId(zone)) { }
|
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_;
|
2012-08-06 14:13:09 +00:00
|
|
|
const BailoutId then_id_;
|
|
|
|
const BailoutId else_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Assignment V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
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_; }
|
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()); }
|
2013-12-12 14:57:00 +00:00
|
|
|
virtual bool IsMonomorphic() V8_OVERRIDE {
|
|
|
|
return receiver_types_.length() == 1;
|
|
|
|
}
|
2013-06-20 13:09:43 +00:00
|
|
|
bool IsUninitialized() { return is_uninitialized_; }
|
2013-10-23 10:41:21 +00:00
|
|
|
bool HasNoTypeInformation() {
|
2014-01-31 16:52:17 +00:00
|
|
|
return is_uninitialized_;
|
2013-10-23 10:41:21 +00:00
|
|
|
}
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE {
|
|
|
|
return &receiver_types_;
|
|
|
|
}
|
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() V8_OVERRIDE {
|
2013-03-20 10:37:13 +00:00
|
|
|
return store_mode_;
|
|
|
|
}
|
2013-12-02 13:49:32 +00:00
|
|
|
void set_is_uninitialized(bool b) { is_uninitialized_ = b; }
|
|
|
|
void set_store_mode(KeyedAccessStoreMode mode) { store_mode_ = mode; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
Assignment(Zone* zone,
|
2012-02-08 09:56:33 +00:00
|
|
|
Token::Value op,
|
|
|
|
Expression* target,
|
|
|
|
Expression* value,
|
|
|
|
int pos);
|
|
|
|
|
|
|
|
template<class Visitor>
|
2014-01-21 16:22:52 +00:00
|
|
|
void Init(Zone* zone, AstNodeFactory<Visitor>* factory) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ASSERT(Token::IsAssignmentOp(op_));
|
|
|
|
if (is_compound()) {
|
2013-10-14 09:24:58 +00:00
|
|
|
binary_operation_ = factory->NewBinaryOperation(
|
|
|
|
binary_op(), target_, value_, position() + 1);
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Token::Value op_;
|
|
|
|
Expression* target_;
|
|
|
|
Expression* value_;
|
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
|
|
|
|
2013-06-20 13:09:43 +00:00
|
|
|
bool is_uninitialized_ : 1;
|
2013-04-09 16:26:30 +00:00
|
|
|
KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed,
|
|
|
|
// must have extra bit.
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Yield V8_FINAL : public Expression {
|
2013-04-02 17:34:59 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(Yield)
|
|
|
|
|
2013-04-19 14:11:23 +00:00
|
|
|
enum Kind {
|
2013-08-20 06:39:04 +00:00
|
|
|
INITIAL, // The initial yield that returns the unboxed generator object.
|
|
|
|
SUSPEND, // A normal yield: { value: EXPRESSION, done: false }
|
|
|
|
DELEGATING, // A yield*.
|
|
|
|
FINAL // A return: { value: EXPRESSION, done: true }
|
2013-04-19 14:11:23 +00:00
|
|
|
};
|
|
|
|
|
2013-04-15 12:29:44 +00:00
|
|
|
Expression* generator_object() const { return generator_object_; }
|
2013-04-02 17:34:59 +00:00
|
|
|
Expression* expression() const { return expression_; }
|
2013-04-19 14:11:23 +00:00
|
|
|
Kind yield_kind() const { return yield_kind_; }
|
2013-04-02 17:34:59 +00:00
|
|
|
|
2013-05-14 16:26:56 +00:00
|
|
|
// Delegating yield surrounds the "yield" in a "try/catch". This index
|
|
|
|
// locates the catch handler in the handler table, and is equivalent to
|
|
|
|
// TryCatchStatement::index().
|
|
|
|
int index() const {
|
2013-08-20 06:39:04 +00:00
|
|
|
ASSERT(yield_kind() == DELEGATING);
|
2013-05-14 16:26:56 +00:00
|
|
|
return index_;
|
|
|
|
}
|
|
|
|
void set_index(int index) {
|
2013-08-20 06:39:04 +00:00
|
|
|
ASSERT(yield_kind() == DELEGATING);
|
2013-05-14 16:26:56 +00:00
|
|
|
index_ = index;
|
|
|
|
}
|
|
|
|
|
2013-04-02 17:34:59 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
Yield(Zone* zone,
|
2013-04-15 12:29:44 +00:00
|
|
|
Expression* generator_object,
|
2013-04-02 17:34:59 +00:00
|
|
|
Expression* expression,
|
2013-04-19 14:11:23 +00:00
|
|
|
Kind yield_kind,
|
2013-04-02 17:34:59 +00:00
|
|
|
int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos),
|
2013-04-15 12:29:44 +00:00
|
|
|
generator_object_(generator_object),
|
2013-04-02 17:34:59 +00:00
|
|
|
expression_(expression),
|
2013-04-19 14:11:23 +00:00
|
|
|
yield_kind_(yield_kind),
|
2013-10-14 09:24:58 +00:00
|
|
|
index_(-1) { }
|
2013-04-02 17:34:59 +00:00
|
|
|
|
|
|
|
private:
|
2013-04-15 12:29:44 +00:00
|
|
|
Expression* generator_object_;
|
2013-04-02 17:34:59 +00:00
|
|
|
Expression* expression_;
|
2013-04-19 14:11:23 +00:00
|
|
|
Kind yield_kind_;
|
2013-05-14 16:26:56 +00:00
|
|
|
int index_;
|
2013-04-02 17:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class Throw V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
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_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
Throw(Zone* zone, Expression* exception, int pos)
|
|
|
|
: Expression(zone, pos), exception_(exception) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Expression* exception_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class FunctionLiteral V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-06-06 13:28:22 +00:00
|
|
|
enum FunctionType {
|
2011-08-09 12:43:08 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2013-04-02 17:34:59 +00:00
|
|
|
enum IsGeneratorFlag {
|
|
|
|
kIsGenerator,
|
|
|
|
kNotGenerator
|
|
|
|
};
|
|
|
|
|
2014-06-17 07:23:26 +00:00
|
|
|
enum ArityRestriction {
|
|
|
|
NORMAL_ARITY,
|
|
|
|
GETTER_ARITY,
|
|
|
|
SETTER_ARITY
|
|
|
|
};
|
|
|
|
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(FunctionLiteral)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> name() const { return raw_name_->string(); }
|
|
|
|
const AstRawString* raw_name() const { return raw_name_; }
|
2010-09-24 08:25:31 +00:00
|
|
|
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_); }
|
2014-03-11 14:41:22 +00:00
|
|
|
StrictMode strict_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_; }
|
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
|
|
|
|
2014-01-09 09:00:19 +00:00
|
|
|
void InitializeSharedInfo(Handle<Code> code);
|
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
Handle<String> debug_name() const {
|
2014-06-24 14:03:24 +00:00
|
|
|
if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
|
|
|
|
return raw_name_->string();
|
|
|
|
}
|
2010-10-04 14:30:43 +00:00
|
|
|
return inferred_name();
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> inferred_name() const {
|
|
|
|
if (!inferred_name_.is_null()) {
|
|
|
|
ASSERT(raw_inferred_name_ == NULL);
|
|
|
|
return inferred_name_;
|
|
|
|
}
|
|
|
|
if (raw_inferred_name_ != NULL) {
|
|
|
|
return raw_inferred_name_->string();
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return Handle<String>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only one of {set_inferred_name, set_raw_inferred_name} should be called.
|
2009-04-14 00:51:59 +00:00
|
|
|
void set_inferred_name(Handle<String> inferred_name) {
|
2014-06-24 14:03:24 +00:00
|
|
|
ASSERT(!inferred_name.is_null());
|
2009-04-14 00:51:59 +00:00
|
|
|
inferred_name_ = inferred_name;
|
2014-06-24 14:03:24 +00:00
|
|
|
ASSERT(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
|
|
|
|
raw_inferred_name_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_raw_inferred_name(const AstString* raw_inferred_name) {
|
|
|
|
ASSERT(raw_inferred_name != NULL);
|
|
|
|
raw_inferred_name_ = raw_inferred_name;
|
|
|
|
ASSERT(inferred_name_.is_null());
|
|
|
|
inferred_name_ = Handle<String>();
|
2009-04-14 00:51:59 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 09:00:19 +00:00
|
|
|
// shared_info may be null if it's not cached in full code.
|
|
|
|
Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
|
|
|
|
|
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
|
|
|
|
2013-04-02 17:34:59 +00:00
|
|
|
bool is_generator() {
|
|
|
|
return IsGenerator::decode(bitfield_) == kIsGenerator;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
int slot_count() {
|
2014-04-30 10:51:01 +00:00
|
|
|
return ast_properties_.feedback_slots();
|
2014-02-10 21:38:17 +00:00
|
|
|
}
|
2013-09-05 13:20:51 +00:00
|
|
|
bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
|
|
|
|
BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
|
|
|
|
void set_dont_optimize_reason(BailoutReason reason) {
|
|
|
|
dont_optimize_reason_ = reason;
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
FunctionLiteral(Zone* zone,
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name,
|
|
|
|
AstValueFactory* ast_value_factory,
|
2012-02-08 09:56:33 +00:00
|
|
|
Scope* scope,
|
|
|
|
ZoneList<Statement*>* body,
|
|
|
|
int materialized_literal_count,
|
|
|
|
int expected_property_count,
|
|
|
|
int handler_count,
|
|
|
|
int parameter_count,
|
2013-06-06 13:28:22 +00:00
|
|
|
FunctionType function_type,
|
2012-02-14 14:14:51 +00:00
|
|
|
ParameterFlag has_duplicate_parameters,
|
2012-08-07 14:47:36 +00:00
|
|
|
IsFunctionFlag is_function,
|
2013-04-02 17:34:59 +00:00
|
|
|
IsParenthesizedFlag is_parenthesized,
|
2013-10-14 09:24:58 +00:00
|
|
|
IsGeneratorFlag is_generator,
|
|
|
|
int position)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, position),
|
2014-06-24 14:03:24 +00:00
|
|
|
raw_name_(name),
|
2012-02-08 09:56:33 +00:00
|
|
|
scope_(scope),
|
|
|
|
body_(body),
|
2014-06-24 14:03:24 +00:00
|
|
|
raw_inferred_name_(ast_value_factory->empty_string()),
|
2013-09-05 13:20:51 +00:00
|
|
|
dont_optimize_reason_(kNoReason),
|
2012-02-08 09:56:33 +00:00
|
|
|
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_ =
|
2013-06-06 13:28:22 +00:00
|
|
|
IsExpression::encode(function_type != DECLARATION) |
|
|
|
|
IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
|
2012-02-08 09:56:33 +00:00
|
|
|
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) |
|
2013-04-02 17:34:59 +00:00
|
|
|
IsParenthesized::encode(is_parenthesized) |
|
|
|
|
IsGenerator::encode(is_generator);
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* raw_name_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> name_;
|
2014-01-09 09:00:19 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Scope* scope_;
|
|
|
|
ZoneList<Statement*>* body_;
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstString* raw_inferred_name_;
|
2011-11-09 13:54:26 +00:00
|
|
|
Handle<String> inferred_name_;
|
2012-02-08 09:56:33 +00:00
|
|
|
AstProperties ast_properties_;
|
2013-09-05 13:20:51 +00:00
|
|
|
BailoutReason dont_optimize_reason_;
|
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_;
|
2013-06-05 08:43:25 +00:00
|
|
|
class IsExpression: public BitField<bool, 0, 1> {};
|
|
|
|
class IsAnonymous: public BitField<bool, 1, 1> {};
|
|
|
|
class Pretenure: public BitField<bool, 2, 1> {};
|
|
|
|
class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {};
|
|
|
|
class IsFunction: public BitField<IsFunctionFlag, 4, 1> {};
|
|
|
|
class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {};
|
|
|
|
class IsGenerator: public BitField<IsGeneratorFlag, 6, 1> {};
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-01 09:47:37 +00:00
|
|
|
class NativeFunctionLiteral V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-10-01 09:47:37 +00:00
|
|
|
DECLARE_NODE_TYPE(NativeFunctionLiteral)
|
2010-09-29 07:51:47 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Handle<String> name() const { return name_->string(); }
|
2013-10-01 09:47:37 +00:00
|
|
|
v8::Extension* extension() const { return extension_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2014-06-24 14:03:24 +00:00
|
|
|
NativeFunctionLiteral(Zone* zone, const AstRawString* name,
|
|
|
|
v8::Extension* extension, int pos)
|
2014-01-21 16:22:52 +00:00
|
|
|
: Expression(zone, pos), name_(name), extension_(extension) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name_;
|
2013-10-01 09:47:37 +00:00
|
|
|
v8::Extension* extension_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class ThisFunction V8_FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2010-09-29 07:51:47 +00:00
|
|
|
DECLARE_NODE_TYPE(ThisFunction)
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit ThisFunction(Zone* zone, int pos): Expression(zone, pos) {}
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpTree : public ZoneObject {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
2008-12-17 12:08:27 +00:00
|
|
|
static const int kInfinity = kMaxInt;
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual ~RegExpTree() {}
|
2008-11-25 11:07:48 +00:00
|
|
|
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);
|
2014-07-07 09:57:29 +00:00
|
|
|
OStream& Print(OStream& os, Zone* zone); // NOLINT
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpDisjunction V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
2008-12-17 10:59:14 +00:00
|
|
|
explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpDisjunction* AsDisjunction() V8_OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() V8_OVERRIDE;
|
|
|
|
virtual bool IsDisjunction() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return min_match_; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpAlternative V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
2008-12-17 10:59:14 +00:00
|
|
|
explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpAlternative* AsAlternative() V8_OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() V8_OVERRIDE;
|
|
|
|
virtual bool IsAlternative() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return min_match_; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpAssertion V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
2013-06-06 13:28:22 +00:00
|
|
|
enum AssertionType {
|
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
|
|
|
};
|
2013-06-06 13:28:22 +00:00
|
|
|
explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpAssertion* AsAssertion() V8_OVERRIDE;
|
|
|
|
virtual bool IsAssertion() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { return 0; }
|
2013-06-06 13:28:22 +00:00
|
|
|
AssertionType assertion_type() { return assertion_type_; }
|
2008-11-25 11:07:48 +00:00
|
|
|
private:
|
2013-06-06 13:28:22 +00:00
|
|
|
AssertionType assertion_type_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class CharacterSet V8_FINAL BASE_EMBEDDED {
|
2009-01-02 12:23:17 +00:00
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpCharacterClass V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
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) { }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpCharacterClass* AsCharacterClass() V8_OVERRIDE;
|
|
|
|
virtual bool IsCharacterClass() V8_OVERRIDE;
|
|
|
|
virtual bool IsTextElement() V8_OVERRIDE { return true; }
|
|
|
|
virtual int min_match() V8_OVERRIDE { return 1; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { return 1; }
|
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone) V8_OVERRIDE;
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpAtom V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
|
|
|
explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpAtom* AsAtom() V8_OVERRIDE;
|
|
|
|
virtual bool IsAtom() V8_OVERRIDE;
|
|
|
|
virtual bool IsTextElement() V8_OVERRIDE { return true; }
|
|
|
|
virtual int min_match() V8_OVERRIDE { return data_.length(); }
|
|
|
|
virtual int max_match() V8_OVERRIDE { return data_.length(); }
|
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone) V8_OVERRIDE;
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpText V8_FINAL : public RegExpTree {
|
2008-12-17 10:59:14 +00:00
|
|
|
public:
|
2012-06-11 12:42:31 +00:00
|
|
|
explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpText* AsText() V8_OVERRIDE;
|
|
|
|
virtual bool IsText() V8_OVERRIDE;
|
|
|
|
virtual bool IsTextElement() V8_OVERRIDE { return true; }
|
|
|
|
virtual int min_match() V8_OVERRIDE { return length_; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { return length_; }
|
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone) V8_OVERRIDE;
|
2012-06-11 12:42:31 +00:00
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpQuantifier V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
2013-06-06 13:28:22 +00:00
|
|
|
enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
|
|
|
|
RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
|
2010-01-07 19:01:23 +00:00
|
|
|
: 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()),
|
2013-06-06 13:28:22 +00:00
|
|
|
quantifier_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();
|
|
|
|
}
|
|
|
|
}
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
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);
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual RegExpQuantifier* AsQuantifier() V8_OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() V8_OVERRIDE;
|
|
|
|
virtual bool IsQuantifier() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return min_match_; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { return max_match_; }
|
2008-11-25 11:07:48 +00:00
|
|
|
int min() { return min_; }
|
|
|
|
int max() { return max_; }
|
2013-06-06 13:28:22 +00:00
|
|
|
bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
|
|
|
|
bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
|
|
|
|
bool is_greedy() { return quantifier_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_;
|
2013-06-06 13:28:22 +00:00
|
|
|
QuantifierType quantifier_type_;
|
2008-11-25 11:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpCapture V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
|
|
|
explicit RegExpCapture(RegExpTree* body, int index)
|
2009-07-03 08:18:35 +00:00
|
|
|
: body_(body), index_(index) { }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
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);
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual RegExpCapture* AsCapture() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() V8_OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() V8_OVERRIDE;
|
|
|
|
virtual bool IsCapture() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return body_->min_match(); }
|
|
|
|
virtual int max_match() V8_OVERRIDE { 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpLookahead V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
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) { }
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpLookahead* AsLookahead() V8_OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() V8_OVERRIDE;
|
|
|
|
virtual bool IsLookahead() V8_OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpBackReference V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
|
|
|
explicit RegExpBackReference(RegExpCapture* capture)
|
2008-11-26 08:03:55 +00:00
|
|
|
: capture_(capture) { }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpBackReference* AsBackReference() V8_OVERRIDE;
|
|
|
|
virtual bool IsBackReference() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { return capture_->max_match(); }
|
2008-11-25 11:07:48 +00:00
|
|
|
int index() { return capture_->index(); }
|
|
|
|
RegExpCapture* capture() { return capture_; }
|
|
|
|
private:
|
|
|
|
RegExpCapture* capture_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
class RegExpEmpty V8_FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
|
|
|
RegExpEmpty() { }
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) V8_OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2013-08-20 11:10:24 +00:00
|
|
|
RegExpNode* on_success) V8_OVERRIDE;
|
|
|
|
virtual RegExpEmpty* AsEmpty() V8_OVERRIDE;
|
|
|
|
virtual bool IsEmpty() V8_OVERRIDE;
|
|
|
|
virtual int min_match() V8_OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() V8_OVERRIDE { 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).
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
inline ModuleVariable::ModuleVariable(Zone* zone, VariableProxy* proxy, int pos)
|
|
|
|
: Module(zone, proxy->interface(), pos),
|
2012-03-08 13:03:07 +00:00
|
|
|
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:
|
2012-12-18 16:25:45 +00:00
|
|
|
AstVisitor() {}
|
2013-08-20 11:10:24 +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.
|
2012-12-18 16:25:45 +00:00
|
|
|
virtual void Visit(AstNode* node) = 0;
|
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);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// 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
|
2012-12-18 16:25:45 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-21 11:57:59 +00:00
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
|
|
|
|
public: \
|
2014-01-21 16:22:52 +00:00
|
|
|
virtual void Visit(AstNode* node) V8_FINAL V8_OVERRIDE { \
|
2012-12-18 16:25:45 +00:00
|
|
|
if (!CheckStackOverflow()) node->Accept(this); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void SetStackOverflow() { stack_overflow_ = true; } \
|
|
|
|
void ClearStackOverflow() { stack_overflow_ = false; } \
|
|
|
|
bool HasStackOverflow() const { return stack_overflow_; } \
|
|
|
|
\
|
|
|
|
bool CheckStackOverflow() { \
|
|
|
|
if (stack_overflow_) return true; \
|
2014-01-21 16:22:52 +00:00
|
|
|
StackLimitCheck check(zone_->isolate()); \
|
2012-12-18 16:25:45 +00:00
|
|
|
if (!check.HasOverflowed()) return false; \
|
|
|
|
return (stack_overflow_ = true); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
private: \
|
2014-01-21 16:22:52 +00:00
|
|
|
void InitializeAstVisitor(Zone* zone) { \
|
|
|
|
zone_ = zone; \
|
2012-12-18 16:25:45 +00:00
|
|
|
stack_overflow_ = false; \
|
|
|
|
} \
|
2014-01-21 16:22:52 +00:00
|
|
|
Zone* zone() { return zone_; } \
|
|
|
|
Isolate* isolate() { return zone_->isolate(); } \
|
2012-12-18 16:25:45 +00:00
|
|
|
\
|
2014-01-21 16:22:52 +00:00
|
|
|
Zone* zone_; \
|
2012-12-18 16:25:45 +00:00
|
|
|
bool stack_overflow_
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Construction time visitor.
|
|
|
|
|
|
|
|
class AstConstructionVisitor BASE_EMBEDDED {
|
|
|
|
public:
|
2014-04-30 12:35:41 +00:00
|
|
|
AstConstructionVisitor() : dont_optimize_reason_(kNoReason) { }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
AstProperties* ast_properties() { return &properties_; }
|
2013-09-05 13:20:51 +00:00
|
|
|
BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
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); }
|
2013-09-05 13:20:51 +00:00
|
|
|
void set_dont_optimize_reason(BailoutReason reason) {
|
|
|
|
dont_optimize_reason_ = reason;
|
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
void add_slot_node(FeedbackSlotInterface* slot_node) {
|
2014-04-30 10:51:01 +00:00
|
|
|
int count = slot_node->ComputeFeedbackSlotCount();
|
|
|
|
if (count > 0) {
|
|
|
|
slot_node->SetFirstFeedbackSlot(properties_.feedback_slots());
|
|
|
|
properties_.increase_feedback_slots(count);
|
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
AstProperties properties_;
|
2013-09-05 13:20:51 +00:00
|
|
|
BailoutReason dont_optimize_reason_;
|
2012-02-08 09:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
2013-08-20 11:10:24 +00:00
|
|
|
class AstNodeFactory V8_FINAL BASE_EMBEDDED {
|
2012-02-08 09:56:33 +00:00
|
|
|
public:
|
2014-06-24 14:03:24 +00:00
|
|
|
explicit AstNodeFactory(Zone* zone, AstValueFactory* ast_value_factory)
|
|
|
|
: zone_(zone), ast_value_factory_(ast_value_factory) {}
|
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,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos) {
|
2012-02-09 13:39:26 +00:00
|
|
|
VariableDeclaration* decl =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
|
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,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos) {
|
2012-02-28 10:12:39 +00:00
|
|
|
FunctionDeclaration* decl =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
|
2012-02-28 10:12:39 +00:00
|
|
|
VISIT_AND_RETURN(FunctionDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
|
|
|
|
Module* module,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos) {
|
2012-02-09 13:40:41 +00:00
|
|
|
ModuleDeclaration* decl =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) ModuleDeclaration(zone_, proxy, module, scope, pos);
|
2012-02-09 13:40:41 +00:00
|
|
|
VISIT_AND_RETURN(ModuleDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2012-02-29 12:12:52 +00:00
|
|
|
ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
|
|
|
|
Module* module,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos) {
|
2012-02-29 12:12:52 +00:00
|
|
|
ImportDeclaration* decl =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) ImportDeclaration(zone_, proxy, module, scope, pos);
|
2012-02-29 12:12:52 +00:00
|
|
|
VISIT_AND_RETURN(ImportDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
|
|
|
ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
|
2013-10-14 09:24:58 +00:00
|
|
|
Scope* scope,
|
|
|
|
int pos) {
|
2012-02-29 12:12:52 +00:00
|
|
|
ExportDeclaration* decl =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) ExportDeclaration(zone_, proxy, scope, pos);
|
2012-02-29 12:12:52 +00:00
|
|
|
VISIT_AND_RETURN(ExportDeclaration, decl)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleLiteral* module =
|
|
|
|
new(zone_) ModuleLiteral(zone_, body, interface, pos);
|
2012-02-09 13:40:41 +00:00
|
|
|
VISIT_AND_RETURN(ModuleLiteral, module)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleVariable* module = new(zone_) ModuleVariable(zone_, proxy, pos);
|
2012-02-20 14:02:59 +00:00
|
|
|
VISIT_AND_RETURN(ModuleVariable, module)
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) {
|
|
|
|
ModulePath* module = new (zone_) ModulePath(zone_, origin, name, pos);
|
2012-02-20 14:02:59 +00:00
|
|
|
VISIT_AND_RETURN(ModulePath, module)
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleUrl* module = new(zone_) ModuleUrl(zone_, url, pos);
|
2012-02-20 14:02:59 +00:00
|
|
|
VISIT_AND_RETURN(ModuleUrl, module)
|
2012-02-09 13:40:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Block* NewBlock(ZoneList<const AstRawString*>* labels,
|
2012-02-08 09:56:33 +00:00
|
|
|
int capacity,
|
2013-10-14 09:24:58 +00:00
|
|
|
bool is_initializer_block,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
Block* block = new(zone_) Block(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, labels, capacity, is_initializer_block, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Block, block)
|
|
|
|
}
|
|
|
|
|
|
|
|
#define STATEMENT_WITH_LABELS(NodeType) \
|
2014-06-24 14:03:24 +00:00
|
|
|
NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
|
2014-01-21 16:22:52 +00:00
|
|
|
NodeType* stmt = new(zone_) NodeType(zone_, labels, pos); \
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(NodeType, stmt); \
|
|
|
|
}
|
|
|
|
STATEMENT_WITH_LABELS(DoWhileStatement)
|
|
|
|
STATEMENT_WITH_LABELS(WhileStatement)
|
|
|
|
STATEMENT_WITH_LABELS(ForStatement)
|
|
|
|
STATEMENT_WITH_LABELS(SwitchStatement)
|
|
|
|
#undef STATEMENT_WITH_LABELS
|
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
|
2014-06-24 14:03:24 +00:00
|
|
|
ZoneList<const AstRawString*>* labels,
|
2013-10-14 09:24:58 +00:00
|
|
|
int pos) {
|
2013-06-06 14:38:26 +00:00
|
|
|
switch (visit_mode) {
|
|
|
|
case ForEachStatement::ENUMERATE: {
|
2014-01-21 16:22:52 +00:00
|
|
|
ForInStatement* stmt = new(zone_) ForInStatement(zone_, labels, pos);
|
2013-06-06 14:38:26 +00:00
|
|
|
VISIT_AND_RETURN(ForInStatement, stmt);
|
|
|
|
}
|
|
|
|
case ForEachStatement::ITERATE: {
|
2014-01-21 16:22:52 +00:00
|
|
|
ForOfStatement* stmt = new(zone_) ForOfStatement(zone_, labels, pos);
|
2013-06-06 14:38:26 +00:00
|
|
|
VISIT_AND_RETURN(ForOfStatement, stmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ModuleStatement* NewModuleStatement(
|
|
|
|
VariableProxy* proxy, Block* body, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ModuleStatement* stmt = new(zone_) ModuleStatement(zone_, proxy, body, pos);
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
VISIT_AND_RETURN(ModuleStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ExpressionStatement* stmt =
|
|
|
|
new(zone_) ExpressionStatement(zone_, expression, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ExpressionStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ContinueStatement* stmt = new(zone_) ContinueStatement(zone_, target, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ContinueStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
BreakStatement* stmt = new(zone_) BreakStatement(zone_, target, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(BreakStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ReturnStatement* stmt = new(zone_) ReturnStatement(zone_, expression, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ReturnStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-04-26 11:55:22 +00:00
|
|
|
WithStatement* NewWithStatement(Scope* scope,
|
|
|
|
Expression* expression,
|
2013-10-14 09:24:58 +00:00
|
|
|
Statement* statement,
|
|
|
|
int pos) {
|
2013-04-26 11:55:22 +00:00
|
|
|
WithStatement* stmt = new(zone_) WithStatement(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, scope, expression, statement, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(WithStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
IfStatement* NewIfStatement(Expression* condition,
|
|
|
|
Statement* then_statement,
|
2013-10-14 09:24:58 +00:00
|
|
|
Statement* else_statement,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
IfStatement* stmt = new(zone_) IfStatement(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, condition, then_statement, else_statement, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(IfStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
TryCatchStatement* NewTryCatchStatement(int index,
|
|
|
|
Block* try_block,
|
|
|
|
Scope* scope,
|
|
|
|
Variable* variable,
|
2013-10-14 09:24:58 +00:00
|
|
|
Block* catch_block,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
TryCatchStatement* stmt = new(zone_) TryCatchStatement(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, index, try_block, scope, variable, catch_block, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(TryCatchStatement, stmt)
|
|
|
|
}
|
|
|
|
|
|
|
|
TryFinallyStatement* NewTryFinallyStatement(int index,
|
|
|
|
Block* try_block,
|
2013-10-14 09:24:58 +00:00
|
|
|
Block* finally_block,
|
|
|
|
int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
TryFinallyStatement* stmt = new(zone_) TryFinallyStatement(
|
|
|
|
zone_, index, try_block, finally_block, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(TryFinallyStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
DebuggerStatement* NewDebuggerStatement(int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
DebuggerStatement* stmt = new(zone_) DebuggerStatement(zone_, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(DebuggerStatement, stmt)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
EmptyStatement* NewEmptyStatement(int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
return new(zone_) EmptyStatement(zone_, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 11:06:15 +00:00
|
|
|
CaseClause* NewCaseClause(
|
|
|
|
Expression* label, ZoneList<Statement*>* statements, int pos) {
|
|
|
|
CaseClause* clause =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) CaseClause(zone_, label, statements, pos);
|
2013-10-14 11:06:15 +00:00
|
|
|
VISIT_AND_RETURN(CaseClause, clause)
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
Literal* NewStringLiteral(const AstRawString* string, int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A JavaScript symbol (ECMA-262 edition 6).
|
|
|
|
Literal* NewSymbolLiteral(const char* name, int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
Literal* NewNumberLiteral(double number, int pos) {
|
2014-06-24 14:03:24 +00:00
|
|
|
Literal* lit = new (zone_)
|
|
|
|
Literal(zone_, ast_value_factory_->NewNumber(number), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewSmiLiteral(int number, int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewBooleanLiteral(bool b, int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewStringListLiteral(ZoneList<const AstRawString*>* strings,
|
|
|
|
int pos) {
|
|
|
|
Literal* lit = new (zone_)
|
|
|
|
Literal(zone_, ast_value_factory_->NewStringList(strings), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewNullLiteral(int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewUndefinedLiteral(int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewTheHoleLiteral(int pos) {
|
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
|
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectLiteral* NewObjectLiteral(
|
|
|
|
ZoneList<ObjectLiteral::Property*>* properties,
|
|
|
|
int literal_index,
|
2013-11-07 12:08:37 +00:00
|
|
|
int boilerplate_properties,
|
2013-10-14 09:24:58 +00:00
|
|
|
bool has_function,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ObjectLiteral* lit = new(zone_) ObjectLiteral(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, properties, literal_index, boilerplate_properties,
|
2013-11-07 12:08:37 +00:00
|
|
|
has_function, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ObjectLiteral, lit)
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key,
|
|
|
|
Expression* value) {
|
2014-06-24 14:03:24 +00:00
|
|
|
return new (zone_)
|
|
|
|
ObjectLiteral::Property(zone_, ast_value_factory_, key, value);
|
2014-01-21 16:22:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
|
2013-10-14 09:24:58 +00:00
|
|
|
FunctionLiteral* value,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ObjectLiteral::Property* prop =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) ObjectLiteral::Property(zone_, is_getter, value);
|
2014-06-24 14:03:24 +00:00
|
|
|
prop->set_key(NewStringLiteral(value->raw_name(), pos));
|
2012-02-08 09:56:33 +00:00
|
|
|
return prop; // Not an AST node, will not be visited.
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
|
|
|
|
const AstRawString* flags,
|
2013-10-14 09:24:58 +00:00
|
|
|
int literal_index,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
RegExpLiteral* lit =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(RegExpLiteral, lit);
|
|
|
|
}
|
|
|
|
|
2013-11-07 12:08:37 +00:00
|
|
|
ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
|
2012-02-08 09:56:33 +00:00
|
|
|
int literal_index,
|
2013-10-14 09:24:58 +00:00
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ArrayLiteral* lit = new(zone_) ArrayLiteral(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, values, literal_index, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ArrayLiteral, lit)
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
VariableProxy* NewVariableProxy(Variable* var,
|
|
|
|
int pos = RelocInfo::kNoPosition) {
|
2014-01-21 16:22:52 +00:00
|
|
|
VariableProxy* proxy = new(zone_) VariableProxy(zone_, var, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(VariableProxy, proxy)
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
VariableProxy* NewVariableProxy(const AstRawString* name,
|
2012-02-08 09:56:33 +00:00
|
|
|
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 =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) VariableProxy(zone_, 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) {
|
2014-01-21 16:22:52 +00:00
|
|
|
Property* prop = new(zone_) Property(zone_, obj, key, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Property, prop)
|
|
|
|
}
|
|
|
|
|
|
|
|
Call* NewCall(Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
Call* call = new(zone_) Call(zone_, expression, arguments, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Call, call)
|
|
|
|
}
|
|
|
|
|
|
|
|
CallNew* NewCallNew(Expression* expression,
|
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
CallNew* call = new(zone_) CallNew(zone_, expression, arguments, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(CallNew, call)
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
CallRuntime* NewCallRuntime(const AstRawString* name,
|
2012-02-08 09:56:33 +00:00
|
|
|
const Runtime::Function* function,
|
2013-10-14 09:24:58 +00:00
|
|
|
ZoneList<Expression*>* arguments,
|
|
|
|
int pos) {
|
2012-02-08 09:56:33 +00:00
|
|
|
CallRuntime* call =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) CallRuntime(zone_, name, function, arguments, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(CallRuntime, call)
|
|
|
|
}
|
|
|
|
|
|
|
|
UnaryOperation* NewUnaryOperation(Token::Value op,
|
|
|
|
Expression* expression,
|
|
|
|
int pos) {
|
|
|
|
UnaryOperation* node =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) UnaryOperation(zone_, op, expression, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(UnaryOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryOperation* NewBinaryOperation(Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos) {
|
|
|
|
BinaryOperation* node =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) BinaryOperation(zone_, op, left, right, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(BinaryOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
CountOperation* NewCountOperation(Token::Value op,
|
|
|
|
bool is_prefix,
|
|
|
|
Expression* expr,
|
|
|
|
int pos) {
|
|
|
|
CountOperation* node =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) CountOperation(zone_, op, is_prefix, expr, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(CountOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
CompareOperation* NewCompareOperation(Token::Value op,
|
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
int pos) {
|
|
|
|
CompareOperation* node =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) CompareOperation(zone_, op, left, right, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(CompareOperation, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
Conditional* NewConditional(Expression* condition,
|
|
|
|
Expression* then_expression,
|
|
|
|
Expression* else_expression,
|
2013-10-14 09:24:58 +00:00
|
|
|
int position) {
|
2012-02-08 09:56:33 +00:00
|
|
|
Conditional* cond = new(zone_) Conditional(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, condition, then_expression, else_expression, position);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Conditional, cond)
|
|
|
|
}
|
|
|
|
|
|
|
|
Assignment* NewAssignment(Token::Value op,
|
|
|
|
Expression* target,
|
|
|
|
Expression* value,
|
|
|
|
int pos) {
|
|
|
|
Assignment* assign =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) Assignment(zone_, op, target, value, pos);
|
|
|
|
assign->Init(zone_, this);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Assignment, assign)
|
|
|
|
}
|
|
|
|
|
2013-04-15 12:29:44 +00:00
|
|
|
Yield* NewYield(Expression *generator_object,
|
|
|
|
Expression* expression,
|
2013-04-19 14:11:23 +00:00
|
|
|
Yield::Kind yield_kind,
|
2013-04-15 12:29:44 +00:00
|
|
|
int pos) {
|
2014-07-02 13:48:28 +00:00
|
|
|
if (!expression) expression = NewUndefinedLiteral(pos);
|
2013-04-15 12:29:44 +00:00
|
|
|
Yield* yield = new(zone_) Yield(
|
2014-01-21 16:22:52 +00:00
|
|
|
zone_, generator_object, expression, yield_kind, pos);
|
2013-04-02 17:34:59 +00:00
|
|
|
VISIT_AND_RETURN(Yield, yield)
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
Throw* NewThrow(Expression* exception, int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
Throw* t = new(zone_) Throw(zone_, exception, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Throw, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionLiteral* NewFunctionLiteral(
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name,
|
|
|
|
AstValueFactory* ast_value_factory,
|
2012-02-08 09:56:33 +00:00
|
|
|
Scope* scope,
|
|
|
|
ZoneList<Statement*>* body,
|
|
|
|
int materialized_literal_count,
|
|
|
|
int expected_property_count,
|
|
|
|
int handler_count,
|
|
|
|
int parameter_count,
|
2012-02-14 14:14:51 +00:00
|
|
|
FunctionLiteral::ParameterFlag has_duplicate_parameters,
|
2013-06-06 13:28:22 +00:00
|
|
|
FunctionLiteral::FunctionType function_type,
|
2012-08-07 14:47:36 +00:00
|
|
|
FunctionLiteral::IsFunctionFlag is_function,
|
2013-04-02 17:34:59 +00:00
|
|
|
FunctionLiteral::IsParenthesizedFlag is_parenthesized,
|
2013-10-14 09:24:58 +00:00
|
|
|
FunctionLiteral::IsGeneratorFlag is_generator,
|
|
|
|
int position) {
|
2012-02-08 09:56:33 +00:00
|
|
|
FunctionLiteral* lit = new(zone_) FunctionLiteral(
|
2014-06-24 14:03:24 +00:00
|
|
|
zone_, name, ast_value_factory, scope, body,
|
2012-02-08 09:56:33 +00:00
|
|
|
materialized_literal_count, expected_property_count, handler_count,
|
2013-06-06 13:28:22 +00:00
|
|
|
parameter_count, function_type, has_duplicate_parameters, is_function,
|
2013-10-14 09:24:58 +00:00
|
|
|
is_parenthesized, is_generator, position);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:41:41 +00:00
|
|
|
NativeFunctionLiteral* NewNativeFunctionLiteral(
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* name, v8::Extension* extension,
|
|
|
|
int pos) {
|
2013-10-01 09:47:37 +00:00
|
|
|
NativeFunctionLiteral* lit =
|
2014-01-21 16:22:52 +00:00
|
|
|
new(zone_) NativeFunctionLiteral(zone_, name, extension, pos);
|
2013-10-01 09:47:37 +00:00
|
|
|
VISIT_AND_RETURN(NativeFunctionLiteral, lit)
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 09:24:58 +00:00
|
|
|
ThisFunction* NewThisFunction(int pos) {
|
2014-01-21 16:22:52 +00:00
|
|
|
ThisFunction* fun = new(zone_) ThisFunction(zone_, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ThisFunction, fun)
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VISIT_AND_RETURN
|
|
|
|
|
|
|
|
private:
|
|
|
|
Zone* zone_;
|
|
|
|
Visitor visitor_;
|
2014-06-24 14:03:24 +00:00
|
|
|
AstValueFactory* ast_value_factory_;
|
2012-02-08 09:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_AST_H_
|