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

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

Issue 211243009: Implement MethodMirror.location in the VM. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add to api and fix type warnings Created 6 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 | « no previous file | runtime/lib/mirrors_impl.dart » ('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 "lib/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 2138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3. 2149 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3.
2150 last_tok_len = 0; 2150 last_tok_len = 0;
2151 } 2151 }
2152 const Instance& result = Instance::Handle( 2152 const Instance& result = Instance::Handle(
2153 script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len)); 2153 script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len));
2154 ASSERT(!result.IsNull()); 2154 ASSERT(!result.IsNull());
2155 return result.raw(); 2155 return result.raw();
2156 } 2156 }
2157 2157
2158 2158
2159 static RawInstance* CreateSourceLocation(const String& uri,
2160 intptr_t line,
2161 intptr_t column) {
2162 const Array& args = Array::Handle(Array::New(3));
2163 args.SetAt(0, uri);
2164 args.SetAt(1, Smi::Handle(Smi::New(line)));
2165 args.SetAt(2, Smi::Handle(Smi::New(column)));
2166 return CreateMirror(Symbols::_SourceLocation(), args);
2167 }
2168
2169
2170 DEFINE_NATIVE_ENTRY(MethodMirror_location, 1) {
2171 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
2172 const Function& func = Function::Handle(ref.GetFunctionReferent());
2173 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) {
2174 // These are synthetic methods; they have no source.
2175 return Instance::null();
2176 }
2177 const Script& script = Script::Handle(func.script());
2178 const String& uri = String::Handle(script.url());
2179 intptr_t from_line = 0;
2180 intptr_t from_col = 0;
2181 if (script.HasSource()) {
2182 script.GetTokenLocation(func.token_pos(), &from_line, &from_col);
2183 } else {
2184 // Avoid the slow path of printing the token stream when precise source
2185 // information is not available.
2186 script.GetTokenLocation(func.token_pos(), &from_line, NULL);
2187 }
2188 // We should always have at least the line number.
2189 ASSERT(from_line != 0);
2190 return CreateSourceLocation(uri, from_line, from_col);
2191 }
2192
2193
2159 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { 2194 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
2160 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 2195 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
2161 const Class& cls = Class::Handle(type.type_class()); 2196 const Class& cls = Class::Handle(type.type_class());
2162 const Function& sig_func = Function::Handle(cls.signature_function()); 2197 const Function& sig_func = Function::Handle(cls.signature_function());
2163 const Class& sig_cls = Class::Handle(sig_func.signature_class()); 2198 const Class& sig_cls = Class::Handle(sig_func.signature_class());
2164 2199
2165 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType()); 2200 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType());
2166 referent_type = InstantiateType(referent_type, type); 2201 referent_type = InstantiateType(referent_type, type);
2167 2202
2168 return CreateFunctionTypeMirror(sig_cls, referent_type); 2203 return CreateFunctionTypeMirror(sig_cls, referent_type);
(...skipping 26 matching lines...) Expand all
2195 } 2230 }
2196 2231
2197 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2232 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
2198 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2233 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2199 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2234 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2200 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2235 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
2201 } 2236 }
2202 2237
2203 2238
2204 } // namespace dart 2239 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698