summaryrefslogtreecommitdiff
path: root/deps/v8/src/parsing/parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/parsing/parser.h')
-rw-r--r--deps/v8/src/parsing/parser.h163
1 files changed, 95 insertions, 68 deletions
diff --git a/deps/v8/src/parsing/parser.h b/deps/v8/src/parsing/parser.h
index 296762c14d..aa800dafc5 100644
--- a/deps/v8/src/parsing/parser.h
+++ b/deps/v8/src/parsing/parser.h
@@ -17,7 +17,6 @@
#include "src/parsing/preparse-data-format.h"
#include "src/parsing/preparse-data.h"
#include "src/parsing/preparser.h"
-#include "src/pending-compilation-error-handler.h"
#include "src/utils.h"
namespace v8 {
@@ -31,6 +30,7 @@ class ParseInfo;
class ScriptData;
class ParserTarget;
class ParserTargetScope;
+class PendingCompilationErrorHandler;
class PreParsedScopeData;
class FunctionEntry BASE_EMBEDDED {
@@ -85,7 +85,7 @@ class ParseData {
if (pd->IsSane()) return pd;
cached_data->Reject();
delete pd;
- return NULL;
+ return nullptr;
}
void Initialize();
@@ -167,6 +167,7 @@ struct ParserTypes<Parser> {
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ClassLiteral::Property* ClassLiteralProperty;
typedef v8::internal::Suspend* Suspend;
+ typedef v8::internal::RewritableExpression* RewritableExpression;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* ObjectPropertyList;
typedef ZoneList<ClassLiteral::Property*>* ClassPropertyList;
@@ -190,9 +191,9 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
explicit Parser(ParseInfo* info);
~Parser() {
delete reusable_preparser_;
- reusable_preparser_ = NULL;
+ reusable_preparser_ = nullptr;
delete cached_parse_data_;
- cached_parse_data_ = NULL;
+ cached_parse_data_ = nullptr;
}
static bool IsPreParser() { return false; }
@@ -210,8 +211,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
void DeserializeScopeChain(ParseInfo* info,
MaybeHandle<ScopeInfo> maybe_outer_scope_info);
- // Handle errors detected during parsing
- void ReportErrors(Isolate* isolate, Handle<Script> script);
// Move statistics to Isolate
void UpdateStatistics(Isolate* isolate, Handle<Script> script);
void HandleSourceURLComments(Isolate* isolate, Handle<Script> script);
@@ -257,7 +256,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
void PrepareGeneratorVariables();
- // Returns NULL if parsing failed.
+ // Returns nullptr if parsing failed.
FunctionLiteral* ParseProgram(Isolate* isolate, ParseInfo* info);
FunctionLiteral* ParseFunction(Isolate* isolate, ParseInfo* info,
@@ -283,22 +282,20 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
PreParser* reusable_preparser() {
- if (reusable_preparser_ == NULL) {
+ if (reusable_preparser_ == nullptr) {
reusable_preparser_ =
new PreParser(zone(), &scanner_, stack_limit_, ast_value_factory(),
- &pending_error_handler_, runtime_call_stats_,
- parsing_on_main_thread_);
+ pending_error_handler(), runtime_call_stats_, logger_,
+ -1, parsing_module_, parsing_on_main_thread_);
#define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
SET_ALLOW(natives);
SET_ALLOW(harmony_do_expressions);
SET_ALLOW(harmony_function_sent);
- SET_ALLOW(harmony_class_fields);
- SET_ALLOW(harmony_object_rest_spread);
+ SET_ALLOW(harmony_public_fields);
SET_ALLOW(harmony_dynamic_import);
SET_ALLOW(harmony_import_meta);
SET_ALLOW(harmony_async_iteration);
- SET_ALLOW(harmony_template_escapes);
- SET_ALLOW(harmony_restrictive_generators);
+ SET_ALLOW(harmony_bigint);
#undef SET_ALLOW
}
return reusable_preparser_;
@@ -348,15 +345,18 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
void ParseAndRewriteAsyncGeneratorFunctionBody(int pos, FunctionKind kind,
ZoneList<Statement*>* body,
bool* ok);
- void CreateFunctionNameAssignment(const AstRawString* function_name, int pos,
- FunctionLiteral::FunctionType function_type,
- DeclarationScope* function_scope,
- ZoneList<Statement*>* result, int index);
+ void DeclareFunctionNameVar(const AstRawString* function_name,
+ FunctionLiteral::FunctionType function_type,
+ DeclarationScope* function_scope);
Statement* DeclareFunction(const AstRawString* variable_name,
FunctionLiteral* function, VariableMode mode,
int pos, bool is_sloppy_block_function,
ZoneList<const AstRawString*>* names, bool* ok);
+ Variable* CreateSyntheticContextVariable(const AstRawString* synthetic_name,
+ bool* ok);
+ FunctionLiteral* CreateInitializerFunction(
+ DeclarationScope* scope, ZoneList<ClassLiteral::Property*>* fields);
V8_INLINE Statement* DeclareClass(const AstRawString* variable_name,
Expression* value,
ZoneList<const AstRawString*>* names,
@@ -368,6 +368,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
ClassLiteralProperty* property,
ClassLiteralProperty::Kind kind,
bool is_static, bool is_constructor,
+ bool is_computed_name,
ClassInfo* class_info, bool* ok);
V8_INLINE Expression* RewriteClassLiteral(Scope* block_scope,
const AstRawString* name,
@@ -426,9 +427,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int function_token_position, FunctionLiteral::FunctionType type,
LanguageMode language_mode, bool* ok);
- // Get odd-ball literals.
- Literal* GetLiteralUndefined(int position);
-
// Check if the scope has conflicting var/let declarations from different
// scopes. This covers for example
//
@@ -499,13 +497,13 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
TemplateLiteral(Zone* zone, int pos)
: cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {}
- const ZoneList<Literal*>* cooked() const { return &cooked_; }
- const ZoneList<Literal*>* raw() const { return &raw_; }
+ const ZoneList<const AstRawString*>* cooked() const { return &cooked_; }
+ const ZoneList<const AstRawString*>* raw() const { return &raw_; }
const ZoneList<Expression*>* expressions() const { return &expressions_; }
int position() const { return pos_; }
- void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) {
- DCHECK_NOT_NULL(cooked);
+ void AddTemplateSpan(const AstRawString* cooked, const AstRawString* raw,
+ int end, Zone* zone) {
DCHECK_NOT_NULL(raw);
cooked_.Add(cooked, zone);
raw_.Add(raw, zone);
@@ -517,8 +515,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
private:
- ZoneList<Literal*> cooked_;
- ZoneList<Literal*> raw_;
+ ZoneList<const AstRawString*> cooked_;
+ ZoneList<const AstRawString*> raw_;
ZoneList<Expression*> expressions_;
int pos_;
};
@@ -529,9 +527,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// "should_cook" means that the span can be "cooked": in tagged template
// literals, both the raw and "cooked" representations are available to user
// code ("cooked" meaning that escape sequences are converted to their
- // interpreted values). With the --harmony-template-escapes flag, invalid
- // escape sequences cause the cooked span to be represented by undefined,
- // instead of being a syntax error.
+ // interpreted values). Invalid escape sequences cause the cooked span
+ // to be represented by undefined, instead of being a syntax error.
// "tail" indicates that this span is the last in the literal.
void AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
bool tail);
@@ -554,20 +551,15 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// Rewrite all DestructuringAssignments in the current FunctionState.
V8_INLINE void RewriteDestructuringAssignments();
- V8_INLINE Expression* RewriteExponentiation(Expression* left,
- Expression* right, int pos);
- V8_INLINE Expression* RewriteAssignExponentiation(Expression* left,
- Expression* right, int pos);
-
- friend class NonPatternRewriter;
- V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
+ Expression* RewriteSpreads(ArrayLiteral* lit);
// Rewrite expressions that are not used as patterns
V8_INLINE void RewriteNonPattern(bool* ok);
V8_INLINE void QueueDestructuringAssignmentForRewriting(
- Expression* assignment);
- V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok);
+ RewritableExpression* assignment);
+ V8_INLINE void QueueNonPatternForRewriting(RewritableExpression* expr,
+ bool* ok);
friend class InitializerRewriter;
void RewriteParameterInitializer(Expression* expr);
@@ -623,9 +615,9 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// Returns true if the expression is of type "this.foo".
V8_INLINE static bool IsThisProperty(Expression* expression) {
- DCHECK(expression != NULL);
+ DCHECK_NOT_NULL(expression);
Property* property = expression->AsProperty();
- return property != NULL && property->obj()->IsVariableProxy() &&
+ return property != nullptr && property->obj()->IsVariableProxy() &&
property->obj()->AsVariableProxy()->is_this();
}
@@ -689,8 +681,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
ExpressionStatement* e_stat = statement->AsExpressionStatement();
if (e_stat == nullptr) return false;
Literal* literal = e_stat->expression()->AsLiteral();
- if (literal == nullptr || !literal->raw_value()->IsString()) return false;
- return arg == nullptr || literal->raw_value()->AsString() == arg;
+ if (literal == nullptr || !literal->IsString()) return false;
+ return arg == nullptr || literal->AsRawString() == arg;
}
V8_INLINE void GetDefaultStrings(
@@ -740,7 +732,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// literal so it can be added as a constant function property.
V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
Expression* left, Expression* right) {
- DCHECK(left != NULL);
+ DCHECK_NOT_NULL(left);
if (left->IsProperty() && right->IsFunctionLiteral()) {
right->AsFunctionLiteral()->set_pretenure();
}
@@ -761,6 +753,13 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
Token::Value op, int pos);
+ // Returns true if we have a binary operation between a binary/n-ary
+ // expression (with the same operation) and a value, which can be collapsed
+ // into a single n-ary expression. In that case, *x will be changed to an
+ // n-ary expression.
+ bool CollapseNaryExpression(Expression** x, Expression* y, Token::Value op,
+ int pos, const SourceRange& range);
+
// Rewrites the following types of unary expressions:
// not <literal> -> true / false
// + <numeric literal> -> <numeric literal>
@@ -798,10 +797,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
}
// Reporting errors.
- V8_INLINE void ReportMessageAt(Scanner::Location source_location,
- MessageTemplate::Template message,
- const char* arg = NULL,
- ParseErrorType error_type = kSyntaxError) {
+ void ReportMessageAt(Scanner::Location source_location,
+ MessageTemplate::Template message,
+ const char* arg = nullptr,
+ ParseErrorType error_type = kSyntaxError) {
if (stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
// stack overflow. The isolate allows only one pending exception at at
@@ -809,15 +808,15 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// and we want to report the stack overflow later.
return;
}
- pending_error_handler_.ReportMessageAt(source_location.beg_pos,
- source_location.end_pos, message,
- arg, error_type);
+ pending_error_handler()->ReportMessageAt(source_location.beg_pos,
+ source_location.end_pos, message,
+ arg, error_type);
}
- V8_INLINE void ReportMessageAt(Scanner::Location source_location,
- MessageTemplate::Template message,
- const AstRawString* arg,
- ParseErrorType error_type = kSyntaxError) {
+ void ReportMessageAt(Scanner::Location source_location,
+ MessageTemplate::Template message,
+ const AstRawString* arg,
+ ParseErrorType error_type = kSyntaxError) {
if (stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
// stack overflow. The isolate allows only one pending exception at at
@@ -825,9 +824,9 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// and we want to report the stack overflow later.
return;
}
- pending_error_handler_.ReportMessageAt(source_location.beg_pos,
- source_location.end_pos, message,
- arg, error_type);
+ pending_error_handler()->ReportMessageAt(source_location.beg_pos,
+ source_location.end_pos, message,
+ arg, error_type);
}
// "null" return type creators.
@@ -845,20 +844,15 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return subject == nullptr;
}
- // Non-NULL empty string.
+ // Non-null empty string.
V8_INLINE const AstRawString* EmptyIdentifierString() const {
return ast_value_factory()->empty_string();
}
- // Odd-ball literal creators.
- V8_INLINE Literal* GetLiteralTheHole(int position) {
- return factory()->NewTheHoleLiteral(kNoSourcePosition);
- }
-
// Producing data during the recursive descent.
V8_INLINE const AstRawString* GetSymbol() const {
const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory());
- DCHECK(result != NULL);
+ DCHECK_NOT_NULL(result);
return result;
}
@@ -882,6 +876,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
Expression* NewSuperCallReference(int pos);
Expression* NewTargetExpression(int pos);
Expression* FunctionSentExpression(int pos);
+ Expression* ImportMetaExpression(int pos);
Literal* ExpressionFromLiteral(Token::Value token, int pos);
@@ -995,7 +990,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return function_state_->GetReportedErrorList();
}
- V8_INLINE ZoneList<Expression*>* GetNonPatternList() const {
+ V8_INLINE ZoneList<RewritableExpression*>* GetNonPatternList() const {
return function_state_->non_patterns_to_rewrite();
}
@@ -1009,6 +1004,32 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return parameters_end_pos_ != kNoSourcePosition;
}
+ V8_INLINE void ConvertBinaryToNaryOperationSourceRange(
+ BinaryOperation* binary_op, NaryOperation* nary_op) {
+ if (source_range_map_ == nullptr) return;
+ DCHECK_NULL(source_range_map_->Find(nary_op));
+
+ BinaryOperationSourceRanges* ranges =
+ static_cast<BinaryOperationSourceRanges*>(
+ source_range_map_->Find(binary_op));
+ if (ranges == nullptr) return;
+
+ SourceRange range = ranges->GetRange(SourceRangeKind::kRight);
+ source_range_map_->Insert(
+ nary_op, new (zone()) NaryOperationSourceRanges(zone(), range));
+ }
+
+ V8_INLINE void AppendNaryOperationSourceRange(NaryOperation* node,
+ const SourceRange& range) {
+ if (source_range_map_ == nullptr) return;
+ NaryOperationSourceRanges* ranges =
+ static_cast<NaryOperationSourceRanges*>(source_range_map_->Find(node));
+ if (ranges == nullptr) return;
+
+ ranges->AddRange(range);
+ DCHECK_EQ(node->subsequent_length(), ranges->RangeCount());
+ }
+
V8_INLINE void RecordBlockSourceRange(Block* node,
int32_t continuation_position) {
if (source_range_map_ == nullptr) return;
@@ -1032,6 +1053,14 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
new (zone()) ConditionalSourceRanges(then_range, else_range));
}
+ V8_INLINE void RecordBinaryOperationSourceRange(
+ Expression* node, const SourceRange& right_range) {
+ if (source_range_map_ == nullptr) return;
+ source_range_map_->Insert(node->AsBinaryOperation(),
+ new (zone())
+ BinaryOperationSourceRanges(right_range));
+ }
+
V8_INLINE void RecordJumpStatementSourceRange(Statement* node,
int32_t continuation_position) {
if (source_range_map_ == nullptr) return;
@@ -1113,8 +1142,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
ScriptCompiler::CompileOptions compile_options_;
ParseData* cached_parse_data_;
- PendingCompilationErrorHandler pending_error_handler_;
-
// Other information which will be stored in Parser and moved to Isolate after
// parsing.
int use_counts_[v8::Isolate::kUseCounterFeatureCount];