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

Unified Diff: src/rewriter.cc

Issue 3561012: More refactoring of class Compiler's interface. (Closed)
Patch Set: Reindent some code, change some copyright dates. Created 10 years, 2 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
« src/compiler.h ('K') | « src/rewriter.h ('k') | src/scopes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« src/compiler.h ('K') | « src/rewriter.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698