Skip to content

Commit

Permalink
Rename Program to Component
Browse files Browse the repository at this point in the history
Change-Id: I1a3cc03fba9783807fa637a9d42fdbad68ee7686
Reviewed-on: https://dart-review.googlesource.com/31040
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
  • Loading branch information
peter-ahe-google authored and commit-bot@chromium.org committed Mar 15, 2018
1 parent a461573 commit 4f2bdff
Show file tree
Hide file tree
Showing 158 changed files with 1,333 additions and 1,305 deletions.
48 changes: 24 additions & 24 deletions pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ class FrontEndCompiler {
/// Each value is the compilation result of the key library.
final Map<Uri, LibraryCompilationResult> _results = {};

/// The [Program] with currently valid libraries. When a file is invalidated,
/// we remove the file, its library, and everything affected from [_program].
Program _program = new Program();
/// The [Component] with currently valid libraries. When a file is invalidated,
/// we remove the file, its library, and everything affected from [_component].
Component _component = new Component();

/// Each key is the file system URI of a library.
/// Each value is the libraries that directly depend on the key library.
final Map<Uri, Set<Uri>> _directLibraryDependencies = {};

/// Each key is the file system URI of a library.
/// Each value is the [Library] that is still in the [_program].
/// Each value is the [Library] that is still in the [_component].
final Map<Uri, Library> _uriToLibrary = {};

/// Each key is the file system URI of a part.
Expand Down Expand Up @@ -227,9 +227,9 @@ class FrontEndCompiler {
var dillTarget =
new DillTarget(_options.ticker, uriTranslator, _options.target);

// Append all libraries what we still have in the current program.
// Append all libraries what we still have in the current component.
await _logger.runAsync('Load dill libraries', () async {
dillTarget.loader.appendLibraries(_program);
dillTarget.loader.appendLibraries(_component);
await dillTarget.buildOutlines();
});

Expand All @@ -238,23 +238,23 @@ class FrontEndCompiler {
uriTranslator, new AnalyzerMetadataCollector());
kernelTarget.read(uri);

// Compile the entry point into the new program.
_program = await _logger.runAsync('Compile', () async {
await kernelTarget.buildOutlines(nameRoot: _program.root);
return await kernelTarget.buildProgram() ?? _program;
// Compile the entry point into the new component.
_component = await _logger.runAsync('Compile', () async {
await kernelTarget.buildOutlines(nameRoot: _component.root);
return await kernelTarget.buildComponent() ?? _component;
});

// TODO(scheglov) Only for new libraries?
_program.computeCanonicalNames();
_component.computeCanonicalNames();

_logger.run('Compute dependencies', _computeDependencies);

// TODO(scheglov) Can we keep the same instance?
var types = new TypeEnvironment(
new CoreTypes(_program), new ClassHierarchy(_program));
new CoreTypes(_component), new ClassHierarchy(_component));

// Add results for new libraries.
for (var library in _program.libraries) {
for (var library in _component.libraries) {
if (!_results.containsKey(library.importUri)) {
Map<Uri, List<CollectedResolution>> libraryResolutions =
kernelTarget.resolutions[library.fileUri];
Expand All @@ -276,7 +276,7 @@ class FrontEndCompiler {
}

var libraryResult = new LibraryCompilationResult(
_program, types, library.importUri, library, files);
_component, types, library.importUri, library, files);
_results[library.importUri] = libraryResult;
}
}
Expand All @@ -299,9 +299,9 @@ class FrontEndCompiler {
if (library == null) return;

// Invalidate the library.
_program.libraries.remove(library);
_program.root.removeChild('${library.importUri}');
_program.uriToSource.remove(libraryUri);
_component.libraries.remove(library);
_component.root.removeChild('${library.importUri}');
_component.uriToSource.remove(libraryUri);
_results.remove(library.importUri);

// Recursively invalidate dependencies.
Expand All @@ -314,7 +314,7 @@ class FrontEndCompiler {
invalidateLibrary(libraryUri);
}

/// Recompute [_directLibraryDependencies] for the current [_program].
/// Recompute [_directLibraryDependencies] for the current [_component].
void _computeDependencies() {
_directLibraryDependencies.clear();
_uriToLibrary.clear();
Expand All @@ -341,8 +341,8 @@ class FrontEndCompiler {
}
}

// Record dependencies for every library in the program.
_program.libraries.forEach(processLibrary);
// Record dependencies for every library in the component.
_component.libraries.forEach(processLibrary);
}

Future<T> _runWithFrontEndContext<T>(String msg, Future<T> f()) async {
Expand All @@ -355,13 +355,13 @@ class FrontEndCompiler {

/// The compilation result for a single library.
class LibraryCompilationResult {
/// The full current [Program]. It has all libraries that are required by
/// The full current [Component]. It has all libraries that are required by
/// this library, but might also have other libraries, that are not required.
///
/// The object is mutable, and is changed when files are invalidated.
final Program program;
final Component component;

/// The [TypeEnvironment] for the [program].
/// The [TypeEnvironment] for the [component].
final TypeEnvironment types;

/// The absolute URI of the library.
Expand All @@ -374,7 +374,7 @@ class LibraryCompilationResult {
final Map<Uri, FileCompilationResult> files;

LibraryCompilationResult(
this.program, this.types, this.uri, this.kernel, this.files);
this.component, this.types, this.uri, this.kernel, this.files);
}

/// The [DietListener] that record resolution information.
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/kernel_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class KernelContext {
// This is probably OK, because we consume them lazily.
var libraryMap = <String, kernel.Library>{};
var libraryExistMap = <String, bool>{};
for (var library in compilationResult.program.libraries) {
for (var library in compilationResult.component.libraries) {
String uriStr = library.importUri.toString();
libraryMap[uriStr] = library;
FileState file = fsState.getFileForUri(library.importUri);
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/kernel_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AnalyzerMetadata {
/// Return the [AnalyzerMetadata] for the [node], or `null` absent.
static AnalyzerMetadata forNode(kernel.TreeNode node) {
var repository =
node.enclosingProgram.metadata[AnalyzerMetadataRepository.TAG];
node.enclosingComponent.metadata[AnalyzerMetadataRepository.TAG];
if (repository != null) {
return repository.mapping[node];
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/analyzer/lib/src/kernel/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ abstract class ReferenceLevelLoader {
}

class DartLoader implements ReferenceLevelLoader {
final ast.Program program;
final ast.Component component;
final ApplicationRoot applicationRoot;
final Bimap<ClassElement, ast.Class> _classes =
new Bimap<ClassElement, ast.Class>();
Expand Down Expand Up @@ -119,7 +119,7 @@ class DartLoader implements ReferenceLevelLoader {

bool get strongMode => context.analysisOptions.strongMode;

DartLoader(this.program, DartOptions options, Packages packages,
DartLoader(this.component, DartOptions options, Packages packages,
{DartSdk dartSdk,
AnalysisContext context,
this.ignoreRedirectingFactories: true})
Expand All @@ -145,7 +145,7 @@ class DartLoader implements ReferenceLevelLoader {
..isExternal = true
..name = getLibraryName(element)
..fileUri = element.source.uri;
program.libraries.add(library..parent = program);
component.libraries.add(library..parent = component);
_libraries[element] = library;
}
return library;
Expand Down Expand Up @@ -732,7 +732,7 @@ class DartLoader implements ReferenceLevelLoader {
}
}

void loadSdkInterface(ast.Program program, Target target) {
void loadSdkInterface(ast.Component component, Target target) {
var requiredSdkMembers = target.requiredSdkClasses;
for (var libraryUri in requiredSdkMembers.keys) {
var source = context.sourceFactory.forUri2(Uri.parse(libraryUri));
Expand Down Expand Up @@ -764,8 +764,8 @@ class DartLoader implements ReferenceLevelLoader {
}
}
}
for (int i = 0; i < program.libraries.length; ++i) {
var library = program.libraries[i];
for (int i = 0; i < component.libraries.length; ++i) {
var library = component.libraries[i];
if (compileSdk || library.importUri.scheme != 'dart') {
ensureLibraryIsLoaded(library);
}
Expand All @@ -777,7 +777,7 @@ class DartLoader implements ReferenceLevelLoader {
/// This operation may be expensive and should only be used for diagnostics.
List<String> getLoadedFileNames() {
var list = <String>[];
for (var library in program.libraries) {
for (var library in component.libraries) {
LibraryElement element = context.computeLibraryElement(context
.sourceFactory
.forUri2(applicationRoot.absoluteUri(library.importUri)));
Expand Down Expand Up @@ -829,22 +829,22 @@ class DartLoader implements ReferenceLevelLoader {
new ast.Name('main'),
ast.ProcedureKind.Method,
new ast.FunctionNode(new ast.ExpressionStatement(new ast.Throw(
new ast.StringLiteral('Program has no main method')))),
new ast.StringLiteral('Component has no main method')))),
isStatic: true)
..fileUri = library.fileUri;
library.addMember(main);
return main;
}

void loadProgram(Uri mainLibrary, {Target target, bool compileSdk}) {
void loadComponent(Uri mainLibrary, {Target target, bool compileSdk}) {
ast.Library library = getLibraryReferenceFromUri(mainLibrary);
ensureLibraryIsLoaded(library);
var mainMethod = _getMainMethod(mainLibrary);
loadEverything(target: target, compileSdk: compileSdk);
if (mainMethod == null) {
mainMethod = _makeMissingMainMethod(library);
}
program.mainMethod = mainMethod;
component.mainMethod = mainMethod;
for (LibraryElement libraryElement in libraryElements) {
for (CompilationUnitElement compilationUnitElement
in libraryElement.units) {
Expand All @@ -858,7 +858,7 @@ class DartLoader implements ReferenceLevelLoader {
// The source's contents could not be accessed.
sourceCode = const <int>[];
}
program.uriToSource[source.uri] =
component.uriToSource[source.uri] =
new ast.Source(lineInfo.lineStarts, sourceCode);
}
}
Expand Down Expand Up @@ -896,7 +896,7 @@ class DartLoaderBatch {
String lastPackagePath;
bool lastStrongMode;

Future<DartLoader> getLoader(ast.Program program, DartOptions options,
Future<DartLoader> getLoader(ast.Component component, DartOptions options,
{String packageDiscoveryPath}) async {
if (dartSdk == null ||
lastSdk != options.sdk ||
Expand All @@ -912,7 +912,7 @@ class DartLoaderBatch {
packages = await createPackages(options.packagePath,
discoveryPath: packageDiscoveryPath);
}
return new DartLoader(program, options, packages, dartSdk: dartSdk);
return new DartLoader(component, options, packages, dartSdk: dartSdk);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class C {
// Remember Kernel libraries produced by the compiler.
var libraryMap = <String, kernel.Library>{};
var libraryExistMap = <String, bool>{};
for (var library in libraryResult.program.libraries) {
for (var library in libraryResult.component.libraries) {
String uriStr = library.importUri.toString();
libraryMap[uriStr] = library;
FileState file = fsState.getFileForUri(library.importUri);
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/inferrer/type_graph_nodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class ParameterAssignments extends IterableBase<TypeInformation> {
}

/**
* A node representing a resolved element of the program. The kind of
* A node representing a resolved element of the component. The kind of
* elements that need an [ElementTypeInformation] are:
*
* - Functions (including getters and setters)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/io/kernel_source_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class KernelSourceInformationBuilder
ir.Location location;
if (offset != null) {
location = node.location;
location = node.enclosingProgram.getLocation(location.file, offset);
location = node.enclosingComponent.getLocation(location.file, offset);
} else {
while (node != null && node.fileOffset == ir.TreeNode.noOffset) {
node = node.parent;
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/kernel/dart2js_target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Dart2jsTarget extends Target {
{void logger(String msg)}) {}

@override
void performGlobalTransformations(CoreTypes coreTypes, Program program,
void performGlobalTransformations(CoreTypes coreTypes, Component component,
{void logger(String msg)}) {}

@override
Expand Down
6 changes: 3 additions & 3 deletions pkg/compiler/lib/src/kernel/element_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ abstract class KernelToElementMap {
abstract class KernelToElementMapForImpact extends KernelToElementMap {
NativeBasicData get nativeBasicData;

/// Adds libraries in [program] to the set of libraries.
/// Adds libraries in [component] to the set of libraries.
///
/// The main method of the first program is used as the main method for the
/// The main method of the first component is used as the main method for the
/// compilation.
void addProgram(ir.Program program);
void addProgram(ir.Component component);

/// Returns the [ConstructorEntity] corresponding to a super initializer in
/// [constructor].
Expand Down
8 changes: 4 additions & 4 deletions pkg/compiler/lib/src/kernel/element_map_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1216,12 +1216,12 @@ class KernelToElementMapForImpactImpl extends KernelToElementMapBase
@override
NativeBasicData get nativeBasicData => _frontendStrategy.nativeBasicData;

/// Adds libraries in [program] to the set of libraries.
/// Adds libraries in [component] to the set of libraries.
///
/// The main method of the first program is used as the main method for the
/// The main method of the first component is used as the main method for the
/// compilation.
void addProgram(ir.Program program) {
_env.addProgram(program);
void addProgram(ir.Component component) {
_env.addProgram(component);
}

@override
Expand Down
18 changes: 9 additions & 9 deletions pkg/compiler/lib/src/kernel/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ import 'element_map_impl.dart';
import 'element_map_mixins.dart';
import 'kelements.dart' show KImport;

/// Environment for fast lookup of program libraries.
/// Environment for fast lookup of component libraries.
class ProgramEnv {
final Set<ir.Program> _programs = new Set<ir.Program>();
final Set<ir.Component> _programs = new Set<ir.Component>();

Map<Uri, LibraryEnv> _libraryMap;

/// TODO(johnniwinther): Handle arbitrary load order if needed.
ir.Member get mainMethod => _programs.first?.mainMethod;

void addProgram(ir.Program program) {
if (_programs.add(program)) {
void addProgram(ir.Component component) {
if (_programs.add(component)) {
if (_libraryMap != null) {
_addLibraries(program);
_addLibraries(component);
}
}
}

void _addLibraries(ir.Program program) {
for (ir.Library library in program.libraries) {
void _addLibraries(ir.Component component) {
for (ir.Library library in component.libraries) {
_libraryMap[library.importUri] = new LibraryEnv(library);
}
}

void _ensureLibraryMap() {
if (_libraryMap == null) {
_libraryMap = <Uri, LibraryEnv>{};
for (ir.Program program in _programs) {
_addLibraries(program);
for (ir.Component component in _programs) {
_addLibraries(component);
}
}
}
Expand Down
Loading

0 comments on commit 4f2bdff

Please sign in to comment.