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

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

Issue 8380020: Refactor the dart api a bit: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 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
OLDNEW
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 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 } 2867 }
2868 const String& name = *CurrentLiteral(); 2868 const String& name = *CurrentLiteral();
2869 ConsumeToken(); 2869 ConsumeToken();
2870 ExpectToken(Token::kRPAREN); 2870 ExpectToken(Token::kRPAREN);
2871 ExpectToken(Token::kSEMICOLON); 2871 ExpectToken(Token::kSEMICOLON);
2872 library_.SetName(name); 2872 library_.SetName(name);
2873 } 2873 }
2874 } 2874 }
2875 2875
2876 2876
2877 Dart_Result Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 2877 Dart_Handle Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
2878 intptr_t token_pos, 2878 intptr_t token_pos,
2879 const String& url) { 2879 const String& url) {
2880 Dart_LibraryTagHandler handler = Isolate::Current()->library_tag_handler(); 2880 Dart_LibraryTagHandler handler = Isolate::Current()->library_tag_handler();
2881 if (handler == NULL) { 2881 if (handler == NULL) {
2882 ErrorMsg(token_pos, "no library handler registered"); 2882 ErrorMsg(token_pos, "no library handler registered");
2883 } 2883 }
2884 Dart_Result result = handler(tag, 2884 Dart_Handle result = handler(tag,
2885 Api::NewLocalHandle(library_), 2885 Api::NewLocalHandle(library_),
2886 Api::NewLocalHandle(url)); 2886 Api::NewLocalHandle(url));
2887 if (!Dart_IsValidResult(result)) { 2887 if (!Dart_IsValid(result)) {
2888 ErrorMsg(token_pos, "library handler failed: %s", 2888 ErrorMsg(token_pos, "library handler failed: %s", Dart_GetError(result));
2889 Dart_GetErrorCString(result));
2890 } 2889 }
2891 return result; 2890 return result;
2892 } 2891 }
2893 2892
2894 2893
2895 void Parser::ParseLibraryImport() { 2894 void Parser::ParseLibraryImport() {
2896 while (CurrentToken() == Token::kIMPORT) { 2895 while (CurrentToken() == Token::kIMPORT) {
2897 intptr_t import_pos = token_index_; 2896 intptr_t import_pos = token_index_;
2898 ConsumeToken(); 2897 ConsumeToken();
2899 ExpectToken(Token::kLPAREN); 2898 ExpectToken(Token::kLPAREN);
(...skipping 13 matching lines...) Expand all
2913 ConsumeToken(); 2912 ConsumeToken();
2914 ExpectToken(Token::kCOLON); 2913 ExpectToken(Token::kCOLON);
2915 if (CurrentToken() != Token::kSTRING) { 2914 if (CurrentToken() != Token::kSTRING) {
2916 ErrorMsg("prefix expected"); 2915 ErrorMsg("prefix expected");
2917 } 2916 }
2918 prefix = CurrentLiteral()->raw(); 2917 prefix = CurrentLiteral()->raw();
2919 ConsumeToken(); 2918 ConsumeToken();
2920 } 2919 }
2921 ExpectToken(Token::kRPAREN); 2920 ExpectToken(Token::kRPAREN);
2922 ExpectToken(Token::kSEMICOLON); 2921 ExpectToken(Token::kSEMICOLON);
2923 Dart_Result result = CallLibraryTagHandler(kCanonicalizeUrl, 2922 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl,
2924 import_pos, 2923 import_pos,
2925 url); 2924 url);
2926 Dart_Handle handle = Dart_GetResult(result);
2927 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 2925 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
2928 // Lookup the library URL. 2926 // Lookup the library URL.
2929 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); 2927 Library& library = Library::Handle(Library::LookupLibrary(canon_url));
2930 if (library.IsNull()) { 2928 if (library.IsNull()) {
2931 // Create a new library object and call the library tag handler. 2929 // Create a new library object and call the library tag handler.
2932 library = Library::New(canon_url); 2930 library = Library::New(canon_url);
2933 library.Register(); 2931 library.Register();
2934 // The tag handler expects the importing library as a parameter. 2932 // The tag handler expects the importing library as a parameter.
2935 CallLibraryTagHandler(kImportTag, import_pos, canon_url); 2933 CallLibraryTagHandler(kImportTag, import_pos, canon_url);
2936 } 2934 }
(...skipping 18 matching lines...) Expand all
2955 intptr_t source_pos = token_index_; 2953 intptr_t source_pos = token_index_;
2956 ConsumeToken(); 2954 ConsumeToken();
2957 ExpectToken(Token::kLPAREN); 2955 ExpectToken(Token::kLPAREN);
2958 if (CurrentToken() != Token::kSTRING) { 2956 if (CurrentToken() != Token::kSTRING) {
2959 ErrorMsg("source url expected"); 2957 ErrorMsg("source url expected");
2960 } 2958 }
2961 const String& url = *CurrentLiteral(); 2959 const String& url = *CurrentLiteral();
2962 ConsumeToken(); 2960 ConsumeToken();
2963 ExpectToken(Token::kRPAREN); 2961 ExpectToken(Token::kRPAREN);
2964 ExpectToken(Token::kSEMICOLON); 2962 ExpectToken(Token::kSEMICOLON);
2965 Dart_Result result = CallLibraryTagHandler(kCanonicalizeUrl, 2963 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl,
2966 source_pos, 2964 source_pos,
2967 url); 2965 url);
2968 Dart_Handle handle = Dart_GetResult(result);
2969 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 2966 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
2970 CallLibraryTagHandler(kSourceTag, source_pos, canon_url); 2967 CallLibraryTagHandler(kSourceTag, source_pos, canon_url);
2971 } 2968 }
2972 } 2969 }
2973 2970
2974 2971
2975 void Parser::ParseLibraryDefinition() { 2972 void Parser::ParseLibraryDefinition() {
2976 // Handle the script tag. 2973 // Handle the script tag.
2977 if (CurrentToken() == Token::kSCRIPTTAG) { 2974 if (CurrentToken() == Token::kSCRIPTTAG) {
2978 // Nothing to do for script tags except to skip them. 2975 // Nothing to do for script tags except to skip them.
(...skipping 4026 matching lines...) Expand 10 before | Expand all | Expand 10 after
7005 } 7002 }
7006 7003
7007 7004
7008 void Parser::SkipNestedExpr() { 7005 void Parser::SkipNestedExpr() {
7009 const bool saved_mode = SetAllowFunctionLiterals(true); 7006 const bool saved_mode = SetAllowFunctionLiterals(true);
7010 SkipExpr(); 7007 SkipExpr();
7011 SetAllowFunctionLiterals(saved_mode); 7008 SetAllowFunctionLiterals(saved_mode);
7012 } 7009 }
7013 7010
7014 } // namespace dart 7011 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698