Chromium Code Reviews| 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import "dart:math" as math; | 7 import "dart:math" as math; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| (...skipping 3044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3055 | 3055 |
| 3056 @override | 3056 @override |
| 3057 Object visitVariableDeclaration(VariableDeclaration node) { | 3057 Object visitVariableDeclaration(VariableDeclaration node) { |
| 3058 bool isConst = node.isConst; | 3058 bool isConst = node.isConst; |
| 3059 bool isFinal = node.isFinal; | 3059 bool isFinal = node.isFinal; |
| 3060 bool hasInitializer = node.initializer != null; | 3060 bool hasInitializer = node.initializer != null; |
| 3061 VariableElementImpl element; | 3061 VariableElementImpl element; |
| 3062 if (_inFieldContext) { | 3062 if (_inFieldContext) { |
| 3063 SimpleIdentifier fieldName = node.name; | 3063 SimpleIdentifier fieldName = node.name; |
| 3064 FieldElementImpl field; | 3064 FieldElementImpl field; |
| 3065 if (isConst && hasInitializer) { | 3065 if ((isConst || isFinal) && hasInitializer) { |
| 3066 field = new ConstFieldElementImpl.con1(fieldName); | 3066 field = new ConstFieldElementImpl.con1(fieldName); |
| 3067 } else { | 3067 } else { |
| 3068 field = new FieldElementImpl.forNode(fieldName); | 3068 field = new FieldElementImpl.forNode(fieldName); |
| 3069 } | 3069 } |
| 3070 element = field; | 3070 element = field; |
| 3071 _currentHolder.addField(field); | 3071 _currentHolder.addField(field); |
| 3072 fieldName.staticElement = field; | 3072 fieldName.staticElement = field; |
| 3073 } else if (_inFunction) { | 3073 } else if (_inFunction) { |
| 3074 SimpleIdentifier variableName = node.name; | 3074 SimpleIdentifier variableName = node.name; |
| 3075 LocalVariableElementImpl variable; | 3075 LocalVariableElementImpl variable; |
| (...skipping 8222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11298 } | 11298 } |
| 11299 return null; | 11299 return null; |
| 11300 } | 11300 } |
| 11301 | 11301 |
| 11302 @override | 11302 @override |
| 11303 Object visitTypeName(TypeName node) => null; | 11303 Object visitTypeName(TypeName node) => null; |
| 11304 | 11304 |
| 11305 @override | 11305 @override |
| 11306 Object visitVariableDeclaration(VariableDeclaration node) { | 11306 Object visitVariableDeclaration(VariableDeclaration node) { |
| 11307 super.visitVariableDeclaration(node); | 11307 super.visitVariableDeclaration(node); |
| 11308 if (node.element.isConst && node.initializer != null) { | 11308 VariableElement element = node.element; |
| 11309 (node.element as ConstVariableElement).constantInitializer = | 11309 // Note: in addition to cloning the initializers for const variables, we |
| 11310 // have to clone the initializers for non-static final fields (because if | |
| 11311 // they occur in a class with a const constructor, they will be needed to | |
| 11312 // evaluate the const constructor). | |
|
Brian Wilkerson
2015/04/22 02:44:00
Do we really need the AST structure? The initializ
Paul Berry
2015/04/24 18:06:33
(Capturing the result of an in-person discussion)
| |
| 11313 if ((element.isConst || | |
| 11314 (element is FieldElement && | |
| 11315 element.isFinal && | |
| 11316 !element.isStatic)) && | |
| 11317 node.initializer != null) { | |
| 11318 (element as ConstVariableElement).constantInitializer = | |
| 11310 new ConstantAstCloner().cloneNode(node.initializer); | 11319 new ConstantAstCloner().cloneNode(node.initializer); |
| 11311 } | 11320 } |
| 11312 return null; | 11321 return null; |
| 11313 } | 11322 } |
| 11314 | 11323 |
| 11315 @override | 11324 @override |
| 11316 Object visitWhileStatement(WhileStatement node) { | 11325 Object visitWhileStatement(WhileStatement node) { |
| 11317 // Note: since we don't call the base class, we have to maintain | 11326 // Note: since we don't call the base class, we have to maintain |
| 11318 // _implicitLabelScope ourselves. | 11327 // _implicitLabelScope ourselves. |
| 11319 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 11328 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| (...skipping 4091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15411 nonFields.add(node); | 15420 nonFields.add(node); |
| 15412 return null; | 15421 return null; |
| 15413 } | 15422 } |
| 15414 | 15423 |
| 15415 @override | 15424 @override |
| 15416 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15425 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15417 | 15426 |
| 15418 @override | 15427 @override |
| 15419 Object visitWithClause(WithClause node) => null; | 15428 Object visitWithClause(WithClause node) => null; |
| 15420 } | 15429 } |
| OLD | NEW |