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

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

Issue 11047027: Implement export clause in VM (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
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 4178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4189 ConsumeToken(); // Identifier. 4189 ConsumeToken(); // Identifier.
4190 if (CurrentToken() != Token::kCOMMA) { 4190 if (CurrentToken() != Token::kCOMMA) {
4191 return; 4191 return;
4192 } 4192 }
4193 ConsumeToken(); // Comma. 4193 ConsumeToken(); // Comma.
4194 } 4194 }
4195 } 4195 }
4196 4196
4197 4197
4198 void Parser::ParseLibraryImportExport() { 4198 void Parser::ParseLibraryImportExport() {
4199 if (IsLiteral("import")) { 4199 bool is_import = IsLiteral("import");
4200 const intptr_t import_pos = TokenPos(); 4200 bool is_export = IsLiteral("export");
4201 ASSERT(is_import || is_export);
4202 const intptr_t import_pos = TokenPos();
4203 ConsumeToken();
4204 if (CurrentToken() != Token::kSTRING) {
4205 ErrorMsg("library url expected");
4206 }
4207 const String& url = *CurrentLiteral();
4208 if (url.Length() == 0) {
4209 ErrorMsg("library url expected");
4210 }
4211 ConsumeToken();
4212 String& prefix = String::Handle();
4213 if (is_import && IsLiteral("as")) {
4201 ConsumeToken(); 4214 ConsumeToken();
4202 if (CurrentToken() != Token::kSTRING) { 4215 prefix = ExpectIdentifier("prefix expected")->raw();
4203 ErrorMsg("library url expected"); 4216 }
4204 }
4205 const String& url = *CurrentLiteral();
4206 if (url.Length() == 0) {
4207 ErrorMsg("library url expected");
4208 }
4209 ConsumeToken();
4210 String& prefix = String::Handle();
4211 if (IsLiteral("as")) {
4212 ConsumeToken();
4213 prefix = ExpectIdentifier("prefix expected")->raw();
4214 }
4215 4217
4216 Array& show_names = Array::Handle(); 4218 Array& show_names = Array::Handle();
4217 Array& hide_names = Array::Handle(); 4219 Array& hide_names = Array::Handle();
4218 if (IsLiteral("show") || IsLiteral("hide")) { 4220 if (IsLiteral("show") || IsLiteral("hide")) {
4219 GrowableObjectArray& show_list = 4221 GrowableObjectArray& show_list =
4220 GrowableObjectArray::Handle(GrowableObjectArray::New()); 4222 GrowableObjectArray::Handle(GrowableObjectArray::New());
4221 GrowableObjectArray& hide_list = 4223 GrowableObjectArray& hide_list =
4222 GrowableObjectArray::Handle(GrowableObjectArray::New()); 4224 GrowableObjectArray::Handle(GrowableObjectArray::New());
4223 for (;;) { 4225 for (;;) {
4224 if (IsLiteral("show")) { 4226 if (IsLiteral("show")) {
4225 ConsumeToken(); 4227 ConsumeToken();
4226 ParseIdentList(&show_list); 4228 ParseIdentList(&show_list);
4227 } else if (IsLiteral("hide")) { 4229 } else if (IsLiteral("hide")) {
4228 ConsumeToken(); 4230 ConsumeToken();
4229 ParseIdentList(&hide_list); 4231 ParseIdentList(&hide_list);
4230 } else { 4232 } else {
4231 break; 4233 break;
4232 }
4233 }
4234 if (show_list.Length() > 0) {
4235 show_names = Array::MakeArray(show_list);
4236 }
4237 if (hide_list.Length() > 0) {
4238 hide_names = Array::MakeArray(hide_list);
4239 } 4234 }
4240 } 4235 }
4241 ExpectSemicolon(); 4236 if (show_list.Length() > 0) {
4237 show_names = Array::MakeArray(show_list);
4238 }
4239 if (hide_list.Length() > 0) {
4240 hide_names = Array::MakeArray(hide_list);
4241 }
4242 }
4243 ExpectSemicolon();
4242 4244
4243 // Canonicalize library URL. 4245 // Canonicalize library URL.
4244 Dart_Handle handle = 4246 Dart_Handle handle =
4245 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url); 4247 CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url);
4246 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 4248 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
4247 // Lookup the library URL. 4249 // Lookup the library URL.
4248 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); 4250 Library& library = Library::Handle(Library::LookupLibrary(canon_url));
4251 if (library.IsNull()) {
4252 // Call the library tag handler to load the library.
4253 CallLibraryTagHandler(kImportTag, import_pos, canon_url);
4254 // If the library tag handler succeded without registering the
4255 // library we create an empty library to import.
4256 library = Library::LookupLibrary(canon_url);
4249 if (library.IsNull()) { 4257 if (library.IsNull()) {
4250 // Call the library tag handler to load the library. 4258 library = Library::New(canon_url);
4251 CallLibraryTagHandler(kImportTag, import_pos, canon_url); 4259 library.Register();
4252 // If the library tag handler succeded without registering the
4253 // library we create an empty library to import.
4254 library = Library::LookupLibrary(canon_url);
4255 if (library.IsNull()) {
4256 library = Library::New(canon_url);
4257 library.Register();
4258 }
4259 } 4260 }
4260 // Add the import to the library. 4261 }
4261 const Namespace& import = 4262 const Namespace& ns =
4262 Namespace::Handle(Namespace::New(library, show_names, hide_names)); 4263 Namespace::Handle(Namespace::New(library, show_names, hide_names));
4264 if (is_import) {
4263 if (prefix.IsNull() || (prefix.Length() == 0)) { 4265 if (prefix.IsNull() || (prefix.Length() == 0)) {
4264 library_.AddImport(import); 4266 library_.AddImport(ns);
4265 } else { 4267 } else {
4266 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); 4268 LibraryPrefix& library_prefix = LibraryPrefix::Handle();
4267 library_prefix = library_.LookupLocalLibraryPrefix(prefix); 4269 library_prefix = library_.LookupLocalLibraryPrefix(prefix);
4268 if (!library_prefix.IsNull()) { 4270 if (!library_prefix.IsNull()) {
4269 library_prefix.AddImport(import); 4271 library_prefix.AddImport(ns);
4270 } else { 4272 } else {
4271 library_prefix = LibraryPrefix::New(prefix, import); 4273 library_prefix = LibraryPrefix::New(prefix, ns);
4272 library_.AddObject(library_prefix, prefix); 4274 library_.AddObject(library_prefix, prefix);
4273 } 4275 }
4274 } 4276 }
4275 } else if (IsLiteral("export")) {
4276 ErrorMsg("export clause not yet supported");
4277 } else { 4277 } else {
4278 ErrorMsg("unreachable"); 4278 ASSERT(is_export);
4279 UNREACHABLE(); 4279 library_.AddExport(ns);
4280 } 4280 }
4281 } 4281 }
4282 4282
4283 4283
4284 void Parser::ParseLibraryPart() { 4284 void Parser::ParseLibraryPart() {
4285 const intptr_t source_pos = TokenPos(); 4285 const intptr_t source_pos = TokenPos();
4286 ConsumeToken(); // Consume "part". 4286 ConsumeToken(); // Consume "part".
4287 if (CurrentToken() != Token::kSTRING) { 4287 if (CurrentToken() != Token::kSTRING) {
4288 ErrorMsg("url expected"); 4288 ErrorMsg("url expected");
4289 } 4289 }
(...skipping 5410 matching lines...) Expand 10 before | Expand all | Expand 10 after
9700 void Parser::SkipQualIdent() { 9700 void Parser::SkipQualIdent() {
9701 ASSERT(IsIdentifier()); 9701 ASSERT(IsIdentifier());
9702 ConsumeToken(); 9702 ConsumeToken();
9703 if (CurrentToken() == Token::kPERIOD) { 9703 if (CurrentToken() == Token::kPERIOD) {
9704 ConsumeToken(); // Consume the kPERIOD token. 9704 ConsumeToken(); // Consume the kPERIOD token.
9705 ExpectIdentifier("identifier expected after '.'"); 9705 ExpectIdentifier("identifier expected after '.'");
9706 } 9706 }
9707 } 9707 }
9708 9708
9709 } // namespace dart 9709 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698