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 '../compiler.dart' show Compiler; | 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 '../util/util.dart' show Link; | 12 import '../util/util.dart' show Link; |
13 | 13 |
14 import 'members.dart' show ResolverVisitor; | 14 import 'members.dart' show ResolverVisitor; |
15 import 'registry.dart' show ResolutionRegistry; | 15 import 'registry.dart' show ResolutionRegistry; |
16 import 'resolution_common.dart' show CommonResolverVisitor; | 16 import 'resolution_common.dart' show CommonResolverVisitor; |
17 import 'scope.dart' show VariableDefinitionScope; | 17 import 'scope.dart' show VariableDefinitionScope; |
18 | 18 |
19 class VariableDefinitionsVisitor extends CommonResolverVisitor<Identifier> { | 19 class VariableDefinitionsVisitor extends CommonResolverVisitor<Identifier> { |
20 VariableDefinitions definitions; | 20 VariableDefinitions definitions; |
21 ResolverVisitor resolver; | 21 ResolverVisitor resolver; |
22 VariableList variables; | 22 VariableList variables; |
23 | 23 |
24 VariableDefinitionsVisitor( | 24 VariableDefinitionsVisitor( |
25 Compiler compiler, this.definitions, this.resolver, this.variables) | 25 Resolution resolution, this.definitions, this.resolver, this.variables) |
26 : super(compiler) {} | 26 : super(resolution); |
27 | 27 |
28 ResolutionRegistry get registry => resolver.registry; | 28 ResolutionRegistry get registry => resolver.registry; |
29 | 29 |
30 Identifier visitSendSet(SendSet node) { | 30 Identifier visitSendSet(SendSet node) { |
31 assert(node.arguments.tail.isEmpty); // Sanity check | 31 assert(node.arguments.tail.isEmpty); // Sanity check |
32 Identifier identifier = node.selector; | 32 Identifier identifier = node.selector; |
33 String name = identifier.source; | 33 String name = identifier.source; |
34 VariableDefinitionScope scope = | 34 VariableDefinitionScope scope = |
35 new VariableDefinitionScope(resolver.scope, name); | 35 new VariableDefinitionScope(resolver.scope, name); |
36 resolver.visitIn(node.arguments.head, scope); | 36 resolver.visitIn(node.arguments.head, scope); |
37 if (scope.variableReferencedInInitializer) { | 37 if (scope.variableReferencedInInitializer) { |
38 reporter.reportErrorMessage(identifier, | 38 reporter.reportErrorMessage(identifier, |
39 MessageKind.REFERENCE_IN_INITIALIZATION, {'variableName': name}); | 39 MessageKind.REFERENCE_IN_INITIALIZATION, {'variableName': name}); |
40 } | 40 } |
41 return identifier; | 41 return identifier; |
42 } | 42 } |
43 | 43 |
44 Identifier visitIdentifier(Identifier node) { | 44 Identifier visitIdentifier(Identifier node) { |
45 // The variable is initialized to null. | 45 // The variable is initialized to null. |
46 // TODO(johnniwinther): Register a feature instead. | 46 // TODO(johnniwinther): Register a feature instead. |
47 registry.registerTypeUse( | 47 registry.registerTypeUse( |
48 new TypeUse.instantiation(compiler.coreTypes.nullType)); | 48 new TypeUse.instantiation(resolution.coreTypes.nullType)); |
49 if (definitions.modifiers.isConst) { | 49 if (definitions.modifiers.isConst) { |
50 if (resolver.inLoopVariable) { | 50 if (resolver.inLoopVariable) { |
51 reporter.reportErrorMessage(node, MessageKind.CONST_LOOP_VARIABLE); | 51 reporter.reportErrorMessage(node, MessageKind.CONST_LOOP_VARIABLE); |
52 } else { | 52 } else { |
53 reporter.reportErrorMessage( | 53 reporter.reportErrorMessage( |
54 node, MessageKind.CONST_WITHOUT_INITIALIZER); | 54 node, MessageKind.CONST_WITHOUT_INITIALIZER); |
55 } | 55 } |
56 } | 56 } |
57 if (definitions.modifiers.isFinal && !resolver.inLoopVariable) { | 57 if (definitions.modifiers.isFinal && !resolver.inLoopVariable) { |
58 reporter.reportErrorMessage(node, MessageKind.FINAL_WITHOUT_INITIALIZER); | 58 reporter.reportErrorMessage(node, MessageKind.FINAL_WITHOUT_INITIALIZER); |
59 } | 59 } |
60 return node; | 60 return node; |
61 } | 61 } |
62 | 62 |
63 visitNodeList(NodeList node) { | 63 visitNodeList(NodeList node) { |
64 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { | 64 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { |
65 Identifier name = visit(link.head); | 65 Identifier name = visit(link.head); |
66 LocalVariableElementX element = new LocalVariableElementX( | 66 LocalVariableElementX element = new LocalVariableElementX( |
67 name.source, resolver.enclosingElement, variables, name.token); | 67 name.source, resolver.enclosingElement, variables, name.token); |
68 resolver.defineLocalVariable(link.head, element); | 68 resolver.defineLocalVariable(link.head, element); |
69 resolver.addToScope(element); | 69 resolver.addToScope(element); |
70 if (definitions.modifiers.isConst) { | 70 if (definitions.modifiers.isConst) { |
71 compiler.enqueuer.resolution.addDeferredAction(element, () { | 71 addDeferredAction(element, () { |
72 element.constant = | 72 element.constant = |
73 compiler.resolver.constantCompiler.compileConstant(element); | 73 resolution.resolver.constantCompiler.compileConstant(element); |
74 }); | 74 }); |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 } | 78 } |
OLD | NEW |