Commit 457fc6bd authored by bradnelson's avatar bradnelson Committed by Commit bot

Visit additional AST nodes as expressions in AstExpressionVisitor .

Visit AST Property nodes as expressions in AstExpressionVisitor.
Visit Yield and Throw as they are expressions too.

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=test-ast-expression-visitor, test-typing-reset
R=rossberg@chromium.org,titzer@chromium.org
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#30367}
parent 48276d34
......@@ -241,19 +241,22 @@ void AstExpressionVisitor::VisitAssignment(Assignment* expr) {
void AstExpressionVisitor::VisitYield(Yield* expr) {
RECURSE(Visit(expr->generator_object()));
RECURSE(Visit(expr->expression()));
VisitExpression(expr);
RECURSE_EXPRESSION(Visit(expr->generator_object()));
RECURSE_EXPRESSION(Visit(expr->expression()));
}
void AstExpressionVisitor::VisitThrow(Throw* expr) {
RECURSE(Visit(expr->exception()));
VisitExpression(expr);
RECURSE_EXPRESSION(Visit(expr->exception()));
}
void AstExpressionVisitor::VisitProperty(Property* expr) {
RECURSE(Visit(expr->obj()));
RECURSE(Visit(expr->key()));
VisitExpression(expr);
RECURSE_EXPRESSION(Visit(expr->obj()));
RECURSE_EXPRESSION(Visit(expr->key()));
}
......
......@@ -163,12 +163,14 @@ TEST(VisitExpressions) {
CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
CHECK_EXPR(Call, DEFAULT_TYPE) {
CHECK_VAR(log, DEFAULT_TYPE);
CHECK_EXPR(Property, DEFAULT_TYPE) {
CHECK_VAR(values, DEFAULT_TYPE);
CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
CHECK_VAR(p, DEFAULT_TYPE);
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
}
}
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
}
......@@ -228,23 +230,33 @@ TEST(VisitExpressions) {
// var exp = stdlib.Math.exp;
CHECK_EXPR(Assignment, DEFAULT_TYPE) {
CHECK_VAR(exp, DEFAULT_TYPE);
CHECK_EXPR(Property, DEFAULT_TYPE) {
CHECK_EXPR(Property, DEFAULT_TYPE) {
CHECK_VAR(stdlib, DEFAULT_TYPE);
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
}
// var log = stdlib.Math.log;
CHECK_EXPR(Assignment, DEFAULT_TYPE) {
CHECK_VAR(log, DEFAULT_TYPE);
CHECK_EXPR(Property, DEFAULT_TYPE) {
CHECK_EXPR(Property, DEFAULT_TYPE) {
CHECK_VAR(stdlib, DEFAULT_TYPE);
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
}
// var values = new stdlib.Float64Array(buffer);
CHECK_EXPR(Assignment, DEFAULT_TYPE) {
CHECK_VAR(values, DEFAULT_TYPE);
CHECK_EXPR(CallNew, DEFAULT_TYPE) {
CHECK_EXPR(Property, DEFAULT_TYPE) {
CHECK_VAR(stdlib, DEFAULT_TYPE);
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
CHECK_VAR(buffer, DEFAULT_TYPE);
}
}
......@@ -297,3 +309,58 @@ TEST(VisitSwitchStatment) {
}
CHECK_TYPES_END
}
TEST(VisitThrow) {
v8::V8::Initialize();
HandleAndZoneScope handles;
ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
// Check that traversing an empty for statement works.
const char test_function[] =
"function foo() {\n"
" throw 123;\n"
"}\n";
CollectTypes(&handles, test_function, &types);
CHECK_TYPES_BEGIN {
CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {
CHECK_EXPR(Throw, DEFAULT_TYPE) { CHECK_EXPR(Literal, DEFAULT_TYPE); }
}
}
CHECK_TYPES_END
}
TEST(VisitYield) {
v8::V8::Initialize();
HandleAndZoneScope handles;
ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
// Check that traversing an empty for statement works.
const char test_function[] =
"function* foo() {\n"
" yield 123;\n"
"}\n";
CollectTypes(&handles, test_function, &types);
CHECK_TYPES_BEGIN {
CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {
// Generator function yields generator on entry.
CHECK_EXPR(Yield, DEFAULT_TYPE) {
CHECK_VAR(.generator_object, DEFAULT_TYPE);
CHECK_EXPR(Assignment, DEFAULT_TYPE) {
CHECK_VAR(.generator_object, DEFAULT_TYPE);
CHECK_EXPR(CallRuntime, DEFAULT_TYPE);
}
}
// Then yields undefined.
CHECK_EXPR(Yield, DEFAULT_TYPE) {
CHECK_VAR(.generator_object, DEFAULT_TYPE);
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
// Then yields 123.
CHECK_EXPR(Yield, DEFAULT_TYPE) {
CHECK_VAR(.generator_object, DEFAULT_TYPE);
CHECK_EXPR(Literal, DEFAULT_TYPE);
}
}
}
CHECK_TYPES_END
}
......@@ -112,12 +112,14 @@ void CheckAllSame(ZoneVector<ExpressionTypeEntry>& types,
CHECK_EXPR(BinaryOperation, expected_type) {
CHECK_EXPR(Call, expected_type) {
CHECK_VAR(log, expected_type);
CHECK_EXPR(Property, expected_type) {
CHECK_VAR(values, expected_type);
CHECK_EXPR(BinaryOperation, expected_type) {
CHECK_VAR(p, expected_type);
CHECK_EXPR(Literal, expected_type);
}
}
}
CHECK_EXPR(Literal, expected_type);
}
}
......@@ -177,23 +179,33 @@ void CheckAllSame(ZoneVector<ExpressionTypeEntry>& types,
// var exp = stdlib.Math.exp;
CHECK_EXPR(Assignment, expected_type) {
CHECK_VAR(exp, expected_type);
CHECK_EXPR(Property, expected_type) {
CHECK_EXPR(Property, expected_type) {
CHECK_VAR(stdlib, expected_type);
CHECK_EXPR(Literal, expected_type);
}
CHECK_EXPR(Literal, expected_type);
}
}
// var log = stdlib.Math.log;
CHECK_EXPR(Assignment, expected_type) {
CHECK_VAR(log, expected_type);
CHECK_EXPR(Property, expected_type) {
CHECK_EXPR(Property, expected_type) {
CHECK_VAR(stdlib, expected_type);
CHECK_EXPR(Literal, expected_type);
}
CHECK_EXPR(Literal, expected_type);
}
}
// var values = new stdlib.Float64Array(buffer);
CHECK_EXPR(Assignment, expected_type) {
CHECK_VAR(values, expected_type);
CHECK_EXPR(CallNew, expected_type) {
CHECK_EXPR(Property, expected_type) {
CHECK_VAR(stdlib, expected_type);
CHECK_EXPR(Literal, expected_type);
}
CHECK_VAR(buffer, expected_type);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment