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 |
11 // is a List type instead of an Element type. | 11 // is a List type instead of an Element type. |
12 String _localName; // optional local name for #each or #with | 12 String _localName; // optional local name for #each or #with |
13 List<CGStatement> _stmts; | 13 List<CGStatement> _stmts; |
14 int localIndex; // Local variable index (e.g., e0, e1, etc.) | 14 int localIndex; // Local variable index (e.g., e0, e1, etc.) |
15 | 15 |
16 // Block Types: | 16 // Block Types: |
17 static const int CONSTRUCTOR = 0; | 17 static const int CONSTRUCTOR = 0; |
18 static const int EACH = 1; | 18 static const int EACH = 1; |
19 static const int WITH = 2; | 19 static const int WITH = 2; |
20 | 20 |
21 CGBlock([this._indent = 4, | 21 CGBlock([this._indent = 4, |
22 this._blockType = CGBlock.CONSTRUCTOR, | 22 this._blockType = CGBlock.CONSTRUCTOR, |
23 this._inEach = false, | 23 this._inEach = false, |
24 this._localName = null]) : | 24 this._localName = null]) : |
25 _stmts = new List<CGStatement>(), localIndex = 0 { | 25 _stmts = new List<CGStatement>(), localIndex = 0 { |
26 assert(_blockType >= CGBlock.CONSTRUCTOR && _blockType <= CGBlock.WITH); | 26 assert(_blockType >= CGBlock.CONSTRUCTOR && _blockType <= CGBlock.WITH); |
27 } | 27 } |
28 | 28 |
29 bool get anyStatements => !_stmts.isEmpty(); | 29 bool get anyStatements => !_stmts.isEmpty; |
30 bool get isConstructor => _blockType == CGBlock.CONSTRUCTOR; | 30 bool get isConstructor => _blockType == CGBlock.CONSTRUCTOR; |
31 bool get isEach => _blockType == CGBlock.EACH; | 31 bool get isEach => _blockType == CGBlock.EACH; |
32 bool get isWith => _blockType == CGBlock.WITH; | 32 bool get isWith => _blockType == CGBlock.WITH; |
33 | 33 |
34 bool get hasLocalName => _localName != null; | 34 bool get hasLocalName => _localName != null; |
35 String get localName => _localName; | 35 String get localName => _localName; |
36 | 36 |
37 CGStatement push(var elem, var parentName, [bool exact = false]) { | 37 CGStatement push(var elem, var parentName, [bool exact = false]) { |
38 var varName; | 38 var varName; |
39 if (elem is TemplateElement && elem.hasVar) { | 39 if (elem is TemplateElement && elem.hasVar) { |
(...skipping 964 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 |