| 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 final bool isDetachable; | |
| 20 | |
| 21 FletchNativeDescriptor(this.enumName, this.cls, this.name, this.index, | |
| 22 this.isDetachable); | |
| 23 | |
| 24 String toString() { | |
| 25 return "FletchNativeDescriptor" | |
| 26 "($enumName, $cls, $name, $index, $isDetachable)"; | |
| 27 } | |
| 28 | |
| 29 static void decode( | |
| 30 String jsonData, | |
| 31 Map<String, FletchNativeDescriptor> natives, | |
| 32 Map<String, String> names) { | |
| 33 Map jsonObjects = JSON.decode(jsonData); | |
| 34 int index = 0; | |
| 35 for (Map native in jsonObjects['natives']) { | |
| 36 String cls = native['class']; | |
| 37 String name = native['name']; | |
| 38 bool isDetachable = native['is_detachable']; | |
| 39 assert(isDetachable != null); | |
| 40 void add(cls, name) { | |
| 41 natives['$cls.$name'] = new FletchNativeDescriptor( | |
| 42 native['enum'], cls, name, index, isDetachable); | |
| 43 natives['$cls._fletchNative$name'] = new FletchNativeDescriptor( | |
| 44 native['enum'], cls, name, index, isDetachable); | |
| 45 } | |
| 46 if (cls == "<none>") { | |
| 47 cls = null; | |
| 48 add("", name); | |
| 49 if (name.startsWith("_")) { | |
| 50 // For private top-level methods, create a public version as well. | |
| 51 // TODO(ahe): Modify the VM table of natives. | |
| 52 add("", name.substring(1)); | |
| 53 } | |
| 54 } else { | |
| 55 add(cls, name); | |
| 56 } | |
| 57 index++; | |
| 58 } | |
| 59 for (Map name in jsonObjects['names']) { | |
| 60 names[name['name']] = name['value']; | |
| 61 } | |
| 62 } | |
| 63 } | |
| OLD | NEW |