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

Side by Side Diff: runtime/vm/parser.cc

Issue 2665003002: Fix background compiler issue with new-space allocation in the parser. (Closed)
Patch Set: use LookupGetter/SetterSymbol Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 2339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 ReportError(token_pos, "class '%s' does not have a superclass", 2350 ReportError(token_pos, "class '%s' does not have a superclass",
2351 String::Handle(Z, current_class().Name()).ToCString()); 2351 String::Handle(Z, current_class().Name()).ToCString());
2352 } 2352 }
2353 Function& super_func = Function::Handle( 2353 Function& super_func = Function::Handle(
2354 Z, Resolver::ResolveDynamicAnyArgs(Z, super_class, name)); 2354 Z, Resolver::ResolveDynamicAnyArgs(Z, super_class, name));
2355 if (!super_func.IsNull() && 2355 if (!super_func.IsNull() &&
2356 !super_func.AreValidArguments(arguments->length(), arguments->names(), 2356 !super_func.AreValidArguments(arguments->length(), arguments->names(),
2357 NULL)) { 2357 NULL)) {
2358 super_func = Function::null(); 2358 super_func = Function::null();
2359 } else if (super_func.IsNull() && resolve_getter) { 2359 } else if (super_func.IsNull() && resolve_getter) {
2360 const String& getter_name = String::ZoneHandle(Z, Field::GetterName(name)); 2360 const String& getter_name =
2361 super_func = Resolver::ResolveDynamicAnyArgs(Z, super_class, getter_name); 2361 String::ZoneHandle(Z, Field::LookupGetterSymbol(name));
2362 ASSERT(super_func.IsNull() || 2362 if (!getter_name.IsNull()) {
2363 (super_func.kind() != RawFunction::kImplicitStaticFinalGetter)); 2363 super_func = Resolver::ResolveDynamicAnyArgs(Z, super_class, getter_name);
2364 ASSERT(super_func.IsNull() ||
2365 (super_func.kind() != RawFunction::kImplicitStaticFinalGetter));
2366 }
2364 } 2367 }
2365 if (super_func.IsNull()) { 2368 if (super_func.IsNull()) {
2366 super_func = Resolver::ResolveDynamicAnyArgs(Z, super_class, 2369 super_func = Resolver::ResolveDynamicAnyArgs(Z, super_class,
2367 Symbols::NoSuchMethod()); 2370 Symbols::NoSuchMethod());
2368 ASSERT(!super_func.IsNull()); 2371 ASSERT(!super_func.IsNull());
2369 *is_no_such_method = true; 2372 *is_no_such_method = true;
2370 } else { 2373 } else {
2371 *is_no_such_method = false; 2374 *is_no_such_method = false;
2372 } 2375 }
2373 return super_func.raw(); 2376 return super_func.raw();
(...skipping 3255 matching lines...) Expand 10 before | Expand all | Expand 10 after
5629 String& var_name = *ExpectIdentifier("variable name expected"); 5632 String& var_name = *ExpectIdentifier("variable name expected");
5630 5633
5631 if (library_.LookupLocalObject(var_name) != Object::null()) { 5634 if (library_.LookupLocalObject(var_name) != Object::null()) {
5632 ReportError(name_pos, "'%s' is already defined", var_name.ToCString()); 5635 ReportError(name_pos, "'%s' is already defined", var_name.ToCString());
5633 } 5636 }
5634 5637
5635 // Check whether a getter or setter for this name exists. A const 5638 // Check whether a getter or setter for this name exists. A const
5636 // or final field implies a setter which throws a NoSuchMethodError, 5639 // or final field implies a setter which throws a NoSuchMethodError,
5637 // thus we need to check for conflicts with existing setters and 5640 // thus we need to check for conflicts with existing setters and
5638 // getters. 5641 // getters.
5639 String& accessor_name = String::Handle(Z, Field::GetterName(var_name)); 5642 String& accessor_name =
5640 if (library_.LookupLocalObject(accessor_name) != Object::null()) { 5643 String::Handle(Z, Field::LookupGetterSymbol(var_name));
5644 if (!accessor_name.IsNull() &&
5645 library_.LookupLocalObject(accessor_name) != Object::null()) {
5641 ReportError(name_pos, "getter for '%s' is already defined", 5646 ReportError(name_pos, "getter for '%s' is already defined",
5642 var_name.ToCString()); 5647 var_name.ToCString());
5643 } 5648 }
5644 accessor_name = Field::SetterName(var_name); 5649 accessor_name = Field::LookupSetterSymbol(var_name);
5645 if (library_.LookupLocalObject(accessor_name) != Object::null()) { 5650 if (!accessor_name.IsNull() &&
5651 library_.LookupLocalObject(accessor_name) != Object::null()) {
5646 ReportError(name_pos, "setter for '%s' is already defined", 5652 ReportError(name_pos, "setter for '%s' is already defined",
5647 var_name.ToCString()); 5653 var_name.ToCString());
5648 } 5654 }
5649 5655
5650 const bool is_reflectable = 5656 const bool is_reflectable =
5651 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); 5657 !(library_.is_dart_scheme() && library_.IsPrivate(var_name));
5652 5658
5653 field = Field::NewTopLevel(var_name, is_final, is_const, owner, name_pos); 5659 field = Field::NewTopLevel(var_name, is_final, is_const, owner, name_pos);
5654 field.SetFieldType(type); 5660 field.SetFieldType(type);
5655 field.set_is_reflectable(is_reflectable); 5661 field.set_is_reflectable(is_reflectable);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
5750 const TokenPosition name_pos = TokenPos(); 5756 const TokenPosition name_pos = TokenPos();
5751 const String& func_name = *ExpectIdentifier("function name expected"); 5757 const String& func_name = *ExpectIdentifier("function name expected");
5752 5758
5753 bool found = library_.LookupLocalObject(func_name) != Object::null(); 5759 bool found = library_.LookupLocalObject(func_name) != Object::null();
5754 if (found && !is_patch) { 5760 if (found && !is_patch) {
5755 ReportError(name_pos, "'%s' is already defined", func_name.ToCString()); 5761 ReportError(name_pos, "'%s' is already defined", func_name.ToCString());
5756 } else if (!found && is_patch) { 5762 } else if (!found && is_patch) {
5757 ReportError(name_pos, "missing '%s' cannot be patched", 5763 ReportError(name_pos, "missing '%s' cannot be patched",
5758 func_name.ToCString()); 5764 func_name.ToCString());
5759 } 5765 }
5760 String& accessor_name = String::Handle(Z, Field::GetterName(func_name)); 5766 const String& accessor_name =
5761 if (library_.LookupLocalObject(accessor_name) != Object::null()) { 5767 String::Handle(Z, Field::LookupGetterSymbol(func_name));
5768 if (!accessor_name.IsNull() &&
5769 library_.LookupLocalObject(accessor_name) != Object::null()) {
5762 ReportError(name_pos, "'%s' is already defined as getter", 5770 ReportError(name_pos, "'%s' is already defined as getter",
5763 func_name.ToCString()); 5771 func_name.ToCString());
5764 } 5772 }
5765 // A setter named x= may co-exist with a function named x, thus we do 5773 // A setter named x= may co-exist with a function named x, thus we do
5766 // not need to check setters. 5774 // not need to check setters.
5767 5775
5768 Function& func = Function::Handle( 5776 Function& func = Function::Handle(
5769 Z, Function::New(func_name, RawFunction::kRegularFunction, 5777 Z, Function::New(func_name, RawFunction::kRegularFunction,
5770 /* is_static = */ true, 5778 /* is_static = */ true,
5771 /* is_const = */ false, 5779 /* is_const = */ false,
(...skipping 5323 matching lines...) Expand 10 before | Expand all | Expand 10 after
11095 } else if ((left_ident != NULL) && 11103 } else if ((left_ident != NULL) &&
11096 (original->IsLiteralNode() || original->IsLoadLocalNode())) { 11104 (original->IsLiteralNode() || original->IsLoadLocalNode())) {
11097 name = left_ident->raw(); 11105 name = left_ident->raw();
11098 } 11106 }
11099 if (name.IsNull()) { 11107 if (name.IsNull()) {
11100 ReportError(left_pos, "expression is not assignable"); 11108 ReportError(left_pos, "expression is not assignable");
11101 } 11109 }
11102 ArgumentListNode* error_arguments = 11110 ArgumentListNode* error_arguments =
11103 new (Z) ArgumentListNode(rhs->token_pos()); 11111 new (Z) ArgumentListNode(rhs->token_pos());
11104 error_arguments->Add(rhs); 11112 error_arguments->Add(rhs);
11105 result = ThrowNoSuchMethodError(original->token_pos(), *target_cls, 11113 result = ThrowNoSuchMethodError(
11106 String::Handle(Z, Field::SetterName(name)), 11114 original->token_pos(), *target_cls,
11107 error_arguments, InvocationMirror::kStatic, 11115 String::Handle(Z, Field::SetterSymbol(name)), error_arguments,
11108 original->IsLoadLocalNode() 11116 InvocationMirror::kStatic,
11109 ? InvocationMirror::kLocalVar 11117 original->IsLoadLocalNode() ? InvocationMirror::kLocalVar
11110 : InvocationMirror::kSetter, 11118 : InvocationMirror::kSetter,
11111 NULL); // No existing function. 11119 NULL); // No existing function.
11112 } 11120 }
11113 // The compound assignment operator a ??= b is different from other 11121 // The compound assignment operator a ??= b is different from other
11114 // a op= b assignments. If a is non-null, the assignment to a must be 11122 // a op= b assignments. If a is non-null, the assignment to a must be
11115 // dropped: 11123 // dropped:
11116 // normally: a op= b ==> a = a op b 11124 // normally: a op= b ==> a = a op b
11117 // however: a ??= b ==> a ?? (a = b) 11125 // however: a ??= b ==> a ?? (a = b)
11118 // Therefore, we need to transform a = (a ?? b) into a ?? (a = b) 11126 // Therefore, we need to transform a = (a ?? b) into a ?? (a = b)
11119 if (is_compound && rhs->IsBinaryOpNode() && 11127 if (is_compound && rhs->IsBinaryOpNode() &&
11120 (rhs->AsBinaryOpNode()->kind() == Token::kIFNULL)) { 11128 (rhs->AsBinaryOpNode()->kind() == Token::kIFNULL)) {
11121 BinaryOpNode* ifnull = rhs->AsBinaryOpNode(); 11129 BinaryOpNode* ifnull = rhs->AsBinaryOpNode();
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
11466 arguments->names())); 11474 arguments->names()));
11467 if (func.IsNull()) { 11475 if (func.IsNull()) {
11468 // Check if there is a static field of the same name, it could be a closure 11476 // Check if there is a static field of the same name, it could be a closure
11469 // and so we try and invoke the closure. 11477 // and so we try and invoke the closure.
11470 AstNode* closure = NULL; 11478 AstNode* closure = NULL;
11471 const Field& field = Field::ZoneHandle(Z, cls.LookupStaticField(func_name)); 11479 const Field& field = Field::ZoneHandle(Z, cls.LookupStaticField(func_name));
11472 Function& func = Function::ZoneHandle(Z); 11480 Function& func = Function::ZoneHandle(Z);
11473 if (field.IsNull()) { 11481 if (field.IsNull()) {
11474 // No field, check if we have an explicit getter function. 11482 // No field, check if we have an explicit getter function.
11475 const String& getter_name = 11483 const String& getter_name =
11476 String::ZoneHandle(Z, Field::GetterName(func_name)); 11484 String::ZoneHandle(Z, Field::LookupGetterSymbol(func_name));
11477 const int kNumArguments = 0; // no arguments. 11485 if (!getter_name.IsNull()) {
11478 func = Resolver::ResolveStatic(cls, getter_name, kNumArguments, 11486 const int kNumArguments = 0; // no arguments.
11479 Object::empty_array()); 11487 func = Resolver::ResolveStatic(cls, getter_name, kNumArguments,
11480 if (!func.IsNull()) { 11488 Object::empty_array());
11481 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); 11489 if (!func.IsNull()) {
11482 closure = new (Z) StaticGetterNode( 11490 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter);
11483 call_pos, NULL, Class::ZoneHandle(Z, cls.raw()), func_name); 11491 closure = new (Z) StaticGetterNode(
11484 return BuildClosureCall(call_pos, closure, arguments); 11492 call_pos, NULL, Class::ZoneHandle(Z, cls.raw()), func_name);
11493 return BuildClosureCall(call_pos, closure, arguments);
11494 }
11485 } 11495 }
11486 } else { 11496 } else {
11487 closure = GenerateStaticFieldLookup(field, call_pos); 11497 closure = GenerateStaticFieldLookup(field, call_pos);
11488 return BuildClosureCall(call_pos, closure, arguments); 11498 return BuildClosureCall(call_pos, closure, arguments);
11489 } 11499 }
11490 // Could not resolve static method: throw a NoSuchMethodError. 11500 // Could not resolve static method: throw a NoSuchMethodError.
11491 return ThrowNoSuchMethodError(ident_pos, cls, func_name, arguments, 11501 return ThrowNoSuchMethodError(ident_pos, cls, func_name, arguments,
11492 InvocationMirror::kStatic, 11502 InvocationMirror::kStatic,
11493 InvocationMirror::kMethod, 11503 InvocationMirror::kMethod,
11494 NULL, // No existing function. 11504 NULL, // No existing function.
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
12004 (extractor_name.CharAt(0) == Library::kPrivateIdentifierStart); 12014 (extractor_name.CharAt(0) == Library::kPrivateIdentifierStart);
12005 if (!is_private_name) { 12015 if (!is_private_name) {
12006 // Private names are not exported by libraries. The name mangling 12016 // Private names are not exported by libraries. The name mangling
12007 // of private names with a library-specific suffix usually ensures 12017 // of private names with a library-specific suffix usually ensures
12008 // that _x in library A is not found when looked up from library B. 12018 // that _x in library A is not found when looked up from library B.
12009 // In the pathological case where a library imports itself with 12019 // In the pathological case where a library imports itself with
12010 // a prefix, the name mangling does not help in hiding the private 12020 // a prefix, the name mangling does not help in hiding the private
12011 // name, so we explicitly prevent lookup of private names here. 12021 // name, so we explicitly prevent lookup of private names here.
12012 if (is_setter_name) { 12022 if (is_setter_name) {
12013 const String& setter_name = 12023 const String& setter_name =
12014 String::Handle(Z, Field::SetterName(extractor_name)); 12024 String::Handle(Z, Field::LookupSetterSymbol(extractor_name));
12015 obj = prefix.LookupObject(setter_name); 12025 if (!setter_name.IsNull()) {
12026 obj = prefix.LookupObject(setter_name);
12027 }
12016 } 12028 }
12017 if (obj.IsNull()) { 12029 if (obj.IsNull()) {
12018 obj = prefix.LookupObject(extractor_name); 12030 obj = prefix.LookupObject(extractor_name);
12019 } 12031 }
12020 } 12032 }
12021 if (!prefix.is_loaded() && (parsed_function() != NULL) && 12033 if (!prefix.is_loaded() && (parsed_function() != NULL) &&
12022 !FLAG_load_deferred_eagerly) { 12034 !FLAG_load_deferred_eagerly) {
12023 // Remember that this function depends on an import prefix of an 12035 // Remember that this function depends on an import prefix of an
12024 // unloaded deferred library. 12036 // unloaded deferred library.
12025 parsed_function()->AddDeferredPrefix(prefix); 12037 parsed_function()->AddDeferredPrefix(prefix);
(...skipping 26 matching lines...) Expand all
12052 } 12064 }
12053 12065
12054 // Handle closurization of static properties of classes, C#n. 12066 // Handle closurization of static properties of classes, C#n.
12055 if (primary->IsPrimaryNode() && 12067 if (primary->IsPrimaryNode() &&
12056 primary->AsPrimaryNode()->primary().IsClass()) { 12068 primary->AsPrimaryNode()->primary().IsClass()) {
12057 const Class& cls = Class::Cast(primary->AsPrimaryNode()->primary()); 12069 const Class& cls = Class::Cast(primary->AsPrimaryNode()->primary());
12058 const Field& field = 12070 const Field& field =
12059 Field::Handle(Z, cls.LookupStaticField(extractor_name)); 12071 Field::Handle(Z, cls.LookupStaticField(extractor_name));
12060 if (!field.IsNull()) { 12072 if (!field.IsNull()) {
12061 if (is_setter_name) { 12073 if (is_setter_name) {
12062 extractor_name = Field::SetterName(extractor_name);
12063 if (!field.is_final()) { 12074 if (!field.is_final()) {
12064 const Instance& setter_closure = 12075 const Instance& setter_closure =
12065 Instance::ZoneHandle(Z, field.SetterClosure()); 12076 Instance::ZoneHandle(Z, field.SetterClosure());
12066 ASSERT(setter_closure.IsClosure()); 12077 ASSERT(setter_closure.IsClosure());
12067 // Note: the created closure is cached after it's created 12078 // Note: the created closure is cached after it's created
12068 // once. If eager compilation is desired, the compiler can 12079 // once. If eager compilation is desired, the compiler can
12069 // be invoked here. The same applies for getters below. 12080 // be invoked here. The same applies for getters below.
12070 return new (Z) LiteralNode(property_pos, setter_closure); 12081 return new (Z) LiteralNode(property_pos, setter_closure);
12071 } 12082 }
12083 extractor_name = Field::SetterSymbol(extractor_name);
12072 } else { 12084 } else {
12073 const Instance& getter_closure = 12085 const Instance& getter_closure =
12074 Instance::ZoneHandle(Z, field.GetterClosure()); 12086 Instance::ZoneHandle(Z, field.GetterClosure());
12075 ASSERT(getter_closure.IsClosure()); 12087 ASSERT(getter_closure.IsClosure());
12076 return new (Z) LiteralNode(property_pos, getter_closure); 12088 return new (Z) LiteralNode(property_pos, getter_closure);
12077 } 12089 }
12078 } else { 12090 } else {
12079 Function& func = Function::Handle(Z); 12091 Function& func = Function::Handle(Z);
12080 if (is_setter_name) { 12092 if (is_setter_name) {
12081 extractor_name = Field::SetterName(extractor_name); 12093 extractor_name = Field::LookupSetterSymbol(extractor_name);
12082 func = cls.LookupStaticFunction(extractor_name); 12094 if (!extractor_name.IsNull()) {
12095 func = cls.LookupStaticFunction(extractor_name);
12096 } else {
12097 extractor_name = Field::SetterSymbol(extractor_name);
12098 }
12083 } else { 12099 } else {
12084 func = cls.LookupStaticFunction(extractor_name); 12100 func = cls.LookupStaticFunction(extractor_name);
12085 if (func.IsNull()) { 12101 if (func.IsNull()) {
12086 const String& getter_name = 12102 const String& getter_name =
12087 String::Handle(Z, Field::GetterName(extractor_name)); 12103 String::Handle(Z, Field::LookupGetterSymbol(extractor_name));
12088 func = cls.LookupStaticFunction(getter_name); 12104 if (!getter_name.IsNull()) {
12105 func = cls.LookupStaticFunction(getter_name);
12106 }
12089 } 12107 }
12090 } 12108 }
12091 if (!func.IsNull()) { 12109 if (!func.IsNull()) {
12092 return CreateImplicitClosureNode(func, property_pos, NULL); 12110 return CreateImplicitClosureNode(func, property_pos, NULL);
12093 } 12111 }
12094 } 12112 }
12095 return ThrowNoSuchMethodError( 12113 return ThrowNoSuchMethodError(
12096 property_pos, cls, extractor_name, 12114 property_pos, cls, extractor_name,
12097 NULL, // No arguments. 12115 NULL, // No arguments.
12098 InvocationMirror::kStatic, 12116 InvocationMirror::kStatic,
(...skipping 2919 matching lines...) Expand 10 before | Expand all | Expand 10 after
15018 const ArgumentListNode& function_args, 15036 const ArgumentListNode& function_args,
15019 const LocalVariable* temp_for_last_arg, 15037 const LocalVariable* temp_for_last_arg,
15020 bool is_super_invocation) { 15038 bool is_super_invocation) {
15021 UNREACHABLE(); 15039 UNREACHABLE();
15022 return NULL; 15040 return NULL;
15023 } 15041 }
15024 15042
15025 } // namespace dart 15043 } // namespace dart
15026 15044
15027 #endif // DART_PRECOMPILED_RUNTIME 15045 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698