From f21b34ef0f518cdc84f536915560f22f1fea0fa8 Mon Sep 17 00:00:00 2001 From: "kmillikin@chromium.org" Date: Thu, 30 Sep 2010 08:48:37 +0000 Subject: [PATCH] Introduce subclasses of class CompilationInfo. It was a wart that we had three handle fields, exactly one of which was non-null; and that we had three overloaded constructors. Instead, introduce subclasses and virtual methods. Remove some unused fields from class CompilationInfo. Review URL: http://codereview.chromium.org/3566003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5560 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler.cc | 16 ++++--- src/compiler.h | 143 +++++++++++++++++++++++++++++++------------------------- src/handles.cc | 6 +-- src/liveedit.cc | 4 +- 4 files changed, 93 insertions(+), 76 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 825198e..ba8aca0 100755 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -146,9 +146,10 @@ static Handle MakeFunctionInfo(bool is_global, bool is_json = (validate == Compiler::VALIDATE_JSON); #ifdef ENABLE_DEBUGGER_SUPPORT if (is_eval || is_json) { - script->set_compilation_type( - is_json ? Smi::FromInt(Script::COMPILATION_TYPE_JSON) : - Smi::FromInt(Script::COMPILATION_TYPE_EVAL)); + Script::CompilationType compilation_type = is_json + ? Script::COMPILATION_TYPE_JSON + : Script::COMPILATION_TYPE_EVAL; + script->set_compilation_type(Smi::FromInt(compilation_type)); // For eval scripts add information on the function from which eval was // called. if (is_eval) { @@ -171,16 +172,16 @@ static Handle MakeFunctionInfo(bool is_global, ASSERT(is_eval || is_global); // Build AST. + EagerCompilationInfo info(script, is_eval); FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data, is_json); - LiveEditFunctionTracker live_edit_tracker(lit); - // Check for parse errors. if (lit == NULL) { ASSERT(Top::has_pending_exception()); return Handle::null(); } + info.set_function(lit); // Measure how long it takes to do the compilation; only take the // rest of the function into account to avoid overlap with the @@ -191,7 +192,7 @@ static Handle MakeFunctionInfo(bool is_global, HistogramTimerScope timer(rate); // Compile the code. - CompilationInfo info(lit, script, is_eval); + LiveEditFunctionTracker live_edit_tracker(lit); Handle code = MakeCode(context, &info); // Check for stack-overflow exceptions. @@ -482,7 +483,8 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, // Generate code and return it. The way that the compilation mode // is controlled by the command-line flags is described in // the static helper function MakeCode. - CompilationInfo info(literal, script, false); + EagerCompilationInfo info(script, false); + info.set_function(literal); bool is_run_once = literal->try_full_codegen(); bool use_full = FLAG_full_compiler && !literal->contains_loops(); diff --git a/src/compiler.h b/src/compiler.h index 10d93dc..ae0d6de 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -41,94 +41,109 @@ namespace internal { // is constructed based on the resources available at compile-time. class CompilationInfo BASE_EMBEDDED { public: - // Lazy compilation of a JSFunction. - CompilationInfo(Handle closure, int loop_nesting) - : closure_(closure), - function_(NULL), - is_eval_(false), - loop_nesting_(loop_nesting) { - ASSERT(!closure_.is_null() && - shared_info_.is_null() && - script_.is_null()); - } + virtual ~CompilationInfo() {} + + // Dispatched behavior. + virtual Handle shared_info() const = 0; - // Lazy compilation based on SharedFunctionInfo. - explicit CompilationInfo(Handle shared_info) - : shared_info_(shared_info), - function_(NULL), - is_eval_(false), - loop_nesting_(0) { - ASSERT(closure_.is_null() && - !shared_info_.is_null() && - script_.is_null()); + virtual Handle