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

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

Issue 11367069: Make library, import, export, part pseudo-keywords (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 | runtime/vm/scanner.cc » ('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 4105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4116 library_.AddObject(func, accessor_name); 4116 library_.AddObject(func, accessor_name);
4117 } else { 4117 } else {
4118 library_.ReplaceObject(func, accessor_name); 4118 library_.ReplaceObject(func, accessor_name);
4119 } 4119 }
4120 } 4120 }
4121 4121
4122 4122
4123 // TODO(hausner): Remove support for old library definition syntax. 4123 // TODO(hausner): Remove support for old library definition syntax.
4124 void Parser::ParseLibraryNameObsoleteSyntax() { 4124 void Parser::ParseLibraryNameObsoleteSyntax() {
4125 if ((script_.kind() == RawScript::kLibraryTag) && 4125 if ((script_.kind() == RawScript::kLibraryTag) &&
4126 (CurrentToken() != Token::kLIBRARY)) { 4126 (CurrentToken() != Token::kLEGACY_LIBRARY)) {
4127 // Handle error case early to get consistent error message. 4127 // Handle error case early to get consistent error message.
4128 ExpectToken(Token::kLIBRARY); 4128 ExpectToken(Token::kLEGACY_LIBRARY);
4129 } 4129 }
4130 if (CurrentToken() == Token::kLIBRARY) { 4130 if (CurrentToken() == Token::kLEGACY_LIBRARY) {
4131 ConsumeToken(); 4131 ConsumeToken();
4132 ExpectToken(Token::kLPAREN); 4132 ExpectToken(Token::kLPAREN);
4133 if (CurrentToken() != Token::kSTRING) { 4133 if (CurrentToken() != Token::kSTRING) {
4134 ErrorMsg("library name expected"); 4134 ErrorMsg("library name expected");
4135 } 4135 }
4136 const String& name = *CurrentLiteral(); 4136 const String& name = *CurrentLiteral();
4137 ConsumeToken(); 4137 ConsumeToken();
4138 ExpectToken(Token::kRPAREN); 4138 ExpectToken(Token::kRPAREN);
4139 ExpectToken(Token::kSEMICOLON); 4139 ExpectToken(Token::kSEMICOLON);
4140 library_.SetName(name); 4140 library_.SetName(name);
(...skipping 16 matching lines...) Expand all
4157 Error& prev_error = Error::Handle(); 4157 Error& prev_error = Error::Handle();
4158 prev_error ^= Api::UnwrapHandle(result); 4158 prev_error ^= Api::UnwrapHandle(result);
4159 AppendErrorMsg(prev_error, token_pos, "library handler failed"); 4159 AppendErrorMsg(prev_error, token_pos, "library handler failed");
4160 } 4160 }
4161 return result; 4161 return result;
4162 } 4162 }
4163 4163
4164 4164
4165 // TODO(hausner): Remove support for old library definition syntax. 4165 // TODO(hausner): Remove support for old library definition syntax.
4166 void Parser::ParseLibraryImportObsoleteSyntax() { 4166 void Parser::ParseLibraryImportObsoleteSyntax() {
4167 while (CurrentToken() == Token::kIMPORT) { 4167 while (CurrentToken() == Token::kLEGACY_IMPORT) {
4168 const intptr_t import_pos = TokenPos(); 4168 const intptr_t import_pos = TokenPos();
4169 ConsumeToken(); 4169 ConsumeToken();
4170 ExpectToken(Token::kLPAREN); 4170 ExpectToken(Token::kLPAREN);
4171 if (CurrentToken() != Token::kSTRING) { 4171 if (CurrentToken() != Token::kSTRING) {
4172 ErrorMsg("library url expected"); 4172 ErrorMsg("library url expected");
4173 } 4173 }
4174 const String& url = *CurrentLiteral(); 4174 const String& url = *CurrentLiteral();
4175 ConsumeToken(); 4175 ConsumeToken();
4176 String& prefix = String::Handle(); 4176 String& prefix = String::Handle();
4177 if (CurrentToken() == Token::kCOMMA) { 4177 if (CurrentToken() == Token::kCOMMA) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 library_prefix = LibraryPrefix::New(prefix, import); 4224 library_prefix = LibraryPrefix::New(prefix, import);
4225 library_.AddObject(library_prefix, prefix); 4225 library_.AddObject(library_prefix, prefix);
4226 } 4226 }
4227 } 4227 }
4228 } 4228 }
4229 } 4229 }
4230 4230
4231 4231
4232 // TODO(hausner): Remove support for old library definition syntax. 4232 // TODO(hausner): Remove support for old library definition syntax.
4233 void Parser::ParseLibraryIncludeObsoleteSyntax() { 4233 void Parser::ParseLibraryIncludeObsoleteSyntax() {
4234 while (CurrentToken() == Token::kSOURCE) { 4234 while (CurrentToken() == Token::kLEGACY_SOURCE) {
4235 const intptr_t source_pos = TokenPos(); 4235 const intptr_t source_pos = TokenPos();
4236 ConsumeToken(); 4236 ConsumeToken();
4237 ExpectToken(Token::kLPAREN); 4237 ExpectToken(Token::kLPAREN);
4238 if (CurrentToken() != Token::kSTRING) { 4238 if (CurrentToken() != Token::kSTRING) {
4239 ErrorMsg("source url expected"); 4239 ErrorMsg("source url expected");
4240 } 4240 }
4241 const String& url = *CurrentLiteral(); 4241 const String& url = *CurrentLiteral();
4242 ConsumeToken(); 4242 ConsumeToken();
4243 ExpectToken(Token::kRPAREN); 4243 ExpectToken(Token::kRPAREN);
4244 ExpectToken(Token::kSEMICOLON); 4244 ExpectToken(Token::kSEMICOLON);
4245 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, 4245 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl,
4246 source_pos, 4246 source_pos,
4247 url); 4247 url);
4248 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 4248 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
4249 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); 4249 CallLibraryTagHandler(kSourceTag, source_pos, canon_url);
4250 } 4250 }
4251 } 4251 }
4252 4252
4253 4253
4254 void Parser::ParseLibraryName() { 4254 void Parser::ParseLibraryName() {
4255 ASSERT(IsLiteral("library")); 4255 ASSERT(CurrentToken() == Token::kLIBRARY);
4256 ConsumeToken(); 4256 ConsumeToken();
4257 // TODO(hausner): Exact syntax of library name still unclear: identifier, 4257 // TODO(hausner): Exact syntax of library name still unclear: identifier,
4258 // qualified identifier or even multiple dots allowed? For now we just 4258 // qualified identifier or even multiple dots allowed? For now we just
4259 // accept simple identifiers. 4259 // accept simple identifiers.
4260 const String& lib_name = *ExpectIdentifier("library name expected"); 4260 const String& lib_name = *ExpectIdentifier("library name expected");
4261 library_.SetName(lib_name); 4261 library_.SetName(lib_name);
4262 ExpectSemicolon(); 4262 ExpectSemicolon();
4263 } 4263 }
4264 4264
4265 4265
4266 void Parser::ParseIdentList(GrowableObjectArray* names) { 4266 void Parser::ParseIdentList(GrowableObjectArray* names) {
4267 while (IsIdentifier()) { 4267 while (IsIdentifier()) {
4268 names->Add(*CurrentLiteral()); 4268 names->Add(*CurrentLiteral());
4269 ConsumeToken(); // Identifier. 4269 ConsumeToken(); // Identifier.
4270 if (CurrentToken() != Token::kCOMMA) { 4270 if (CurrentToken() != Token::kCOMMA) {
4271 return; 4271 return;
4272 } 4272 }
4273 ConsumeToken(); // Comma. 4273 ConsumeToken(); // Comma.
4274 } 4274 }
4275 } 4275 }
4276 4276
4277 4277
4278 void Parser::ParseLibraryImportExport() { 4278 void Parser::ParseLibraryImportExport() {
4279 bool is_import = IsLiteral("import"); 4279 bool is_import = (CurrentToken() == Token::kIMPORT);
4280 bool is_export = IsLiteral("export"); 4280 bool is_export = (CurrentToken() == Token::kEXPORT);
4281 ASSERT(is_import || is_export); 4281 ASSERT(is_import || is_export);
4282 const intptr_t import_pos = TokenPos(); 4282 const intptr_t import_pos = TokenPos();
4283 ConsumeToken(); 4283 ConsumeToken();
4284 if (CurrentToken() != Token::kSTRING) { 4284 if (CurrentToken() != Token::kSTRING) {
4285 ErrorMsg("library url expected"); 4285 ErrorMsg("library url expected");
4286 } 4286 }
4287 const String& url = *CurrentLiteral(); 4287 const String& url = *CurrentLiteral();
4288 if (url.Length() == 0) { 4288 if (url.Length() == 0) {
4289 ErrorMsg("library url expected"); 4289 ErrorMsg("library url expected");
4290 } 4290 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4380 void Parser::ParseLibraryDefinition() { 4380 void Parser::ParseLibraryDefinition() {
4381 TRACE_PARSER("ParseLibraryDefinition"); 4381 TRACE_PARSER("ParseLibraryDefinition");
4382 4382
4383 // Handle the script tag. 4383 // Handle the script tag.
4384 if (CurrentToken() == Token::kSCRIPTTAG) { 4384 if (CurrentToken() == Token::kSCRIPTTAG) {
4385 // Nothing to do for script tags except to skip them. 4385 // Nothing to do for script tags except to skip them.
4386 ConsumeToken(); 4386 ConsumeToken();
4387 } 4387 }
4388 4388
4389 // TODO(hausner): Remove support for old library definition syntax. 4389 // TODO(hausner): Remove support for old library definition syntax.
4390 if ((CurrentToken() == Token::kLIBRARY) || 4390 if ((CurrentToken() == Token::kLEGACY_LIBRARY) ||
4391 (CurrentToken() == Token::kIMPORT) || 4391 (CurrentToken() == Token::kLEGACY_IMPORT) ||
4392 (CurrentToken() == Token::kSOURCE)) { 4392 (CurrentToken() == Token::kLEGACY_SOURCE)) {
4393 ParseLibraryNameObsoleteSyntax(); 4393 ParseLibraryNameObsoleteSyntax();
4394 ParseLibraryImportObsoleteSyntax(); 4394 ParseLibraryImportObsoleteSyntax();
4395 ParseLibraryIncludeObsoleteSyntax(); 4395 ParseLibraryIncludeObsoleteSyntax();
4396 // Core lib has not been explicitly imported, so we implicitly 4396 // Core lib has not been explicitly imported, so we implicitly
4397 // import it here. 4397 // import it here.
4398 if (!library_.ImportsCorelib()) { 4398 if (!library_.ImportsCorelib()) {
4399 Library& core_lib = Library::Handle(Library::CoreLibrary()); 4399 Library& core_lib = Library::Handle(Library::CoreLibrary());
4400 ASSERT(!core_lib.IsNull()); 4400 ASSERT(!core_lib.IsNull());
4401 const Namespace& core_ns = Namespace::Handle( 4401 const Namespace& core_ns = Namespace::Handle(
4402 Namespace::New(core_lib, Array::Handle(), Array::Handle())); 4402 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
4403 library_.AddImport(core_ns); 4403 library_.AddImport(core_ns);
4404 } 4404 }
4405 return; 4405 return;
4406 } 4406 }
4407 4407
4408 // We may read metadata tokens that are part of the toplevel 4408 // We may read metadata tokens that are part of the toplevel
4409 // declaration that follows the library definitions. Therefore, we 4409 // declaration that follows the library definitions. Therefore, we
4410 // need to remember the position of the last token that was 4410 // need to remember the position of the last token that was
4411 // successfully consumed. 4411 // successfully consumed.
4412 intptr_t metadata_pos = TokenPos(); 4412 intptr_t metadata_pos = TokenPos();
4413 SkipMetadata(); 4413 SkipMetadata();
4414 if (IsLiteral("library")) { 4414 if (CurrentToken() == Token::kLIBRARY) {
4415 ParseLibraryName(); 4415 ParseLibraryName();
4416 metadata_pos = TokenPos(); 4416 metadata_pos = TokenPos();
4417 SkipMetadata(); 4417 SkipMetadata();
4418 } else if (script_.kind() == RawScript::kLibraryTag) { 4418 } else if (script_.kind() == RawScript::kLibraryTag) {
4419 ErrorMsg("library name definition expected"); 4419 ErrorMsg("library name definition expected");
4420 } 4420 }
4421 while (IsLiteral("import") || IsLiteral("export")) { 4421 while ((CurrentToken() == Token::kIMPORT) ||
4422 (CurrentToken() == Token::kEXPORT)) {
4422 ParseLibraryImportExport(); 4423 ParseLibraryImportExport();
4423 metadata_pos = TokenPos(); 4424 metadata_pos = TokenPos();
4424 SkipMetadata(); 4425 SkipMetadata();
4425 } 4426 }
4426 // Core lib has not been explicitly imported, so we implicitly 4427 // Core lib has not been explicitly imported, so we implicitly
4427 // import it here. 4428 // import it here.
4428 if (!library_.ImportsCorelib()) { 4429 if (!library_.ImportsCorelib()) {
4429 Library& core_lib = Library::Handle(Library::CoreLibrary()); 4430 Library& core_lib = Library::Handle(Library::CoreLibrary());
4430 ASSERT(!core_lib.IsNull()); 4431 ASSERT(!core_lib.IsNull());
4431 const Namespace& core_ns = Namespace::Handle( 4432 const Namespace& core_ns = Namespace::Handle(
4432 Namespace::New(core_lib, Array::Handle(), Array::Handle())); 4433 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
4433 library_.AddImport(core_ns); 4434 library_.AddImport(core_ns);
4434 } 4435 }
4435 while (IsLiteral("part")) { 4436 while (CurrentToken() == Token::kPART) {
4436 ParseLibraryPart(); 4437 ParseLibraryPart();
4437 metadata_pos = TokenPos(); 4438 metadata_pos = TokenPos();
4438 SkipMetadata(); 4439 SkipMetadata();
4439 } 4440 }
4440 if (IsLiteral("library") || IsLiteral("import") || IsLiteral("export")) {
4441 ErrorMsg("unexpected token '%s'", CurrentLiteral()->ToCString());
4442 }
4443 SetPosition(metadata_pos); 4441 SetPosition(metadata_pos);
4444 } 4442 }
4445 4443
4446 4444
4447 void Parser::ParsePartHeader() { 4445 void Parser::ParsePartHeader() {
4448 intptr_t metadata_pos = TokenPos(); 4446 intptr_t metadata_pos = TokenPos();
4449 SkipMetadata(); 4447 SkipMetadata();
4450 // TODO(hausner): Once support for old #source directive is removed 4448 // TODO(hausner): Once support for old #source directive is removed
4451 // from the compiler, add an error message here if we don't find 4449 // from the compiler, add an error message here if we don't find
4452 // a 'part of' directive. 4450 // a 'part of' directive.
4453 if (IsLiteral("part")) { 4451 if (CurrentToken() == Token::kPART) {
4454 ConsumeToken(); 4452 ConsumeToken();
4455 if (!IsLiteral("of")) { 4453 if (!IsLiteral("of")) {
4456 ErrorMsg("'part of' expected"); 4454 ErrorMsg("'part of' expected");
4457 } 4455 }
4458 ConsumeToken(); 4456 ConsumeToken();
4459 // TODO(hausner): Exact syntax of library name still unclear: identifier, 4457 // TODO(hausner): Exact syntax of library name still unclear: identifier,
4460 // qualified identifier or even multiple dots allowed? For now we just 4458 // qualified identifier or even multiple dots allowed? For now we just
4461 // accept simple identifiers. 4459 // accept simple identifiers.
4462 // The VM is not required to check that the library name matches the 4460 // The VM is not required to check that the library name matches the
4463 // name of the current library, so we ignore it. 4461 // name of the current library, so we ignore it.
(...skipping 5439 matching lines...) Expand 10 before | Expand all | Expand 10 after
9903 void Parser::SkipQualIdent() { 9901 void Parser::SkipQualIdent() {
9904 ASSERT(IsIdentifier()); 9902 ASSERT(IsIdentifier());
9905 ConsumeToken(); 9903 ConsumeToken();
9906 if (CurrentToken() == Token::kPERIOD) { 9904 if (CurrentToken() == Token::kPERIOD) {
9907 ConsumeToken(); // Consume the kPERIOD token. 9905 ConsumeToken(); // Consume the kPERIOD token.
9908 ExpectIdentifier("identifier expected after '.'"); 9906 ExpectIdentifier("identifier expected after '.'");
9909 } 9907 }
9910 } 9908 }
9911 9909
9912 } // namespace dart 9910 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698