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

Side by Side Diff: vm/parser.cc

Issue 9334007: Fix http://dartbug.com/1133: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 8 years, 10 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 | « 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 5130 matching lines...) Expand 10 before | Expand all | Expand 10 after
5141 return statement; 5141 return statement;
5142 } 5142 }
5143 5143
5144 5144
5145 // Static 5145 // Static
5146 RawError* Parser::FormatError(const Script& script, 5146 RawError* Parser::FormatError(const Script& script,
5147 intptr_t token_index, 5147 intptr_t token_index,
5148 const char* message_header, 5148 const char* message_header,
5149 const char* format, 5149 const char* format,
5150 va_list args) { 5150 va_list args) {
5151 const intptr_t kMessageBufferSize = 512; 5151 const String& msg = String::Handle(
5152 char message_buffer[kMessageBufferSize]; 5152 FormatMessage(script, token_index, message_header, format, args));
5153 FormatMessage(script, token_index, message_header,
5154 message_buffer, kMessageBufferSize,
5155 format, args);
5156 const String& msg = String::Handle(String::New(message_buffer));
5157 return LanguageError::New(msg); 5153 return LanguageError::New(msg);
5158 } 5154 }
5159 5155
5160 5156
5157 static RawString* VFormatMessageHelper(const char* format, va_list args) {
5158 Zone* zone = Isolate::Current()->current_zone();
5159 va_list args2;
5160 va_copy(args2, args);
5161 int msg_len = OS::VSNPrint(NULL, 0, format, args2) + 1;
5162 va_end(args2);
5163 char* chars = reinterpret_cast<char*>(zone->Allocate(msg_len));
5164 OS::VSNPrint(chars, msg_len, format, args);
5165 return String::New(chars);
5166 }
5167
5168
5169 static RawString* FormatMessageHelper(const char* format, ...) {
hausner 2012/02/07 01:00:55 This could be called Stringf(format, ...) and th
Ivan Posva 2012/02/07 04:09:55 Actually they might be generally useful factories
5170 va_list args;
5171 va_start(args, format);
5172 const String& result = String::Handle(VFormatMessageHelper(format, args));
5173 va_end(args);
5174 return result.raw();
5175 }
5176
5177
5161 // Static. 5178 // Static.
5162 void Parser::FormatMessage(const Script& script, 5179 RawString* Parser::FormatMessage(const Script& script,
5163 intptr_t token_index, 5180 intptr_t token_index,
Ivan Posva 2012/02/07 04:09:55 Bad indentation, will fix...
5164 const char* message_header, 5181 const char* message_header,
5165 char* message_buffer,
5166 intptr_t message_buffer_size,
5167 const char* format, va_list args) { 5182 const char* format, va_list args) {
5168 intptr_t msg_len = 0; 5183 Zone* zone = Isolate::Current()->current_zone();
5184 String& message = String::Handle();
5185
5169 if (!script.IsNull()) { 5186 if (!script.IsNull()) {
5170 const String& script_url = String::CheckedHandle(script.url()); 5187 const String& script_url = String::CheckedHandle(script.url());
5188 String& msg_part = String::Handle();
5189 // Prepend the script to the message with the format "'%s'".
5190 msg_part = String::New("'");
5191 message = String::Concat(msg_part, script_url);
5192 message = String::Concat(message, msg_part);
5193
5171 if (token_index >= 0) { 5194 if (token_index >= 0) {
5172 intptr_t line, column; 5195 intptr_t line, column;
5173 script.GetTokenLocation(token_index, &line, &column); 5196 script.GetTokenLocation(token_index, &line, &column);
5174 msg_len += OS::SNPrint(message_buffer + msg_len, 5197 msg_part = FormatMessageHelper(": %s: line %d pos %d: ",
hausner 2012/02/07 01:00:55 Why not include the script name in this format str
Ivan Posva 2012/02/07 04:09:55 Because the script_url could contain Unicode chara
5175 message_buffer_size - msg_len, 5198 message_header, line, column);
5176 "'%s': %s: line %d pos %d: ", 5199 message = String::Concat(message, msg_part);
5177 script_url.ToCString(), 5200
5178 message_header, 5201 // Append the formatted error or warning message.
5179 line, 5202 msg_part = VFormatMessageHelper(format, args);
5180 column); 5203 message = String::Concat(message, msg_part);
hausner 2012/02/07 01:00:55 These two calls can be factored out.
5181 if (msg_len < message_buffer_size) { 5204
5182 // Append the formatted error or warning message. 5205 // Append the source line.
5183 msg_len += OS::VSNPrint(message_buffer + msg_len, 5206 const String& script_line = String::Handle(script.GetLine(line));
5184 message_buffer_size - msg_len, 5207 ASSERT(!script_line.IsNull());
5185 format, 5208 msg_part = String::New("\n");
5186 args); 5209 message = String::Concat(message, msg_part);
5187 if (msg_len < message_buffer_size) { 5210 message = String::Concat(message, script_line);
5188 // Append the source line. 5211 msg_part = FormatMessageHelper("\n%*s\n", column, "^");
5189 const String& script_line = String::Handle(script.GetLine(line)); 5212 message = String::Concat(message, msg_part);
5190 ASSERT(!script_line.IsNull());
5191 msg_len += OS::SNPrint(message_buffer + msg_len,
5192 message_buffer_size - msg_len,
5193 "\n%s\n%*s\n",
5194 script_line.ToCString(),
5195 column,
5196 "^");
5197 }
5198 }
5199 } else { 5213 } else {
5200 // Token position is unknown. 5214 // Token position is unknown.
5201 msg_len += OS::SNPrint(message_buffer + msg_len, 5215 msg_part = FormatMessageHelper(": %s: ", message_header);
5202 message_buffer_size - msg_len, 5216 message = String::Concat(message, msg_part);
5203 "'%s': %s: ", 5217
5204 script_url.ToCString(), 5218 // Append the formatted error or warning message.
5205 message_header); 5219 msg_part = VFormatMessageHelper(format, args);
5206 if (msg_len < message_buffer_size) { 5220 message = String::Concat(message, msg_part);
5207 // Append the formatted error or warning message.
5208 msg_len += OS::VSNPrint(message_buffer + msg_len,
5209 message_buffer_size - msg_len,
5210 format,
5211 args);
5212 }
5213 } 5221 }
5214 } else { 5222 } else {
5215 // Script is unknown. 5223 // Script is unknown.
5216 // Append the formatted error or warning message. 5224 // Append the formatted error or warning message.
5217 msg_len += OS::VSNPrint(message_buffer + msg_len, 5225 message = VFormatMessageHelper(format, args);
5218 message_buffer_size - msg_len,
5219 format,
5220 args);
5221 } 5226 }
5227 return message.raw();
5222 } 5228 }
5223 5229
5224 5230
5225 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) { 5231 void Parser::ErrorMsg(intptr_t token_index, const char* format, ...) {
5226 va_list args; 5232 va_list args;
5227 va_start(args, format); 5233 va_start(args, format);
5228 const Error& error = Error::Handle( 5234 const Error& error = Error::Handle(
5229 FormatError(script_, token_index, "Error", format, args)); 5235 FormatError(script_, token_index, "Error", format, args));
5230 va_end(args); 5236 va_end(args);
5231 Isolate::Current()->long_jump_base()->Jump(1, error); 5237 Isolate::Current()->long_jump_base()->Jump(1, error);
(...skipping 2550 matching lines...) Expand 10 before | Expand all | Expand 10 after
7782 void Parser::SkipQualIdent() { 7788 void Parser::SkipQualIdent() {
7783 ASSERT(IsIdentifier()); 7789 ASSERT(IsIdentifier());
7784 ConsumeToken(); 7790 ConsumeToken();
7785 if (CurrentToken() == Token::kPERIOD) { 7791 if (CurrentToken() == Token::kPERIOD) {
7786 ConsumeToken(); // Consume the kPERIOD token. 7792 ConsumeToken(); // Consume the kPERIOD token.
7787 ExpectIdentifier("identifier expected after '.'"); 7793 ExpectIdentifier("identifier expected after '.'");
7788 } 7794 }
7789 } 7795 }
7790 7796
7791 } // namespace dart 7797 } // namespace dart
OLDNEW
« no previous file with comments | « vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698