Commit d52010e0 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[parser] Unify and simplify handling of "null" types

Before this patch, the parser mixed mixed "Null" and "Empty" as names
for null placeholder instances in ParserBase. Confusingly, those meant
different things in case of Statements.

This patch uses "Null" anywhere the meaning is "== nullptr" in the Parser.
It also makes use of std::nullptr_t and templatized IsNull() methods to
reduce the amount of boilerplate needed in both the Parser and PreParser.

Change-Id: I1451ba56d1a56466beb7e0c91dcf8e2bb7084413
Reviewed-on: https://chromium-review.googlesource.com/618167
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47406}
parent 627c440b
This diff is collapsed.
......@@ -843,42 +843,18 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
// "null" return type creators.
V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; }
V8_INLINE static bool IsEmptyIdentifier(const AstRawString* name) {
return name == nullptr;
}
V8_INLINE static Expression* EmptyExpression() { return nullptr; }
V8_INLINE static Literal* EmptyLiteral() { return nullptr; }
V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() {
return nullptr;
}
V8_INLINE static ClassLiteralProperty* EmptyClassLiteralProperty() {
return nullptr;
}
V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
V8_INLINE static Block* NullBlock() { return nullptr; }
V8_INLINE static bool IsEmptyExpression(Expression* expr) {
return expr == nullptr;
}
// Used in error return values.
V8_INLINE static std::nullptr_t NullIdentifier() { return nullptr; }
V8_INLINE static std::nullptr_t NullExpression() { return nullptr; }
V8_INLINE static std::nullptr_t NullLiteralProperty() { return nullptr; }
V8_INLINE static ZoneList<Expression*>* NullExpressionList() {
return nullptr;
}
V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) {
return exprs == nullptr;
}
V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; }
V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) {
return stmts == nullptr;
}
// TODO(adamk): Use nullptr_t throughout more widely to remove redundant code.
V8_INLINE static std::nullptr_t NullStatement() { return nullptr; }
V8_INLINE bool IsNullStatement(Statement* stmt) { return stmt == nullptr; }
V8_INLINE bool IsEmptyStatement(Statement* stmt) {
DCHECK_NOT_NULL(stmt);
return stmt->IsEmpty();
template <typename T>
V8_INLINE static bool IsNull(T subject) {
return subject == nullptr;
}
// Non-NULL empty string.
......
......@@ -30,8 +30,8 @@ class PreParserIdentifier {
static PreParserIdentifier Default() {
return PreParserIdentifier(kUnknownIdentifier);
}
static PreParserIdentifier Empty() {
return PreParserIdentifier(kEmptyIdentifier);
static PreParserIdentifier Null() {
return PreParserIdentifier(kNullIdentifier);
}
static PreParserIdentifier Eval() {
return PreParserIdentifier(kEvalIdentifier);
......@@ -75,7 +75,7 @@ class PreParserIdentifier {
static PreParserIdentifier Name() {
return PreParserIdentifier(kNameIdentifier);
}
bool IsEmpty() const { return type_ == kEmptyIdentifier; }
bool IsNull() const { return type_ == kNullIdentifier; }
bool IsEval() const { return type_ == kEvalIdentifier; }
bool IsArguments() const { return type_ == kArgumentsIdentifier; }
bool IsEvalOrArguments() const { return IsEval() || IsArguments(); }
......@@ -99,7 +99,7 @@ class PreParserIdentifier {
private:
enum Type {
kEmptyIdentifier,
kNullIdentifier,
kUnknownIdentifier,
kFutureReservedIdentifier,
kFutureStrictReservedIdentifier,
......@@ -130,9 +130,9 @@ class PreParserIdentifier {
class PreParserExpression {
public:
PreParserExpression()
: code_(TypeField::encode(kEmpty)), variables_(nullptr) {}
: code_(TypeField::encode(kNull)), variables_(nullptr) {}
static PreParserExpression Empty() { return PreParserExpression(); }
static PreParserExpression Null() { return PreParserExpression(); }
static PreParserExpression Default(
ZoneList<VariableProxy*>* variables = nullptr) {
......@@ -251,7 +251,7 @@ class PreParserExpression {
ExpressionTypeField::encode(kNoTemplateTagExpression));
}
bool IsEmpty() const { return TypeField::decode(code_) == kEmpty; }
bool IsNull() const { return TypeField::decode(code_) == kNull; }
bool IsIdentifier() const {
return TypeField::decode(code_) == kIdentifierExpression;
......@@ -348,7 +348,7 @@ class PreParserExpression {
private:
enum Type {
kEmpty,
kNull,
kExpression,
kIdentifierExpression,
kStringLiteralExpression,
......@@ -514,9 +514,12 @@ class PreParserStatement {
return code_ == kJumpStatement;
}
bool IsNullStatement() { return code_ == kNullStatement; }
bool IsNull() { return code_ == kNullStatement; }
bool IsEmptyStatement() { return code_ == kEmptyStatement; }
bool IsEmptyStatement() {
DCHECK(!IsNull());
return code_ == kEmptyStatement;
}
// Dummy implementation for making statement->somefunc() work in both Parser
// and PreParser.
......@@ -999,7 +1002,9 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
bool tail) {}
V8_INLINE PreParserExpression CloseTemplateLiteral(
TemplateLiteralState* state, int start, PreParserExpression tag);
TemplateLiteralState* state, int start, PreParserExpression tag) {
return PreParserExpression::Default();
}
V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
V8_INLINE void SetLanguageMode(Scope* scope, LanguageMode mode) {
......@@ -1459,62 +1464,29 @@ class PreParser : public ParserBase<PreParser> {
}
// "null" return type creators.
V8_INLINE static PreParserIdentifier EmptyIdentifier() {
return PreParserIdentifier::Empty();
}
V8_INLINE static bool IsEmptyIdentifier(PreParserIdentifier name) {
return name.IsEmpty();
}
V8_INLINE static PreParserExpression EmptyExpression() {
return PreParserExpression::Empty();
}
V8_INLINE static PreParserExpression EmptyLiteral() {
return PreParserExpression::Default();
V8_INLINE static PreParserIdentifier NullIdentifier() {
return PreParserIdentifier::Null();
}
V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() {
return PreParserExpression::Default();
}
V8_INLINE static PreParserExpression EmptyClassLiteralProperty() {
return PreParserExpression::Default();
V8_INLINE static PreParserExpression NullExpression() {
return PreParserExpression::Null();
}
V8_INLINE static PreParserExpression EmptyFunctionLiteral() {
return PreParserExpression::Default();
V8_INLINE static PreParserExpression NullLiteralProperty() {
return PreParserExpression::Null();
}
V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) {
return expr.IsEmpty();
}
V8_INLINE static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList::Null();
}
V8_INLINE static bool IsNullExpressionList(PreParserExpressionList exprs) {
return exprs.IsNull();
}
V8_INLINE static PreParserStatementList NullStatementList() {
return PreParserStatementList::Null();
}
V8_INLINE static bool IsNullStatementList(PreParserStatementList stmts) {
return stmts.IsNull();
}
V8_INLINE static PreParserStatement NullStatement() {
return PreParserStatement::Null();
}
V8_INLINE bool IsNullStatement(PreParserStatement stmt) {
return stmt.IsNullStatement();
}
V8_INLINE bool IsEmptyStatement(PreParserStatement stmt) {
return stmt.IsEmptyStatement();
}
V8_INLINE static PreParserStatement NullBlock() {
return PreParserStatement::Null();
template <typename T>
V8_INLINE static bool IsNull(T subject) {
return subject.IsNull();
}
V8_INLINE PreParserIdentifier EmptyIdentifierString() const {
......@@ -1654,7 +1626,7 @@ class PreParser : public ParserBase<PreParser> {
parameters->params.Add(new (zone()) PreParserFormalParameters::Parameter(
pattern.variables_, is_rest));
}
parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest);
parameters->UpdateArityAndFunctionLength(!initializer.IsNull(), is_rest);
}
V8_INLINE void DeclareFormalParameters(
......@@ -1772,12 +1744,6 @@ PreParserExpression PreParser::SpreadCallNew(PreParserExpression function,
return factory()->NewCallNew(function, args, pos);
}
PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state,
int start,
PreParserExpression tag) {
return EmptyExpression();
}
} // namespace internal
} // namespace v8
......
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