Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
| 6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/base/compiler-specific.h" | 10 #include "src/base/compiler-specific.h" |
| 11 #include "src/globals.h" | 11 #include "src/globals.h" |
| 12 #include "src/parsing/parser-base.h" | 12 #include "src/parsing/parser-base.h" |
| 13 #include "src/parsing/preparse-data-format.h" | 13 #include "src/parsing/preparse-data-format.h" |
| 14 #include "src/parsing/preparse-data.h" | 14 #include "src/parsing/preparse-data.h" |
| 15 #include "src/parsing/preparser.h" | 15 #include "src/parsing/preparser.h" |
| 16 #include "src/pending-compilation-error-handler.h" | 16 #include "src/pending-compilation-error-handler.h" |
| 17 #include "src/utils.h" | |
| 17 | 18 |
| 18 namespace v8 { | 19 namespace v8 { |
| 19 | 20 |
| 20 class ScriptCompiler; | 21 class ScriptCompiler; |
| 21 | 22 |
| 22 namespace internal { | 23 namespace internal { |
| 23 | 24 |
| 24 class ParseInfo; | 25 class ParseInfo; |
| 25 class ScriptData; | 26 class ScriptData; |
| 26 class ParserTarget; | 27 class ParserTarget; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 DISALLOW_COPY_AND_ASSIGN(ParseData); | 129 DISALLOW_COPY_AND_ASSIGN(ParseData); |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 // ---------------------------------------------------------------------------- | 132 // ---------------------------------------------------------------------------- |
| 132 // JAVASCRIPT PARSING | 133 // JAVASCRIPT PARSING |
| 133 | 134 |
| 134 class Parser; | 135 class Parser; |
| 135 | 136 |
| 136 | 137 |
| 137 struct ParserFormalParameters : FormalParametersBase { | 138 struct ParserFormalParameters : FormalParametersBase { |
| 138 struct Parameter { | 139 struct Parameter : public ZoneObject { |
| 139 Parameter(const AstRawString* name, Expression* pattern, | 140 Parameter(const AstRawString* name, Expression* pattern, |
| 140 Expression* initializer, int initializer_end_position, | 141 Expression* initializer, int initializer_end_position, |
| 141 bool is_rest) | 142 bool is_rest) |
| 142 : name(name), | 143 : name(name), |
| 143 pattern(pattern), | 144 pattern(pattern), |
| 144 initializer(initializer), | 145 initializer(initializer), |
| 145 initializer_end_position(initializer_end_position), | 146 initializer_end_position(initializer_end_position), |
| 146 is_rest(is_rest) {} | 147 is_rest(is_rest) {} |
| 147 const AstRawString* name; | 148 const AstRawString* name; |
| 148 Expression* pattern; | 149 Expression* pattern; |
| 149 Expression* initializer; | 150 Expression* initializer; |
| 150 int initializer_end_position; | 151 int initializer_end_position; |
| 151 bool is_rest; | 152 bool is_rest; |
| 153 Parameter* next_parameter = nullptr; | |
| 152 bool is_simple() const { | 154 bool is_simple() const { |
| 153 return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; | 155 return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; |
| 154 } | 156 } |
| 157 Parameter** next() { return &next_parameter; } | |
| 158 Parameter* const* next() const { return &next_parameter; } | |
| 155 }; | 159 }; |
| 156 | 160 |
| 157 explicit ParserFormalParameters(DeclarationScope* scope) | 161 explicit ParserFormalParameters(DeclarationScope* scope) |
| 158 : FormalParametersBase(scope), params(4, scope->zone()) {} | 162 : FormalParametersBase(scope) {} |
| 159 ZoneList<Parameter> params; | 163 ThreadedList<Parameter> params; |
|
Toon Verwaest
2016/11/24 15:09:41
Oh my... it didn't use Parameter* ... good thing y
| |
| 160 | |
| 161 const Parameter& at(int i) const { return params[i]; } | |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 template <> | 166 template <> |
| 165 struct ParserTypes<Parser> { | 167 struct ParserTypes<Parser> { |
| 166 typedef ParserBase<Parser> Base; | 168 typedef ParserBase<Parser> Base; |
| 167 typedef Parser Impl; | 169 typedef Parser Impl; |
| 168 | 170 |
| 169 typedef v8::internal::Variable Variable; | 171 typedef v8::internal::Variable Variable; |
| 170 | 172 |
| 171 // Return types for traversing functions. | 173 // Return types for traversing functions. |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 1038 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
| 1037 Expression* pattern, | 1039 Expression* pattern, |
| 1038 Expression* initializer, | 1040 Expression* initializer, |
| 1039 int initializer_end_position, | 1041 int initializer_end_position, |
| 1040 bool is_rest) { | 1042 bool is_rest) { |
| 1041 parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest); | 1043 parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest); |
| 1042 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; | 1044 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; |
| 1043 const AstRawString* name = is_simple | 1045 const AstRawString* name = is_simple |
| 1044 ? pattern->AsVariableProxy()->raw_name() | 1046 ? pattern->AsVariableProxy()->raw_name() |
| 1045 : ast_value_factory()->empty_string(); | 1047 : ast_value_factory()->empty_string(); |
| 1046 parameters->params.Add( | 1048 auto parameter = |
| 1047 ParserFormalParameters::Parameter(name, pattern, initializer, | 1049 new (parameters->scope->zone()) ParserFormalParameters::Parameter( |
| 1048 initializer_end_position, is_rest), | 1050 name, pattern, initializer, initializer_end_position, is_rest); |
| 1049 parameters->scope->zone()); | 1051 |
| 1052 parameters->params.Add(parameter); | |
| 1050 } | 1053 } |
| 1051 | 1054 |
| 1052 V8_INLINE void DeclareFormalParameter( | 1055 V8_INLINE void DeclareFormalParameters( |
| 1053 DeclarationScope* scope, | 1056 DeclarationScope* scope, |
| 1054 const ParserFormalParameters::Parameter& parameter) { | 1057 const ThreadedList<ParserFormalParameters::Parameter>& parameters) { |
| 1055 bool is_duplicate = false; | 1058 for (auto parameter : parameters) { |
| 1056 bool is_simple = classifier()->is_simple_parameter_list(); | 1059 bool is_duplicate = false; |
| 1057 auto name = is_simple || parameter.is_rest | 1060 bool is_simple = classifier()->is_simple_parameter_list(); |
| 1058 ? parameter.name | 1061 auto name = is_simple || parameter->is_rest |
| 1059 : ast_value_factory()->empty_string(); | 1062 ? parameter->name |
| 1060 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | 1063 : ast_value_factory()->empty_string(); |
| 1061 if (!is_simple) scope->SetHasNonSimpleParameters(); | 1064 auto mode = is_simple || parameter->is_rest ? VAR : TEMPORARY; |
| 1062 bool is_optional = parameter.initializer != nullptr; | 1065 if (!is_simple) scope->SetHasNonSimpleParameters(); |
| 1063 Variable* var = | 1066 bool is_optional = parameter->initializer != nullptr; |
| 1064 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest, | 1067 Variable* var = |
| 1065 &is_duplicate, ast_value_factory()); | 1068 scope->DeclareParameter(name, mode, is_optional, parameter->is_rest, |
| 1066 if (is_duplicate) { | 1069 &is_duplicate, ast_value_factory()); |
| 1067 classifier()->RecordDuplicateFormalParameterError(scanner()->location()); | 1070 if (is_duplicate && |
| 1068 } | 1071 classifier()->is_valid_formal_parameter_list_without_duplicates()) { |
| 1069 if (is_sloppy(scope->language_mode())) { | 1072 classifier()->RecordDuplicateFormalParameterError( |
| 1070 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1073 scanner()->location()); |
| 1071 // conservative approximation necessary to account for parameters | 1074 } |
| 1072 // that are assigned via the arguments array. | 1075 if (is_sloppy(scope->language_mode())) { |
| 1073 var->set_maybe_assigned(); | 1076 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 1077 // conservative approximation necessary to account for parameters | |
| 1078 // that are assigned via the arguments array. | |
| 1079 var->set_maybe_assigned(); | |
| 1080 } | |
| 1074 } | 1081 } |
| 1075 } | 1082 } |
| 1076 | 1083 |
| 1077 void DeclareArrowFunctionFormalParameters(ParserFormalParameters* parameters, | 1084 void DeclareArrowFunctionFormalParameters(ParserFormalParameters* parameters, |
| 1078 Expression* params, | 1085 Expression* params, |
| 1079 const Scanner::Location& params_loc, | 1086 const Scanner::Location& params_loc, |
| 1080 Scanner::Location* duplicate_loc, | 1087 Scanner::Location* duplicate_loc, |
| 1081 bool* ok); | 1088 bool* ok); |
| 1082 | 1089 |
| 1083 void ReindexLiterals(const ParserFormalParameters& parameters); | 1090 void ReindexLiterals(const ParserFormalParameters& parameters); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1179 | 1186 |
| 1180 private: | 1187 private: |
| 1181 ParserTarget** variable_; | 1188 ParserTarget** variable_; |
| 1182 ParserTarget* previous_; | 1189 ParserTarget* previous_; |
| 1183 }; | 1190 }; |
| 1184 | 1191 |
| 1185 } // namespace internal | 1192 } // namespace internal |
| 1186 } // namespace v8 | 1193 } // namespace v8 |
| 1187 | 1194 |
| 1188 #endif // V8_PARSING_PARSER_H_ | 1195 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |