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

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

Issue 103913005: Introduce class TypeRef in the VM to fully support recursive types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_store.h ('k') | runtime/vm/raw_object.h » ('j') | 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 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/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 8343 matching lines...) Expand 10 before | Expand all | Expand 10 after
8354 left = LoadClosure(left->AsPrimaryNode()); 8354 left = LoadClosure(left->AsPrimaryNode());
8355 } else if (left->AsPrimaryNode()->primary().IsTypeParameter()) { 8355 } else if (left->AsPrimaryNode()->primary().IsTypeParameter()) {
8356 if (current_block_->scope->function_level() > 0) { 8356 if (current_block_->scope->function_level() > 0) {
8357 // Make sure that the instantiator is captured. 8357 // Make sure that the instantiator is captured.
8358 CaptureInstantiator(); 8358 CaptureInstantiator();
8359 } 8359 }
8360 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); 8360 TypeParameter& type_parameter = TypeParameter::ZoneHandle();
8361 type_parameter ^= ClassFinalizer::FinalizeType( 8361 type_parameter ^= ClassFinalizer::FinalizeType(
8362 current_class(), 8362 current_class(),
8363 TypeParameter::Cast(left->AsPrimaryNode()->primary()), 8363 TypeParameter::Cast(left->AsPrimaryNode()->primary()),
8364 ClassFinalizer::kFinalize); 8364 ClassFinalizer::kCanonicalize);
8365 ASSERT(!type_parameter.IsMalformed()); 8365 ASSERT(!type_parameter.IsMalformed());
8366 left = new TypeNode(primary->token_pos(), type_parameter); 8366 left = new TypeNode(primary->token_pos(), type_parameter);
8367 } else { 8367 } else {
8368 // Super field access handled in ParseSuperFieldAccess(), 8368 // Super field access handled in ParseSuperFieldAccess(),
8369 // super calls handled in ParseSuperCall(). 8369 // super calls handled in ParseSuperCall().
8370 ASSERT(!left->AsPrimaryNode()->IsSuper()); 8370 ASSERT(!left->AsPrimaryNode()->IsSuper());
8371 left = LoadFieldIfUnresolved(left); 8371 left = LoadFieldIfUnresolved(left);
8372 } 8372 }
8373 } 8373 }
8374 const intptr_t ident_pos = TokenPos(); 8374 const intptr_t ident_pos = TokenPos();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
8431 array = new TypeNode(primary->token_pos(), type); 8431 array = new TypeNode(primary->token_pos(), type);
8432 } else if (primary->primary().IsTypeParameter()) { 8432 } else if (primary->primary().IsTypeParameter()) {
8433 if (current_block_->scope->function_level() > 0) { 8433 if (current_block_->scope->function_level() > 0) {
8434 // Make sure that the instantiator is captured. 8434 // Make sure that the instantiator is captured.
8435 CaptureInstantiator(); 8435 CaptureInstantiator();
8436 } 8436 }
8437 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); 8437 TypeParameter& type_parameter = TypeParameter::ZoneHandle();
8438 type_parameter ^= ClassFinalizer::FinalizeType( 8438 type_parameter ^= ClassFinalizer::FinalizeType(
8439 current_class(), 8439 current_class(),
8440 TypeParameter::Cast(primary->primary()), 8440 TypeParameter::Cast(primary->primary()),
8441 ClassFinalizer::kFinalize); 8441 ClassFinalizer::kCanonicalize);
8442 ASSERT(!type_parameter.IsMalformed()); 8442 ASSERT(!type_parameter.IsMalformed());
8443 array = new TypeNode(primary->token_pos(), type_parameter); 8443 array = new TypeNode(primary->token_pos(), type_parameter);
8444 } else { 8444 } else {
8445 UNREACHABLE(); // Internal parser error. 8445 UNREACHABLE(); // Internal parser error.
8446 } 8446 }
8447 } 8447 }
8448 selector = new LoadIndexedNode(bracket_pos, 8448 selector = new LoadIndexedNode(bracket_pos,
8449 array, 8449 array,
8450 index, 8450 index,
8451 Class::ZoneHandle()); 8451 Class::ZoneHandle());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
8496 TypeParameter::Cast(primary->primary()).name()); 8496 TypeParameter::Cast(primary->primary()).name());
8497 selector = ThrowNoSuchMethodError(primary->token_pos(), 8497 selector = ThrowNoSuchMethodError(primary->token_pos(),
8498 current_class(), 8498 current_class(),
8499 name, 8499 name,
8500 NULL, // No arguments. 8500 NULL, // No arguments.
8501 InvocationMirror::kStatic, 8501 InvocationMirror::kStatic,
8502 InvocationMirror::kMethod, 8502 InvocationMirror::kMethod,
8503 NULL); // No existing function. 8503 NULL); // No existing function.
8504 } else if (primary->primary().IsClass()) { 8504 } else if (primary->primary().IsClass()) {
8505 const Class& type_class = Class::Cast(primary->primary()); 8505 const Class& type_class = Class::Cast(primary->primary());
8506 AbstractType& type = Type::ZoneHandle( 8506 AbstractType& type = Type::ZoneHandle(Type::New(
8507 Type::New(type_class, TypeArguments::Handle(), 8507 type_class, TypeArguments::Handle(), primary->token_pos()));
8508 primary->token_pos(), Heap::kOld));
8509 type ^= ClassFinalizer::FinalizeType( 8508 type ^= ClassFinalizer::FinalizeType(
8510 current_class(), type, ClassFinalizer::kCanonicalize); 8509 current_class(), type, ClassFinalizer::kCanonicalize);
8511 // Type may be malbounded, but not malformed. 8510 // Type may be malbounded, but not malformed.
8512 ASSERT(!type.IsMalformed()); 8511 ASSERT(!type.IsMalformed());
8513 selector = new TypeNode(primary->token_pos(), type); 8512 selector = new TypeNode(primary->token_pos(), type);
8514 } else { 8513 } else {
8515 UNREACHABLE(); // Internal parser error. 8514 UNREACHABLE(); // Internal parser error.
8516 } 8515 }
8517 } else { 8516 } else {
8518 // Left is not a primary node; this must be a closure call. 8517 // Left is not a primary node; this must be a closure call.
8519 AstNode* closure = left; 8518 AstNode* closure = left;
8520 selector = ParseClosureCall(closure); 8519 selector = ParseClosureCall(closure);
8521 } 8520 }
8522 } else { 8521 } else {
8523 // No (more) selectors to parse. 8522 // No (more) selectors to parse.
8524 left = LoadFieldIfUnresolved(left); 8523 left = LoadFieldIfUnresolved(left);
8525 if (left->IsPrimaryNode()) { 8524 if (left->IsPrimaryNode()) {
8526 PrimaryNode* primary = left->AsPrimaryNode(); 8525 PrimaryNode* primary = left->AsPrimaryNode();
8527 if (primary->primary().IsFunction()) { 8526 if (primary->primary().IsFunction()) {
8528 // Treat as implicit closure. 8527 // Treat as implicit closure.
8529 left = LoadClosure(primary); 8528 left = LoadClosure(primary);
8530 } else if (primary->primary().IsClass()) { 8529 } else if (primary->primary().IsClass()) {
8531 const Class& type_class = Class::Cast(primary->primary()); 8530 const Class& type_class = Class::Cast(primary->primary());
8532 AbstractType& type = Type::ZoneHandle( 8531 AbstractType& type = Type::ZoneHandle(Type::New(
8533 Type::New(type_class, TypeArguments::Handle(), 8532 type_class, TypeArguments::Handle(), primary->token_pos()));
8534 primary->token_pos(), Heap::kOld));
8535 type = ClassFinalizer::FinalizeType( 8533 type = ClassFinalizer::FinalizeType(
8536 current_class(), type, ClassFinalizer::kCanonicalize); 8534 current_class(), type, ClassFinalizer::kCanonicalize);
8537 // Type may be malbounded, but not malformed. 8535 // Type may be malbounded, but not malformed.
8538 ASSERT(!type.IsMalformed()); 8536 ASSERT(!type.IsMalformed());
8539 left = new TypeNode(primary->token_pos(), type); 8537 left = new TypeNode(primary->token_pos(), type);
8540 } else if (primary->primary().IsTypeParameter()) { 8538 } else if (primary->primary().IsTypeParameter()) {
8541 if (current_block_->scope->function_level() > 0) { 8539 if (current_block_->scope->function_level() > 0) {
8542 // Make sure that the instantiator is captured. 8540 // Make sure that the instantiator is captured.
8543 CaptureInstantiator(); 8541 CaptureInstantiator();
8544 } 8542 }
8545 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); 8543 TypeParameter& type_parameter = TypeParameter::ZoneHandle();
8546 type_parameter ^= ClassFinalizer::FinalizeType( 8544 type_parameter ^= ClassFinalizer::FinalizeType(
8547 current_class(), 8545 current_class(),
8548 TypeParameter::Cast(primary->primary()), 8546 TypeParameter::Cast(primary->primary()),
8549 ClassFinalizer::kFinalize); 8547 ClassFinalizer::kCanonicalize);
8550 ASSERT(!type_parameter.IsMalformed()); 8548 ASSERT(!type_parameter.IsMalformed());
8551 left = new TypeNode(primary->token_pos(), type_parameter); 8549 left = new TypeNode(primary->token_pos(), type_parameter);
8552 } else if (primary->IsSuper()) { 8550 } else if (primary->IsSuper()) {
8553 // Return "super" to handle unary super operator calls, 8551 // Return "super" to handle unary super operator calls,
8554 // or to report illegal use of "super" otherwise. 8552 // or to report illegal use of "super" otherwise.
8555 left = primary; 8553 left = primary;
8556 } else { 8554 } else {
8557 UNREACHABLE(); // Internal parser error. 8555 UNREACHABLE(); // Internal parser error.
8558 } 8556 }
8559 } 8557 }
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
9213 // Check whether the identifier is a type parameter. 9211 // Check whether the identifier is a type parameter.
9214 if (!current_class().IsNull()) { 9212 if (!current_class().IsNull()) {
9215 TypeParameter& type_parameter = TypeParameter::ZoneHandle( 9213 TypeParameter& type_parameter = TypeParameter::ZoneHandle(
9216 current_class().LookupTypeParameter(ident)); 9214 current_class().LookupTypeParameter(ident));
9217 if (!type_parameter.IsNull()) { 9215 if (!type_parameter.IsNull()) {
9218 if (current_block_->scope->function_level() > 0) { 9216 if (current_block_->scope->function_level() > 0) {
9219 // Make sure that the instantiator is captured. 9217 // Make sure that the instantiator is captured.
9220 CaptureInstantiator(); 9218 CaptureInstantiator();
9221 } 9219 }
9222 type_parameter ^= ClassFinalizer::FinalizeType( 9220 type_parameter ^= ClassFinalizer::FinalizeType(
9223 current_class(), type_parameter, ClassFinalizer::kFinalize); 9221 current_class(), type_parameter, ClassFinalizer::kCanonicalize);
9224 ASSERT(!type_parameter.IsMalformed()); 9222 ASSERT(!type_parameter.IsMalformed());
9225 return new TypeNode(ident_pos, type_parameter); 9223 return new TypeNode(ident_pos, type_parameter);
9226 } 9224 }
9227 } 9225 }
9228 // Not found in the local scope, and the name is not a type parameter. 9226 // Not found in the local scope, and the name is not a type parameter.
9229 // Try finding the variable in the library scope (current library 9227 // Try finding the variable in the library scope (current library
9230 // and all libraries imported by it without a library prefix). 9228 // and all libraries imported by it without a library prefix).
9231 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); 9229 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident);
9232 } 9230 }
9233 if (resolved->IsPrimaryNode()) { 9231 if (resolved->IsPrimaryNode()) {
(...skipping 19 matching lines...) Expand all
9253 } else if (primary->primary().IsFunction()) { 9251 } else if (primary->primary().IsFunction()) {
9254 if (allow_closure_names) { 9252 if (allow_closure_names) {
9255 resolved = LoadClosure(primary); 9253 resolved = LoadClosure(primary);
9256 } else { 9254 } else {
9257 ErrorMsg(ident_pos, "illegal reference to method '%s'", 9255 ErrorMsg(ident_pos, "illegal reference to method '%s'",
9258 ident.ToCString()); 9256 ident.ToCString());
9259 } 9257 }
9260 } else if (primary->primary().IsClass()) { 9258 } else if (primary->primary().IsClass()) {
9261 const Class& type_class = Class::Cast(primary->primary()); 9259 const Class& type_class = Class::Cast(primary->primary());
9262 AbstractType& type = Type::ZoneHandle( 9260 AbstractType& type = Type::ZoneHandle(
9263 Type::New(type_class, TypeArguments::Handle(), 9261 Type::New(type_class, TypeArguments::Handle(), primary->token_pos()));
9264 primary->token_pos(), Heap::kOld));
9265 type ^= ClassFinalizer::FinalizeType( 9262 type ^= ClassFinalizer::FinalizeType(
9266 current_class(), type, ClassFinalizer::kCanonicalize); 9263 current_class(), type, ClassFinalizer::kCanonicalize);
9267 // Type may be malbounded, but not malformed. 9264 // Type may be malbounded, but not malformed.
9268 ASSERT(!type.IsMalformed()); 9265 ASSERT(!type.IsMalformed());
9269 resolved = new TypeNode(primary->token_pos(), type); 9266 resolved = new TypeNode(primary->token_pos(), type);
9270 } 9267 }
9271 } 9268 }
9272 return resolved; 9269 return resolved;
9273 } 9270 }
9274 9271
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after
10754 void Parser::SkipQualIdent() { 10751 void Parser::SkipQualIdent() {
10755 ASSERT(IsIdentifier()); 10752 ASSERT(IsIdentifier());
10756 ConsumeToken(); 10753 ConsumeToken();
10757 if (CurrentToken() == Token::kPERIOD) { 10754 if (CurrentToken() == Token::kPERIOD) {
10758 ConsumeToken(); // Consume the kPERIOD token. 10755 ConsumeToken(); // Consume the kPERIOD token.
10759 ExpectIdentifier("identifier expected after '.'"); 10756 ExpectIdentifier("identifier expected after '.'");
10760 } 10757 }
10761 } 10758 }
10762 10759
10763 } // namespace dart 10760 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_store.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698