| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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/report.h" | 5 #include "vm/report.h" |
| 6 | 6 |
| 7 #include "vm/code_patcher.h" | 7 #include "vm/code_patcher.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 strs.SetAt(2, Symbols::NewLine()); | 78 strs.SetAt(2, Symbols::NewLine()); |
| 79 strs.SetAt(3, script_line); | 79 strs.SetAt(3, script_line); |
| 80 strs.SetAt(4, Symbols::NewLine()); | 80 strs.SetAt(4, Symbols::NewLine()); |
| 81 // Append the column marker. | 81 // Append the column marker. |
| 82 const String& column_line = String::Handle(String::NewFormatted( | 82 const String& column_line = String::Handle(String::NewFormatted( |
| 83 Heap::kOld, "%*s\n", static_cast<int>(column), "^")); | 83 Heap::kOld, "%*s\n", static_cast<int>(column), "^")); |
| 84 strs.SetAt(5, column_line); | 84 strs.SetAt(5, column_line); |
| 85 result = String::ConcatAll(strs, Heap::kOld); | 85 result = String::ConcatAll(strs, Heap::kOld); |
| 86 } else { | 86 } else { |
| 87 // Token position is unknown. | 87 // Token position is unknown. |
| 88 result = String::NewFormatted(Heap::kOld, "'%s': %s: ", | 88 result = String::NewFormatted( |
| 89 script_url.ToCString(), message_header); | 89 Heap::kOld, "'%s': %s: ", script_url.ToCString(), message_header); |
| 90 result = String::Concat(result, message, Heap::kOld); | 90 result = String::Concat(result, message, Heap::kOld); |
| 91 } | 91 } |
| 92 } else { | 92 } else { |
| 93 // Script is unknown. | 93 // Script is unknown. |
| 94 // Append the formatted error or warning message. | 94 // Append the formatted error or warning message. |
| 95 result = String::NewFormatted(Heap::kOld, "%s: ", message_header); | 95 result = String::NewFormatted(Heap::kOld, "%s: ", message_header); |
| 96 result = String::Concat(result, message, Heap::kOld); | 96 result = String::Concat(result, message, Heap::kOld); |
| 97 } | 97 } |
| 98 return result.raw(); | 98 return result.raw(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | |
| 102 void Report::LongJump(const Error& error) { | 101 void Report::LongJump(const Error& error) { |
| 103 Thread::Current()->long_jump_base()->Jump(1, error); | 102 Thread::Current()->long_jump_base()->Jump(1, error); |
| 104 UNREACHABLE(); | 103 UNREACHABLE(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 | |
| 108 void Report::LongJumpF(const Error& prev_error, | 106 void Report::LongJumpF(const Error& prev_error, |
| 109 const Script& script, | 107 const Script& script, |
| 110 TokenPosition token_pos, | 108 TokenPosition token_pos, |
| 111 const char* format, | 109 const char* format, |
| 112 ...) { | 110 ...) { |
| 113 va_list args; | 111 va_list args; |
| 114 va_start(args, format); | 112 va_start(args, format); |
| 115 LongJumpV(prev_error, script, token_pos, format, args); | 113 LongJumpV(prev_error, script, token_pos, format, args); |
| 116 va_end(args); | 114 va_end(args); |
| 117 UNREACHABLE(); | 115 UNREACHABLE(); |
| 118 } | 116 } |
| 119 | 117 |
| 120 | |
| 121 void Report::LongJumpV(const Error& prev_error, | 118 void Report::LongJumpV(const Error& prev_error, |
| 122 const Script& script, | 119 const Script& script, |
| 123 TokenPosition token_pos, | 120 TokenPosition token_pos, |
| 124 const char* format, | 121 const char* format, |
| 125 va_list args) { | 122 va_list args) { |
| 126 const Error& error = Error::Handle(LanguageError::NewFormattedV( | 123 const Error& error = Error::Handle(LanguageError::NewFormattedV( |
| 127 prev_error, script, token_pos, Report::AtLocation, kError, Heap::kOld, | 124 prev_error, script, token_pos, Report::AtLocation, kError, Heap::kOld, |
| 128 format, args)); | 125 format, args)); |
| 129 LongJump(error); | 126 LongJump(error); |
| 130 UNREACHABLE(); | 127 UNREACHABLE(); |
| 131 } | 128 } |
| 132 | 129 |
| 133 | |
| 134 void Report::MessageF(Kind kind, | 130 void Report::MessageF(Kind kind, |
| 135 const Script& script, | 131 const Script& script, |
| 136 TokenPosition token_pos, | 132 TokenPosition token_pos, |
| 137 bool report_after_token, | 133 bool report_after_token, |
| 138 const char* format, | 134 const char* format, |
| 139 ...) { | 135 ...) { |
| 140 va_list args; | 136 va_list args; |
| 141 va_start(args, format); | 137 va_start(args, format); |
| 142 MessageV(kind, script, token_pos, report_after_token, format, args); | 138 MessageV(kind, script, token_pos, report_after_token, format, args); |
| 143 va_end(args); | 139 va_end(args); |
| 144 } | 140 } |
| 145 | 141 |
| 146 | |
| 147 void Report::MessageV(Kind kind, | 142 void Report::MessageV(Kind kind, |
| 148 const Script& script, | 143 const Script& script, |
| 149 TokenPosition token_pos, | 144 TokenPosition token_pos, |
| 150 bool report_after_token, | 145 bool report_after_token, |
| 151 const char* format, | 146 const char* format, |
| 152 va_list args) { | 147 va_list args) { |
| 153 if (kind < kError) { | 148 if (kind < kError) { |
| 154 // Reporting a warning. | 149 // Reporting a warning. |
| 155 if (FLAG_silent_warnings) { | 150 if (FLAG_silent_warnings) { |
| 156 return; | 151 return; |
| 157 } | 152 } |
| 158 if (!FLAG_warning_as_error) { | 153 if (!FLAG_warning_as_error) { |
| 159 const String& msg = String::Handle(String::NewFormattedV(format, args)); | 154 const String& msg = String::Handle(String::NewFormattedV(format, args)); |
| 160 const String& snippet_msg = String::Handle( | 155 const String& snippet_msg = String::Handle( |
| 161 PrependSnippet(kind, script, token_pos, report_after_token, msg)); | 156 PrependSnippet(kind, script, token_pos, report_after_token, msg)); |
| 162 OS::Print("%s", snippet_msg.ToCString()); | 157 OS::Print("%s", snippet_msg.ToCString()); |
| 163 return; | 158 return; |
| 164 } | 159 } |
| 165 } | 160 } |
| 166 // Reporting an error (or a warning as error). | 161 // Reporting an error (or a warning as error). |
| 167 const Error& error = Error::Handle(LanguageError::NewFormattedV( | 162 const Error& error = Error::Handle(LanguageError::NewFormattedV( |
| 168 Error::Handle(), // No previous error. | 163 Error::Handle(), // No previous error. |
| 169 script, token_pos, report_after_token, kind, Heap::kOld, format, args)); | 164 script, token_pos, report_after_token, kind, Heap::kOld, format, args)); |
| 170 LongJump(error); | 165 LongJump(error); |
| 171 UNREACHABLE(); | 166 UNREACHABLE(); |
| 172 } | 167 } |
| 173 | 168 |
| 174 } // namespace dart | 169 } // namespace dart |
| OLD | NEW |