| Index: src/rewriter.cc
|
| diff --git a/src/rewriter.cc b/src/rewriter.cc
|
| index f253ec53377edb0c63abe9e086550fc270ac80b6..b6f82406149ea946ecec323363b973cb124326ef 100644
|
| --- a/src/rewriter.cc
|
| +++ b/src/rewriter.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
| +// Copyright 2010 the V8 project authors. All rights reserved.
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| // met:
|
| @@ -27,9 +27,11 @@
|
|
|
| #include "v8.h"
|
|
|
| +#include "rewriter.h"
|
| +
|
| #include "ast.h"
|
| +#include "compiler.h"
|
| #include "scopes.h"
|
| -#include "rewriter.h"
|
|
|
| namespace v8 {
|
| namespace internal {
|
| @@ -986,34 +988,40 @@ void Processor::VisitThisFunction(ThisFunction* node) {
|
| }
|
|
|
|
|
| -bool Rewriter::Process(FunctionLiteral* function) {
|
| - HistogramTimerScope timer(&Counters::rewriting);
|
| +// Assumes code has been parsed and scopes hve been analyzed. Mutates the
|
| +// AST, so the AST should not continue to be used in the case of failure.
|
| +bool Rewriter::Rewrite(CompilationInfo* info) {
|
| + FunctionLiteral* function = info->function();
|
| + ASSERT(function != NULL);
|
| Scope* scope = function->scope();
|
| + ASSERT(scope != NULL);
|
| if (scope->is_function_scope()) return true;
|
|
|
| ZoneList<Statement*>* body = function->body();
|
| - if (body->is_empty()) return true;
|
| + if (!body->is_empty()) {
|
| + VariableProxy* result = scope->NewTemporary(Factory::result_symbol());
|
| + Processor processor(result);
|
| + processor.Process(body);
|
| + if (processor.HasStackOverflow()) return false;
|
|
|
| - VariableProxy* result = scope->NewTemporary(Factory::result_symbol());
|
| - Processor processor(result);
|
| - processor.Process(body);
|
| - if (processor.HasStackOverflow()) return false;
|
| + if (processor.result_assigned()) body->Add(new ReturnStatement(result));
|
| + }
|
|
|
| - if (processor.result_assigned()) body->Add(new ReturnStatement(result));
|
| return true;
|
| }
|
|
|
|
|
| -bool Rewriter::Optimize(FunctionLiteral* function) {
|
| - ZoneList<Statement*>* body = function->body();
|
| +// Assumes code has been parsed and scopes have been analyzed. Mutates the
|
| +// AST, so the AST should not continue to be used in the case of failure.
|
| +bool Rewriter::Analyze(CompilationInfo* info) {
|
| + FunctionLiteral* function = info->function();
|
| + ASSERT(function != NULL && function->scope() != NULL);
|
|
|
| + ZoneList<Statement*>* body = function->body();
|
| if (FLAG_optimize_ast && !body->is_empty()) {
|
| - HistogramTimerScope timer(&Counters::ast_optimization);
|
| AstOptimizer optimizer;
|
| optimizer.Optimize(body);
|
| - if (optimizer.HasStackOverflow()) {
|
| - return false;
|
| - }
|
| + if (optimizer.HasStackOverflow()) return false;
|
| }
|
| return true;
|
| }
|
|
|