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

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

Issue 9186058: Make the "sticky error" an Error instead of a String. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 signature_function, 878 signature_function,
879 script_); 879 script_);
880 // Record the function signature class in the current library. 880 // Record the function signature class in the current library.
881 library_.AddClass(signature_class); 881 library_.AddClass(signature_class);
882 } else { 882 } else {
883 signature_function.set_signature_class(signature_class); 883 signature_function.set_signature_class(signature_class);
884 } 884 }
885 ASSERT(signature_function.signature_class() == signature_class.raw()); 885 ASSERT(signature_function.signature_class() == signature_class.raw());
886 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); 886 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType());
887 if (!is_top_level_ && !signature_type.IsFinalized()) { 887 if (!is_top_level_ && !signature_type.IsFinalized()) {
888 String& errmsg = String::Handle(); 888 Error& error = Error::Handle();
889 signature_type ^= 889 signature_type ^=
890 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, 890 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
891 signature_type, 891 signature_type,
892 &errmsg); 892 &error);
893 if (!errmsg.IsNull()) { 893 if (!error.IsNull()) {
894 ErrorMsg(errmsg.ToCString()); 894 ErrorMsg(error.ToErrorCString());
895 } 895 }
896 } 896 }
897 // The type of the parameter is now the signature type. 897 // The type of the parameter is now the signature type.
898 parameter.type = &signature_type; 898 parameter.type = &signature_type;
899 } 899 }
900 } 900 }
901 901
902 if (CurrentToken() == Token::kASSIGN) { 902 if (CurrentToken() == Token::kASSIGN) {
903 if (!params->has_named_optional_parameters || 903 if (!params->has_named_optional_parameters ||
904 !allow_explicit_default_value) { 904 !allow_explicit_default_value) {
(...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after
3829 // Patch the function type now that the signature is known. 3829 // Patch the function type now that the signature is known.
3830 // We need to create a new type for proper finalization, since the existing 3830 // We need to create a new type for proper finalization, since the existing
3831 // type is already marked as finalized. 3831 // type is already marked as finalized.
3832 Type& signature_type = Type::Handle(signature_class.SignatureType()); 3832 Type& signature_type = Type::Handle(signature_class.SignatureType());
3833 const AbstractTypeArguments& signature_type_arguments = 3833 const AbstractTypeArguments& signature_type_arguments =
3834 AbstractTypeArguments::Handle(signature_type.arguments()); 3834 AbstractTypeArguments::Handle(signature_type.arguments());
3835 3835
3836 // Since the signature type is cached by the signature class, it may have 3836 // Since the signature type is cached by the signature class, it may have
3837 // been finalized already. 3837 // been finalized already.
3838 if (!signature_type.IsFinalized()) { 3838 if (!signature_type.IsFinalized()) {
3839 String& errmsg = String::Handle(); 3839 Error& error = Error::Handle();
3840 signature_type ^= 3840 signature_type ^=
3841 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, 3841 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
3842 signature_type, 3842 signature_type,
3843 &errmsg); 3843 &error);
3844 if (!errmsg.IsNull()) { 3844 if (!error.IsNull()) {
3845 ErrorMsg(errmsg.ToCString()); 3845 ErrorMsg(error.ToErrorCString());
3846 } 3846 }
3847 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have 3847 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have
3848 // extended the vector of type arguments. 3848 // extended the vector of type arguments.
3849 ASSERT(signature_type_arguments.IsNull() || 3849 ASSERT(signature_type_arguments.IsNull() ||
3850 (signature_type_arguments.Length() == 3850 (signature_type_arguments.Length() ==
3851 signature_class.NumTypeArguments())); 3851 signature_class.NumTypeArguments()));
3852 // The signature_class should not have changed. 3852 // The signature_class should not have changed.
3853 ASSERT(signature_type.type_class() == signature_class.raw()); 3853 ASSERT(signature_type.type_class() == signature_class.raw());
3854 } 3854 }
3855 3855
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
5162 new LoadLocalNode(statement_pos, *trace_var)); 5162 new LoadLocalNode(statement_pos, *trace_var));
5163 } 5163 }
5164 } else { 5164 } else {
5165 statement = ParseExpr(kAllowConst); 5165 statement = ParseExpr(kAllowConst);
5166 ExpectSemicolon(); 5166 ExpectSemicolon();
5167 } 5167 }
5168 return statement; 5168 return statement;
5169 } 5169 }
5170 5170
5171 5171
5172 // Static
5173 RawError* Parser::FormatError(const Script& script,
5174 intptr_t token_index,
5175 const char* message_header,
5176 const char* format,
5177 va_list args) {
5178 const intptr_t kMessageBufferSize = 512;
5179 char message_buffer[kMessageBufferSize];
5180 FormatMessage(script, token_index, message_header,
5181 message_buffer, kMessageBufferSize,
5182 format, args);
5183 const String& msg = String::Handle(String::New(message_buffer));
5184 return LanguageError::New(msg);
5185 }
5186
5187
5172 // Static. 5188 // Static.
5173 void Parser::FormatMessage(const Script& script, 5189 void Parser::FormatMessage(const Script& script,
5174 intptr_t token_index, 5190 intptr_t token_index,
5175 const char* message_header, 5191 const char* message_header,
5176 char* message_buffer, 5192 char* message_buffer,
5177 intptr_t message_buffer_size, 5193 intptr_t message_buffer_size,
5178 const char* format, va_list args) { 5194 const char* format, va_list args) {
5179 intptr_t msg_len = 0; 5195 intptr_t msg_len = 0;
5180 if (!script.IsNull()) { 5196 if (!script.IsNull()) {
5181 const String& script_url = String::CheckedHandle(script.url()); 5197 const String& script_url = String::CheckedHandle(script.url());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5227 // Append the formatted error or warning message. 5243 // Append the formatted error or warning message.
5228 msg_len += OS::VSNPrint(message_buffer + msg_len, 5244 msg_len += OS::VSNPrint(message_buffer + msg_len,
5229 message_buffer_size - msg_len, 5245 message_buffer_size - msg_len,
5230 format, 5246 format,
5231 args); 5247 args);
5232 } 5248 }
5233 } 5249 }
5234 5250
5235 5251
5236 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) { 5252 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) {
5237 const intptr_t kMessageBufferSize = 512;
5238 char message_buffer[kMessageBufferSize];
5239 va_list args; 5253 va_list args;
5240 va_start(args, format); 5254 va_start(args, format);
5241 FormatMessage(script_, token_index, "Error", 5255 const Error& error = Error::Handle(
5242 message_buffer, kMessageBufferSize, 5256 FormatError(script_, token_index, "Error", format, args));
5243 format, args);
5244 va_end(args); 5257 va_end(args);
5245 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); 5258 Isolate::Current()->long_jump_base()->Jump(1, error);
5246 UNREACHABLE(); 5259 UNREACHABLE();
5247 } 5260 }
5248 5261
5249 5262
5250 void Parser::ErrorMsg(const char* format, ...) { 5263 void Parser::ErrorMsg(const char* format, ...) {
5251 const intptr_t kMessageBufferSize = 512;
5252 char message_buffer[kMessageBufferSize];
5253 va_list args; 5264 va_list args;
5254 va_start(args, format); 5265 va_start(args, format);
5255 FormatMessage(script_, token_index_, "Error", 5266 const Error& error = Error::Handle(
5256 message_buffer, kMessageBufferSize, 5267 FormatError(script_, token_index_, "Error", format, args));
5257 format, args);
5258 va_end(args); 5268 va_end(args);
5259 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); 5269 Isolate::Current()->long_jump_base()->Jump(1, error);
5260 UNREACHABLE(); 5270 UNREACHABLE();
5261 } 5271 }
5262 5272
5263 5273
5264 void Parser::Warning(intptr_t token_index, const char* format, ...) { 5274 void Parser::Warning(intptr_t token_index, const char* format, ...) {
5265 const intptr_t kMessageBufferSize = 512;
5266 char message_buffer[kMessageBufferSize];
5267 if (FLAG_silent_warnings) return; 5275 if (FLAG_silent_warnings) return;
5268 va_list args; 5276 va_list args;
5269 va_start(args, format); 5277 va_start(args, format);
5270 FormatMessage(script_, token_index, "Warning", 5278 const Error& error = Error::Handle(
5271 message_buffer, kMessageBufferSize, 5279 FormatError(script_, token_index, "Warning", format, args));
5272 format, args);
5273 va_end(args); 5280 va_end(args);
5274 if (FLAG_warning_as_error) { 5281 if (FLAG_warning_as_error) {
5275 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); 5282 Isolate::Current()->long_jump_base()->Jump(1, error);
5276 UNREACHABLE(); 5283 UNREACHABLE();
5277 } else { 5284 } else {
5278 OS::Print(message_buffer); 5285 OS::Print("%s", error.ToErrorCString());
5279 } 5286 }
5280 } 5287 }
5281 5288
5282 5289
5283 void Parser::Warning(const char* format, ...) { 5290 void Parser::Warning(const char* format, ...) {
5284 const intptr_t kMessageBufferSize = 512;
5285 char message_buffer[kMessageBufferSize];
5286 if (FLAG_silent_warnings) return; 5291 if (FLAG_silent_warnings) return;
5287 va_list args; 5292 va_list args;
5288 va_start(args, format); 5293 va_start(args, format);
5289 FormatMessage(script_, token_index_, "Warning", 5294 const Error& error = Error::Handle(
5290 message_buffer, kMessageBufferSize, 5295 FormatError(script_, token_index_, "Warning", format, args));
5291 format, args);
5292 va_end(args); 5296 va_end(args);
5293 if (FLAG_warning_as_error) { 5297 if (FLAG_warning_as_error) {
5294 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); 5298 Isolate::Current()->long_jump_base()->Jump(1, error);
5295 UNREACHABLE(); 5299 UNREACHABLE();
5296 } else { 5300 } else {
5297 OS::Print(message_buffer); 5301 OS::Print("%s", error.ToErrorCString());
5298 } 5302 }
5299 } 5303 }
5300 5304
5301 5305
5302 void Parser::Unimplemented(const char* msg) { 5306 void Parser::Unimplemented(const char* msg) {
5303 ErrorMsg(token_index_, msg); 5307 ErrorMsg(token_index_, msg);
5304 } 5308 }
5305 5309
5306 5310
5307 void Parser::ExpectToken(Token::Kind token_expected) { 5311 void Parser::ExpectToken(Token::Kind token_expected) {
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after
6674 } else { 6678 } else {
6675 // Check if ident is a type parameter in scope. 6679 // Check if ident is a type parameter in scope.
6676 type_parameter = scope_class.LookupTypeParameter(*type_name.ident); 6680 type_parameter = scope_class.LookupTypeParameter(*type_name.ident);
6677 if (!type_parameter.IsNull()) { 6681 if (!type_parameter.IsNull()) {
6678 if (CurrentToken() == Token::kLT) { 6682 if (CurrentToken() == Token::kLT) {
6679 // A type parameter cannot be parameterized. 6683 // A type parameter cannot be parameterized.
6680 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", 6684 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized",
6681 String::Handle(type_parameter.Name()).ToCString()); 6685 String::Handle(type_parameter.Name()).ToCString());
6682 } 6686 }
6683 if (type_resolution == kMustResolve) { 6687 if (type_resolution == kMustResolve) {
6684 String& errmsg = String::Handle(); 6688 Error& error = Error::Handle();
6685 type_parameter ^= 6689 type_parameter ^=
6686 ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, 6690 ClassFinalizer::FinalizeAndCanonicalizeType(scope_class,
6687 type_parameter, 6691 type_parameter,
6688 &errmsg); 6692 &error);
6689 if (!errmsg.IsNull()) { 6693 if (!error.IsNull()) {
6690 ErrorMsg(errmsg.ToCString()); 6694 ErrorMsg(error.ToErrorCString());
6691 } 6695 }
6692 } 6696 }
6693 return type_parameter.raw(); 6697 return type_parameter.raw();
6694 } 6698 }
6695 } 6699 }
6696 } 6700 }
6697 // Try to resolve the type class. 6701 // Try to resolve the type class.
6698 type_class = LookupTypeClass(type_name, type_resolution); 6702 type_class = LookupTypeClass(type_name, type_resolution);
6699 } 6703 }
6700 AbstractTypeArguments& type_arguments = 6704 AbstractTypeArguments& type_arguments =
6701 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution)); 6705 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution));
6702 Type& type = Type::Handle( 6706 Type& type = Type::Handle(
6703 Type::NewParameterizedType(type_class, type_arguments)); 6707 Type::NewParameterizedType(type_class, type_arguments));
6704 if (type_resolution == kMustResolve) { 6708 if (type_resolution == kMustResolve) {
6705 ASSERT(type_class.IsClass()); // Must be resolved. 6709 ASSERT(type_class.IsClass()); // Must be resolved.
6706 String& errmsg = String::Handle(); 6710 Error& error = Error::Handle();
6707 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, 6711 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class,
6708 type, 6712 type,
6709 &errmsg); 6713 &error);
6710 if (!errmsg.IsNull()) { 6714 if (!error.IsNull()) {
6711 ErrorMsg(errmsg.ToCString()); 6715 ErrorMsg(error.ToErrorCString());
6712 } 6716 }
6713 } 6717 }
6714 return type.raw(); 6718 return type.raw();
6715 } 6719 }
6716 6720
6717 6721
6718 void Parser::CheckConstructorCallTypeArguments( 6722 void Parser::CheckConstructorCallTypeArguments(
6719 intptr_t pos, Function& constructor, 6723 intptr_t pos, Function& constructor,
6720 const AbstractTypeArguments& type_arguments) { 6724 const AbstractTypeArguments& type_arguments) {
6721 if (!type_arguments.IsNull()) { 6725 if (!type_arguments.IsNull()) {
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
7253 if (constructor.IsFactory() && 7257 if (constructor.IsFactory() &&
7254 (constructor.signature_class() != Class::null())) { 7258 (constructor.signature_class() != Class::null())) {
7255 signature_class = constructor.signature_class(); 7259 signature_class = constructor.signature_class();
7256 } else { 7260 } else {
7257 signature_class = constructor.owner(); 7261 signature_class = constructor.owner();
7258 ASSERT(signature_class.raw() == type_class.raw()); 7262 ASSERT(signature_class.raw() == type_class.raw());
7259 } 7263 }
7260 // TODO(regis): Temporary type should be allocated in new gen heap. 7264 // TODO(regis): Temporary type should be allocated in new gen heap.
7261 Type& type = Type::Handle( 7265 Type& type = Type::Handle(
7262 Type::NewParameterizedType(signature_class, type_arguments)); 7266 Type::NewParameterizedType(signature_class, type_arguments));
7263 String& errmsg = String::Handle(); 7267 Error& error = Error::Handle();
7264 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, 7268 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
7265 type, 7269 type,
7266 &errmsg); 7270 &error);
7267 if (!errmsg.IsNull()) { 7271 if (!error.IsNull()) {
7268 ErrorMsg(errmsg.ToCString()); 7272 ErrorMsg(error.ToErrorCString());
7269 } 7273 }
7270 // The type argument vector may have been expanded with the type arguments 7274 // The type argument vector may have been expanded with the type arguments
7271 // of the super type when finalizing the type. 7275 // of the super type when finalizing the type.
7272 type_arguments = type.arguments(); 7276 type_arguments = type.arguments();
7273 } 7277 }
7274 7278
7275 type_arguments ^= type_arguments.Canonicalize(); 7279 type_arguments ^= type_arguments.Canonicalize();
7276 // Make the constructor call. 7280 // Make the constructor call.
7277 AstNode* new_object = NULL; 7281 AstNode* new_object = NULL;
7278 if (is_const) { 7282 if (is_const) {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
7739 } 7743 }
7740 7744
7741 7745
7742 void Parser::SkipNestedExpr() { 7746 void Parser::SkipNestedExpr() {
7743 const bool saved_mode = SetAllowFunctionLiterals(true); 7747 const bool saved_mode = SetAllowFunctionLiterals(true);
7744 SkipExpr(); 7748 SkipExpr();
7745 SetAllowFunctionLiterals(saved_mode); 7749 SetAllowFunctionLiterals(saved_mode);
7746 } 7750 }
7747 7751
7748 } // namespace dart 7752 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698