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:io'; | 5 import 'dart:io'; |
6 | 6 |
7 // TODO(jmesserly): should be importing a compiler mirrors package. | 7 // TODO(jmesserly): should be importing a compiler mirrors package. |
8 // This is currently generated by the shell script. | 8 // This is currently generated by the shell script. |
9 import 'compile_mirrors.dart'; | 9 import 'compile_mirrors.dart'; |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 The information is used to create "$OUTPUT_NAME". | 33 The information is used to create "$OUTPUT_NAME". |
34 '''); | 34 '''); |
35 | 35 |
36 var sdk = Platform.environment['DART_SDK']; | 36 var sdk = Platform.environment['DART_SDK']; |
37 if (sdk == null) { | 37 if (sdk == null) { |
38 print('DART_SDK path must be set. Use gen_html_setters.sh.'); | 38 print('DART_SDK path must be set. Use gen_html_setters.sh.'); |
39 exit(1); | 39 exit(1); |
40 } | 40 } |
41 | 41 |
42 var htmlPath = new Path('dart:html'); | 42 var htmlPath = new Path('dart:html'); |
43 var libPath = new Path(sdk); | 43 var audioPath = new Path('dart:web_audio'); |
| 44 var svgPath = new Path('dart:svg'); |
| 45 var libPath = new Path(sdk).append('/'); |
44 var pkgPath = new Path(sdk).append('pkg/'); | 46 var pkgPath = new Path(sdk).append('pkg/'); |
45 | 47 |
46 var mirrors = new Compilation.library([htmlPath], libPath, pkgPath).mirrors; | 48 var mirrors = new Compilation.library( |
| 49 [htmlPath, audioPath, svgPath], libPath, pkgPath).mirrors; |
47 var html = mirrors.libraries['html']; | 50 var html = mirrors.libraries['html']; |
48 | 51 |
49 | 52 |
50 var extendsCode = new StringBuffer(); | 53 var extendsCode = new StringBuffer(); |
51 extendsCode.add('var htmlElementExtends = const {\n'); | 54 extendsCode.add('var htmlElementExtends = const {\n'); |
52 | 55 |
53 var code = new StringBuffer(); | 56 var code = new StringBuffer(); |
54 code.add('// This file is autogenerated by $MY_NAME. Do not edit.\n'); | 57 code.add('// This file is autogenerated by $MY_NAME. Do not edit.\n'); |
55 code.add('library html5_setters;\n'); | 58 code.add('library html5_setters;\n'); |
56 | 59 |
57 var elemSet = new Set(); | 60 var elemSet = new Set(); |
58 for (var name in htmlElementNames.values) { | 61 for (var name in htmlElementNames.values) { |
59 _addElement(html.classes[name], elemSet); | 62 var qualifiedName = name.split('.'); |
| 63 var lib = mirrors.libraries[qualifiedName[0]]; |
| 64 _addElement(lib.classes[qualifiedName[1]], elemSet); |
60 } | 65 } |
61 _addElement(html.classes['UnknownElement'], elemSet); | 66 _addElement(html.classes['UnknownElement'], elemSet); |
62 | 67 |
63 code.add('var htmlElementFields = const {\n'); | 68 code.add('var htmlElementFields = const {\n'); |
64 var elements = new List.from(elemSet); | 69 var elements = new List.from(elemSet); |
65 elements.sort(); | 70 elements.sort((a, b) => a.displayName.compareTo(b.displayName)); |
66 for (var element in elements) { | 71 for (var cls in elements) { |
67 var cls = html.classes[element]; | 72 var element = cls.qualifiedName; |
68 var setters = []; | 73 var setters = []; |
69 | 74 |
70 if (cls.superclass != null | 75 if (cls.superclass != null |
71 && cls.superclass.displayName.endsWith('Element')) { | 76 && cls.superclass.displayName.endsWith('Element')) { |
72 extendsCode.add(" '$element': '${cls.superclass.displayName}',\n"); | 77 extendsCode.add(" '$element': '${cls.superclass.qualifiedName}',\n"); |
73 } | 78 } |
74 | 79 |
75 // TODO(jmesserly): using "cls.setters" does not seem to work | 80 // TODO(jmesserly): using "cls.setters" does not seem to work |
76 for (var member in cls.members.values) { | 81 for (var member in cls.members.values) { |
77 if (member.simpleName.startsWith(r'$')) continue; | 82 if (member.simpleName.startsWith(r'$')) continue; |
78 if (member is! VariableMirror) continue; | 83 if (member is! VariableMirror) continue; |
79 if (member.isFinal || member.isConst) continue; | 84 if (member.isFinal || member.isConst) continue; |
80 setters.add(member.displayName); | 85 setters.add(member.displayName); |
81 } | 86 } |
82 | 87 |
(...skipping 18 matching lines...) Expand all Loading... |
101 .openSync(FileMode.WRITE) | 106 .openSync(FileMode.WRITE) |
102 ..writeStringSync(code.toString()) | 107 ..writeStringSync(code.toString()) |
103 ..closeSync(); | 108 ..closeSync(); |
104 | 109 |
105 print('Wrote $outPath.'); | 110 print('Wrote $outPath.'); |
106 } | 111 } |
107 | 112 |
108 /** Add an element class and its element super classes to [elemSet]. */ | 113 /** Add an element class and its element super classes to [elemSet]. */ |
109 void _addElement(ClassMirror cls, Set elemSet) { | 114 void _addElement(ClassMirror cls, Set elemSet) { |
110 while (cls != null) { | 115 while (cls != null) { |
111 var name = cls.displayName; | 116 if (!cls.isOriginalDeclaration) cls = cls.originalDeclaration; |
112 if (!name.endsWith('Element') || elemSet.contains(name)) { | 117 if (!cls.displayName.endsWith('Element') || elemSet.contains(cls)) { |
113 break; | 118 break; |
114 } | 119 } |
115 elemSet.add(name); | 120 elemSet.add(cls); |
116 cls = cls.superclass; | 121 cls = cls.superclass; |
117 } | 122 } |
118 } | 123 } |
OLD | NEW |