[parser] Separate PreParser StatementList from ExpressionList

For statementlists we only need to track whether they are null or not. We
especially do not need to track possible variable declarations.

Change-Id: I66377521c924931a1871e5df0e55a7b45f169155
Reviewed-on: https://chromium-review.googlesource.com/1249267
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56272}
This commit is contained in:
Toon Verwaest 2018-09-27 17:59:38 +02:00 committed by Commit Bot
parent 2c2af0022d
commit 5f8a320ea5

View File

@ -415,31 +415,39 @@ class PreParserExpression {
friend class PreParser; friend class PreParser;
friend class PreParserFactory; friend class PreParserFactory;
template <typename T> friend class PreParserExpressionList;
friend class PreParserList;
}; };
// The pre-parser doesn't need to build lists of expressions, identifiers, or // The pre-parser doesn't need to build lists of expressions, identifiers, or
// the like. If the PreParser is used in variable tracking mode, it needs to // the like. If the PreParser is used in variable tracking mode, it needs to
// build lists of variables though. // build lists of variables though.
template <typename T> class PreParserExpressionList {
class PreParserList {
using VariableZoneThreadedListType = using VariableZoneThreadedListType =
ZoneThreadedList<VariableProxy, VariableProxy::PreParserNext>; ZoneThreadedList<VariableProxy, VariableProxy::PreParserNext>;
public: public:
// These functions make list->Add(some_expression) work (and do nothing). // These functions make list->Add(some_expression) work (and do nothing).
PreParserList() : length_(0), variables_(nullptr) {} PreParserExpressionList() : PreParserExpressionList(0) {}
PreParserList* operator->() { return this; } PreParserExpressionList* operator->() { return this; }
void Add(const T& element, Zone* zone); void Add(const PreParserExpression& expression, Zone* zone) {
if (expression.variables_ != nullptr) {
DCHECK(FLAG_lazy_inner_functions);
DCHECK_NOT_NULL(zone);
if (variables_ == nullptr) {
variables_ = new (zone) VariableZoneThreadedListType();
}
variables_->Append(std::move(*expression.variables_));
}
++length_;
}
int length() const { return length_; } int length() const { return length_; }
static PreParserList Null() { return PreParserList(-1); } static PreParserExpressionList Null() { return PreParserExpressionList(-1); }
bool IsNull() const { return length_ == -1; } bool IsNull() const { return length_ == -1; }
void Set(int index, const T& element) {} void Set(int index, const PreParserExpression& element) {}
private: private:
explicit PreParserList(int n) : length_(n), variables_(nullptr) {} explicit PreParserExpressionList(int n) : length_(n), variables_(nullptr) {}
int length_; int length_;
VariableZoneThreadedListType* variables_; VariableZoneThreadedListType* variables_;
@ -448,29 +456,20 @@ class PreParserList {
friend class PreParserFactory; friend class PreParserFactory;
}; };
template <>
inline void PreParserList<PreParserExpression>::Add(
const PreParserExpression& expression, Zone* zone) {
if (expression.variables_ != nullptr) {
DCHECK(FLAG_lazy_inner_functions);
DCHECK_NOT_NULL(zone);
if (variables_ == nullptr) {
variables_ = new (zone) VariableZoneThreadedListType();
}
variables_->Append(std::move(*expression.variables_));
}
++length_;
}
template <typename T>
void PreParserList<T>::Add(const T& element, Zone* zone) {
++length_;
}
typedef PreParserList<PreParserExpression> PreParserExpressionList;
class PreParserStatement; class PreParserStatement;
typedef PreParserList<PreParserStatement> PreParserStatementList;
class PreParserStatementList {
public:
PreParserStatementList() : PreParserStatementList(false) {}
PreParserStatementList* operator->() { return this; }
void Add(const PreParserStatement& element, Zone* zone) {}
static PreParserStatementList Null() { return PreParserStatementList(true); }
bool IsNull() const { return is_null_; }
private:
explicit PreParserStatementList(bool is_null) : is_null_(is_null) {}
bool is_null_;
};
class PreParserStatement { class PreParserStatement {
public: public:
@ -533,8 +532,6 @@ class PreParserStatement {
// and PreParser. // and PreParser.
PreParserStatement* operator->() { return this; } PreParserStatement* operator->() { return this; }
// TODO(adamk): These should return something even lighter-weight than
// PreParserStatementList.
PreParserStatementList statements() { return PreParserStatementList(); } PreParserStatementList statements() { return PreParserStatementList(); }
PreParserStatementList cases() { return PreParserStatementList(); } PreParserStatementList cases() { return PreParserStatementList(); }