mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:29:48 +00:00
Use Map(s) for top-level declarations.
This would help to implement 'get sources by name' that Paul pointed out in a previous CL. R=brianwilkerson@google.com, paulberry@google.com BUG= Review URL: https://codereview.chromium.org/2543263002 .
This commit is contained in:
parent
8e2011aa21
commit
d6e89bf3a2
|
@ -101,8 +101,8 @@ class FileState {
|
||||||
Set<FileState> _transitiveFiles;
|
Set<FileState> _transitiveFiles;
|
||||||
String _transitiveSignature;
|
String _transitiveSignature;
|
||||||
|
|
||||||
List<TopLevelDeclaration> _topLevelDeclarations;
|
Map<String, TopLevelDeclaration> _topLevelDeclarations;
|
||||||
List<TopLevelDeclaration> _exportedTopLevelDeclarations;
|
Map<String, TopLevelDeclaration> _exportedTopLevelDeclarations;
|
||||||
|
|
||||||
FileState._(this._fsState, this.path, this.uri, this.source);
|
FileState._(this._fsState, this.path, this.uri, this.source);
|
||||||
|
|
||||||
|
@ -133,47 +133,43 @@ class FileState {
|
||||||
List<FileState> get exportedFiles => _exportedFiles;
|
List<FileState> get exportedFiles => _exportedFiles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return [TopLevelDeclaration]s exported from the this library file.
|
* Return [TopLevelDeclaration]s exported from the this library file. The
|
||||||
|
* keys to the map are names of declarations.
|
||||||
*/
|
*/
|
||||||
List<TopLevelDeclaration> get exportedTopLevelDeclarations {
|
Map<String, TopLevelDeclaration> get exportedTopLevelDeclarations {
|
||||||
if (_exportedTopLevelDeclarations == null) {
|
if (_exportedTopLevelDeclarations == null) {
|
||||||
_exportedTopLevelDeclarations = <TopLevelDeclaration>[];
|
_exportedTopLevelDeclarations = <String, TopLevelDeclaration>{};
|
||||||
|
|
||||||
Set<FileState> seenLibraries = new Set<FileState>();
|
Set<FileState> seenLibraries = new Set<FileState>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute [TopLevelDeclaration]s exported from the [library].
|
* Compute [TopLevelDeclaration]s exported from the [library].
|
||||||
*/
|
*/
|
||||||
List<TopLevelDeclaration> computeExported(FileState library) {
|
Map<String, TopLevelDeclaration> computeExported(FileState library) {
|
||||||
var declarations = <String, TopLevelDeclaration>{};
|
var declarations = <String, TopLevelDeclaration>{};
|
||||||
if (seenLibraries.add(library)) {
|
if (seenLibraries.add(library)) {
|
||||||
// Append the library declarations.
|
// Append the exported declarations.
|
||||||
for (TopLevelDeclaration t in library.topLevelDeclarations) {
|
for (int i = 0; i < library._exportedFiles.length; i++) {
|
||||||
|
Map<String, TopLevelDeclaration> exported =
|
||||||
|
computeExported(library._exportedFiles[i]);
|
||||||
|
for (TopLevelDeclaration t in exported.values) {
|
||||||
|
if (library._exportFilters[i].accepts(t.name)) {
|
||||||
declarations[t.name] = t;
|
declarations[t.name] = t;
|
||||||
}
|
}
|
||||||
for (FileState part in library.partedFiles) {
|
|
||||||
for (TopLevelDeclaration t in part.topLevelDeclarations) {
|
|
||||||
declarations[t.name] = t;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the exported declarations.
|
// Append the library declarations.
|
||||||
for (int i = 0; i < library._exportedFiles.length; i++) {
|
declarations.addAll(library.topLevelDeclarations);
|
||||||
List<TopLevelDeclaration> exported =
|
for (FileState part in library.partedFiles) {
|
||||||
computeExported(library._exportedFiles[i]);
|
declarations.addAll(part.topLevelDeclarations);
|
||||||
for (TopLevelDeclaration t in exported) {
|
|
||||||
if (!declarations.containsKey(t.name) &&
|
|
||||||
library._exportFilters[i].accepts(t.name)) {
|
|
||||||
declarations[t.name] = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're done with this library.
|
// We're done with this library.
|
||||||
seenLibraries.remove(library);
|
seenLibraries.remove(library);
|
||||||
}
|
}
|
||||||
|
|
||||||
return declarations.values.toList();
|
return declarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
_exportedTopLevelDeclarations = computeExported(this);
|
_exportedTopLevelDeclarations = computeExported(this);
|
||||||
|
@ -224,15 +220,16 @@ class FileState {
|
||||||
Set<String> get referencedNames => _referencedNames;
|
Set<String> get referencedNames => _referencedNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return public top-level declarations declared in the file.
|
* Return public top-level declarations declared in the file. The keys to the
|
||||||
|
* map are names of declarations.
|
||||||
*/
|
*/
|
||||||
List<TopLevelDeclaration> get topLevelDeclarations {
|
Map<String, TopLevelDeclaration> get topLevelDeclarations {
|
||||||
if (_topLevelDeclarations == null) {
|
if (_topLevelDeclarations == null) {
|
||||||
_topLevelDeclarations = <TopLevelDeclaration>[];
|
_topLevelDeclarations = <String, TopLevelDeclaration>{};
|
||||||
|
|
||||||
void addDeclaration(TopLevelDeclarationKind kind, String name) {
|
void addDeclaration(TopLevelDeclarationKind kind, String name) {
|
||||||
if (!name.startsWith('_')) {
|
if (!name.startsWith('_')) {
|
||||||
_topLevelDeclarations.add(new TopLevelDeclaration(kind, name));
|
_topLevelDeclarations[name] = new TopLevelDeclaration(kind, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,9 @@ export 'a.dart';
|
||||||
class B {}
|
class B {}
|
||||||
''');
|
''');
|
||||||
FileState file = fileSystemState.getFileForPath(b);
|
FileState file = fileSystemState.getFileForPath(b);
|
||||||
List<TopLevelDeclaration> declarations = file.exportedTopLevelDeclarations;
|
Map<String, TopLevelDeclaration> declarations =
|
||||||
expect(declarations.map((t) => t.name), unorderedEquals(['A', 'B']));
|
file.exportedTopLevelDeclarations;
|
||||||
|
expect(declarations.keys, unorderedEquals(['A', 'B']));
|
||||||
}
|
}
|
||||||
|
|
||||||
test_exportedTopLevelDeclarations_export2_show() {
|
test_exportedTopLevelDeclarations_export2_show() {
|
||||||
|
@ -162,9 +163,10 @@ export 'a.dart';
|
||||||
int V;
|
int V;
|
||||||
''');
|
''');
|
||||||
FileState file = fileSystemState.getFileForPath(b);
|
FileState file = fileSystemState.getFileForPath(b);
|
||||||
List<TopLevelDeclaration> declarations = file.exportedTopLevelDeclarations;
|
Map<String, TopLevelDeclaration> declarations =
|
||||||
expect(declarations.map((t) => t.name), unorderedEquals(['V']));
|
file.exportedTopLevelDeclarations;
|
||||||
expect(declarations.single.kind, TopLevelDeclarationKind.variable);
|
expect(declarations.keys, unorderedEquals(['V']));
|
||||||
|
expect(declarations['V'].kind, TopLevelDeclarationKind.variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
test_exportedTopLevelDeclarations_export_show() {
|
test_exportedTopLevelDeclarations_export_show() {
|
||||||
|
@ -499,16 +501,13 @@ set _V3(_) {}
|
||||||
''');
|
''');
|
||||||
FileState file = fileSystemState.getFileForPath(path);
|
FileState file = fileSystemState.getFileForPath(path);
|
||||||
|
|
||||||
List<TopLevelDeclaration> declarations = file.topLevelDeclarations;
|
Map<String, TopLevelDeclaration> declarations = file.topLevelDeclarations;
|
||||||
|
|
||||||
void assertHas(String name, TopLevelDeclarationKind kind) {
|
void assertHas(String name, TopLevelDeclarationKind kind) {
|
||||||
expect(
|
expect(declarations[name]?.kind, kind);
|
||||||
declarations,
|
|
||||||
contains(predicate(
|
|
||||||
(TopLevelDeclaration t) => t.name == name && t.kind == kind)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(declarations.map((t) => t.name),
|
expect(declarations.keys,
|
||||||
unorderedEquals(['C', 'F', 'E', 'f', 'V1', 'V2', 'V3', 'V4']));
|
unorderedEquals(['C', 'F', 'E', 'f', 'V1', 'V2', 'V3', 'V4']));
|
||||||
assertHas('C', TopLevelDeclarationKind.type);
|
assertHas('C', TopLevelDeclarationKind.type);
|
||||||
assertHas('F', TopLevelDeclarationKind.type);
|
assertHas('F', TopLevelDeclarationKind.type);
|
||||||
|
@ -636,8 +635,9 @@ set _V3(_) {}
|
||||||
|
|
||||||
void _assertExportedTopLevelDeclarations(String path, List<String> expected) {
|
void _assertExportedTopLevelDeclarations(String path, List<String> expected) {
|
||||||
FileState file = fileSystemState.getFileForPath(path);
|
FileState file = fileSystemState.getFileForPath(path);
|
||||||
List<TopLevelDeclaration> declarations = file.exportedTopLevelDeclarations;
|
Map<String, TopLevelDeclaration> declarations =
|
||||||
expect(declarations.map((t) => t.name), unorderedEquals(expected));
|
file.exportedTopLevelDeclarations;
|
||||||
|
expect(declarations.keys, unorderedEquals(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _assertFilesWithoutTransitiveFiles(List<FileState> expected) {
|
void _assertFilesWithoutTransitiveFiles(List<FileState> expected) {
|
||||||
|
|
Loading…
Reference in a new issue