Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: src/ast.h

Issue 1148007: Merge bleeding_edge from version 2.1.3 up to revision 4205... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/array.js ('k') | src/ast.cc » ('j') | src/heap.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.h
===================================================================
--- src/ast.h (revision 4205)
+++ src/ast.h (working copy)
@@ -103,6 +103,7 @@
class TargetCollector;
class MaterializedLiteral;
class DefinitionInfo;
+class BitVector;
#define DEF_FORWARD_DECLARATION(type) class type;
AST_NODE_LIST(DEF_FORWARD_DECLARATION)
@@ -120,11 +121,15 @@
static const int kNoNumber = -1;
AstNode() : num_(kNoNumber) {}
+
+ explicit AstNode(AstNode* other);
+
virtual ~AstNode() { }
virtual void Accept(AstVisitor* v) = 0;
// Type testing & conversion.
virtual Statement* AsStatement() { return NULL; }
+ virtual Block* AsBlock() { return NULL; }
virtual ExpressionStatement* AsExpressionStatement() { return NULL; }
virtual EmptyStatement* AsEmptyStatement() { return NULL; }
virtual Expression* AsExpression() { return NULL; }
@@ -136,7 +141,9 @@
virtual TargetCollector* AsTargetCollector() { return NULL; }
virtual BreakableStatement* AsBreakableStatement() { return NULL; }
virtual IterationStatement* AsIterationStatement() { return NULL; }
+ virtual ForStatement* AsForStatement() { return NULL; }
virtual UnaryOperation* AsUnaryOperation() { return NULL; }
+ virtual CountOperation* AsCountOperation() { return NULL; }
virtual BinaryOperation* AsBinaryOperation() { return NULL; }
virtual Assignment* AsAssignment() { return NULL; }
virtual FunctionLiteral* AsFunctionLiteral() { return NULL; }
@@ -158,9 +165,14 @@
public:
Statement() : statement_pos_(RelocInfo::kNoPosition) {}
+ explicit Statement(Statement* other);
+
virtual Statement* AsStatement() { return this; }
virtual ReturnStatement* AsReturnStatement() { return NULL; }
+ virtual Assignment* StatementAsSimpleAssignment() { return NULL; }
+ virtual CountOperation* StatementAsCountOperation() { return NULL; }
+
bool IsEmpty() { return AsEmptyStatement() != NULL; }
void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
@@ -191,15 +203,16 @@
kTestValue
};
- Expression()
- : bitfields_(0),
- def_(NULL),
- defined_vars_(NULL) {}
+ Expression() : bitfields_(0) {}
+ explicit Expression(Expression* other);
+
virtual Expression* AsExpression() { return this; }
virtual bool IsValidLeftHandSide() { return false; }
+ virtual Variable* AssignedVar() { return NULL; }
+
// 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.
@@ -214,6 +227,10 @@
// evaluate out of order.
virtual bool IsTrivial() { return false; }
+ // True if the expression always has one of the non-Object JS types
+ // (Undefined, Null, Boolean, String, or Number).
+ virtual bool IsPrimitive() = 0;
+
// Mark the expression as being compiled as an expression
// statement. This is used to transform postfix increments to
// (faster) prefix increments.
@@ -222,15 +239,6 @@
// Static type information for this expression.
StaticType* type() { return &type_; }
- // Data flow information.
- DefinitionInfo* var_def() { return def_; }
- void set_var_def(DefinitionInfo* def) { def_ = def; }
-
- ZoneList<DefinitionInfo*>* defined_vars() { return defined_vars_; }
- void set_defined_vars(ZoneList<DefinitionInfo*>* defined_vars) {
- defined_vars_ = defined_vars;
- }
-
// AST analysis results
// True if the expression rooted at this node can be compiled by the
@@ -241,6 +249,14 @@
bitfields_ |= SideEffectFreeField::encode(is_side_effect_free);
}
+ // Will the use of this expression treat -0 the same as 0 in all cases?
+ // If so, we can return 0 instead of -0 if we want to, to optimize code.
+ bool no_negative_zero() { return NoNegativeZeroField::decode(bitfields_); }
+ void set_no_negative_zero(bool no_negative_zero) {
+ bitfields_ &= ~NoNegativeZeroField::mask();
+ bitfields_ |= NoNegativeZeroField::encode(no_negative_zero);
+ }
+
// Will ToInt32 (ECMA 262-3 9.5) or ToUint32 (ECMA 262-3 9.6)
// be applied to the value of this expression?
// If so, we may be able to optimize the calculation of the value.
@@ -250,17 +266,25 @@
bitfields_ |= ToInt32Field::encode(to_int32);
}
+ // How many bitwise logical or shift operators are used in this expression?
+ int num_bit_ops() { return NumBitOpsField::decode(bitfields_); }
+ void set_num_bit_ops(int num_bit_ops) {
+ bitfields_ &= ~NumBitOpsField::mask();
+ num_bit_ops = Min(num_bit_ops, kMaxNumBitOps);
+ bitfields_ |= NumBitOpsField::encode(num_bit_ops);
+ }
private:
+ static const int kMaxNumBitOps = (1 << 5) - 1;
+
uint32_t bitfields_;
StaticType type_;
- DefinitionInfo* def_;
- ZoneList<DefinitionInfo*>* defined_vars_;
-
// Using template BitField<type, start, size>.
class SideEffectFreeField : public BitField<bool, 0, 1> {};
- class ToInt32Field : public BitField<bool, 1, 1> {};
+ class NoNegativeZeroField : public BitField<bool, 1, 1> {};
+ class ToInt32Field : public BitField<bool, 2, 1> {};
+ class NumBitOpsField : public BitField<int, 3, 5> {};
};
@@ -274,6 +298,12 @@
virtual bool IsValidLeftHandSide() { return true; }
virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
static ValidLeftHandSideSentinel* instance() { return &instance_; }
+
+ virtual bool IsPrimitive() {
+ UNREACHABLE();
+ return false;
+ }
+
private:
static ValidLeftHandSideSentinel instance_;
};
@@ -305,6 +335,8 @@
ASSERT(labels == NULL || labels->length() > 0);
}
+ explicit BreakableStatement(BreakableStatement* other);
+
private:
ZoneStringList* labels_;
Type type_;
@@ -319,8 +351,24 @@
statements_(capacity),
is_initializer_block_(is_initializer_block) { }
+ // Construct a clone initialized from the original block and
+ // a deep copy of all statements of the original block.
+ Block(Block* other, ZoneList<Statement*>* statements);
+
virtual void Accept(AstVisitor* v);
+ virtual Block* AsBlock() { return this; }
+
+ virtual Assignment* StatementAsSimpleAssignment() {
+ if (statements_.length() != 1) return NULL;
+ return statements_[0]->StatementAsSimpleAssignment();
+ }
+
+ virtual CountOperation* StatementAsCountOperation() {
+ if (statements_.length() != 1) return NULL;
+ return statements_[0]->StatementAsCountOperation();
+ }
+
void AddStatement(Statement* statement) { statements_.Add(statement); }
ZoneList<Statement*>* statements() { return &statements_; }
@@ -362,6 +410,7 @@
virtual IterationStatement* AsIterationStatement() { return this; }
Statement* body() const { return body_; }
+ void set_body(Statement* stmt) { body_ = stmt; }
// Code generation
BreakTarget* continue_target() { return &continue_target_; }
@@ -370,6 +419,10 @@
explicit IterationStatement(ZoneStringList* labels)
: BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { }
+ // Construct a clone initialized from original and
+ // a deep copy of the original body.
+ IterationStatement(IterationStatement* other, Statement* body);
+
void Initialize(Statement* body) {
body_ = body;
}
@@ -442,9 +495,20 @@
init_(NULL),
cond_(NULL),
next_(NULL),
- may_have_function_literal_(true) {
- }
+ may_have_function_literal_(true),
+ loop_variable_(NULL),
+ peel_this_loop_(false) {}
+ // Construct a for-statement initialized from another for-statement
+ // and deep copies of all parts of the original statement.
+ ForStatement(ForStatement* other,
+ Statement* init,
+ Expression* cond,
+ Statement* next,
+ Statement* body);
+
+ virtual ForStatement* AsForStatement() { return this; }
+
void Initialize(Statement* init,
Expression* cond,
Statement* next,
@@ -458,18 +522,30 @@
virtual void Accept(AstVisitor* v);
Statement* init() const { return init_; }
+ void set_init(Statement* stmt) { init_ = stmt; }
Expression* cond() const { return cond_; }
+ void set_cond(Expression* expr) { cond_ = expr; }
Statement* next() const { return next_; }
+ void set_next(Statement* stmt) { next_ = stmt; }
bool may_have_function_literal() const {
return may_have_function_literal_;
}
+ bool is_fast_smi_loop() { return loop_variable_ != NULL; }
+ Variable* loop_variable() { return loop_variable_; }
+ void set_loop_variable(Variable* var) { loop_variable_ = var; }
+
+ bool peel_this_loop() { return peel_this_loop_; }
+ void set_peel_this_loop(bool b) { peel_this_loop_ = b; }
+
private:
Statement* init_;
Expression* cond_;
Statement* next_;
// True if there is a function literal subexpression in the condition.
bool may_have_function_literal_;
+ Variable* loop_variable_;
+ bool peel_this_loop_;
friend class AstOptimizer;
};
@@ -502,11 +578,18 @@
explicit ExpressionStatement(Expression* expression)
: expression_(expression) { }
+ // Construct an expression statement initialized from another
+ // expression statement and a deep copy of the original expression.
+ ExpressionStatement(ExpressionStatement* other, Expression* expression);
+
virtual void Accept(AstVisitor* v);
// Type testing & conversion.
virtual ExpressionStatement* AsExpressionStatement() { return this; }
+ virtual Assignment* StatementAsSimpleAssignment();
+ virtual CountOperation* StatementAsCountOperation();
+
void set_expression(Expression* e) { expression_ = e; }
Expression* expression() { return expression_; }
@@ -641,6 +724,13 @@
then_statement_(then_statement),
else_statement_(else_statement) { }
+ // Construct an if-statement initialized from another if-statement
+ // and deep copies of all parts of the original.
+ IfStatement(IfStatement* other,
+ Expression* condition,
+ Statement* then_statement,
+ Statement* else_statement);
+
virtual void Accept(AstVisitor* v);
bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
@@ -648,7 +738,9 @@
Expression* condition() const { return condition_; }
Statement* then_statement() const { return then_statement_; }
+ void set_then_statement(Statement* stmt) { then_statement_ = stmt; }
Statement* else_statement() const { return else_statement_; }
+ void set_else_statement(Statement* stmt) { else_statement_ = stmt; }
private:
Expression* condition_;
@@ -743,6 +835,10 @@
class EmptyStatement: public Statement {
public:
+ EmptyStatement() {}
+
+ explicit EmptyStatement(EmptyStatement* other);
+
virtual void Accept(AstVisitor* v);
// Type testing & conversion.
@@ -774,6 +870,7 @@
virtual bool IsLeaf() { return true; }
virtual bool IsTrivial() { return true; }
+ virtual bool IsPrimitive();
// Identity testers.
bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); }
@@ -849,24 +946,31 @@
ZoneList<Property*>* properties,
int literal_index,
bool is_simple,
+ bool fast_elements,
int depth)
: MaterializedLiteral(literal_index, is_simple, depth),
constant_properties_(constant_properties),
- properties_(properties) {}
+ properties_(properties),
+ fast_elements_(fast_elements) {}
virtual ObjectLiteral* AsObjectLiteral() { return this; }
virtual void Accept(AstVisitor* v);
virtual bool IsLeaf() { return properties()->is_empty(); }
+ virtual bool IsPrimitive();
+
Handle<FixedArray> constant_properties() const {
return constant_properties_;
}
ZoneList<Property*>* properties() const { return properties_; }
+ bool fast_elements() const { return fast_elements_; }
+
private:
Handle<FixedArray> constant_properties_;
ZoneList<Property*>* properties_;
+ bool fast_elements_;
};
@@ -884,6 +988,8 @@
virtual bool IsLeaf() { return true; }
+ virtual bool IsPrimitive();
+
Handle<String> pattern() const { return pattern_; }
Handle<String> flags() const { return flags_; }
@@ -910,6 +1016,8 @@
virtual bool IsLeaf() { return values()->is_empty(); }
+ virtual bool IsPrimitive();
+
Handle<FixedArray> constant_elements() const { return constant_elements_; }
ZoneList<Expression*>* values() const { return values_; }
@@ -930,6 +1038,8 @@
virtual void Accept(AstVisitor* v);
+ virtual bool IsPrimitive();
+
Literal* key() const { return key_; }
VariableProxy* value() const { return value_; }
@@ -964,8 +1074,10 @@
// Reading from a mutable variable is a side effect, but 'this' is
// immutable.
- virtual bool IsTrivial() { return is_this(); }
+ virtual bool IsTrivial() { return is_trivial_; }
+ virtual bool IsPrimitive();
+
bool IsVariable(Handle<String> n) {
return !is_this() && name().is_identical_to(n);
}
@@ -979,7 +1091,12 @@
Variable* var() const { return var_; }
bool is_this() const { return is_this_; }
bool inside_with() const { return inside_with_; }
+ bool is_trivial() { return is_trivial_; }
+ void set_is_trivial(bool b) { is_trivial_ = b; }
+ BitVector* reaching_definitions() { return reaching_definitions_; }
+ void set_reaching_definitions(BitVector* rd) { reaching_definitions_ = rd; }
+
// Bind this proxy to the variable var.
void BindTo(Variable* var);
@@ -988,6 +1105,8 @@
Variable* var_; // resolved variable, or NULL
bool is_this_;
bool inside_with_;
+ bool is_trivial_;
+ BitVector* reaching_definitions_;
VariableProxy(Handle<String> name, bool is_this, bool inside_with);
explicit VariableProxy(bool is_this);
@@ -1004,6 +1123,11 @@
return &identifier_proxy_;
}
+ virtual bool IsPrimitive() {
+ UNREACHABLE();
+ return false;
+ }
+
private:
explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { }
static VariableProxySentinel this_proxy_;
@@ -1047,6 +1171,11 @@
virtual bool IsLeaf() { return true; }
+ virtual bool IsPrimitive() {
+ UNREACHABLE();
+ return false;
+ }
+
bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; }
// Accessors
@@ -1072,6 +1201,8 @@
Property(Expression* obj, Expression* key, int pos, Type type = NORMAL)
: obj_(obj), key_(key), pos_(pos), type_(type) { }
+ Property(Property* other, Expression* obj, Expression* key);
+
virtual void Accept(AstVisitor* v);
// Type testing & conversion
@@ -1079,6 +1210,8 @@
virtual bool IsValidLeftHandSide() { return true; }
+ virtual bool IsPrimitive();
+
Expression* obj() const { return obj_; }
Expression* key() const { return key_; }
int position() const { return pos_; }
@@ -1104,11 +1237,15 @@
Call(Expression* expression, ZoneList<Expression*>* arguments, int pos)
: expression_(expression), arguments_(arguments), pos_(pos) { }
+ Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments);
+
virtual void Accept(AstVisitor* v);
// Type testing and conversion.
virtual Call* AsCall() { return this; }
+ virtual bool IsPrimitive();
+
Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
int position() { return pos_; }
@@ -1131,6 +1268,8 @@
virtual void Accept(AstVisitor* v);
+ virtual bool IsPrimitive();
+
Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
int position() { return pos_; }
@@ -1155,6 +1294,8 @@
virtual void Accept(AstVisitor* v);
+ virtual bool IsPrimitive();
+
Handle<String> name() const { return name_; }
Runtime::Function* function() const { return function_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
@@ -1174,11 +1315,15 @@
ASSERT(Token::IsUnaryOp(op));
}
+ UnaryOperation(UnaryOperation* other, Expression* expression);
+
virtual void Accept(AstVisitor* v);
// Type testing & conversion
virtual UnaryOperation* AsUnaryOperation() { return this; }
+ virtual bool IsPrimitive();
+
Token::Value op() const { return op_; }
Expression* expression() const { return expression_; }
@@ -1195,11 +1340,15 @@
ASSERT(Token::IsBinaryOp(op));
}
+ BinaryOperation(BinaryOperation* other, Expression* left, Expression* right);
+
virtual void Accept(AstVisitor* v);
// Type testing & conversion
virtual BinaryOperation* AsBinaryOperation() { return this; }
+ virtual bool IsPrimitive();
+
// True iff the result can be safely overwritten (to avoid allocation).
// False for operations that can return one of their operands.
bool ResultOverwriteAllowed() {
@@ -1244,8 +1393,18 @@
ASSERT(Token::IsCountOp(op));
}
+ CountOperation(CountOperation* other, Expression* expression);
+
virtual void Accept(AstVisitor* v);
+ virtual CountOperation* AsCountOperation() { return this; }
+
+ virtual Variable* AssignedVar() {
+ return expression()->AsVariableProxy()->AsVariable();
+ }
+
+ virtual bool IsPrimitive();
+
bool is_prefix() const { return is_prefix_; }
bool is_postfix() const { return !is_prefix_; }
Token::Value op() const { return op_; }
@@ -1270,8 +1429,14 @@
ASSERT(Token::IsCompareOp(op));
}
+ CompareOperation(CompareOperation* other,
+ Expression* left,
+ Expression* right);
+
virtual void Accept(AstVisitor* v);
+ virtual bool IsPrimitive();
+
Token::Value op() const { return op_; }
Expression* left() const { return left_; }
Expression* right() const { return right_; }
@@ -1302,6 +1467,8 @@
virtual void Accept(AstVisitor* v);
+ virtual bool IsPrimitive();
+
Expression* condition() const { return condition_; }
Expression* then_expression() const { return then_expression_; }
Expression* else_expression() const { return else_expression_; }
@@ -1321,9 +1488,19 @@
ASSERT(Token::IsAssignmentOp(op));
}
+ Assignment(Assignment* other, Expression* target, Expression* value);
+
virtual void Accept(AstVisitor* v);
virtual Assignment* AsAssignment() { return this; }
+ virtual bool IsPrimitive();
+
+ Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
+
+ virtual Variable* AssignedVar() {
+ return target()->AsVariableProxy()->AsVariable();
+ }
+
Token::Value binary_op() const;
Token::Value op() const { return op_; }
@@ -1358,6 +1535,9 @@
: exception_(exception), pos_(pos) {}
virtual void Accept(AstVisitor* v);
+
+ virtual bool IsPrimitive();
+
Expression* exception() const { return exception_; }
int position() const { return pos_; }
@@ -1407,6 +1587,8 @@
virtual bool IsLeaf() { return true; }
+ virtual bool IsPrimitive();
+
Handle<String> name() const { return name_; }
Scope* scope() const { return scope_; }
ZoneList<Statement*>* body() const { return body_; }
@@ -1477,6 +1659,8 @@
virtual void Accept(AstVisitor* v);
+ virtual bool IsPrimitive();
+
private:
Handle<JSFunction> boilerplate_;
};
@@ -1486,6 +1670,7 @@
public:
virtual void Accept(AstVisitor* v);
virtual bool IsLeaf() { return true; }
+ virtual bool IsPrimitive();
};
@@ -1880,6 +2065,28 @@
};
+class CopyAstVisitor : public AstVisitor {
+ public:
+ Expression* DeepCopyExpr(Expression* expr);
+
+ Statement* DeepCopyStmt(Statement* stmt);
+
+ private:
+ ZoneList<Expression*>* DeepCopyExprList(ZoneList<Expression*>* expressions);
+
+ ZoneList<Statement*>* DeepCopyStmtList(ZoneList<Statement*>* statements);
+
+ // AST node visit functions.
+#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
+ AST_NODE_LIST(DECLARE_VISIT)
+#undef DECLARE_VISIT
+
+ // Holds the result of copying an expression.
+ Expression* expr_;
+ // Holds the result of copying a statement.
+ Statement* stmt_;
+};
+
} } // namespace v8::internal
#endif // V8_AST_H_
« no previous file with comments | « src/array.js ('k') | src/ast.cc » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698