OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 List sorted(Iterable input, [compare, key]) { | 5 List sorted(Iterable input, [compare, key]) { |
6 comparator(compare, key) { | 6 comparator(compare, key) { |
7 if (compare == null && key == null) | 7 if (compare == null && key == null) |
8 return (a, b) => a.compareTo(b); | 8 return (a, b) => a.compareTo(b); |
9 if (compare == null) | 9 if (compare == null) |
10 return (a, b) => key(a).compareTo(key(b)); | 10 return (a, b) => key(a).compareTo(key(b)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 indented(() { | 68 indented(() { |
69 w(node.interfaces); | 69 w(node.interfaces); |
70 w(node.typedefs); | 70 w(node.typedefs); |
71 }); | 71 }); |
72 wln('};'); | 72 wln('};'); |
73 } else if (node is IDLInterface) { | 73 } else if (node is IDLInterface) { |
74 w(node.annotations); | 74 w(node.annotations); |
75 w(node.extAttrs); | 75 w(node.extAttrs); |
76 w('interface ${node.id}'); | 76 w('interface ${node.id}'); |
77 indented(() { | 77 indented(() { |
78 if (!node.parents.isEmpty()) { | 78 if (!node.parents.isEmpty) { |
79 wln(' :'); | 79 wln(' :'); |
80 w(node.parents, ',\n'); | 80 w(node.parents, ',\n'); |
81 } | 81 } |
82 wln(' {'); | 82 wln(' {'); |
83 section(list, comment) { | 83 section(list, comment) { |
84 if (list != null && !list.isEmpty()) { | 84 if (list != null && !list.isEmpty) { |
85 wln(); | 85 wln(); |
86 wln(comment); | 86 wln(comment); |
87 w(sort(list)); | 87 w(sort(list)); |
88 } | 88 } |
89 } | 89 } |
90 section(node.constants, '/* Constants */'); | 90 section(node.constants, '/* Constants */'); |
91 section(node.attributes, '/* Attributes */'); | 91 section(node.attributes, '/* Attributes */'); |
92 section(node.operations, '/* Operations */'); | 92 section(node.operations, '/* Operations */'); |
93 section(node.snippets, '/* Snippets */'); | 93 section(node.snippets, '/* Snippets */'); |
94 }); | 94 }); |
95 wln('};'); | 95 wln('};'); |
96 } else if (node is IDLParentInterface) { | 96 } else if (node is IDLParentInterface) { |
97 w(node.annotations); | 97 w(node.annotations); |
98 w(node.type.id); | 98 w(node.type.id); |
99 } else if (node is IDLAnnotations) { | 99 } else if (node is IDLAnnotations) { |
100 for (var name in sorted(node.map.getKeys())) { | 100 for (var name in sorted(node.map.getKeys())) { |
101 IDLAnnotation annotation = node.map[name]; | 101 IDLAnnotation annotation = node.map[name]; |
102 var args = annotation.map; | 102 var args = annotation.map; |
103 if (args.isEmpty()) { | 103 if (args.isEmpty) { |
104 w('@$name'); | 104 w('@$name'); |
105 } else { | 105 } else { |
106 var formattedArgs = []; | 106 var formattedArgs = []; |
107 for (var argName in sorted(args.getKeys())) { | 107 for (var argName in sorted(args.getKeys())) { |
108 var argValue = args[argName]; | 108 var argValue = args[argName]; |
109 if (argValue == null) | 109 if (argValue == null) |
110 formattedArgs.add(argName); | 110 formattedArgs.add(argName); |
111 else | 111 else |
112 formattedArgs.add('$argName=$argValue'); | 112 formattedArgs.add('$argName=$argValue'); |
113 } | 113 } |
114 w('@$name(${Strings.join(formattedArgs,',')})'); | 114 w('@$name(${Strings.join(formattedArgs,',')})'); |
115 } | 115 } |
116 w(' '); | 116 w(' '); |
117 } | 117 } |
118 } else if (node is IDLExtAttrs) { | 118 } else if (node is IDLExtAttrs) { |
119 if(!node.map.isEmpty()) { | 119 if(!node.map.isEmpty) { |
120 w('['); | 120 w('['); |
121 var sep = null; | 121 var sep = null; |
122 for (var name in sorted(node.map.getKeys())) { | 122 for (var name in sorted(node.map.getKeys())) { |
123 w(sep); | 123 w(sep); |
124 sep = ', '; | 124 sep = ', '; |
125 w(name); | 125 w(name); |
126 var value = node.map[name]; | 126 var value = node.map[name]; |
127 if (value != null) { | 127 if (value != null) { |
128 w('='); | 128 w('='); |
129 w(value); | 129 w(value); |
(...skipping 12 matching lines...) Expand all Loading... |
142 } else if (node is IDLConstant) { | 142 } else if (node is IDLConstant) { |
143 w(node.annotations); | 143 w(node.annotations); |
144 w(node.extAttrs); | 144 w(node.extAttrs); |
145 wln('const ${node.type.id} ${node.id} = ${node.value};'); | 145 wln('const ${node.type.id} ${node.id} = ${node.value};'); |
146 } else if (node is IDLSnippet) { | 146 } else if (node is IDLSnippet) { |
147 w(node.annotations); | 147 w(node.annotations); |
148 wln('snippet {${node.text}};'); | 148 wln('snippet {${node.text}};'); |
149 } else if (node is IDLOperation) { | 149 } else if (node is IDLOperation) { |
150 w(node.annotations); | 150 w(node.annotations); |
151 w(node.extAttrs); | 151 w(node.extAttrs); |
152 if (node.specials != null && !node.specials.isEmpty()) { | 152 if (node.specials != null && !node.specials.isEmpty) { |
153 w(node.specials, ' '); | 153 w(node.specials, ' '); |
154 w(' '); | 154 w(' '); |
155 } | 155 } |
156 w('${node.type.id} ${node.id}'); | 156 w('${node.type.id} ${node.id}'); |
157 w('('); | 157 w('('); |
158 w(node.arguments, ', '); | 158 w(node.arguments, ', '); |
159 wln(');'); | 159 wln(');'); |
160 } else if (node is IDLArgument) { | 160 } else if (node is IDLArgument) { |
161 w(node.extAttrs); | 161 w(node.extAttrs); |
162 w('in '); | 162 w('in '); |
163 if (node.isOptional) | 163 if (node.isOptional) |
164 w('optional '); | 164 w('optional '); |
165 w('${node.type.id} ${node.id}'); | 165 w('${node.type.id} ${node.id}'); |
166 } else if (node is IDLExtAttrFunctionValue) { | 166 } else if (node is IDLExtAttrFunctionValue) { |
167 w(node.name); | 167 w(node.name); |
168 w('('); | 168 w('('); |
169 w(node.arguments, ', '); | 169 w(node.arguments, ', '); |
170 w(')'); | 170 w(')'); |
171 } else if (node is IDLTypeDef) { | 171 } else if (node is IDLTypeDef) { |
172 wln('typedef ${node.type.id} ${node.id};'); | 172 wln('typedef ${node.type.id} ${node.id};'); |
173 } else { | 173 } else { |
174 w('// $node\n'); | 174 w('// $node\n'); |
175 } | 175 } |
176 }; | 176 }; |
177 | 177 |
178 w(idl_node); | 178 w(idl_node); |
179 return Strings.concatAll(output); | 179 return Strings.concatAll(output); |
180 } | 180 } |
OLD | NEW |