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

Side by Side Diff: runtime/lib/error.cc

Issue 8503034: Add type check tracing (--trace_type_checks). Inline type checks with class types that have only ... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | « no previous file | runtime/vm/code_generator_ia32.h » ('j') | runtime/vm/code_generator_ia32.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "lib/error.h" 5 #include "lib/error.h"
6 6
7 #include "vm/bootstrap_natives.h" 7 #include "vm/bootstrap_natives.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/runtime_entry.h" 10 #include "vm/runtime_entry.h"
11 #include "vm/stack_frame.h" 11 #include "vm/stack_frame.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks.");
15 DECLARE_FLAG(bool, print_stack_trace_at_throw); 16 DECLARE_FLAG(bool, print_stack_trace_at_throw);
16 17
17 18
18 // Static helpers for allocating, initializing, and throwing an error instance. 19 // Static helpers for allocating, initializing, and throwing an error instance.
19 20
20 // Return the script of the Dart function that called the native entry or the 21 // Return the script of the Dart function that called the native entry or the
21 // runtime entry. The frame iterator points to the callee. 22 // runtime entry. The frame iterator points to the callee.
22 static RawScript* GetCallerScript(DartFrameIterator* iterator) { 23 static RawScript* GetCallerScript(DartFrameIterator* iterator) {
23 DartFrame* caller_frame = iterator->NextFrame(); 24 DartFrame* caller_frame = iterator->NextFrame();
24 ASSERT(caller_frame != NULL); 25 ASSERT(caller_frame != NULL);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // Instantiate dst_type before reporting the error. 207 // Instantiate dst_type before reporting the error.
207 const Type& instantiated_dst_type = Type::Handle( 208 const Type& instantiated_dst_type = Type::Handle(
208 dst_type.InstantiateFrom(dst_type_instantiator, 0)); 209 dst_type.InstantiateFrom(dst_type_instantiator, 0));
209 dst_type_name = instantiated_dst_type.Name(); 210 dst_type_name = instantiated_dst_type.Name();
210 } else { 211 } else {
211 dst_type_name = dst_type.Name(); 212 dst_type_name = dst_type.Name();
212 } 213 }
213 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); 214 ThrowTypeError(location, src_type_name, dst_type_name, dst_name);
214 UNREACHABLE(); 215 UNREACHABLE();
215 } 216 }
217
218 if (FLAG_trace_type_checks) {
regis 2011/11/09 01:47:53 Are you planning on leaving this flag in or was it
srdjan 2011/11/09 19:36:30 I plan to keep it in, removed "if (known_type)".
219 Class& cls = Class::Handle(src_instance.clazz());
220 // TODO(regis): Remove once all classes finalized.
221 if (cls.is_finalized()) {
222 bool known_type =
223 (cls.type_arguments_instance_field_offset()
224 == Class::kNoTypeArguments) ||
regis 2011/11/09 01:47:53 cls.HasTypeArguments() ? And why only print raw t
srdjan 2011/11/09 19:36:30 Removed.
225 TypeArguments::Handle(src_instance.GetTypeArguments()).
226 IsTypeArray();
227 if (known_type) {
228 OS::Print("TypeCheck <%s> vs <%s>\n",
regis 2011/11/09 01:47:53 The chosen print syntax with "<" and ">" is unfort
srdjan 2011/11/09 19:36:30 :-). Using quotes instead.
229 String::Handle(Type::Handle(src_instance.GetType()).Name()).
230 ToCString(),
231 String::Handle(dst_type.Name()).ToCString());
232 }
233 }
234 }
216 arguments.SetReturn(src_instance); 235 arguments.SetReturn(src_instance);
217 } 236 }
218 237
219 238
220 // Report that the type of the given object is not bool in conditional context. 239 // Report that the type of the given object is not bool in conditional context.
221 // Arg0: index of the token of the assignment (source location). 240 // Arg0: index of the token of the assignment (source location).
222 // Arg1: bad object. 241 // Arg1: bad object.
223 // Return value: none, throws a TypeError. 242 // Return value: none, throws a TypeError.
224 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { 243 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) {
225 ASSERT(arguments.Count() == 244 ASSERT(arguments.Count() ==
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 dst_type_name = element_type.Name(); 298 dst_type_name = element_type.Name();
280 } 299 }
281 const String& dst_name = String::Handle(String::New(buf)); 300 const String& dst_name = String::Handle(String::New(buf));
282 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); 301 ThrowTypeError(location, src_type_name, dst_type_name, dst_name);
283 UNREACHABLE(); 302 UNREACHABLE();
284 } 303 }
285 } 304 }
286 } 305 }
287 306
288 } // namespace dart 307 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/code_generator_ia32.h » ('j') | runtime/vm/code_generator_ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698