OLD | NEW |
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 import "dart:nativewrappers"; | 5 import "dart:nativewrappers"; |
6 // TODO(ahe): Move _symbol_dev.Symbol to its own "private" library? | 6 // TODO(ahe): Move _symbol_dev.Symbol to its own "private" library? |
7 import "dart:_collection-dev" as _symbol_dev; | 7 import "dart:_collection-dev" as _symbol_dev; |
8 | 8 |
9 /** | 9 /** |
10 * Returns a [MirrorSystem] for the current isolate. | 10 * Returns a [MirrorSystem] for the current isolate. |
(...skipping 22 matching lines...) Expand all Loading... |
33 return _Mirrors.reflectClass(key); | 33 return _Mirrors.reflectClass(key); |
34 } | 34 } |
35 | 35 |
36 patch TypeMirror reflectType(Type key) { | 36 patch TypeMirror reflectType(Type key) { |
37 return _Mirrors.reflectType(key); | 37 return _Mirrors.reflectType(key); |
38 } | 38 } |
39 | 39 |
40 patch class MirrorSystem { | 40 patch class MirrorSystem { |
41 /* patch */ static String getName(Symbol symbol) { | 41 /* patch */ static String getName(Symbol symbol) { |
42 String string = _symbol_dev.Symbol.getName(symbol); | 42 String string = _symbol_dev.Symbol.getName(symbol); |
43 if (string.contains(' with ')) return string; | 43 |
44 return _unmangleName(string); | 44 // get:foo -> foo |
| 45 // set:foo -> foo= |
| 46 // get:_foo@xxx -> _foo |
| 47 // set:_foo@xxx -> _foo= |
| 48 // Class._constructor@xxx -> Class._constructor |
| 49 // _Class@xxx._constructor@xxx -> _Class._constructor |
| 50 // lib._S@xxx with lib._M1@xxx, lib._M2@xxx -> lib._S with lib._M1, lib._M2 |
| 51 StringBuffer result = new StringBuffer(); |
| 52 bool add_setter_suffix = false; |
| 53 var pos = 0; |
| 54 if (string.length >= 4 && string[3] == ':') { |
| 55 // Drop 'get:' or 'set:' prefix. |
| 56 pos = 4; |
| 57 if (string[0] == 's') { |
| 58 add_setter_suffix; |
| 59 } |
| 60 } |
| 61 // Skip everything between AT and PERIOD, SPACE, COMMA or END |
| 62 bool skip = false; |
| 63 for (; pos < string.length; pos++) { |
| 64 var char = string[pos]; |
| 65 if (char == '@') { |
| 66 skip = true; |
| 67 } else if (char == '.' || char == ' ' || char == ',') { |
| 68 skip = false; |
| 69 } |
| 70 if (!skip) { |
| 71 result.write(char); |
| 72 } |
| 73 } |
| 74 if (add_setter_suffix) { |
| 75 result.write('='); |
| 76 } |
| 77 return result.toString(); |
45 } | 78 } |
| 79 |
46 /* patch */ static Symbol getSymbol(String name, [LibraryMirror library]) { | 80 /* patch */ static Symbol getSymbol(String name, [LibraryMirror library]) { |
47 if (library is! LibraryMirror || | 81 if (library is! LibraryMirror || |
48 ((name[0] == '_') && (library == null))) { | 82 ((name.length > 0) && (name[0] == '_') && (library == null))) { |
49 throw new ArgumentError(library); | 83 throw new ArgumentError(library); |
50 } | 84 } |
51 if (library != null) name = _mangleName(name, library._reflectee); | 85 if (library != null) name = _mangleName(name, library._reflectee); |
52 return new _symbol_dev.Symbol.unvalidated(name); | 86 return new _symbol_dev.Symbol.unvalidated(name); |
53 } | 87 } |
54 | 88 |
55 static _unmangleName(String name) | |
56 native "Mirrors_unmangleName"; | |
57 static _mangleName(String name, _MirrorReference lib) | 89 static _mangleName(String name, _MirrorReference lib) |
58 native "Mirrors_mangleName"; | 90 native "Mirrors_mangleName"; |
59 } | 91 } |
60 | 92 |
61 // TODO(rmacnak): Eliminate this class. | 93 // TODO(rmacnak): Eliminate this class. |
62 class MirroredCompilationError { | 94 class MirroredCompilationError { |
63 final String message; | 95 final String message; |
64 | 96 |
65 MirroredCompilationError(this.message); | 97 MirroredCompilationError(this.message); |
66 | 98 |
67 String toString() { | 99 String toString() { |
68 return "Compile-time error during mirrored execution: <$message>"; | 100 return "Compile-time error during mirrored execution: <$message>"; |
69 } | 101 } |
70 } | 102 } |
OLD | NEW |