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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 unsigned ParseData::Version() { | 160 unsigned ParseData::Version() { |
161 return Data()[PreparseDataConstants::kVersionOffset]; | 161 return Data()[PreparseDataConstants::kVersionOffset]; |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 int ParseData::FunctionsSize() { | 165 int ParseData::FunctionsSize() { |
166 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]); | 166 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]); |
167 } | 167 } |
168 | 168 |
| 169 // Helper for putting parts of the parse results into a temporary zone when |
| 170 // parsing inner function bodies. |
| 171 class DiscardableZoneScope { |
| 172 public: |
| 173 DiscardableZoneScope(Parser* parser, Zone* temp_zone, bool use_temp_zone) |
| 174 : ast_node_factory_scope_(parser->factory(), temp_zone, use_temp_zone), |
| 175 fni_(parser->ast_value_factory_, temp_zone), |
| 176 parser_(parser), |
| 177 prev_fni_(parser->fni_) { |
| 178 if (use_temp_zone) { |
| 179 parser_->fni_ = &fni_; |
| 180 } |
| 181 } |
| 182 ~DiscardableZoneScope() { parser_->fni_ = prev_fni_; } |
| 183 |
| 184 private: |
| 185 AstNodeFactory::BodyScope ast_node_factory_scope_; |
| 186 FuncNameInferrer fni_; |
| 187 Parser* parser_; |
| 188 FuncNameInferrer* prev_fni_; |
| 189 }; |
169 | 190 |
170 void Parser::SetCachedData(ParseInfo* info) { | 191 void Parser::SetCachedData(ParseInfo* info) { |
171 if (compile_options_ == ScriptCompiler::kNoCompileOptions) { | 192 if (compile_options_ == ScriptCompiler::kNoCompileOptions) { |
172 cached_parse_data_ = NULL; | 193 cached_parse_data_ = NULL; |
173 } else { | 194 } else { |
174 DCHECK(info->cached_data() != NULL); | 195 DCHECK(info->cached_data() != NULL); |
175 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { | 196 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { |
176 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); | 197 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); |
177 } | 198 } |
178 } | 199 } |
(...skipping 4234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4413 // FunctionExpression; even without enclosing parentheses it might be | 4434 // FunctionExpression; even without enclosing parentheses it might be |
4414 // immediately invoked. | 4435 // immediately invoked. |
4415 // - The function literal shouldn't be hinted to eagerly compile. | 4436 // - The function literal shouldn't be hinted to eagerly compile. |
4416 // - For asm.js functions the body needs to be available when module | 4437 // - For asm.js functions the body needs to be available when module |
4417 // validation is active, because we examine the entire module at once. | 4438 // validation is active, because we examine the entire module at once. |
4418 bool use_temp_zone = | 4439 bool use_temp_zone = |
4419 FLAG_lazy && !allow_natives() && extension_ == NULL && allow_lazy() && | 4440 FLAG_lazy && !allow_natives() && extension_ == NULL && allow_lazy() && |
4420 function_type == FunctionLiteral::kDeclaration && | 4441 function_type == FunctionLiteral::kDeclaration && |
4421 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && | 4442 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && |
4422 !(FLAG_validate_asm && scope->asm_function()); | 4443 !(FLAG_validate_asm && scope->asm_function()); |
4423 // Open a new BodyScope, which sets our AstNodeFactory to allocate in the | 4444 // Open a new zone scope, which sets our AstNodeFactory to allocate in the |
4424 // new temporary zone if the preconditions are satisfied, and ensures that | 4445 // new temporary zone if the preconditions are satisfied, and ensures that |
4425 // the previous zone is always restored after parsing the body. | 4446 // the previous zone is always restored after parsing the body. |
4426 // For the purpose of scope analysis, some ZoneObjects allocated by the | 4447 // For the purpose of scope analysis, some ZoneObjects allocated by the |
4427 // factory must persist after the function body is thrown away and | 4448 // factory must persist after the function body is thrown away and |
4428 // temp_zone is deallocated. These objects are instead allocated in a | 4449 // temp_zone is deallocated. These objects are instead allocated in a |
4429 // parser-persistent zone (see parser_zone_ in AstNodeFactory). | 4450 // parser-persistent zone (see parser_zone_ in AstNodeFactory). |
4430 { | 4451 { |
4431 Zone temp_zone(zone()->allocator()); | 4452 Zone temp_zone(zone()->allocator()); |
4432 AstNodeFactory::BodyScope inner(factory(), &temp_zone, use_temp_zone); | 4453 DiscardableZoneScope(this, &temp_zone, use_temp_zone); |
4433 | |
4434 body = ParseEagerFunctionBody(function_name, pos, formals, kind, | 4454 body = ParseEagerFunctionBody(function_name, pos, formals, kind, |
4435 function_type, CHECK_OK); | 4455 function_type, CHECK_OK); |
4436 } | 4456 } |
4437 materialized_literal_count = function_state.materialized_literal_count(); | 4457 materialized_literal_count = function_state.materialized_literal_count(); |
4438 expected_property_count = function_state.expected_property_count(); | 4458 expected_property_count = function_state.expected_property_count(); |
4439 if (use_temp_zone) { | 4459 if (use_temp_zone) { |
4440 // If the preconditions are correct the function body should never be | 4460 // If the preconditions are correct the function body should never be |
4441 // accessed, but do this anyway for better behaviour if they're wrong. | 4461 // accessed, but do this anyway for better behaviour if they're wrong. |
4442 body = NULL; | 4462 body = NULL; |
4443 } | 4463 } |
(...skipping 2618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7062 | 7082 |
7063 #ifdef DEBUG | 7083 #ifdef DEBUG |
7064 void Parser::Print(AstNode* node) { | 7084 void Parser::Print(AstNode* node) { |
7065 ast_value_factory()->Internalize(Isolate::Current()); | 7085 ast_value_factory()->Internalize(Isolate::Current()); |
7066 node->Print(Isolate::Current()); | 7086 node->Print(Isolate::Current()); |
7067 } | 7087 } |
7068 #endif // DEBUG | 7088 #endif // DEBUG |
7069 | 7089 |
7070 } // namespace internal | 7090 } // namespace internal |
7071 } // namespace v8 | 7091 } // namespace v8 |
OLD | NEW |