Commit 58cfe4d6 authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Clean up type definitions

This patch:

1. Removes the unecessary inheritance of ParserBaseTraits<Impl>
   in ParserBase<Impl>.
2. Flattens ParserBaseTraits<Impl> and renames it to
   ParserTypes<Impl>.  The Traits parameter/member is renamed to
   Types.
3. Removes unecessary v8::internal:: qualifications from parser
   types.

R=adamk@chromium.org, marja@chromium.org
BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2279773002
Cr-Commit-Position: refs/heads/master@{#38927}
parent b143cb09
......@@ -26,7 +26,7 @@ class DuplicateFinder;
T(TailCallExpressionProduction, 8) \
T(AsyncArrowFormalParametersProduction, 9)
template <typename Traits>
template <typename Types>
class ExpressionClassifier {
public:
enum ErrorKind : unsigned {
......@@ -72,7 +72,7 @@ class ExpressionClassifier {
NonSimpleParameter = 1 << 0
};
explicit ExpressionClassifier(const typename Traits::Type::Base* base,
explicit ExpressionClassifier(const typename Types::Base* base,
DuplicateFinder* duplicate_finder = nullptr)
: zone_(base->impl()->zone()),
non_patterns_to_rewrite_(base->impl()->GetNonPatternList()),
......@@ -418,7 +418,7 @@ class ExpressionClassifier {
}
Zone* zone_;
ZoneList<typename Traits::Type::Expression>* non_patterns_to_rewrite_;
ZoneList<typename Types::Expression>* non_patterns_to_rewrite_;
ZoneList<Error>* reported_errors_;
DuplicateFinder* duplicate_finder_;
// The uint16_t for non_pattern_begin_ will not be enough in the case,
......
This diff is collapsed.
......@@ -3866,7 +3866,7 @@ void Parser::ParseArrowFunctionFormalParameterList(
return;
}
Type::ExpressionClassifier classifier(this);
ExpressionClassifier classifier(this);
if (!parameters->is_simple) {
classifier.RecordNonSimpleParameter();
}
......@@ -5260,11 +5260,9 @@ uint32_t Parser::ComputeTemplateLiteralHash(const TemplateLiteral* lit) {
return running_hash;
}
ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
ZoneList<v8::internal::Expression*>* list) {
ZoneList<v8::internal::Expression*>* args =
new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
ZoneList<Expression*>* Parser::PrepareSpreadArguments(
ZoneList<Expression*>* list) {
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
if (list->length() == 1) {
// Spread-call with single spread argument produces an InternalArray
// containing the values from the array.
......@@ -5291,8 +5289,8 @@ ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
int n = list->length();
while (i < n) {
if (!list->at(i)->IsSpread()) {
ZoneList<v8::internal::Expression*>* unspread =
new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
ZoneList<Expression*>* unspread =
new (zone()) ZoneList<Expression*>(1, zone());
// Push array of unspread parameters
while (i < n && !list->at(i)->IsSpread()) {
......@@ -5307,15 +5305,15 @@ ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
}
// Push eagerly spread argument
ZoneList<v8::internal::Expression*>* spread_list =
new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
ZoneList<Expression*>* spread_list =
new (zone()) ZoneList<Expression*>(1, zone());
spread_list->Add(list->at(i++)->AsSpread()->expression(), zone());
args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX,
spread_list, kNoSourcePosition),
zone());
}
list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone());
list = new (zone()) ZoneList<Expression*>(1, zone());
list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args,
kNoSourcePosition),
zone());
......@@ -5324,10 +5322,8 @@ ZoneList<v8::internal::Expression*>* Parser::PrepareSpreadArguments(
UNREACHABLE();
}
Expression* Parser::SpreadCall(Expression* function,
ZoneList<v8::internal::Expression*>* args,
int pos) {
ZoneList<Expression*>* args, int pos) {
if (function->IsSuperCallReference()) {
// Super calls
// $super_constructor = %_GetSuperConstructor(<this-function>)
......@@ -5369,10 +5365,8 @@ Expression* Parser::SpreadCall(Expression* function,
}
}
Expression* Parser::SpreadCallNew(Expression* function,
ZoneList<v8::internal::Expression*>* args,
int pos) {
ZoneList<Expression*>* args, int pos) {
args->InsertAt(0, function, zone());
return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
......
......@@ -138,36 +138,33 @@ struct ParserFormalParameters : FormalParametersBase {
};
template <>
class ParserBaseTraits<Parser> {
public:
struct Type {
typedef ParserBase<Parser> Base;
typedef Parser Impl;
typedef Variable GeneratorVariable;
typedef v8::internal::AstProperties AstProperties;
typedef v8::internal::ExpressionClassifier<ParserBaseTraits<Parser>>
ExpressionClassifier;
// Return types for traversing functions.
typedef const AstRawString* Identifier;
typedef v8::internal::Expression* Expression;
typedef Yield* YieldExpression;
typedef v8::internal::FunctionLiteral* FunctionLiteral;
typedef v8::internal::ClassLiteral* ClassLiteral;
typedef v8::internal::Literal* Literal;
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
typedef ParserFormalParameters::Parameter FormalParameter;
typedef ParserFormalParameters FormalParameters;
typedef ZoneList<v8::internal::Statement*>* StatementList;
// For constructing objects returned by the traversing functions.
typedef AstNodeFactory Factory;
};
struct ParserTypes<Parser> {
typedef ParserBase<Parser> Base;
typedef Parser Impl;
typedef Variable GeneratorVariable;
typedef v8::internal::AstProperties AstProperties;
typedef v8::internal::ExpressionClassifier<ParserTypes<Parser>>
ExpressionClassifier;
// Return types for traversing functions.
typedef const AstRawString* Identifier;
typedef v8::internal::Expression* Expression;
typedef Yield* YieldExpression;
typedef v8::internal::FunctionLiteral* FunctionLiteral;
typedef v8::internal::ClassLiteral* ClassLiteral;
typedef v8::internal::Literal* Literal;
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
typedef ParserFormalParameters::Parameter FormalParameter;
typedef ParserFormalParameters FormalParameters;
typedef ZoneList<v8::internal::Statement*>* StatementList;
// For constructing objects returned by the traversing functions.
typedef AstNodeFactory Factory;
};
class Parser : public ParserBase<Parser> {
......@@ -197,7 +194,7 @@ class Parser : public ParserBase<Parser> {
private:
friend class ParserBase<Parser>;
friend class v8::internal::ExpressionClassifier<ParserBaseTraits<Parser>>;
friend class v8::internal::ExpressionClassifier<ParserTypes<Parser>>;
// Runtime encoding of different completion modes.
enum CompletionKind {
......@@ -480,7 +477,7 @@ class Parser : public ParserBase<Parser> {
void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope,
ZoneList<Statement*>* body,
Type::ExpressionClassifier* classifier,
ExpressionClassifier* classifier,
FunctionKind kind, FunctionBodyType type,
bool accept_IN, int pos, bool* ok);
......@@ -623,12 +620,11 @@ class Parser : public ParserBase<Parser> {
pos, ok);
}
ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
ZoneList<v8::internal::Expression*>* list);
Expression* SpreadCall(Expression* function,
ZoneList<v8::internal::Expression*>* args, int pos);
Expression* SpreadCallNew(Expression* function,
ZoneList<v8::internal::Expression*>* args, int pos);
ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list);
Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args,
int pos);
Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args,
int pos);
void SetLanguageMode(Scope* scope, LanguageMode mode);
void RaiseLanguageMode(LanguageMode mode);
......@@ -943,22 +939,20 @@ class Parser : public ParserBase<Parser> {
return factory()->NewStringLiteral(symbol, pos);
}
V8_INLINE ZoneList<v8::internal::Expression*>* NewExpressionList(
int size) const {
return new (zone()) ZoneList<v8::internal::Expression*>(size, zone());
V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const {
return new (zone()) ZoneList<Expression*>(size, zone());
}
V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList(
int size) const {
return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone());
}
V8_INLINE ZoneList<v8::internal::Statement*>* NewStatementList(
int size) const {
return new (zone()) ZoneList<v8::internal::Statement*>(size, zone());
V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const {
return new (zone()) ZoneList<Statement*>(size, zone());
}
V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
const ParserFormalParameters& parameters, ZoneList<Statement*>* body,
bool is_async, bool* ok) {
if (parameters.is_simple) return;
auto* init_block = BuildParameterInitializationBlock(parameters, ok);
if (!*ok) return;
......@@ -984,7 +978,7 @@ class Parser : public ParserBase<Parser> {
V8_INLINE void DeclareFormalParameter(
DeclarationScope* scope,
const ParserFormalParameters::Parameter& parameter,
Type::ExpressionClassifier* classifier) {
ExpressionClassifier* classifier) {
bool is_duplicate = false;
bool is_simple = classifier->is_simple_parameter_list();
auto name = is_simple || parameter.is_rest
......@@ -1029,7 +1023,7 @@ class Parser : public ParserBase<Parser> {
void SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier);
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
V8_INLINE ZoneList<typename ExpressionClassifier::Error>*
GetReportedErrorList() const {
return function_state_->GetReportedErrorList();
}
......
......@@ -18,6 +18,14 @@
namespace v8 {
namespace internal {
// Whereas the Parser generates AST during the recursive descent,
// the PreParser doesn't create a tree. Instead, it passes around minimal
// data objects (PreParserExpression, PreParserIdentifier etc.) which contain
// just enough data for the upper layer functions. PreParserFactory is
// responsible for creating these dummy objects. It provides a similar kind of
// interface as AstNodeFactory, so ParserBase doesn't need to care which one is
// used.
class PreParserIdentifier {
public:
PreParserIdentifier() : type_(kUnknownIdentifier) {}
......@@ -585,37 +593,34 @@ struct PreParserFormalParameters : FormalParametersBase {
class PreParser;
template <>
class ParserBaseTraits<PreParser> {
public:
struct Type {
typedef ParserBase<PreParser> Base;
typedef PreParser Impl;
// PreParser doesn't need to store generator variables.
typedef void GeneratorVariable;
typedef int AstProperties;
typedef v8::internal::ExpressionClassifier<ParserBaseTraits<PreParser>>
ExpressionClassifier;
// Return types for traversing functions.
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
typedef PreParserExpression YieldExpression;
typedef PreParserExpression FunctionLiteral;
typedef PreParserExpression ClassLiteral;
typedef PreParserExpression Literal;
typedef PreParserExpression ObjectLiteralProperty;
typedef PreParserExpressionList ExpressionList;
typedef PreParserExpressionList PropertyList;
typedef PreParserIdentifier FormalParameter;
typedef PreParserFormalParameters FormalParameters;
typedef PreParserStatementList StatementList;
// For constructing objects returned by the traversing functions.
typedef PreParserFactory Factory;
};
struct ParserTypes<PreParser> {
typedef ParserBase<PreParser> Base;
typedef PreParser Impl;
// PreParser doesn't need to store generator variables.
typedef void GeneratorVariable;
typedef int AstProperties;
typedef v8::internal::ExpressionClassifier<ParserTypes<PreParser>>
ExpressionClassifier;
// Return types for traversing functions.
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
typedef PreParserExpression YieldExpression;
typedef PreParserExpression FunctionLiteral;
typedef PreParserExpression ClassLiteral;
typedef PreParserExpression Literal;
typedef PreParserExpression ObjectLiteralProperty;
typedef PreParserExpressionList ExpressionList;
typedef PreParserExpressionList PropertyList;
typedef PreParserIdentifier FormalParameter;
typedef PreParserFormalParameters FormalParameters;
typedef PreParserStatementList StatementList;
// For constructing objects returned by the traversing functions.
typedef PreParserFactory Factory;
};
......@@ -633,7 +638,7 @@ class ParserBaseTraits<PreParser> {
// it is used) are generally omitted.
class PreParser : public ParserBase<PreParser> {
friend class ParserBase<PreParser>;
friend class v8::internal::ExpressionClassifier<ParserBaseTraits<PreParser>>;
friend class v8::internal::ExpressionClassifier<ParserTypes<PreParser>>;
public:
typedef PreParserIdentifier Identifier;
......@@ -836,8 +841,7 @@ class PreParser : public ParserBase<PreParser> {
int pos) {
return PreParserExpression::Default();
}
V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok) {
V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) {
ValidateExpression(classifier, ok);
}
......@@ -1092,9 +1096,9 @@ class PreParser : public ParserBase<PreParser> {
++parameters->arity;
}
V8_INLINE void DeclareFormalParameter(
DeclarationScope* scope, PreParserIdentifier parameter,
Type::ExpressionClassifier* classifier) {
V8_INLINE void DeclareFormalParameter(DeclarationScope* scope,
PreParserIdentifier parameter,
ExpressionClassifier* classifier) {
if (!classifier->is_simple_parameter_list()) {
scope->SetHasNonSimpleParameters();
}
......@@ -1135,7 +1139,7 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE void SetFunctionNameFromIdentifierRef(
PreParserExpression value, PreParserExpression identifier) {}
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
V8_INLINE ZoneList<typename ExpressionClassifier::Error>*
GetReportedErrorList() const {
return function_state_->GetReportedErrorList();
}
......
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