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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 7461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7472 selector = ParseClosureCall(closure); | 7472 selector = ParseClosureCall(closure); |
7473 } | 7473 } |
7474 } else { | 7474 } else { |
7475 // No (more) selectors to parse. | 7475 // No (more) selectors to parse. |
7476 left = LoadFieldIfUnresolved(left); | 7476 left = LoadFieldIfUnresolved(left); |
7477 if (left->IsPrimaryNode()) { | 7477 if (left->IsPrimaryNode()) { |
7478 PrimaryNode* primary = left->AsPrimaryNode(); | 7478 PrimaryNode* primary = left->AsPrimaryNode(); |
7479 if (primary->primary().IsFunction()) { | 7479 if (primary->primary().IsFunction()) { |
7480 // Treat as implicit closure. | 7480 // Treat as implicit closure. |
7481 left = LoadClosure(primary); | 7481 left = LoadClosure(primary); |
7482 } else if (left->AsPrimaryNode()->primary().IsClass()) { | 7482 } else if (left->AsPrimaryNode()->primary().IsClass()) { |
Ivan Posva
2012/12/21 00:14:27
left->AsPrimaryNode() can be short-circuited to pr
Tom Ball
2012/12/21 22:24:11
Done.
| |
7483 Class& cls = Class::CheckedHandle( | 7483 Class& type_class = Class::Handle(); |
7484 left->AsPrimaryNode()->primary().raw()); | 7484 type_class ^= primary->primary().raw(); |
7485 String& cls_name = String::Handle(cls.Name()); | 7485 Type& type = Type::ZoneHandle( |
7486 ErrorMsg(left->token_pos(), | 7486 Type::New(type_class, TypeArguments::Handle(), |
Ivan Posva
2012/12/21 00:14:27
Instead of the acrobatics creating a type_class ha
Tom Ball
2012/12/21 22:24:11
Done.
| |
7487 "illegal use of class name '%s'", | 7487 primary->token_pos())); |
7488 cls_name.ToCString()); | 7488 type ^= ClassFinalizer::FinalizeType( |
7489 current_class(), type, ClassFinalizer::kCanonicalize); | |
7490 left = new LiteralNode(primary->token_pos(), type); | |
7489 } else if (primary->IsSuper()) { | 7491 } else if (primary->IsSuper()) { |
7490 // Return "super" to handle unary super operator calls, | 7492 // Return "super" to handle unary super operator calls, |
7491 // or to report illegal use of "super" otherwise. | 7493 // or to report illegal use of "super" otherwise. |
7492 left = primary; | 7494 left = primary; |
7493 } else { | 7495 } else { |
7494 UNREACHABLE(); // Internal parser error. | 7496 UNREACHABLE(); // Internal parser error. |
7495 } | 7497 } |
7496 } | 7498 } |
7497 // Done parsing selectors. | 7499 // Done parsing selectors. |
7498 return left; | 7500 return left; |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8326 // if we're compiling a static method. | 8328 // if we're compiling a static method. |
8327 AstNode* Parser::ResolveIdent(intptr_t ident_pos, | 8329 AstNode* Parser::ResolveIdent(intptr_t ident_pos, |
8328 const String& ident, | 8330 const String& ident, |
8329 bool allow_closure_names) { | 8331 bool allow_closure_names) { |
8330 TRACE_PARSER("ResolveIdent"); | 8332 TRACE_PARSER("ResolveIdent"); |
8331 // First try to find the variable in the local scope (block scope or | 8333 // First try to find the variable in the local scope (block scope or |
8332 // class scope). | 8334 // class scope). |
8333 AstNode* resolved = NULL; | 8335 AstNode* resolved = NULL; |
8334 ResolveIdentInLocalScope(ident_pos, ident, &resolved); | 8336 ResolveIdentInLocalScope(ident_pos, ident, &resolved); |
8335 if (resolved == NULL) { | 8337 if (resolved == NULL) { |
8336 // Check whether the identifier is a type parameter. Type parameters | |
8337 // can never be used in primary expressions. | |
8338 if (!current_class().IsNull()) { | |
8339 TypeParameter& type_param = TypeParameter::Handle( | |
8340 current_class().LookupTypeParameter(ident, ident_pos)); | |
8341 if (!type_param.IsNull()) { | |
8342 String& type_param_name = String::Handle(type_param.name()); | |
8343 ErrorMsg(ident_pos, "illegal use of type parameter %s", | |
8344 type_param_name.ToCString()); | |
8345 } | |
8346 } | |
regis
2012/12/21 00:09:10
Removing this code cannot be correct. The identifi
Tom Ball
2012/12/21 22:24:11
I restored this block and the next, and restored t
| |
8347 // Not found in the local scope, and the name is not a type parameter. | 8338 // Not found in the local scope, and the name is not a type parameter. |
8348 // Try finding the variable in the library scope (current library | 8339 // Try finding the variable in the library scope (current library |
8349 // and all libraries imported by it without a library prefix). | 8340 // and all libraries imported by it without a library prefix). |
8350 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); | 8341 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); |
8351 } | 8342 } |
8352 if (resolved->IsPrimaryNode()) { | 8343 if (resolved->IsPrimaryNode()) { |
8353 PrimaryNode* primary = resolved->AsPrimaryNode(); | 8344 PrimaryNode* primary = resolved->AsPrimaryNode(); |
8354 if (primary->primary().IsString()) { | 8345 if (primary->primary().IsString()) { |
8355 // We got an unresolved name. If we are compiling a static | 8346 // We got an unresolved name. If we are compiling a static |
8356 // method, evaluation of an unresolved identifier causes a | 8347 // method, evaluation of an unresolved identifier causes a |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9269 OpenBlock(); | 9260 OpenBlock(); |
9270 primary = ParseFunctionStatement(true); | 9261 primary = ParseFunctionStatement(true); |
9271 CloseBlock(); | 9262 CloseBlock(); |
9272 } else if (IsIdentifier()) { | 9263 } else if (IsIdentifier()) { |
9273 QualIdent qual_ident; | 9264 QualIdent qual_ident; |
9274 ParseQualIdent(&qual_ident); | 9265 ParseQualIdent(&qual_ident); |
9275 if (qual_ident.lib_prefix == NULL) { | 9266 if (qual_ident.lib_prefix == NULL) { |
9276 if (!ResolveIdentInLocalScope(qual_ident.ident_pos, | 9267 if (!ResolveIdentInLocalScope(qual_ident.ident_pos, |
9277 *qual_ident.ident, | 9268 *qual_ident.ident, |
9278 &primary)) { | 9269 &primary)) { |
9279 // Check whether the identifier is a type parameter. Type parameters | |
9280 // can never be used as part of primary expressions. | |
9281 if (!current_class().IsNull()) { | |
9282 TypeParameter& type_param = TypeParameter::ZoneHandle( | |
9283 current_class().LookupTypeParameter(*(qual_ident.ident), | |
9284 TokenPos())); | |
9285 if (!type_param.IsNull()) { | |
9286 const String& type_param_name = String::Handle(type_param.name()); | |
9287 ErrorMsg(qual_ident.ident_pos, | |
9288 "illegal use of type parameter %s", | |
9289 type_param_name.ToCString()); | |
9290 } | |
9291 } | |
regis
2012/12/21 00:09:10
ditto
| |
9292 // This is a non-local unqualified identifier so resolve the | 9270 // This is a non-local unqualified identifier so resolve the |
9293 // identifier locally in the main app library and all libraries | 9271 // identifier locally in the main app library and all libraries |
9294 // imported by it. | 9272 // imported by it. |
9295 primary = ResolveIdentInCurrentLibraryScope(qual_ident.ident_pos, | 9273 primary = ResolveIdentInCurrentLibraryScope(qual_ident.ident_pos, |
9296 *qual_ident.ident); | 9274 *qual_ident.ident); |
9297 } | 9275 } |
9298 } else { | 9276 } else { |
9299 // This is a qualified identifier with a library prefix so resolve | 9277 // This is a qualified identifier with a library prefix so resolve |
9300 // the identifier locally in that library (we do not include the | 9278 // the identifier locally in that library (we do not include the |
9301 // libraries imported by that library). | 9279 // libraries imported by that library). |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9697 void Parser::SkipQualIdent() { | 9675 void Parser::SkipQualIdent() { |
9698 ASSERT(IsIdentifier()); | 9676 ASSERT(IsIdentifier()); |
9699 ConsumeToken(); | 9677 ConsumeToken(); |
9700 if (CurrentToken() == Token::kPERIOD) { | 9678 if (CurrentToken() == Token::kPERIOD) { |
9701 ConsumeToken(); // Consume the kPERIOD token. | 9679 ConsumeToken(); // Consume the kPERIOD token. |
9702 ExpectIdentifier("identifier expected after '.'"); | 9680 ExpectIdentifier("identifier expected after '.'"); |
9703 } | 9681 } |
9704 } | 9682 } |
9705 | 9683 |
9706 } // namespace dart | 9684 } // namespace dart |
OLD | NEW |