| OLD | NEW |
| 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 AsyncMarker, ProcedureKind; | 7 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; |
| 8 | 8 |
| 9 import '../combinator.dart' show Combinator; | 9 import '../combinator.dart' show Combinator; |
| 10 | 10 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 266 } |
| 267 Map<String, Builder> members = currentDeclaration.members; | 267 Map<String, Builder> members = currentDeclaration.members; |
| 268 Builder existing = members[name]; | 268 Builder existing = members[name]; |
| 269 builder.next = existing; | 269 builder.next = existing; |
| 270 if (builder is PrefixBuilder && existing is PrefixBuilder) { | 270 if (builder is PrefixBuilder && existing is PrefixBuilder) { |
| 271 assert(existing.next == null); | 271 assert(existing.next == null); |
| 272 builder.exports.forEach((String name, Builder builder) { | 272 builder.exports.forEach((String name, Builder builder) { |
| 273 Builder other = existing.exports.putIfAbsent(name, () => builder); | 273 Builder other = existing.exports.putIfAbsent(name, () => builder); |
| 274 if (other != builder) { | 274 if (other != builder) { |
| 275 existing.exports[name] = | 275 existing.exports[name] = |
| 276 other.combineAmbiguousImport(name, builder, this); | 276 buildAmbiguousBuilder(name, other, builder, charOffset); |
| 277 } | 277 } |
| 278 }); | 278 }); |
| 279 return existing; | 279 return existing; |
| 280 } else if (isDuplicatedDefinition(existing, builder)) { | 280 } else if (isDuplicatedDefinition(existing, builder)) { |
| 281 addCompileTimeError(charOffset, "Duplicated definition of '$name'."); | 281 addCompileTimeError(charOffset, "Duplicated definition of '$name'."); |
| 282 } | 282 } |
| 283 return members[name] = builder; | 283 return members[name] = builder; |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool isDuplicatedDefinition(Builder existing, Builder other) { | 286 bool isDuplicatedDefinition(Builder existing, Builder other) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 addBuilder(name, builder, builder.charOffset); | 376 addBuilder(name, builder, builder.charOffset); |
| 377 }); | 377 }); |
| 378 types.addAll(part.types); | 378 types.addAll(part.types); |
| 379 constructorReferences.addAll(part.constructorReferences); | 379 constructorReferences.addAll(part.constructorReferences); |
| 380 part.partOfLibrary = this; | 380 part.partOfLibrary = this; |
| 381 // TODO(ahe): Include metadata from part? | 381 // TODO(ahe): Include metadata from part? |
| 382 } | 382 } |
| 383 | 383 |
| 384 void buildInitialScopes() { | 384 void buildInitialScopes() { |
| 385 members.forEach(addToExportScope); | 385 members.forEach(addToExportScope); |
| 386 members.forEach(addToScope); | 386 members.forEach((String name, Builder member) { |
| 387 addToScope(name, member, member.charOffset, false); |
| 388 }); |
| 387 } | 389 } |
| 388 | 390 |
| 389 void addImportsToScope() { | 391 void addImportsToScope() { |
| 390 bool explicitCoreImport = this == loader.coreLibrary; | 392 bool explicitCoreImport = this == loader.coreLibrary; |
| 391 for (Import import in imports) { | 393 for (Import import in imports) { |
| 392 if (import.imported == loader.coreLibrary) { | 394 if (import.imported == loader.coreLibrary) { |
| 393 explicitCoreImport = true; | 395 explicitCoreImport = true; |
| 394 } | 396 } |
| 395 import.finalizeImports(this); | 397 import.finalizeImports(this); |
| 396 } | 398 } |
| 397 if (!explicitCoreImport) { | 399 if (!explicitCoreImport) { |
| 398 loader.coreLibrary.exports.forEach(addToScope); | 400 loader.coreLibrary.exports.forEach((String name, Builder member) { |
| 401 addToScope(name, member, -1, true); |
| 402 }); |
| 399 } | 403 } |
| 400 } | 404 } |
| 401 | 405 |
| 402 void addToScope(String name, Builder member) { | 406 @override |
| 407 void addToScope(String name, Builder member, int charOffset, bool isImport) { |
| 403 Builder existing = scope.lookup(name, member.charOffset, fileUri); | 408 Builder existing = scope.lookup(name, member.charOffset, fileUri); |
| 404 if (existing != null) { | 409 if (existing != null) { |
| 405 if (existing != member) { | 410 if (existing != member) { |
| 406 scope.local[name] = existing.combineAmbiguousImport(name, member, this); | 411 scope.local[name] = buildAmbiguousBuilder( |
| 412 name, existing, member, charOffset, |
| 413 isImport: isImport); |
| 407 } | 414 } |
| 408 // TODO(ahe): handle duplicated names. | |
| 409 } else { | 415 } else { |
| 410 scope.local[name] = member; | 416 scope.local[name] = member; |
| 411 } | 417 } |
| 412 } | 418 } |
| 413 | 419 |
| 414 /// Returns true if the export scope was modified. | 420 /// Returns true if the export scope was modified. |
| 415 bool addToExportScope(String name, Builder member) { | 421 bool addToExportScope(String name, Builder member) { |
| 416 if (name.startsWith("_")) return false; | 422 if (name.startsWith("_")) return false; |
| 417 if (member is PrefixBuilder) return false; | 423 if (member is PrefixBuilder) return false; |
| 418 Builder existing = exports[name]; | 424 Builder existing = exports[name]; |
| 419 if (existing == member) return false; | 425 if (existing == member) return false; |
| 420 if (existing != null) { | 426 if (existing != null) { |
| 421 exports[name] = buildAmbiguousBuilder(name, existing, member, -1); | 427 Builder result = |
| 428 buildAmbiguousBuilder(name, existing, member, -1, isExport: true); |
| 429 exports[name] = result; |
| 430 return result != existing; |
| 422 } else { | 431 } else { |
| 423 exports[name] = member; | 432 exports[name] = member; |
| 424 } | 433 } |
| 425 return true; | 434 return true; |
| 426 } | 435 } |
| 427 | 436 |
| 428 int resolveTypes(_) { | 437 int resolveTypes(_) { |
| 429 int typeCount = types.length; | 438 int typeCount = types.length; |
| 430 for (T t in types) { | 439 for (T t in types) { |
| 431 t.resolveIn(scope); | 440 t.resolveIn(scope); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } | 536 } |
| 528 | 537 |
| 529 /// Called to register [procedure] as a factory whose types are collected in | 538 /// Called to register [procedure] as a factory whose types are collected in |
| 530 /// [factoryDeclaration]. Later, once the class has been built, we can | 539 /// [factoryDeclaration]. Later, once the class has been built, we can |
| 531 /// synthesize type variables on the factory matching the class'. | 540 /// synthesize type variables on the factory matching the class'. |
| 532 void addFactoryDeclaration( | 541 void addFactoryDeclaration( |
| 533 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 542 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
| 534 factoryDeclarations[procedure] = factoryDeclaration; | 543 factoryDeclarations[procedure] = factoryDeclaration; |
| 535 } | 544 } |
| 536 } | 545 } |
| OLD | NEW |