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

Side by Side Diff: runtime/vm/parser.cc

Issue 9559001: Fix Issue 1846: Improve error reporting in presence of imports. With this CL: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « runtime/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 3292 matching lines...) Expand 10 before | Expand all | Expand 10 after
3303 const Array& import_map) { 3303 const Array& import_map) {
3304 Dart_LibraryTagHandler handler = Isolate::Current()->library_tag_handler(); 3304 Dart_LibraryTagHandler handler = Isolate::Current()->library_tag_handler();
3305 if (handler == NULL) { 3305 if (handler == NULL) {
3306 ErrorMsg(token_pos, "no library handler registered"); 3306 ErrorMsg(token_pos, "no library handler registered");
3307 } 3307 }
3308 Dart_Handle result = handler(tag, 3308 Dart_Handle result = handler(tag,
3309 Api::NewLocalHandle(library_), 3309 Api::NewLocalHandle(library_),
3310 Api::NewLocalHandle(url), 3310 Api::NewLocalHandle(url),
3311 Api::NewLocalHandle(import_map)); 3311 Api::NewLocalHandle(import_map));
3312 if (Dart_IsError(result)) { 3312 if (Dart_IsError(result)) {
3313 ErrorMsg(token_pos, "library handler failed: %s", Dart_GetError(result)); 3313 AppendErrorMsg(
3314 Dart_GetError(result), token_pos, "library handler failed");
hausner 2012/02/29 22:56:02 Dart_GetError() copies the error message out of an
srdjan 2012/02/29 23:47:04 Done.
3314 } 3315 }
3315 return result; 3316 return result;
3316 } 3317 }
3317 3318
3318 3319
3319 void Parser::ParseLibraryImport() { 3320 void Parser::ParseLibraryImport() {
3320 TRACE_PARSER("ParseLibraryImport"); 3321 TRACE_PARSER("ParseLibraryImport");
3321 while (CurrentToken() == Token::kIMPORT) { 3322 while (CurrentToken() == Token::kIMPORT) {
3322 const intptr_t import_pos = token_index_; 3323 const intptr_t import_pos = token_index_;
3323 ConsumeToken(); 3324 ConsumeToken();
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after
5247 new LoadLocalNode(statement_pos, *trace_var)); 5248 new LoadLocalNode(statement_pos, *trace_var));
5248 } 5249 }
5249 } else { 5250 } else {
5250 statement = ParseExpr(kAllowConst); 5251 statement = ParseExpr(kAllowConst);
5251 ExpectSemicolon(); 5252 ExpectSemicolon();
5252 } 5253 }
5253 return statement; 5254 return statement;
5254 } 5255 }
5255 5256
5256 5257
5258 RawError* Parser::FormatErrorWithAppend(const char* prev_error,
5259 const Script& script,
5260 intptr_t token_index,
5261 const char* message_header,
5262 const char* format,
5263 va_list args) {
5264 const intptr_t kMessageBufferSize = 512;
5265 char message_buffer[kMessageBufferSize];
5266 FormatMessage(script, token_index, message_header,
5267 message_buffer, kMessageBufferSize,
5268 format, args);
5269 const String& msg1 = String::Handle(String::New(prev_error));
5270 const String& msg2 = String::Handle(String::New(message_buffer));
5271 return LanguageError::New(String::Handle(String::Concat(msg1, msg2)));
5272 }
5273
5274
5257 RawError* Parser::FormatError(const Script& script, 5275 RawError* Parser::FormatError(const Script& script,
5258 intptr_t token_index, 5276 intptr_t token_index,
5259 const char* message_header, 5277 const char* message_header,
5260 const char* format, 5278 const char* format,
5261 va_list args) { 5279 va_list args) {
5262 const intptr_t kMessageBufferSize = 512; 5280 const intptr_t kMessageBufferSize = 512;
5263 char message_buffer[kMessageBufferSize]; 5281 char message_buffer[kMessageBufferSize];
5264 FormatMessage(script, token_index, message_header, 5282 FormatMessage(script, token_index, message_header,
5265 message_buffer, kMessageBufferSize, 5283 message_buffer, kMessageBufferSize,
5266 format, args); 5284 format, args);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
5347 va_list args; 5365 va_list args;
5348 va_start(args, format); 5366 va_start(args, format);
5349 const Error& error = Error::Handle( 5367 const Error& error = Error::Handle(
5350 FormatError(script_, token_index_, "Error", format, args)); 5368 FormatError(script_, token_index_, "Error", format, args));
5351 va_end(args); 5369 va_end(args);
5352 Isolate::Current()->long_jump_base()->Jump(1, error); 5370 Isolate::Current()->long_jump_base()->Jump(1, error);
5353 UNREACHABLE(); 5371 UNREACHABLE();
5354 } 5372 }
5355 5373
5356 5374
5375 void Parser::AppendErrorMsg(
5376 const char* prev_error, intptr_t token_index, const char* format, ...) {
5377 va_list args;
5378 va_start(args, format);
5379 const Error& error = Error::Handle(FormatErrorWithAppend(
5380 prev_error, script_, token_index, "Error", format, args));
5381 va_end(args);
5382 Isolate::Current()->long_jump_base()->Jump(1, error);
5383 UNREACHABLE();
5384 }
5385
5386
5357 void Parser::Warning(intptr_t token_index, const char* format, ...) { 5387 void Parser::Warning(intptr_t token_index, const char* format, ...) {
5358 if (FLAG_silent_warnings) return; 5388 if (FLAG_silent_warnings) return;
5359 va_list args; 5389 va_list args;
5360 va_start(args, format); 5390 va_start(args, format);
5361 const Error& error = Error::Handle( 5391 const Error& error = Error::Handle(
5362 FormatError(script_, token_index, "Warning", format, args)); 5392 FormatError(script_, token_index, "Warning", format, args));
5363 va_end(args); 5393 va_end(args);
5364 if (FLAG_warning_as_error) { 5394 if (FLAG_warning_as_error) {
5365 Isolate::Current()->long_jump_base()->Jump(1, error); 5395 Isolate::Current()->long_jump_base()->Jump(1, error);
5366 UNREACHABLE(); 5396 UNREACHABLE();
(...skipping 2609 matching lines...) Expand 10 before | Expand all | Expand 10 after
7976 void Parser::SkipQualIdent() { 8006 void Parser::SkipQualIdent() {
7977 ASSERT(IsIdentifier()); 8007 ASSERT(IsIdentifier());
7978 ConsumeToken(); 8008 ConsumeToken();
7979 if (CurrentToken() == Token::kPERIOD) { 8009 if (CurrentToken() == Token::kPERIOD) {
7980 ConsumeToken(); // Consume the kPERIOD token. 8010 ConsumeToken(); // Consume the kPERIOD token.
7981 ExpectIdentifier("identifier expected after '.'"); 8011 ExpectIdentifier("identifier expected after '.'");
7982 } 8012 }
7983 } 8013 }
7984 8014
7985 } // namespace dart 8015 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698