Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: pkg/compiler/lib/src/resolution/variables.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8 import '../compiler.dart' show Compiler;
9 Compiler; 9 import '../elements/modelx.dart' show LocalVariableElementX, VariableList;
10 import '../elements/modelx.dart' show
11 LocalVariableElementX,
12 VariableList;
13 import '../tree/tree.dart'; 10 import '../tree/tree.dart';
14 import '../universe/use.dart' show 11 import '../universe/use.dart' show TypeUse;
15 TypeUse; 12 import '../util/util.dart' show Link;
16 import '../util/util.dart' show
17 Link;
18 13
19 import 'members.dart' show 14 import 'members.dart' show ResolverVisitor;
20 ResolverVisitor; 15 import 'registry.dart' show ResolutionRegistry;
21 import 'registry.dart' show 16 import 'resolution_common.dart' show CommonResolverVisitor;
22 ResolutionRegistry; 17 import 'scope.dart' show VariableDefinitionScope;
23 import 'resolution_common.dart' show
24 CommonResolverVisitor;
25 import 'scope.dart' show
26 VariableDefinitionScope;
27 18
28 class VariableDefinitionsVisitor extends CommonResolverVisitor<Identifier> { 19 class VariableDefinitionsVisitor extends CommonResolverVisitor<Identifier> {
29 VariableDefinitions definitions; 20 VariableDefinitions definitions;
30 ResolverVisitor resolver; 21 ResolverVisitor resolver;
31 VariableList variables; 22 VariableList variables;
32 23
33 VariableDefinitionsVisitor(Compiler compiler, 24 VariableDefinitionsVisitor(
34 this.definitions, 25 Compiler compiler, this.definitions, this.resolver, this.variables)
35 this.resolver, 26 : super(compiler) {}
36 this.variables)
37 : super(compiler) {
38 }
39 27
40 ResolutionRegistry get registry => resolver.registry; 28 ResolutionRegistry get registry => resolver.registry;
41 29
42 Identifier visitSendSet(SendSet node) { 30 Identifier visitSendSet(SendSet node) {
43 assert(node.arguments.tail.isEmpty); // Sanity check 31 assert(node.arguments.tail.isEmpty); // Sanity check
44 Identifier identifier = node.selector; 32 Identifier identifier = node.selector;
45 String name = identifier.source; 33 String name = identifier.source;
46 VariableDefinitionScope scope = 34 VariableDefinitionScope scope =
47 new VariableDefinitionScope(resolver.scope, name); 35 new VariableDefinitionScope(resolver.scope, name);
48 resolver.visitIn(node.arguments.head, scope); 36 resolver.visitIn(node.arguments.head, scope);
49 if (scope.variableReferencedInInitializer) { 37 if (scope.variableReferencedInInitializer) {
50 reporter.reportErrorMessage( 38 reporter.reportErrorMessage(identifier,
51 identifier, MessageKind.REFERENCE_IN_INITIALIZATION, 39 MessageKind.REFERENCE_IN_INITIALIZATION, {'variableName': name});
52 {'variableName': name});
53 } 40 }
54 return identifier; 41 return identifier;
55 } 42 }
56 43
57 Identifier visitIdentifier(Identifier node) { 44 Identifier visitIdentifier(Identifier node) {
58 // The variable is initialized to null. 45 // The variable is initialized to null.
59 // TODO(johnniwinther): Register a feature instead. 46 // TODO(johnniwinther): Register a feature instead.
60 registry.registerTypeUse( 47 registry.registerTypeUse(
61 new TypeUse.instantiation(compiler.coreTypes.nullType)); 48 new TypeUse.instantiation(compiler.coreTypes.nullType));
62 if (definitions.modifiers.isConst) { 49 if (definitions.modifiers.isConst) {
63 if (resolver.inLoopVariable) { 50 if (resolver.inLoopVariable) {
64 reporter.reportErrorMessage( 51 reporter.reportErrorMessage(node, MessageKind.CONST_LOOP_VARIABLE);
65 node, MessageKind.CONST_LOOP_VARIABLE);
66 } else { 52 } else {
67 reporter.reportErrorMessage( 53 reporter.reportErrorMessage(
68 node, MessageKind.CONST_WITHOUT_INITIALIZER); 54 node, MessageKind.CONST_WITHOUT_INITIALIZER);
69 } 55 }
70 } 56 }
71 if (definitions.modifiers.isFinal && 57 if (definitions.modifiers.isFinal && !resolver.inLoopVariable) {
72 !resolver.inLoopVariable) { 58 reporter.reportErrorMessage(node, MessageKind.FINAL_WITHOUT_INITIALIZER);
73 reporter.reportErrorMessage(
74 node, MessageKind.FINAL_WITHOUT_INITIALIZER);
75 } 59 }
76 return node; 60 return node;
77 } 61 }
78 62
79 visitNodeList(NodeList node) { 63 visitNodeList(NodeList node) {
80 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { 64 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) {
81 Identifier name = visit(link.head); 65 Identifier name = visit(link.head);
82 LocalVariableElementX element = new LocalVariableElementX( 66 LocalVariableElementX element = new LocalVariableElementX(
83 name.source, resolver.enclosingElement, 67 name.source, resolver.enclosingElement, variables, name.token);
84 variables, name.token);
85 resolver.defineLocalVariable(link.head, element); 68 resolver.defineLocalVariable(link.head, element);
86 resolver.addToScope(element); 69 resolver.addToScope(element);
87 if (definitions.modifiers.isConst) { 70 if (definitions.modifiers.isConst) {
88 compiler.enqueuer.resolution.addDeferredAction(element, () { 71 compiler.enqueuer.resolution.addDeferredAction(element, () {
89 element.constant = 72 element.constant =
90 compiler.resolver.constantCompiler.compileConstant(element); 73 compiler.resolver.constantCompiler.compileConstant(element);
91 }); 74 });
92 } 75 }
93 } 76 }
94 } 77 }
95 } 78 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/typedefs.dart ('k') | pkg/compiler/lib/src/scanner/array_based_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698