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

Side by Side Diff: vm/dart_api_impl.cc

Issue 10826191: Improve the stack trace output to be more readable. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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 | « tests/vm/dart/isolate_mirror_local_test.dart ('k') | vm/dart_api_impl_test.cc » ('j') | 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 "include/dart_api.h" 5 #include "include/dart_api.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/dart.h" 10 #include "vm/dart.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 do { \ 70 do { \
71 intptr_t len = (length); \ 71 intptr_t len = (length); \
72 intptr_t max = (max_elements); \ 72 intptr_t max = (max_elements); \
73 if (len < 0 || len > max) { \ 73 if (len < 0 || len > max) { \
74 return Api::NewError( \ 74 return Api::NewError( \
75 "%s expects argument '%s' to be in the range [0..%ld].", \ 75 "%s expects argument '%s' to be in the range [0..%ld].", \
76 CURRENT_FUNC, #length, max); \ 76 CURRENT_FUNC, #length, max); \
77 } \ 77 } \
78 } while (0) 78 } while (0)
79 79
80 // Takes a vm internal name and makes it suitable for external user.
81 //
82 // Examples:
83 //
84 // Internal getter and setter prefices are removed:
85 //
86 // get:foo -> foo
87 // set:foo -> foo
88 //
89 // Private name mangling is removed, possibly twice:
90 //
91 // _ReceivePortImpl@6be832b -> _ReceivePortImpl
92 // _ReceivePortImpl@6be832b._internal@6be832b -> +ReceivePortImpl._internal
93 //
94 // The trailing . on the default constructor name is dropped:
95 //
96 // List. -> List
97 //
98 // And so forth:
99 //
100 // get:foo@6be832b -> foo
101 // _MyClass@6b3832b. -> _MyClass
102 // _MyClass@6b3832b.named -> _MyClass.named
103 //
104 static RawString* IdentifierPrettyName(Isolate* isolate, const String& name) {
105 intptr_t len = name.Length();
106 intptr_t start = 0;
107 intptr_t at_pos = len; // Position of '@' in the name.
108 intptr_t dot_pos = len; // Position of '.' in the name.
109
110 for (int i = 0; i < name.Length(); i++) {
111 if (name.CharAt(i) == ':') {
112 ASSERT(start == 0);
113 start = i + 1;
114 } else if (name.CharAt(i) == '@') {
115 ASSERT(at_pos == len);
116 at_pos = i;
117 } else if (name.CharAt(i) == '.') {
118 dot_pos = i;
119 break;
120 }
121 }
122 intptr_t limit = (at_pos < dot_pos ? at_pos : dot_pos);
123 if (start == 0 && limit == len) {
124 // This name is fine as it is.
125 return name.raw();
126 }
127
128 String& result = String::Handle(isolate);
129 result = String::SubString(name, start, (limit - start));
130
131 // Look for a second '@' now to correctly handle names like
132 // "_ReceivePortImpl@6be832b._internal@6be832b".
133 at_pos = len;
134 for (int i = dot_pos; i < name.Length(); i++) {
135 if (name.CharAt(i) == '@') {
136 ASSERT(at_pos == len);
137 at_pos = i;
138 }
139 }
140
141 intptr_t suffix_len = at_pos - dot_pos;
142 if (suffix_len <= 1) {
143 // The constructor name is of length 0 or 1. That means that
144 // either this isn't a constructor or that this is an unnamed
145 // constructor. In either case, we're done.
146 return result.raw();
147 }
148
149 const String& suffix =
150 String::Handle(isolate, String::SubString(name, dot_pos, suffix_len));
151 return String::Concat(result, suffix);
152 }
153
154 80
155 // Return error if isolate is in an inconsistent state. 81 // Return error if isolate is in an inconsistent state.
156 // Return NULL when no error condition exists. 82 // Return NULL when no error condition exists.
157 // 83 //
158 // TODO(turnidge): Make this function return an error handle directly 84 // TODO(turnidge): Make this function return an error handle directly
159 // rather than returning an error string. The current behavior can 85 // rather than returning an error string. The current behavior can
160 // cause compilation errors to appear to be api errors. 86 // cause compilation errors to appear to be api errors.
161 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { 87 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) {
162 bool success = true; 88 bool success = true;
163 if (!ClassFinalizer::AllClassesFinalized()) { 89 if (!ClassFinalizer::AllClassesFinalized()) {
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 2402
2477 2403
2478 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { 2404 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) {
2479 Isolate* isolate = Isolate::Current(); 2405 Isolate* isolate = Isolate::Current();
2480 DARTSCOPE(isolate); 2406 DARTSCOPE(isolate);
2481 const Class& cls = Class::Handle( 2407 const Class& cls = Class::Handle(
2482 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); 2408 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2483 if (cls.IsNull()) { 2409 if (cls.IsNull()) {
2484 RETURN_TYPE_ERROR(isolate, clazz, Class); 2410 RETURN_TYPE_ERROR(isolate, clazz, Class);
2485 } 2411 }
2486 const String& cls_name = String::Handle(isolate, cls.Name()); 2412 return Api::NewHandle(isolate, cls.UserVisibleName());
2487 return Api::NewHandle(isolate, IdentifierPrettyName(isolate, cls_name));
2488 } 2413 }
2489 2414
2490 2415
2491 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { 2416 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) {
2492 Isolate* isolate = Isolate::Current(); 2417 Isolate* isolate = Isolate::Current();
2493 DARTSCOPE(isolate); 2418 DARTSCOPE(isolate);
2494 const Class& cls = Class::Handle( 2419 const Class& cls = Class::Handle(
2495 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); 2420 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2496 if (cls.IsNull()) { 2421 if (cls.IsNull()) {
2497 RETURN_TYPE_ERROR(isolate, clazz, Class); 2422 RETURN_TYPE_ERROR(isolate, clazz, Class);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2584 2509
2585 // --- Function and Variable Reflection --- 2510 // --- Function and Variable Reflection ---
2586 2511
2587 2512
2588 // Outside of the vm, we expose setter names with a trailing '='. 2513 // Outside of the vm, we expose setter names with a trailing '='.
2589 static bool HasExternalSetterSuffix(const String& name) { 2514 static bool HasExternalSetterSuffix(const String& name) {
2590 return name.CharAt(name.Length() - 1) == '='; 2515 return name.CharAt(name.Length() - 1) == '=';
2591 } 2516 }
2592 2517
2593 2518
2594 static RawString* AddExternalSetterSuffix(const String& name) {
2595 const String& equals = String::Handle(Symbols::New("="));
2596 return String::Concat(name, equals);
2597 }
2598
2599
2600 static RawString* RemoveExternalSetterSuffix(const String& name) { 2519 static RawString* RemoveExternalSetterSuffix(const String& name) {
2601 ASSERT(HasExternalSetterSuffix(name)); 2520 ASSERT(HasExternalSetterSuffix(name));
2602 return String::SubString(name, 0, name.Length() - 1); 2521 return String::SubString(name, 0, name.Length() - 1);
2603 } 2522 }
2604 2523
2605 2524
2606 DART_EXPORT Dart_Handle Dart_GetFunctionNames(Dart_Handle target) { 2525 DART_EXPORT Dart_Handle Dart_GetFunctionNames(Dart_Handle target) {
2607 Isolate* isolate = Isolate::Current(); 2526 Isolate* isolate = Isolate::Current();
2608 DARTSCOPE(isolate); 2527 DARTSCOPE(isolate);
2609 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 2528 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
(...skipping 15 matching lines...) Expand all
2625 for (intptr_t i = 0; i < func_array.Length(); ++i) { 2544 for (intptr_t i = 0; i < func_array.Length(); ++i) {
2626 func ^= func_array.At(i); 2545 func ^= func_array.At(i);
2627 2546
2628 // Skip implicit getters and setters. 2547 // Skip implicit getters and setters.
2629 if (func.kind() == RawFunction::kImplicitGetter || 2548 if (func.kind() == RawFunction::kImplicitGetter ||
2630 func.kind() == RawFunction::kImplicitSetter || 2549 func.kind() == RawFunction::kImplicitSetter ||
2631 func.kind() == RawFunction::kConstImplicitGetter) { 2550 func.kind() == RawFunction::kConstImplicitGetter) {
2632 continue; 2551 continue;
2633 } 2552 }
2634 2553
2635 name = func.name(); 2554 name = func.UserVisibleName();
2636 bool is_setter = Field::IsSetterName(name);
2637 name = IdentifierPrettyName(isolate, name);
2638
2639 if (is_setter) {
2640 name = AddExternalSetterSuffix(name);
2641 }
2642 names.Add(name); 2555 names.Add(name);
2643 } 2556 }
2644 } 2557 }
2645 } else if (obj.IsLibrary()) { 2558 } else if (obj.IsLibrary()) {
2646 const Library& lib = Library::Cast(obj); 2559 const Library& lib = Library::Cast(obj);
2647 DictionaryIterator it(lib); 2560 DictionaryIterator it(lib);
2648 Object& obj = Object::Handle(); 2561 Object& obj = Object::Handle();
2649 while (it.HasNext()) { 2562 while (it.HasNext()) {
2650 obj = it.GetNext(); 2563 obj = it.GetNext();
2651 if (obj.IsFunction()) { 2564 if (obj.IsFunction()) {
2652 func ^= obj.raw(); 2565 func ^= obj.raw();
2653 name = func.name(); 2566 name = func.UserVisibleName();
2654 bool is_setter = Field::IsSetterName(name);
2655 name = IdentifierPrettyName(isolate, name);
2656 if (is_setter) {
2657 name = AddExternalSetterSuffix(name);
2658 }
2659 names.Add(name); 2567 names.Add(name);
2660 } 2568 }
2661 } 2569 }
2662 } else { 2570 } else {
2663 return Api::NewError( 2571 return Api::NewError(
2664 "%s expects argument 'target' to be a class or library.", 2572 "%s expects argument 'target' to be a class or library.",
2665 CURRENT_FUNC); 2573 CURRENT_FUNC);
2666 } 2574 }
2667 return Api::NewHandle(isolate, Array::MakeArray(names)); 2575 return Api::NewHandle(isolate, Array::MakeArray(names));
2668 } 2576 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2756 } 2664 }
2757 2665
2758 2666
2759 DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function) { 2667 DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function) {
2760 Isolate* isolate = Isolate::Current(); 2668 Isolate* isolate = Isolate::Current();
2761 DARTSCOPE(isolate); 2669 DARTSCOPE(isolate);
2762 const Function& func = Api::UnwrapFunctionHandle(isolate, function); 2670 const Function& func = Api::UnwrapFunctionHandle(isolate, function);
2763 if (func.IsNull()) { 2671 if (func.IsNull()) {
2764 RETURN_TYPE_ERROR(isolate, function, Function); 2672 RETURN_TYPE_ERROR(isolate, function, Function);
2765 } 2673 }
2766 String& func_name = String::Handle(isolate); 2674 return Api::NewHandle(isolate, func.UserVisibleName());
2767 func_name = func.name();
2768 bool is_setter = Field::IsSetterName(func_name);
2769 func_name = IdentifierPrettyName(isolate, func_name);
2770 if (is_setter) {
2771 func_name = AddExternalSetterSuffix(func_name);
2772 }
2773 return Api::NewHandle(isolate, func_name.raw());
2774 } 2675 }
2775 2676
2776 2677
2777 DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function) { 2678 DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function) {
2778 Isolate* isolate = Isolate::Current(); 2679 Isolate* isolate = Isolate::Current();
2779 DARTSCOPE(isolate); 2680 DARTSCOPE(isolate);
2780 const Function& func = Api::UnwrapFunctionHandle(isolate, function); 2681 const Function& func = Api::UnwrapFunctionHandle(isolate, function);
2781 if (func.IsNull()) { 2682 if (func.IsNull()) {
2782 RETURN_TYPE_ERROR(isolate, function, Function); 2683 RETURN_TYPE_ERROR(isolate, function, Function);
2783 } 2684 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2932 const Array& field_array = Array::Handle(cls.fields()); 2833 const Array& field_array = Array::Handle(cls.fields());
2933 2834
2934 // Some special types like 'Dynamic' have a null fields list. 2835 // Some special types like 'Dynamic' have a null fields list.
2935 // 2836 //
2936 // TODO(turnidge): Fix 'Dynamic' so that it does not have a null 2837 // TODO(turnidge): Fix 'Dynamic' so that it does not have a null
2937 // fields list. This will have to wait until the empty array is 2838 // fields list. This will have to wait until the empty array is
2938 // allocated in the vm isolate. 2839 // allocated in the vm isolate.
2939 if (!field_array.IsNull()) { 2840 if (!field_array.IsNull()) {
2940 for (intptr_t i = 0; i < field_array.Length(); ++i) { 2841 for (intptr_t i = 0; i < field_array.Length(); ++i) {
2941 field ^= field_array.At(i); 2842 field ^= field_array.At(i);
2942 name = field.name(); 2843 name = field.UserVisibleName();
2943 name = IdentifierPrettyName(isolate, name);
2944 names.Add(name); 2844 names.Add(name);
2945 } 2845 }
2946 } 2846 }
2947 } else if (obj.IsLibrary()) { 2847 } else if (obj.IsLibrary()) {
2948 const Library& lib = Library::Cast(obj); 2848 const Library& lib = Library::Cast(obj);
2949 DictionaryIterator it(lib); 2849 DictionaryIterator it(lib);
2950 Object& obj = Object::Handle(isolate); 2850 Object& obj = Object::Handle(isolate);
2951 while (it.HasNext()) { 2851 while (it.HasNext()) {
2952 obj = it.GetNext(); 2852 obj = it.GetNext();
2953 if (obj.IsField()) { 2853 if (obj.IsField()) {
2954 field ^= obj.raw(); 2854 field ^= obj.raw();
2955 name = field.name(); 2855 name = field.UserVisibleName();
2956 name = IdentifierPrettyName(isolate, name);
2957 names.Add(name); 2856 names.Add(name);
2958 } 2857 }
2959 } 2858 }
2960 } else { 2859 } else {
2961 return Api::NewError( 2860 return Api::NewError(
2962 "%s expects argument 'target' to be a class or library.", 2861 "%s expects argument 'target' to be a class or library.",
2963 CURRENT_FUNC); 2862 CURRENT_FUNC);
2964 } 2863 }
2965 return Api::NewHandle(isolate, Array::MakeArray(names)); 2864 return Api::NewHandle(isolate, Array::MakeArray(names));
2966 } 2865 }
(...skipping 30 matching lines...) Expand all
2997 } 2896 }
2998 2897
2999 2898
3000 DART_EXPORT Dart_Handle Dart_VariableName(Dart_Handle variable) { 2899 DART_EXPORT Dart_Handle Dart_VariableName(Dart_Handle variable) {
3001 Isolate* isolate = Isolate::Current(); 2900 Isolate* isolate = Isolate::Current();
3002 DARTSCOPE(isolate); 2901 DARTSCOPE(isolate);
3003 const Field& var = Api::UnwrapFieldHandle(isolate, variable); 2902 const Field& var = Api::UnwrapFieldHandle(isolate, variable);
3004 if (var.IsNull()) { 2903 if (var.IsNull()) {
3005 RETURN_TYPE_ERROR(isolate, variable, Field); 2904 RETURN_TYPE_ERROR(isolate, variable, Field);
3006 } 2905 }
3007 const String& var_name = String::Handle(var.name()); 2906 return Api::NewHandle(isolate, var.UserVisibleName());
3008 return Api::NewHandle(isolate, IdentifierPrettyName(isolate, var_name));
3009 } 2907 }
3010 2908
3011 2909
3012 DART_EXPORT Dart_Handle Dart_VariableIsStatic(Dart_Handle variable, 2910 DART_EXPORT Dart_Handle Dart_VariableIsStatic(Dart_Handle variable,
3013 bool* is_static) { 2911 bool* is_static) {
3014 Isolate* isolate = Isolate::Current(); 2912 Isolate* isolate = Isolate::Current();
3015 DARTSCOPE(isolate); 2913 DARTSCOPE(isolate);
3016 if (is_static == NULL) { 2914 if (is_static == NULL) {
3017 RETURN_NULL_ERROR(is_static); 2915 RETURN_NULL_ERROR(is_static);
3018 } 2916 }
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
4011 ClassDictionaryIterator it(lib); 3909 ClassDictionaryIterator it(lib);
4012 Class& cls = Class::Handle(); 3910 Class& cls = Class::Handle();
4013 String& name = String::Handle(); 3911 String& name = String::Handle();
4014 while (it.HasNext()) { 3912 while (it.HasNext()) {
4015 cls = it.GetNextClass(); 3913 cls = it.GetNextClass();
4016 // For now we suppress the signature classes of closures. 3914 // For now we suppress the signature classes of closures.
4017 // 3915 //
4018 // TODO(turnidge): Add this to the unit test. 3916 // TODO(turnidge): Add this to the unit test.
4019 const Function& signature_func = Function::Handle(cls.signature_function()); 3917 const Function& signature_func = Function::Handle(cls.signature_function());
4020 if (signature_func.IsNull()) { 3918 if (signature_func.IsNull()) {
4021 name = cls.Name(); 3919 name = cls.UserVisibleName();
4022 name = IdentifierPrettyName(isolate, name);
4023 names.Add(name); 3920 names.Add(name);
4024 } 3921 }
4025 } 3922 }
4026 return Api::NewHandle(isolate, Array::MakeArray(names)); 3923 return Api::NewHandle(isolate, Array::MakeArray(names));
4027 } 3924 }
4028 3925
4029 3926
4030 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { 3927 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
4031 Isolate* isolate = Isolate::Current(); 3928 Isolate* isolate = Isolate::Current();
4032 DARTSCOPE(isolate); 3929 DARTSCOPE(isolate);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
4184 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4081 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4185 Dart::set_perf_events_writer(function); 4082 Dart::set_perf_events_writer(function);
4186 } 4083 }
4187 4084
4188 4085
4189 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4086 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4190 Dart::set_flow_graph_writer(function); 4087 Dart::set_flow_graph_writer(function);
4191 } 4088 }
4192 4089
4193 } // namespace dart 4090 } // namespace dart
OLDNEW
« no previous file with comments | « tests/vm/dart/isolate_mirror_local_test.dart ('k') | vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698