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

Side by Side Diff: pkg/front_end/lib/src/fasta/builder/constructor_reference_builder.dart

Issue 2996063002: Implement type arguments in redirecting factories.
Patch Set: Address Johnni's comments. Created 3 years, 3 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
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/fasta_codes_generated.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.constructor_reference_builder; 5 library fasta.constructor_reference_builder;
6 6
7 import 'builder.dart' 7 import 'builder.dart'
8 show 8 show
9 Builder, 9 Builder,
10 ClassBuilder, 10 ClassBuilder,
11 LibraryBuilder, 11 LibraryBuilder,
12 PrefixBuilder, 12 PrefixBuilder,
13 Scope, 13 Scope,
14 TypeBuilder; 14 TypeBuilder;
15 15
16 import '../messages.dart' show templateConstructorNotFound, warning; 16 import '../messages.dart'
17 show
18 templateClassNotFound,
19 templateConstructorNotFound,
20 templateNotAConstructor,
21 warning;
17 22
18 class ConstructorReferenceBuilder extends Builder { 23 class ConstructorReferenceBuilder extends Builder {
19 final String name; 24 final String name;
20 25
21 final List<TypeBuilder> typeArguments; 26 final List<TypeBuilder> typeArguments;
22 27
23 /// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`. 28 /// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`.
24 final String suffix; 29 final String suffix;
25 30
26 Builder target; 31 Builder target;
27 32
33 ClassBuilder classBuilder;
34
28 ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix, 35 ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix,
29 Builder parent, int charOffset) 36 Builder parent, int charOffset)
30 : super(parent, charOffset, parent.fileUri); 37 : super(parent, charOffset, parent.fileUri);
31 38
32 String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}"; 39 String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}";
33 40
34 void resolveIn(Scope scope, LibraryBuilder accessingLibrary) { 41 void resolveIn(Scope scope, LibraryBuilder accessingLibrary) {
42 List<String> identifiers;
35 int index = name.indexOf("."); 43 int index = name.indexOf(".");
44 if (index == -1) {
45 if (suffix == null) {
46 identifiers = <String>[name];
47 } else {
48 identifiers = <String>[name, suffix];
49 }
50 } else {
51 String first = name.substring(0, index);
52 String second = name.substring(index + 1);
53 if (suffix == null) {
54 identifiers = <String>[first, second];
55 } else {
56 identifiers = <String>[first, second, suffix];
57 }
58 }
59
36 Builder builder; 60 Builder builder;
37 if (index == -1) { 61 bool isConstructor = false;
38 builder = scope.lookup(name, charOffset, fileUri); 62 ClassBuilder cls;
39 } else { 63 for (String identifier in identifiers) {
40 String prefix = name.substring(0, index); 64 isConstructor = false;
41 String middle = name.substring(index + 1); 65 if (builder == null) {
42 builder = scope.lookup(prefix, charOffset, fileUri); 66 builder = scope.lookup(identifier, charOffset, fileUri);
43 if (builder is PrefixBuilder) { 67 if (builder == null) {
44 PrefixBuilder prefix = builder; 68 warning(templateClassNotFound.withArguments(identifier), charOffset,
45 builder = prefix.lookup(middle, charOffset, fileUri); 69 fileUri);
46 } else if (builder is ClassBuilder) {
47 ClassBuilder cls = builder;
48 builder = cls.findConstructorOrFactory(
49 middle, charOffset, fileUri, accessingLibrary);
50 if (suffix == null) {
51 target = builder;
52 return; 70 return;
53 } 71 }
72 } else if (builder is PrefixBuilder) {
73 PrefixBuilder prefix = builder;
74 builder = prefix.lookup(identifier, charOffset, fileUri);
75 if (builder == null) {
76 warning(templateClassNotFound.withArguments(identifier), charOffset,
77 fileUri);
78 return;
79 }
80 } else if (builder is ClassBuilder) {
81 cls = builder;
82 builder = cls.findConstructorOrFactory(
83 identifier, charOffset, fileUri, accessingLibrary);
84 if (builder == null) {
85 warning(templateConstructorNotFound.withArguments(identifier),
86 charOffset, fileUri);
87 return;
88 }
89 isConstructor = true;
90 } else {
91 warning(templateNotAConstructor.withArguments(fullNameForErrors),
92 charOffset, fileUri);
93 return;
54 } 94 }
55 } 95 }
96
56 if (builder is ClassBuilder) { 97 if (builder is ClassBuilder) {
57 target = builder.findConstructorOrFactory( 98 cls = builder;
58 suffix ?? "", charOffset, fileUri, accessingLibrary); 99 builder = cls.findConstructorOrFactory(
100 "", charOffset, fileUri, accessingLibrary);
101 if (builder == null) {
102 warning(templateConstructorNotFound.withArguments(fullNameForErrors),
103 charOffset, fileUri);
104 return;
105 }
106 isConstructor = true;
59 } 107 }
60 if (target == null) { 108
61 warning(templateConstructorNotFound.withArguments(fullNameForErrors), 109 if (isConstructor) {
110 target = builder;
111 classBuilder = cls;
112 } else {
113 warning(templateNotAConstructor.withArguments(fullNameForErrors),
62 charOffset, fileUri); 114 charOffset, fileUri);
63 } 115 }
64 } 116 }
65 } 117 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/fasta_codes_generated.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698