Chromium Code Reviews| Index: src/parsing/preparser.h |
| diff --git a/src/parsing/preparser.h b/src/parsing/preparser.h |
| index ef60b3d4d3be418bfdcfcfed9cd71de289832370..b33ad3f345b1bc2406e4b688e45b9edefb09b142 100644 |
| --- a/src/parsing/preparser.h |
| +++ b/src/parsing/preparser.h |
| @@ -5,6 +5,7 @@ |
| #ifndef V8_PARSING_PREPARSER_H |
| #define V8_PARSING_PREPARSER_H |
| +#include "src/ast/ast.h" |
|
Toon Verwaest
2016/12/01 13:34:08
Should we split out VariableProxy into a separate
marja
2016/12/06 14:50:05
It won't help here since we need to call AstNodeFa
|
| #include "src/ast/scopes.h" |
| #include "src/parsing/parser-base.h" |
| @@ -125,25 +126,26 @@ class PreParserIdentifier { |
| class PreParserExpression { |
| public: |
| PreParserExpression() |
| - : code_(TypeField::encode(kEmpty)), identifiers_(nullptr) {} |
| + : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} |
| static PreParserExpression Empty() { return PreParserExpression(); } |
| static PreParserExpression Default( |
| - ZoneList<const AstRawString*>* identifiers = nullptr) { |
| - return PreParserExpression(TypeField::encode(kExpression), identifiers); |
| + ZoneList<VariableProxy*>* variables = nullptr) { |
| + return PreParserExpression(TypeField::encode(kExpression), variables); |
| } |
| static PreParserExpression Spread(PreParserExpression expression) { |
| return PreParserExpression(TypeField::encode(kSpreadExpression), |
| - expression.identifiers_); |
| + expression.variables_); |
| } |
| static PreParserExpression FromIdentifier(PreParserIdentifier id, |
| + VariableProxy* variable, |
| Zone* zone) { |
| PreParserExpression expression(TypeField::encode(kIdentifierExpression) | |
| IdentifierTypeField::encode(id.type_)); |
| - expression.AddIdentifier(id.string_, zone); |
| + expression.AddVariable(variable, zone); |
| return expression; |
| } |
| @@ -154,22 +156,22 @@ class PreParserExpression { |
| } |
| static PreParserExpression Assignment( |
| - ZoneList<const AstRawString*>* identifiers = nullptr) { |
| + ZoneList<VariableProxy*>* variables = nullptr) { |
| return PreParserExpression(TypeField::encode(kExpression) | |
| ExpressionTypeField::encode(kAssignment), |
| - identifiers); |
| + variables); |
| } |
| static PreParserExpression ObjectLiteral( |
| - ZoneList<const AstRawString*>* identifiers = nullptr) { |
| + ZoneList<VariableProxy*>* variables = nullptr) { |
| return PreParserExpression(TypeField::encode(kObjectLiteralExpression), |
| - identifiers); |
| + variables); |
| } |
| static PreParserExpression ArrayLiteral( |
| - ZoneList<const AstRawString*>* identifiers = nullptr) { |
| + ZoneList<VariableProxy*>* variables = nullptr) { |
| return PreParserExpression(TypeField::encode(kArrayLiteralExpression), |
| - identifiers); |
| + variables); |
| } |
| static PreParserExpression StringLiteral() { |
| @@ -346,19 +348,18 @@ class PreParserExpression { |
| kAssignment |
| }; |
| - explicit PreParserExpression( |
| - uint32_t expression_code, |
| - ZoneList<const AstRawString*>* identifiers = nullptr) |
| - : code_(expression_code), identifiers_(identifiers) {} |
| + explicit PreParserExpression(uint32_t expression_code, |
| + ZoneList<VariableProxy*>* variables = nullptr) |
| + : code_(expression_code), variables_(variables) {} |
| - void AddIdentifier(const AstRawString* identifier, Zone* zone) { |
| - if (identifier == nullptr) { |
| + void AddVariable(VariableProxy* variable, Zone* zone) { |
| + if (variable == nullptr) { |
| return; |
| } |
| - if (identifiers_ == nullptr) { |
| - identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); |
| + if (variables_ == nullptr) { |
| + variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
| } |
| - identifiers_->Add(identifier, zone); |
| + variables_->Add(variable, zone); |
| } |
| // The first three bits are for the Type. |
| @@ -381,9 +382,9 @@ class PreParserExpression { |
| typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; |
| uint32_t code_; |
| - // If the PreParser is used in the identifier tracking mode, |
| - // PreParserExpression accumulates identifiers in that expression. |
| - ZoneList<const AstRawString*>* identifiers_; |
| + // If the PreParser is used in the variable tracking mode, PreParserExpression |
| + // accumulates variables in that expression. |
| + ZoneList<VariableProxy*>* variables_; |
| friend class PreParser; |
| friend class PreParserFactory; |
| @@ -393,13 +394,13 @@ class PreParserExpression { |
| // The pre-parser doesn't need to build lists of expressions, identifiers, or |
| -// the like. If the PreParser is used in identifier tracking mode, it needs to |
| -// build lists of identifiers though. |
| +// the like. If the PreParser is used in variable tracking mode, it needs to |
| +// build lists of variables though. |
| template <typename T> |
| class PreParserList { |
| public: |
| // These functions make list->Add(some_expression) work (and do nothing). |
| - PreParserList() : length_(0), identifiers_(nullptr) {} |
| + PreParserList() : length_(0), variables_(nullptr) {} |
| PreParserList* operator->() { return this; } |
| void Add(T, Zone* zone); |
| int length() const { return length_; } |
| @@ -407,9 +408,9 @@ class PreParserList { |
| bool IsNull() const { return length_ == -1; } |
| private: |
| - explicit PreParserList(int n) : length_(n), identifiers_(nullptr) {} |
| + explicit PreParserList(int n) : length_(n), variables_(nullptr) {} |
| int length_; |
| - ZoneList<const AstRawString*>* identifiers_; |
| + ZoneList<VariableProxy*>* variables_; |
| friend class PreParser; |
| friend class PreParserFactory; |
| @@ -418,14 +419,14 @@ class PreParserList { |
| template <> |
| inline void PreParserList<PreParserExpression>::Add( |
| PreParserExpression expression, Zone* zone) { |
| - if (expression.identifiers_ != nullptr) { |
| + if (expression.variables_ != nullptr) { |
| DCHECK(FLAG_lazy_inner_functions); |
| DCHECK(zone != nullptr); |
| - if (identifiers_ == nullptr) { |
| - identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); |
| + if (variables_ == nullptr) { |
| + variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
| } |
| - for (auto identifier : (*expression.identifiers_)) { |
| - identifiers_->Add(identifier, zone); |
| + for (auto identifier : (*expression.variables_)) { |
| + variables_->Add(identifier, zone); |
| } |
| } |
| ++length_; |
| @@ -524,7 +525,8 @@ class PreParserStatement { |
| class PreParserFactory { |
| public: |
| explicit PreParserFactory(AstValueFactory* ast_value_factory) |
| - : zone_(ast_value_factory->zone()) {} |
| + : ast_value_factory_(ast_value_factory), |
| + zone_(ast_value_factory->zone()) {} |
| void set_zone(Zone* zone) { zone_ = zone; } |
| @@ -533,7 +535,14 @@ class PreParserFactory { |
| // This is needed for object literal property names. Property names are |
| // normalized to string literals during object literal parsing. |
| PreParserExpression expression = PreParserExpression::Default(); |
| - expression.AddIdentifier(identifier.string_, zone_); |
| + if (identifier.string_ != nullptr) { |
| + DCHECK(FLAG_lazy_inner_functions); |
| + AstNodeFactory factory(ast_value_factory_); |
| + factory.set_zone(zone_); |
| + VariableProxy* variable = |
| + factory.NewVariableProxy(identifier.string_, NORMAL_VARIABLE); |
| + expression.AddVariable(variable, zone_); |
| + } |
| return expression; |
| } |
| PreParserExpression NewNumberLiteral(double number, |
| @@ -551,7 +560,7 @@ class PreParserFactory { |
| PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| int first_spread_index, int literal_index, |
| int pos) { |
| - return PreParserExpression::ArrayLiteral(values.identifiers_); |
| + return PreParserExpression::ArrayLiteral(values.variables_); |
| } |
| PreParserExpression NewClassLiteralProperty(PreParserExpression key, |
| PreParserExpression value, |
| @@ -564,18 +573,18 @@ class PreParserFactory { |
| PreParserExpression value, |
| ObjectLiteralProperty::Kind kind, |
| bool is_computed_name) { |
| - return PreParserExpression::Default(value.identifiers_); |
| + return PreParserExpression::Default(value.variables_); |
| } |
| PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| PreParserExpression value, |
| bool is_computed_name) { |
| - return PreParserExpression::Default(value.identifiers_); |
| + return PreParserExpression::Default(value.variables_); |
| } |
| PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
| int literal_index, |
| int boilerplate_properties, |
| int pos) { |
| - return PreParserExpression::ObjectLiteral(properties.identifiers_); |
| + return PreParserExpression::ObjectLiteral(properties.variables_); |
| } |
| PreParserExpression NewVariableProxy(void* variable) { |
| return PreParserExpression::Default(); |
| @@ -610,8 +619,8 @@ class PreParserFactory { |
| PreParserExpression left, |
| PreParserExpression right, |
| int pos) { |
| - // For tracking identifiers for parameters with a default value. |
| - return PreParserExpression::Assignment(left.identifiers_); |
| + // For tracking variables for parameters with a default value. |
| + return PreParserExpression::Assignment(left.variables_); |
| } |
| PreParserExpression NewYield(PreParserExpression generator_object, |
| PreParserExpression expression, int pos, |
| @@ -748,6 +757,7 @@ class PreParserFactory { |
| } |
| private: |
| + AstValueFactory* ast_value_factory_; |
| Zone* zone_; |
| }; |
| @@ -1235,10 +1245,16 @@ class PreParser : public ParserBase<PreParser> { |
| V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
| PreParserExpression left, PreParserExpression right) {} |
| - V8_INLINE static void MarkExpressionAsAssigned( |
| - PreParserExpression expression) { |
| + V8_INLINE void MarkExpressionAsAssigned(PreParserExpression expression) { |
| // TODO(marja): To be able to produce the same errors, the preparser needs |
| // to start tracking which expressions are variables and which are assigned. |
| + if (expression.variables_ != nullptr) { |
|
Toon Verwaest
2016/12/01 13:34:08
This is still broken I think since it's broken in
marja
2016/12/06 14:50:05
Hmm, what do you mean?
|
| + DCHECK(FLAG_lazy_inner_functions); |
| + DCHECK(track_unresolved_variables_); |
| + for (auto variable : *expression.variables_) { |
| + variable->set_is_assigned(); |
| + } |
| + } |
| } |
| V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
| @@ -1485,11 +1501,11 @@ class PreParser : public ParserBase<PreParser> { |
| DCHECK(FLAG_lazy_inner_functions); |
| bool is_simple = pattern.IsIdentifier() && IsEmptyExpression(initializer); |
| if (is_simple) { |
| - DCHECK_EQ(1, pattern.identifiers_->length()); |
| + DCHECK_EQ(1, pattern.variables_->length()); |
| parameters->params.Add( |
| new (zone()) PreParserFormalParameters::Parameter( |
| - (*pattern.identifiers_)[0], !IsEmptyExpression(initializer), |
| - is_rest)); |
| + (*pattern.variables_)[0]->raw_name(), |
| + !IsEmptyExpression(initializer), is_rest)); |
| } else { |
| parameters->params.Add( |
| new (zone()) PreParserFormalParameters::Parameter( |
| @@ -1515,10 +1531,10 @@ class PreParser : public ParserBase<PreParser> { |
| parameter->is_rest, &is_duplicate, |
| ast_value_factory()); |
| } |
| - if (parameter->pattern.identifiers_ != nullptr) { |
| + if (parameter->pattern.variables_ != nullptr) { |
| DCHECK(FLAG_lazy_inner_functions); |
| - for (auto i : *parameter->pattern.identifiers_) { |
| - scope->DeclareVariableName(i, VAR); |
| + for (auto i : *parameter->pattern.variables_) { |
| + scope->DeclareVariableName(i->raw_name(), VAR); |
| } |
| } |
| } |
| @@ -1554,7 +1570,7 @@ class PreParser : public ParserBase<PreParser> { |
| V8_INLINE PreParserExpression |
| ExpressionListToExpression(PreParserExpressionList args) { |
| - return PreParserExpression::Default(args.identifiers_); |
| + return PreParserExpression::Default(args.variables_); |
| } |
| V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, |