| 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 "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 4315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4326 // TODO(hausner): Exact syntax of library name still unclear: identifier, | 4326 // TODO(hausner): Exact syntax of library name still unclear: identifier, |
| 4327 // qualified identifier or even multiple dots allowed? For now we just | 4327 // qualified identifier or even multiple dots allowed? For now we just |
| 4328 // accept simple identifiers. | 4328 // accept simple identifiers. |
| 4329 const String& lib_name = *ExpectIdentifier("library name expected"); | 4329 const String& lib_name = *ExpectIdentifier("library name expected"); |
| 4330 library_.SetName(lib_name); | 4330 library_.SetName(lib_name); |
| 4331 ExpectSemicolon(); | 4331 ExpectSemicolon(); |
| 4332 } | 4332 } |
| 4333 | 4333 |
| 4334 | 4334 |
| 4335 void Parser::ParseIdentList(GrowableObjectArray* names) { | 4335 void Parser::ParseIdentList(GrowableObjectArray* names) { |
| 4336 if (!IsIdentifier()) { |
| 4337 ErrorMsg("identifier expected"); |
| 4338 } |
| 4336 while (IsIdentifier()) { | 4339 while (IsIdentifier()) { |
| 4337 names->Add(*CurrentLiteral()); | 4340 names->Add(*CurrentLiteral()); |
| 4338 ConsumeToken(); // Identifier. | 4341 ConsumeToken(); // Identifier. |
| 4339 if (CurrentToken() != Token::kCOMMA) { | 4342 if (CurrentToken() != Token::kCOMMA) { |
| 4340 return; | 4343 return; |
| 4341 } | 4344 } |
| 4342 ConsumeToken(); // Comma. | 4345 ConsumeToken(); // Comma. |
| 4343 } | 4346 } |
| 4344 } | 4347 } |
| 4345 | 4348 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4467 if (!library_.ImportsCorelib()) { | 4470 if (!library_.ImportsCorelib()) { |
| 4468 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 4471 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 4469 ASSERT(!core_lib.IsNull()); | 4472 ASSERT(!core_lib.IsNull()); |
| 4470 const Namespace& core_ns = Namespace::Handle( | 4473 const Namespace& core_ns = Namespace::Handle( |
| 4471 Namespace::New(core_lib, Array::Handle(), Array::Handle())); | 4474 Namespace::New(core_lib, Array::Handle(), Array::Handle())); |
| 4472 library_.AddImport(core_ns); | 4475 library_.AddImport(core_ns); |
| 4473 } | 4476 } |
| 4474 return; | 4477 return; |
| 4475 } | 4478 } |
| 4476 | 4479 |
| 4480 const bool is_script = (script_.kind() == RawScript::kScriptTag); |
| 4481 const bool is_library = (script_.kind() == RawScript::kLibraryTag); |
| 4482 ASSERT(script_.kind() != RawScript::kSourceTag); |
| 4483 |
| 4477 // We may read metadata tokens that are part of the toplevel | 4484 // We may read metadata tokens that are part of the toplevel |
| 4478 // declaration that follows the library definitions. Therefore, we | 4485 // declaration that follows the library definitions. Therefore, we |
| 4479 // need to remember the position of the last token that was | 4486 // need to remember the position of the last token that was |
| 4480 // successfully consumed. | 4487 // successfully consumed. |
| 4481 intptr_t metadata_pos = TokenPos(); | 4488 intptr_t metadata_pos = TokenPos(); |
| 4482 SkipMetadata(); | 4489 SkipMetadata(); |
| 4483 if (CurrentToken() == Token::kLIBRARY) { | 4490 if (CurrentToken() == Token::kLIBRARY) { |
| 4484 ParseLibraryName(); | 4491 ParseLibraryName(); |
| 4485 metadata_pos = TokenPos(); | 4492 metadata_pos = TokenPos(); |
| 4486 SkipMetadata(); | 4493 SkipMetadata(); |
| 4487 } else if (script_.kind() == RawScript::kLibraryTag) { | 4494 } else if (is_library) { |
| 4488 ErrorMsg("library name definition expected"); | 4495 ErrorMsg("library name definition expected"); |
| 4489 } | 4496 } |
| 4490 while ((CurrentToken() == Token::kIMPORT) || | 4497 while ((CurrentToken() == Token::kIMPORT) || |
| 4491 (CurrentToken() == Token::kEXPORT)) { | 4498 (CurrentToken() == Token::kEXPORT)) { |
| 4499 if (is_script && (CurrentToken() == Token::kEXPORT)) { |
| 4500 ErrorMsg("export not allowed in scripts"); |
| 4501 } |
| 4492 ParseLibraryImportExport(); | 4502 ParseLibraryImportExport(); |
| 4493 metadata_pos = TokenPos(); | 4503 metadata_pos = TokenPos(); |
| 4494 SkipMetadata(); | 4504 SkipMetadata(); |
| 4495 } | 4505 } |
| 4496 // Core lib has not been explicitly imported, so we implicitly | 4506 // Core lib has not been explicitly imported, so we implicitly |
| 4497 // import it here. | 4507 // import it here. |
| 4498 if (!library_.ImportsCorelib()) { | 4508 if (!library_.ImportsCorelib()) { |
| 4499 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 4509 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 4500 ASSERT(!core_lib.IsNull()); | 4510 ASSERT(!core_lib.IsNull()); |
| 4501 const Namespace& core_ns = Namespace::Handle( | 4511 const Namespace& core_ns = Namespace::Handle( |
| (...skipping 5472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9974 void Parser::SkipQualIdent() { | 9984 void Parser::SkipQualIdent() { |
| 9975 ASSERT(IsIdentifier()); | 9985 ASSERT(IsIdentifier()); |
| 9976 ConsumeToken(); | 9986 ConsumeToken(); |
| 9977 if (CurrentToken() == Token::kPERIOD) { | 9987 if (CurrentToken() == Token::kPERIOD) { |
| 9978 ConsumeToken(); // Consume the kPERIOD token. | 9988 ConsumeToken(); // Consume the kPERIOD token. |
| 9979 ExpectIdentifier("identifier expected after '.'"); | 9989 ExpectIdentifier("identifier expected after '.'"); |
| 9980 } | 9990 } |
| 9981 } | 9991 } |
| 9982 | 9992 |
| 9983 } // namespace dart | 9993 } // namespace dart |
| OLD | NEW |