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 // TODO(asiva): Need to also check that prefix is not a reserved keyword. |
| 3166 if (!Scanner::IsIdent(prefix)) { |
| 3167 ErrorMsg("prefix should be an identifier"); |
| 3168 } |
3165 ConsumeToken(); | 3169 ConsumeToken(); |
3166 } | 3170 } |
3167 ExpectToken(Token::kRPAREN); | 3171 ExpectToken(Token::kRPAREN); |
3168 ExpectToken(Token::kSEMICOLON); | 3172 ExpectToken(Token::kSEMICOLON); |
3169 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, | 3173 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, |
3170 import_pos, | 3174 import_pos, |
3171 url); | 3175 url); |
3172 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); | 3176 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); |
3173 // Lookup the library URL. | 3177 // Lookup the library URL. |
3174 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); | 3178 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); |
3175 if (library.IsNull()) { | 3179 if (library.IsNull()) { |
3176 // Create a new library object and call the library tag handler. | 3180 // Create a new library object and call the library tag handler. |
3177 library = Library::New(canon_url); | 3181 library = Library::New(canon_url); |
3178 library.Register(); | 3182 library.Register(); |
3179 // The tag handler expects the importing library as a parameter. | 3183 // The tag handler expects the importing library as a parameter. |
3180 CallLibraryTagHandler(kImportTag, import_pos, canon_url); | 3184 CallLibraryTagHandler(kImportTag, import_pos, canon_url); |
3181 } | 3185 } |
3182 // Add the import to the library. | 3186 // Add the import to the library. |
3183 if (prefix.IsNull() || (prefix.Length() == 0)) { | 3187 if (prefix.IsNull() || (prefix.Length() == 0)) { |
3184 library_.AddImport(library); | 3188 library_.AddImport(library); |
3185 } else { | 3189 } else { |
3186 if (library_.LookupLocalObject(prefix) != Object::null()) { | 3190 if (library_.LookupLocalObject(prefix) != Object::null()) { |
3187 ErrorMsg(token_index_, "'%s' is already defined", prefix.ToCString()); | 3191 ErrorMsg(token_index_, "'%s' is already defined", prefix.ToCString()); |
3188 } | 3192 } |
3189 prefix = String::NewSymbol(prefix); | |
3190 const LibraryPrefix& library_prefix = | 3193 const LibraryPrefix& library_prefix = |
3191 LibraryPrefix::Handle(LibraryPrefix::New(prefix, library)); | 3194 LibraryPrefix::Handle(LibraryPrefix::New(prefix, library)); |
3192 library_.AddObject(library_prefix, prefix); | 3195 library_.AddObject(library_prefix, prefix); |
3193 } | 3196 } |
3194 } | 3197 } |
3195 } | 3198 } |
3196 | 3199 |
3197 | 3200 |
3198 void Parser::ParseLibraryInclude() { | 3201 void Parser::ParseLibraryInclude() { |
3199 while (CurrentToken() == Token::kSOURCE) { | 3202 while (CurrentToken() == Token::kSOURCE) { |
(...skipping 4229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7429 } | 7432 } |
7430 | 7433 |
7431 | 7434 |
7432 void Parser::SkipNestedExpr() { | 7435 void Parser::SkipNestedExpr() { |
7433 const bool saved_mode = SetAllowFunctionLiterals(true); | 7436 const bool saved_mode = SetAllowFunctionLiterals(true); |
7434 SkipExpr(); | 7437 SkipExpr(); |
7435 SetAllowFunctionLiterals(saved_mode); | 7438 SetAllowFunctionLiterals(saved_mode); |
7436 } | 7439 } |
7437 | 7440 |
7438 } // namespace dart | 7441 } // namespace dart |
OLD | NEW |