OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.resolution.variables; | 5 library dart2js.resolution.variables; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/resolution.dart'; | 8 import '../common/resolution.dart'; |
9 import '../elements/modelx.dart' show LocalVariableElementX, VariableList; | 9 import '../elements/modelx.dart' show LocalVariableElementX, VariableList; |
10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
11 import '../universe/use.dart' show TypeUse; | 11 import '../universe/use.dart' show TypeUse; |
| 12 import '../universe/feature.dart'; |
12 import '../util/util.dart' show Link; | 13 import '../util/util.dart' show Link; |
13 import 'members.dart' show ResolverVisitor; | 14 import 'members.dart' show ResolverVisitor; |
14 import 'registry.dart' show ResolutionRegistry; | 15 import 'registry.dart' show ResolutionRegistry; |
15 import 'resolution_common.dart' show CommonResolverVisitor; | 16 import 'resolution_common.dart' show CommonResolverVisitor; |
16 import 'scope.dart' show VariableDefinitionScope; | 17 import 'scope.dart' show VariableDefinitionScope; |
17 | 18 |
18 class VariableDefinitionsVisitor extends CommonResolverVisitor<Identifier> { | 19 class VariableDefinitionsVisitor extends CommonResolverVisitor<Identifier> { |
19 VariableDefinitions definitions; | 20 VariableDefinitions definitions; |
20 ResolverVisitor resolver; | 21 ResolverVisitor resolver; |
21 VariableList variables; | 22 VariableList variables; |
(...skipping 13 matching lines...) Expand all Loading... |
35 resolver.visitIn(node.arguments.head, scope); | 36 resolver.visitIn(node.arguments.head, scope); |
36 if (scope.variableReferencedInInitializer) { | 37 if (scope.variableReferencedInInitializer) { |
37 reporter.reportErrorMessage(identifier, | 38 reporter.reportErrorMessage(identifier, |
38 MessageKind.REFERENCE_IN_INITIALIZATION, {'variableName': name}); | 39 MessageKind.REFERENCE_IN_INITIALIZATION, {'variableName': name}); |
39 } | 40 } |
40 return identifier; | 41 return identifier; |
41 } | 42 } |
42 | 43 |
43 Identifier visitIdentifier(Identifier node) { | 44 Identifier visitIdentifier(Identifier node) { |
44 // The variable is initialized to null. | 45 // The variable is initialized to null. |
45 // TODO(johnniwinther): Register a feature instead. | 46 registry.registerFeature(Feature.LOCAL_WITHOUT_INITIALIZER); |
46 registry.registerTypeUse( | |
47 new TypeUse.instantiation(resolution.coreTypes.nullType)); | |
48 if (definitions.modifiers.isConst) { | 47 if (definitions.modifiers.isConst) { |
49 if (resolver.inLoopVariable) { | 48 if (resolver.inLoopVariable) { |
50 reporter.reportErrorMessage(node, MessageKind.CONST_LOOP_VARIABLE); | 49 reporter.reportErrorMessage(node, MessageKind.CONST_LOOP_VARIABLE); |
51 } else { | 50 } else { |
52 reporter.reportErrorMessage( | 51 reporter.reportErrorMessage( |
53 node, MessageKind.CONST_WITHOUT_INITIALIZER); | 52 node, MessageKind.CONST_WITHOUT_INITIALIZER); |
54 } | 53 } |
55 } | 54 } |
56 if (definitions.modifiers.isFinal && !resolver.inLoopVariable) { | 55 if (definitions.modifiers.isFinal && !resolver.inLoopVariable) { |
57 reporter.reportErrorMessage(node, MessageKind.FINAL_WITHOUT_INITIALIZER); | 56 reporter.reportErrorMessage(node, MessageKind.FINAL_WITHOUT_INITIALIZER); |
(...skipping 10 matching lines...) Expand all Loading... |
68 resolver.addToScope(element); | 67 resolver.addToScope(element); |
69 if (definitions.modifiers.isConst) { | 68 if (definitions.modifiers.isConst) { |
70 addDeferredAction(element, () { | 69 addDeferredAction(element, () { |
71 element.constant = | 70 element.constant = |
72 resolution.resolver.constantCompiler.compileConstant(element); | 71 resolution.resolver.constantCompiler.compileConstant(element); |
73 }); | 72 }); |
74 } | 73 } |
75 } | 74 } |
76 } | 75 } |
77 } | 76 } |
OLD | NEW |