OLD | NEW |
---|---|
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 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1114 ASSERT(field.is_static()); | 1114 ASSERT(field.is_static()); |
1115 Thread* thread = Thread::Current(); | 1115 Thread* thread = Thread::Current(); |
1116 // TODO(koda): Should there be a StackZone here? | 1116 // TODO(koda): Should there be a StackZone here? |
1117 Zone* zone = thread->zone(); | 1117 Zone* zone = thread->zone(); |
1118 | 1118 |
1119 const Class& script_cls = Class::Handle(zone, field.origin()); | 1119 const Class& script_cls = Class::Handle(zone, field.origin()); |
1120 const Script& script = Script::Handle(zone, script_cls.script()); | 1120 const Script& script = Script::Handle(zone, script_cls.script()); |
1121 | 1121 |
1122 const String& field_name = String::Handle(zone, field.name()); | 1122 const String& field_name = String::Handle(zone, field.name()); |
1123 String& init_name = String::Handle(zone, | 1123 String& init_name = String::Handle(zone, |
1124 String::Concat(Symbols::InitPrefix(), field_name)); | 1124 Symbols::FromConcat(Symbols::InitPrefix(), field_name)); |
1125 init_name = Symbols::New(init_name); | |
1126 | 1125 |
1127 const Function& initializer = Function::ZoneHandle(zone, | 1126 const Function& initializer = Function::ZoneHandle(zone, |
1128 Function::New(init_name, | 1127 Function::New(init_name, |
1129 RawFunction::kRegularFunction, | 1128 RawFunction::kRegularFunction, |
1130 true, // static | 1129 true, // static |
1131 false, // !const | 1130 false, // !const |
1132 false, // !abstract | 1131 false, // !abstract |
1133 false, // !external | 1132 false, // !external |
1134 false, // !native | 1133 false, // !native |
1135 Class::Handle(field.owner()), | 1134 Class::Handle(field.owner()), |
(...skipping 3697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4833 const Array& functions = | 4832 const Array& functions = |
4834 Array::Handle(Z, Array::MakeArray(enum_members.functions())); | 4833 Array::Handle(Z, Array::MakeArray(enum_members.functions())); |
4835 cls.SetFunctions(functions); | 4834 cls.SetFunctions(functions); |
4836 } | 4835 } |
4837 | 4836 |
4838 | 4837 |
4839 // Add an implicit constructor to the given class. | 4838 // Add an implicit constructor to the given class. |
4840 void Parser::AddImplicitConstructor(const Class& cls) { | 4839 void Parser::AddImplicitConstructor(const Class& cls) { |
4841 // The implicit constructor is unnamed, has no explicit parameter. | 4840 // The implicit constructor is unnamed, has no explicit parameter. |
4842 String& ctor_name = String::ZoneHandle(Z, cls.Name()); | 4841 String& ctor_name = String::ZoneHandle(Z, cls.Name()); |
4843 ctor_name = String::Concat(ctor_name, Symbols::Dot()); | 4842 ctor_name = Symbols::FromConcat(ctor_name, Symbols::Dot()); |
4844 ctor_name = Symbols::New(ctor_name); | |
4845 // To indicate that this is an implicit constructor, we set the | 4843 // To indicate that this is an implicit constructor, we set the |
4846 // token position and end token position of the function | 4844 // token position and end token position of the function |
4847 // to the token position of the class. | 4845 // to the token position of the class. |
4848 Function& ctor = Function::Handle(Z, | 4846 Function& ctor = Function::Handle(Z, |
4849 Function::New(ctor_name, | 4847 Function::New(ctor_name, |
4850 RawFunction::kConstructor, | 4848 RawFunction::kConstructor, |
4851 /* is_static = */ false, | 4849 /* is_static = */ false, |
4852 /* is_const = */ false, | 4850 /* is_const = */ false, |
4853 /* is_abstract = */ false, | 4851 /* is_abstract = */ false, |
4854 /* is_external = */ false, | 4852 /* is_external = */ false, |
(...skipping 6815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11670 is_setter_name | 11668 is_setter_name |
11671 ? InvocationMirror::kSetter | 11669 ? InvocationMirror::kSetter |
11672 : InvocationMirror::kMethod, | 11670 : InvocationMirror::kMethod, |
11673 NULL); // No existing function. | 11671 NULL); // No existing function. |
11674 } | 11672 } |
11675 | 11673 |
11676 // Closurization of instance getter, setter, method or operator. | 11674 // Closurization of instance getter, setter, method or operator. |
11677 if (is_setter_name) { | 11675 if (is_setter_name) { |
11678 extractor_name = String::Concat(Symbols::SetterPrefix(), extractor_name); | 11676 extractor_name = String::Concat(Symbols::SetterPrefix(), extractor_name); |
11679 } | 11677 } |
11680 extractor_name = String::Concat(Symbols::HashMark(), extractor_name); | 11678 extractor_name = Symbols::FromConcat(Symbols::HashMark(), extractor_name); |
11681 extractor_name = Symbols::New(extractor_name); | |
11682 return new(Z) InstanceGetterNode(property_pos, primary, extractor_name); | 11679 return new(Z) InstanceGetterNode(property_pos, primary, extractor_name); |
11683 } | 11680 } |
11684 | 11681 |
11685 | 11682 |
11686 AstNode* Parser::ParsePostfixExpr() { | 11683 AstNode* Parser::ParsePostfixExpr() { |
11687 TRACE_PARSER("ParsePostfixExpr"); | 11684 TRACE_PARSER("ParsePostfixExpr"); |
11688 String* expr_ident = | 11685 String* expr_ident = |
11689 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; | 11686 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; |
11690 const intptr_t expr_pos = TokenPos(); | 11687 const intptr_t expr_pos = TokenPos(); |
11691 AstNode* expr = ParsePrimary(); | 11688 AstNode* expr = ParsePrimary(); |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13037 } | 13034 } |
13038 | 13035 |
13039 | 13036 |
13040 static String& BuildConstructorName(const String& type_class_name, | 13037 static String& BuildConstructorName(const String& type_class_name, |
13041 const String* named_constructor) { | 13038 const String* named_constructor) { |
13042 // By convention, the static function implementing a named constructor 'C' | 13039 // By convention, the static function implementing a named constructor 'C' |
13043 // for class 'A' is labeled 'A.C', and the static function implementing the | 13040 // for class 'A' is labeled 'A.C', and the static function implementing the |
13044 // unnamed constructor for class 'A' is labeled 'A.'. | 13041 // unnamed constructor for class 'A' is labeled 'A.'. |
13045 // This convention prevents users from explicitly calling constructors. | 13042 // This convention prevents users from explicitly calling constructors. |
13046 String& constructor_name = | 13043 String& constructor_name = |
13047 String::Handle(String::Concat(type_class_name, Symbols::Dot())); | 13044 String::Handle(Symbols::FromConcat(type_class_name, Symbols::Dot())); |
hausner
2015/08/20 21:45:46
Isn't it premature to create a symbol here? If it'
srdjan
2015/08/20 22:11:18
Discussed offline, agreed to keep it as it is, oth
| |
13048 if (named_constructor != NULL) { | 13045 if (named_constructor != NULL) { |
13049 constructor_name = String::Concat(constructor_name, *named_constructor); | 13046 constructor_name = |
13047 Symbols::FromConcat(constructor_name, *named_constructor); | |
13050 } | 13048 } |
13051 return constructor_name; | 13049 return constructor_name; |
13052 } | 13050 } |
13053 | 13051 |
13054 | 13052 |
13055 // Parse a primary expression of the form new T# or new T#m. | 13053 // Parse a primary expression of the form new T# or new T#m. |
13056 // Current token position is after the keyword new. Extracts the | 13054 // Current token position is after the keyword new. Extracts the |
13057 // anonymous or named constructor and type arguments. | 13055 // anonymous or named constructor and type arguments. |
13058 // Note that type type T has already been parsed before | 13056 // Note that type type T has already been parsed before |
13059 // (by ParseNewOperator()) and is guaranteed to be well-formed, | 13057 // (by ParseNewOperator()) and is guaranteed to be well-formed, |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13656 // For example, we don't know yet whether the unresolved name | 13654 // For example, we don't know yet whether the unresolved name |
13657 // refers to a getter or a setter. However, it is more awkward | 13655 // refers to a getter or a setter. However, it is more awkward |
13658 // to distinuish four NoSuchMethodError cases all over the place | 13656 // to distinuish four NoSuchMethodError cases all over the place |
13659 // in the parser. The four cases are: prefixed vs non-prefixed | 13657 // in the parser. The four cases are: prefixed vs non-prefixed |
13660 // name, static vs dynamic context in which the unresolved name | 13658 // name, static vs dynamic context in which the unresolved name |
13661 // is used. We cheat a little here by looking at the next token | 13659 // is used. We cheat a little here by looking at the next token |
13662 // to determine whether we have an unresolved method call or | 13660 // to determine whether we have an unresolved method call or |
13663 // field access. | 13661 // field access. |
13664 String& qualified_name = String::ZoneHandle(Z, prefix.name()); | 13662 String& qualified_name = String::ZoneHandle(Z, prefix.name()); |
13665 qualified_name = String::Concat(qualified_name, Symbols::Dot()); | 13663 qualified_name = String::Concat(qualified_name, Symbols::Dot()); |
13666 qualified_name = String::Concat(qualified_name, ident); | 13664 qualified_name = Symbols::FromConcat(qualified_name, ident); |
13667 qualified_name = Symbols::New(qualified_name); | |
13668 InvocationMirror::Type call_type = | 13665 InvocationMirror::Type call_type = |
13669 CurrentToken() == Token::kLPAREN ? | 13666 CurrentToken() == Token::kLPAREN ? |
13670 InvocationMirror::kMethod : InvocationMirror::kGetter; | 13667 InvocationMirror::kMethod : InvocationMirror::kGetter; |
13671 primary = ThrowNoSuchMethodError(qual_ident_pos, | 13668 primary = ThrowNoSuchMethodError(qual_ident_pos, |
13672 current_class(), | 13669 current_class(), |
13673 qualified_name, | 13670 qualified_name, |
13674 NULL, // No arguments. | 13671 NULL, // No arguments. |
13675 InvocationMirror::kTopLevel, | 13672 InvocationMirror::kTopLevel, |
13676 call_type, | 13673 call_type, |
13677 NULL); // No existing function. | 13674 NULL); // No existing function. |
13678 } | 13675 } |
13679 } else if (FLAG_load_deferred_eagerly && prefix.is_deferred_load()) { | 13676 } else if (FLAG_load_deferred_eagerly && prefix.is_deferred_load()) { |
13680 // primary != NULL. | 13677 // primary != NULL. |
13681 String& qualified_name = String::ZoneHandle(Z, prefix.name()); | 13678 String& qualified_name = String::ZoneHandle(Z, prefix.name()); |
13682 qualified_name = String::Concat(qualified_name, Symbols::Dot()); | 13679 qualified_name = String::Concat(qualified_name, Symbols::Dot()); |
13683 qualified_name = String::Concat(qualified_name, ident); | 13680 qualified_name = Symbols::FromConcat(qualified_name, ident); |
13684 qualified_name = Symbols::New(qualified_name); | |
13685 InvocationMirror::Type call_type = | 13681 InvocationMirror::Type call_type = |
13686 CurrentToken() == Token::kLPAREN ? | 13682 CurrentToken() == Token::kLPAREN ? |
13687 InvocationMirror::kMethod : InvocationMirror::kGetter; | 13683 InvocationMirror::kMethod : InvocationMirror::kGetter; |
13688 // Note: Adding a statement to current block is a hack, parsing an | 13684 // Note: Adding a statement to current block is a hack, parsing an |
13689 // espression should have no side-effect. | 13685 // espression should have no side-effect. |
13690 current_block_->statements->Add(ThrowNoSuchMethodError( | 13686 current_block_->statements->Add(ThrowNoSuchMethodError( |
13691 qual_ident_pos, | 13687 qual_ident_pos, |
13692 current_class(), | 13688 current_class(), |
13693 qualified_name, | 13689 qualified_name, |
13694 NULL, // No arguments. | 13690 NULL, // No arguments. |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14191 void Parser::SkipQualIdent() { | 14187 void Parser::SkipQualIdent() { |
14192 ASSERT(IsIdentifier()); | 14188 ASSERT(IsIdentifier()); |
14193 ConsumeToken(); | 14189 ConsumeToken(); |
14194 if (CurrentToken() == Token::kPERIOD) { | 14190 if (CurrentToken() == Token::kPERIOD) { |
14195 ConsumeToken(); // Consume the kPERIOD token. | 14191 ConsumeToken(); // Consume the kPERIOD token. |
14196 ExpectIdentifier("identifier expected after '.'"); | 14192 ExpectIdentifier("identifier expected after '.'"); |
14197 } | 14193 } |
14198 } | 14194 } |
14199 | 14195 |
14200 } // namespace dart | 14196 } // namespace dart |
OLD | NEW |