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

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

Issue 2780543002: Handle complicated imports. (Closed)
Patch Set: Fix infinite loop. Created 3 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
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/builder/invalid_type_builder.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.builder; 5 library fasta.builder;
6 6
7 import '../errors.dart' show internalError; 7 import '../errors.dart' show internalError;
8 8
9 import '../messages.dart' show nit;
10
11 export 'class_builder.dart' show ClassBuilder; 9 export 'class_builder.dart' show ClassBuilder;
12 10
13 export 'field_builder.dart' show FieldBuilder; 11 export 'field_builder.dart' show FieldBuilder;
14 12
15 export 'library_builder.dart' show LibraryBuilder; 13 export 'library_builder.dart' show LibraryBuilder;
16 14
17 export 'procedure_builder.dart' show ProcedureBuilder; 15 export 'procedure_builder.dart' show ProcedureBuilder;
18 16
19 export 'type_builder.dart' show TypeBuilder; 17 export 'type_builder.dart' show TypeBuilder;
20 18
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 export 'builtin_type_builder.dart' show BuiltinTypeBuilder; 53 export 'builtin_type_builder.dart' show BuiltinTypeBuilder;
56 54
57 export 'dynamic_type_builder.dart' show DynamicTypeBuilder; 55 export 'dynamic_type_builder.dart' show DynamicTypeBuilder;
58 56
59 export 'void_type_builder.dart' show VoidTypeBuilder; 57 export 'void_type_builder.dart' show VoidTypeBuilder;
60 58
61 export 'function_type_builder.dart' show FunctionTypeBuilder; 59 export 'function_type_builder.dart' show FunctionTypeBuilder;
62 60
63 import 'library_builder.dart' show LibraryBuilder; 61 import 'library_builder.dart' show LibraryBuilder;
64 62
65 import 'invalid_type_builder.dart' show InvalidTypeBuilder;
66
67 abstract class Builder { 63 abstract class Builder {
68 /// Used when multiple things with the same name are declared within the same 64 /// Used when multiple things with the same name are declared within the same
69 /// parent. Only used for declarations, not for scopes. 65 /// parent. Only used for declarations, not for scopes.
70 /// 66 ///
71 // TODO(ahe): Move to member builder or something. Then we can make 67 // TODO(ahe): Move to member builder or something. Then we can make
72 // this a const class. 68 // this a const class.
73 Builder next; 69 Builder next;
74 70
75 /// The values of [parent], [charOffset], and [fileUri] aren't stored. We 71 /// The values of [parent], [charOffset], and [fileUri] aren't stored. We
76 /// need to evaluate the memory impact of doing so, but want to ensure the 72 /// need to evaluate the memory impact of doing so, but want to ensure the
(...skipping 10 matching lines...) Expand all
87 } 83 }
88 84
89 /// Resolve types (lookup names in scope) recorded in this builder and return 85 /// Resolve types (lookup names in scope) recorded in this builder and return
90 /// the number of types resolved. 86 /// the number of types resolved.
91 int resolveTypes(covariant Builder parent) => 0; 87 int resolveTypes(covariant Builder parent) => 0;
92 88
93 /// Resolve constructors (lookup names in scope) recorded in this builder and 89 /// Resolve constructors (lookup names in scope) recorded in this builder and
94 /// return the number of constructors resolved. 90 /// return the number of constructors resolved.
95 int resolveConstructors(covariant Builder parent) => 0; 91 int resolveConstructors(covariant Builder parent) => 0;
96 92
97 /// This builder and [other] has been imported into [library] using [name].
98 ///
99 /// This method handles this case according to the Dart language
100 /// specification.
101 Builder combineAmbiguousImport(
102 String name, Builder other, LibraryBuilder library) {
103 if (other == this) return this;
104 if (other is InvalidTypeBuilder) return other;
105 bool isLocal = false;
106 Builder preferred;
107 Builder hidden;
108 if (library.members[name] == this) {
109 isLocal = true;
110 preferred = this;
111 hidden = other;
112 } else if (getUri(other)?.scheme == "dart" &&
113 getUri(this)?.scheme != "dart") {
114 preferred = this;
115 hidden = other;
116 } else if (getUri(this)?.scheme == "dart" &&
117 getUri(other)?.scheme != "dart") {
118 preferred = other;
119 hidden = this;
120 } else {
121 nit(
122 library.fileUri,
123 -1,
124 "'$name' is imported from both "
125 "'${getUri(this)}' and '${getUri(other)}'.");
126 return library.buildAmbiguousBuilder(name, this, other, charOffset);
127 }
128 if (isLocal) {
129 nit(
130 library.fileUri,
131 -1,
132 "Local definition of '$name' hides imported "
133 "version from '${getUri(other)}'.");
134 } else {
135 nit(
136 library.fileUri,
137 -1,
138 "Import of '$name' "
139 "(from '${getUri(preferred)}') hides imported version from "
140 "'${getUri(hidden)}'.");
141 }
142 return preferred;
143 }
144
145 Builder get parent => null; 93 Builder get parent => null;
146 94
147 bool get isFinal => false; 95 bool get isFinal => false;
148 96
149 bool get isField => false; 97 bool get isField => false;
150 98
151 bool get isRegularMethod => false; 99 bool get isRegularMethod => false;
152 100
153 bool get isGetter => false; 101 bool get isGetter => false;
154 102
(...skipping 16 matching lines...) Expand all
171 bool get isLocal => false; 119 bool get isLocal => false;
172 120
173 bool get isConst => false; 121 bool get isConst => false;
174 122
175 get target => internalError("Unsupported operation $runtimeType."); 123 get target => internalError("Unsupported operation $runtimeType.");
176 124
177 bool get hasProblem => false; 125 bool get hasProblem => false;
178 126
179 String get fullNameForErrors; 127 String get fullNameForErrors;
180 128
181 static Uri getUri(Builder builder) { 129 Uri computeLibraryUri() {
182 if (builder == null) return internalError("Builder is null."); 130 Builder builder = this;
183 while (builder != null) { 131 do {
184 if (builder is LibraryBuilder) return builder.uri; 132 if (builder is LibraryBuilder) return builder.uri;
185 builder = builder.parent; 133 builder = builder.parent;
186 } 134 } while (builder != null);
187 return internalError("No library parent."); 135 return internalError("No library parent.");
188 } 136 }
189 } 137 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/builder/invalid_type_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698