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-09-24 07:08:27 +00:00
|
|
|
#include "src/bailout-reason.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/factory.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-09-25 07:16:15 +00:00
|
|
|
#include "src/runtime/runtime.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#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.
|
|
|
|
|
2014-09-16 22:15:39 +00:00
|
|
|
#define DECLARATION_NODE_LIST(V) \
|
|
|
|
V(VariableDeclaration) \
|
|
|
|
V(FunctionDeclaration) \
|
|
|
|
V(ModuleDeclaration) \
|
|
|
|
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)
|
|
|
|
|
2014-09-16 22:15:39 +00:00
|
|
|
#define EXPRESSION_NODE_LIST(V) \
|
|
|
|
V(FunctionLiteral) \
|
|
|
|
V(ClassLiteral) \
|
|
|
|
V(NativeFunctionLiteral) \
|
|
|
|
V(Conditional) \
|
|
|
|
V(VariableProxy) \
|
|
|
|
V(Literal) \
|
|
|
|
V(RegExpLiteral) \
|
|
|
|
V(ObjectLiteral) \
|
|
|
|
V(ArrayLiteral) \
|
|
|
|
V(Assignment) \
|
|
|
|
V(Yield) \
|
|
|
|
V(Throw) \
|
|
|
|
V(Property) \
|
|
|
|
V(Call) \
|
|
|
|
V(CallNew) \
|
|
|
|
V(CallRuntime) \
|
|
|
|
V(UnaryOperation) \
|
|
|
|
V(CountOperation) \
|
|
|
|
V(BinaryOperation) \
|
|
|
|
V(CompareOperation) \
|
|
|
|
V(ThisFunction) \
|
|
|
|
V(SuperReference) \
|
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) \
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void Accept(AstVisitor* v) OVERRIDE; \
|
|
|
|
virtual AstNode::NodeType node_type() const FINAL OVERRIDE { \
|
2013-08-20 11:10:24 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
class FeedbackVectorRequirements {
|
|
|
|
public:
|
|
|
|
FeedbackVectorRequirements(int slots, int ic_slots)
|
|
|
|
: slots_(slots), ic_slots_(ic_slots) {}
|
|
|
|
|
|
|
|
int slots() const { return slots_; }
|
|
|
|
int ic_slots() const { return ic_slots_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int slots_;
|
|
|
|
int ic_slots_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class AstProperties FINAL BASE_EMBEDDED {
|
2012-02-08 09:56:33 +00:00
|
|
|
public:
|
|
|
|
class Flags : public EnumSet<AstPropertiesFlag, int> {};
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
AstProperties() : node_count_(0), feedback_slots_(0), ic_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;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
int ic_feedback_slots() const { return ic_feedback_slots_; }
|
|
|
|
void increase_ic_feedback_slots(int count) { ic_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_;
|
2014-10-20 11:42:56 +00:00
|
|
|
int ic_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
|
|
|
|
2014-10-02 09:38:28 +00:00
|
|
|
// The interface for feedback slots, with default no-op implementations for
|
|
|
|
// node types which don't actually have this. Note that this is conceptually
|
|
|
|
// not really nice, but multiple inheritance would introduce yet another
|
|
|
|
// vtable entry per node, something we don't want for space reasons.
|
2014-10-20 11:42:56 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() {
|
|
|
|
return FeedbackVectorRequirements(0, 0);
|
2014-10-02 09:38:28 +00:00
|
|
|
}
|
2014-10-10 13:22:10 +00:00
|
|
|
virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) { UNREACHABLE(); }
|
2014-10-20 11:42:56 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2014-10-02 09:38:28 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class SmallMapList 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-07-21 15:59:05 +00:00
|
|
|
if (!Map::TryUpdate(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
|
2014-11-05 12:40:56 +00:00
|
|
|
bool is_parenthesized() const {
|
|
|
|
return IsParenthesizedField::decode(bit_field_);
|
|
|
|
}
|
|
|
|
bool is_multi_parenthesized() const {
|
|
|
|
return IsMultiParenthesizedField::decode(bit_field_);
|
|
|
|
}
|
2014-10-02 11:52:54 +00:00
|
|
|
void increase_parenthesization_level() {
|
2014-11-05 12:40:56 +00:00
|
|
|
bit_field_ =
|
|
|
|
IsMultiParenthesizedField::update(bit_field_, is_parenthesized());
|
|
|
|
bit_field_ = IsParenthesizedField::update(bit_field_, true);
|
2014-10-02 11:52:54 +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
|
|
|
|
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;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() const {
|
2013-03-20 10:37:13 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return STANDARD_STORE;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
virtual IcCheckType GetKeyType() const {
|
2014-10-10 13:27:52 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
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);
|
2014-11-05 12:40:56 +00:00
|
|
|
byte to_boolean_types() const {
|
|
|
|
return ToBooleanTypesField::decode(bit_field_);
|
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
void set_base_id(int id) { base_id_ = id; }
|
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId id() const { return BailoutId(local_id(0)); }
|
|
|
|
TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
|
2011-05-31 09:34:37 +00:00
|
|
|
|
2012-02-09 13:40:41 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
Expression(Zone* zone, int pos)
|
2013-10-14 09:24:58 +00:00
|
|
|
: AstNode(pos),
|
2014-10-21 12:16:37 +00:00
|
|
|
base_id_(BailoutId::None().ToInt()),
|
2014-10-14 10:24:18 +00:00
|
|
|
bounds_(Bounds::Unbounded(zone)),
|
2014-11-05 12:40:56 +00:00
|
|
|
bit_field_(0) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return 0; }
|
2014-11-05 12:40:56 +00:00
|
|
|
void set_to_boolean_types(byte types) {
|
|
|
|
bit_field_ = ToBooleanTypesField::update(bit_field_, types);
|
|
|
|
}
|
2012-02-09 13:40:41 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
int base_id() const {
|
|
|
|
DCHECK(!BailoutId(base_id_).IsNone());
|
|
|
|
return base_id_;
|
|
|
|
}
|
2014-10-10 10:52:31 +00:00
|
|
|
|
2008-10-28 22:33:00 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
|
|
|
int base_id_;
|
2014-10-14 10:24:18 +00:00
|
|
|
Bounds bounds_;
|
2014-11-05 12:40:56 +00:00
|
|
|
class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
|
|
|
|
class IsParenthesizedField : public BitField16<bool, 8, 1> {};
|
|
|
|
class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {};
|
|
|
|
uint16_t bit_field_;
|
|
|
|
// Ends with 16-bit field; deriving classes in turn begin with
|
|
|
|
// 16-bit fields for optimum packing efficiency.
|
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.
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual BreakableStatement* AsBreakableStatement() FINAL OVERRIDE {
|
2013-08-20 11:10:24 +00:00
|
|
|
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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
void set_base_id(int id) { base_id_ = id; }
|
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId EntryId() const { return BailoutId(local_id(0)); }
|
|
|
|
BailoutId ExitId() const { return BailoutId(local_id(1)); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
|
2014-10-21 12:16:37 +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-10-21 12:16:37 +00:00
|
|
|
base_id_(BailoutId::None().ToInt()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(labels == NULL || labels->length() > 0);
|
2011-11-09 11:32:54 +00:00
|
|
|
}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return 0; }
|
2011-11-09 11:32:54 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
int base_id() const {
|
|
|
|
DCHECK(!BailoutId(base_id_).IsNone());
|
|
|
|
return base_id_;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
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_;
|
2014-10-21 12:16:37 +00:00
|
|
|
int base_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class Block 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-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
|
|
|
BailoutId DeclsId() const { return BailoutId(local_id(0)); }
|
2014-06-05 07:33:01 +00:00
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsJump() const 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-08-22 11:12:29 +00:00
|
|
|
Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
|
2014-10-21 12:16:37 +00:00
|
|
|
bool is_initializer_block, 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-08-22 11:12:29 +00:00
|
|
|
scope_(NULL) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return BreakableStatement::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Statement*> statements_;
|
|
|
|
bool is_initializer_block_;
|
2012-04-16 14:43:27 +00:00
|
|
|
Scope* scope_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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-10-14 10:24:18 +00:00
|
|
|
Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
|
2013-10-14 09:24:58 +00:00
|
|
|
int pos)
|
2014-10-14 10:24:18 +00:00
|
|
|
: AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsDeclaredVariableMode(mode));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-10-11 08:41:19 +00:00
|
|
|
VariableMode mode_;
|
2014-10-14 10:24:18 +00:00
|
|
|
VariableProxy* proxy_;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class VariableDeclaration FINAL : public Declaration {
|
2012-02-09 13:39:26 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(VariableDeclaration)
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual InitializationFlag initialization() const 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
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class FunctionDeclaration FINAL : public Declaration {
|
2012-02-28 10:12:39 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(FunctionDeclaration)
|
|
|
|
|
|
|
|
FunctionLiteral* fun() const { return fun_; }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual InitializationFlag initialization() const OVERRIDE {
|
2012-02-28 10:12:39 +00:00
|
|
|
return kCreatedInitialized;
|
|
|
|
}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsInlineable() const 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...
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(mode == VAR || mode == LET);
|
|
|
|
DCHECK(fun != NULL);
|
2012-02-09 13:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FunctionLiteral* fun_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ModuleDeclaration FINAL : public Declaration {
|
2012-02-09 13:40:41 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ModuleDeclaration)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual InitializationFlag initialization() const 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ImportDeclaration FINAL : public Declaration {
|
2012-02-29 12:12:52 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ImportDeclaration)
|
|
|
|
|
|
|
|
Module* module() const { return module_; }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual InitializationFlag initialization() const 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ExportDeclaration FINAL : public Declaration {
|
2012-02-29 12:12:52 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(ExportDeclaration)
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual InitializationFlag initialization() const 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ModuleLiteral 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ModuleVariable 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ModulePath 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ModuleUrl 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ModuleStatement 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.
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual IterationStatement* AsIterationStatement() FINAL OVERRIDE {
|
2013-08-20 11:10:24 +00:00
|
|
|
return this;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Statement* body() const { return body_; }
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
|
|
|
BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
|
2012-08-06 14:13:09 +00:00
|
|
|
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-10-21 12:16:37 +00:00
|
|
|
IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
|
2014-10-10 10:52:31 +00:00
|
|
|
body_(NULL) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return BreakableStatement::num_ids(); }
|
|
|
|
void Initialize(Statement* body) { body_ = body; }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Statement* body_;
|
2011-04-07 14:42:37 +00:00
|
|
|
Label continue_target_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class DoWhileStatement 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_; }
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
2014-10-10 10:52:31 +00:00
|
|
|
virtual BailoutId ContinueId() const OVERRIDE {
|
2014-10-21 12:16:37 +00:00
|
|
|
return BailoutId(local_id(0));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
|
|
|
virtual BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
|
2014-10-21 12:16:37 +00:00
|
|
|
BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: IterationStatement(zone, labels, pos), cond_(NULL) {}
|
|
|
|
static int parent_num_ids() { return IterationStatement::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
Expression* cond_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class WhileStatement 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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual BailoutId ContinueId() const OVERRIDE { return EntryId(); }
|
2014-10-10 10:52:31 +00:00
|
|
|
virtual BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
|
2014-10-21 12:16:37 +00:00
|
|
|
BailoutId BodyId() const { return BailoutId(local_id(0)); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: IterationStatement(zone, labels, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
cond_(NULL),
|
2014-10-10 10:52:31 +00:00
|
|
|
may_have_function_literal_(true) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return IterationStatement::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ForStatement 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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
2014-10-10 10:52:31 +00:00
|
|
|
virtual BailoutId ContinueId() const OVERRIDE {
|
2014-10-21 12:16:37 +00:00
|
|
|
return BailoutId(local_id(0));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
|
|
|
virtual BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
|
2014-10-21 12:16:37 +00:00
|
|
|
BailoutId BodyId() const { return BailoutId(local_id(1)); }
|
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-10-21 12:16:37 +00:00
|
|
|
ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: IterationStatement(zone, labels, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
init_(NULL),
|
|
|
|
cond_(NULL),
|
|
|
|
next_(NULL),
|
|
|
|
may_have_function_literal_(true),
|
2014-10-10 10:52:31 +00:00
|
|
|
loop_variable_(NULL) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return IterationStatement::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
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_;
|
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-10-21 12:16:37 +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-10-02 09:38:28 +00:00
|
|
|
class ForInStatement FINAL : public ForEachStatement {
|
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-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(1, 0);
|
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
|
2014-10-10 13:22:10 +00:00
|
|
|
for_in_feedback_slot_ = slot;
|
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
FeedbackVectorSlot ForInFeedbackSlot() {
|
|
|
|
DCHECK(!for_in_feedback_slot_.IsInvalid());
|
2014-02-10 21:38:17 +00:00
|
|
|
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
|
|
|
|
2014-10-26 10:24:49 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 4; }
|
2014-10-21 12:16:37 +00:00
|
|
|
BailoutId BodyId() const { return BailoutId(local_id(0)); }
|
|
|
|
BailoutId PrepareId() const { return BailoutId(local_id(1)); }
|
2014-10-26 10:24:49 +00:00
|
|
|
BailoutId EnumId() const { return BailoutId(local_id(2)); }
|
|
|
|
BailoutId ToObjectId() const { return BailoutId(local_id(3)); }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual BailoutId ContinueId() const OVERRIDE { return EntryId(); }
|
2014-10-10 10:52:31 +00:00
|
|
|
virtual BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
|
2013-06-07 11:12:21 +00:00
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: ForEachStatement(zone, labels, pos),
|
2013-06-07 11:12:21 +00:00
|
|
|
for_in_type_(SLOW_FOR_IN),
|
2014-10-10 13:22:10 +00:00
|
|
|
for_in_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return ForEachStatement::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
ForInType for_in_type_;
|
2014-10-10 13:22:10 +00:00
|
|
|
FeedbackVectorSlot for_in_feedback_slot_;
|
2013-06-06 14:38:26 +00:00
|
|
|
};
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ForOfStatement 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,
|
|
|
|
Expression* assign_iterator,
|
|
|
|
Expression* next_result,
|
|
|
|
Expression* result_done,
|
|
|
|
Expression* assign_each) {
|
|
|
|
ForEachStatement::Initialize(each, subject, body);
|
|
|
|
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-07-24 13:40:08 +00:00
|
|
|
// var iterator = subject[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_;
|
|
|
|
}
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual BailoutId ContinueId() const OVERRIDE { return EntryId(); }
|
|
|
|
virtual BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
|
2013-06-07 11:12:21 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
|
|
|
BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
|
2013-06-07 11:12:21 +00:00
|
|
|
|
2013-06-06 14:38:26 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: ForEachStatement(zone, labels, pos),
|
2013-06-07 11:12:21 +00:00
|
|
|
assign_iterator_(NULL),
|
|
|
|
next_result_(NULL),
|
|
|
|
result_done_(NULL),
|
2014-10-10 10:52:31 +00:00
|
|
|
assign_each_(NULL) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return ForEachStatement::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2013-06-07 11:12:21 +00:00
|
|
|
Expression* assign_iterator_;
|
|
|
|
Expression* next_result_;
|
|
|
|
Expression* result_done_;
|
|
|
|
Expression* assign_each_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ExpressionStatement 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_; }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsJump() const 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:
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsJump() const FINAL 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ContinueStatement 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class BreakStatement 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ReturnStatement 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class WithStatement 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class CaseClause 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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId EntryId() const { return BailoutId(local_id(0)); }
|
|
|
|
TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
|
2011-03-09 12:06:54 +00:00
|
|
|
|
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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
protected:
|
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-08-22 11:12:29 +00:00
|
|
|
CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
|
2014-10-21 12:16:37 +00:00
|
|
|
int pos);
|
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
2014-10-10 10:52:31 +00:00
|
|
|
|
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_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class SwitchStatement 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-10-21 12:16:37 +00:00
|
|
|
SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
|
|
|
|
: BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
|
2012-02-08 09:56:33 +00:00
|
|
|
tag_(NULL),
|
2014-08-22 11:12:29 +00:00
|
|
|
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.
|
2014-09-02 07:07:52 +00:00
|
|
|
class IfStatement 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_; }
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsJump() const OVERRIDE {
|
2013-08-06 12:57:23 +00:00
|
|
|
return HasThenStatement() && then_statement()->IsJump()
|
|
|
|
&& HasElseStatement() && else_statement()->IsJump();
|
|
|
|
}
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
void set_base_id(int id) { base_id_ = id; }
|
|
|
|
static int num_ids() { return parent_num_ids() + 3; }
|
|
|
|
BailoutId IfId() const { return BailoutId(local_id(0)); }
|
|
|
|
BailoutId ThenId() const { return BailoutId(local_id(1)); }
|
|
|
|
BailoutId ElseId() const { return BailoutId(local_id(2)); }
|
2010-12-16 13:13:36 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
|
2014-10-21 12:16:37 +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-10-21 12:16:37 +00:00
|
|
|
base_id_(BailoutId::None().ToInt()) {}
|
|
|
|
static int parent_num_ids() { return 0; }
|
2014-10-10 10:52:31 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
int base_id() const {
|
|
|
|
DCHECK(!BailoutId(base_id_).IsNone());
|
|
|
|
return base_id_;
|
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* condition_;
|
|
|
|
Statement* then_statement_;
|
|
|
|
Statement* else_statement_;
|
2014-10-21 12:16:37 +00:00
|
|
|
int base_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.
|
2014-09-02 07:07:52 +00:00
|
|
|
class TargetCollector 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.
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void Accept(AstVisitor* v) OVERRIDE { UNREACHABLE(); }
|
|
|
|
virtual NodeType node_type() const OVERRIDE { return kInvalid; }
|
|
|
|
virtual TargetCollector* AsTargetCollector() 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class TryCatchStatement 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class TryFinallyStatement 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class DebuggerStatement 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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
void set_base_id(int id) { base_id_ = id; }
|
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
|
|
|
BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
|
2014-08-21 11:56:46 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
explicit DebuggerStatement(Zone* zone, int pos)
|
|
|
|
: Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {}
|
|
|
|
static int parent_num_ids() { return 0; }
|
2014-10-10 10:52:31 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
int base_id() const {
|
|
|
|
DCHECK(!BailoutId(base_id_).IsNone());
|
|
|
|
return base_id_;
|
|
|
|
}
|
2014-08-21 11:56:46 +00:00
|
|
|
|
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
|
|
|
int base_id_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class EmptyStatement 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class Literal 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-09-02 07:07:52 +00:00
|
|
|
virtual bool IsPropertyName() const 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() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsPropertyName());
|
2014-06-24 14:03:24 +00:00
|
|
|
return Handle<String>::cast(value());
|
|
|
|
}
|
|
|
|
|
|
|
|
const AstRawString* AsRawPropertyName() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsPropertyName());
|
2014-06-24 14:03:24 +00:00
|
|
|
return value_->AsString();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool ToBooleanIsTrue() const OVERRIDE {
|
2014-06-24 14:03:24 +00:00
|
|
|
return value()->BooleanValue();
|
2013-08-20 11:10:24 +00:00
|
|
|
}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool ToBooleanIsFalse() const 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!
|
2014-10-02 13:05:11 +00:00
|
|
|
uint32_t Hash();
|
|
|
|
static bool Match(void* literal1, void* literal2);
|
2012-03-09 08:34:35 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
2014-10-10 10:52:31 +00:00
|
|
|
TypeFeedbackId LiteralFeedbackId() const {
|
2014-10-21 12:16:37 +00:00
|
|
|
return TypeFeedbackId(local_id(0));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
2012-08-06 14:13:09 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
Literal(Zone* zone, const AstValue* value, int position)
|
|
|
|
: Expression(zone, position), value_(value) {}
|
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstValue* value_;
|
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.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(depth_ >= 1);
|
2013-11-20 14:17:47 +00:00
|
|
|
return depth_;
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
MaterializedLiteral(Zone* zone, int literal_index, int pos)
|
|
|
|
: 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) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(depth >= 1);
|
2013-11-20 14:17:47 +00:00
|
|
|
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.
|
2014-09-02 07:07:52 +00:00
|
|
|
class ObjectLiteralProperty 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,
|
2014-09-16 22:15:39 +00:00
|
|
|
Literal* key, Expression* value, bool is_static);
|
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();
|
|
|
|
|
2014-10-28 12:43:05 +00:00
|
|
|
bool is_static() const { return is_static_; }
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
protected:
|
|
|
|
template<class> friend class AstNodeFactory;
|
|
|
|
|
2014-09-16 22:15:39 +00:00
|
|
|
ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value,
|
|
|
|
bool is_static);
|
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_;
|
2014-09-16 22:15:39 +00:00
|
|
|
bool is_static_;
|
2013-05-27 13:59:20 +00:00
|
|
|
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.
|
2014-09-02 07:07:52 +00:00
|
|
|
class ObjectLiteral 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
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Assemble bitfield of flags for the CreateObjectLiteral helper.
|
|
|
|
int ComputeFlags() const {
|
|
|
|
int flags = fast_elements() ? kFastElements : kNoFlags;
|
|
|
|
flags |= has_function() ? kHasFunction : kNoFlags;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
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 {
|
2014-10-26 10:24:49 +00:00
|
|
|
Accessors() : getter(NULL), setter(NULL) {}
|
2012-03-15 07:13:46 +00:00
|
|
|
Expression* getter;
|
|
|
|
Expression* setter;
|
|
|
|
};
|
|
|
|
|
2014-10-26 10:24:49 +00:00
|
|
|
BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
|
|
|
|
|
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
|
2014-10-21 12:16:37 +00:00
|
|
|
int boilerplate_properties, bool has_function, int pos)
|
|
|
|
: 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) {}
|
2014-10-26 10:24:49 +00:00
|
|
|
static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-10-26 10:24:49 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
2008-07-03 15:10:15 +00:00
|
|
|
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.
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpLiteral 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-08-22 11:12:29 +00:00
|
|
|
RegExpLiteral(Zone* zone, const AstRawString* pattern,
|
2014-10-21 12:16:37 +00:00
|
|
|
const AstRawString* flags, int literal_index, int pos)
|
|
|
|
: 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.
|
2014-09-02 07:07:52 +00:00
|
|
|
class ArrayLiteral 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_; }
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
// Unlike other AST nodes, this number of bailout IDs allocated for an
|
|
|
|
// ArrayLiteral can vary, so num_ids() is not a static method.
|
|
|
|
int num_ids() const { return parent_num_ids() + values()->length(); }
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
// Return an AST id for an element that is used in simulate instructions.
|
2014-10-21 12:16:37 +00:00
|
|
|
BailoutId GetIdForElement(int i) { return BailoutId(local_id(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
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Assemble bitfield of flags for the CreateArrayLiteral helper.
|
|
|
|
int ComputeFlags() const {
|
|
|
|
int flags = depth() == 1 ? kShallowElements : kNoFlags;
|
|
|
|
flags |= ArrayLiteral::kDisableMementos;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
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-08-22 11:12:29 +00:00
|
|
|
ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index,
|
2014-10-21 12:16:37 +00:00
|
|
|
int pos)
|
|
|
|
: MaterializedLiteral(zone, literal_index, pos), values_(values) {}
|
|
|
|
static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2009-12-22 12:41:45 +00:00
|
|
|
Handle<FixedArray> constant_elements_;
|
2008-07-03 15:10:15 +00:00
|
|
|
ZoneList<Expression*>* values_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-02 09:38:28 +00:00
|
|
|
class VariableProxy 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-09-02 07:07:52 +00:00
|
|
|
virtual bool IsValidReferenceExpression() const OVERRIDE {
|
2014-10-06 12:56:11 +00:00
|
|
|
return !is_resolved() || var()->IsValidReference();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-06-24 08:01:38 +00:00
|
|
|
|
2014-10-06 12:56:11 +00:00
|
|
|
bool IsArguments() const { return is_resolved() && var()->is_arguments(); }
|
|
|
|
|
|
|
|
Handle<String> name() const { return raw_name()->string(); }
|
|
|
|
const AstRawString* raw_name() const {
|
|
|
|
return is_resolved() ? var_->raw_name() : raw_name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variable* var() const {
|
|
|
|
DCHECK(is_resolved());
|
|
|
|
return var_;
|
|
|
|
}
|
|
|
|
void set_var(Variable* v) {
|
|
|
|
DCHECK(!is_resolved());
|
|
|
|
DCHECK_NOT_NULL(v);
|
|
|
|
var_ = v;
|
|
|
|
}
|
2009-06-24 08:01:38 +00:00
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
bool is_this() const { return IsThisField::decode(bit_field_); }
|
2012-03-08 13:03:07 +00:00
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
bool is_assigned() const { return IsAssignedField::decode(bit_field_); }
|
|
|
|
void set_is_assigned() {
|
|
|
|
bit_field_ = IsAssignedField::update(bit_field_, true);
|
|
|
|
}
|
2010-03-16 10:54:02 +00:00
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
bool is_resolved() const { return IsResolvedField::decode(bit_field_); }
|
|
|
|
void set_is_resolved() {
|
|
|
|
bit_field_ = IsResolvedField::update(bit_field_, true);
|
|
|
|
}
|
2014-10-06 12:56:11 +00:00
|
|
|
|
|
|
|
Interface* interface() const { return interface_; }
|
|
|
|
|
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);
|
|
|
|
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
|
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
|
2014-07-21 11:19:56 +00:00
|
|
|
variable_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot VariableFeedbackSlot() {
|
|
|
|
return variable_feedback_slot_;
|
|
|
|
}
|
2014-07-21 11:19:56 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
VariableProxy(Zone* zone, Variable* var, int position);
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2014-08-22 11:12:29 +00:00
|
|
|
VariableProxy(Zone* zone, const AstRawString* name, bool is_this,
|
2014-10-21 12:16:37 +00:00
|
|
|
Interface* interface, int position);
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
class IsThisField : public BitField8<bool, 0, 1> {};
|
|
|
|
class IsAssignedField : public BitField8<bool, 1, 1> {};
|
|
|
|
class IsResolvedField : public BitField8<bool, 2, 1> {};
|
|
|
|
|
|
|
|
// Start with 16-bit (or smaller) field, which should get packed together
|
|
|
|
// with Expression's trailing 16-bit field.
|
|
|
|
uint8_t bit_field_;
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot variable_feedback_slot_;
|
2014-10-06 12:56:11 +00:00
|
|
|
union {
|
|
|
|
const AstRawString* raw_name_; // if !is_resolved_
|
|
|
|
Variable* var_; // if is_resolved_
|
|
|
|
};
|
2012-03-08 13:03:07 +00:00
|
|
|
Interface* interface_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-02 09:38:28 +00:00
|
|
|
class Property 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-09-02 07:07:52 +00:00
|
|
|
virtual bool IsValidReferenceExpression() const OVERRIDE { return true; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Expression* obj() const { return obj_; }
|
|
|
|
Expression* key() const { return key_; }
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId LoadId() const { return BailoutId(local_id(0)); }
|
|
|
|
TypeFeedbackId PropertyFeedbackId() { return TypeFeedbackId(local_id(1)); }
|
2012-07-30 10:42:21 +00:00
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
bool IsStringAccess() const {
|
|
|
|
return IsStringAccessField::decode(bit_field_);
|
|
|
|
}
|
2010-12-22 15:43:32 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information.
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsMonomorphic() OVERRIDE {
|
2013-12-12 14:57:00 +00:00
|
|
|
return receiver_types_.length() == 1;
|
|
|
|
}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() OVERRIDE {
|
2013-08-20 11:10:24 +00:00
|
|
|
return &receiver_types_;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
|
2013-03-20 10:37:13 +00:00
|
|
|
return STANDARD_STORE;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
virtual IcCheckType GetKeyType() const OVERRIDE {
|
2014-10-14 13:52:15 +00:00
|
|
|
// PROPERTY key types currently aren't implemented for KeyedLoadICs.
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
bool IsUninitialized() const {
|
|
|
|
return !is_for_call() && HasNoTypeInformation();
|
|
|
|
}
|
|
|
|
bool HasNoTypeInformation() const {
|
|
|
|
return IsUninitializedField::decode(bit_field_);
|
|
|
|
}
|
|
|
|
void set_is_uninitialized(bool b) {
|
|
|
|
bit_field_ = IsUninitializedField::update(bit_field_, b);
|
2013-10-23 10:41:21 +00:00
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
void set_is_string_access(bool b) {
|
|
|
|
bit_field_ = IsStringAccessField::update(bit_field_, b);
|
|
|
|
}
|
|
|
|
void mark_for_call() {
|
|
|
|
bit_field_ = IsForCallField::update(bit_field_, true);
|
|
|
|
}
|
|
|
|
bool is_for_call() const { return IsForCallField::decode(bit_field_); }
|
2013-11-28 15:25:38 +00:00
|
|
|
|
2014-08-18 12:35:34 +00:00
|
|
|
bool IsSuperAccess() {
|
|
|
|
return obj()->IsSuperReference();
|
|
|
|
}
|
|
|
|
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
|
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
|
2014-07-21 11:19:56 +00:00
|
|
|
property_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot PropertyFeedbackSlot() const {
|
2014-10-10 13:22:10 +00:00
|
|
|
return property_feedback_slot_;
|
|
|
|
}
|
2014-07-21 11:19:56 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
Property(Zone* zone, Expression* obj, Expression* key, int pos)
|
|
|
|
: Expression(zone, pos),
|
2014-11-05 12:40:56 +00:00
|
|
|
bit_field_(IsForCallField::encode(false) |
|
|
|
|
IsUninitializedField::encode(false) |
|
|
|
|
IsStringAccessField::encode(false)),
|
2014-10-20 11:42:56 +00:00
|
|
|
property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
|
2014-10-14 10:24:18 +00:00
|
|
|
obj_(obj),
|
|
|
|
key_(key) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
class IsForCallField : public BitField8<bool, 0, 1> {};
|
|
|
|
class IsUninitializedField : public BitField8<bool, 1, 1> {};
|
|
|
|
class IsStringAccessField : public BitField8<bool, 2, 1> {};
|
|
|
|
uint8_t bit_field_;
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot property_feedback_slot_;
|
2014-10-14 10:24:18 +00:00
|
|
|
Expression* obj_;
|
|
|
|
Expression* key_;
|
|
|
|
SmallMapList receiver_types_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-02 09:38:28 +00:00
|
|
|
class Call FINAL : public Expression {
|
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-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(0, 1);
|
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
|
2014-02-10 21:38:17 +00:00
|
|
|
call_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
bool HasCallFeedbackSlot() const { return !call_feedback_slot_.IsInvalid(); }
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot CallFeedbackSlot() const { return call_feedback_slot_; }
|
2013-03-12 17:01:03 +00:00
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() OVERRIDE {
|
2014-01-31 16:52:17 +00:00
|
|
|
if (expression()->IsProperty()) {
|
|
|
|
return expression()->AsProperty()->GetReceiverTypes();
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-03-12 17:01:03 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsMonomorphic() OVERRIDE {
|
2014-01-31 16:52:17 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-08-19 17:04:23 +00:00
|
|
|
bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupIterator* it);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId ReturnId() const { return BailoutId(local_id(0)); }
|
|
|
|
BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
|
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,
|
2014-10-17 09:16:03 +00:00
|
|
|
SUPER_CALL,
|
2014-01-17 14:08:50 +00:00
|
|
|
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-08-22 11:12:29 +00:00
|
|
|
Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
|
2014-10-21 12:16:37 +00:00
|
|
|
int pos)
|
|
|
|
: Expression(zone, pos),
|
2014-10-20 11:42:56 +00:00
|
|
|
call_feedback_slot_(FeedbackVectorICSlot::Invalid()),
|
2012-02-08 09:56:33 +00:00
|
|
|
expression_(expression),
|
2014-10-14 10:24:18 +00:00
|
|
|
arguments_(arguments) {
|
2014-01-31 16:52:17 +00:00
|
|
|
if (expression->IsProperty()) {
|
|
|
|
expression->AsProperty()->mark_for_call();
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot call_feedback_slot_;
|
2008-07-03 15:10:15 +00:00
|
|
|
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_;
|
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-10-02 09:38:28 +00:00
|
|
|
class CallNew FINAL : public Expression {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2012-02-08 09:56:33 +00:00
|
|
|
DECLARE_NODE_TYPE(CallNew)
|
|
|
|
|
|
|
|
Expression* expression() const { return expression_; }
|
|
|
|
ZoneList<Expression*>* arguments() const { return arguments_; }
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
// Type feedback information.
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
|
2014-03-19 13:39:09 +00:00
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
|
2014-02-10 21:38:17 +00:00
|
|
|
callnew_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
FeedbackVectorSlot CallNewFeedbackSlot() { return callnew_feedback_slot_; }
|
|
|
|
FeedbackVectorSlot AllocationSiteFeedbackSlot() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(FLAG_pretenuring_call_new);
|
2014-10-10 13:22:10 +00:00
|
|
|
return CallNewFeedbackSlot().next();
|
2014-03-19 13:39:09 +00:00
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsMonomorphic() OVERRIDE { return is_monomorphic_; }
|
2013-05-27 13:59:20 +00:00
|
|
|
Handle<JSFunction> target() const { return target_; }
|
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-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
2014-02-10 21:38:17 +00:00
|
|
|
static int feedback_slots() { return 1; }
|
2014-10-21 12:16:37 +00:00
|
|
|
BailoutId ReturnId() const { return BailoutId(local_id(0)); }
|
2012-02-28 09:05:55 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
|
2014-10-21 12:16:37 +00:00
|
|
|
int pos)
|
|
|
|
: 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),
|
2014-10-10 13:22:10 +00:00
|
|
|
callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
|
2014-10-10 10:52:31 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-30 09:49:36 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2009-09-30 09:49:36 +00:00
|
|
|
Expression* expression_;
|
|
|
|
ZoneList<Expression*>* arguments_;
|
2012-02-28 09:05:55 +00:00
|
|
|
bool is_monomorphic_;
|
|
|
|
Handle<JSFunction> target_;
|
2014-01-20 09:48:05 +00:00
|
|
|
Handle<AllocationSite> allocation_site_;
|
2014-10-10 13:22:10 +00:00
|
|
|
FeedbackVectorSlot callnew_feedback_slot_;
|
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").
|
2014-10-02 09:38:28 +00:00
|
|
|
class CallRuntime 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; }
|
|
|
|
|
2014-07-21 11:19:56 +00:00
|
|
|
// Type feedback information.
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(
|
|
|
|
0, (FLAG_vector_ics && is_jsruntime()) ? 1 : 0);
|
2014-07-21 11:19:56 +00:00
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
|
2014-07-21 11:19:56 +00:00
|
|
|
callruntime_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
|
2014-07-21 11:19:56 +00:00
|
|
|
return callruntime_feedback_slot_;
|
|
|
|
}
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
2014-10-10 10:52:31 +00:00
|
|
|
TypeFeedbackId CallRuntimeFeedbackId() const {
|
2014-10-21 12:16:37 +00:00
|
|
|
return TypeFeedbackId(local_id(0));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
2012-08-06 14:13:09 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
CallRuntime(Zone* zone, const AstRawString* name,
|
2011-03-18 20:35:07 +00:00
|
|
|
const Runtime::Function* function,
|
2014-10-21 12:16:37 +00:00
|
|
|
ZoneList<Expression*>* arguments, int pos)
|
|
|
|
: Expression(zone, pos),
|
2014-06-24 14:03:24 +00:00
|
|
|
raw_name_(name),
|
2011-07-18 17:32:41 +00:00
|
|
|
function_(function),
|
2014-10-10 13:22:10 +00:00
|
|
|
arguments_(arguments),
|
2014-10-20 11:42:56 +00:00
|
|
|
callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
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_;
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot callruntime_feedback_slot_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class UnaryOperation 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_; }
|
|
|
|
|
2014-10-10 10:52:31 +00:00
|
|
|
// For unary not (Token::NOT), the AST ids where true and false will
|
|
|
|
// actually be materialized, respectively.
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
|
|
|
|
BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
|
2012-08-06 14:13:09 +00:00
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void RecordToBooleanTypeFeedback(
|
2014-09-02 07:07:52 +00:00
|
|
|
TypeFeedbackOracle* oracle) OVERRIDE;
|
2013-06-25 11:49:46 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
|
|
|
|
: Expression(zone, pos), op_(op), expression_(expression) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(Token::IsUnaryOp(op));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Token::Value op_;
|
|
|
|
Expression* expression_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class BinaryOperation 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-09-02 07:07:52 +00:00
|
|
|
virtual bool ResultOverwriteAllowed() const OVERRIDE;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-10-14 10:24:18 +00:00
|
|
|
Token::Value op() const { return static_cast<Token::Value>(op_); }
|
2008-07-03 15:10:15 +00:00
|
|
|
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
|
|
|
|
2014-10-10 10:52:31 +00:00
|
|
|
// The short-circuit logical operations need an AST ID for their
|
|
|
|
// right-hand subexpression.
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId RightId() const { return BailoutId(local_id(0)); }
|
2012-08-06 14:13:09 +00:00
|
|
|
|
2014-10-10 10:52:31 +00:00
|
|
|
TypeFeedbackId BinaryOperationFeedbackId() const {
|
2014-10-21 12:16:37 +00:00
|
|
|
return TypeFeedbackId(local_id(1));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
2014-10-14 10:24:18 +00:00
|
|
|
Maybe<int> fixed_right_arg() const {
|
|
|
|
return has_fixed_right_arg_ ? Maybe<int>(fixed_right_arg_value_)
|
|
|
|
: Maybe<int>();
|
|
|
|
}
|
|
|
|
void set_fixed_right_arg(Maybe<int> arg) {
|
|
|
|
has_fixed_right_arg_ = arg.has_value;
|
|
|
|
if (arg.has_value) fixed_right_arg_value_ = arg.value;
|
|
|
|
}
|
2010-12-16 13:13:36 +00:00
|
|
|
|
2013-08-20 11:10:24 +00:00
|
|
|
virtual void RecordToBooleanTypeFeedback(
|
2014-09-02 07:07:52 +00:00
|
|
|
TypeFeedbackOracle* oracle) OVERRIDE;
|
2013-06-25 11:49:46 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
BinaryOperation(Zone* zone, Token::Value op, Expression* left,
|
2014-10-21 12:16:37 +00:00
|
|
|
Expression* right, int pos)
|
|
|
|
: Expression(zone, pos),
|
2014-10-14 10:24:18 +00:00
|
|
|
op_(static_cast<byte>(op)),
|
2014-11-03 14:59:19 +00:00
|
|
|
has_fixed_right_arg_(false),
|
|
|
|
fixed_right_arg_value_(0),
|
2012-07-20 09:39:27 +00:00
|
|
|
left_(left),
|
2014-10-10 10:52:31 +00:00
|
|
|
right_(right) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(Token::IsBinaryOp(op));
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-10-14 10:24:18 +00:00
|
|
|
const byte op_; // actually Token::Value
|
|
|
|
// TODO(rossberg): the fixed arg should probably be represented as a Constant
|
|
|
|
// type for the RHS. Currenty it's actually a Maybe<int>
|
|
|
|
bool has_fixed_right_arg_;
|
|
|
|
int fixed_right_arg_value_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* left_;
|
|
|
|
Expression* right_;
|
2014-01-02 15:31:27 +00:00
|
|
|
Handle<AllocationSite> allocation_site_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class CountOperation 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
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
|
|
|
|
bool is_postfix() const { return !is_prefix(); }
|
2010-08-24 12:56:45 +00:00
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
Token::Value op() const { return TokenField::decode(bit_field_); }
|
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
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsMonomorphic() OVERRIDE {
|
2013-12-12 14:57:00 +00:00
|
|
|
return receiver_types_.length() == 1;
|
|
|
|
}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() OVERRIDE {
|
2013-08-20 11:10:24 +00:00
|
|
|
return &receiver_types_;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
virtual IcCheckType GetKeyType() const OVERRIDE {
|
|
|
|
return KeyTypeField::decode(bit_field_);
|
|
|
|
}
|
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
|
|
|
|
return StoreModeField::decode(bit_field_);
|
2013-03-20 10:37:13 +00:00
|
|
|
}
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* type() const { return type_; }
|
2014-11-05 12:40:56 +00:00
|
|
|
void set_key_type(IcCheckType type) {
|
|
|
|
bit_field_ = KeyTypeField::update(bit_field_, type);
|
|
|
|
}
|
|
|
|
void set_store_mode(KeyedAccessStoreMode mode) {
|
|
|
|
bit_field_ = StoreModeField::update(bit_field_, mode);
|
|
|
|
}
|
2014-01-21 16:22:52 +00:00
|
|
|
void set_type(Type* type) { type_ = type; }
|
2011-04-07 09:51:25 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 3; }
|
|
|
|
BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
|
2014-10-10 10:52:31 +00:00
|
|
|
TypeFeedbackId CountBinOpFeedbackId() const {
|
2014-10-21 12:16:37 +00:00
|
|
|
return TypeFeedbackId(local_id(1));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
|
|
|
TypeFeedbackId CountStoreFeedbackId() const {
|
2014-10-21 12:16:37 +00:00
|
|
|
return TypeFeedbackId(local_id(2));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
2012-08-06 14:13:09 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
|
2014-10-21 12:16:37 +00:00
|
|
|
int pos)
|
|
|
|
: Expression(zone, pos),
|
2014-11-05 12:40:56 +00:00
|
|
|
bit_field_(IsPrefixField::encode(is_prefix) |
|
|
|
|
KeyTypeField::encode(ELEMENT) |
|
|
|
|
StoreModeField::encode(STANDARD_STORE) |
|
|
|
|
TokenField::encode(op)),
|
|
|
|
type_(NULL),
|
2014-10-10 10:52:31 +00:00
|
|
|
expression_(expr) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
class IsPrefixField : public BitField16<bool, 0, 1> {};
|
|
|
|
class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
|
|
|
|
class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
|
|
|
|
class TokenField : public BitField16<Token::Value, 6, 8> {};
|
|
|
|
|
|
|
|
// Starts with 16-bit field, which should get packed together with
|
|
|
|
// Expression's trailing 16-bit field.
|
|
|
|
uint16_t bit_field_;
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* type_;
|
2011-04-07 07:56:43 +00:00
|
|
|
Expression* expression_;
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class CompareOperation 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.
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
2014-10-10 10:52:31 +00:00
|
|
|
TypeFeedbackId CompareOperationFeedbackId() const {
|
2014-10-21 12:16:37 +00:00
|
|
|
return TypeFeedbackId(local_id(0));
|
2014-10-10 10:52:31 +00:00
|
|
|
}
|
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-08-22 11:12:29 +00:00
|
|
|
CompareOperation(Zone* zone, Token::Value op, Expression* left,
|
2014-10-21 12:16:37 +00:00
|
|
|
Expression* right, int pos)
|
|
|
|
: 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)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(Token::IsCompareOp(op));
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class Conditional 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_; }
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId ThenId() const { return BailoutId(local_id(0)); }
|
|
|
|
BailoutId ElseId() const { return BailoutId(local_id(1)); }
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
Conditional(Zone* zone, Expression* condition, Expression* then_expression,
|
2014-10-21 12:16:37 +00:00
|
|
|
Expression* else_expression, int position)
|
|
|
|
: 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),
|
2014-10-10 10:52:31 +00:00
|
|
|
else_expression_(else_expression) {}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* condition_;
|
|
|
|
Expression* then_expression_;
|
|
|
|
Expression* else_expression_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class Assignment 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;
|
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
Token::Value op() const { return TokenField::decode(bit_field_); }
|
2008-07-03 15:10:15 +00:00
|
|
|
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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 2; }
|
|
|
|
BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
|
2012-08-06 14:13:09 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Type feedback information.
|
2014-10-21 12:16:37 +00:00
|
|
|
TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual bool IsMonomorphic() OVERRIDE {
|
2013-12-12 14:57:00 +00:00
|
|
|
return receiver_types_.length() == 1;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
bool IsUninitialized() const {
|
|
|
|
return IsUninitializedField::decode(bit_field_);
|
|
|
|
}
|
2013-10-23 10:41:21 +00:00
|
|
|
bool HasNoTypeInformation() {
|
2014-11-05 12:40:56 +00:00
|
|
|
return IsUninitializedField::decode(bit_field_);
|
2013-10-23 10:41:21 +00:00
|
|
|
}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual SmallMapList* GetReceiverTypes() OVERRIDE {
|
2013-08-20 11:10:24 +00:00
|
|
|
return &receiver_types_;
|
|
|
|
}
|
2014-11-05 12:40:56 +00:00
|
|
|
virtual IcCheckType GetKeyType() const OVERRIDE {
|
|
|
|
return KeyTypeField::decode(bit_field_);
|
|
|
|
}
|
|
|
|
virtual KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
|
|
|
|
return StoreModeField::decode(bit_field_);
|
|
|
|
}
|
|
|
|
void set_is_uninitialized(bool b) {
|
|
|
|
bit_field_ = IsUninitializedField::update(bit_field_, b);
|
|
|
|
}
|
|
|
|
void set_key_type(IcCheckType key_type) {
|
|
|
|
bit_field_ = KeyTypeField::update(bit_field_, key_type);
|
|
|
|
}
|
|
|
|
void set_store_mode(KeyedAccessStoreMode mode) {
|
|
|
|
bit_field_ = StoreModeField::update(bit_field_, mode);
|
2013-03-20 10:37:13 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
|
2014-10-21 12:16:37 +00:00
|
|
|
int pos);
|
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-10 10:52:31 +00:00
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
template <class Visitor>
|
|
|
|
void Init(AstNodeFactory<Visitor>* factory) {
|
2014-11-05 12:40:56 +00:00
|
|
|
DCHECK(Token::IsAssignmentOp(op()));
|
2012-02-08 09:56:33 +00:00
|
|
|
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:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-11-05 12:40:56 +00:00
|
|
|
class IsUninitializedField : public BitField16<bool, 0, 1> {};
|
|
|
|
class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
|
|
|
|
class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
|
|
|
|
class TokenField : public BitField16<Token::Value, 6, 8> {};
|
|
|
|
|
|
|
|
// Starts with 16-bit field, which should get packed together with
|
|
|
|
// Expression's trailing 16-bit field.
|
|
|
|
uint16_t bit_field_;
|
2014-10-14 10:24:18 +00:00
|
|
|
Expression* target_;
|
|
|
|
Expression* value_;
|
|
|
|
BinaryOperation* binary_operation_;
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList receiver_types_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-02 09:38:28 +00:00
|
|
|
class Yield 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 {
|
2014-09-02 07:07:52 +00:00
|
|
|
kInitial, // The initial yield that returns the unboxed generator object.
|
|
|
|
kSuspend, // A normal yield: { value: EXPRESSION, done: false }
|
|
|
|
kDelegating, // A yield*.
|
|
|
|
kFinal // 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 {
|
2014-09-02 07:07:52 +00:00
|
|
|
DCHECK_EQ(kDelegating, yield_kind());
|
2013-05-14 16:26:56 +00:00
|
|
|
return index_;
|
|
|
|
}
|
|
|
|
void set_index(int index) {
|
2014-09-02 07:07:52 +00:00
|
|
|
DCHECK_EQ(kDelegating, yield_kind());
|
2013-05-14 16:26:56 +00:00
|
|
|
index_ = index;
|
|
|
|
}
|
|
|
|
|
2014-07-21 11:19:56 +00:00
|
|
|
// Type feedback information.
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(
|
|
|
|
0, (FLAG_vector_ics && yield_kind() == kDelegating) ? 3 : 0);
|
2014-07-21 11:19:56 +00:00
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
|
2014-07-21 11:19:56 +00:00
|
|
|
yield_first_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
|
2014-07-21 11:19:56 +00:00
|
|
|
return yield_first_feedback_slot_;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot DoneFeedbackSlot() {
|
2014-10-10 13:22:10 +00:00
|
|
|
return KeyedLoadFeedbackSlot().next();
|
2014-07-21 11:19:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
|
2014-07-21 11:19:56 +00:00
|
|
|
|
2013-04-02 17:34:59 +00:00
|
|
|
protected:
|
2014-08-22 11:12:29 +00:00
|
|
|
Yield(Zone* zone, Expression* generator_object, Expression* expression,
|
2014-10-21 12:16:37 +00:00
|
|
|
Kind yield_kind, int pos)
|
|
|
|
: 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),
|
2014-07-21 11:19:56 +00:00
|
|
|
index_(-1),
|
2014-10-20 11:42:56 +00:00
|
|
|
yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
|
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_;
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot yield_first_feedback_slot_;
|
2013-04-02 17:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class Throw 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-10-21 12:16:37 +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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class FunctionLiteral 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
|
|
|
|
};
|
|
|
|
|
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()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_inferred_name_ == NULL);
|
2014-06-24 14:03:24 +00:00
|
|
|
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-08-04 11:34:54 +00:00
|
|
|
DCHECK(!inferred_name.is_null());
|
2009-04-14 00:51:59 +00:00
|
|
|
inferred_name_ = inferred_name;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
|
2014-06-24 14:03:24 +00:00
|
|
|
raw_inferred_name_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_raw_inferred_name(const AstString* raw_inferred_name) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(raw_inferred_name != NULL);
|
2014-06-24 14:03:24 +00:00
|
|
|
raw_inferred_name_ = raw_inferred_name;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(inferred_name_.is_null());
|
2014-06-24 14:03:24 +00:00
|
|
|
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
|
|
|
|
2014-09-10 16:39:42 +00:00
|
|
|
FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
|
|
|
|
bool is_arrow() {
|
|
|
|
return IsArrowFunction(FunctionKindBits::decode(bitfield_));
|
|
|
|
}
|
|
|
|
bool is_generator() {
|
|
|
|
return IsGeneratorFunction(FunctionKindBits::decode(bitfield_));
|
|
|
|
}
|
|
|
|
bool is_concise_method() {
|
|
|
|
return IsConciseMethod(FunctionKindBits::decode(bitfield_));
|
|
|
|
}
|
2013-04-02 17:34:59 +00:00
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
int ast_node_count() { return ast_properties_.node_count(); }
|
|
|
|
AstProperties::Flags* flags() { return ast_properties_.flags(); }
|
|
|
|
void set_ast_properties(AstProperties* ast_properties) {
|
|
|
|
ast_properties_ = *ast_properties;
|
|
|
|
}
|
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
|
|
|
}
|
2014-10-20 11:42:56 +00:00
|
|
|
int ic_slot_count() { return ast_properties_.ic_feedback_slots(); }
|
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-07-21 09:58:01 +00:00
|
|
|
FunctionLiteral(Zone* zone, const AstRawString* name,
|
|
|
|
AstValueFactory* ast_value_factory, Scope* scope,
|
|
|
|
ZoneList<Statement*>* body, int materialized_literal_count,
|
|
|
|
int expected_property_count, int handler_count,
|
|
|
|
int parameter_count, 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,
|
2014-09-10 16:39:42 +00:00
|
|
|
IsParenthesizedFlag is_parenthesized, FunctionKind kind,
|
2014-10-21 12:16:37 +00:00
|
|
|
int position)
|
|
|
|
: 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) {
|
2014-07-21 09:58:01 +00:00
|
|
|
bitfield_ = IsExpression::encode(function_type != DECLARATION) |
|
|
|
|
IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
|
|
|
|
Pretenure::encode(false) |
|
|
|
|
HasDuplicateParameters::encode(has_duplicate_parameters) |
|
|
|
|
IsFunction::encode(is_function) |
|
|
|
|
IsParenthesized::encode(is_parenthesized) |
|
2014-09-10 16:39:42 +00:00
|
|
|
FunctionKindBits::encode(kind);
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
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_;
|
2014-09-10 16:39:42 +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 FunctionKindBits : public BitField<FunctionKind, 6, 3> {};
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-16 22:15:39 +00:00
|
|
|
class ClassLiteral FINAL : public Expression {
|
|
|
|
public:
|
|
|
|
typedef ObjectLiteralProperty Property;
|
|
|
|
|
|
|
|
DECLARE_NODE_TYPE(ClassLiteral)
|
|
|
|
|
|
|
|
Handle<String> name() const { return raw_name_->string(); }
|
|
|
|
const AstRawString* raw_name() const { return raw_name_; }
|
|
|
|
Expression* extends() const { return extends_; }
|
2014-09-18 17:39:49 +00:00
|
|
|
Expression* constructor() const { return constructor_; }
|
2014-09-16 22:15:39 +00:00
|
|
|
ZoneList<Property*>* properties() const { return properties_; }
|
2014-10-08 14:48:48 +00:00
|
|
|
int start_position() const { return position(); }
|
|
|
|
int end_position() const { return end_position_; }
|
2014-09-16 22:15:39 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends,
|
2014-09-18 17:39:49 +00:00
|
|
|
Expression* constructor, ZoneList<Property*>* properties,
|
2014-10-21 12:16:37 +00:00
|
|
|
int start_position, int end_position)
|
|
|
|
: Expression(zone, start_position),
|
2014-09-16 22:15:39 +00:00
|
|
|
raw_name_(name),
|
|
|
|
extends_(extends),
|
|
|
|
constructor_(constructor),
|
2014-10-08 14:48:48 +00:00
|
|
|
properties_(properties),
|
|
|
|
end_position_(end_position) {}
|
2014-09-16 22:15:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const AstRawString* raw_name_;
|
|
|
|
Expression* extends_;
|
2014-09-18 17:39:49 +00:00
|
|
|
Expression* constructor_;
|
2014-09-16 22:15:39 +00:00
|
|
|
ZoneList<Property*>* properties_;
|
2014-10-08 14:48:48 +00:00
|
|
|
int end_position_;
|
2014-09-16 22:15:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class NativeFunctionLiteral 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,
|
2014-10-21 12:16:37 +00:00
|
|
|
v8::Extension* extension, int pos)
|
|
|
|
: 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class ThisFunction 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-10-21 12:16:37 +00:00
|
|
|
ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2014-08-18 12:35:34 +00:00
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class SuperReference FINAL : public Expression {
|
2014-08-18 12:35:34 +00:00
|
|
|
public:
|
|
|
|
DECLARE_NODE_TYPE(SuperReference)
|
|
|
|
|
|
|
|
VariableProxy* this_var() const { return this_var_; }
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
static int num_ids() { return parent_num_ids() + 1; }
|
|
|
|
TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); }
|
2014-08-18 12:35:34 +00:00
|
|
|
|
2014-10-08 09:15:09 +00:00
|
|
|
// Type feedback information.
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE {
|
2014-10-20 11:42:56 +00:00
|
|
|
return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
|
|
|
|
}
|
2014-10-29 18:31:01 +00:00
|
|
|
virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
|
2014-10-08 09:15:09 +00:00
|
|
|
homeobject_feedback_slot_ = slot;
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot HomeObjectFeedbackSlot() {
|
2014-10-10 13:22:10 +00:00
|
|
|
DCHECK(!FLAG_vector_ics || !homeobject_feedback_slot_.IsInvalid());
|
2014-10-08 09:15:09 +00:00
|
|
|
return homeobject_feedback_slot_;
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:35:34 +00:00
|
|
|
protected:
|
2014-10-21 12:16:37 +00:00
|
|
|
SuperReference(Zone* zone, VariableProxy* this_var, int pos)
|
|
|
|
: Expression(zone, pos),
|
2014-10-08 09:15:09 +00:00
|
|
|
this_var_(this_var),
|
2014-10-20 11:42:56 +00:00
|
|
|
homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
|
2014-08-22 11:12:29 +00:00
|
|
|
DCHECK(this_var->is_this());
|
2014-08-18 12:35:34 +00:00
|
|
|
}
|
2014-10-21 12:16:37 +00:00
|
|
|
static int parent_num_ids() { return Expression::num_ids(); }
|
2014-10-21 08:52:32 +00:00
|
|
|
|
2014-10-21 10:55:12 +00:00
|
|
|
private:
|
2014-10-21 12:16:37 +00:00
|
|
|
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
|
|
|
|
|
2014-08-18 12:35:34 +00:00
|
|
|
VariableProxy* this_var_;
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorICSlot homeobject_feedback_slot_;
|
2014-08-18 12:35:34 +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-09-30 10:29:32 +00:00
|
|
|
std::ostream& Print(std::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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpDisjunction 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);
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpDisjunction* AsDisjunction() OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() OVERRIDE;
|
|
|
|
virtual bool IsDisjunction() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return min_match_; }
|
|
|
|
virtual int max_match() 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpAlternative 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);
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpAlternative* AsAlternative() OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() OVERRIDE;
|
|
|
|
virtual bool IsAlternative() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return min_match_; }
|
|
|
|
virtual int max_match() 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpAssertion 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) { }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpAssertion* AsAssertion() OVERRIDE;
|
|
|
|
virtual bool IsAssertion() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class CharacterSet 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpCharacterClass 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) { }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpCharacterClass* AsCharacterClass() OVERRIDE;
|
|
|
|
virtual bool IsCharacterClass() OVERRIDE;
|
|
|
|
virtual bool IsTextElement() OVERRIDE { return true; }
|
|
|
|
virtual int min_match() OVERRIDE { return 1; }
|
|
|
|
virtual int max_match() OVERRIDE { return 1; }
|
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone) 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpAtom FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
|
|
|
explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpAtom* AsAtom() OVERRIDE;
|
|
|
|
virtual bool IsAtom() OVERRIDE;
|
|
|
|
virtual bool IsTextElement() OVERRIDE { return true; }
|
|
|
|
virtual int min_match() OVERRIDE { return data_.length(); }
|
|
|
|
virtual int max_match() OVERRIDE { return data_.length(); }
|
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone) 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpText 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) {}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-12-17 10:59:14 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpText* AsText() OVERRIDE;
|
|
|
|
virtual bool IsText() OVERRIDE;
|
|
|
|
virtual bool IsTextElement() OVERRIDE { return true; }
|
|
|
|
virtual int min_match() OVERRIDE { return length_; }
|
|
|
|
virtual int max_match() OVERRIDE { return length_; }
|
|
|
|
virtual void AppendToText(RegExpText* text, Zone* zone) 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpQuantifier 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();
|
|
|
|
}
|
|
|
|
}
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) 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);
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual RegExpQuantifier* AsQuantifier() OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() OVERRIDE;
|
|
|
|
virtual bool IsQuantifier() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return min_match_; }
|
|
|
|
virtual int max_match() 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpCapture 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) { }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) 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);
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual RegExpCapture* AsCapture() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtEnd() OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() OVERRIDE;
|
|
|
|
virtual bool IsCapture() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return body_->min_match(); }
|
|
|
|
virtual int max_match() 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpLookahead 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) { }
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpLookahead* AsLookahead() OVERRIDE;
|
|
|
|
virtual Interval CaptureRegisters() OVERRIDE;
|
|
|
|
virtual bool IsLookahead() OVERRIDE;
|
|
|
|
virtual bool IsAnchoredAtStart() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpBackReference 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) { }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpBackReference* AsBackReference() OVERRIDE;
|
|
|
|
virtual bool IsBackReference() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() 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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-02 07:07:52 +00:00
|
|
|
class RegExpEmpty FINAL : public RegExpTree {
|
2008-11-25 11:07:48 +00:00
|
|
|
public:
|
|
|
|
RegExpEmpty() { }
|
2014-09-02 07:07:52 +00:00
|
|
|
virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
|
2008-11-25 11:07:48 +00:00
|
|
|
virtual RegExpNode* ToNode(RegExpCompiler* compiler,
|
2014-09-02 07:07:52 +00:00
|
|
|
RegExpNode* on_success) OVERRIDE;
|
|
|
|
virtual RegExpEmpty* AsEmpty() OVERRIDE;
|
|
|
|
virtual bool IsEmpty() OVERRIDE;
|
|
|
|
virtual int min_match() OVERRIDE { return 0; }
|
|
|
|
virtual int max_match() 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-09-02 07:07:52 +00:00
|
|
|
virtual void Visit(AstNode* node) FINAL 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-09-15 15:06:05 +00:00
|
|
|
AstConstructionVisitor()
|
|
|
|
: dont_crankshaft_reason_(kNoReason), dont_turbofan_reason_(kNoReason) {}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
|
|
|
AstProperties* ast_properties() { return &properties_; }
|
2014-09-15 15:06:05 +00:00
|
|
|
BailoutReason dont_optimize_reason() {
|
|
|
|
if (dont_turbofan_reason_ != kNoReason) {
|
|
|
|
return dont_turbofan_reason_;
|
|
|
|
} else {
|
|
|
|
return dont_crankshaft_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 add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); }
|
2014-09-15 15:06:05 +00:00
|
|
|
void set_dont_crankshaft_reason(BailoutReason reason) {
|
|
|
|
dont_crankshaft_reason_ = reason;
|
|
|
|
}
|
|
|
|
void set_dont_turbofan_reason(BailoutReason reason) {
|
|
|
|
dont_turbofan_reason_ = reason;
|
2013-09-05 13:20:51 +00:00
|
|
|
}
|
2012-02-08 09:56:33 +00:00
|
|
|
|
2014-10-02 09:38:28 +00:00
|
|
|
void add_slot_node(AstNode* slot_node) {
|
2014-10-20 11:42:56 +00:00
|
|
|
FeedbackVectorRequirements reqs = slot_node->ComputeFeedbackRequirements();
|
|
|
|
if (reqs.slots() > 0) {
|
2014-10-10 13:22:10 +00:00
|
|
|
slot_node->SetFirstFeedbackSlot(
|
|
|
|
FeedbackVectorSlot(properties_.feedback_slots()));
|
2014-10-20 11:42:56 +00:00
|
|
|
properties_.increase_feedback_slots(reqs.slots());
|
|
|
|
}
|
|
|
|
if (reqs.ic_slots() > 0) {
|
|
|
|
slot_node->SetFirstFeedbackICSlot(
|
|
|
|
FeedbackVectorICSlot(properties_.ic_feedback_slots()));
|
|
|
|
properties_.increase_ic_feedback_slots(reqs.ic_slots());
|
2014-04-30 10:51:01 +00:00
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
AstProperties properties_;
|
2014-09-15 15:06:05 +00:00
|
|
|
BailoutReason dont_crankshaft_reason_;
|
|
|
|
BailoutReason dont_turbofan_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>
|
2014-09-02 07:07:52 +00:00
|
|
|
class AstNodeFactory FINAL BASE_EMBEDDED {
|
2012-02-08 09:56:33 +00:00
|
|
|
public:
|
2014-10-21 12:16:37 +00:00
|
|
|
explicit AstNodeFactory(AstValueFactory* ast_value_factory)
|
|
|
|
: zone_(ast_value_factory->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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Block* block =
|
|
|
|
new (zone_) Block(zone_, labels, capacity, is_initializer_block, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(Block, block)
|
|
|
|
}
|
|
|
|
|
2014-08-22 11:12:29 +00:00
|
|
|
#define STATEMENT_WITH_LABELS(NodeType) \
|
2014-06-24 14:03:24 +00:00
|
|
|
NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
|
2014-10-21 12:16:37 +00:00
|
|
|
NodeType* stmt = new (zone_) NodeType(zone_, labels, pos); \
|
2014-08-22 11:12:29 +00:00
|
|
|
VISIT_AND_RETURN(NodeType, stmt); \
|
2012-02-08 09:56:33 +00:00
|
|
|
}
|
|
|
|
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-10-21 12:16:37 +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-10-21 12:16:37 +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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
IfStatement* stmt = new (zone_)
|
|
|
|
IfStatement(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-10-21 12:16:37 +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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
CaseClause* clause = 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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A JavaScript symbol (ECMA-262 edition 6).
|
|
|
|
Literal* NewSymbolLiteral(const char* name, int pos) {
|
2014-10-21 12:16:37 +00:00
|
|
|
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-10-21 12:16:37 +00:00
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewNumber(number), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewSmiLiteral(int number, int pos) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewBooleanLiteral(bool b, int pos) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewNullLiteral(int pos) {
|
|
|
|
Literal* lit =
|
2014-10-21 12:16:37 +00:00
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewUndefinedLiteral(int pos) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
VISIT_AND_RETURN(Literal, lit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal* NewTheHoleLiteral(int pos) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Literal* lit =
|
|
|
|
new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
|
2014-06-24 14:03:24 +00:00
|
|
|
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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
ObjectLiteral* lit =
|
|
|
|
new (zone_) ObjectLiteral(zone_, properties, literal_index,
|
|
|
|
boilerplate_properties, 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,
|
2014-09-16 22:15:39 +00:00
|
|
|
Expression* value,
|
|
|
|
bool is_static) {
|
|
|
|
return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key,
|
|
|
|
value, is_static);
|
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,
|
2014-09-16 22:15:39 +00:00
|
|
|
int pos, bool is_static) {
|
2012-02-08 09:56:33 +00:00
|
|
|
ObjectLiteral::Property* prop =
|
2014-09-16 22:15:39 +00:00
|
|
|
new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static);
|
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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
RegExpLiteral* lit =
|
|
|
|
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) {
|
2014-08-22 11:12:29 +00:00
|
|
|
ArrayLiteral* lit =
|
2014-10-21 12:16:37 +00:00
|
|
|
new (zone_) ArrayLiteral(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-10-21 12:16:37 +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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
VariableProxy* proxy =
|
|
|
|
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-10-21 12:16:37 +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-10-21 12:16:37 +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-10-21 12:16:37 +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-10-21 12:16:37 +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-10-21 12:16:37 +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-10-21 12:16:37 +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-10-21 12:16:37 +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-10-21 12:16:37 +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) {
|
2014-08-22 11:12:29 +00:00
|
|
|
Conditional* cond = new (zone_) Conditional(
|
2014-10-21 12:16:37 +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) {
|
2014-10-21 12:16:37 +00:00
|
|
|
Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
|
|
|
|
assign->Init(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);
|
2014-10-21 12:16:37 +00:00
|
|
|
Yield* yield =
|
|
|
|
new (zone_) Yield(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-10-21 12:16:37 +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-07-21 09:58:01 +00:00
|
|
|
const AstRawString* name, AstValueFactory* ast_value_factory,
|
|
|
|
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,
|
2014-09-10 16:39:42 +00:00
|
|
|
FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
|
|
|
|
int position) {
|
2014-07-21 09:58:01 +00:00
|
|
|
FunctionLiteral* lit = new (zone_) FunctionLiteral(
|
|
|
|
zone_, name, ast_value_factory, scope, body, materialized_literal_count,
|
|
|
|
expected_property_count, handler_count, parameter_count, function_type,
|
2014-10-21 12:16:37 +00:00
|
|
|
has_duplicate_parameters, is_function, is_parenthesized, kind,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-16 22:15:39 +00:00
|
|
|
ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends,
|
2014-09-18 17:39:49 +00:00
|
|
|
Expression* constructor,
|
2014-09-16 22:15:39 +00:00
|
|
|
ZoneList<ObjectLiteral::Property*>* properties,
|
2014-10-08 14:48:48 +00:00
|
|
|
int start_position, int end_position) {
|
|
|
|
ClassLiteral* lit =
|
|
|
|
new (zone_) ClassLiteral(zone_, name, extends, constructor, properties,
|
2014-10-21 12:16:37 +00:00
|
|
|
start_position, end_position);
|
2014-09-16 22:15:39 +00:00
|
|
|
VISIT_AND_RETURN(ClassLiteral, lit)
|
|
|
|
}
|
|
|
|
|
2014-08-22 11:12:29 +00:00
|
|
|
NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
|
|
|
|
v8::Extension* extension,
|
|
|
|
int pos) {
|
2013-10-01 09:47:37 +00:00
|
|
|
NativeFunctionLiteral* lit =
|
2014-10-21 12:16:37 +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-10-21 12:16:37 +00:00
|
|
|
ThisFunction* fun = new (zone_) ThisFunction(zone_, pos);
|
2012-02-08 09:56:33 +00:00
|
|
|
VISIT_AND_RETURN(ThisFunction, fun)
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:35:34 +00:00
|
|
|
SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
|
2014-10-21 12:16:37 +00:00
|
|
|
SuperReference* super = new (zone_) SuperReference(zone_, this_var, pos);
|
2014-08-18 12:35:34 +00:00
|
|
|
VISIT_AND_RETURN(SuperReference, super);
|
|
|
|
}
|
|
|
|
|
2012-02-08 09:56:33 +00:00
|
|
|
#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_
|