| 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 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 signature_function, | 883 signature_function, |
| 884 script_); | 884 script_); |
| 885 // Record the function signature class in the current library. | 885 // Record the function signature class in the current library. |
| 886 library_.AddClass(signature_class); | 886 library_.AddClass(signature_class); |
| 887 } else { | 887 } else { |
| 888 signature_function.set_signature_class(signature_class); | 888 signature_function.set_signature_class(signature_class); |
| 889 } | 889 } |
| 890 ASSERT(signature_function.signature_class() == signature_class.raw()); | 890 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 891 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); | 891 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); |
| 892 if (!is_top_level_ && !signature_type.IsFinalized()) { | 892 if (!is_top_level_ && !signature_type.IsFinalized()) { |
| 893 String& errmsg = String::Handle(); | 893 Error& error = Error::Handle(); |
| 894 signature_type ^= | 894 signature_type ^= |
| 895 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, | 895 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, |
| 896 signature_type, | 896 signature_type, |
| 897 &errmsg); | 897 &error); |
| 898 if (!errmsg.IsNull()) { | 898 if (!error.IsNull()) { |
| 899 ErrorMsg(errmsg.ToCString()); | 899 ErrorMsg(error.ToErrorCString()); |
| 900 } | 900 } |
| 901 } | 901 } |
| 902 // The type of the parameter is now the signature type. | 902 // The type of the parameter is now the signature type. |
| 903 parameter.type = &signature_type; | 903 parameter.type = &signature_type; |
| 904 } | 904 } |
| 905 } | 905 } |
| 906 | 906 |
| 907 if (CurrentToken() == Token::kASSIGN) { | 907 if (CurrentToken() == Token::kASSIGN) { |
| 908 if (!params->has_named_optional_parameters || | 908 if (!params->has_named_optional_parameters || |
| 909 !allow_explicit_default_value) { | 909 !allow_explicit_default_value) { |
| (...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3834 // Patch the function type now that the signature is known. | 3834 // Patch the function type now that the signature is known. |
| 3835 // We need to create a new type for proper finalization, since the existing | 3835 // We need to create a new type for proper finalization, since the existing |
| 3836 // type is already marked as finalized. | 3836 // type is already marked as finalized. |
| 3837 Type& signature_type = Type::Handle(signature_class.SignatureType()); | 3837 Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 3838 const AbstractTypeArguments& signature_type_arguments = | 3838 const AbstractTypeArguments& signature_type_arguments = |
| 3839 AbstractTypeArguments::Handle(signature_type.arguments()); | 3839 AbstractTypeArguments::Handle(signature_type.arguments()); |
| 3840 | 3840 |
| 3841 // Since the signature type is cached by the signature class, it may have | 3841 // Since the signature type is cached by the signature class, it may have |
| 3842 // been finalized already. | 3842 // been finalized already. |
| 3843 if (!signature_type.IsFinalized()) { | 3843 if (!signature_type.IsFinalized()) { |
| 3844 String& errmsg = String::Handle(); | 3844 Error& error = Error::Handle(); |
| 3845 signature_type ^= | 3845 signature_type ^= |
| 3846 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, | 3846 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, |
| 3847 signature_type, | 3847 signature_type, |
| 3848 &errmsg); | 3848 &error); |
| 3849 if (!errmsg.IsNull()) { | 3849 if (!error.IsNull()) { |
| 3850 ErrorMsg(errmsg.ToCString()); | 3850 ErrorMsg(error.ToErrorCString()); |
| 3851 } | 3851 } |
| 3852 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have | 3852 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have |
| 3853 // extended the vector of type arguments. | 3853 // extended the vector of type arguments. |
| 3854 ASSERT(signature_type_arguments.IsNull() || | 3854 ASSERT(signature_type_arguments.IsNull() || |
| 3855 (signature_type_arguments.Length() == | 3855 (signature_type_arguments.Length() == |
| 3856 signature_class.NumTypeArguments())); | 3856 signature_class.NumTypeArguments())); |
| 3857 // The signature_class should not have changed. | 3857 // The signature_class should not have changed. |
| 3858 ASSERT(signature_type.type_class() == signature_class.raw()); | 3858 ASSERT(signature_type.type_class() == signature_class.raw()); |
| 3859 } | 3859 } |
| 3860 | 3860 |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5159 new LoadLocalNode(statement_pos, *trace_var)); | 5159 new LoadLocalNode(statement_pos, *trace_var)); |
| 5160 } | 5160 } |
| 5161 } else { | 5161 } else { |
| 5162 statement = ParseExpr(kAllowConst); | 5162 statement = ParseExpr(kAllowConst); |
| 5163 ExpectSemicolon(); | 5163 ExpectSemicolon(); |
| 5164 } | 5164 } |
| 5165 return statement; | 5165 return statement; |
| 5166 } | 5166 } |
| 5167 | 5167 |
| 5168 | 5168 |
| 5169 // Static |
| 5170 RawError* Parser::FormatError(const Script& script, |
| 5171 intptr_t token_index, |
| 5172 const char* message_header, |
| 5173 const char* format, |
| 5174 va_list args) { |
| 5175 const intptr_t kMessageBufferSize = 512; |
| 5176 char message_buffer[kMessageBufferSize]; |
| 5177 FormatMessage(script, token_index, message_header, |
| 5178 message_buffer, kMessageBufferSize, |
| 5179 format, args); |
| 5180 const String& msg = String::Handle(String::New(message_buffer)); |
| 5181 return LanguageError::New(msg); |
| 5182 } |
| 5183 |
| 5184 |
| 5169 // Static. | 5185 // Static. |
| 5170 void Parser::FormatMessage(const Script& script, | 5186 void Parser::FormatMessage(const Script& script, |
| 5171 intptr_t token_index, | 5187 intptr_t token_index, |
| 5172 const char* message_header, | 5188 const char* message_header, |
| 5173 char* message_buffer, | 5189 char* message_buffer, |
| 5174 intptr_t message_buffer_size, | 5190 intptr_t message_buffer_size, |
| 5175 const char* format, va_list args) { | 5191 const char* format, va_list args) { |
| 5176 intptr_t msg_len = 0; | 5192 intptr_t msg_len = 0; |
| 5177 if (!script.IsNull()) { | 5193 if (!script.IsNull()) { |
| 5178 const String& script_url = String::CheckedHandle(script.url()); | 5194 const String& script_url = String::CheckedHandle(script.url()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5224 // Append the formatted error or warning message. | 5240 // Append the formatted error or warning message. |
| 5225 msg_len += OS::VSNPrint(message_buffer + msg_len, | 5241 msg_len += OS::VSNPrint(message_buffer + msg_len, |
| 5226 message_buffer_size - msg_len, | 5242 message_buffer_size - msg_len, |
| 5227 format, | 5243 format, |
| 5228 args); | 5244 args); |
| 5229 } | 5245 } |
| 5230 } | 5246 } |
| 5231 | 5247 |
| 5232 | 5248 |
| 5233 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) { | 5249 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) { |
| 5234 const intptr_t kMessageBufferSize = 512; | |
| 5235 char message_buffer[kMessageBufferSize]; | |
| 5236 va_list args; | 5250 va_list args; |
| 5237 va_start(args, format); | 5251 va_start(args, format); |
| 5238 FormatMessage(script_, token_index, "Error", | 5252 const Error& error = Error::Handle( |
| 5239 message_buffer, kMessageBufferSize, | 5253 FormatError(script_, token_index, "Error", format, args)); |
| 5240 format, args); | |
| 5241 va_end(args); | 5254 va_end(args); |
| 5242 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 5255 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 5243 UNREACHABLE(); | 5256 UNREACHABLE(); |
| 5244 } | 5257 } |
| 5245 | 5258 |
| 5246 | 5259 |
| 5247 void Parser::ErrorMsg(const char* format, ...) { | 5260 void Parser::ErrorMsg(const char* format, ...) { |
| 5248 const intptr_t kMessageBufferSize = 512; | |
| 5249 char message_buffer[kMessageBufferSize]; | |
| 5250 va_list args; | 5261 va_list args; |
| 5251 va_start(args, format); | 5262 va_start(args, format); |
| 5252 FormatMessage(script_, token_index_, "Error", | 5263 const Error& error = Error::Handle( |
| 5253 message_buffer, kMessageBufferSize, | 5264 FormatError(script_, token_index_, "Error", format, args)); |
| 5254 format, args); | |
| 5255 va_end(args); | 5265 va_end(args); |
| 5256 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 5266 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 5257 UNREACHABLE(); | 5267 UNREACHABLE(); |
| 5258 } | 5268 } |
| 5259 | 5269 |
| 5260 | 5270 |
| 5261 void Parser::Warning(intptr_t token_index, const char* format, ...) { | 5271 void Parser::Warning(intptr_t token_index, const char* format, ...) { |
| 5262 const intptr_t kMessageBufferSize = 512; | |
| 5263 char message_buffer[kMessageBufferSize]; | |
| 5264 if (FLAG_silent_warnings) return; | 5272 if (FLAG_silent_warnings) return; |
| 5265 va_list args; | 5273 va_list args; |
| 5266 va_start(args, format); | 5274 va_start(args, format); |
| 5267 FormatMessage(script_, token_index, "Warning", | 5275 const Error& error = Error::Handle( |
| 5268 message_buffer, kMessageBufferSize, | 5276 FormatError(script_, token_index, "Warning", format, args)); |
| 5269 format, args); | |
| 5270 va_end(args); | 5277 va_end(args); |
| 5271 if (FLAG_warning_as_error) { | 5278 if (FLAG_warning_as_error) { |
| 5272 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 5279 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 5273 UNREACHABLE(); | 5280 UNREACHABLE(); |
| 5274 } else { | 5281 } else { |
| 5275 OS::Print(message_buffer); | 5282 OS::Print("%s", error.ToErrorCString()); |
| 5276 } | 5283 } |
| 5277 } | 5284 } |
| 5278 | 5285 |
| 5279 | 5286 |
| 5280 void Parser::Warning(const char* format, ...) { | 5287 void Parser::Warning(const char* format, ...) { |
| 5281 const intptr_t kMessageBufferSize = 512; | |
| 5282 char message_buffer[kMessageBufferSize]; | |
| 5283 if (FLAG_silent_warnings) return; | 5288 if (FLAG_silent_warnings) return; |
| 5284 va_list args; | 5289 va_list args; |
| 5285 va_start(args, format); | 5290 va_start(args, format); |
| 5286 FormatMessage(script_, token_index_, "Warning", | 5291 const Error& error = Error::Handle( |
| 5287 message_buffer, kMessageBufferSize, | 5292 FormatError(script_, token_index_, "Warning", format, args)); |
| 5288 format, args); | |
| 5289 va_end(args); | 5293 va_end(args); |
| 5290 if (FLAG_warning_as_error) { | 5294 if (FLAG_warning_as_error) { |
| 5291 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 5295 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 5292 UNREACHABLE(); | 5296 UNREACHABLE(); |
| 5293 } else { | 5297 } else { |
| 5294 OS::Print(message_buffer); | 5298 OS::Print("%s", error.ToErrorCString()); |
| 5295 } | 5299 } |
| 5296 } | 5300 } |
| 5297 | 5301 |
| 5298 | 5302 |
| 5299 void Parser::Unimplemented(const char* msg) { | 5303 void Parser::Unimplemented(const char* msg) { |
| 5300 ErrorMsg(token_index_, msg); | 5304 ErrorMsg(token_index_, msg); |
| 5301 } | 5305 } |
| 5302 | 5306 |
| 5303 | 5307 |
| 5304 void Parser::ExpectToken(Token::Kind token_expected) { | 5308 void Parser::ExpectToken(Token::Kind token_expected) { |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6665 } else { | 6669 } else { |
| 6666 // Check if ident is a type parameter in scope. | 6670 // Check if ident is a type parameter in scope. |
| 6667 type_parameter = scope_class.LookupTypeParameter(*type_name.ident); | 6671 type_parameter = scope_class.LookupTypeParameter(*type_name.ident); |
| 6668 if (!type_parameter.IsNull()) { | 6672 if (!type_parameter.IsNull()) { |
| 6669 if (CurrentToken() == Token::kLT) { | 6673 if (CurrentToken() == Token::kLT) { |
| 6670 // A type parameter cannot be parameterized. | 6674 // A type parameter cannot be parameterized. |
| 6671 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", | 6675 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", |
| 6672 String::Handle(type_parameter.Name()).ToCString()); | 6676 String::Handle(type_parameter.Name()).ToCString()); |
| 6673 } | 6677 } |
| 6674 if (type_resolution == kMustResolve) { | 6678 if (type_resolution == kMustResolve) { |
| 6675 String& errmsg = String::Handle(); | 6679 Error& error = Error::Handle(); |
| 6676 type_parameter ^= | 6680 type_parameter ^= |
| 6677 ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, | 6681 ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, |
| 6678 type_parameter, | 6682 type_parameter, |
| 6679 &errmsg); | 6683 &error); |
| 6680 if (!errmsg.IsNull()) { | 6684 if (!error.IsNull()) { |
| 6681 ErrorMsg(errmsg.ToCString()); | 6685 ErrorMsg(error.ToErrorCString()); |
| 6682 } | 6686 } |
| 6683 } | 6687 } |
| 6684 return type_parameter.raw(); | 6688 return type_parameter.raw(); |
| 6685 } | 6689 } |
| 6686 } | 6690 } |
| 6687 } | 6691 } |
| 6688 // Try to resolve the type class. | 6692 // Try to resolve the type class. |
| 6689 type_class = LookupTypeClass(type_name, type_resolution); | 6693 type_class = LookupTypeClass(type_name, type_resolution); |
| 6690 } | 6694 } |
| 6691 AbstractTypeArguments& type_arguments = | 6695 AbstractTypeArguments& type_arguments = |
| 6692 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution)); | 6696 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution)); |
| 6693 Type& type = Type::Handle( | 6697 Type& type = Type::Handle( |
| 6694 Type::NewParameterizedType(type_class, type_arguments)); | 6698 Type::NewParameterizedType(type_class, type_arguments)); |
| 6695 if (type_resolution == kMustResolve) { | 6699 if (type_resolution == kMustResolve) { |
| 6696 ASSERT(type_class.IsClass()); // Must be resolved. | 6700 ASSERT(type_class.IsClass()); // Must be resolved. |
| 6697 String& errmsg = String::Handle(); | 6701 Error& error = Error::Handle(); |
| 6698 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, | 6702 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, |
| 6699 type, | 6703 type, |
| 6700 &errmsg); | 6704 &error); |
| 6701 if (!errmsg.IsNull()) { | 6705 if (!error.IsNull()) { |
| 6702 ErrorMsg(errmsg.ToCString()); | 6706 ErrorMsg(error.ToErrorCString()); |
| 6703 } | 6707 } |
| 6704 } | 6708 } |
| 6705 return type.raw(); | 6709 return type.raw(); |
| 6706 } | 6710 } |
| 6707 | 6711 |
| 6708 | 6712 |
| 6709 void Parser::CheckConstructorCallTypeArguments( | 6713 void Parser::CheckConstructorCallTypeArguments( |
| 6710 intptr_t pos, Function& constructor, | 6714 intptr_t pos, Function& constructor, |
| 6711 const AbstractTypeArguments& type_arguments) { | 6715 const AbstractTypeArguments& type_arguments) { |
| 6712 if (!type_arguments.IsNull()) { | 6716 if (!type_arguments.IsNull()) { |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7244 if (constructor.IsFactory() && | 7248 if (constructor.IsFactory() && |
| 7245 (constructor.signature_class() != Class::null())) { | 7249 (constructor.signature_class() != Class::null())) { |
| 7246 signature_class = constructor.signature_class(); | 7250 signature_class = constructor.signature_class(); |
| 7247 } else { | 7251 } else { |
| 7248 signature_class = constructor.owner(); | 7252 signature_class = constructor.owner(); |
| 7249 ASSERT(signature_class.raw() == type_class.raw()); | 7253 ASSERT(signature_class.raw() == type_class.raw()); |
| 7250 } | 7254 } |
| 7251 // TODO(regis): Temporary type should be allocated in new gen heap. | 7255 // TODO(regis): Temporary type should be allocated in new gen heap. |
| 7252 Type& type = Type::Handle( | 7256 Type& type = Type::Handle( |
| 7253 Type::NewParameterizedType(signature_class, type_arguments)); | 7257 Type::NewParameterizedType(signature_class, type_arguments)); |
| 7254 String& errmsg = String::Handle(); | 7258 Error& error = Error::Handle(); |
| 7255 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, | 7259 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, |
| 7256 type, | 7260 type, |
| 7257 &errmsg); | 7261 &error); |
| 7258 if (!errmsg.IsNull()) { | 7262 if (!error.IsNull()) { |
| 7259 ErrorMsg(errmsg.ToCString()); | 7263 ErrorMsg(error.ToErrorCString()); |
| 7260 } | 7264 } |
| 7261 // The type argument vector may have been expanded with the type arguments | 7265 // The type argument vector may have been expanded with the type arguments |
| 7262 // of the super type when finalizing the type. | 7266 // of the super type when finalizing the type. |
| 7263 type_arguments = type.arguments(); | 7267 type_arguments = type.arguments(); |
| 7264 } | 7268 } |
| 7265 | 7269 |
| 7266 type_arguments ^= type_arguments.Canonicalize(); | 7270 type_arguments ^= type_arguments.Canonicalize(); |
| 7267 // Make the constructor call. | 7271 // Make the constructor call. |
| 7268 AstNode* new_object = NULL; | 7272 AstNode* new_object = NULL; |
| 7269 if (is_const) { | 7273 if (is_const) { |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7726 } | 7730 } |
| 7727 | 7731 |
| 7728 | 7732 |
| 7729 void Parser::SkipNestedExpr() { | 7733 void Parser::SkipNestedExpr() { |
| 7730 const bool saved_mode = SetAllowFunctionLiterals(true); | 7734 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7731 SkipExpr(); | 7735 SkipExpr(); |
| 7732 SetAllowFunctionLiterals(saved_mode); | 7736 SetAllowFunctionLiterals(saved_mode); |
| 7733 } | 7737 } |
| 7734 | 7738 |
| 7735 } // namespace dart | 7739 } // namespace dart |
| OLD | NEW |