| 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 "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 4000 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4011   AddFormalParamsToFunction(¶ms, func); |  4011   AddFormalParamsToFunction(¶ms, func); | 
|  4012   top_level->functions.Add(func); |  4012   top_level->functions.Add(func); | 
|  4013   if (!is_patch) { |  4013   if (!is_patch) { | 
|  4014     library_.AddObject(func, accessor_name); |  4014     library_.AddObject(func, accessor_name); | 
|  4015   } else { |  4015   } else { | 
|  4016     library_.ReplaceObject(func, accessor_name); |  4016     library_.ReplaceObject(func, accessor_name); | 
|  4017   } |  4017   } | 
|  4018 } |  4018 } | 
|  4019  |  4019  | 
|  4020  |  4020  | 
|  4021 void Parser::ParseLibraryName() { |  4021 // TODO(hausner): Remove support for old library definition syntax. | 
|  4022   TRACE_PARSER("ParseLibraryName"); |  4022 void Parser::ParseLibraryNameObsoleteSyntax() { | 
|  4023   if ((script_.kind() == RawScript::kLibraryTag) && |  4023   if ((script_.kind() == RawScript::kLibraryTag) && | 
|  4024       (CurrentToken() != Token::kLIBRARY)) { |  4024       (CurrentToken() != Token::kLIBRARY)) { | 
|  4025     // Handle error case early to get consistent error message. |  4025     // Handle error case early to get consistent error message. | 
|  4026     ExpectToken(Token::kLIBRARY); |  4026     ExpectToken(Token::kLIBRARY); | 
|  4027   } |  4027   } | 
|  4028   if (CurrentToken() == Token::kLIBRARY) { |  4028   if (CurrentToken() == Token::kLIBRARY) { | 
|  4029     ConsumeToken(); |  4029     ConsumeToken(); | 
|  4030     ExpectToken(Token::kLPAREN); |  4030     ExpectToken(Token::kLPAREN); | 
|  4031     if (CurrentToken() != Token::kSTRING) { |  4031     if (CurrentToken() != Token::kSTRING) { | 
|  4032       ErrorMsg("library name expected"); |  4032       ErrorMsg("library name expected"); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  4053                                Api::NewHandle(isolate, url.raw())); |  4053                                Api::NewHandle(isolate, url.raw())); | 
|  4054   if (Dart_IsError(result)) { |  4054   if (Dart_IsError(result)) { | 
|  4055     Error& prev_error = Error::Handle(); |  4055     Error& prev_error = Error::Handle(); | 
|  4056     prev_error ^= Api::UnwrapHandle(result); |  4056     prev_error ^= Api::UnwrapHandle(result); | 
|  4057     AppendErrorMsg(prev_error, token_pos, "library handler failed"); |  4057     AppendErrorMsg(prev_error, token_pos, "library handler failed"); | 
|  4058   } |  4058   } | 
|  4059   return result; |  4059   return result; | 
|  4060 } |  4060 } | 
|  4061  |  4061  | 
|  4062  |  4062  | 
|  4063 void Parser::ParseLibraryImport() { |  4063 // TODO(hausner): Remove support for old library definition syntax. | 
|  4064   TRACE_PARSER("ParseLibraryImport"); |  4064 void Parser::ParseLibraryImportObsoleteSyntax() { | 
|  4065   while (CurrentToken() == Token::kIMPORT) { |  4065   while (CurrentToken() == Token::kIMPORT) { | 
|  4066     const intptr_t import_pos = TokenPos(); |  4066     const intptr_t import_pos = TokenPos(); | 
|  4067     ConsumeToken(); |  4067     ConsumeToken(); | 
|  4068     ExpectToken(Token::kLPAREN); |  4068     ExpectToken(Token::kLPAREN); | 
|  4069     if (CurrentToken() != Token::kSTRING) { |  4069     if (CurrentToken() != Token::kSTRING) { | 
|  4070       ErrorMsg("library url expected"); |  4070       ErrorMsg("library url expected"); | 
|  4071     } |  4071     } | 
|  4072     const String& url = *CurrentLiteral(); |  4072     const String& url = *CurrentLiteral(); | 
|  4073     ConsumeToken(); |  4073     ConsumeToken(); | 
|  4074     String& prefix = String::Handle(); |  4074     String& prefix = String::Handle(); | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4118         library_prefix.AddLibrary(library); |  4118         library_prefix.AddLibrary(library); | 
|  4119       } else { |  4119       } else { | 
|  4120         library_prefix = LibraryPrefix::New(prefix, library); |  4120         library_prefix = LibraryPrefix::New(prefix, library); | 
|  4121         library_.AddObject(library_prefix, prefix); |  4121         library_.AddObject(library_prefix, prefix); | 
|  4122       } |  4122       } | 
|  4123     } |  4123     } | 
|  4124   } |  4124   } | 
|  4125 } |  4125 } | 
|  4126  |  4126  | 
|  4127  |  4127  | 
|  4128 void Parser::ParseLibraryInclude() { |  4128 // TODO(hausner): Remove support for old library definition syntax. | 
|  4129   TRACE_PARSER("ParseLibraryInclude"); |  4129 void Parser::ParseLibraryIncludeObsoleteSyntax() { | 
|  4130   while (CurrentToken() == Token::kSOURCE) { |  4130   while (CurrentToken() == Token::kSOURCE) { | 
|  4131     const intptr_t source_pos = TokenPos(); |  4131     const intptr_t source_pos = TokenPos(); | 
|  4132     ConsumeToken(); |  4132     ConsumeToken(); | 
|  4133     ExpectToken(Token::kLPAREN); |  4133     ExpectToken(Token::kLPAREN); | 
|  4134     if (CurrentToken() != Token::kSTRING) { |  4134     if (CurrentToken() != Token::kSTRING) { | 
|  4135       ErrorMsg("source url expected"); |  4135       ErrorMsg("source url expected"); | 
|  4136     } |  4136     } | 
|  4137     const String& url = *CurrentLiteral(); |  4137     const String& url = *CurrentLiteral(); | 
|  4138     ConsumeToken(); |  4138     ConsumeToken(); | 
|  4139     ExpectToken(Token::kRPAREN); |  4139     ExpectToken(Token::kRPAREN); | 
|  4140     ExpectToken(Token::kSEMICOLON); |  4140     ExpectToken(Token::kSEMICOLON); | 
|  4141     Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, |  4141     Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, | 
|  4142                                                source_pos, |  4142                                                source_pos, | 
|  4143                                                url); |  4143                                                url); | 
|  4144     const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); |  4144     const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | 
|  4145     CallLibraryTagHandler(kSourceTag, source_pos, canon_url); |  4145     CallLibraryTagHandler(kSourceTag, source_pos, canon_url); | 
|  4146   } |  4146   } | 
|  4147 } |  4147 } | 
|  4148  |  4148  | 
|  4149  |  4149  | 
|  4150 void Parser::ParseLibraryResource() { |  4150 // TODO(hausner): Remove support for old library definition syntax. | 
|  4151   TRACE_PARSER("ParseLibraryResource"); |  4151 void Parser::ParseLibraryResourceObsoleteSyntax() { | 
|  4152   while (CurrentToken() == Token::kRESOURCE) { |  4152   while (CurrentToken() == Token::kRESOURCE) { | 
|  4153     // Currently the VM does ignore #resource library tags. They are only used |  4153     // Currently the VM does ignore #resource library tags. They are only used | 
|  4154     // by the IDE. |  4154     // by the IDE. | 
|  4155     ConsumeToken(); |  4155     ConsumeToken(); | 
|  4156     ExpectToken(Token::kLPAREN); |  4156     ExpectToken(Token::kLPAREN); | 
|  4157     if (CurrentToken() != Token::kSTRING) { |  4157     if (CurrentToken() != Token::kSTRING) { | 
|  4158       ErrorMsg("resource url expected"); |  4158       ErrorMsg("resource url expected"); | 
|  4159     } |  4159     } | 
|  4160     ConsumeToken(); |  4160     ConsumeToken(); | 
|  4161     ExpectToken(Token::kRPAREN); |  4161     ExpectToken(Token::kRPAREN); | 
|  4162     ExpectToken(Token::kSEMICOLON); |  4162     ExpectToken(Token::kSEMICOLON); | 
|  4163   } |  4163   } | 
|  4164 } |  4164 } | 
|  4165  |  4165  | 
|  4166  |  4166  | 
 |  4167 void Parser::ParseLibraryName() { | 
 |  4168   ASSERT(IsLiteral("library")); | 
 |  4169   ConsumeToken(); | 
 |  4170   // TODO(hausner): Exact syntax of library name still unclear: identifier, | 
 |  4171   // qualified identifier or even multiple dots allowed? For now we just | 
 |  4172   // accept simple identifiers. | 
 |  4173   const String& lib_name = *ExpectIdentifier("library name expected"); | 
 |  4174   library_.SetName(lib_name); | 
 |  4175   ExpectSemicolon(); | 
 |  4176 } | 
 |  4177  | 
 |  4178  | 
 |  4179 void Parser::ParseLibraryImportExport() { | 
 |  4180   if (IsLiteral("import")) { | 
 |  4181     const intptr_t import_pos = TokenPos(); | 
 |  4182     ConsumeToken(); | 
 |  4183     if (CurrentToken() != Token::kSTRING) { | 
 |  4184       ErrorMsg("library url expected"); | 
 |  4185     } | 
 |  4186     const String& url = *CurrentLiteral(); | 
 |  4187     if (url.Length() == 0) { | 
 |  4188       ErrorMsg("library url expected"); | 
 |  4189     } | 
 |  4190     ConsumeToken(); | 
 |  4191     String& prefix = String::Handle(); | 
 |  4192     if (IsLiteral("as")) { | 
 |  4193       ConsumeToken(); | 
 |  4194       prefix = ExpectIdentifier("prefix expected")->raw(); | 
 |  4195     } | 
 |  4196     if (IsLiteral("show")) { | 
 |  4197       ErrorMsg("show combinator not yet supported"); | 
 |  4198     } else if (IsLiteral("hide")) { | 
 |  4199       ErrorMsg("hide combinator not yet supported"); | 
 |  4200     } | 
 |  4201     ExpectSemicolon(); | 
 |  4202  | 
 |  4203     // Canonicalize library URL. | 
 |  4204     Dart_Handle handle = | 
 |  4205         CallLibraryTagHandler(kCanonicalizeUrl, import_pos, url); | 
 |  4206     const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | 
 |  4207     // Lookup the library URL. | 
 |  4208     Library& library = Library::Handle(Library::LookupLibrary(canon_url)); | 
 |  4209     if (library.IsNull()) { | 
 |  4210       // Call the library tag handler to load the library. | 
 |  4211       CallLibraryTagHandler(kImportTag, import_pos, canon_url); | 
 |  4212       // If the library tag handler succeded without registering the | 
 |  4213       // library we create an empty library to import. | 
 |  4214       library = Library::LookupLibrary(canon_url); | 
 |  4215       if (library.IsNull()) { | 
 |  4216         library = Library::New(canon_url); | 
 |  4217         library.Register(); | 
 |  4218       } | 
 |  4219     } | 
 |  4220     // Add the import to the library. | 
 |  4221     if (prefix.IsNull() || (prefix.Length() == 0)) { | 
 |  4222       library_.AddImport(library); | 
 |  4223     } else { | 
 |  4224       LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 
 |  4225       library_prefix = library_.LookupLocalLibraryPrefix(prefix); | 
 |  4226       if (!library_prefix.IsNull()) { | 
 |  4227         library_prefix.AddLibrary(library); | 
 |  4228       } else { | 
 |  4229         library_prefix = LibraryPrefix::New(prefix, library); | 
 |  4230         library_.AddObject(library_prefix, prefix); | 
 |  4231       } | 
 |  4232     } | 
 |  4233   } else if (IsLiteral("export")) { | 
 |  4234     ErrorMsg("export clause not yet supported"); | 
 |  4235   } else { | 
 |  4236     ErrorMsg("unreachable"); | 
 |  4237     UNREACHABLE(); | 
 |  4238   } | 
 |  4239 } | 
 |  4240  | 
 |  4241  | 
 |  4242 void Parser::ParseLibraryPart() { | 
 |  4243   ErrorMsg("library part definitions not implemented"); | 
 |  4244 } | 
 |  4245  | 
 |  4246  | 
