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 part of dart_backend; | 5 part of dart_backend; |
6 | 6 |
7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
10 class ElementAst { | 10 class ElementAst { |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 } else { | 374 } else { |
375 if (element.isTopLevel()) { | 375 if (element.isTopLevel()) { |
376 addTopLevel(element, elementAst); | 376 addTopLevel(element, elementAst); |
377 } | 377 } |
378 } | 378 } |
379 }); | 379 }); |
380 | 380 |
381 // Add synthesized constructors to classes with no resolved constructors, | 381 // Add synthesized constructors to classes with no resolved constructors, |
382 // but which originally had any constructor. That should prevent | 382 // but which originally had any constructor. That should prevent |
383 // those classes from being instantiable with default constructor. | 383 // those classes from being instantiable with default constructor. |
384 Identifier synthesizedIdentifier = | 384 Identifier synthesizedIdentifier = new Identifier( |
385 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); | 385 new StringToken.fromString(IDENTIFIER_INFO, '', -1)); |
386 | 386 |
387 NextClassElement: | 387 NextClassElement: |
388 for (ClassElement classElement in classMembers.keys) { | 388 for (ClassElement classElement in classMembers.keys) { |
389 for (Element member in classMembers[classElement]) { | 389 for (Element member in classMembers[classElement]) { |
390 if (member.isConstructor()) continue NextClassElement; | 390 if (member.isConstructor()) continue NextClassElement; |
391 } | 391 } |
392 if (classElement.constructors.isEmpty) continue NextClassElement; | 392 if (classElement.constructors.isEmpty) continue NextClassElement; |
393 | 393 |
394 // TODO(antonm): check with AAR team if there is better approach. | 394 // TODO(antonm): check with AAR team if there is better approach. |
395 // As an idea: provide template as a Dart code---class C { C.name(); }--- | 395 // As an idea: provide template as a Dart code---class C { C.name(); }--- |
396 // and then overwrite necessary parts. | 396 // and then overwrite necessary parts. |
397 var classNode = classElement.parseNode(compiler); | 397 var classNode = classElement.parseNode(compiler); |
398 SynthesizedConstructorElementX constructor = | 398 SynthesizedConstructorElementX constructor = |
399 new SynthesizedConstructorElementX( | 399 new SynthesizedConstructorElementX( |
400 classElement.name, null, classElement, false); | 400 classElement.name, null, classElement, false); |
401 constructor.type = new FunctionType( | 401 constructor.type = new FunctionType( |
402 constructor, | 402 constructor, |
403 compiler.types.voidType, | 403 compiler.types.voidType, |
404 const Link<DartType>(), | 404 const Link<DartType>(), |
405 const Link<DartType>(), | 405 const Link<DartType>(), |
406 const Link<String>(), | 406 const Link<String>(), |
407 const Link<DartType>() | 407 const Link<DartType>() |
408 ); | 408 ); |
409 constructor.cachedNode = new FunctionExpression( | 409 constructor.cachedNode = new FunctionExpression( |
410 new Send(classNode.name, synthesizedIdentifier), | 410 new Send(classNode.name, synthesizedIdentifier), |
411 new NodeList(new StringToken(OPEN_PAREN_INFO, '(', -1), | 411 new NodeList(new StringToken.fromString(OPEN_PAREN_INFO, '(', -1), |
412 const Link<Node>(), | 412 const Link<Node>(), |
413 new StringToken(CLOSE_PAREN_INFO, ')', -1)), | 413 new StringToken.fromString(CLOSE_PAREN_INFO, ')', -1)), |
414 new EmptyStatement(new StringToken(SEMICOLON_INFO, ';', -1)), | 414 new EmptyStatement( |
| 415 new StringToken.fromString(SEMICOLON_INFO, ';', -1)), |
415 null, Modifiers.EMPTY, null, null); | 416 null, Modifiers.EMPTY, null, null); |
416 | 417 |
417 if (!constructor.isSynthesized) { | 418 if (!constructor.isSynthesized) { |
418 classMembers[classElement].add(constructor); | 419 classMembers[classElement].add(constructor); |
419 } | 420 } |
420 elementAsts[constructor] = | 421 elementAsts[constructor] = |
421 new ElementAst(constructor.cachedNode, new TreeElementMapping(null)); | 422 new ElementAst(constructor.cachedNode, new TreeElementMapping(null)); |
422 } | 423 } |
423 | 424 |
424 // Create all necessary placeholders. | 425 // Create all necessary placeholders. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 logResultBundleSizeInfo(topLevelElements); | 500 logResultBundleSizeInfo(topLevelElements); |
500 } | 501 } |
501 | 502 |
502 void logResultBundleSizeInfo(Set<Element> topLevelElements) { | 503 void logResultBundleSizeInfo(Set<Element> topLevelElements) { |
503 Iterable<LibraryElement> referencedLibraries = | 504 Iterable<LibraryElement> referencedLibraries = |
504 compiler.libraries.values.where(isUserLibrary); | 505 compiler.libraries.values.where(isUserLibrary); |
505 // Sum total size of scripts in each referenced library. | 506 // Sum total size of scripts in each referenced library. |
506 int nonPlatformSize = 0; | 507 int nonPlatformSize = 0; |
507 for (LibraryElement lib in referencedLibraries) { | 508 for (LibraryElement lib in referencedLibraries) { |
508 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { | 509 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { |
509 nonPlatformSize += compilationUnit.script.text.length; | 510 nonPlatformSize += compilationUnit.script.file.length; |
510 } | 511 } |
511 } | 512 } |
512 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize; | 513 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize; |
513 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' | 514 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' |
514 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)'); | 515 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)'); |
515 } | 516 } |
516 | 517 |
517 log(String message) => compiler.log('[DartBackend] $message'); | 518 log(String message) => compiler.log('[DartBackend] $message'); |
518 | 519 |
519 Future onLibraryLoaded(LibraryElement library, Uri uri) { | 520 Future onLibraryLoaded(LibraryElement library, Uri uri) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 } | 629 } |
629 | 630 |
630 compareElements(e0, e1) { | 631 compareElements(e0, e1) { |
631 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); | 632 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); |
632 if (result != 0) return result; | 633 if (result != 0) return result; |
633 return compareBy((e) => e.position().charOffset)(e0, e1); | 634 return compareBy((e) => e.position().charOffset)(e0, e1); |
634 } | 635 } |
635 | 636 |
636 List<Element> sortElements(Iterable<Element> elements) => | 637 List<Element> sortElements(Iterable<Element> elements) => |
637 sorted(elements, compareElements); | 638 sorted(elements, compareElements); |
OLD | NEW |