| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 import 'js_emitter.dart' show computeMixinClass; | 7 import 'js_emitter.dart' show computeMixinClass; |
| 8 import 'model.dart'; | 8 import 'model.dart'; |
| 9 | 9 |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 element, name, null, [], instanceFields, [], [], [], null, | 293 element, name, null, [], instanceFields, [], [], [], null, |
| 294 isDirectlyInstantiated: true, | 294 isDirectlyInstantiated: true, |
| 295 onlyForRti: false, | 295 onlyForRti: false, |
| 296 isNative: element.isNative); | 296 isNative: element.isNative); |
| 297 } | 297 } |
| 298 | 298 |
| 299 Class _buildClass(ClassElement element) { | 299 Class _buildClass(ClassElement element) { |
| 300 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element); | 300 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element); |
| 301 | 301 |
| 302 List<Method> methods = []; | 302 List<Method> methods = []; |
| 303 List<StubMethod> callStubs = <StubMethod>[]; | 303 List<StubMethod> stubs = <StubMethod>[]; |
| 304 |
| 305 ClassStubGenerator classStubGenerator = |
| 306 new ClassStubGenerator(_compiler, namer, backend); |
| 304 | 307 |
| 305 void visitMember(ClassElement enclosing, Element member) { | 308 void visitMember(ClassElement enclosing, Element member) { |
| 306 assert(invariant(element, member.isDeclaration)); | 309 assert(invariant(element, member.isDeclaration)); |
| 307 assert(invariant(element, element == enclosing)); | 310 assert(invariant(element, element == enclosing)); |
| 308 | 311 |
| 309 if (Elements.isNonAbstractInstanceMember(member)) { | 312 if (Elements.isNonAbstractInstanceMember(member)) { |
| 310 js.Expression code = backend.generatedCode[member]; | 313 js.Expression code = backend.generatedCode[member]; |
| 311 // TODO(herhut): Remove once _buildMethod can no longer return null. | 314 // TODO(herhut): Remove once _buildMethod can no longer return null. |
| 312 Method method = _buildMethod(member); | 315 Method method = _buildMethod(member); |
| 313 if (method != null) methods.add(method); | 316 if (method != null) methods.add(method); |
| 314 } | 317 } |
| 315 if (member.isGetter || member.isField) { | 318 if (member.isGetter || member.isField) { |
| 316 Set<Selector> selectors = | 319 Set<Selector> selectors = |
| 317 _compiler.codegenWorld.invokedNames[member.name]; | 320 _compiler.codegenWorld.invokedNames[member.name]; |
| 318 if (selectors != null && !selectors.isEmpty) { | 321 if (selectors != null && !selectors.isEmpty) { |
| 319 ClassStubGenerator generator = | 322 |
| 320 new ClassStubGenerator(_compiler, namer, backend); | |
| 321 Map<String, js.Expression> callStubsForMember = | 323 Map<String, js.Expression> callStubsForMember = |
| 322 generator.generateCallStubsForGetter(member, selectors); | 324 classStubGenerator.generateCallStubsForGetter(member, selectors); |
| 323 callStubsForMember.forEach((String name, js.Expression code) { | 325 callStubsForMember.forEach((String name, js.Expression code) { |
| 324 callStubs.add(_buildStubMethod(name, code, element: member)); | 326 stubs.add(_buildStubMethod(name, code, element: member)); |
| 325 }); | 327 }); |
| 326 } | 328 } |
| 327 } | 329 } |
| 328 } | 330 } |
| 329 | 331 |
| 332 if (element == _compiler.objectClass) { |
| 333 Map<String, Selector> selectors = |
| 334 classStubGenerator.computeSelectorsForNsmHandlers(); |
| 335 selectors.forEach((String name, Selector selector) { |
| 336 stubs.add(classStubGenerator.generateStubForNoSuchMethod(selector)); |
| 337 }); |
| 338 } |
| 339 |
| 330 ClassElement implementation = element.implementation; | 340 ClassElement implementation = element.implementation; |
| 331 | 341 |
| 332 // MixinApplications run through the members of their mixin. Here, we are | 342 // MixinApplications run through the members of their mixin. Here, we are |
| 333 // only interested in direct members. | 343 // only interested in direct members. |
| 334 if (!onlyForRti && !element.isMixinApplication) { | 344 if (!onlyForRti && !element.isMixinApplication) { |
| 335 implementation.forEachMember(visitMember, includeBackendMembers: true); | 345 implementation.forEachMember(visitMember, includeBackendMembers: true); |
| 336 } | 346 } |
| 337 | 347 |
| 338 List<Field> instanceFields = | 348 List<Field> instanceFields = |
| 339 onlyForRti ? const <Field>[] : _buildFields(element, false); | 349 onlyForRti ? const <Field>[] : _buildFields(element, false); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 360 | 370 |
| 361 Class result; | 371 Class result; |
| 362 if (element.isMixinApplication && !onlyForRti) { | 372 if (element.isMixinApplication && !onlyForRti) { |
| 363 assert(!element.isNative); | 373 assert(!element.isNative); |
| 364 assert(methods.isEmpty); | 374 assert(methods.isEmpty); |
| 365 | 375 |
| 366 result = new MixinApplication(element, | 376 result = new MixinApplication(element, |
| 367 name, holder, | 377 name, holder, |
| 368 instanceFields, | 378 instanceFields, |
| 369 staticFieldsForReflection, | 379 staticFieldsForReflection, |
| 370 callStubs, | 380 stubs, |
| 371 isChecks, | 381 isChecks, |
| 372 typeTests.functionTypeIndex, | 382 typeTests.functionTypeIndex, |
| 373 isDirectlyInstantiated: isInstantiated, | 383 isDirectlyInstantiated: isInstantiated, |
| 374 onlyForRti: onlyForRti); | 384 onlyForRti: onlyForRti); |
| 375 } else { | 385 } else { |
| 376 result = new Class(element, | 386 result = new Class(element, |
| 377 name, holder, methods, instanceFields, | 387 name, holder, methods, instanceFields, |
| 378 staticFieldsForReflection, | 388 staticFieldsForReflection, |
| 379 callStubs, | 389 stubs, |
| 380 isChecks, | 390 isChecks, |
| 381 typeTests.functionTypeIndex, | 391 typeTests.functionTypeIndex, |
| 382 isDirectlyInstantiated: isInstantiated, | 392 isDirectlyInstantiated: isInstantiated, |
| 383 onlyForRti: onlyForRti, | 393 onlyForRti: onlyForRti, |
| 384 isNative: element.isNative); | 394 isNative: element.isNative); |
| 385 } | 395 } |
| 386 _classes[element] = result; | 396 _classes[element] = result; |
| 387 return result; | 397 return result; |
| 388 } | 398 } |
| 389 | 399 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 _registry.registerConstant(outputUnit, constantValue); | 630 _registry.registerConstant(outputUnit, constantValue); |
| 621 assert(!_constants.containsKey(constantValue)); | 631 assert(!_constants.containsKey(constantValue)); |
| 622 String name = namer.constantName(constantValue); | 632 String name = namer.constantName(constantValue); |
| 623 String constantObject = namer.globalObjectForConstant(constantValue); | 633 String constantObject = namer.globalObjectForConstant(constantValue); |
| 624 Holder holder = _registry.registerHolder(constantObject); | 634 Holder holder = _registry.registerHolder(constantObject); |
| 625 Constant constant = new Constant(name, holder, constantValue); | 635 Constant constant = new Constant(name, holder, constantValue); |
| 626 _constants[constantValue] = constant; | 636 _constants[constantValue] = constant; |
| 627 } | 637 } |
| 628 } | 638 } |
| 629 } | 639 } |
| OLD | NEW |