| OLD | NEW |
| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 5233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5244 // with the formal parameter types and names. | 5244 // with the formal parameter types and names. |
| 5245 void Parser::AddFormalParamsToFunction(const ParamList* params, | 5245 void Parser::AddFormalParamsToFunction(const ParamList* params, |
| 5246 const Function& func) { | 5246 const Function& func) { |
| 5247 ASSERT((params != NULL) && (params->parameters != NULL)); | 5247 ASSERT((params != NULL) && (params->parameters != NULL)); |
| 5248 ASSERT((params->num_optional_parameters > 0) == | 5248 ASSERT((params->num_optional_parameters > 0) == |
| 5249 (params->has_optional_positional_parameters || | 5249 (params->has_optional_positional_parameters || |
| 5250 params->has_optional_named_parameters)); | 5250 params->has_optional_named_parameters)); |
| 5251 if (!Utils::IsInt(16, params->num_fixed_parameters) || | 5251 if (!Utils::IsInt(16, params->num_fixed_parameters) || |
| 5252 !Utils::IsInt(16, params->num_optional_parameters)) { | 5252 !Utils::IsInt(16, params->num_optional_parameters)) { |
| 5253 const Script& script = Script::Handle(Class::Handle(func.Owner()).script()); | 5253 const Script& script = Script::Handle(Class::Handle(func.Owner()).script()); |
| 5254 const Error& error = Error::Handle(FormatErrorMsg( | 5254 const Error& error = Error::Handle(LanguageError::NewFormatted( |
| 5255 script, func.token_pos(), "Error", "too many formal parameters")); | 5255 Error::Handle(), script, func.token_pos(), |
| 5256 LanguageError::kError, Heap::kNew, |
| 5257 "too many formal parameters")); |
| 5256 ErrorMsg(error); | 5258 ErrorMsg(error); |
| 5257 } | 5259 } |
| 5258 func.set_num_fixed_parameters(params->num_fixed_parameters); | 5260 func.set_num_fixed_parameters(params->num_fixed_parameters); |
| 5259 func.SetNumOptionalParameters(params->num_optional_parameters, | 5261 func.SetNumOptionalParameters(params->num_optional_parameters, |
| 5260 params->has_optional_positional_parameters); | 5262 params->has_optional_positional_parameters); |
| 5261 const int num_parameters = params->parameters->length(); | 5263 const int num_parameters = params->parameters->length(); |
| 5262 ASSERT(num_parameters == func.NumParameters()); | 5264 ASSERT(num_parameters == func.NumParameters()); |
| 5263 func.set_parameter_types(Array::Handle(Array::New(num_parameters, | 5265 func.set_parameter_types(Array::Handle(Array::New(num_parameters, |
| 5264 Heap::kOld))); | 5266 Heap::kOld))); |
| 5265 func.set_parameter_names(Array::Handle(Array::New(num_parameters, | 5267 func.set_parameter_names(Array::Handle(Array::New(num_parameters, |
| (...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7219 new LoadLocalNode(statement_pos, excp_var), | 7221 new LoadLocalNode(statement_pos, excp_var), |
| 7220 new LoadLocalNode(statement_pos, trace_var)); | 7222 new LoadLocalNode(statement_pos, trace_var)); |
| 7221 } else { | 7223 } else { |
| 7222 statement = ParseExpr(kAllowConst, kConsumeCascades); | 7224 statement = ParseExpr(kAllowConst, kConsumeCascades); |
| 7223 ExpectSemicolon(); | 7225 ExpectSemicolon(); |
| 7224 } | 7226 } |
| 7225 return statement; | 7227 return statement; |
| 7226 } | 7228 } |
| 7227 | 7229 |
| 7228 | 7230 |
| 7229 RawError* Parser::FormatErrorWithAppend(const Error& prev_error, | |
| 7230 const Script& script, | |
| 7231 intptr_t token_pos, | |
| 7232 const char* message_header, | |
| 7233 const char* format, | |
| 7234 va_list args) { | |
| 7235 const String& msg1 = String::Handle(String::New(prev_error.ToErrorCString())); | |
| 7236 const String& msg2 = String::Handle( | |
| 7237 FormatMessage(script, token_pos, message_header, format, args)); | |
| 7238 return LanguageError::New(String::Handle(String::Concat(msg1, msg2))); | |
| 7239 } | |
| 7240 | |
| 7241 | |
| 7242 RawError* Parser::FormatError(const Script& script, | |
| 7243 intptr_t token_pos, | |
| 7244 const char* message_header, | |
| 7245 const char* format, | |
| 7246 va_list args) { | |
| 7247 const String& msg = String::Handle( | |
| 7248 FormatMessage(script, token_pos, message_header, format, args)); | |
| 7249 return LanguageError::New(msg); | |
| 7250 } | |
| 7251 | |
| 7252 | |
| 7253 RawError* Parser::FormatErrorMsg(const Script& script, | |
| 7254 intptr_t token_pos, | |
| 7255 const char* message_header, | |
| 7256 const char* format, ...) { | |
| 7257 va_list args; | |
| 7258 va_start(args, format); | |
| 7259 const Error& error = Error::Handle( | |
| 7260 FormatError(script, token_pos, message_header, format, args)); | |
| 7261 va_end(args); | |
| 7262 return error.raw(); | |
| 7263 } | |
| 7264 | |
| 7265 | |
| 7266 RawString* Parser::FormatMessage(const Script& script, | |
| 7267 intptr_t token_pos, | |
| 7268 const char* message_header, | |
| 7269 const char* format, va_list args) { | |
| 7270 String& result = String::Handle(); | |
| 7271 const String& msg = String::Handle(String::NewFormattedV(format, args)); | |
| 7272 if (!script.IsNull()) { | |
| 7273 const String& script_url = String::Handle(script.url()); | |
| 7274 if (token_pos >= 0) { | |
| 7275 intptr_t line, column; | |
| 7276 script.GetTokenLocation(token_pos, &line, &column); | |
| 7277 // Only report the line position if we have the original source. We still | |
| 7278 // need to get a valid column so that we can report the ^ mark below the | |
| 7279 // snippet. | |
| 7280 if (script.HasSource()) { | |
| 7281 result = String::NewFormatted("'%s': %s: line %" Pd " pos %" Pd ": ", | |
| 7282 script_url.ToCString(), | |
| 7283 message_header, | |
| 7284 line, | |
| 7285 column); | |
| 7286 } else { | |
| 7287 result = String::NewFormatted("'%s': %s: line %" Pd ": ", | |
| 7288 script_url.ToCString(), | |
| 7289 message_header, | |
| 7290 line); | |
| 7291 } | |
| 7292 // Append the formatted error or warning message. | |
| 7293 result = String::Concat(result, msg); | |
| 7294 const String& new_line = String::Handle(String::New("\n")); | |
| 7295 // Append the source line. | |
| 7296 const String& script_line = String::Handle(script.GetLine(line)); | |
| 7297 ASSERT(!script_line.IsNull()); | |
| 7298 result = String::Concat(result, new_line); | |
| 7299 result = String::Concat(result, script_line); | |
| 7300 result = String::Concat(result, new_line); | |
| 7301 // Append the column marker. | |
| 7302 const String& column_line = String::Handle( | |
| 7303 String::NewFormatted("%*s\n", static_cast<int>(column), "^")); | |
| 7304 result = String::Concat(result, column_line); | |
| 7305 } else { | |
| 7306 // Token position is unknown. | |
| 7307 result = String::NewFormatted("'%s': %s: ", | |
| 7308 script_url.ToCString(), | |
| 7309 message_header); | |
| 7310 result = String::Concat(result, msg); | |
| 7311 } | |
| 7312 } else { | |
| 7313 // Script is unknown. | |
| 7314 // Append the formatted error or warning message. | |
| 7315 result = msg.raw(); | |
| 7316 } | |
| 7317 return result.raw(); | |
| 7318 } | |
| 7319 | |
| 7320 | |
| 7321 void Parser::PrintMessage(const Script& script, | |
| 7322 intptr_t token_pos, | |
| 7323 const char* message_header, | |
| 7324 const char* format, ...) { | |
| 7325 va_list args; | |
| 7326 va_start(args, format); | |
| 7327 const String& buf = String::Handle( | |
| 7328 FormatMessage(script, token_pos, message_header, format, args)); | |
| 7329 va_end(args); | |
| 7330 OS::Print("%s", buf.ToCString()); | |
| 7331 } | |
| 7332 | |
| 7333 | |
| 7334 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) const { | 7231 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) const { |
| 7335 va_list args; | 7232 va_list args; |
| 7336 va_start(args, format); | 7233 va_start(args, format); |
| 7337 const Error& error = Error::Handle( | 7234 const Error& error = Error::Handle(LanguageError::NewFormattedV( |
| 7338 FormatError(script_, token_pos, "Error", format, args)); | 7235 Error::Handle(), script_, token_pos, |
| 7236 LanguageError::kError, Heap::kNew, format, args)); |
| 7339 va_end(args); | 7237 va_end(args); |
| 7340 isolate()->long_jump_base()->Jump(1, error); | 7238 isolate()->long_jump_base()->Jump(1, error); |
| 7341 UNREACHABLE(); | 7239 UNREACHABLE(); |
| 7342 } | 7240 } |
| 7343 | 7241 |
| 7344 | 7242 |
| 7345 void Parser::ErrorMsg(const char* format, ...) { | 7243 void Parser::ErrorMsg(const char* format, ...) { |
| 7346 va_list args; | 7244 va_list args; |
| 7347 va_start(args, format); | 7245 va_start(args, format); |
| 7348 const Error& error = Error::Handle( | 7246 const Error& error = Error::Handle(LanguageError::NewFormattedV( |
| 7349 FormatError(script_, TokenPos(), "Error", format, args)); | 7247 Error::Handle(), script_, TokenPos(), |
| 7248 LanguageError::kError, Heap::kNew, format, args)); |
| 7350 va_end(args); | 7249 va_end(args); |
| 7351 isolate()->long_jump_base()->Jump(1, error); | 7250 isolate()->long_jump_base()->Jump(1, error); |
| 7352 UNREACHABLE(); | 7251 UNREACHABLE(); |
| 7353 } | 7252 } |
| 7354 | 7253 |
| 7355 | 7254 |
| 7356 void Parser::ErrorMsg(const Error& error) { | 7255 void Parser::ErrorMsg(const Error& error) { |
| 7357 Isolate::Current()->long_jump_base()->Jump(1, error); | 7256 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 7358 UNREACHABLE(); | 7257 UNREACHABLE(); |
| 7359 } | 7258 } |
| 7360 | 7259 |
| 7361 | 7260 |
| 7362 void Parser::AppendErrorMsg( | 7261 void Parser::AppendErrorMsg( |
| 7363 const Error& prev_error, intptr_t token_pos, const char* format, ...) { | 7262 const Error& prev_error, intptr_t token_pos, const char* format, ...) { |
| 7364 va_list args; | 7263 va_list args; |
| 7365 va_start(args, format); | 7264 va_start(args, format); |
| 7366 const Error& error = Error::Handle(FormatErrorWithAppend( | 7265 const Error& error = Error::Handle( |
| 7367 prev_error, script_, token_pos, "Error", format, args)); | 7266 LanguageError::NewFormattedV( |
| 7267 prev_error, script_, token_pos, |
| 7268 LanguageError::kError, Heap::kNew, |
| 7269 format, args)); |
| 7368 va_end(args); | 7270 va_end(args); |
| 7369 isolate()->long_jump_base()->Jump(1, error); | 7271 isolate()->long_jump_base()->Jump(1, error); |
| 7370 UNREACHABLE(); | 7272 UNREACHABLE(); |
| 7371 } | 7273 } |
| 7372 | 7274 |
| 7373 | 7275 |
| 7374 void Parser::Warning(intptr_t token_pos, const char* format, ...) { | 7276 void Parser::Warning(intptr_t token_pos, const char* format, ...) { |
| 7375 if (FLAG_silent_warnings) return; | 7277 if (FLAG_silent_warnings) return; |
| 7376 va_list args; | 7278 va_list args; |
| 7377 va_start(args, format); | 7279 va_start(args, format); |
| 7378 const Error& error = Error::Handle( | 7280 const Error& error = Error::Handle( |
| 7379 FormatError(script_, token_pos, "Warning", format, args)); | 7281 LanguageError::NewFormattedV( |
| 7282 Error::Handle(), script_, token_pos, |
| 7283 LanguageError::kWarning, Heap::kNew, |
| 7284 format, args)); |
| 7380 va_end(args); | 7285 va_end(args); |
| 7381 if (FLAG_warning_as_error) { | 7286 if (FLAG_warning_as_error) { |
| 7382 isolate()->long_jump_base()->Jump(1, error); | 7287 isolate()->long_jump_base()->Jump(1, error); |
| 7383 UNREACHABLE(); | 7288 UNREACHABLE(); |
| 7384 } else { | 7289 } else { |
| 7385 OS::Print("%s", error.ToErrorCString()); | 7290 OS::Print("%s", error.ToErrorCString()); |
| 7386 } | 7291 } |
| 7387 } | 7292 } |
| 7388 | 7293 |
| 7389 | 7294 |
| 7390 void Parser::Warning(const char* format, ...) { | 7295 void Parser::Warning(const char* format, ...) { |
| 7391 if (FLAG_silent_warnings) return; | 7296 if (FLAG_silent_warnings) return; |
| 7392 va_list args; | 7297 va_list args; |
| 7393 va_start(args, format); | 7298 va_start(args, format); |
| 7394 const Error& error = Error::Handle( | 7299 const Error& error = Error::Handle( |
| 7395 FormatError(script_, TokenPos(), "Warning", format, args)); | 7300 LanguageError::NewFormattedV( |
| 7301 Error::Handle(), script_, TokenPos(), |
| 7302 LanguageError::kWarning, Heap::kNew, |
| 7303 format, args)); |
| 7396 va_end(args); | 7304 va_end(args); |
| 7397 if (FLAG_warning_as_error) { | 7305 if (FLAG_warning_as_error) { |
| 7398 isolate()->long_jump_base()->Jump(1, error); | 7306 isolate()->long_jump_base()->Jump(1, error); |
| 7399 UNREACHABLE(); | 7307 UNREACHABLE(); |
| 7400 } else { | 7308 } else { |
| 7401 OS::Print("%s", error.ToErrorCString()); | 7309 OS::Print("%s", error.ToErrorCString()); |
| 7402 } | 7310 } |
| 7403 } | 7311 } |
| 7404 | 7312 |
| 7405 | 7313 |
| (...skipping 3360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10766 void Parser::SkipQualIdent() { | 10674 void Parser::SkipQualIdent() { |
| 10767 ASSERT(IsIdentifier()); | 10675 ASSERT(IsIdentifier()); |
| 10768 ConsumeToken(); | 10676 ConsumeToken(); |
| 10769 if (CurrentToken() == Token::kPERIOD) { | 10677 if (CurrentToken() == Token::kPERIOD) { |
| 10770 ConsumeToken(); // Consume the kPERIOD token. | 10678 ConsumeToken(); // Consume the kPERIOD token. |
| 10771 ExpectIdentifier("identifier expected after '.'"); | 10679 ExpectIdentifier("identifier expected after '.'"); |
| 10772 } | 10680 } |
| 10773 } | 10681 } |
| 10774 | 10682 |
| 10775 } // namespace dart | 10683 } // namespace dart |
| OLD | NEW |