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 "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 4907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4918 names->Add(*CurrentLiteral()); | 4918 names->Add(*CurrentLiteral()); |
4919 ConsumeToken(); // Identifier. | 4919 ConsumeToken(); // Identifier. |
4920 if (CurrentToken() != Token::kCOMMA) { | 4920 if (CurrentToken() != Token::kCOMMA) { |
4921 return; | 4921 return; |
4922 } | 4922 } |
4923 ConsumeToken(); // Comma. | 4923 ConsumeToken(); // Comma. |
4924 } | 4924 } |
4925 } | 4925 } |
4926 | 4926 |
4927 | 4927 |
4928 void Parser::ParseLibraryImportExport() { | 4928 void Parser::ParseLibraryImportExport(intptr_t metadata_pos) { |
4929 bool is_import = (CurrentToken() == Token::kIMPORT); | 4929 bool is_import = (CurrentToken() == Token::kIMPORT); |
4930 bool is_export = (CurrentToken() == Token::kEXPORT); | 4930 bool is_export = (CurrentToken() == Token::kEXPORT); |
4931 ASSERT(is_import || is_export); | 4931 ASSERT(is_import || is_export); |
4932 const intptr_t import_pos = TokenPos(); | 4932 const intptr_t import_pos = TokenPos(); |
4933 ConsumeToken(); | 4933 ConsumeToken(); |
4934 CheckToken(Token::kSTRING, "library url expected"); | 4934 CheckToken(Token::kSTRING, "library url expected"); |
4935 AstNode* url_literal = ParseStringLiteral(false); | 4935 AstNode* url_literal = ParseStringLiteral(false); |
4936 ASSERT(url_literal->IsLiteralNode()); | 4936 ASSERT(url_literal->IsLiteralNode()); |
4937 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); | 4937 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); |
4938 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); | 4938 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4981 // Call the library tag handler to load the library. | 4981 // Call the library tag handler to load the library. |
4982 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url); | 4982 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url); |
4983 // If the library tag handler succeded without registering the | 4983 // If the library tag handler succeded without registering the |
4984 // library we create an empty library to import. | 4984 // library we create an empty library to import. |
4985 library = Library::LookupLibrary(canon_url); | 4985 library = Library::LookupLibrary(canon_url); |
4986 if (library.IsNull()) { | 4986 if (library.IsNull()) { |
4987 library = Library::New(canon_url); | 4987 library = Library::New(canon_url); |
4988 library.Register(); | 4988 library.Register(); |
4989 } | 4989 } |
4990 } | 4990 } |
4991 const Namespace& ns = | 4991 |
4992 Namespace::Handle(Namespace::New(library, show_names, hide_names)); | 4992 Namespace& ns = |
| 4993 Namespace::Handle(Namespace::New(library, show_names, hide_names)); |
| 4994 if (metadata_pos >= 0) { |
| 4995 ns.AddMetadata(metadata_pos, current_class()); |
| 4996 } |
| 4997 |
4993 if (is_import) { | 4998 if (is_import) { |
4994 // Ensure that private dart:_ libraries are only imported into dart: | 4999 // Ensure that private dart:_ libraries are only imported into dart: |
4995 // libraries. | 5000 // libraries. |
4996 const String& lib_url = String::Handle(library_.url()); | 5001 const String& lib_url = String::Handle(library_.url()); |
4997 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) && | 5002 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) && |
4998 !lib_url.StartsWith(Symbols::DartScheme())) { | 5003 !lib_url.StartsWith(Symbols::DartScheme())) { |
4999 ErrorMsg(import_pos, "private library is not accessible"); | 5004 ErrorMsg(import_pos, "private library is not accessible"); |
5000 } | 5005 } |
5001 if (prefix.IsNull() || (prefix.Length() == 0)) { | 5006 if (prefix.IsNull() || (prefix.Length() == 0)) { |
5002 library_.AddImport(ns); | 5007 library_.AddImport(ns); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5055 } | 5060 } |
5056 ParseLibraryName(); | 5061 ParseLibraryName(); |
5057 if (metadata_pos >= 0) { | 5062 if (metadata_pos >= 0) { |
5058 library_.AddLibraryMetadata(current_class(), metadata_pos); | 5063 library_.AddLibraryMetadata(current_class(), metadata_pos); |
5059 } | 5064 } |
5060 rewind_pos = TokenPos(); | 5065 rewind_pos = TokenPos(); |
5061 metadata_pos = SkipMetadata(); | 5066 metadata_pos = SkipMetadata(); |
5062 } | 5067 } |
5063 while ((CurrentToken() == Token::kIMPORT) || | 5068 while ((CurrentToken() == Token::kIMPORT) || |
5064 (CurrentToken() == Token::kEXPORT)) { | 5069 (CurrentToken() == Token::kEXPORT)) { |
5065 ParseLibraryImportExport(); | 5070 ParseLibraryImportExport(metadata_pos); |
5066 rewind_pos = TokenPos(); | 5071 rewind_pos = TokenPos(); |
5067 metadata_pos = SkipMetadata(); | 5072 metadata_pos = SkipMetadata(); |
5068 } | 5073 } |
5069 // Core lib has not been explicitly imported, so we implicitly | 5074 // Core lib has not been explicitly imported, so we implicitly |
5070 // import it here. | 5075 // import it here. |
5071 if (!library_.ImportsCorelib()) { | 5076 if (!library_.ImportsCorelib()) { |
5072 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 5077 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
5073 ASSERT(!core_lib.IsNull()); | 5078 ASSERT(!core_lib.IsNull()); |
5074 const Namespace& core_ns = Namespace::Handle( | 5079 const Namespace& core_ns = Namespace::Handle( |
5075 Namespace::New(core_lib, Object::null_array(), Object::null_array())); | 5080 Namespace::New(core_lib, Object::null_array(), Object::null_array())); |
(...skipping 5698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10774 void Parser::SkipQualIdent() { | 10779 void Parser::SkipQualIdent() { |
10775 ASSERT(IsIdentifier()); | 10780 ASSERT(IsIdentifier()); |
10776 ConsumeToken(); | 10781 ConsumeToken(); |
10777 if (CurrentToken() == Token::kPERIOD) { | 10782 if (CurrentToken() == Token::kPERIOD) { |
10778 ConsumeToken(); // Consume the kPERIOD token. | 10783 ConsumeToken(); // Consume the kPERIOD token. |
10779 ExpectIdentifier("identifier expected after '.'"); | 10784 ExpectIdentifier("identifier expected after '.'"); |
10780 } | 10785 } |
10781 } | 10786 } |
10782 | 10787 |
10783 } // namespace dart | 10788 } // namespace dart |
OLD | NEW |