| 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 4998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5009 } | 5009 } |
| 5010 } else { | 5010 } else { |
| 5011 statement = ParseExpr(kAllowConst); | 5011 statement = ParseExpr(kAllowConst); |
| 5012 ExpectSemicolon(); | 5012 ExpectSemicolon(); |
| 5013 } | 5013 } |
| 5014 return statement; | 5014 return statement; |
| 5015 } | 5015 } |
| 5016 | 5016 |
| 5017 | 5017 |
| 5018 // Static. | 5018 // Static. |
| 5019 void Parser::ReportMsg(const Script& script, | 5019 void Parser::FormatMessage(const Script& script, |
| 5020 intptr_t token_index, | 5020 intptr_t token_index, |
| 5021 const char* msg_type, | 5021 const char* message_header, |
| 5022 char* message, | 5022 char* message_buffer, |
| 5023 const char* format, va_list args) { | 5023 intptr_t message_buffer_size, |
| 5024 const String& script_url = String::CheckedHandle(script.url()); | 5024 const char* format, va_list args) { |
| 5025 const int buf_size = 256; | 5025 intptr_t msg_len = 0; |
| 5026 static char text_buffer[buf_size]; | 5026 if (!script.IsNull()) { |
| 5027 | 5027 const String& script_url = String::CheckedHandle(script.url()); |
| 5028 intptr_t line, column; | 5028 if (token_index >= 0) { |
| 5029 script.GetTokenLocation(token_index, &line, &column); | 5029 intptr_t line, column; |
| 5030 OS::VSNPrint(text_buffer, buf_size, format, args); | 5030 script.GetTokenLocation(token_index, &line, &column); |
| 5031 intptr_t msg_len = | 5031 msg_len += OS::SNPrint(message_buffer + msg_len, |
| 5032 OS::SNPrint(message, Parser::kErrorBuflen, | 5032 message_buffer_size - msg_len, |
| 5033 "'%s': %s: line %d pos %d: %s\n", | 5033 "'%s': %s: line %d pos %d: ", |
| 5034 script_url.ToCString(), msg_type, line, column, text_buffer); | 5034 script_url.ToCString(), |
| 5035 const String& text = String::Handle(script.GetLine(line)); | 5035 message_header, |
| 5036 ASSERT(!text.IsNull()); | 5036 line, |
| 5037 if (text.Length() < buf_size) { | 5037 column); |
| 5038 OS::SNPrint(message + msg_len, Parser::kErrorBuflen - msg_len, | 5038 if (msg_len < message_buffer_size) { |
| 5039 "%s\n%*s\n", text.ToCString(), column, "^"); | 5039 // Append the formatted error or warning message. |
| 5040 msg_len += OS::VSNPrint(message_buffer + msg_len, |
| 5041 message_buffer_size - msg_len, |
| 5042 format, |
| 5043 args); |
| 5044 if (msg_len < message_buffer_size) { |
| 5045 // Append the source line. |
| 5046 const String& script_line = String::Handle(script.GetLine(line)); |
| 5047 ASSERT(!script_line.IsNull()); |
| 5048 msg_len += OS::SNPrint(message_buffer + msg_len, |
| 5049 message_buffer_size - msg_len, |
| 5050 "\n%s\n%*s\n", |
| 5051 script_line.ToCString(), |
| 5052 column, |
| 5053 "^"); |
| 5054 } |
| 5055 } |
| 5056 } else { |
| 5057 // Token position is unknown. |
| 5058 msg_len += OS::SNPrint(message_buffer + msg_len, |
| 5059 message_buffer_size - msg_len, |
| 5060 "'%s': %s: ", |
| 5061 script_url.ToCString(), |
| 5062 message_header); |
| 5063 if (msg_len < message_buffer_size) { |
| 5064 // Append the formatted error or warning message. |
| 5065 msg_len += OS::VSNPrint(message_buffer + msg_len, |
| 5066 message_buffer_size - msg_len, |
| 5067 format, |
| 5068 args); |
| 5069 } |
| 5070 } |
| 5071 } else { |
| 5072 // Script is unknown. |
| 5073 // Append the formatted error or warning message. |
| 5074 msg_len += OS::VSNPrint(message_buffer + msg_len, |
| 5075 message_buffer_size - msg_len, |
| 5076 format, |
| 5077 args); |
| 5040 } | 5078 } |
| 5041 } | 5079 } |
| 5042 | 5080 |
| 5043 | 5081 |
| 5044 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) { | 5082 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) { |
| 5083 const intptr_t kMessageBufferSize = 512; |
| 5084 char message_buffer[kMessageBufferSize]; |
| 5045 va_list args; | 5085 va_list args; |
| 5046 va_start(args, format); | 5086 va_start(args, format); |
| 5047 ReportMsg(script_, token_index, "Error", error_msg_, format, args); | 5087 FormatMessage(script_, token_index, "Error", |
| 5048 Isolate::Current()->long_jump_base()->Jump(1, error_msg_); | 5088 message_buffer, kMessageBufferSize, |
| 5089 format, args); |
| 5090 va_end(args); |
| 5091 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 5049 UNREACHABLE(); | 5092 UNREACHABLE(); |
| 5050 } | 5093 } |
| 5051 | 5094 |
| 5052 | 5095 |
| 5053 void Parser::ErrorMsg(const char* format, ...) { | 5096 void Parser::ErrorMsg(const char* format, ...) { |
| 5097 const intptr_t kMessageBufferSize = 512; |
| 5098 char message_buffer[kMessageBufferSize]; |
| 5054 va_list args; | 5099 va_list args; |
| 5055 va_start(args, format); | 5100 va_start(args, format); |
| 5056 ReportMsg(script_, token_index_, "Error", error_msg_, format, args); | 5101 FormatMessage(script_, token_index_, "Error", |
| 5057 Isolate::Current()->long_jump_base()->Jump(1, error_msg_); | 5102 message_buffer, kMessageBufferSize, |
| 5103 format, args); |
| 5104 va_end(args); |
| 5105 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 5058 UNREACHABLE(); | 5106 UNREACHABLE(); |
| 5059 } | 5107 } |
| 5060 | 5108 |
| 5061 | 5109 |
| 5062 void Parser::Warning(const char* format, ...) { | 5110 void Parser::Warning(const char* format, ...) { |
| 5111 const intptr_t kMessageBufferSize = 512; |
| 5112 char message_buffer[kMessageBufferSize]; |
| 5063 if (FLAG_silent_warnings) return; | 5113 if (FLAG_silent_warnings) return; |
| 5064 va_list args; | 5114 va_list args; |
| 5065 va_start(args, format); | 5115 va_start(args, format); |
| 5066 ReportMsg(script_, token_index_, "Warning", error_msg_, format, args); | 5116 FormatMessage(script_, token_index_, "Warning", |
| 5117 message_buffer, kMessageBufferSize, |
| 5118 format, args); |
| 5119 va_end(args); |
| 5067 if (FLAG_warning_as_error) { | 5120 if (FLAG_warning_as_error) { |
| 5068 Isolate::Current()->long_jump_base()->Jump(1, error_msg_); | 5121 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 5069 UNREACHABLE(); | 5122 UNREACHABLE(); |
| 5070 } else { | 5123 } else { |
| 5071 OS::Print(error_msg_); | 5124 OS::Print(message_buffer); |
| 5072 } | 5125 } |
| 5073 } | 5126 } |
| 5074 | 5127 |
| 5075 | 5128 |
| 5076 void Parser::Unimplemented(const char* msg) { | 5129 void Parser::Unimplemented(const char* msg) { |
| 5077 ErrorMsg(token_index_, msg); | 5130 ErrorMsg(token_index_, msg); |
| 5078 } | 5131 } |
| 5079 | 5132 |
| 5080 | 5133 |
| 5081 void Parser::ExpectToken(Token::Kind token_expected) { | 5134 void Parser::ExpectToken(Token::Kind token_expected) { |
| (...skipping 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7376 } | 7429 } |
| 7377 | 7430 |
| 7378 | 7431 |
| 7379 void Parser::SkipNestedExpr() { | 7432 void Parser::SkipNestedExpr() { |
| 7380 const bool saved_mode = SetAllowFunctionLiterals(true); | 7433 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7381 SkipExpr(); | 7434 SkipExpr(); |
| 7382 SetAllowFunctionLiterals(saved_mode); | 7435 SetAllowFunctionLiterals(saved_mode); |
| 7383 } | 7436 } |
| 7384 | 7437 |
| 7385 } // namespace dart | 7438 } // namespace dart |
| OLD | NEW |