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

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

Issue 12880023: Remove legacy syntax support for library import (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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
« no previous file with comments | « runtime/vm/intrinsifier.h ('k') | runtime/vm/scanner.h » ('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 "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 4179 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 AddFormalParamsToFunction(&params, func); 4190 AddFormalParamsToFunction(&params, func);
4191 top_level->functions.Add(func); 4191 top_level->functions.Add(func);
4192 if (!is_patch) { 4192 if (!is_patch) {
4193 library_.AddObject(func, accessor_name); 4193 library_.AddObject(func, accessor_name);
4194 } else { 4194 } else {
4195 library_.ReplaceObject(func, accessor_name); 4195 library_.ReplaceObject(func, accessor_name);
4196 } 4196 }
4197 } 4197 }
4198 4198
4199 4199
4200 // TODO(hausner): Remove support for old library definition syntax.
4201 void Parser::ParseLibraryNameObsoleteSyntax() {
4202 if ((script_.kind() == RawScript::kLibraryTag) &&
4203 (CurrentToken() != Token::kLEGACY_LIBRARY)) {
4204 // Handle error case early to get consistent error message.
4205 ExpectToken(Token::kLEGACY_LIBRARY);
4206 }
4207 if (CurrentToken() == Token::kLEGACY_LIBRARY) {
4208 ConsumeToken();
4209 ExpectToken(Token::kLPAREN);
4210 if (CurrentToken() != Token::kSTRING) {
4211 ErrorMsg("library name expected");
4212 }
4213 const String& name = *CurrentLiteral();
4214 ConsumeToken();
4215 ExpectToken(Token::kRPAREN);
4216 ExpectToken(Token::kSEMICOLON);
4217 library_.SetName(name);
4218 }
4219 }
4220
4221 4200
4222 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 4201 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
4223 intptr_t token_pos, 4202 intptr_t token_pos,
4224 const String& url) { 4203 const String& url) {
4225 Isolate* isolate = Isolate::Current(); 4204 Isolate* isolate = Isolate::Current();
4226 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); 4205 Dart_LibraryTagHandler handler = isolate->library_tag_handler();
4227 if (handler == NULL) { 4206 if (handler == NULL) {
4228 if (url.StartsWith(Symbols::DartScheme())) { 4207 if (url.StartsWith(Symbols::DartScheme())) {
4229 if (tag == kCanonicalizeUrl) { 4208 if (tag == kCanonicalizeUrl) {
4230 return url.raw(); 4209 return url.raw();
(...skipping 14 matching lines...) Expand all
4245 } 4224 }
4246 if (tag == kCanonicalizeUrl) { 4225 if (tag == kCanonicalizeUrl) {
4247 if (!Dart_IsString(result)) { 4226 if (!Dart_IsString(result)) {
4248 ErrorMsg(token_pos, "library handler failed URI canonicalization"); 4227 ErrorMsg(token_pos, "library handler failed URI canonicalization");
4249 } 4228 }
4250 } 4229 }
4251 return Api::UnwrapHandle(result); 4230 return Api::UnwrapHandle(result);
4252 } 4231 }
4253 4232
4254 4233
4255 // TODO(hausner): Remove support for old library definition syntax.
4256 void Parser::ParseLibraryImportObsoleteSyntax() {
4257 while (CurrentToken() == Token::kLEGACY_IMPORT) {
4258 const intptr_t import_pos = TokenPos();
4259 ConsumeToken();
4260 ExpectToken(Token::kLPAREN);
4261 if (CurrentToken() != Token::kSTRING) {
4262 ErrorMsg("library url expected");
4263 }
4264 const String& url = *CurrentLiteral();
4265 ConsumeToken();
4266 String& prefix = String::Handle();
4267 if (CurrentToken() == Token::kCOMMA) {
4268 ConsumeToken();
4269 if (!IsLiteral("prefix")) {
4270 ErrorMsg("prefix: expected");
4271 }
4272 ConsumeToken();
4273 ExpectToken(Token::kCOLON);
4274 if (CurrentToken() != Token::kSTRING) {
4275 ErrorMsg("prefix expected");
4276 }
4277 prefix = CurrentLiteral()->raw();
4278 // TODO(asiva): Need to also check that prefix is not a reserved keyword.
4279 if (!Scanner::IsIdent(prefix)) {
4280 ErrorMsg("prefix should be an identifier");
4281 }
4282 ConsumeToken();
4283 }
4284 ExpectToken(Token::kRPAREN);
4285 ExpectToken(Token::kSEMICOLON);
4286 const String& canon_url = String::CheckedHandle(
4287 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url));
4288 // Lookup the library URL.
4289 Library& library = Library::Handle(Library::LookupLibrary(canon_url));
4290 if (library.IsNull()) {
4291 // Call the library tag handler to load the library.
4292 CallLibraryTagHandler(kImportTag, import_pos, canon_url);
4293 // If the library tag handler succeded without registering the
4294 // library we create an empty library to import.
4295 library = Library::LookupLibrary(canon_url);
4296 if (library.IsNull()) {
4297 library = Library::New(canon_url);
4298 library.Register();
4299 }
4300 }
4301 // Add the import to the library.
4302 const Namespace& import = Namespace::Handle(
4303 Namespace::New(library, Array::Handle(), Array::Handle()));
4304 if (prefix.IsNull() || (prefix.Length() == 0)) {
4305 library_.AddImport(import);
4306 } else {
4307 LibraryPrefix& library_prefix = LibraryPrefix::Handle();
4308 library_prefix = library_.LookupLocalLibraryPrefix(prefix);
4309 if (!library_prefix.IsNull()) {
4310 library_prefix.AddImport(import);
4311 } else {
4312 library_prefix = LibraryPrefix::New(prefix, import);
4313 library_.AddObject(library_prefix, prefix);
4314 }
4315 }
4316 }
4317 }
4318
4319
4320 // TODO(hausner): Remove support for old library definition syntax.
4321 void Parser::ParseLibraryIncludeObsoleteSyntax() {
4322 while (CurrentToken() == Token::kLEGACY_SOURCE) {
4323 const intptr_t source_pos = TokenPos();
4324 ConsumeToken();
4325 ExpectToken(Token::kLPAREN);
4326 if (CurrentToken() != Token::kSTRING) {
4327 ErrorMsg("source url expected");
4328 }
4329 const String& url = *CurrentLiteral();
4330 ConsumeToken();
4331 ExpectToken(Token::kRPAREN);
4332 ExpectToken(Token::kSEMICOLON);
4333 const String& canon_url = String::CheckedHandle(
4334 CallLibraryTagHandler(kCanonicalizeUrl, source_pos, url));
4335 CallLibraryTagHandler(kSourceTag, source_pos, canon_url);
4336 }
4337 }
4338
4339
4340 void Parser::ParseLibraryName() { 4234 void Parser::ParseLibraryName() {
4341 ASSERT(CurrentToken() == Token::kLIBRARY); 4235 ASSERT(CurrentToken() == Token::kLIBRARY);
4342 ConsumeToken(); 4236 ConsumeToken();
4343 String& lib_name = *ExpectIdentifier("library name expected"); 4237 String& lib_name = *ExpectIdentifier("library name expected");
4344 if (CurrentToken() == Token::kPERIOD) { 4238 if (CurrentToken() == Token::kPERIOD) {
4345 while (CurrentToken() == Token::kPERIOD) { 4239 while (CurrentToken() == Token::kPERIOD) {
4346 ConsumeToken(); 4240 ConsumeToken();
4347 lib_name = String::Concat(lib_name, Symbols::Dot()); 4241 lib_name = String::Concat(lib_name, Symbols::Dot());
4348 lib_name = String::Concat(lib_name, 4242 lib_name = String::Concat(lib_name,
4349 *ExpectIdentifier("malformed library name")); 4243 *ExpectIdentifier("malformed library name"));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
4479 4373
4480 void Parser::ParseLibraryDefinition() { 4374 void Parser::ParseLibraryDefinition() {
4481 TRACE_PARSER("ParseLibraryDefinition"); 4375 TRACE_PARSER("ParseLibraryDefinition");
4482 4376
4483 // Handle the script tag. 4377 // Handle the script tag.
4484 if (CurrentToken() == Token::kSCRIPTTAG) { 4378 if (CurrentToken() == Token::kSCRIPTTAG) {
4485 // Nothing to do for script tags except to skip them. 4379 // Nothing to do for script tags except to skip them.
4486 ConsumeToken(); 4380 ConsumeToken();
4487 } 4381 }
4488 4382
4489 // TODO(hausner): Remove support for old library definition syntax.
4490 if ((CurrentToken() == Token::kLEGACY_LIBRARY) ||
4491 (CurrentToken() == Token::kLEGACY_IMPORT) ||
4492 (CurrentToken() == Token::kLEGACY_SOURCE)) {
4493 ParseLibraryNameObsoleteSyntax();
4494 ParseLibraryImportObsoleteSyntax();
4495 ParseLibraryIncludeObsoleteSyntax();
4496 // Core lib has not been explicitly imported, so we implicitly
4497 // import it here.
4498 if (!library_.ImportsCorelib()) {
4499 Library& core_lib = Library::Handle(Library::CoreLibrary());
4500 ASSERT(!core_lib.IsNull());
4501 const Namespace& core_ns = Namespace::Handle(
4502 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
4503 library_.AddImport(core_ns);
4504 }
4505 return;
4506 }
4507
4508 ASSERT(script_.kind() != RawScript::kSourceTag); 4383 ASSERT(script_.kind() != RawScript::kSourceTag);
4509 4384
4510 // We may read metadata tokens that are part of the toplevel 4385 // We may read metadata tokens that are part of the toplevel
4511 // declaration that follows the library definitions. Therefore, we 4386 // declaration that follows the library definitions. Therefore, we
4512 // need to remember the position of the last token that was 4387 // need to remember the position of the last token that was
4513 // successfully consumed. 4388 // successfully consumed.
4514 intptr_t metadata_pos = TokenPos(); 4389 intptr_t metadata_pos = TokenPos();
4515 SkipMetadata(); 4390 SkipMetadata();
4516 if (CurrentToken() == Token::kLIBRARY) { 4391 if (CurrentToken() == Token::kLIBRARY) {
4517 if (is_patch_source()) { 4392 if (is_patch_source()) {
(...skipping 5511 matching lines...) Expand 10 before | Expand all | Expand 10 after
10029 void Parser::SkipQualIdent() { 9904 void Parser::SkipQualIdent() {
10030 ASSERT(IsIdentifier()); 9905 ASSERT(IsIdentifier());
10031 ConsumeToken(); 9906 ConsumeToken();
10032 if (CurrentToken() == Token::kPERIOD) { 9907 if (CurrentToken() == Token::kPERIOD) {
10033 ConsumeToken(); // Consume the kPERIOD token. 9908 ConsumeToken(); // Consume the kPERIOD token.
10034 ExpectIdentifier("identifier expected after '.'"); 9909 ExpectIdentifier("identifier expected after '.'");
10035 } 9910 }
10036 } 9911 }
10037 9912
10038 } // namespace dart 9913 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier.h ('k') | runtime/vm/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698