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 "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 Loading... | |
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)) { |
4267 Error& prev_error = Error::Handle(); | 4273 Error& prev_error = Error::Handle(); |
4268 prev_error ^= Api::UnwrapHandle(result); | 4274 prev_error ^= Api::UnwrapHandle(result); |
4269 AppendErrorMsg(prev_error, token_pos, "library handler failed"); | 4275 AppendErrorMsg(prev_error, token_pos, "library handler failed"); |
4276 UNREACHABLE(); | |
siva
2013/02/23 00:11:03
Why UNREACHABLE here (AppendErrorMsg already has o
Ivan Posva
2013/02/25 22:20:14
I wanted to make it clear that we will not be able
| |
4270 } | 4277 } |
4271 return result; | 4278 if (tag == kCanonicalizeUrl) { |
4279 if (!Dart_IsString(result)) { | |
4280 ErrorMsg(token_pos, "library handler failed URI canonicalization"); | |
4281 } | |
4282 } | |
4283 return Api::UnwrapHandle(result); | |
4272 } | 4284 } |
4273 | 4285 |
4274 | 4286 |
4275 // TODO(hausner): Remove support for old library definition syntax. | 4287 // TODO(hausner): Remove support for old library definition syntax. |
4276 void Parser::ParseLibraryImportObsoleteSyntax() { | 4288 void Parser::ParseLibraryImportObsoleteSyntax() { |
4277 while (CurrentToken() == Token::kLEGACY_IMPORT) { | 4289 while (CurrentToken() == Token::kLEGACY_IMPORT) { |
4278 const intptr_t import_pos = TokenPos(); | 4290 const intptr_t import_pos = TokenPos(); |
4279 ConsumeToken(); | 4291 ConsumeToken(); |
4280 ExpectToken(Token::kLPAREN); | 4292 ExpectToken(Token::kLPAREN); |
4281 if (CurrentToken() != Token::kSTRING) { | 4293 if (CurrentToken() != Token::kSTRING) { |
(...skipping 14 matching lines...) Expand all Loading... | |
4296 } | 4308 } |
4297 prefix = CurrentLiteral()->raw(); | 4309 prefix = CurrentLiteral()->raw(); |
4298 // TODO(asiva): Need to also check that prefix is not a reserved keyword. | 4310 // TODO(asiva): Need to also check that prefix is not a reserved keyword. |
4299 if (!Scanner::IsIdent(prefix)) { | 4311 if (!Scanner::IsIdent(prefix)) { |
4300 ErrorMsg("prefix should be an identifier"); | 4312 ErrorMsg("prefix should be an identifier"); |
4301 } | 4313 } |
4302 ConsumeToken(); | 4314 ConsumeToken(); |
4303 } | 4315 } |
4304 ExpectToken(Token::kRPAREN); | 4316 ExpectToken(Token::kRPAREN); |
4305 ExpectToken(Token::kSEMICOLON); | 4317 ExpectToken(Token::kSEMICOLON); |
4306 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, | 4318 const String& canon_url = String::CheckedHandle( |
4307 import_pos, | 4319 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url)); |
4308 url); | |
4309 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | |
4310 // Lookup the library URL. | 4320 // Lookup the library URL. |
4311 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); | 4321 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); |
4312 if (library.IsNull()) { | 4322 if (library.IsNull()) { |
4313 // Call the library tag handler to load the library. | 4323 // Call the library tag handler to load the library. |
4314 CallLibraryTagHandler(kImportTag, import_pos, canon_url); | 4324 CallLibraryTagHandler(kImportTag, import_pos, canon_url); |
4315 // If the library tag handler succeded without registering the | 4325 // If the library tag handler succeded without registering the |
4316 // library we create an empty library to import. | 4326 // library we create an empty library to import. |
4317 library = Library::LookupLibrary(canon_url); | 4327 library = Library::LookupLibrary(canon_url); |
4318 if (library.IsNull()) { | 4328 if (library.IsNull()) { |
4319 library = Library::New(canon_url); | 4329 library = Library::New(canon_url); |
(...skipping 25 matching lines...) Expand all Loading... | |
4345 const intptr_t source_pos = TokenPos(); | 4355 const intptr_t source_pos = TokenPos(); |
4346 ConsumeToken(); | 4356 ConsumeToken(); |
4347 ExpectToken(Token::kLPAREN); | 4357 ExpectToken(Token::kLPAREN); |
4348 if (CurrentToken() != Token::kSTRING) { | 4358 if (CurrentToken() != Token::kSTRING) { |
4349 ErrorMsg("source url expected"); | 4359 ErrorMsg("source url expected"); |
4350 } | 4360 } |
4351 const String& url = *CurrentLiteral(); | 4361 const String& url = *CurrentLiteral(); |
4352 ConsumeToken(); | 4362 ConsumeToken(); |
4353 ExpectToken(Token::kRPAREN); | 4363 ExpectToken(Token::kRPAREN); |
4354 ExpectToken(Token::kSEMICOLON); | 4364 ExpectToken(Token::kSEMICOLON); |
4355 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, | 4365 const String& canon_url = String::CheckedHandle( |
4356 source_pos, | 4366 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url)); |
4357 url); | |
4358 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | |
4359 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); | 4367 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); |
4360 } | 4368 } |
4361 } | 4369 } |
4362 | 4370 |
4363 | 4371 |
4364 void Parser::ParseLibraryName() { | 4372 void Parser::ParseLibraryName() { |
4365 ASSERT(CurrentToken() == Token::kLIBRARY); | 4373 ASSERT(CurrentToken() == Token::kLIBRARY); |
4366 ConsumeToken(); | 4374 ConsumeToken(); |
4367 String& lib_name = *ExpectIdentifier("library name expected"); | 4375 String& lib_name = *ExpectIdentifier("library name expected"); |
4368 if (CurrentToken() == Token::kPERIOD) { | 4376 if (CurrentToken() == Token::kPERIOD) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4435 if (show_list.Length() > 0) { | 4443 if (show_list.Length() > 0) { |
4436 show_names = Array::MakeArray(show_list); | 4444 show_names = Array::MakeArray(show_list); |
4437 } | 4445 } |
4438 if (hide_list.Length() > 0) { | 4446 if (hide_list.Length() > 0) { |
4439 hide_names = Array::MakeArray(hide_list); | 4447 hide_names = Array::MakeArray(hide_list); |
4440 } | 4448 } |
4441 } | 4449 } |
4442 ExpectSemicolon(); | 4450 ExpectSemicolon(); |
4443 | 4451 |
4444 // Canonicalize library URL. | 4452 // Canonicalize library URL. |
4445 Dart_Handle handle = | 4453 const String& canon_url = String::CheckedHandle( |
4446 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url); | 4454 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url)); |
4447 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | |
4448 // Lookup the library URL. | 4455 // Lookup the library URL. |
4449 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); | 4456 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); |
4450 if (library.IsNull()) { | 4457 if (library.IsNull()) { |
4451 // Call the library tag handler to load the library. | 4458 // Call the library tag handler to load the library. |
4452 CallLibraryTagHandler(kImportTag, import_pos, canon_url); | 4459 CallLibraryTagHandler(kImportTag, import_pos, canon_url); |
4453 // If the library tag handler succeded without registering the | 4460 // If the library tag handler succeded without registering the |
4454 // library we create an empty library to import. | 4461 // library we create an empty library to import. |
4455 library = Library::LookupLibrary(canon_url); | 4462 library = Library::LookupLibrary(canon_url); |
4456 if (library.IsNull()) { | 4463 if (library.IsNull()) { |
4457 library = Library::New(canon_url); | 4464 library = Library::New(canon_url); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4489 | 4496 |
4490 void Parser::ParseLibraryPart() { | 4497 void Parser::ParseLibraryPart() { |
4491 const intptr_t source_pos = TokenPos(); | 4498 const intptr_t source_pos = TokenPos(); |
4492 ConsumeToken(); // Consume "part". | 4499 ConsumeToken(); // Consume "part". |
4493 if (CurrentToken() != Token::kSTRING) { | 4500 if (CurrentToken() != Token::kSTRING) { |
4494 ErrorMsg("url expected"); | 4501 ErrorMsg("url expected"); |
4495 } | 4502 } |
4496 const String& url = *CurrentLiteral(); | 4503 const String& url = *CurrentLiteral(); |
4497 ConsumeToken(); | 4504 ConsumeToken(); |
4498 ExpectSemicolon(); | 4505 ExpectSemicolon(); |
4499 Dart_Handle handle = | 4506 const String& canon_url = String::CheckedHandle( |
4500 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url); | 4507 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url)); |
4501 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | |
4502 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); | 4508 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); |
4503 } | 4509 } |
4504 | 4510 |
4505 | 4511 |
4506 void Parser::ParseLibraryDefinition() { | 4512 void Parser::ParseLibraryDefinition() { |
4507 TRACE_PARSER("ParseLibraryDefinition"); | 4513 TRACE_PARSER("ParseLibraryDefinition"); |
4508 | 4514 |
4509 // Handle the script tag. | 4515 // Handle the script tag. |
4510 if (CurrentToken() == Token::kSCRIPTTAG) { | 4516 if (CurrentToken() == Token::kSCRIPTTAG) { |
4511 // Nothing to do for script tags except to skip them. | 4517 // Nothing to do for script tags except to skip them. |
(...skipping 5530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10042 void Parser::SkipQualIdent() { | 10048 void Parser::SkipQualIdent() { |
10043 ASSERT(IsIdentifier()); | 10049 ASSERT(IsIdentifier()); |
10044 ConsumeToken(); | 10050 ConsumeToken(); |
10045 if (CurrentToken() == Token::kPERIOD) { | 10051 if (CurrentToken() == Token::kPERIOD) { |
10046 ConsumeToken(); // Consume the kPERIOD token. | 10052 ConsumeToken(); // Consume the kPERIOD token. |
10047 ExpectIdentifier("identifier expected after '.'"); | 10053 ExpectIdentifier("identifier expected after '.'"); |
10048 } | 10054 } |
10049 } | 10055 } |
10050 | 10056 |
10051 } // namespace dart | 10057 } // namespace dart |
OLD | NEW |