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 class CGBlock { | 5 class CGBlock { |
6 int _blockType; // Code type of this block | 6 int _blockType; // Code type of this block |
7 int _indent; // Number of spaces to prefix for each statement | 7 int _indent; // Number of spaces to prefix for each statement |
8 bool _inEach; // This block or any currently active blocks is a | 8 bool _inEach; // This block or any currently active blocks is a |
9 // #each. If so then any element marked with a | 9 // #each. If so then any element marked with a |
10 // var attribute is repeated therefore the var | 10 // var attribute is repeated therefore the var |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 _stmts.add(stmt); | 47 _stmts.add(stmt); |
48 | 48 |
49 return stmt; | 49 return stmt; |
50 } | 50 } |
51 | 51 |
52 void pop() { | 52 void pop() { |
53 _stmts.removeLast(); | 53 _stmts.removeLast(); |
54 } | 54 } |
55 | 55 |
56 void add(String value) { | 56 void add(String value) { |
57 if (_stmts.last() != null) { | 57 if (_stmts.last != null) { |
58 _stmts.last().add(value); | 58 _stmts.last.add(value); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 CGStatement get last => _stmts.length > 0 ? _stmts.last() : null; | 62 CGStatement get last => _stmts.length > 0 ? _stmts.last : null; |
63 | 63 |
64 /** | 64 /** |
65 * Returns mixed list of elements marked with the var attribute. If the | 65 * Returns mixed list of elements marked with the var attribute. If the |
66 * element is inside of a #each the name exposed is: | 66 * element is inside of a #each the name exposed is: |
67 * | 67 * |
68 * List varName; | 68 * List varName; |
69 * | 69 * |
70 * otherwise it's: | 70 * otherwise it's: |
71 * | 71 * |
72 * var varName; | 72 * var varName; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 515 |
516 ElemCG() : | 516 ElemCG() : |
517 expressions = [], | 517 expressions = [], |
518 eachs = [], | 518 eachs = [], |
519 withs = [], | 519 withs = [], |
520 _cgBlocks = [], | 520 _cgBlocks = [], |
521 _globalDecls = new StringBuffer(), | 521 _globalDecls = new StringBuffer(), |
522 _globalInits = new StringBuffer(); | 522 _globalInits = new StringBuffer(); |
523 | 523 |
524 bool get isLastBlockConstructor { | 524 bool get isLastBlockConstructor { |
525 CGBlock block = _cgBlocks.last(); | 525 CGBlock block = _cgBlocks.last; |
526 return block.isConstructor; | 526 return block.isConstructor; |
527 } | 527 } |
528 | 528 |
529 List<String> activeBlocksLocalNames() { | 529 List<String> activeBlocksLocalNames() { |
530 List<String> result = []; | 530 List<String> result = []; |
531 | 531 |
532 for (final CGBlock block in _cgBlocks) { | 532 for (final CGBlock block in _cgBlocks) { |
533 if (block.isEach || block.isWith) { | 533 if (block.isEach || block.isWith) { |
534 if (block.hasLocalName) { | 534 if (block.hasLocalName) { |
535 result.add(block.localName); | 535 result.add(block.localName); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 return lastBlock.last.variableName; | 642 return lastBlock.last.variableName; |
643 } | 643 } |
644 } | 644 } |
645 | 645 |
646 String get lastParentName { | 646 String get lastParentName { |
647 if (lastBlock != null && lastBlock.last != null) { | 647 if (lastBlock != null && lastBlock.last != null) { |
648 return lastBlock.last.parentName; | 648 return lastBlock.last.parentName; |
649 } | 649 } |
650 } | 650 } |
651 | 651 |
652 CGBlock get lastBlock => _cgBlocks.length > 0 ? _cgBlocks.last() : null; | 652 CGBlock get lastBlock => _cgBlocks.length > 0 ? _cgBlocks.last : null; |
653 | 653 |
654 void add(String str) { | 654 void add(String str) { |
655 _cgBlocks.last().add(str); | 655 _cgBlocks.last.add(str); |
656 } | 656 } |
657 | 657 |
658 String get globalDeclarations { | 658 String get globalDeclarations { |
659 assert(_cgBlocks.length == 1); // Only constructor body should be left. | 659 assert(_cgBlocks.length == 1); // Only constructor body should be left. |
660 _globalDecls.add(lastBlock.globalDeclarations); | 660 _globalDecls.add(lastBlock.globalDeclarations); |
661 return _globalDecls.toString(); | 661 return _globalDecls.toString(); |
662 } | 662 } |
663 | 663 |
664 String get globalInitializers { | 664 String get globalInitializers { |
665 assert(_cgBlocks.length == 1); // Only constructor body should be left. | 665 assert(_cgBlocks.length == 1); // Only constructor body should be left. |
666 _globalInits.add(lastBlock.globalInitializers); | 666 _globalInits.add(lastBlock.globalInitializers); |
667 return _globalInits.toString(); | 667 return _globalInits.toString(); |
668 } | 668 } |
669 | 669 |
670 String get codeBody { | 670 String get codeBody { |
671 closeStatement(); | 671 closeStatement(); |
672 return _cgBlocks.last().codeBody; | 672 return _cgBlocks.last.codeBody; |
673 } | 673 } |
674 | 674 |
675 /* scopeName for expression | 675 /* scopeName for expression |
676 * parentVarOrIndex if # it's a local variable if string it's an exposed | 676 * parentVarOrIndex if # it's a local variable if string it's an exposed |
677 * name (specified by the var attribute) for this element. | 677 * name (specified by the var attribute) for this element. |
678 * | 678 * |
679 */ | 679 */ |
680 emitElement(var elem, | 680 emitElement(var elem, |
681 [String scopeName = "", | 681 [String scopeName = "", |
682 var parentVarOrIdx = 0, | 682 var parentVarOrIdx = 0, |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 for (String name in names) { | 1004 for (String name in names) { |
1005 buff.add(" var ${name} = _scopes[\"${name}\"];\n"); | 1005 buff.add(" var ${name} = _scopes[\"${name}\"];\n"); |
1006 } | 1006 } |
1007 buff.add("\n"); | 1007 buff.add("\n"); |
1008 } | 1008 } |
1009 | 1009 |
1010 return buff.toString(); | 1010 return buff.toString(); |
1011 } | 1011 } |
1012 | 1012 |
1013 } | 1013 } |
OLD | NEW |