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

Side by Side Diff: vm/parser.cc

Issue 10933021: - Do not limit the compiler message buffer, by allocating the message (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 3 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
« vm/object.cc ('K') | « 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 6202 matching lines...) Expand 10 before | Expand all | Expand 10 after
6213 return statement; 6213 return statement;
6214 } 6214 }
6215 6215
6216 6216
6217 RawError* Parser::FormatErrorWithAppend(const Error& prev_error, 6217 RawError* Parser::FormatErrorWithAppend(const Error& prev_error,
6218 const Script& script, 6218 const Script& script,
6219 intptr_t token_pos, 6219 intptr_t token_pos,
6220 const char* message_header, 6220 const char* message_header,
6221 const char* format, 6221 const char* format,
6222 va_list args) { 6222 va_list args) {
6223 const intptr_t kMessageBufferSize = 512;
6224 char message_buffer[kMessageBufferSize];
6225 FormatMessage(script, token_pos, message_header,
6226 message_buffer, kMessageBufferSize,
6227 format, args);
6228 const String& msg1 = String::Handle(String::New(prev_error.ToErrorCString())); 6223 const String& msg1 = String::Handle(String::New(prev_error.ToErrorCString()));
6229 const String& msg2 = String::Handle(String::New(message_buffer)); 6224 const String& msg2 = String::Handle(
6225 FormatMessage(script, token_pos, message_header, format, args));
6230 return LanguageError::New(String::Handle(String::Concat(msg1, msg2))); 6226 return LanguageError::New(String::Handle(String::Concat(msg1, msg2)));
6231 } 6227 }
6232 6228
6233 6229
6234 RawError* Parser::FormatError(const Script& script, 6230 RawError* Parser::FormatError(const Script& script,
6235 intptr_t token_pos, 6231 intptr_t token_pos,
6236 const char* message_header, 6232 const char* message_header,
6237 const char* format, 6233 const char* format,
6238 va_list args) { 6234 va_list args) {
6239 const intptr_t kMessageBufferSize = 512; 6235 const String& msg = String::Handle(
6240 char message_buffer[kMessageBufferSize]; 6236 FormatMessage(script, token_pos, message_header, format, args));
6241 FormatMessage(script, token_pos, message_header,
6242 message_buffer, kMessageBufferSize,
6243 format, args);
6244 const String& msg = String::Handle(String::New(message_buffer));
6245 return LanguageError::New(msg); 6237 return LanguageError::New(msg);
6246 } 6238 }
6247 6239
6248 6240
6249 void Parser::FormatMessage(const Script& script, 6241 RawString* Parser::FormatMessage(const Script& script,
6250 intptr_t token_pos, 6242 intptr_t token_pos,
6251 const char* message_header, 6243 const char* message_header,
6252 char* message_buffer, 6244 const char* format, va_list args) {
6253 intptr_t message_buffer_size, 6245 String& result = String::Handle();
6254 const char* format, va_list args) { 6246 const String& msg = String::Handle(String::NewFormattedV(format, args));
6255 intptr_t msg_len = 0;
6256 if (!script.IsNull()) { 6247 if (!script.IsNull()) {
6257 const String& script_url = String::CheckedHandle(script.url()); 6248 const String& script_url = String::CheckedHandle(script.url());
6258 if (token_pos >= 0) { 6249 if (token_pos >= 0) {
6259 intptr_t line, column; 6250 intptr_t line, column;
6260 script.GetTokenLocation(token_pos, &line, &column); 6251 script.GetTokenLocation(token_pos, &line, &column);
6261 msg_len += OS::SNPrint(message_buffer + msg_len, 6252 result = String::NewFormatted("'%s': %s: line %"Pd" pos %"Pd": ",
6262 message_buffer_size - msg_len, 6253 script_url.ToCString(),
6263 "'%s': %s: line %"Pd" pos %"Pd": ", 6254 message_header,
6264 script_url.ToCString(), 6255 line,
6265 message_header, 6256 column);
6266 line, 6257 // Append the formatted error or warning message.
6267 column); 6258 result = String::Concat(result, msg);
6268 if (msg_len < message_buffer_size) { 6259 const String& new_line = String::Handle(String::New("\n"));
6269 // Append the formatted error or warning message. 6260 // Append the source line.
6270 msg_len += OS::VSNPrint(message_buffer + msg_len, 6261 const String& script_line = String::Handle(script.GetLine(line));
6271 message_buffer_size - msg_len, 6262 ASSERT(!script_line.IsNull());
6272 format, 6263 result = String::Concat(result, new_line);
6273 args); 6264 result = String::Concat(result, script_line);
6274 if (msg_len < message_buffer_size) { 6265 result = String::Concat(result, new_line);
6275 // Append the source line. 6266 // Append the column marker.
6276 const String& script_line = String::Handle(script.GetLine(line)); 6267 const String& column_line = String::Handle(
6277 ASSERT(!script_line.IsNull()); 6268 String::NewFormatted("%*s\n", static_cast<int>(column), "^"));
6278 msg_len += OS::SNPrint(message_buffer + msg_len, 6269 result = String::Concat(result, column_line);
6279 message_buffer_size - msg_len,
6280 "\n%s\n%*s\n",
6281 script_line.ToCString(),
6282 static_cast<int>(column),
6283 "^");
6284 }
6285 }
6286 } else { 6270 } else {
6287 // Token position is unknown. 6271 // Token position is unknown.
6288 msg_len += OS::SNPrint(message_buffer + msg_len, 6272 result = String::NewFormatted("'%s': %s: ",
6289 message_buffer_size - msg_len, 6273 script_url.ToCString(),
6290 "'%s': %s: ", 6274 message_header);
6291 script_url.ToCString(), 6275 result = String::Concat(result, msg);
6292 message_header);
6293 if (msg_len < message_buffer_size) {
6294 // Append the formatted error or warning message.
6295 msg_len += OS::VSNPrint(message_buffer + msg_len,
6296 message_buffer_size - msg_len,
6297 format,
6298 args);
6299 }
6300 } 6276 }
6301 } else { 6277 } else {
6302 // Script is unknown. 6278 // Script is unknown.
6303 // Append the formatted error or warning message. 6279 // Append the formatted error or warning message.
6304 msg_len += OS::VSNPrint(message_buffer + msg_len, 6280 result = msg.raw();
6305 message_buffer_size - msg_len,
6306 format,
6307 args);
6308 } 6281 }
6282 return result.raw();
6309 } 6283 }
6310 6284
6311 6285
6312 void Parser::PrintMessage(const Script& script, 6286 void Parser::PrintMessage(const Script& script,
6313 intptr_t token_pos, 6287 intptr_t token_pos,
6314 const char* message_header, 6288 const char* message_header,
6315 const char* format, ...) { 6289 const char* format, ...) {
6316 va_list args; 6290 va_list args;
6317 va_start(args, format); 6291 va_start(args, format);
6318 const intptr_t kMessageBufferSize = 512; 6292 const String& buf = String::Handle(
6319 char message_buffer[kMessageBufferSize]; 6293 FormatMessage(script, token_pos, message_header, format, args));
6320 FormatMessage(script, token_pos, message_header,
6321 message_buffer, kMessageBufferSize,
6322 format, args);
6323 va_end(args); 6294 va_end(args);
6324 OS::Print("%s", message_buffer); 6295 OS::Print("%s", buf.ToCString());
6325 } 6296 }
6326 6297
6327 6298
6328 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) { 6299 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) {
6329 va_list args; 6300 va_list args;
6330 va_start(args, format); 6301 va_start(args, format);
6331 const Error& error = Error::Handle( 6302 const Error& error = Error::Handle(
6332 FormatError(script_, token_pos, "Error", format, args)); 6303 FormatError(script_, token_pos, "Error", format, args));
6333 va_end(args); 6304 va_end(args);
6334 Isolate::Current()->long_jump_base()->Jump(1, error); 6305 Isolate::Current()->long_jump_base()->Jump(1, error);
(...skipping 3137 matching lines...) Expand 10 before | Expand all | Expand 10 after
9472 void Parser::SkipQualIdent() { 9443 void Parser::SkipQualIdent() {
9473 ASSERT(IsIdentifier()); 9444 ASSERT(IsIdentifier());
9474 ConsumeToken(); 9445 ConsumeToken();
9475 if (CurrentToken() == Token::kPERIOD) { 9446 if (CurrentToken() == Token::kPERIOD) {
9476 ConsumeToken(); // Consume the kPERIOD token. 9447 ConsumeToken(); // Consume the kPERIOD token.
9477 ExpectIdentifier("identifier expected after '.'"); 9448 ExpectIdentifier("identifier expected after '.'");
9478 } 9449 }
9479 } 9450 }
9480 9451
9481 } // namespace dart 9452 } // namespace dart
OLDNEW
« vm/object.cc ('K') | « vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698