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

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

Issue 1071703002: Remove some duplication in code that extracts the source for a function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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/vm/compiler_test.cc » ('j') | runtime/vm/compiler_test.cc » ('J')
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/mirrors.h" 5 #include "lib/mirrors.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 // We handle constructors in Dart code. 1861 // We handle constructors in Dart code.
1862 ASSERT(!func.IsGenerativeConstructor()); 1862 ASSERT(!func.IsGenerativeConstructor());
1863 const AbstractType& type = AbstractType::Handle(func.result_type()); 1863 const AbstractType& type = AbstractType::Handle(func.result_type());
1864 return InstantiateType(type, instantiator); 1864 return InstantiateType(type, instantiator);
1865 } 1865 }
1866 1866
1867 1867
1868 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) { 1868 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
1869 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1869 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1870 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1870 const Function& func = Function::Handle(ref.GetFunctionReferent());
1871 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { 1871 return func.GetSource();
1872 // We may need to handle more cases when the restrictions on mixins are
1873 // relaxed. In particular we might start associating some source with the
1874 // forwarding constructors when it becomes possible to specify a particular
1875 // constructor from the mixin to use.
1876 return Instance::null();
1877 }
1878 const Script& script = Script::Handle(func.script());
1879 const TokenStream& stream = TokenStream::Handle(script.tokens());
1880 if (!script.HasSource()) {
1881 // When source is not available, avoid printing the whole token stream and
1882 // doing expensive position calculations.
1883 return stream.GenerateSource(func.token_pos(), func.end_token_pos() + 1);
1884 }
1885
1886 const TokenStream::Iterator tkit(stream, func.end_token_pos());
1887 intptr_t from_line;
1888 intptr_t from_col;
1889 intptr_t to_line;
1890 intptr_t to_col;
1891 script.GetTokenLocation(func.token_pos(), &from_line, &from_col);
1892 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col);
1893 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length();
1894 // Handle special cases for end tokens of closures (where we exclude the last
1895 // token):
1896 // (1) "foo(() => null, bar);": End token is `,', but we don't print it.
1897 // (2) "foo(() => null);": End token is ')`, but we don't print it.
1898 // (3) "var foo = () => null;": End token is `;', but in this case the token
1899 // semicolon belongs to the assignment so we skip it.
1900 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1.
1901 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2.
1902 (tkit.CurrentTokenKind() == Token::kSEMICOLON &&
1903 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3.
1904 last_tok_len = 0;
1905 }
1906 const Instance& result = Instance::Handle(
1907 script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len));
1908 ASSERT(!result.IsNull());
1909 return result.raw();
1910 } 1872 }
1911 1873
1912 1874
1913 static RawInstance* CreateSourceLocation(const String& uri, 1875 static RawInstance* CreateSourceLocation(const String& uri,
1914 intptr_t line, 1876 intptr_t line,
1915 intptr_t column) { 1877 intptr_t column) {
1916 const Array& args = Array::Handle(Array::New(3)); 1878 const Array& args = Array::Handle(Array::New(3));
1917 args.SetAt(0, uri); 1879 args.SetAt(0, uri);
1918 args.SetAt(1, Smi::Handle(Smi::New(line))); 1880 args.SetAt(1, Smi::Handle(Smi::New(line)));
1919 args.SetAt(2, Smi::Handle(Smi::New(column))); 1881 args.SetAt(2, Smi::Handle(Smi::New(column)));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 } 2009 }
2048 2010
2049 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2011 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
2050 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2012 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2051 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2013 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2052 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2014 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
2053 } 2015 }
2054 2016
2055 2017
2056 } // namespace dart 2018 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/compiler_test.cc » ('j') | runtime/vm/compiler_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698