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