Commit ba9367db authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Clean up (pre)parser traits, part 5, last

This patch moves the following methods from the traits objects to
the (pre)parser implementation objects:

- AddFormalParameter
- AddParameterInitializationBlock
- DeclareFormalParameter
- ExpressionListToExpression
- GetNonPatternList
- GetReportedErrorList
- IsTaggedTemplate
- MaterializeUnspreadArgumentsLiterals
- NoTemplateTag
- ParseArrowFunctionFormalParameterList
- ReindexLiterals
- SetFunctionNameFromIdentifierRef
- SetFunctionNameFromPropertyName

It moves the Void method from the preparser traits object to the
preparser implementation object.  It also removes the traits zone
method and replaces it with that of ParserBase, which it turns to
public.

After all this, the traits objects contain just typedefs and the
delegate methods are no more necessary.

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

Review-Url: https://codereview.chromium.org/2277843002
Cr-Commit-Position: refs/heads/master@{#38892}
parent 95560650
......@@ -77,21 +77,11 @@ class ExpressionClassifier {
NonSimpleParameter = 1 << 0
};
explicit ExpressionClassifier(const Traits* t)
: zone_(t->zone()),
non_patterns_to_rewrite_(t->GetNonPatternList()),
reported_errors_(t->GetReportedErrorList()),
duplicate_finder_(nullptr),
invalid_productions_(0),
function_properties_(0) {
reported_errors_begin_ = reported_errors_end_ = reported_errors_->length();
non_pattern_begin_ = non_patterns_to_rewrite_->length();
}
ExpressionClassifier(const Traits* t, DuplicateFinder* duplicate_finder)
: zone_(t->zone()),
non_patterns_to_rewrite_(t->GetNonPatternList()),
reported_errors_(t->GetReportedErrorList()),
explicit ExpressionClassifier(const typename Traits::Type::Base* base,
DuplicateFinder* duplicate_finder = nullptr)
: zone_(base->impl()->zone()),
non_patterns_to_rewrite_(base->impl()->GetNonPatternList()),
reported_errors_(base->impl()->GetReportedErrorList()),
duplicate_finder_(duplicate_finder),
invalid_productions_(0),
function_properties_(0) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -140,14 +140,15 @@ struct ParserFormalParameters : FormalParametersBase {
template <>
class ParserBaseTraits<Parser> {
public:
typedef ParserBaseTraits<Parser> ParserTraits;
struct Type {
typedef ParserBase<Parser> Base;
typedef Parser Impl;
typedef Variable GeneratorVariable;
typedef v8::internal::AstProperties AstProperties;
typedef v8::internal::ExpressionClassifier<ParserTraits>
typedef v8::internal::ExpressionClassifier<ParserBaseTraits<Parser>>
ExpressionClassifier;
// Return types for traversing functions.
......@@ -167,53 +168,6 @@ class ParserBaseTraits<Parser> {
// For constructing objects returned by the traversing functions.
typedef AstNodeFactory Factory;
};
// TODO(nikolaos): The traits methods should not need to call methods
// of the implementation object.
Parser* delegate() { return reinterpret_cast<Parser*>(this); }
const Parser* delegate() const {
return reinterpret_cast<const Parser*>(this);
}
V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok);
V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
Expression* pattern,
Expression* initializer,
int initializer_end_position, bool is_rest);
V8_INLINE void DeclareFormalParameter(
DeclarationScope* scope,
const ParserFormalParameters::Parameter& parameter,
Type::ExpressionClassifier* classifier);
void ParseArrowFunctionFormalParameterList(
ParserFormalParameters* parameters, Expression* params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok);
void ReindexLiterals(const ParserFormalParameters& parameters);
V8_INLINE Expression* NoTemplateTag() { return NULL; }
V8_INLINE static bool IsTaggedTemplate(const Expression* tag) {
return tag != NULL;
}
V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
Expression* ExpressionListToExpression(ZoneList<Expression*>* args);
void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name);
void SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier);
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
GetReportedErrorList() const;
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<Expression*>* GetNonPatternList() const;
};
class Parser : public ParserBase<Parser> {
......@@ -243,9 +197,7 @@ class Parser : public ParserBase<Parser> {
private:
friend class ParserBase<Parser>;
// TODO(nikolaos): This should not be necessary. It will be removed
// when the traits object stops delegating to the implementation object.
friend class ParserBaseTraits<Parser>;
friend class v8::internal::ExpressionClassifier<ParserBaseTraits<Parser>>;
// Runtime encoding of different completion modes.
enum CompletionKind {
......@@ -1004,6 +956,88 @@ class Parser : public ParserBase<Parser> {
return new (zone()) ZoneList<v8::internal::Statement*>(size, zone());
}
V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
if (parameters.is_simple) return;
auto* init_block = BuildParameterInitializationBlock(parameters, ok);
if (!*ok) return;
if (is_async) init_block = BuildRejectPromiseOnException(init_block);
if (init_block != nullptr) body->Add(init_block, zone());
}
V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
Expression* pattern,
Expression* initializer,
int initializer_end_position,
bool is_rest) {
bool is_simple = pattern->IsVariableProxy() && initializer == nullptr;
const AstRawString* name = is_simple
? pattern->AsVariableProxy()->raw_name()
: ast_value_factory()->empty_string();
parameters->params.Add(
ParserFormalParameters::Parameter(name, pattern, initializer,
initializer_end_position, is_rest),
parameters->scope->zone());
}
V8_INLINE void DeclareFormalParameter(
DeclarationScope* scope,
const ParserFormalParameters::Parameter& parameter,
Type::ExpressionClassifier* classifier) {
bool is_duplicate = false;
bool is_simple = classifier->is_simple_parameter_list();
auto name = is_simple || parameter.is_rest
? parameter.name
: ast_value_factory()->empty_string();
auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY;
if (!is_simple) scope->SetHasNonSimpleParameters();
bool is_optional = parameter.initializer != nullptr;
Variable* var =
scope->DeclareParameter(name, mode, is_optional, parameter.is_rest,
&is_duplicate, ast_value_factory());
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(scanner()->location());
}
if (is_sloppy(scope->language_mode())) {
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
// conservative approximation necessary to account for parameters
// that are assigned via the arguments array.
var->set_maybe_assigned();
}
}
void ParseArrowFunctionFormalParameterList(
ParserFormalParameters* parameters, Expression* params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok);
void ReindexLiterals(const ParserFormalParameters& parameters);
V8_INLINE Expression* NoTemplateTag() { return NULL; }
V8_INLINE static bool IsTaggedTemplate(const Expression* tag) {
return tag != NULL;
}
V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
Expression* ExpressionListToExpression(ZoneList<Expression*>* args);
void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name);
void SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier);
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
GetReportedErrorList() const {
return function_state_->GetReportedErrorList();
}
V8_INLINE ZoneList<Expression*>* GetNonPatternList() const {
return function_state_->non_patterns_to_rewrite();
}
// Parser's private field members.
Scanner scanner_;
......@@ -1057,63 +1091,6 @@ class CompileTimeValue: public AllStatic {
DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
};
void ParserBaseTraits<Parser>::AddFormalParameter(
ParserFormalParameters* parameters, Expression* pattern,
Expression* initializer, int initializer_end_position, bool is_rest) {
bool is_simple = pattern->IsVariableProxy() && initializer == nullptr;
const AstRawString* name =
is_simple ? pattern->AsVariableProxy()->raw_name()
: delegate()->ast_value_factory()->empty_string();
parameters->params.Add(
ParserFormalParameters::Parameter(name, pattern, initializer,
initializer_end_position, is_rest),
parameters->scope->zone());
}
void ParserBaseTraits<Parser>::DeclareFormalParameter(
DeclarationScope* scope, const ParserFormalParameters::Parameter& parameter,
Type::ExpressionClassifier* classifier) {
bool is_duplicate = false;
bool is_simple = classifier->is_simple_parameter_list();
auto name = is_simple || parameter.is_rest
? parameter.name
: delegate()->ast_value_factory()->empty_string();
auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY;
if (!is_simple) scope->SetHasNonSimpleParameters();
bool is_optional = parameter.initializer != nullptr;
Variable* var =
scope->DeclareParameter(name, mode, is_optional, parameter.is_rest,
&is_duplicate, delegate()->ast_value_factory());
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(
delegate()->scanner()->location());
}
if (is_sloppy(scope->language_mode())) {
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
// conservative approximation necessary to account for parameters
// that are assigned via the arguments array.
var->set_maybe_assigned();
}
}
void ParserBaseTraits<Parser>::AddParameterInitializationBlock(
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
if (!parameters.is_simple) {
auto* init_block =
delegate()->BuildParameterInitializationBlock(parameters, ok);
if (!*ok) return;
if (is_async) {
init_block = delegate()->BuildRejectPromiseOnException(init_block);
}
if (init_block != nullptr) {
body->Add(init_block, delegate()->zone());
}
}
}
} // namespace internal
} // namespace v8
......
......@@ -18,7 +18,6 @@
namespace v8 {
namespace internal {
class PreParserIdentifier {
public:
PreParserIdentifier() : type_(kUnknownIdentifier) {}
......@@ -588,15 +587,16 @@ class PreParser;
template <>
class ParserBaseTraits<PreParser> {
public:
typedef ParserBaseTraits<PreParser> PreParserTraits;
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<PreParserTraits>
typedef v8::internal::ExpressionClassifier<ParserBaseTraits<PreParser>>
ExpressionClassifier;
// Return types for traversing functions.
......@@ -616,66 +616,6 @@ class ParserBaseTraits<PreParser> {
// For constructing objects returned by the traversing functions.
typedef PreParserFactory Factory;
};
// TODO(nikolaos): The traits methods should not need to call methods
// of the implementation object.
PreParser* delegate() { return reinterpret_cast<PreParser*>(this); }
const PreParser* delegate() const {
return reinterpret_cast<const PreParser*>(this);
}
// A dummy function, just useful as an argument to CHECK_OK_CUSTOM.
static void Void() {}
void AddParameterInitializationBlock(
const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) {}
void AddFormalParameter(PreParserFormalParameters* parameters,
PreParserExpression pattern,
PreParserExpression initializer,
int initializer_end_position, bool is_rest) {
++parameters->arity;
}
void DeclareFormalParameter(DeclarationScope* scope,
PreParserIdentifier parameter,
Type::ExpressionClassifier* classifier) {
if (!classifier->is_simple_parameter_list()) {
scope->SetHasNonSimpleParameters();
}
}
V8_INLINE void ParseArrowFunctionFormalParameterList(
PreParserFormalParameters* parameters, PreParserExpression params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok);
void ReindexLiterals(const PreParserFormalParameters& parameters) {}
V8_INLINE PreParserExpression NoTemplateTag() {
return PreParserExpression::NoTemplateTag();
}
V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) {
return !tag.IsNoTemplateTag();
}
inline void MaterializeUnspreadArgumentsLiterals(int count);
inline PreParserExpression ExpressionListToExpression(
PreParserExpressionList args) {
return PreParserExpression::Default();
}
void SetFunctionNameFromPropertyName(PreParserExpression property,
PreParserIdentifier name) {}
void SetFunctionNameFromIdentifierRef(PreParserExpression value,
PreParserExpression identifier) {}
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
GetReportedErrorList() const;
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
};
......@@ -693,9 +633,7 @@ class ParserBaseTraits<PreParser> {
// it is used) are generally omitted.
class PreParser : public ParserBase<PreParser> {
friend class ParserBase<PreParser>;
// TODO(nikolaos): This should not be necessary. It will be removed
// when the traits object stops delegating to the implementation object.
friend class ParserBaseTraits<PreParser>;
friend class v8::internal::ExpressionClassifier<ParserBaseTraits<PreParser>>;
public:
typedef PreParserIdentifier Identifier;
......@@ -763,6 +701,9 @@ class PreParser : public ParserBase<PreParser> {
Scanner::BookmarkScope* bookmark,
int* use_counts);
// A dummy function, just useful as an argument to CHECK_OK_CUSTOM.
static void Void() {}
private:
static const int kLazyParseTrialLimit = 200;
......@@ -1139,17 +1080,74 @@ class PreParser : public ParserBase<PreParser> {
return PreParserStatementList();
}
// Preparser's private field members.
V8_INLINE void AddParameterInitializationBlock(
const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) {}
int* use_counts_;
};
V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters,
PreParserExpression pattern,
PreParserExpression initializer,
int initializer_end_position,
bool is_rest) {
++parameters->arity;
}
void ParserBaseTraits<PreParser>::MaterializeUnspreadArgumentsLiterals(
int count) {
V8_INLINE void DeclareFormalParameter(
DeclarationScope* scope, PreParserIdentifier parameter,
Type::ExpressionClassifier* classifier) {
if (!classifier->is_simple_parameter_list()) {
scope->SetHasNonSimpleParameters();
}
}
V8_INLINE void ParseArrowFunctionFormalParameterList(
PreParserFormalParameters* parameters, PreParserExpression params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok) {
// TODO(wingo): Detect duplicated identifiers in paramlists. Detect
// parameter
// lists that are too long.
}
V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {}
V8_INLINE PreParserExpression NoTemplateTag() {
return PreParserExpression::NoTemplateTag();
}
V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) {
return !tag.IsNoTemplateTag();
}
V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {
for (int i = 0; i < count; ++i) {
delegate()->function_state_->NextMaterializedLiteralIndex();
function_state_->NextMaterializedLiteralIndex();
}
}
}
V8_INLINE PreParserExpression
ExpressionListToExpression(PreParserExpressionList args) {
return PreParserExpression::Default();
}
V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property,
PreParserIdentifier name) {}
V8_INLINE void SetFunctionNameFromIdentifierRef(
PreParserExpression value, PreParserExpression identifier) {}
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
GetReportedErrorList() const {
return function_state_->GetReportedErrorList();
}
V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const {
return function_state_->non_patterns_to_rewrite();
}
// Preparser's private field members.
int* use_counts_;
};
PreParserExpression PreParser::SpreadCall(PreParserExpression function,
PreParserExpressionList args,
......@@ -1163,29 +1161,6 @@ PreParserExpression PreParser::SpreadCallNew(PreParserExpression function,
return factory()->NewCallNew(function, args, pos);
}
void ParserBaseTraits<PreParser>::ParseArrowFunctionFormalParameterList(
PreParserFormalParameters* parameters, PreParserExpression params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok) {
// TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
// lists that are too long.
}
ZoneList<PreParserExpression>* ParserBaseTraits<PreParser>::GetNonPatternList()
const {
return delegate()->function_state_->non_patterns_to_rewrite();
}
ZoneList<
typename ParserBaseTraits<PreParser>::Type::ExpressionClassifier::Error>*
ParserBaseTraits<PreParser>::GetReportedErrorList() const {
return delegate()->function_state_->GetReportedErrorList();
}
Zone* ParserBaseTraits<PreParser>::zone() const {
return delegate()->function_state_->scope()->zone();
}
PreParserStatementList PreParser::ParseEagerFunctionBody(
PreParserIdentifier function_name, int pos,
const PreParserFormalParameters& parameters, FunctionKind kind,
......
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