A small collection of cleanup in the parser and AST.

* Remove a couple of unused fields from the FunctionLiteral, ensure that all
  the bools are packed.
* Rename SaveScope and LexicalScope in the parser.
* Use an enum to generate the numbers 0..N and the dependent count, rather
  than static const ints.  This is simpler to extend (coming in a future
  change).

R=danno@chromium.org,keuchel@chromium.org
BUG=
TEST=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9933 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9f501470
......@@ -440,7 +440,6 @@ class IterationStatement: public BreakableStatement {
IterationStatement(Isolate* isolate, ZoneStringList* labels)
: BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
body_(NULL),
continue_target_(),
osr_entry_id_(GetNextId(isolate)) {
}
......@@ -1647,25 +1646,26 @@ class FunctionLiteral: public Expression {
int expected_property_count,
bool has_only_simple_this_property_assignments,
Handle<FixedArray> this_property_assignments,
int num_parameters,
int parameter_count,
Type type,
bool has_duplicate_parameters)
: Expression(isolate),
name_(name),
scope_(scope),
body_(body),
this_property_assignments_(this_property_assignments),
inferred_name_(isolate->factory()->empty_string()),
materialized_literal_count_(materialized_literal_count),
expected_property_count_(expected_property_count),
has_only_simple_this_property_assignments_(
has_only_simple_this_property_assignments),
this_property_assignments_(this_property_assignments),
num_parameters_(num_parameters),
function_token_position_(RelocInfo::kNoPosition),
inferred_name_(HEAP->empty_string()),
is_expression_(type != DECLARATION),
is_anonymous_(type == ANONYMOUS_EXPRESSION),
pretenure_(false),
has_duplicate_parameters_(has_duplicate_parameters) {
parameter_count_(parameter_count),
function_token_position_(RelocInfo::kNoPosition) {
bitfield_ =
HasOnlySimpleThisPropertyAssignments::encode(
has_only_simple_this_property_assignments) |
IsExpression::encode(type != DECLARATION) |
IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) |
Pretenure::encode(false) |
HasDuplicateParameters::encode(has_duplicate_parameters);
}
DECLARE_NODE_TYPE(FunctionLiteral)
......@@ -1677,20 +1677,20 @@ class FunctionLiteral: public Expression {
int function_token_position() const { return function_token_position_; }
int start_position() const;
int end_position() const;
bool is_expression() const { return is_expression_; }
bool is_anonymous() const { return is_anonymous_; }
bool is_expression() const { return IsExpression::decode(bitfield_); }
bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
bool strict_mode() const { return strict_mode_flag() == kStrictMode; }
StrictModeFlag strict_mode_flag() const;
int materialized_literal_count() { return materialized_literal_count_; }
int expected_property_count() { return expected_property_count_; }
bool has_only_simple_this_property_assignments() {
return has_only_simple_this_property_assignments_;
return HasOnlySimpleThisPropertyAssignments::decode(bitfield_);
}
Handle<FixedArray> this_property_assignments() {
return this_property_assignments_;
}
int num_parameters() { return num_parameters_; }
int parameter_count() { return parameter_count_; }
bool AllowsLazyCompilation();
......@@ -1704,29 +1704,32 @@ class FunctionLiteral: public Expression {
inferred_name_ = inferred_name;
}
bool pretenure() { return pretenure_; }
void set_pretenure(bool value) { pretenure_ = value; }
bool pretenure() { return Pretenure::decode(bitfield_); }
void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
virtual bool IsInlineable() const;
bool has_duplicate_parameters() { return has_duplicate_parameters_; }
bool has_duplicate_parameters() {
return HasDuplicateParameters::decode(bitfield_);
}
private:
Handle<String> name_;
Scope* scope_;
ZoneList<Statement*>* body_;
Handle<FixedArray> this_property_assignments_;
Handle<String> inferred_name_;
int materialized_literal_count_;
int expected_property_count_;
bool has_only_simple_this_property_assignments_;
Handle<FixedArray> this_property_assignments_;
int num_parameters_;
int start_position_;
int end_position_;
int parameter_count_;
int function_token_position_;
Handle<String> inferred_name_;
bool is_expression_;
bool is_anonymous_;
bool pretenure_;
bool has_duplicate_parameters_;
unsigned bitfield_;
class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {};
class IsExpression: public BitField<bool, 1, 1> {};
class IsAnonymous: public BitField<bool, 2, 1> {};
class Pretenure: public BitField<bool, 3, 1> {};
class HasDuplicateParameters: public BitField<bool, 4, 1> {};
};
......
......@@ -734,8 +734,8 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
FunctionLiteral* lit,
bool is_toplevel,
Handle<Script> script) {
function_info->set_length(lit->num_parameters());
function_info->set_formal_parameter_count(lit->num_parameters());
function_info->set_length(lit->parameter_count());
function_info->set_formal_parameter_count(lit->parameter_count());
function_info->set_script(*script);
function_info->set_function_token_position(lit->function_token_position());
function_info->set_start_position(lit->start_position());
......
......@@ -797,7 +797,7 @@ class FunctionInfoListener {
HandleScope scope;
FunctionInfoWrapper info = FunctionInfoWrapper::Create();
info.SetInitialProperties(fun->name(), fun->start_position(),
fun->end_position(), fun->num_parameters(),
fun->end_position(), fun->parameter_count(),
current_parent_index_);
current_parent_index_ = len_;
SetElementNonStrict(result_, len_, info.GetJSArray());
......
This diff is collapsed.
......@@ -43,8 +43,6 @@ class FuncNameInferrer;
class ParserLog;
class PositionStack;
class Target;
class LexicalScope;
class SaveScope;
template <typename T> class ZoneListWrapper;
......@@ -69,30 +67,32 @@ class ParserMessage : public Malloced {
class FunctionEntry BASE_EMBEDDED {
public:
enum {
kStartPositionIndex,
kEndPositionIndex,
kLiteralCountIndex,
kPropertyCountIndex,
kStrictModeIndex,
kSize
};
explicit FunctionEntry(Vector<unsigned> backing) : backing_(backing) { }
FunctionEntry() : backing_(Vector<unsigned>::empty()) { }
int start_pos() { return backing_[kStartPosOffset]; }
int end_pos() { return backing_[kEndPosOffset]; }
int literal_count() { return backing_[kLiteralCountOffset]; }
int property_count() { return backing_[kPropertyCountOffset]; }
int start_pos() { return backing_[kStartPositionIndex]; }
int end_pos() { return backing_[kEndPositionIndex]; }
int literal_count() { return backing_[kLiteralCountIndex]; }
int property_count() { return backing_[kPropertyCountIndex]; }
StrictModeFlag strict_mode_flag() {
ASSERT(backing_[kStrictModeOffset] == kStrictMode ||
backing_[kStrictModeOffset] == kNonStrictMode);
return static_cast<StrictModeFlag>(backing_[kStrictModeOffset]);
ASSERT(backing_[kStrictModeIndex] == kStrictMode ||
backing_[kStrictModeIndex] == kNonStrictMode);
return static_cast<StrictModeFlag>(backing_[kStrictModeIndex]);
}
bool is_valid() { return backing_.length() > 0; }
static const int kSize = 5;
bool is_valid() { return !backing_.is_empty(); }
private:
Vector<unsigned> backing_;
static const int kStartPosOffset = 0;
static const int kEndPosOffset = 1;
static const int kLiteralCountOffset = 2;
static const int kPropertyCountOffset = 3;
static const int kStrictModeOffset = 4;
};
......@@ -451,9 +451,7 @@ class Parser {
// should be checked.
static const int kMaxNumFunctionParameters = 32766;
static const int kMaxNumFunctionLocals = 32767;
FunctionLiteral* ParseLazy(CompilationInfo* info,
UC16CharacterStream* source,
ZoneScope* zone_scope);
enum Mode {
PARSE_LAZILY,
PARSE_EAGERLY
......@@ -471,6 +469,13 @@ class Parser {
kHasNoInitializers
};
class BlockState;
class FunctionState;
FunctionLiteral* ParseLazy(CompilationInfo* info,
UC16CharacterStream* source,
ZoneScope* zone_scope);
Isolate* isolate() { return isolate_; }
Zone* zone() { return isolate_->zone(); }
......@@ -730,7 +735,7 @@ class Parser {
Scope* top_scope_;
LexicalScope* lexical_scope_;
FunctionState* current_function_state_;
Mode mode_;
Target* target_stack_; // for break, continue statements
......@@ -747,8 +752,8 @@ class Parser {
bool parenthesized_function_;
bool harmony_scoping_;
friend class LexicalScope;
friend class SaveScope;
friend class BlockState;
friend class FunctionState;
};
......
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