|  4167 void Parser::ParseLibraryDefinition() { |  4247 void Parser::ParseLibraryDefinition() { | 
|  4168   TRACE_PARSER("ParseLibraryDefinition"); |  4248   TRACE_PARSER("ParseLibraryDefinition"); | 
 |  4249  | 
|  4169   // Handle the script tag. |  4250   // Handle the script tag. | 
|  4170   if (CurrentToken() == Token::kSCRIPTTAG) { |  4251   if (CurrentToken() == Token::kSCRIPTTAG) { | 
|  4171     // Nothing to do for script tags except to skip them. |  4252     // Nothing to do for script tags except to skip them. | 
|  4172     ConsumeToken(); |  4253     ConsumeToken(); | 
|  4173   } |  4254   } | 
|  4174  |  4255  | 
|  4175   ParseLibraryName(); |  4256   // TODO(hausner): Remove support for old library definition syntax. | 
|  4176   ParseLibraryImport(); |  4257   if ((CurrentToken() == Token::kLIBRARY) || | 
|  4177   ParseLibraryInclude(); |  4258       (CurrentToken() == Token::kIMPORT) || | 
|  4178   ParseLibraryResource(); |  4259       (CurrentToken() == Token::kSOURCE) || | 
 |  4260       (CurrentToken() == Token::kRESOURCE)) { | 
 |  4261     ParseLibraryNameObsoleteSyntax(); | 
 |  4262     ParseLibraryImportObsoleteSyntax(); | 
 |  4263     ParseLibraryIncludeObsoleteSyntax(); | 
 |  4264     ParseLibraryResourceObsoleteSyntax(); | 
 |  4265     return; | 
 |  4266   } | 
 |  4267  | 
 |  4268   // We may read metadata tokens that are part of the toplevel | 
 |  4269   // declaration that follows the library definitions. Therefore, we | 
 |  4270   // need to remember the position of the last token that was | 
 |  4271   // successfully consumed. | 
 |  4272   intptr_t metadata_pos = TokenPos(); | 
 |  4273   SkipMetadata(); | 
 |  4274   if (IsLiteral("library")) { | 
 |  4275     ParseLibraryName(); | 
 |  4276     metadata_pos = TokenPos(); | 
 |  4277     SkipMetadata(); | 
 |  4278   } else if (script_.kind() == RawScript::kLibraryTag) { | 
 |  4279     ErrorMsg("library name definition expected"); | 
 |  4280   } | 
 |  4281   while (IsLiteral("import") || IsLiteral("export")) { | 
 |  4282     ParseLibraryImportExport(); | 
 |  4283     metadata_pos = TokenPos(); | 
 |  4284     SkipMetadata(); | 
 |  4285   } | 
 |  4286   while (IsLiteral("part")) { | 
 |  4287     ParseLibraryPart(); | 
 |  4288     metadata_pos = TokenPos(); | 
 |  4289     SkipMetadata(); | 
 |  4290   } | 
 |  4291   if (IsLiteral("library") || IsLiteral("import") || IsLiteral("export")) { | 
 |  4292     ErrorMsg("unexpected token '%s'", CurrentLiteral()->ToCString()); | 
 |  4293   } | 
 |  4294   SetPosition(metadata_pos); | 
|  4179 } |  4295 } | 
|  4180  |  4296  | 
|  4181  |  4297  | 
|  4182 void Parser::ParseTopLevel() { |  4298 void Parser::ParseTopLevel() { | 
|  4183   TRACE_PARSER("ParseTopLevel"); |  4299   TRACE_PARSER("ParseTopLevel"); | 
|  4184   // Collect the classes found at the top level in this growable array. |  4300   // Collect the classes found at the top level in this growable array. | 
|  4185   // They need to be registered with class finalization after parsing |  4301   // They need to be registered with class finalization after parsing | 
|  4186   // has been completed. |  4302   // has been completed. | 
|  4187   Isolate* isolate = Isolate::Current(); |  4303   Isolate* isolate = Isolate::Current(); | 
|  4188   ObjectStore* object_store = isolate->object_store(); |  4304   ObjectStore* object_store = isolate->object_store(); | 
| (...skipping 5254 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  9443 void Parser::SkipQualIdent() { |  9559 void Parser::SkipQualIdent() { | 
|  9444   ASSERT(IsIdentifier()); |  9560   ASSERT(IsIdentifier()); | 
|  9445   ConsumeToken(); |  9561   ConsumeToken(); | 
|  9446   if (CurrentToken() == Token::kPERIOD) { |  9562   if (CurrentToken() == Token::kPERIOD) { | 
|  9447     ConsumeToken();  // Consume the kPERIOD token. |  9563     ConsumeToken();  // Consume the kPERIOD token. | 
|  9448     ExpectIdentifier("identifier expected after '.'"); |  9564     ExpectIdentifier("identifier expected after '.'"); | 
|  9449   } |  9565   } | 
|  9450 } |  9566 } | 
|  9451  |  9567  | 
|  9452 }  // namespace dart |  9568 }  // namespace dart | 
| OLD | NEW |