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

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

Issue 12321082: - Properly load the core libraries as libraries and not as scripts. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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
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 "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 4234 matching lines...) Expand 10 before | Expand all | Expand 10 after
4245 } 4245 }
4246 const String& name = *CurrentLiteral(); 4246 const String& name = *CurrentLiteral();
4247 ConsumeToken(); 4247 ConsumeToken();
4248 ExpectToken(Token::kRPAREN); 4248 ExpectToken(Token::kRPAREN);
4249 ExpectToken(Token::kSEMICOLON); 4249 ExpectToken(Token::kSEMICOLON);
4250 library_.SetName(name); 4250 library_.SetName(name);
4251 } 4251 }
4252 } 4252 }
4253 4253
4254 4254
4255 Dart_Handle Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 4255 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
4256 intptr_t token_pos, 4256 intptr_t token_pos,
4257 const String& url) { 4257 const String& url) {
4258 Isolate* isolate = Isolate::Current(); 4258 Isolate* isolate = Isolate::Current();
4259 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); 4259 Dart_LibraryTagHandler handler = isolate->library_tag_handler();
4260 if (handler == NULL) { 4260 if (handler == NULL) {
4261 if (url.StartsWith(Symbols::DartScheme())) {
4262 if (tag == kCanonicalizeUrl) {
4263 return url.raw();
4264 }
4265 return Object::null();
4266 }
4261 ErrorMsg(token_pos, "no library handler registered"); 4267 ErrorMsg(token_pos, "no library handler registered");
4262 } 4268 }
4263 Dart_Handle result = handler(tag, 4269 Dart_Handle result = handler(tag,
4264 Api::NewHandle(isolate, library_.raw()), 4270 Api::NewHandle(isolate, library_.raw()),
4265 Api::NewHandle(isolate, url.raw())); 4271 Api::NewHandle(isolate, url.raw()));
4266 if (Dart_IsError(result)) { 4272 if (Dart_IsError(result)) {
4273 // In case of an error we append an explanatory error message to the
4274 // error obtained from the library tag handler.
4267 Error& prev_error = Error::Handle(); 4275 Error& prev_error = Error::Handle();
4268 prev_error ^= Api::UnwrapHandle(result); 4276 prev_error ^= Api::UnwrapHandle(result);
4269 AppendErrorMsg(prev_error, token_pos, "library handler failed"); 4277 AppendErrorMsg(prev_error, token_pos, "library handler failed");
4270 } 4278 }
4271 return result; 4279 if (tag == kCanonicalizeUrl) {
4280 if (!Dart_IsString(result)) {
4281 ErrorMsg(token_pos, "library handler failed URI canonicalization");
4282 }
4283 }
4284 return Api::UnwrapHandle(result);
4272 } 4285 }
4273 4286
4274 4287
4275 // TODO(hausner): Remove support for old library definition syntax. 4288 // TODO(hausner): Remove support for old library definition syntax.
4276 void Parser::ParseLibraryImportObsoleteSyntax() { 4289 void Parser::ParseLibraryImportObsoleteSyntax() {
4277 while (CurrentToken() == Token::kLEGACY_IMPORT) { 4290 while (CurrentToken() == Token::kLEGACY_IMPORT) {
4278 const intptr_t import_pos = TokenPos(); 4291 const intptr_t import_pos = TokenPos();
4279 ConsumeToken(); 4292 ConsumeToken();
4280 ExpectToken(Token::kLPAREN); 4293 ExpectToken(Token::kLPAREN);
4281 if (CurrentToken() != Token::kSTRING) { 4294 if (CurrentToken() != Token::kSTRING) {
(...skipping 14 matching lines...) Expand all
4296 } 4309 }
4297 prefix = CurrentLiteral()->raw(); 4310 prefix = CurrentLiteral()->raw();
4298 // TODO(asiva): Need to also check that prefix is not a reserved keyword. 4311 // TODO(asiva): Need to also check that prefix is not a reserved keyword.
4299 if (!Scanner::IsIdent(prefix)) { 4312 if (!Scanner::IsIdent(prefix)) {
4300 ErrorMsg("prefix should be an identifier"); 4313 ErrorMsg("prefix should be an identifier");
4301 } 4314 }
4302 ConsumeToken(); 4315 ConsumeToken();
4303 } 4316 }
4304 ExpectToken(Token::kRPAREN); 4317 ExpectToken(Token::kRPAREN);
4305 ExpectToken(Token::kSEMICOLON); 4318 ExpectToken(Token::kSEMICOLON);
4306 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, 4319 const String& canon_url = String::CheckedHandle(
4307 import_pos, 4320 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url));
4308 url);
4309 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
4310 // Lookup the library URL. 4321 // Lookup the library URL.
4311 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); 4322 Library& library = Library::Handle(Library::LookupLibrary(canon_url));
4312 if (library.IsNull()) { 4323 if (library.IsNull()) {
4313 // Call the library tag handler to load the library. 4324 // Call the library tag handler to load the library.
4314 CallLibraryTagHandler(kImportTag, import_pos, canon_url); 4325 CallLibraryTagHandler(kImportTag, import_pos, canon_url);
4315 // If the library tag handler succeded without registering the 4326 // If the library tag handler succeded without registering the
4316 // library we create an empty library to import. 4327 // library we create an empty library to import.
4317 library = Library::LookupLibrary(canon_url); 4328 library = Library::LookupLibrary(canon_url);
4318 if (library.IsNull()) { 4329 if (library.IsNull()) {
4319 library = Library::New(canon_url); 4330 library = Library::New(canon_url);
(...skipping 25 matching lines...) Expand all
4345 const intptr_t source_pos = TokenPos(); 4356 const intptr_t source_pos = TokenPos();
4346 ConsumeToken(); 4357 ConsumeToken();
4347 ExpectToken(Token::kLPAREN); 4358 ExpectToken(Token::kLPAREN);
4348 if (CurrentToken() != Token::kSTRING) { 4359 if (CurrentToken() != Token::kSTRING) {
4349 ErrorMsg("source url expected"); 4360 ErrorMsg("source url expected");
4350 } 4361 }
4351 const String& url = *CurrentLiteral(); 4362 const String& url = *CurrentLiteral();
4352 ConsumeToken(); 4363 ConsumeToken();
4353 ExpectToken(Token::kRPAREN); 4364 ExpectToken(Token::kRPAREN);
4354 ExpectToken(Token::kSEMICOLON); 4365 ExpectToken(Token::kSEMICOLON);
4355 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, 4366 const String& canon_url = String::CheckedHandle(
4356 source_pos, 4367 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url));
4357 url);
4358 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
4359 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); 4368 CallLibraryTagHandler(kSourceTag, source_pos, canon_url);
4360 } 4369 }
4361 } 4370 }
4362 4371
4363 4372
4364 void Parser::ParseLibraryName() { 4373 void Parser::ParseLibraryName() {
4365 ASSERT(CurrentToken() == Token::kLIBRARY); 4374 ASSERT(CurrentToken() == Token::kLIBRARY);
4366 ConsumeToken(); 4375 ConsumeToken();
4367 String& lib_name = *ExpectIdentifier("library name expected"); 4376 String& lib_name = *ExpectIdentifier("library name expected");
4368 if (CurrentToken() == Token::kPERIOD) { 4377 if (CurrentToken() == Token::kPERIOD) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
4435 if (show_list.Length() > 0) { 4444 if (show_list.Length() > 0) {
4436 show_names = Array::MakeArray(show_list); 4445 show_names = Array::MakeArray(show_list);
4437 } 4446 }
4438 if (hide_list.Length() > 0) { 4447 if (hide_list.Length() > 0) {
4439 hide_names = Array::MakeArray(hide_list); 4448 hide_names = Array::MakeArray(hide_list);
4440 } 4449 }
4441 } 4450 }
4442 ExpectSemicolon(); 4451 ExpectSemicolon();
4443 4452
4444 // Canonicalize library URL. 4453 // Canonicalize library URL.
4445 Dart_Handle handle = 4454 const String& canon_url = String::CheckedHandle(
4446 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url); 4455 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url));
4447 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
4448 // Lookup the library URL. 4456 // Lookup the library URL.
4449 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); 4457 Library& library = Library::Handle(Library::LookupLibrary(canon_url));
4450 if (library.IsNull()) { 4458 if (library.IsNull()) {
4451 // Call the library tag handler to load the library. 4459 // Call the library tag handler to load the library.
4452 CallLibraryTagHandler(kImportTag, import_pos, canon_url); 4460 CallLibraryTagHandler(kImportTag, import_pos, canon_url);
4453 // If the library tag handler succeded without registering the 4461 // If the library tag handler succeded without registering the
4454 // library we create an empty library to import. 4462 // library we create an empty library to import.
4455 library = Library::LookupLibrary(canon_url); 4463 library = Library::LookupLibrary(canon_url);
4456 if (library.IsNull()) { 4464 if (library.IsNull()) {
4457 library = Library::New(canon_url); 4465 library = Library::New(canon_url);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4489 4497
4490 void Parser::ParseLibraryPart() { 4498 void Parser::ParseLibraryPart() {
4491 const intptr_t source_pos = TokenPos(); 4499 const intptr_t source_pos = TokenPos();
4492 ConsumeToken(); // Consume "part". 4500 ConsumeToken(); // Consume "part".
4493 if (CurrentToken() != Token::kSTRING) { 4501 if (CurrentToken() != Token::kSTRING) {
4494 ErrorMsg("url expected"); 4502 ErrorMsg("url expected");
4495 } 4503 }
4496 const String& url = *CurrentLiteral(); 4504 const String& url = *CurrentLiteral();
4497 ConsumeToken(); 4505 ConsumeToken();
4498 ExpectSemicolon(); 4506 ExpectSemicolon();
4499 Dart_Handle handle = 4507 const String& canon_url = String::CheckedHandle(
4500 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url); 4508 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url));
4501 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
4502 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); 4509 CallLibraryTagHandler(kSourceTag, source_pos, canon_url);
4503 } 4510 }
4504 4511
4505 4512
4506 void Parser::ParseLibraryDefinition() { 4513 void Parser::ParseLibraryDefinition() {
4507 TRACE_PARSER("ParseLibraryDefinition"); 4514 TRACE_PARSER("ParseLibraryDefinition");
4508 4515
4509 // Handle the script tag. 4516 // Handle the script tag.
4510 if (CurrentToken() == Token::kSCRIPTTAG) { 4517 if (CurrentToken() == Token::kSCRIPTTAG) {
4511 // Nothing to do for script tags except to skip them. 4518 // Nothing to do for script tags except to skip them.
(...skipping 14 matching lines...) Expand all
4526 ASSERT(!core_lib.IsNull()); 4533 ASSERT(!core_lib.IsNull());
4527 const Namespace& core_ns = Namespace::Handle( 4534 const Namespace& core_ns = Namespace::Handle(
4528 Namespace::New(core_lib, Array::Handle(), Array::Handle())); 4535 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
4529 library_.AddImport(core_ns); 4536 library_.AddImport(core_ns);
4530 } 4537 }
4531 return; 4538 return;
4532 } 4539 }
4533 4540
4534 const bool is_script = (script_.kind() == RawScript::kScriptTag); 4541 const bool is_script = (script_.kind() == RawScript::kScriptTag);
4535 const bool is_library = (script_.kind() == RawScript::kLibraryTag); 4542 const bool is_library = (script_.kind() == RawScript::kLibraryTag);
4543 const bool is_patch = (script_.kind() == RawScript::kPatchTag);
4536 ASSERT(script_.kind() != RawScript::kSourceTag); 4544 ASSERT(script_.kind() != RawScript::kSourceTag);
4537 4545
4538 // We may read metadata tokens that are part of the toplevel 4546 // We may read metadata tokens that are part of the toplevel
4539 // declaration that follows the library definitions. Therefore, we 4547 // declaration that follows the library definitions. Therefore, we
4540 // need to remember the position of the last token that was 4548 // need to remember the position of the last token that was
4541 // successfully consumed. 4549 // successfully consumed.
4542 intptr_t metadata_pos = TokenPos(); 4550 intptr_t metadata_pos = TokenPos();
4543 SkipMetadata(); 4551 SkipMetadata();
4544 if (CurrentToken() == Token::kLIBRARY) { 4552 if (CurrentToken() == Token::kLIBRARY) {
4553 if (is_patch) {
4554 ErrorMsg("patch cannot override library name");
4555 }
4545 ParseLibraryName(); 4556 ParseLibraryName();
4546 metadata_pos = TokenPos(); 4557 metadata_pos = TokenPos();
4547 SkipMetadata(); 4558 SkipMetadata();
4548 } else if (is_library) { 4559 } else if (is_library) {
4549 ErrorMsg("library name definition expected"); 4560 ErrorMsg("library name definition expected");
4550 } 4561 }
4551 while ((CurrentToken() == Token::kIMPORT) || 4562 while ((CurrentToken() == Token::kIMPORT) ||
4552 (CurrentToken() == Token::kEXPORT)) { 4563 (CurrentToken() == Token::kEXPORT)) {
4553 if (is_script && (CurrentToken() == Token::kEXPORT)) { 4564 if (is_script && (CurrentToken() == Token::kEXPORT)) {
4554 ErrorMsg("export not allowed in scripts"); 4565 ErrorMsg("export not allowed in scripts");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4610 ObjectStore* object_store = isolate->object_store(); 4621 ObjectStore* object_store = isolate->object_store();
4611 const GrowableObjectArray& pending_classes = 4622 const GrowableObjectArray& pending_classes =
4612 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); 4623 GrowableObjectArray::Handle(isolate, object_store->pending_classes());
4613 SetPosition(0); 4624 SetPosition(0);
4614 is_top_level_ = true; 4625 is_top_level_ = true;
4615 TopLevel top_level; 4626 TopLevel top_level;
4616 Class& toplevel_class = Class::Handle( 4627 Class& toplevel_class = Class::Handle(
4617 Class::New(Symbols::TopLevel(), script_, TokenPos())); 4628 Class::New(Symbols::TopLevel(), script_, TokenPos()));
4618 toplevel_class.set_library(library_); 4629 toplevel_class.set_library(library_);
4619 4630
4620 if (is_library_source()) { 4631 if (is_library_source() || is_patch_source()) {
4621 ParseLibraryDefinition(); 4632 ParseLibraryDefinition();
4622 } else if (is_part_source()) { 4633 } else if (is_part_source()) {
4623 ParsePartHeader(); 4634 ParsePartHeader();
4624 } 4635 }
4625 4636
4626 while (true) { 4637 while (true) {
4627 set_current_class(Class::Handle()); // No current class. 4638 set_current_class(Class::Handle()); // No current class.
4628 SkipMetadata(); 4639 SkipMetadata();
4629 if (CurrentToken() == Token::kCLASS) { 4640 if (CurrentToken() == Token::kCLASS) {
4630 ParseClassDefinition(pending_classes); 4641 ParseClassDefinition(pending_classes);
(...skipping 5411 matching lines...) Expand 10 before | Expand all | Expand 10 after
10042 void Parser::SkipQualIdent() { 10053 void Parser::SkipQualIdent() {
10043 ASSERT(IsIdentifier()); 10054 ASSERT(IsIdentifier());
10044 ConsumeToken(); 10055 ConsumeToken();
10045 if (CurrentToken() == Token::kPERIOD) { 10056 if (CurrentToken() == Token::kPERIOD) {
10046 ConsumeToken(); // Consume the kPERIOD token. 10057 ConsumeToken(); // Consume the kPERIOD token.
10047 ExpectIdentifier("identifier expected after '.'"); 10058 ExpectIdentifier("identifier expected after '.'");
10048 } 10059 }
10049 } 10060 }
10050 10061
10051 } // namespace dart 10062 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698