Merge in changes from readability review.

All changes from http://codereview.chromium.org/115024, except splitting namespace declarations in two lines (will be done separately for all source files).

Review URL: http://codereview.chromium.org/113763


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2037 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9f69c414
...@@ -211,7 +211,7 @@ Handle<Code> CodeGenerator::MakeCode(FunctionLiteral* flit, ...@@ -211,7 +211,7 @@ Handle<Code> CodeGenerator::MakeCode(FunctionLiteral* flit,
bool CodeGenerator::ShouldGenerateLog(Expression* type) { bool CodeGenerator::ShouldGenerateLog(Expression* type) {
ASSERT(type != NULL); ASSERT(type != NULL);
if (!Logger::is_enabled()) return false; if (!Logger::IsEnabled()) return false;
Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle()); Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
if (FLAG_log_regexp) { if (FLAG_log_regexp) {
static Vector<const char> kRegexp = CStrVector("regexp"); static Vector<const char> kRegexp = CStrVector("regexp");
......
...@@ -159,7 +159,7 @@ static Handle<JSFunction> MakeFunction(bool is_global, ...@@ -159,7 +159,7 @@ static Handle<JSFunction> MakeFunction(bool is_global,
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
// Log the code generation for the script. Check explicit whether logging is // Log the code generation for the script. Check explicit whether logging is
// to avoid allocating when not required. // to avoid allocating when not required.
if (Logger::is_enabled() || OProfileAgent::is_enabled()) { if (Logger::IsEnabled() || OProfileAgent::is_enabled()) {
if (script->name()->IsString()) { if (script->name()->IsString()) {
SmartPointer<char> data = SmartPointer<char> data =
String::cast(script->name())->ToCString(DISALLOW_NULLS); String::cast(script->name())->ToCString(DISALLOW_NULLS);
...@@ -356,7 +356,7 @@ bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared, ...@@ -356,7 +356,7 @@ bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared,
// Log the code generation. If source information is available include script // Log the code generation. If source information is available include script
// name and line number. Check explicit whether logging is enabled as finding // name and line number. Check explicit whether logging is enabled as finding
// the line number is not for free. // the line number is not for free.
if (Logger::is_enabled() || OProfileAgent::is_enabled()) { if (Logger::IsEnabled() || OProfileAgent::is_enabled()) {
Handle<String> func_name(name->length() > 0 ? Handle<String> func_name(name->length() > 0 ?
*name : shared->inferred_name()); *name : shared->inferred_name());
if (script->name()->IsString()) { if (script->name()->IsString()) {
......
...@@ -34,41 +34,46 @@ namespace v8 { namespace internal { ...@@ -34,41 +34,46 @@ namespace v8 { namespace internal {
// inference for anonymous functions during static analysis of source code. // inference for anonymous functions during static analysis of source code.
// Inference is performed in cases when an anonymous function is assigned // Inference is performed in cases when an anonymous function is assigned
// to a variable or a property (see test-func-name-inference.cc for examples.) // to a variable or a property (see test-func-name-inference.cc for examples.)
//
// The basic idea is that during AST traversal LHSs of expressions are // The basic idea is that during AST traversal LHSs of expressions are
// always visited before RHSs. Thus, during visiting the LHS, a name can be // always visited before RHSs. Thus, during visiting the LHS, a name can be
// collected, and during visiting the RHS, a function literal can be collected. // collected, and during visiting the RHS, a function literal can be collected.
// Inference is performed while leaving the assignment node. // Inference is performed while leaving the assignment node.
class FuncNameInferrer BASE_EMBEDDED { class FuncNameInferrer BASE_EMBEDDED {
public: public:
FuncNameInferrer() : FuncNameInferrer()
entries_stack_(10), : entries_stack_(10),
names_stack_(5), names_stack_(5),
funcs_to_infer_(4), funcs_to_infer_(4),
dot_(Factory::NewStringFromAscii(CStrVector("."))) { dot_(Factory::NewStringFromAscii(CStrVector("."))) {
} }
// Returns whether we have entered name collection state.
bool IsOpen() const { return !entries_stack_.is_empty(); } bool IsOpen() const { return !entries_stack_.is_empty(); }
// Pushes an enclosing the name of enclosing function onto names stack.
void PushEnclosingName(Handle<String> name); void PushEnclosingName(Handle<String> name);
// Enters name collection state.
void Enter() { void Enter() {
entries_stack_.Add(names_stack_.length()); entries_stack_.Add(names_stack_.length());
} }
// Pushes an encountered name onto names stack when in collection state.
void PushName(Handle<String> name) { void PushName(Handle<String> name) {
if (IsOpen()) { if (IsOpen()) {
names_stack_.Add(name); names_stack_.Add(name);
} }
} }
// Adds a function to infer name for.
void AddFunction(FunctionLiteral* func_to_infer) { void AddFunction(FunctionLiteral* func_to_infer) {
if (IsOpen()) { if (IsOpen()) {
funcs_to_infer_.Add(func_to_infer); funcs_to_infer_.Add(func_to_infer);
} }
} }
// Infers a function name and leaves names collection state.
void InferAndLeave() { void InferAndLeave() {
ASSERT(IsOpen()); ASSERT(IsOpen());
if (!funcs_to_infer_.is_empty()) { if (!funcs_to_infer_.is_empty()) {
...@@ -78,8 +83,13 @@ class FuncNameInferrer BASE_EMBEDDED { ...@@ -78,8 +83,13 @@ class FuncNameInferrer BASE_EMBEDDED {
} }
private: private:
// Constructs a full name in dotted notation from gathered names.
Handle<String> MakeNameFromStack(); Handle<String> MakeNameFromStack();
// A helper function for MakeNameFromStack.
Handle<String> MakeNameFromStackHelper(int pos, Handle<String> prev); Handle<String> MakeNameFromStackHelper(int pos, Handle<String> prev);
// Performs name inferring for added functions.
void InferFunctionsNames(); void InferFunctionsNames();
ZoneList<int> entries_stack_; ZoneList<int> entries_stack_;
...@@ -95,15 +105,17 @@ class FuncNameInferrer BASE_EMBEDDED { ...@@ -95,15 +105,17 @@ class FuncNameInferrer BASE_EMBEDDED {
// leaving scope. // leaving scope.
class ScopedFuncNameInferrer BASE_EMBEDDED { class ScopedFuncNameInferrer BASE_EMBEDDED {
public: public:
explicit ScopedFuncNameInferrer(FuncNameInferrer* inferrer) : explicit ScopedFuncNameInferrer(FuncNameInferrer* inferrer)
inferrer_(inferrer), : inferrer_(inferrer),
is_entered_(false) {} is_entered_(false) {}
~ScopedFuncNameInferrer() { ~ScopedFuncNameInferrer() {
if (is_entered_) { if (is_entered_) {
inferrer_->InferAndLeave(); inferrer_->InferAndLeave();
} }
} }
// Triggers the wrapped inferrer into name collection state.
void Enter() { void Enter() {
inferrer_->Enter(); inferrer_->Enter();
is_entered_ = true; is_entered_ = true;
......
This diff is collapsed.
...@@ -75,7 +75,7 @@ class LogMessageBuilder; ...@@ -75,7 +75,7 @@ class LogMessageBuilder;
#ifdef ENABLE_LOGGING_AND_PROFILING #ifdef ENABLE_LOGGING_AND_PROFILING
#define LOG(Call) \ #define LOG(Call) \
do { \ do { \
if (v8::internal::Logger::is_enabled()) \ if (v8::internal::Logger::IsEnabled()) \
v8::internal::Logger::Call; \ v8::internal::Logger::Call; \
} while (false) } while (false)
#else #else
...@@ -201,7 +201,7 @@ class Logger { ...@@ -201,7 +201,7 @@ class Logger {
return current_state_ ? current_state_->state() : OTHER; return current_state_ ? current_state_->state() : OTHER;
} }
static bool is_enabled(); static bool IsEnabled();
// Pause/Resume collection of profiling data. // Pause/Resume collection of profiling data.
// When data collection is paused, Tick events are discarded until // When data collection is paused, Tick events are discarded until
......
...@@ -32,15 +32,18 @@ ...@@ -32,15 +32,18 @@
#include "cctest.h" #include "cctest.h"
using ::v8::internal::CStrVector;
using ::v8::internal::Factory;
using ::v8::internal::Handle; using ::v8::internal::Handle;
using ::v8::internal::Heap;
using ::v8::internal::JSFunction; using ::v8::internal::JSFunction;
using ::v8::internal::Object; using ::v8::internal::Object;
using ::v8::internal::Runtime;
using ::v8::internal::Script; using ::v8::internal::Script;
using ::v8::internal::SmartPointer;
using ::v8::internal::SharedFunctionInfo; using ::v8::internal::SharedFunctionInfo;
using ::v8::internal::String; using ::v8::internal::String;
namespace i = ::v8::internal;
static v8::Persistent<v8::Context> env; static v8::Persistent<v8::Context> env;
...@@ -66,19 +69,19 @@ static void CheckFunctionName(v8::Handle<v8::Script> script, ...@@ -66,19 +69,19 @@ static void CheckFunctionName(v8::Handle<v8::Script> script,
// Find the position of a given func source substring in the source. // Find the position of a given func source substring in the source.
Handle<String> func_pos_str = Handle<String> func_pos_str =
i::Factory::NewStringFromAscii(i::CStrVector(func_pos_src)); Factory::NewStringFromAscii(CStrVector(func_pos_src));
int func_pos = i::Runtime::StringMatch(script_src, func_pos_str, 0); int func_pos = Runtime::StringMatch(script_src, func_pos_str, 0);
CHECK_NE(0, func_pos); CHECK_NE(0, func_pos);
// Obtain SharedFunctionInfo for the function. // Obtain SharedFunctionInfo for the function.
Object* shared_func_info_ptr = Object* shared_func_info_ptr =
i::Runtime::FindSharedFunctionInfoInScript(i_script, func_pos); Runtime::FindSharedFunctionInfoInScript(i_script, func_pos);
CHECK(shared_func_info_ptr != i::Heap::undefined_value()); CHECK(shared_func_info_ptr != Heap::undefined_value());
Handle<SharedFunctionInfo> shared_func_info( Handle<SharedFunctionInfo> shared_func_info(
SharedFunctionInfo::cast(shared_func_info_ptr)); SharedFunctionInfo::cast(shared_func_info_ptr));
// Verify inferred function name. // Verify inferred function name.
i::SmartPointer<char> inferred_name = SmartPointer<char> inferred_name =
shared_func_info->inferred_name()->ToCString(); shared_func_info->inferred_name()->ToCString();
CHECK_EQ(ref_inferred_name, *inferred_name); CHECK_EQ(ref_inferred_name, *inferred_name);
} }
......
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