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