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

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

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