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

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

Issue 2691523002: Ensure locations are always provided, but don't store them yet. (Closed)
Patch Set: Address comments. Created 3 years, 10 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) 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.source_library_builder; 5 library fasta.source_library_builder;
6 6
7 import 'package:kernel/ast.dart' show 7 import 'package:kernel/ast.dart' show
8 AsyncMarker, 8 AsyncMarker,
9 ProcedureKind; 9 ProcedureKind;
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 String partOf; 68 String partOf;
69 69
70 List<MetadataBuilder> metadata; 70 List<MetadataBuilder> metadata;
71 71
72 /// The current declaration that is being built. When we start parsing a 72 /// The current declaration that is being built. When we start parsing a
73 /// declaration (class, method, and so on), we don't have enough information 73 /// declaration (class, method, and so on), we don't have enough information
74 /// to create a builder and this object records its members and types until, 74 /// to create a builder and this object records its members and types until,
75 /// for example, [addClass] is called. 75 /// for example, [addClass] is called.
76 DeclarationBuilder<T> currentDeclaration; 76 DeclarationBuilder<T> currentDeclaration;
77 77
78 SourceLibraryBuilder(this.loader, this.fileUri) { 78 SourceLibraryBuilder(this.loader, Uri fileUri)
79 : fileUri = fileUri, super(fileUri) {
79 currentDeclaration = libraryDeclaration; 80 currentDeclaration = libraryDeclaration;
80 } 81 }
81 82
82 Uri get uri; 83 Uri get uri;
83 84
84 bool get isPart => partOf != null; 85 bool get isPart => partOf != null;
85 86
86 Map<String, Builder> get members => libraryDeclaration.members; 87 Map<String, Builder> get members => libraryDeclaration.members;
87 88
88 List<T> get types => libraryDeclaration.types; 89 List<T> get types => libraryDeclaration.types;
89 90
90 /// When parsing a class, this returns a map of its members (that have been 91 /// When parsing a class, this returns a map of its members (that have been
91 /// parsed so far). 92 /// parsed so far).
92 Map<String, MemberBuilder> get classMembers { 93 Map<String, MemberBuilder> get classMembers {
93 assert(currentDeclaration.parent == libraryDeclaration); 94 assert(currentDeclaration.parent == libraryDeclaration);
94 return currentDeclaration.members; 95 return currentDeclaration.members;
95 } 96 }
96 97
97 List<T> get declarationTypes { 98 List<T> get declarationTypes {
98 assert(currentDeclaration.parent == libraryDeclaration); 99 assert(currentDeclaration.parent == libraryDeclaration);
99 return currentDeclaration.types; 100 return currentDeclaration.types;
100 } 101 }
101 102
102 T addNamedType(String name, List<T> arguments); 103 T addNamedType(String name, List<T> arguments, int charOffset);
103 104
104 T addMixinApplication(T supertype, List<T> mixins); 105 T addMixinApplication(T supertype, List<T> mixins, int charOffset);
105 106
106 T addType(T type) { 107 T addType(T type) {
107 currentDeclaration.addType(type); 108 currentDeclaration.addType(type);
108 return type; 109 return type;
109 } 110 }
110 111
111 T addVoidType(); 112 T addVoidType(int charOffset);
112 113
113 ConstructorReferenceBuilder addConstructorReference( 114 ConstructorReferenceBuilder addConstructorReference(
114 String name, List<T> typeArguments, String suffix) { 115 String name, List<T> typeArguments, String suffix, int charOffset) {
115 ConstructorReferenceBuilder ref = 116 ConstructorReferenceBuilder ref = new ConstructorReferenceBuilder(name,
116 new ConstructorReferenceBuilder(name, typeArguments, suffix); 117 typeArguments, suffix, this, charOffset);
117 constructorReferences.add(ref); 118 constructorReferences.add(ref);
118 return ref; 119 return ref;
119 } 120 }
120 121
121 void beginNestedDeclaration({bool hasMembers}) { 122 void beginNestedDeclaration({bool hasMembers}) {
122 currentDeclaration = 123 currentDeclaration =
123 new DeclarationBuilder(<String, MemberBuilder>{}, currentDeclaration); 124 new DeclarationBuilder(<String, MemberBuilder>{}, currentDeclaration);
124 } 125 }
125 126
126 DeclarationBuilder<T> endNestedDeclaration() { 127 DeclarationBuilder<T> endNestedDeclaration() {
127 DeclarationBuilder<T> previous = currentDeclaration; 128 DeclarationBuilder<T> previous = currentDeclaration;
128 currentDeclaration = currentDeclaration.parent; 129 currentDeclaration = currentDeclaration.parent;
129 return previous; 130 return previous;
130 } 131 }
131 132
132 Uri resolve(String path) => uri.resolve(path); 133 Uri resolve(String path) => uri.resolve(path);
133 134
134 void addExport(List<MetadataBuilder> metadata, String uri, 135 void addExport(List<MetadataBuilder> metadata, String uri,
135 Unhandled conditionalUris, List<Combinator> combinators) { 136 Unhandled conditionalUris, List<Combinator> combinators, int charOffset) {
136 loader.read(resolve(uri)).addExporter(this, combinators); 137 loader.read(resolve(uri)).addExporter(this, combinators, charOffset);
137 } 138 }
138 139
139 void addImport(List<MetadataBuilder> metadata, String uri, 140 void addImport(List<MetadataBuilder> metadata, String uri,
140 Unhandled conditionalUris, String prefix, List<Combinator> combinators, 141 Unhandled conditionalUris, String prefix, List<Combinator> combinators,
141 bool deferred) { 142 bool deferred, int charOffset, int prefixCharOffset) {
142 imports.add(new Import(loader.read(resolve(uri)), prefix, combinators)); 143 imports.add(new Import(this, loader.read(resolve(uri)), prefix, combinators,
144 charOffset, prefixCharOffset));
143 } 145 }
144 146
145 void addPart(List<MetadataBuilder> metadata, String path) { 147 void addPart(List<MetadataBuilder> metadata, String path) {
146 Uri resolvedUri; 148 Uri resolvedUri;
147 Uri newFileUri; 149 Uri newFileUri;
148 if (uri.scheme == "dart") { 150 if (uri.scheme == "dart") {
149 resolvedUri = new Uri(scheme: "dart", path: "${uri.path}/$path"); 151 resolvedUri = new Uri(scheme: "dart", path: "${uri.path}/$path");
150 newFileUri = fileUri.resolve(path); 152 newFileUri = fileUri.resolve(path);
151 } else { 153 } else {
152 resolvedUri = uri.resolve(path); 154 resolvedUri = uri.resolve(path);
153 newFileUri = fileUri.resolve(path); 155 newFileUri = fileUri.resolve(path);
154 } 156 }
155 parts.add(loader.read(resolvedUri, newFileUri)); 157 parts.add(loader.read(resolvedUri, newFileUri));
156 } 158 }
157 159
158 void addPartOf(List<MetadataBuilder> metadata, String name) { 160 void addPartOf(List<MetadataBuilder> metadata, String name) {
159 partOf = name; 161 partOf = name;
160 } 162 }
161 163
162 ClassBuilder addClass(List<MetadataBuilder> metadata, 164 ClassBuilder addClass(List<MetadataBuilder> metadata,
163 int modifiers, String name, 165 int modifiers, String name,
164 List<TypeVariableBuilder> typeVariables, T supertype, 166 List<TypeVariableBuilder> typeVariables, T supertype,
165 List<T> interfaces); 167 List<T> interfaces, int charOffset);
166 168
167 NamedMixinApplicationBuilder addNamedMixinApplication( 169 NamedMixinApplicationBuilder addNamedMixinApplication(
168 List<MetadataBuilder> metadata, String name, 170 List<MetadataBuilder> metadata, String name,
169 List<TypeVariableBuilder> typeVariables, int modifiers, 171 List<TypeVariableBuilder> typeVariables, int modifiers,
170 T mixinApplication, List<T> interfaces); 172 T mixinApplication, List<T> interfaces, int charOffset);
171 173
172 FieldBuilder addField(List<MetadataBuilder> metadata, 174 FieldBuilder addField(List<MetadataBuilder> metadata,
173 int modifiers, T type, String name); 175 int modifiers, T type, String name, int charOffset);
174 176
175 void addFields(List<MetadataBuilder> metadata, int modifiers, 177 void addFields(List<MetadataBuilder> metadata, int modifiers,
176 T type, List<String> names) { 178 T type, List<String> names) {
177 for (String name in names) { 179 for (String name in names) {
178 addField(metadata, modifiers, type, name); 180 // TODO(ahe): Get charOffset of name.
181 addField(metadata, modifiers, type, name, -1);
179 } 182 }
180 } 183 }
181 184
182 ProcedureBuilder addProcedure(List<MetadataBuilder> metadata, 185 ProcedureBuilder addProcedure(List<MetadataBuilder> metadata,
183 int modifiers, T returnType, String name, 186 int modifiers, T returnType, String name,
184 List<TypeVariableBuilder> typeVariables, 187 List<TypeVariableBuilder> typeVariables,
185 List<FormalParameterBuilder> formals, AsyncMarker asyncModifier, 188 List<FormalParameterBuilder> formals, AsyncMarker asyncModifier,
186 ProcedureKind kind); 189 ProcedureKind kind, int charOffset);
187 190
188 EnumBuilder addEnum(List<MetadataBuilder> metadata, String name, 191 EnumBuilder addEnum(List<MetadataBuilder> metadata, String name,
189 List<String> constants); 192 List<String> constants, int charOffset);
190 193
191 FunctionTypeAliasBuilder addFunctionTypeAlias(List<MetadataBuilder> metadata, 194 FunctionTypeAliasBuilder addFunctionTypeAlias(List<MetadataBuilder> metadata,
192 T returnType, String name, 195 T returnType, String name,
193 List<TypeVariableBuilder> typeVariables, 196 List<TypeVariableBuilder> typeVariables,
194 List<FormalParameterBuilder> formals); 197 List<FormalParameterBuilder> formals, int charOffset);
195 198
196 void addFactoryMethod(List<MetadataBuilder> metadata, 199 void addFactoryMethod(List<MetadataBuilder> metadata,
197 ConstructorReferenceBuilder name, List<FormalParameterBuilder> formals, 200 ConstructorReferenceBuilder name, List<FormalParameterBuilder> formals,
198 AsyncMarker asyncModifier, ConstructorReferenceBuilder redirectionTarget); 201 AsyncMarker asyncModifier, ConstructorReferenceBuilder redirectionTarget,
202 int charOffset);
199 203
200 FormalParameterBuilder addFormalParameter( 204 FormalParameterBuilder addFormalParameter(
201 List<MetadataBuilder> metadata, int modifiers, 205 List<MetadataBuilder> metadata, int modifiers,
202 T type, String name, bool hasThis); 206 T type, String name, bool hasThis, int charOffset);
203 207
204 TypeVariableBuilder addTypeVariable(String name, T bound); 208 TypeVariableBuilder addTypeVariable(String name, T bound, int charOffset);
205 209
206 Builder addBuilder(String name, Builder builder) { 210 Builder addBuilder(String name, Builder builder) {
207 // TODO(ahe): Set the parent correctly here. Could then change the 211 // TODO(ahe): Set the parent correctly here. Could then change the
208 // implementation of MemberBuilder.isTopLevel to test explicitly for a 212 // implementation of MemberBuilder.isTopLevel to test explicitly for a
209 // LibraryBuilder. 213 // LibraryBuilder.
210 if (currentDeclaration == libraryDeclaration) { 214 if (currentDeclaration == libraryDeclaration) {
211 if (builder is MemberBuilder) { 215 if (builder is MemberBuilder) {
212 builder.parent = this; 216 builder.parent = this;
213 } else if (builder is TypeDeclarationBuilder) { 217 } else if (builder is TypeDeclarationBuilder) {
214 builder.parent = this; 218 builder.parent = this;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 explicitCoreImport = true; 307 explicitCoreImport = true;
304 } 308 }
305 import.finalizeImports(this); 309 import.finalizeImports(this);
306 } 310 }
307 if (!explicitCoreImport) { 311 if (!explicitCoreImport) {
308 loader.coreLibrary.exports.forEach(addToScope); 312 loader.coreLibrary.exports.forEach(addToScope);
309 } 313 }
310 } 314 }
311 315
312 void addToScope(String name, Builder member) { 316 void addToScope(String name, Builder member) {
313 Builder existing = scope.lookup(name); 317 Builder existing = scope.lookup(name, member.charOffset, fileUri);
314 if (existing != null) { 318 if (existing != null) {
315 if (existing != member) { 319 if (existing != member) {
316 scope.local[name] = existing.combineAmbiguousImport(name, member, this); 320 scope.local[name] = existing.combineAmbiguousImport(name, member, this);
317 } 321 }
318 // TODO(ahe): handle duplicated names. 322 // TODO(ahe): handle duplicated names.
319 } else { 323 } else {
320 scope.local[name] = member; 324 scope.local[name] = member;
321 } 325 }
322 } 326 }
323 327
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // parent declaration. 418 // parent declaration.
415 parent.addType(type); 419 parent.addType(type);
416 } else { 420 } else {
417 type.bind(builder); 421 type.bind(builder);
418 } 422 }
419 } 423 }
420 } 424 }
421 types.clear(); 425 types.clear();
422 } 426 }
423 } 427 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/source_class_builder.dart ('k') | pkg/front_end/lib/src/fasta/util/relativize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698