| Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| index f9d81e92bd138a147b1ed05cdc9005d0d324835f..c127ce326387c4b3e56bed16a97830c0790daa89 100644
|
| --- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| +++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| @@ -3,6 +3,7 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| +import 'dart:async';
|
| import 'dart:collection' show HashMap, HashSet;
|
| import 'dart:math' show min, max;
|
|
|
| @@ -13,6 +14,7 @@ import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
|
| import 'package:analyzer/dart/ast/standard_resolution_map.dart';
|
| import 'package:analyzer/dart/element/element.dart';
|
| import 'package:analyzer/dart/element/type.dart';
|
| +import 'package:analyzer/src/dart/analysis/driver.dart';
|
| import 'package:analyzer/src/dart/ast/token.dart' show StringToken;
|
| import 'package:analyzer/src/dart/element/element.dart'
|
| show FieldElementImpl, LocalVariableElementImpl;
|
| @@ -20,7 +22,7 @@ import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl;
|
| import 'package:analyzer/src/dart/sdk/sdk.dart';
|
| import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
|
| import 'package:analyzer/src/generated/resolver.dart'
|
| - show TypeProvider, NamespaceBuilder;
|
| + show NamespaceBuilder, TypeProvider, TypeProviderImpl;
|
| import 'package:analyzer/src/generated/type_system.dart'
|
| show StrongTypeSystemImpl;
|
| import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit;
|
| @@ -56,11 +58,11 @@ import 'type_utilities.dart';
|
|
|
| class CodeGenerator extends GeneralizingAstVisitor
|
| with ClosureAnnotator, JsTypeRefCodegen, NullableTypeInference {
|
| - final AnalysisContext context;
|
| + final AnalysisDriver driver;
|
| final SummaryDataStore summaryData;
|
|
|
| final CompilerOptions options;
|
| - final StrongTypeSystemImpl rules;
|
| + StrongTypeSystemImpl rules;
|
|
|
| /// The set of libraries we are currently compiling, and the temporaries used
|
| /// to refer to them.
|
| @@ -108,26 +110,26 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| final _eagerTopLevelFields = new HashSet<Element>.identity();
|
|
|
| /// The type provider from the current Analysis [context].
|
| - final TypeProvider types;
|
| + TypeProvider types;
|
|
|
| - final LibraryElement dartCoreLibrary;
|
| - final LibraryElement dartJSLibrary;
|
| + LibraryElement dartCoreLibrary;
|
| + LibraryElement dartJSLibrary;
|
|
|
| /// The dart:async `StreamIterator<>` type.
|
| - final InterfaceType _asyncStreamIterator;
|
| + InterfaceType _asyncStreamIterator;
|
|
|
| /// The dart:_interceptors JSArray element.
|
| - final ClassElement _jsArray;
|
| -
|
| - final ClassElement boolClass;
|
| - final ClassElement intClass;
|
| - final ClassElement interceptorClass;
|
| - final ClassElement nullClass;
|
| - final ClassElement numClass;
|
| - final ClassElement objectClass;
|
| - final ClassElement stringClass;
|
| - final ClassElement functionClass;
|
| - final ClassElement privateSymbolClass;
|
| + ClassElement _jsArray;
|
| +
|
| + ClassElement boolClass;
|
| + ClassElement intClass;
|
| + ClassElement interceptorClass;
|
| + ClassElement nullClass;
|
| + ClassElement numClass;
|
| + ClassElement objectClass;
|
| + ClassElement stringClass;
|
| + ClassElement functionClass;
|
| + ClassElement privateSymbolClass;
|
|
|
| ConstFieldVisitor _constants;
|
|
|
| @@ -156,27 +158,47 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| /// class we're currently compiling, or `null` if we aren't compiling a class.
|
| ClassPropertyModel _classProperties;
|
|
|
| - CodeGenerator(
|
| - AnalysisContext c, this.summaryData, this.options, this._extensionTypes)
|
| - : context = c,
|
| - rules = new StrongTypeSystemImpl(c.typeProvider),
|
| - types = c.typeProvider,
|
| - _asyncStreamIterator =
|
| - _getLibrary(c, 'dart:async').getType('StreamIterator').type,
|
| - _jsArray = _getLibrary(c, 'dart:_interceptors').getType('JSArray'),
|
| - interceptorClass =
|
| - _getLibrary(c, 'dart:_interceptors').getType('Interceptor'),
|
| - dartCoreLibrary = _getLibrary(c, 'dart:core'),
|
| - boolClass = _getLibrary(c, 'dart:core').getType('bool'),
|
| - intClass = _getLibrary(c, 'dart:core').getType('int'),
|
| - numClass = _getLibrary(c, 'dart:core').getType('num'),
|
| - nullClass = _getLibrary(c, 'dart:core').getType('Null'),
|
| - objectClass = _getLibrary(c, 'dart:core').getType('Object'),
|
| - stringClass = _getLibrary(c, 'dart:core').getType('String'),
|
| - functionClass = _getLibrary(c, 'dart:core').getType('Function'),
|
| - privateSymbolClass =
|
| - _getLibrary(c, 'dart:_internal').getType('PrivateSymbol'),
|
| - dartJSLibrary = _getLibrary(c, 'dart:js');
|
| + CodeGenerator._(
|
| + this.driver, this.summaryData, this.options, this._extensionTypes);
|
| +
|
| + static Future<CodeGenerator> create(
|
| + AnalysisDriver driver,
|
| + SummaryDataStore summaryData,
|
| + CompilerOptions options,
|
| + ExtensionTypeSet extensionTypes) async {
|
| + CodeGenerator codeGenerator =
|
| + new CodeGenerator._(driver, summaryData, options, extensionTypes);
|
| + await codeGenerator._initialize();
|
| + return codeGenerator;
|
| + }
|
| +
|
| + Future<Null> _initialize() async {
|
| + var coreLibrary = await _computeLibraryByUri('dart:core');
|
| + var asyncLibrary = await _computeLibraryByUri('dart:async');
|
| +
|
| + types = new TypeProviderImpl(coreLibrary, asyncLibrary);
|
| + rules = new StrongTypeSystemImpl(types);
|
| +
|
| + _asyncStreamIterator = asyncLibrary.getType('StreamIterator').type;
|
| +
|
| + var interceptorsLibrary = await _computeLibraryByUri('dart:_interceptors');
|
| + _jsArray = interceptorsLibrary.getType('JSArray');
|
| + interceptorClass = interceptorsLibrary.getType('Interceptor');
|
| +
|
| + dartCoreLibrary = coreLibrary;
|
| + boolClass = coreLibrary.getType('bool');
|
| + intClass = coreLibrary.getType('int');
|
| + numClass = coreLibrary.getType('num');
|
| + nullClass = coreLibrary.getType('Null');
|
| + objectClass = coreLibrary.getType('Object');
|
| + stringClass = coreLibrary.getType('String');
|
| + functionClass = coreLibrary.getType('Function');
|
| +
|
| + var internalLibrary = await _computeLibraryByUri('dart:_internal');
|
| + privateSymbolClass = internalLibrary.getType('PrivateSymbol');
|
| +
|
| + dartJSLibrary = await _computeLibraryByUri('dart:js');
|
| + }
|
|
|
| LibraryElement get currentLibrary => _loader.currentElement.library;
|
|
|
| @@ -205,7 +227,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| .elementDeclaredByCompilationUnit(u)
|
| .librarySource
|
| .isInSystemLibrary)) {
|
| - var sdk = context.sourceFactory.dartSdk;
|
| + var sdk = driver.sourceFactory.dartSdk;
|
| summaryData.addBundle(
|
| null,
|
| sdk is SummaryBasedDartSdk
|
| @@ -228,7 +250,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| uriToUnit.keys.toSet(),
|
| (uri) => summaryData.linkedMap[uri],
|
| (uri) => summaryData.unlinkedMap[uri] ?? uriToUnit[uri],
|
| - context.declaredVariables.get,
|
| + driver.declaredVariables.get,
|
| true)
|
| .forEach(assembler.addLinkedLibrary);
|
|
|
| @@ -283,7 +305,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|
|
| // Collect all Element -> Node mappings, in case we need to forward declare
|
| // any nodes.
|
| - var nodes = new HashMap<Element, AstNode>.identity();
|
| + var nodes = new HashMap<Element, AstNode>();
|
| var sdkBootstrappingFns = new List<FunctionElement>();
|
| for (var unit in compilationUnits) {
|
| if (_isDartRuntime(
|
| @@ -295,7 +317,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| }
|
| _loader = new ElementLoader(nodes);
|
| if (compilationUnits.isNotEmpty) {
|
| - _constants = new ConstFieldVisitor(context,
|
| + _constants = new ConstFieldVisitor(types, driver.declaredVariables,
|
| dummySource: resolutionMap
|
| .elementDeclaredByCompilationUnit(compilationUnits.first)
|
| .source);
|
| @@ -1865,7 +1887,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| } else {
|
| // Method
|
| // Swap in "Object" for parameter types that are covariant overrides.
|
| - var objectType = context.typeProvider.objectType;
|
| + var objectType = types.objectType;
|
| elementToType =
|
| (MethodElement element) => element.getReifiedType(objectType);
|
| getOverride = classElem.lookUpInheritedConcreteMethod;
|
| @@ -5922,6 +5944,10 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|
|
| return path.endsWith(".template.dart");
|
| }
|
| +
|
| + Future<LibraryElement> _computeLibraryByUri(String libraryUri) async {
|
| + return await driver.resynthesizeLibrary(libraryUri);
|
| + }
|
| }
|
|
|
| /// Choose a canonical name from the [library] element.
|
|
|