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