[parser] Clean up dead or overly general code in ExpressionClassifier
ParseErrorType is never passed to ExpressionClassifier, so there's no need to store it in the Error struct (we can always use the Parser's default of SyntaxError). Also simplify the handling of non-simple parameter detection, which was stored in a two-bit function_properties_ field that was only being used for this purpose. Bug: v8:8015 Change-Id: I198e8285cbafee650614d1ff5bb434fe9fd2a338 Reviewed-on: https://chromium-review.googlesource.com/1180525 Reviewed-by: Marja Hölttä <marja@chromium.org> Commit-Queue: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/master@{#55234}
This commit is contained in:
parent
8fa7f9ed93
commit
e0d77f3ec4
@ -61,18 +61,15 @@ class ExpressionClassifier {
|
|||||||
: location(Scanner::Location::invalid()),
|
: location(Scanner::Location::invalid()),
|
||||||
message(MessageTemplate::kNone),
|
message(MessageTemplate::kNone),
|
||||||
kind(kUnusedError),
|
kind(kUnusedError),
|
||||||
type(kSyntaxError),
|
|
||||||
arg(nullptr) {}
|
arg(nullptr) {}
|
||||||
V8_INLINE explicit Error(Scanner::Location loc,
|
V8_INLINE explicit Error(Scanner::Location loc,
|
||||||
MessageTemplate::Template msg, ErrorKind k,
|
MessageTemplate::Template msg, ErrorKind k,
|
||||||
const char* a = nullptr,
|
const char* a = nullptr)
|
||||||
ParseErrorType t = kSyntaxError)
|
: location(loc), message(msg), kind(k), arg(a) {}
|
||||||
: location(loc), message(msg), kind(k), type(t), arg(a) {}
|
|
||||||
|
|
||||||
Scanner::Location location;
|
Scanner::Location location;
|
||||||
MessageTemplate::Template message : 26;
|
MessageTemplate::Template message : 28;
|
||||||
unsigned kind : 4;
|
unsigned kind : 4;
|
||||||
ParseErrorType type : 2;
|
|
||||||
const char* arg;
|
const char* arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,10 +85,6 @@ class ExpressionClassifier {
|
|||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
enum FunctionProperties : unsigned {
|
|
||||||
NonSimpleParameter = 1 << 0
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit ExpressionClassifier(typename Types::Base* base,
|
explicit ExpressionClassifier(typename Types::Base* base,
|
||||||
DuplicateFinder* duplicate_finder = nullptr)
|
DuplicateFinder* duplicate_finder = nullptr)
|
||||||
: base_(base),
|
: base_(base),
|
||||||
@ -100,7 +93,7 @@ class ExpressionClassifier {
|
|||||||
reported_errors_(base->impl()->GetReportedErrorList()),
|
reported_errors_(base->impl()->GetReportedErrorList()),
|
||||||
duplicate_finder_(duplicate_finder),
|
duplicate_finder_(duplicate_finder),
|
||||||
invalid_productions_(0),
|
invalid_productions_(0),
|
||||||
function_properties_(0) {
|
is_non_simple_parameter_list_(0) {
|
||||||
base->classifier_ = this;
|
base->classifier_ = this;
|
||||||
reported_errors_begin_ = reported_errors_end_ = reported_errors_->length();
|
reported_errors_begin_ = reported_errors_end_ = reported_errors_->length();
|
||||||
}
|
}
|
||||||
@ -193,11 +186,11 @@ class ExpressionClassifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
V8_INLINE bool is_simple_parameter_list() const {
|
V8_INLINE bool is_simple_parameter_list() const {
|
||||||
return !(function_properties_ & NonSimpleParameter);
|
return !is_non_simple_parameter_list_;
|
||||||
}
|
}
|
||||||
|
|
||||||
V8_INLINE void RecordNonSimpleParameter() {
|
V8_INLINE void RecordNonSimpleParameter() {
|
||||||
function_properties_ |= NonSimpleParameter;
|
is_non_simple_parameter_list_ = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordExpressionError(const Scanner::Location& loc,
|
void RecordExpressionError(const Scanner::Location& loc,
|
||||||
@ -208,14 +201,6 @@ class ExpressionClassifier {
|
|||||||
Add(Error(loc, message, kExpressionProduction, arg));
|
Add(Error(loc, message, kExpressionProduction, arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordExpressionError(const Scanner::Location& loc,
|
|
||||||
MessageTemplate::Template message,
|
|
||||||
ParseErrorType type, const char* arg = nullptr) {
|
|
||||||
if (!is_valid_expression()) return;
|
|
||||||
invalid_productions_ |= ExpressionProduction;
|
|
||||||
Add(Error(loc, message, kExpressionProduction, arg, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecordFormalParameterInitializerError(const Scanner::Location& loc,
|
void RecordFormalParameterInitializerError(const Scanner::Location& loc,
|
||||||
MessageTemplate::Template message,
|
MessageTemplate::Template message,
|
||||||
const char* arg = nullptr) {
|
const char* arg = nullptr) {
|
||||||
@ -305,9 +290,9 @@ class ExpressionClassifier {
|
|||||||
bool copy_BP_to_AFP = false;
|
bool copy_BP_to_AFP = false;
|
||||||
if (productions & ArrowFormalParametersProduction &&
|
if (productions & ArrowFormalParametersProduction &&
|
||||||
is_valid_arrow_formal_parameters()) {
|
is_valid_arrow_formal_parameters()) {
|
||||||
// Also copy function properties if expecting an arrow function
|
// Also whether we've seen any non-simple parameters
|
||||||
// parameter.
|
// if expecting an arrow function parameter.
|
||||||
function_properties_ |= inner->function_properties_;
|
is_non_simple_parameter_list_ |= inner->is_non_simple_parameter_list_;
|
||||||
if (!inner->is_valid_binding_pattern()) {
|
if (!inner->is_valid_binding_pattern()) {
|
||||||
copy_BP_to_AFP = true;
|
copy_BP_to_AFP = true;
|
||||||
invalid_productions_ |= ArrowFormalParametersProduction;
|
invalid_productions_ |= ArrowFormalParametersProduction;
|
||||||
@ -411,8 +396,8 @@ class ExpressionClassifier {
|
|||||||
Zone* zone_;
|
Zone* zone_;
|
||||||
ZoneList<Error>* reported_errors_;
|
ZoneList<Error>* reported_errors_;
|
||||||
DuplicateFinder* duplicate_finder_;
|
DuplicateFinder* duplicate_finder_;
|
||||||
unsigned invalid_productions_ : 14;
|
unsigned invalid_productions_ : 15;
|
||||||
unsigned function_properties_ : 2;
|
unsigned is_non_simple_parameter_list_ : 1;
|
||||||
// The uint16_t for reported_errors_begin_ and reported_errors_end_ will
|
// The uint16_t for reported_errors_begin_ and reported_errors_end_ will
|
||||||
// not be enough in the case of a long series of expressions using nested
|
// not be enough in the case of a long series of expressions using nested
|
||||||
// classifiers, e.g., a long sequence of assignments, as in:
|
// classifiers, e.g., a long sequence of assignments, as in:
|
||||||
|
@ -962,8 +962,7 @@ class ParserBase {
|
|||||||
|
|
||||||
void ReportClassifierError(
|
void ReportClassifierError(
|
||||||
const typename ExpressionClassifier::Error& error) {
|
const typename ExpressionClassifier::Error& error) {
|
||||||
impl()->ReportMessageAt(error.location, error.message, error.arg,
|
impl()->ReportMessageAt(error.location, error.message, error.arg);
|
||||||
error.type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateExpression(bool* ok) {
|
void ValidateExpression(bool* ok) {
|
||||||
|
Loading…
Reference in New Issue
Block a user