Unify handling of position info in AST, part 3

* Turn CaseClause into a proper AstNode

R=yangguo@chromium.org
BUG=

Review URL: https://codereview.chromium.org/23684058

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
rossberg@chromium.org 2013-10-14 11:06:15 +00:00
parent 629b26c519
commit c806a2385d
8 changed files with 77 additions and 43 deletions

View File

@ -1034,9 +1034,9 @@ CaseClause::CaseClause(Isolate* isolate,
Expression* label,
ZoneList<Statement*>* statements,
int pos)
: label_(label),
: AstNode(pos),
label_(label),
statements_(statements),
position_(pos),
compare_type_(Type::None(), isolate),
compare_id_(AstNode::GetNextId(isolate)),
entry_id_(AstNode::GetNextId(isolate)) {
@ -1078,6 +1078,7 @@ REGULAR_NODE(ContinueStatement)
REGULAR_NODE(BreakStatement)
REGULAR_NODE(ReturnStatement)
REGULAR_NODE(SwitchStatement)
REGULAR_NODE(CaseClause)
REGULAR_NODE(Conditional)
REGULAR_NODE(Literal)
REGULAR_NODE(ArrayLiteral)

View File

@ -117,11 +117,15 @@ namespace internal {
V(CompareOperation) \
V(ThisFunction)
#define AUXILIARY_NODE_LIST(V) \
V(CaseClause)
#define AST_NODE_LIST(V) \
DECLARATION_NODE_LIST(V) \
MODULE_NODE_LIST(V) \
STATEMENT_NODE_LIST(V) \
EXPRESSION_NODE_LIST(V)
EXPRESSION_NODE_LIST(V) \
AUXILIARY_NODE_LIST(V)
// Forward declarations
class AstConstructionVisitor;
@ -1102,12 +1106,9 @@ class WithStatement V8_FINAL : public Statement {
};
class CaseClause V8_FINAL : public ZoneObject {
class CaseClause V8_FINAL : public AstNode {
public:
CaseClause(Isolate* isolate,
Expression* label,
ZoneList<Statement*>* statements,
int pos);
DECLARE_NODE_TYPE(CaseClause)
bool is_default() const { return label_ == NULL; }
Expression* label() const {
@ -1117,9 +1118,6 @@ class CaseClause V8_FINAL : public ZoneObject {
Label* body_target() { return &body_target_; }
ZoneList<Statement*>* statements() const { return statements_; }
int position() const { return position_; }
void set_position(int pos) { position_ = pos; }
BailoutId EntryId() const { return entry_id_; }
// Type feedback information.
@ -1128,10 +1126,14 @@ class CaseClause V8_FINAL : public ZoneObject {
Handle<Type> compare_type() { return compare_type_; }
private:
CaseClause(Isolate* isolate,
Expression* label,
ZoneList<Statement*>* statements,
int pos);
Expression* label_;
Label body_target_;
ZoneList<Statement*>* statements_;
int position_;
Handle<Type> compare_type_;
const TypeFeedbackId compare_id_;
@ -3036,6 +3038,13 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
return new(zone_) EmptyStatement(pos);
}
CaseClause* NewCaseClause(
Expression* label, ZoneList<Statement*>* statements, int pos) {
CaseClause* clause =
new(zone_) CaseClause(isolate_, label, statements, pos);
VISIT_AND_RETURN(CaseClause, clause)
}
Literal* NewLiteral(Handle<Object> handle, int pos) {
Literal* lit = new(zone_) Literal(isolate_, handle, pos);
VISIT_AND_RETURN(Literal, lit)

View File

@ -193,6 +193,10 @@ void BreakableStatementChecker::VisitDebuggerStatement(
}
void BreakableStatementChecker::VisitCaseClause(CaseClause* clause) {
}
void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) {
}
@ -1515,6 +1519,11 @@ void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
}
void FullCodeGenerator::VisitCaseClause(CaseClause* clause) {
UNREACHABLE();
}
void FullCodeGenerator::VisitConditional(Conditional* expr) {
Comment cmnt(masm_, "[ Conditional");
Label true_case, false_case, done;

View File

@ -3969,6 +3969,11 @@ void HOptimizedGraphBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) {
}
void HOptimizedGraphBuilder::VisitCaseClause(CaseClause* clause) {
UNREACHABLE();
}
static Handle<SharedFunctionInfo> SearchSharedFunctionInfo(
Code* unoptimized_code, FunctionLiteral* expr) {
int start_position = expr->start_position();

View File

@ -2392,7 +2392,7 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
statements->Add(stat, zone());
}
return new(zone()) CaseClause(isolate(), label, statements, pos);
return factory()->NewCaseClause(label, statements, pos);
}
@ -3231,7 +3231,7 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
return factory()->NewCountOperation(op,
true /* prefix */,
expression,
position()); // TODO(rossberg): ???
position());
} else {
return ParsePostfixExpression(ok);
@ -3267,7 +3267,7 @@ Expression* Parser::ParsePostfixExpression(bool* ok) {
factory()->NewCountOperation(next,
false /* postfix */,
expression,
position()); // TODO(rossberg): ???
position());
}
return expression;
}

View File

@ -200,11 +200,25 @@ void PrettyPrinter::VisitSwitchStatement(SwitchStatement* node) {
Print(") { ");
ZoneList<CaseClause*>* cases = node->cases();
for (int i = 0; i < cases->length(); i++)
PrintCaseClause(cases->at(i));
Visit(cases->at(i));
Print("}");
}
void PrettyPrinter::VisitCaseClause(CaseClause* clause) {
if (clause->is_default()) {
Print("default");
} else {
Print("case ");
Visit(clause->label());
}
Print(": ");
PrintStatements(clause->statements());
if (clause->statements()->length() > 0)
Print(" ");
}
void PrettyPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
PrintLabels(node->labels());
Print("do ");
@ -620,20 +634,6 @@ void PrettyPrinter::PrintFunctionLiteral(FunctionLiteral* function) {
}
void PrettyPrinter::PrintCaseClause(CaseClause* clause) {
if (clause->is_default()) {
Print("default");
} else {
Print("case ");
Visit(clause->label());
}
Print(": ");
PrintStatements(clause->statements());
if (clause->statements()->length() > 0)
Print(" ");
}
//-----------------------------------------------------------------------------
class IndentedScope BASE_EMBEDDED {
@ -761,18 +761,6 @@ void AstPrinter::PrintArguments(ZoneList<Expression*>* arguments) {
}
void AstPrinter::PrintCaseClause(CaseClause* clause) {
if (clause->is_default()) {
IndentedScope indent(this, "DEFAULT");
PrintStatements(clause->statements());
} else {
IndentedScope indent(this, "CASE");
Visit(clause->label());
PrintStatements(clause->statements());
}
}
void AstPrinter::VisitBlock(Block* node) {
const char* block_txt = node->is_initializer_block() ? "BLOCK INIT" : "BLOCK";
IndentedScope indent(this, block_txt);
@ -900,7 +888,19 @@ void AstPrinter::VisitSwitchStatement(SwitchStatement* node) {
PrintLabelsIndented(node->labels());
PrintIndentedVisit("TAG", node->tag());
for (int i = 0; i < node->cases()->length(); i++) {
PrintCaseClause(node->cases()->at(i));
Visit(node->cases()->at(i));
}
}
void AstPrinter::VisitCaseClause(CaseClause* clause) {
if (clause->is_default()) {
IndentedScope indent(this, "DEFAULT");
PrintStatements(clause->statements());
} else {
IndentedScope indent(this, "CASE");
Visit(clause->label());
PrintStatements(clause->statements());
}
}

View File

@ -207,6 +207,11 @@ void Processor::VisitSwitchStatement(SwitchStatement* node) {
}
void Processor::VisitCaseClause(CaseClause* clause) {
UNREACHABLE();
}
void Processor::VisitContinueStatement(ContinueStatement* node) {
is_set_ = false;
}

View File

@ -206,6 +206,11 @@ void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) {
}
void AstTyper::VisitCaseClause(CaseClause* clause) {
UNREACHABLE();
}
void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) {
// Collect type feedback.
if (!stmt->cond()->ToBooleanIsTrue()) {