OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
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.md file. | |
4 | |
5 library fletchc.fletch_native_descriptor; | |
6 | |
7 import 'dart:convert' show | |
8 JSON; | |
9 | |
10 class FletchNativeDescriptor { | |
11 final String enumName; | |
12 | |
13 final String cls; | |
14 | |
15 final String name; | |
16 | |
17 final int index; | |
18 | |
19 FletchNativeDescriptor(this.enumName, this.cls, this.name, this.index); | |
20 | |
21 String toString() => "FletchNativeDescriptor($enumName, $cls, $name, $index)"; | |
22 | |
23 static void decode( | |
24 String jsonData, | |
25 Map<String, FletchNativeDescriptor> natives, | |
26 Map<String, String> names) { | |
27 Map jsonObjects = JSON.decode(jsonData); | |
28 int index = 0; | |
29 for (Map native in jsonObjects['natives']) { | |
30 String cls = native['class']; | |
31 String name = native['name']; | |
32 void add(cls, name) { | |
33 natives['$cls.$name'] = | |
34 new FletchNativeDescriptor(native['enum'], cls, name, index); | |
35 natives['$cls._fletchNative$name'] = | |
36 new FletchNativeDescriptor(native['enum'], cls, name, index); | |
37 } | |
38 if (cls == "<none>") { | |
39 cls = null; | |
40 add("", name); | |
41 if (name.startsWith("_")) { | |
42 // For private top-level methods, create a public version as well. | |
43 // TODO(ahe): Modify the VM table of natives. | |
44 add("", name.substring(1)); | |
45 } | |
46 } else { | |
47 add(cls, name); | |
48 } | |
49 index++; | |
50 } | |
51 for (Map name in jsonObjects['names']) { | |
52 names[name['name']] = name['value']; | |
53 } | |
54 } | |
55 } | |
OLD | NEW |