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

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

Issue 11312197: Enforce proper library/import syntax (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « no previous file | tests/co19/co19-runtime.status » ('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 4456 matching lines...) Expand 10 before | Expand all | Expand 10 after
4467 if (!library_.ImportsCorelib()) { 4467 if (!library_.ImportsCorelib()) {
4468 Library& core_lib = Library::Handle(Library::CoreLibrary()); 4468 Library& core_lib = Library::Handle(Library::CoreLibrary());
4469 ASSERT(!core_lib.IsNull()); 4469 ASSERT(!core_lib.IsNull());
4470 const Namespace& core_ns = Namespace::Handle( 4470 const Namespace& core_ns = Namespace::Handle(
4471 Namespace::New(core_lib, Array::Handle(), Array::Handle())); 4471 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
4472 library_.AddImport(core_ns); 4472 library_.AddImport(core_ns);
4473 } 4473 }
4474 return; 4474 return;
4475 } 4475 }
4476 4476
4477 const bool is_script = (script_.kind() == RawScript::kScriptTag);
4478 const bool is_library = (script_.kind() == RawScript::kLibraryTag);
4479 ASSERT(script_.kind() != RawScript::kSourceTag);
4480
4477 // We may read metadata tokens that are part of the toplevel 4481 // We may read metadata tokens that are part of the toplevel
4478 // declaration that follows the library definitions. Therefore, we 4482 // declaration that follows the library definitions. Therefore, we
4479 // need to remember the position of the last token that was 4483 // need to remember the position of the last token that was
4480 // successfully consumed. 4484 // successfully consumed.
4481 intptr_t metadata_pos = TokenPos(); 4485 intptr_t metadata_pos = TokenPos();
4482 SkipMetadata(); 4486 SkipMetadata();
4483 if (CurrentToken() == Token::kLIBRARY) { 4487 if (CurrentToken() == Token::kLIBRARY) {
4484 ParseLibraryName(); 4488 ParseLibraryName();
4485 metadata_pos = TokenPos(); 4489 metadata_pos = TokenPos();
4486 SkipMetadata(); 4490 SkipMetadata();
4487 } else if (script_.kind() == RawScript::kLibraryTag) { 4491 } else if (is_library) {
siva 2012/11/13 00:21:53 isn't this equivalent to else if (!is_script) { ..
hausner 2012/11/13 01:07:13 Keeping as is, as per our offline discussion. On
4488 ErrorMsg("library name definition expected"); 4492 ErrorMsg("library name definition expected");
4489 } 4493 }
4490 while ((CurrentToken() == Token::kIMPORT) || 4494 while ((CurrentToken() == Token::kIMPORT) ||
4491 (CurrentToken() == Token::kEXPORT)) { 4495 (CurrentToken() == Token::kEXPORT)) {
4496 if (is_script && (CurrentToken() == Token::kEXPORT)) {
4497 ErrorMsg("export not allowed in scripts");
4498 }
4492 ParseLibraryImportExport(); 4499 ParseLibraryImportExport();
4493 metadata_pos = TokenPos(); 4500 metadata_pos = TokenPos();
4494 SkipMetadata(); 4501 SkipMetadata();
4495 } 4502 }
4496 // Core lib has not been explicitly imported, so we implicitly 4503 // Core lib has not been explicitly imported, so we implicitly
4497 // import it here. 4504 // import it here.
4498 if (!library_.ImportsCorelib()) { 4505 if (!library_.ImportsCorelib()) {
4499 Library& core_lib = Library::Handle(Library::CoreLibrary()); 4506 Library& core_lib = Library::Handle(Library::CoreLibrary());
4500 ASSERT(!core_lib.IsNull()); 4507 ASSERT(!core_lib.IsNull());
4501 const Namespace& core_ns = Namespace::Handle( 4508 const Namespace& core_ns = Namespace::Handle(
(...skipping 5472 matching lines...) Expand 10 before | Expand all | Expand 10 after
9974 void Parser::SkipQualIdent() { 9981 void Parser::SkipQualIdent() {
9975 ASSERT(IsIdentifier()); 9982 ASSERT(IsIdentifier());
9976 ConsumeToken(); 9983 ConsumeToken();
9977 if (CurrentToken() == Token::kPERIOD) { 9984 if (CurrentToken() == Token::kPERIOD) {
9978 ConsumeToken(); // Consume the kPERIOD token. 9985 ConsumeToken(); // Consume the kPERIOD token.
9979 ExpectIdentifier("identifier expected after '.'"); 9986 ExpectIdentifier("identifier expected after '.'");
9980 } 9987 }
9981 } 9988 }
9982 9989
9983 } // namespace dart 9990 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698