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