Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 3144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3155 if ((CurrentToken() != Token::kIDENT) || | 3155 if ((CurrentToken() != Token::kIDENT) || |
| 3156 !kPrefix.Equals(*CurrentLiteral())) { | 3156 !kPrefix.Equals(*CurrentLiteral())) { |
| 3157 ErrorMsg("prefix: expected"); | 3157 ErrorMsg("prefix: expected"); |
| 3158 } | 3158 } |
| 3159 ConsumeToken(); | 3159 ConsumeToken(); |
| 3160 ExpectToken(Token::kCOLON); | 3160 ExpectToken(Token::kCOLON); |
| 3161 if (CurrentToken() != Token::kSTRING) { | 3161 if (CurrentToken() != Token::kSTRING) { |
| 3162 ErrorMsg("prefix expected"); | 3162 ErrorMsg("prefix expected"); |
| 3163 } | 3163 } |
| 3164 prefix = CurrentLiteral()->raw(); | 3164 prefix = CurrentLiteral()->raw(); |
| 3165 // Canonicalize the prefix string, this also simplifies the string. | |
| 3166 prefix = String::NewSymbol(prefix); | |
|
hausner
2011/11/21 21:58:10
The scanner already makes a symbol out of a string
siva
2011/11/21 22:14:28
Done.
| |
| 3167 // TODO(asiva): Need to also check that prefix is not a reserved keyword. | |
| 3168 if (!Scanner::IsIdent(prefix)) { | |
| 3169 ErrorMsg("prefix should be an identifier"); | |
| 3170 } | |
| 3165 ConsumeToken(); | 3171 ConsumeToken(); |
| 3166 } | 3172 } |
| 3167 ExpectToken(Token::kRPAREN); | 3173 ExpectToken(Token::kRPAREN); |
| 3168 ExpectToken(Token::kSEMICOLON); | 3174 ExpectToken(Token::kSEMICOLON); |
| 3169 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, | 3175 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, |
| 3170 import_pos, | 3176 import_pos, |
| 3171 url); | 3177 url); |
| 3172 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | 3178 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); |
| 3173 // Lookup the library URL. | 3179 // Lookup the library URL. |
| 3174 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); | 3180 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); |
| 3175 if (library.IsNull()) { | 3181 if (library.IsNull()) { |
| 3176 // Create a new library object and call the library tag handler. | 3182 // Create a new library object and call the library tag handler. |
| 3177 library = Library::New(canon_url); | 3183 library = Library::New(canon_url); |
| 3178 library.Register(); | 3184 library.Register(); |
| 3179 // The tag handler expects the importing library as a parameter. | 3185 // The tag handler expects the importing library as a parameter. |
| 3180 CallLibraryTagHandler(kImportTag, import_pos, canon_url); | 3186 CallLibraryTagHandler(kImportTag, import_pos, canon_url); |
| 3181 } | 3187 } |
| 3182 // Add the import to the library. | 3188 // Add the import to the library. |
| 3183 if (prefix.IsNull() || (prefix.Length() == 0)) { | 3189 if (prefix.IsNull() || (prefix.Length() == 0)) { |
| 3184 library_.AddImport(library); | 3190 library_.AddImport(library); |
| 3185 } else { | 3191 } else { |
| 3186 if (library_.LookupLocalObject(prefix) != Object::null()) { | 3192 if (library_.LookupLocalObject(prefix) != Object::null()) { |
| 3187 ErrorMsg(token_index_, "'%s' is already defined", prefix.ToCString()); | 3193 ErrorMsg(token_index_, "'%s' is already defined", prefix.ToCString()); |
| 3188 } | 3194 } |
| 3189 prefix = String::NewSymbol(prefix); | |
| 3190 const LibraryPrefix& library_prefix = | 3195 const LibraryPrefix& library_prefix = |
| 3191 LibraryPrefix::Handle(LibraryPrefix::New(prefix, library)); | 3196 LibraryPrefix::Handle(LibraryPrefix::New(prefix, library)); |
| 3192 library_.AddObject(library_prefix, prefix); | 3197 library_.AddObject(library_prefix, prefix); |
| 3193 } | 3198 } |
| 3194 } | 3199 } |
| 3195 } | 3200 } |
| 3196 | 3201 |
| 3197 | 3202 |
| 3198 void Parser::ParseLibraryInclude() { | 3203 void Parser::ParseLibraryInclude() { |
| 3199 while (CurrentToken() == Token::kSOURCE) { | 3204 while (CurrentToken() == Token::kSOURCE) { |
| (...skipping 4229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7429 } | 7434 } |
| 7430 | 7435 |
| 7431 | 7436 |
| 7432 void Parser::SkipNestedExpr() { | 7437 void Parser::SkipNestedExpr() { |
| 7433 const bool saved_mode = SetAllowFunctionLiterals(true); | 7438 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7434 SkipExpr(); | 7439 SkipExpr(); |
| 7435 SetAllowFunctionLiterals(saved_mode); | 7440 SetAllowFunctionLiterals(saved_mode); |
| 7436 } | 7441 } |
| 7437 | 7442 |
| 7438 } // namespace dart | 7443 } // namespace dart |
| OLD | NEW |