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

Unified Diff: src/ast.h

Issue 3146037: Cleanup the AST code by removing unused parts and get rid of the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 4 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
Index: src/ast.h
===================================================================
--- src/ast.h (revision 5322)
+++ src/ast.h (working copy)
@@ -92,6 +92,7 @@
V(CountOperation) \
V(BinaryOperation) \
V(CompareOperation) \
+ V(CompareToNull) \
V(ThisFunction)
#define AST_NODE_LIST(V) \
@@ -118,12 +119,6 @@
class AstNode: public ZoneObject {
public:
- static const int kNoNumber = -1;
-
- AstNode() : num_(kNoNumber) {}
-
- explicit AstNode(AstNode* other);
-
virtual ~AstNode() { }
virtual void Accept(AstVisitor* v) = 0;
@@ -151,20 +146,6 @@
virtual ObjectLiteral* AsObjectLiteral() { return NULL; }
virtual ArrayLiteral* AsArrayLiteral() { return NULL; }
virtual CompareOperation* AsCompareOperation() { return NULL; }
-
- // True if the AST node is critical (its execution is needed or externally
- // visible in some way).
- virtual bool IsCritical() {
- UNREACHABLE();
- return true;
- }
-
- int num() { return num_; }
- void set_num(int n) { num_ = n; }
-
- private:
- // Support for ast node numbering.
- int num_;
};
@@ -172,8 +153,6 @@
public:
Statement() : statement_pos_(RelocInfo::kNoPosition) {}
- explicit Statement(Statement* other);
-
virtual Statement* AsStatement() { return this; }
virtual ReturnStatement* AsReturnStatement() { return NULL; }
@@ -206,32 +185,16 @@
Expression() : bitfields_(0) {}
- explicit Expression(Expression* other);
-
virtual Expression* AsExpression() { return this; }
+ virtual bool IsTrivial() { return false; }
virtual bool IsValidLeftHandSide() { return false; }
- virtual Variable* AssignedVariable() { 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.
virtual bool IsPropertyName() { return false; }
- // True if the expression does not have (evaluated) subexpressions.
- // Function literals are leaves because their subexpressions are not
- // evaluated.
- virtual bool IsLeaf() { return false; }
-
- // True if the expression has no side effects and is safe to
- // 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.
@@ -253,7 +216,8 @@
// top operation is a bit operation with a mask, or a shift.
bool GuaranteedSmiResult();
- // AST analysis results
+ // AST analysis results.
+ void CopyAnalysisResultsFrom(Expression* other);
// True if the expression rooted at this node can be compiled by the
// side-effect free compiler.
@@ -314,11 +278,6 @@
virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
static ValidLeftHandSideSentinel* instance() { return &instance_; }
- virtual bool IsPrimitive() {
- UNREACHABLE();
- return false;
- }
-
private:
static ValidLeftHandSideSentinel instance_;
};
@@ -347,8 +306,6 @@
protected:
inline BreakableStatement(ZoneStringList* labels, Type type);
- explicit BreakableStatement(BreakableStatement* other);
-
private:
ZoneStringList* labels_;
Type type_;
@@ -360,10 +317,6 @@
public:
inline Block(ZoneStringList* labels, int capacity, bool 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; }
@@ -427,10 +380,6 @@
protected:
explicit inline IterationStatement(ZoneStringList* labels);
- // 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;
}
@@ -480,13 +429,14 @@
bool may_have_function_literal() const {
return may_have_function_literal_;
}
+ void set_may_have_function_literal(bool value) {
+ may_have_function_literal_ = value;
+ }
private:
Expression* cond_;
// True if there is a function literal subexpression in the condition.
bool may_have_function_literal_;
-
- friend class AstOptimizer;
};
@@ -494,14 +444,6 @@
public:
explicit inline ForStatement(ZoneStringList* labels);
- // 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,
@@ -522,17 +464,18 @@
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_;
}
+ void set_may_have_function_literal(bool value) {
+ may_have_function_literal_ = value;
+ }
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_;
@@ -540,9 +483,6 @@
// 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;
};
@@ -572,10 +512,6 @@
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.
@@ -715,13 +651,6 @@
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(); }
@@ -828,8 +757,6 @@
public:
EmptyStatement() {}
- explicit EmptyStatement(EmptyStatement* other);
-
virtual void Accept(AstVisitor* v);
// Type testing & conversion.
@@ -842,6 +769,7 @@
explicit Literal(Handle<Object> handle) : handle_(handle) { }
virtual void Accept(AstVisitor* v);
+ virtual bool IsTrivial() { return true; }
// Type testing & conversion.
virtual Literal* AsLiteral() { return this; }
@@ -859,11 +787,6 @@
return false;
}
- virtual bool IsLeaf() { return true; }
- virtual bool IsTrivial() { return true; }
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
// Identity testers.
bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); }
bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); }
@@ -910,7 +833,6 @@
// to the code generator.
class Property: public ZoneObject {
public:
-
enum Kind {
CONSTANT, // Property with constant value (compile time).
COMPUTED, // Property with computed value (execution time).
@@ -948,10 +870,6 @@
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_;
}
@@ -978,10 +896,6 @@
virtual void Accept(AstVisitor* v);
- virtual bool IsLeaf() { return true; }
-
- virtual bool IsPrimitive();
-
Handle<String> pattern() const { return pattern_; }
Handle<String> flags() const { return flags_; }
@@ -1006,10 +920,6 @@
virtual void Accept(AstVisitor* v);
virtual ArrayLiteral* AsArrayLiteral() { return this; }
- virtual bool IsLeaf() { return values()->is_empty(); }
-
- virtual bool IsPrimitive();
-
Handle<FixedArray> constant_elements() const { return constant_elements_; }
ZoneList<Expression*>* values() const { return values_; }
@@ -1030,8 +940,6 @@
virtual void Accept(AstVisitor* v);
- virtual bool IsPrimitive();
-
Literal* key() const { return key_; }
VariableProxy* value() const { return value_; }
@@ -1049,8 +957,11 @@
virtual Property* AsProperty() {
return var_ == NULL ? NULL : var_->AsProperty();
}
- virtual VariableProxy* AsVariableProxy() { return this; }
+ virtual VariableProxy* AsVariableProxy() {
+ return this;
+ }
+
Variable* AsVariable() {
return this == NULL || var_ == NULL ? NULL : var_->AsVariable();
}
@@ -1059,20 +970,12 @@
return var_ == NULL ? true : var_->IsValidLeftHandSide();
}
- virtual bool IsLeaf() {
- ASSERT(var_ != NULL); // Variable must be resolved.
- return var()->is_global() || var()->rewrite()->IsLeaf();
+ virtual bool IsTrivial() {
+ // Reading from a mutable variable is a side effect, but the
+ // variable for 'this' is immutable.
+ return is_this_ || is_trivial_;
}
- // Reading from a mutable variable is a side effect, but 'this' is
- // immutable.
- virtual bool IsTrivial() { return is_trivial_; }
-
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
- void SetIsPrimitive(bool value) { is_primitive_ = value; }
-
bool IsVariable(Handle<String> n) {
return !is_this() && name().is_identical_to(n);
}
@@ -1086,11 +989,8 @@
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; }
+ void MarkAsTrivial() { is_trivial_ = true; }
// Bind this proxy to the variable var.
void BindTo(Variable* var);
@@ -1101,8 +1001,6 @@
bool is_this_;
bool inside_with_;
bool is_trivial_;
- BitVector* reaching_definitions_;
- bool is_primitive_;
VariableProxy(Handle<String> name, bool is_this, bool inside_with);
explicit VariableProxy(bool is_this);
@@ -1119,11 +1017,6 @@
return &identifier_proxy_;
}
- virtual bool IsPrimitive() {
- UNREACHABLE();
- return false;
- }
-
private:
explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { }
static VariableProxySentinel this_proxy_;
@@ -1165,13 +1058,6 @@
// Type testing & conversion
virtual Slot* AsSlot() { return this; }
- virtual bool IsLeaf() { return true; }
-
- virtual bool IsPrimitive() {
- UNREACHABLE();
- return false;
- }
-
bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; }
// Accessors
@@ -1197,8 +1083,6 @@
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
@@ -1206,9 +1090,6 @@
virtual bool IsValidLeftHandSide() { return true; }
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
Expression* obj() const { return obj_; }
Expression* key() const { return key_; }
int position() const { return pos_; }
@@ -1234,16 +1115,11 @@
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();
- virtual bool IsCritical();
-
Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
int position() { return pos_; }
@@ -1266,8 +1142,6 @@
virtual void Accept(AstVisitor* v);
- virtual bool IsPrimitive();
-
Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; }
int position() { return pos_; }
@@ -1292,8 +1166,6 @@
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_; }
@@ -1313,16 +1185,11 @@
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();
- virtual bool IsCritical();
-
Token::Value op() const { return op_; }
Expression* expression() const { return expression_; }
@@ -1339,22 +1206,11 @@
ASSERT(Token::IsBinaryOp(op));
}
- // Construct a binary operation with a given operator and left and right
- // subexpressions. The rest of the expression state is copied from
- // another expression.
- BinaryOperation(Expression* other,
- Token::Value op,
- Expression* left,
- Expression* right);
-
virtual void Accept(AstVisitor* v);
// Type testing & conversion
virtual BinaryOperation* AsBinaryOperation() { return this; }
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
// True iff the result can be safely overwritten (to avoid allocation).
// False for operations that can return one of their operands.
bool ResultOverwriteAllowed() {
@@ -1399,19 +1255,10 @@
ASSERT(Token::IsCountOp(op));
}
- CountOperation(CountOperation* other, Expression* expression);
-
virtual void Accept(AstVisitor* v);
virtual CountOperation* AsCountOperation() { return this; }
- virtual Variable* AssignedVariable() {
- return expression()->AsVariableProxy()->AsVariable();
- }
-
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
bool is_prefix() const { return is_prefix_; }
bool is_postfix() const { return !is_prefix_; }
Token::Value op() const { return op_; }
@@ -1436,15 +1283,8 @@
ASSERT(Token::IsCompareOp(op));
}
- CompareOperation(CompareOperation* other,
- Expression* left,
- Expression* right);
-
virtual void Accept(AstVisitor* v);
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
Token::Value op() const { return op_; }
Expression* left() const { return left_; }
Expression* right() const { return right_; }
@@ -1459,6 +1299,23 @@
};
+class CompareToNull: public Expression {
+ public:
+ CompareToNull(bool is_strict, Expression* expression)
+ : is_strict_(is_strict), expression_(expression) { }
+
+ virtual void Accept(AstVisitor* v);
+
+ bool is_strict() const { return is_strict_; }
+ Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; }
+ Expression* expression() const { return expression_; }
+
+ private:
+ bool is_strict_;
+ Expression* expression_;
+};
+
+
class Conditional: public Expression {
public:
Conditional(Expression* condition,
@@ -1474,8 +1331,6 @@
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_; }
@@ -1500,20 +1355,11 @@
ASSERT(Token::IsAssignmentOp(op));
}
- Assignment(Assignment* other, Expression* target, Expression* value);
-
virtual void Accept(AstVisitor* v);
virtual Assignment* AsAssignment() { return this; }
- virtual bool IsPrimitive();
- virtual bool IsCritical();
-
Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
- virtual Variable* AssignedVariable() {
- return target()->AsVariableProxy()->AsVariable();
- }
-
Token::Value binary_op() const;
Token::Value op() const { return op_; }
@@ -1549,8 +1395,6 @@
virtual void Accept(AstVisitor* v);
- virtual bool IsPrimitive();
-
Expression* exception() const { return exception_; }
int position() const { return pos_; }
@@ -1598,10 +1442,6 @@
// Type testing & conversion
virtual FunctionLiteral* AsFunctionLiteral() { return this; }
- 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_; }
@@ -1669,12 +1509,8 @@
return shared_function_info_;
}
- virtual bool IsLeaf() { return true; }
-
virtual void Accept(AstVisitor* v);
- virtual bool IsPrimitive();
-
private:
Handle<SharedFunctionInfo> shared_function_info_;
};
@@ -1683,8 +1519,6 @@
class ThisFunction: public Expression {
public:
virtual void Accept(AstVisitor* v);
- virtual bool IsLeaf() { return true; }
- virtual bool IsPrimitive();
};
@@ -2072,29 +1906,6 @@
bool stack_overflow_;
};
-
-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/arm/full-codegen-arm.cc ('k') | src/ast.cc » ('j') | src/x64/full-codegen-x64.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698