Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/parser.cc

Issue 868883002: Remove the dependency of Zone on Isolate (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: All platforms Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 DCHECK(info_->cached_data() != NULL); 258 DCHECK(info_->cached_data() != NULL);
259 if (compile_options() == ScriptCompiler::kConsumeParserCache) { 259 if (compile_options() == ScriptCompiler::kConsumeParserCache) {
260 cached_parse_data_ = ParseData::FromCachedData(*info_->cached_data()); 260 cached_parse_data_ = ParseData::FromCachedData(*info_->cached_data());
261 } 261 }
262 } 262 }
263 } 263 }
264 264
265 265
266 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 266 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
267 DCHECK(ast_value_factory()); 267 DCHECK(ast_value_factory());
268 Scope* result = 268 Scope* result = new (zone())
269 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone()); 269 Scope(isolate(), zone(), parent, scope_type, ast_value_factory());
270 result->Initialize(); 270 result->Initialize();
271 return result; 271 return result;
272 } 272 }
273 273
274 274
275 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, 275 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
276 int pos, int end_pos) { 276 int pos, int end_pos) {
277 int materialized_literal_count = -1; 277 int materialized_literal_count = -1;
278 int expected_property_count = -1; 278 int expected_property_count = -1;
279 int handler_count = 0; 279 int handler_count = 0;
280 int parameter_count = 0; 280 int parameter_count = 0;
281 const AstRawString* name = ast_value_factory()->empty_string(); 281 const AstRawString* name = ast_value_factory()->empty_string();
282 282
283 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); 283 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE);
284 function_scope->SetStrictMode(STRICT); 284 function_scope->SetStrictMode(STRICT);
285 // Set start and end position to the same value 285 // Set start and end position to the same value
286 function_scope->set_start_position(pos); 286 function_scope->set_start_position(pos);
287 function_scope->set_end_position(pos); 287 function_scope->set_end_position(pos);
288 ZoneList<Statement*>* body = NULL; 288 ZoneList<Statement*>* body = NULL;
289 289
290 { 290 {
291 AstNodeFactory function_factory(ast_value_factory()); 291 AstNodeFactory function_factory(isolate(), ast_value_factory());
292 FunctionState function_state(&function_state_, &scope_, function_scope, 292 FunctionState function_state(&function_state_, &scope_, function_scope,
293 &function_factory); 293 &function_factory);
294 294
295 body = new (zone()) ZoneList<Statement*>(1, zone()); 295 body = new (zone()) ZoneList<Statement*>(1, zone());
296 if (call_super) { 296 if (call_super) {
297 ZoneList<Expression*>* args = 297 ZoneList<Expression*>* args =
298 new (zone()) ZoneList<Expression*>(0, zone()); 298 new (zone()) ZoneList<Expression*>(0, zone());
299 CallRuntime* call = factory()->NewCallRuntime( 299 CallRuntime* call = factory()->NewCallRuntime(
300 ast_value_factory()->empty_string(), 300 ast_value_factory()->empty_string(),
301 Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args, 301 Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args,
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 771
772 ClassLiteral* ParserTraits::ParseClassLiteral( 772 ClassLiteral* ParserTraits::ParseClassLiteral(
773 const AstRawString* name, Scanner::Location class_name_location, 773 const AstRawString* name, Scanner::Location class_name_location,
774 bool name_is_strict_reserved, int pos, bool* ok) { 774 bool name_is_strict_reserved, int pos, bool* ok) {
775 return parser_->ParseClassLiteral(name, class_name_location, 775 return parser_->ParseClassLiteral(name, class_name_location,
776 name_is_strict_reserved, pos, ok); 776 name_is_strict_reserved, pos, ok);
777 } 777 }
778 778
779 779
780 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) 780 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
781 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, 781 : ParserBase<ParserTraits>(info->isolate(), info->zone(), &scanner_,
782 info->extension(), NULL, info->zone(), this), 782 parse_info->stack_limit, info->extension(), NULL,
783 this),
783 scanner_(parse_info->unicode_cache), 784 scanner_(parse_info->unicode_cache),
784 reusable_preparser_(NULL), 785 reusable_preparser_(NULL),
785 original_scope_(NULL), 786 original_scope_(NULL),
786 target_stack_(NULL), 787 target_stack_(NULL),
787 cached_parse_data_(NULL), 788 cached_parse_data_(NULL),
788 info_(info), 789 info_(info),
789 has_pending_error_(false), 790 has_pending_error_(false),
790 pending_error_message_(NULL), 791 pending_error_message_(NULL),
791 pending_error_arg_(NULL), 792 pending_error_arg_(NULL),
792 pending_error_char_arg_(NULL), 793 pending_error_char_arg_(NULL),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope, 891 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope,
891 Scope** eval_scope) { 892 Scope** eval_scope) {
892 DCHECK(scope_ == NULL); 893 DCHECK(scope_ == NULL);
893 DCHECK(target_stack_ == NULL); 894 DCHECK(target_stack_ == NULL);
894 895
895 FunctionLiteral* result = NULL; 896 FunctionLiteral* result = NULL;
896 { 897 {
897 *scope = NewScope(scope_, SCRIPT_SCOPE); 898 *scope = NewScope(scope_, SCRIPT_SCOPE);
898 info->SetScriptScope(*scope); 899 info->SetScriptScope(*scope);
899 if (!info->context().is_null() && !info->context()->IsNativeContext()) { 900 if (!info->context().is_null() && !info->context()->IsNativeContext()) {
900 *scope = Scope::DeserializeScopeChain(*info->context(), *scope, zone()); 901 *scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
902 *info->context(), *scope);
901 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this 903 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
902 // means the Parser cannot operate independent of the V8 heap. Tell the 904 // means the Parser cannot operate independent of the V8 heap. Tell the
903 // string table to internalize strings and values right after they're 905 // string table to internalize strings and values right after they're
904 // created. 906 // created.
905 ast_value_factory()->Internalize(isolate()); 907 ast_value_factory()->Internalize(isolate());
906 } 908 }
907 original_scope_ = *scope; 909 original_scope_ = *scope;
908 if (info->is_eval()) { 910 if (info->is_eval()) {
909 if (!(*scope)->is_script_scope() || info->strict_mode() == STRICT) { 911 if (!(*scope)->is_script_scope() || info->strict_mode() == STRICT) {
910 *scope = NewScope(*scope, EVAL_SCOPE); 912 *scope = NewScope(*scope, EVAL_SCOPE);
911 } 913 }
912 } else if (info->is_global()) { 914 } else if (info->is_global()) {
913 *scope = NewScope(*scope, SCRIPT_SCOPE); 915 *scope = NewScope(*scope, SCRIPT_SCOPE);
914 } 916 }
915 (*scope)->set_start_position(0); 917 (*scope)->set_start_position(0);
916 // End position will be set by the caller. 918 // End position will be set by the caller.
917 919
918 // Compute the parsing mode. 920 // Compute the parsing mode.
919 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 921 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
920 if (allow_natives() || extension_ != NULL || 922 if (allow_natives() || extension_ != NULL ||
921 (*scope)->is_eval_scope()) { 923 (*scope)->is_eval_scope()) {
922 mode = PARSE_EAGERLY; 924 mode = PARSE_EAGERLY;
923 } 925 }
924 ParsingModeScope parsing_mode(this, mode); 926 ParsingModeScope parsing_mode(this, mode);
925 927
926 // Enters 'scope'. 928 // Enters 'scope'.
927 AstNodeFactory function_factory(ast_value_factory()); 929 AstNodeFactory function_factory(isolate(), ast_value_factory());
928 FunctionState function_state(&function_state_, &scope_, *scope, 930 FunctionState function_state(&function_state_, &scope_, *scope,
929 &function_factory); 931 &function_factory);
930 932
931 scope_->SetStrictMode(info->strict_mode()); 933 scope_->SetStrictMode(info->strict_mode());
932 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 934 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
933 bool ok = true; 935 bool ok = true;
934 int beg_pos = scanner()->location().beg_pos; 936 int beg_pos = scanner()->location().beg_pos;
935 ParseSourceElements(body, Token::EOS, info->is_eval(), true, eval_scope, 937 ParseSourceElements(body, Token::EOS, info->is_eval(), true, eval_scope,
936 &ok); 938 &ok);
937 939
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1026 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1025 1027
1026 // Place holder for the result. 1028 // Place holder for the result.
1027 FunctionLiteral* result = NULL; 1029 FunctionLiteral* result = NULL;
1028 1030
1029 { 1031 {
1030 // Parse the function literal. 1032 // Parse the function literal.
1031 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); 1033 Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
1032 info()->SetScriptScope(scope); 1034 info()->SetScriptScope(scope);
1033 if (!info()->closure().is_null()) { 1035 if (!info()->closure().is_null()) {
1034 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 1036 scope = Scope::DeserializeScopeChain(isolate(), zone(),
1035 zone()); 1037 info()->closure()->context(), scope);
1036 } 1038 }
1037 original_scope_ = scope; 1039 original_scope_ = scope;
1038 AstNodeFactory function_factory(ast_value_factory()); 1040 AstNodeFactory function_factory(isolate(), ast_value_factory());
1039 FunctionState function_state(&function_state_, &scope_, scope, 1041 FunctionState function_state(&function_state_, &scope_, scope,
1040 &function_factory); 1042 &function_factory);
1041 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 1043 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
1042 DCHECK(info()->strict_mode() == shared_info->strict_mode()); 1044 DCHECK(info()->strict_mode() == shared_info->strict_mode());
1043 scope->SetStrictMode(shared_info->strict_mode()); 1045 scope->SetStrictMode(shared_info->strict_mode());
1044 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 1046 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
1045 ? (shared_info->is_anonymous() 1047 ? (shared_info->is_anonymous()
1046 ? FunctionLiteral::ANONYMOUS_EXPRESSION 1048 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1047 : FunctionLiteral::NAMED_EXPRESSION) 1049 : FunctionLiteral::NAMED_EXPRESSION)
1048 : FunctionLiteral::DECLARATION; 1050 : FunctionLiteral::DECLARATION;
(...skipping 2568 matching lines...) Expand 10 before | Expand all | Expand 10 after
3617 int materialized_literal_count = -1; 3619 int materialized_literal_count = -1;
3618 int expected_property_count = -1; 3620 int expected_property_count = -1;
3619 int handler_count = 0; 3621 int handler_count = 0;
3620 FunctionLiteral::ParameterFlag duplicate_parameters = 3622 FunctionLiteral::ParameterFlag duplicate_parameters =
3621 FunctionLiteral::kNoDuplicateParameters; 3623 FunctionLiteral::kNoDuplicateParameters;
3622 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3624 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3623 ? FunctionLiteral::kIsParenthesized 3625 ? FunctionLiteral::kIsParenthesized
3624 : FunctionLiteral::kNotParenthesized; 3626 : FunctionLiteral::kNotParenthesized;
3625 // Parse function body. 3627 // Parse function body.
3626 { 3628 {
3627 AstNodeFactory function_factory(ast_value_factory()); 3629 AstNodeFactory function_factory(isolate(), ast_value_factory());
3628 FunctionState function_state(&function_state_, &scope_, scope, 3630 FunctionState function_state(&function_state_, &scope_, scope,
3629 &function_factory); 3631 &function_factory);
3630 scope_->SetScopeName(function_name); 3632 scope_->SetScopeName(function_name);
3631 3633
3632 if (is_generator) { 3634 if (is_generator) {
3633 // For generators, allocating variables in contexts is currently a win 3635 // For generators, allocating variables in contexts is currently a win
3634 // because it minimizes the work needed to suspend and resume an 3636 // because it minimizes the work needed to suspend and resume an
3635 // activation. 3637 // activation.
3636 scope_->ForceContextAllocation(); 3638 scope_->ForceContextAllocation();
3637 3639
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
3934 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( 3936 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
3935 SingletonLogger* logger) { 3937 SingletonLogger* logger) {
3936 // This function may be called on a background thread too; record only the 3938 // This function may be called on a background thread too; record only the
3937 // main thread preparse times. 3939 // main thread preparse times.
3938 if (pre_parse_timer_ != NULL) { 3940 if (pre_parse_timer_ != NULL) {
3939 pre_parse_timer_->Start(); 3941 pre_parse_timer_->Start();
3940 } 3942 }
3941 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 3943 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
3942 3944
3943 if (reusable_preparser_ == NULL) { 3945 if (reusable_preparser_ == NULL) {
3944 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_); 3946 reusable_preparser_ =
3947 new PreParser(isolate(), &scanner_, NULL, stack_limit_);
3945 reusable_preparser_->set_allow_lazy(true); 3948 reusable_preparser_->set_allow_lazy(true);
3946 reusable_preparser_->set_allow_natives(allow_natives()); 3949 reusable_preparser_->set_allow_natives(allow_natives());
3947 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); 3950 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping());
3948 reusable_preparser_->set_allow_harmony_modules(allow_harmony_modules()); 3951 reusable_preparser_->set_allow_harmony_modules(allow_harmony_modules());
3949 reusable_preparser_->set_allow_harmony_arrow_functions( 3952 reusable_preparser_->set_allow_harmony_arrow_functions(
3950 allow_harmony_arrow_functions()); 3953 allow_harmony_arrow_functions());
3951 reusable_preparser_->set_allow_harmony_numeric_literals( 3954 reusable_preparser_->set_allow_harmony_numeric_literals(
3952 allow_harmony_numeric_literals()); 3955 allow_harmony_numeric_literals());
3953 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); 3956 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes());
3954 reusable_preparser_->set_allow_harmony_object_literals( 3957 reusable_preparser_->set_allow_harmony_object_literals(
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
4243 isolate()->counters()->total_preparse_skipped()->Increment( 4246 isolate()->counters()->total_preparse_skipped()->Increment(
4244 total_preparse_skipped_); 4247 total_preparse_skipped_);
4245 } 4248 }
4246 4249
4247 4250
4248 // ---------------------------------------------------------------------------- 4251 // ----------------------------------------------------------------------------
4249 // Regular expressions 4252 // Regular expressions
4250 4253
4251 4254
4252 RegExpParser::RegExpParser(FlatStringReader* in, Handle<String>* error, 4255 RegExpParser::RegExpParser(FlatStringReader* in, Handle<String>* error,
4253 bool multiline, bool unicode, Zone* zone) 4256 bool multiline, bool unicode, Isolate* isolate,
4254 : isolate_(zone->isolate()), 4257 Zone* zone)
4258 : isolate_(isolate),
4255 zone_(zone), 4259 zone_(zone),
4256 error_(error), 4260 error_(error),
4257 captures_(NULL), 4261 captures_(NULL),
4258 in_(in), 4262 in_(in),
4259 current_(kEndMarker), 4263 current_(kEndMarker),
4260 next_pos_(0), 4264 next_pos_(0),
4261 capture_count_(0), 4265 capture_count_(0),
4262 has_more_(true), 4266 has_more_(true),
4263 multiline_(multiline), 4267 multiline_(multiline),
4264 unicode_(unicode), 4268 unicode_(unicode),
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
5127 ranges->Add(CharacterRange::Everything(), zone()); 5131 ranges->Add(CharacterRange::Everything(), zone());
5128 is_negated = !is_negated; 5132 is_negated = !is_negated;
5129 } 5133 }
5130 return new(zone()) RegExpCharacterClass(ranges, is_negated); 5134 return new(zone()) RegExpCharacterClass(ranges, is_negated);
5131 } 5135 }
5132 5136
5133 5137
5134 // ---------------------------------------------------------------------------- 5138 // ----------------------------------------------------------------------------
5135 // The Parser interface. 5139 // The Parser interface.
5136 5140
5137 bool RegExpParser::ParseRegExp(FlatStringReader* input, bool multiline, 5141 bool RegExpParser::ParseRegExp(Isolate* isolate, Zone* zone,
5138 bool unicode, RegExpCompileData* result, 5142 FlatStringReader* input, bool multiline,
5139 Zone* zone) { 5143 bool unicode, RegExpCompileData* result) {
5140 DCHECK(result != NULL); 5144 DCHECK(result != NULL);
5141 RegExpParser parser(input, &result->error, multiline, unicode, zone); 5145 RegExpParser parser(input, &result->error, multiline, unicode, isolate, zone);
5142 RegExpTree* tree = parser.ParsePattern(); 5146 RegExpTree* tree = parser.ParsePattern();
5143 if (parser.failed()) { 5147 if (parser.failed()) {
5144 DCHECK(tree == NULL); 5148 DCHECK(tree == NULL);
5145 DCHECK(!result->error.is_null()); 5149 DCHECK(!result->error.is_null());
5146 } else { 5150 } else {
5147 DCHECK(tree != NULL); 5151 DCHECK(tree != NULL);
5148 DCHECK(result->error.is_null()); 5152 DCHECK(result->error.is_null());
5149 result->tree = tree; 5153 result->tree = tree;
5150 int capture_count = parser.captures_started(); 5154 int capture_count = parser.captures_started();
5151 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; 5155 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
5341 } else { 5345 } else {
5342 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5346 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5343 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5347 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5344 raw_string->length()); 5348 raw_string->length());
5345 } 5349 }
5346 } 5350 }
5347 5351
5348 return running_hash; 5352 return running_hash;
5349 } 5353 }
5350 } } // namespace v8::internal 5354 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698