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 class NativeEmitter { | 5 class NativeEmitter { |
6 | 6 |
7 CodeEmitterTask emitter; | 7 CodeEmitterTask emitter; |
8 CodeBuffer nativeBuffer; | 8 CodeBuffer nativeBuffer; |
9 | 9 |
10 // Classes that participate in dynamic dispatch. These are the | 10 // Classes that participate in dynamic dispatch. These are the |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 assert(classElement.backendMembers.isEmpty()); | 143 assert(classElement.backendMembers.isEmpty()); |
144 String quotedName = classElement.nativeName.slowToString(); | 144 String quotedName = classElement.nativeName.slowToString(); |
145 if (isNativeLiteral(quotedName)) { | 145 if (isNativeLiteral(quotedName)) { |
146 generateNativeLiteral(classElement); | 146 generateNativeLiteral(classElement); |
147 // The native literal kind needs to be dealt with specially when | 147 // The native literal kind needs to be dealt with specially when |
148 // generating code for it. | 148 // generating code for it. |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 CodeBuffer fieldBuffer = new CodeBuffer(); | 152 CodeBuffer fieldBuffer = new CodeBuffer(); |
153 emitter.emitClassFields(classElement, fieldBuffer); | 153 List<String> checkedSetters = |
| 154 emitter.emitClassFields(classElement, fieldBuffer); |
154 | 155 |
155 CodeBuffer methodBuffer = new CodeBuffer(); | 156 CodeBuffer methodBuffer = new CodeBuffer(); |
156 emitter.emitInstanceMembers(classElement, methodBuffer, false); | 157 emitter.emitInstanceMembers(classElement, methodBuffer, false); |
157 | 158 |
158 if (methodBuffer.isEmpty() && fieldBuffer.isEmpty()) return; | 159 if (methodBuffer.isEmpty() && fieldBuffer.isEmpty()) return; |
159 | 160 |
160 String nativeName = toNativeName(classElement); | 161 String nativeName = toNativeName(classElement); |
161 nativeBuffer.add("$defineNativeClassName('$nativeName', ["); | 162 nativeBuffer.add("$defineNativeClassName('$nativeName', ["); |
162 nativeBuffer.add(fieldBuffer); | 163 nativeBuffer.add(fieldBuffer); |
163 nativeBuffer.add('], {'); | 164 nativeBuffer.add('], {'); |
| 165 if (!checkedSetters.isEmpty()) { |
| 166 nativeBuffer.add('${Strings.join(checkedSetters, ",\n")}'); |
| 167 nativeBuffer.add(',\n'); |
| 168 } |
164 nativeBuffer.add(methodBuffer); | 169 nativeBuffer.add(methodBuffer); |
165 nativeBuffer.add('\n});\n\n'); | 170 nativeBuffer.add('\n});\n\n'); |
166 | 171 |
167 classesWithDynamicDispatch.add(classElement); | 172 classesWithDynamicDispatch.add(classElement); |
168 } | 173 } |
169 | 174 |
170 List<ClassElement> getDirectSubclasses(ClassElement cls) { | 175 List<ClassElement> getDirectSubclasses(ClassElement cls) { |
171 List<ClassElement> result = directSubtypes[cls]; | 176 List<ClassElement> result = directSubtypes[cls]; |
172 return result === null ? const<ClassElement>[] : result; | 177 return result === null ? const<ClassElement>[] : result; |
173 } | 178 } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 if (!first) targetBuffer.add(",\n"); | 437 if (!first) targetBuffer.add(",\n"); |
433 targetBuffer.add(" $name: $function"); | 438 targetBuffer.add(" $name: $function"); |
434 first = false; | 439 first = false; |
435 }); | 440 }); |
436 targetBuffer.add("\n});\n\n"); | 441 targetBuffer.add("\n});\n\n"); |
437 } | 442 } |
438 targetBuffer.add('$nativeBuffer'); | 443 targetBuffer.add('$nativeBuffer'); |
439 targetBuffer.add('\n'); | 444 targetBuffer.add('\n'); |
440 } | 445 } |
441 } | 446 } |
OLD | NEW |