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