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

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

Issue 10332257: Revert my last change. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/parser.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 "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 3508 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 ConsumeToken(); 3519 ConsumeToken();
3520 ExpectToken(Token::kRPAREN); 3520 ExpectToken(Token::kRPAREN);
3521 ExpectToken(Token::kSEMICOLON); 3521 ExpectToken(Token::kSEMICOLON);
3522 library_.SetName(name); 3522 library_.SetName(name);
3523 } 3523 }
3524 } 3524 }
3525 3525
3526 3526
3527 Dart_Handle Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 3527 Dart_Handle Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
3528 intptr_t token_pos, 3528 intptr_t token_pos,
3529 const String& url) { 3529 const String& url,
3530 const Array& import_map) {
3530 Isolate* isolate = Isolate::Current(); 3531 Isolate* isolate = Isolate::Current();
3531 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); 3532 Dart_LibraryTagHandler handler = isolate->library_tag_handler();
3532 if (handler == NULL) { 3533 if (handler == NULL) {
3533 ErrorMsg(token_pos, "no library handler registered"); 3534 ErrorMsg(token_pos, "no library handler registered");
3534 } 3535 }
3535 Dart_Handle result = handler(tag, 3536 Dart_Handle result = handler(tag,
3536 Api::NewHandle(isolate, library_.raw()), 3537 Api::NewHandle(isolate, library_.raw()),
3537 Api::NewHandle(isolate, url.raw())); 3538 Api::NewHandle(isolate, url.raw()),
3539 Api::NewHandle(isolate, import_map.raw()));
3538 if (Dart_IsError(result)) { 3540 if (Dart_IsError(result)) {
3539 Error& prev_error = Error::Handle(); 3541 Error& prev_error = Error::Handle();
3540 prev_error ^= Api::UnwrapHandle(result); 3542 prev_error ^= Api::UnwrapHandle(result);
3541 AppendErrorMsg(prev_error, token_pos, "library handler failed"); 3543 AppendErrorMsg(prev_error, token_pos, "library handler failed");
3542 } 3544 }
3543 return result; 3545 return result;
3544 } 3546 }
3545 3547
3546 3548
3547 void Parser::ParseLibraryImport() { 3549 void Parser::ParseLibraryImport() {
(...skipping 19 matching lines...) Expand all
3567 } 3569 }
3568 prefix = CurrentLiteral()->raw(); 3570 prefix = CurrentLiteral()->raw();
3569 // TODO(asiva): Need to also check that prefix is not a reserved keyword. 3571 // TODO(asiva): Need to also check that prefix is not a reserved keyword.
3570 if (!Scanner::IsIdent(prefix)) { 3572 if (!Scanner::IsIdent(prefix)) {
3571 ErrorMsg("prefix should be an identifier"); 3573 ErrorMsg("prefix should be an identifier");
3572 } 3574 }
3573 ConsumeToken(); 3575 ConsumeToken();
3574 } 3576 }
3575 ExpectToken(Token::kRPAREN); 3577 ExpectToken(Token::kRPAREN);
3576 ExpectToken(Token::kSEMICOLON); 3578 ExpectToken(Token::kSEMICOLON);
3579 const Array& import_map = Array::Handle(library_.import_map());
3577 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, 3580 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl,
3578 import_pos, 3581 import_pos,
3579 url); 3582 url,
3583 import_map);
3580 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 3584 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
3581 // Lookup the library URL. 3585 // Lookup the library URL.
3582 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); 3586 Library& library = Library::Handle(Library::LookupLibrary(canon_url));
3583 if (library.IsNull()) { 3587 if (library.IsNull()) {
3584 // Call the library tag handler to load the library. 3588 // Call the library tag handler to load the library.
3585 CallLibraryTagHandler(kImportTag, import_pos, canon_url); 3589 CallLibraryTagHandler(kImportTag, import_pos, canon_url, import_map);
3586 // If the library tag handler succeded without registering the 3590 // If the library tag handler succeded without registering the
3587 // library we create an empty library to import. 3591 // library we create an empty library to import.
3588 library = Library::LookupLibrary(canon_url); 3592 library = Library::LookupLibrary(canon_url);
3589 if (library.IsNull()) { 3593 if (library.IsNull()) {
3590 library = Library::New(canon_url); 3594 library = Library::New(canon_url);
3591 library.Register(); 3595 library.Register();
3592 } 3596 }
3593 } 3597 }
3594 // Add the import to the library. 3598 // Add the import to the library.
3595 if (prefix.IsNull() || (prefix.Length() == 0)) { 3599 if (prefix.IsNull() || (prefix.Length() == 0)) {
3596 library_.AddImport(library); 3600 library_.AddImport(library);
3597 } else { 3601 } else {
3598 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); 3602 LibraryPrefix& library_prefix = LibraryPrefix::Handle();
3599 library_prefix = library_.LookupLocalLibraryPrefix(prefix); 3603 library_prefix = library_.LookupLocalLibraryPrefix(prefix);
3600 if (!library_prefix.IsNull()) { 3604 if (!library_prefix.IsNull()) {
3601 library_prefix.AddLibrary(library); 3605 library_prefix.AddLibrary(library);
3602 } else { 3606 } else {
3603 library_prefix = LibraryPrefix::New(prefix, library); 3607 library_prefix = LibraryPrefix::New(prefix, library);
3604 library_.AddObject(library_prefix, prefix); 3608 library_.AddObject(library_prefix, prefix);
3605 } 3609 }
3606 } 3610 }
3607 } 3611 }
3608 } 3612 }
3609 3613
3610 3614
3611 void Parser::ParseLibraryInclude() { 3615 void Parser::ParseLibraryInclude() {
3612 TRACE_PARSER("ParseLibraryInclude"); 3616 TRACE_PARSER("ParseLibraryInclude");
3617 const Array& import_map = Array::Handle(library_.import_map());
3613 while (CurrentToken() == Token::kSOURCE) { 3618 while (CurrentToken() == Token::kSOURCE) {
3614 const intptr_t source_pos = token_index_; 3619 const intptr_t source_pos = token_index_;
3615 ConsumeToken(); 3620 ConsumeToken();
3616 ExpectToken(Token::kLPAREN); 3621 ExpectToken(Token::kLPAREN);
3617 if (CurrentToken() != Token::kSTRING) { 3622 if (CurrentToken() != Token::kSTRING) {
3618 ErrorMsg("source url expected"); 3623 ErrorMsg("source url expected");
3619 } 3624 }
3620 const String& url = *ParseImportStringLiteral(); 3625 const String& url = *ParseImportStringLiteral();
3621 ExpectToken(Token::kRPAREN); 3626 ExpectToken(Token::kRPAREN);
3622 ExpectToken(Token::kSEMICOLON); 3627 ExpectToken(Token::kSEMICOLON);
3623 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, 3628 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl,
3624 source_pos, 3629 source_pos,
3625 url); 3630 url,
3631 import_map);
3626 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 3632 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
3627 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); 3633 CallLibraryTagHandler(kSourceTag, source_pos, canon_url, import_map);
3628 } 3634 }
3629 } 3635 }
3630 3636
3631 3637
3632 void Parser::ParseLibraryResource() { 3638 void Parser::ParseLibraryResource() {
3633 TRACE_PARSER("ParseLibraryResource"); 3639 TRACE_PARSER("ParseLibraryResource");
3634 while (CurrentToken() == Token::kRESOURCE) { 3640 while (CurrentToken() == Token::kRESOURCE) {
3635 // Currently the VM does ignore #resource library tags. They are only used 3641 // Currently the VM does ignore #resource library tags. They are only used
3636 // by the IDE. 3642 // by the IDE.
3637 ConsumeToken(); 3643 ConsumeToken();
(...skipping 3549 matching lines...) Expand 10 before | Expand all | Expand 10 after
7187 return var_or_field; 7193 return var_or_field;
7188 } 7194 }
7189 7195
7190 7196
7191 // Resolve variables used in an import string literal. 7197 // Resolve variables used in an import string literal.
7192 // If the variable name cannot be resolved issue an error message. 7198 // If the variable name cannot be resolved issue an error message.
7193 // Currently we only resolve against the global map which is passed in 7199 // Currently we only resolve against the global map which is passed in
7194 // when the script is loaded. 7200 // when the script is loaded.
7195 RawString* Parser::ResolveImportVar(intptr_t ident_pos, const String& ident) { 7201 RawString* Parser::ResolveImportVar(intptr_t ident_pos, const String& ident) {
7196 TRACE_PARSER("ResolveImportVar"); 7202 TRACE_PARSER("ResolveImportVar");
7197 const Array& import_map = 7203 String& map_name = String::Handle(library_.LookupImportMap(ident));
7198 Array::Handle(Isolate::Current()->object_store()->import_map()); 7204 if (!map_name.IsNull()) {
7199 if (!import_map.IsNull()) { 7205 return map_name.raw();
7200 intptr_t length = import_map.Length();
7201 intptr_t index = 0;
7202 String& name = String::Handle();
7203 while (index < (length - 1)) {
7204 name ^= import_map.At(index);
7205 if (name.Equals(ident)) {
7206 name ^= import_map.At(index + 1);
7207 return name.raw();
7208 }
7209 index += 2;
7210 }
7211 } 7206 }
7212 ErrorMsg(ident_pos, "import variable '%s' has not been defined", 7207 ErrorMsg(ident_pos, "import variable '%s' has not been defined",
7213 ident.ToCString()); 7208 ident.ToCString());
7214 return String::null(); 7209 return String::null();
7215 } 7210 }
7216 7211
7217 7212
7218 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and 7213 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and
7219 // finalize it according to the given type finalization mode. 7214 // finalize it according to the given type finalization mode.
7220 RawAbstractType* Parser::ParseType( 7215 RawAbstractType* Parser::ParseType(
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
8468 void Parser::SkipQualIdent() { 8463 void Parser::SkipQualIdent() {
8469 ASSERT(IsIdentifier()); 8464 ASSERT(IsIdentifier());
8470 ConsumeToken(); 8465 ConsumeToken();
8471 if (CurrentToken() == Token::kPERIOD) { 8466 if (CurrentToken() == Token::kPERIOD) {
8472 ConsumeToken(); // Consume the kPERIOD token. 8467 ConsumeToken(); // Consume the kPERIOD token.
8473 ExpectIdentifier("identifier expected after '.'"); 8468 ExpectIdentifier("identifier expected after '.'");
8474 } 8469 }
8475 } 8470 }
8476 8471
8477 } // namespace dart 8472 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698