| 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 part of dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 typedef bool IsSafeToRemoveTypeDeclarations( | 7 typedef bool IsSafeToRemoveTypeDeclarations( |
| 8 Map<ClassElement, Iterable<Element>> classMembers); | 8 Map<ClassElement, Iterable<Element>> classMembers); |
| 9 typedef void ElementCallback<E>(E element); | 9 typedef void ElementCallback<E>(E element); |
| 10 typedef void ElementPostProcessFunction( | 10 typedef void ElementPostProcessFunction( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 PlaceholderCollector collector = new PlaceholderCollector( | 155 PlaceholderCollector collector = new PlaceholderCollector( |
| 156 listener, | 156 listener, |
| 157 mirrorRenamer, | 157 mirrorRenamer, |
| 158 libraryInfo.fixedDynamicNames, | 158 libraryInfo.fixedDynamicNames, |
| 159 elementInfo.elementAsts, | 159 elementInfo.elementAsts, |
| 160 mainFunction); | 160 mainFunction); |
| 161 | 161 |
| 162 makePlaceholders(element) { | 162 makePlaceholders(element) { |
| 163 collector.collect(element); | 163 collector.collect(element); |
| 164 | 164 |
| 165 if (element.isClass) { | 165 if (element.isClass && !element.isEnumClass) { |
| 166 elementInfo.classMembers[element].forEach(makePlaceholders); | 166 elementInfo.classMembers[element].forEach(makePlaceholders); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 elementInfo.topLevelElements.forEach(makePlaceholders); | 169 elementInfo.topLevelElements.forEach(makePlaceholders); |
| 170 return collector; | 170 return collector; |
| 171 } | 171 } |
| 172 | 172 |
| 173 static PlaceholderRenamer createRenamer( | 173 static PlaceholderRenamer createRenamer( |
| 174 PlaceholderCollector collector, | 174 PlaceholderCollector collector, |
| 175 LibraryInfo libraryInfo, | 175 LibraryInfo libraryInfo, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 if (!library.isInternalLibrary && | 269 if (!library.isInternalLibrary && |
| 270 export.library.isInternalLibrary) { | 270 export.library.isInternalLibrary) { |
| 271 // If an element of an internal library is reexported by a platform | 271 // If an element of an internal library is reexported by a platform |
| 272 // library, we have to import the reexporting library instead of the | 272 // library, we have to import the reexporting library instead of the |
| 273 // internal library, because the internal library is an | 273 // internal library, because the internal library is an |
| 274 // implementation detail of dart2js. | 274 // implementation detail of dart2js. |
| 275 reexportingLibraries[export] = library; | 275 reexportingLibraries[export] = library; |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 |
| 279 // As of now names of named optionals are not renamed. Therefore add all | 280 // As of now names of named optionals are not renamed. Therefore add all |
| 280 // field names used as named optionals into [fixedMemberNames]. | 281 // field names used as named optionals into [fixedMemberNames]. |
| 281 for (final element in resolvedElements) { | 282 for (final element in resolvedElements) { |
| 282 if (!element.isConstructor) continue; | 283 if (!element.isConstructor) continue; |
| 283 Link<Element> optionalParameters = | 284 Link<Element> optionalParameters = |
| 284 element.functionSignature.optionalParameters; | 285 element.functionSignature.optionalParameters; |
| 285 for (final optional in optionalParameters) { | 286 for (final optional in optionalParameters) { |
| 286 if (!optional.isInitializingFormal) continue; | 287 if (!optional.isInitializingFormal) continue; |
| 287 fixedDynamicNames.add(optional.name); | 288 fixedDynamicNames.add(optional.name); |
| 288 } | 289 } |
| 290 ClassElement cls = element.enclosingClass; |
| 291 if (cls != null && cls.isEnumClass) { |
| 292 fixedDynamicNames.add('index'); |
| 293 } |
| 289 } | 294 } |
| 290 // The VM will automatically invoke the call method of objects | 295 // The VM will automatically invoke the call method of objects |
| 291 // that are invoked as functions. Make sure to not rename that. | 296 // that are invoked as functions. Make sure to not rename that. |
| 292 fixedDynamicNames.add('call'); | 297 fixedDynamicNames.add('call'); |
| 293 | 298 |
| 294 return new LibraryInfo( | 299 return new LibraryInfo( |
| 295 fixedStaticNames, fixedDynamicNames, | 300 fixedStaticNames, fixedDynamicNames, |
| 296 reexportingLibraries, userLibraries); | 301 reexportingLibraries, userLibraries); |
| 297 } | 302 } |
| 298 } | 303 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 Node node = treePrinter.makeTypedef(element); | 407 Node node = treePrinter.makeTypedef(element); |
| 403 addTopLevel(element, new ElementAst(node, treeElements)); | 408 addTopLevel(element, new ElementAst(node, treeElements)); |
| 404 } | 409 } |
| 405 | 410 |
| 406 void newClassElementCallback(ClassElement classElement) { | 411 void newClassElementCallback(ClassElement classElement) { |
| 407 if (!shouldOutput(classElement)) return; | 412 if (!shouldOutput(classElement)) return; |
| 408 addClass(classElement); | 413 addClass(classElement); |
| 409 } | 414 } |
| 410 | 415 |
| 411 void addMember(element) { | 416 void addMember(element) { |
| 412 ElementAst elementAst = parseElementAst(element); | |
| 413 if (element.isClassMember) { | 417 if (element.isClassMember) { |
| 414 ClassElement enclosingClass = element.enclosingClass; | 418 ClassElement enclosingClass = element.enclosingClass; |
| 415 assert(enclosingClass.isClass); | 419 assert(enclosingClass.isClass); |
| 416 assert(enclosingClass.isTopLevel); | 420 assert(enclosingClass.isTopLevel); |
| 417 assert(shouldOutput(enclosingClass)); | 421 assert(shouldOutput(enclosingClass)); |
| 418 addClass(enclosingClass); | 422 addClass(enclosingClass); |
| 419 classMembers[enclosingClass].add(element); | 423 classMembers[enclosingClass].add(element); |
| 420 processElement(element, elementAst); | 424 if (enclosingClass.isEnumClass) return; |
| 425 processElement(element, parseElementAst(element)); |
| 421 } else { | 426 } else { |
| 422 if (element.isTopLevel) { | 427 if (element.isTopLevel) { |
| 423 addTopLevel(element, elementAst); | 428 addTopLevel(element, parseElementAst(element)); |
| 424 } | 429 } |
| 425 } | 430 } |
| 426 } | 431 } |
| 427 } | 432 } |
| 428 | 433 |
| 429 /// Main output generator for [DartOutputter] that emits dart code through a | 434 /// Main output generator for [DartOutputter] that emits dart code through a |
| 430 /// [CompilerOutputProvider]. | 435 /// [CompilerOutputProvider]. |
| 431 class MainOutputGenerator { | 436 class MainOutputGenerator { |
| 432 final Map<ClassNode, List<Node>> memberNodes = | 437 final Map<ClassNode, List<Node>> memberNodes = |
| 433 new Map<ClassNode, List<Node>>(); | 438 new Map<ClassNode, List<Node>>(); |
| 434 final List<Node> topLevelNodes = <Node>[]; | 439 final List<Node> topLevelNodes = <Node>[]; |
| 435 | 440 |
| 436 /// Generates the code and returns the total size. | 441 /// Generates the code and returns the total size. |
| 437 int generateCode( | 442 int generateCode( |
| 438 LibraryInfo libraryInfo, | 443 LibraryInfo libraryInfo, |
| 439 ElementInfo elementInfo, | 444 ElementInfo elementInfo, |
| 440 PlaceholderCollector collector, | 445 PlaceholderCollector collector, |
| 441 PlaceholderRenamer placeholderRenamer, | 446 PlaceholderRenamer placeholderRenamer, |
| 442 FunctionElement mainFunction, | 447 FunctionElement mainFunction, |
| 443 Uri outputUri, | 448 Uri outputUri, |
| 444 CompilerOutputProvider outputProvider, | 449 CompilerOutputProvider outputProvider, |
| 445 MirrorRenamer mirrorRenamer, | 450 MirrorRenamer mirrorRenamer, |
| 446 {bool multiFile: false, | 451 {bool multiFile: false, |
| 447 bool forceStripTypes: false, | 452 bool forceStripTypes: false, |
| 448 bool enableMinification: false}) { | 453 bool enableMinification: false}) { |
| 449 for (Element element in elementInfo.topLevelElements) { | 454 for (Element element in elementInfo.topLevelElements) { |
| 450 topLevelNodes.add(elementInfo.elementAsts[element].ast); | 455 topLevelNodes.add(elementInfo.elementAsts[element].ast); |
| 451 if (element.isClass && !element.isMixinApplication) { | 456 if (element.isClass) { |
| 457 ClassElement cls = element; |
| 458 if (cls.isMixinApplication || cls.isEnumClass) { |
| 459 continue; |
| 460 } |
| 452 final members = <Node>[]; | 461 final members = <Node>[]; |
| 453 for (Element member in elementInfo.classMembers[element]) { | 462 for (Element member in elementInfo.classMembers[cls]) { |
| 454 members.add(elementInfo.elementAsts[member].ast); | 463 members.add(elementInfo.elementAsts[member].ast); |
| 455 } | 464 } |
| 456 memberNodes[elementInfo.elementAsts[element].ast] = members; | 465 memberNodes[elementInfo.elementAsts[cls].ast] = members; |
| 457 } | 466 } |
| 458 } | 467 } |
| 459 | 468 |
| 460 mirrorRenamer.addRenames(placeholderRenamer.renames, | 469 mirrorRenamer.addRenames(placeholderRenamer.renames, |
| 461 topLevelNodes, collector); | 470 topLevelNodes, collector); |
| 462 | 471 |
| 463 Map<LibraryElement, String> outputPaths = new Map<LibraryElement, String>(); | 472 Map<LibraryElement, String> outputPaths = new Map<LibraryElement, String>(); |
| 464 Map<LibraryElement, EmitterUnparser> unparsers = | 473 Map<LibraryElement, EmitterUnparser> unparsers = |
| 465 new Map<LibraryElement, EmitterUnparser>(); | 474 new Map<LibraryElement, EmitterUnparser>(); |
| 466 | 475 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 outputProvider("", "dart") | 573 outputProvider("", "dart") |
| 565 ..add(code) | 574 ..add(code) |
| 566 ..close(); | 575 ..close(); |
| 567 | 576 |
| 568 totalSize = code.length; | 577 totalSize = code.length; |
| 569 } | 578 } |
| 570 | 579 |
| 571 return totalSize; | 580 return totalSize; |
| 572 } | 581 } |
| 573 } | 582 } |
| OLD | NEW |