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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 2016543002: Resynthesize FieldFormalParameterElementImpl(s) lazily. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 List<FunctionElementImpl> buildTopLevelFunctions() { 1539 List<FunctionElementImpl> buildTopLevelFunctions() {
1540 return _unitResynthesizer.buildTopLevelFunctions(); 1540 return _unitResynthesizer.buildTopLevelFunctions();
1541 } 1541 }
1542 1542
1543 @override 1543 @override
1544 UnitExplicitTopLevelVariables buildTopLevelVariables() { 1544 UnitExplicitTopLevelVariables buildTopLevelVariables() {
1545 return _unitResynthesizer.buildUnitExplicitTopLevelVariables(); 1545 return _unitResynthesizer.buildUnitExplicitTopLevelVariables();
1546 } 1546 }
1547 1547
1548 @override 1548 @override
1549 DartType resolveLinkedType(
1550 int slot, TypeParameterizedElementMixin typeParameterContext) {
1551 return _unitResynthesizer.buildLinkedType(slot, typeParameterContext);
1552 }
1553
1554 @override
1549 DartType resolveTypeRef( 1555 DartType resolveTypeRef(
1550 EntityRef type, TypeParameterizedElementMixin typeParameterContext, 1556 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
1551 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) { 1557 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) {
1552 return _unitResynthesizer.buildType(type, typeParameterContext, 1558 return _unitResynthesizer.buildType(type, typeParameterContext,
1553 defaultVoid: defaultVoid, 1559 defaultVoid: defaultVoid,
1554 instantiateToBoundsAllowed: instantiateToBoundsAllowed); 1560 instantiateToBoundsAllowed: instantiateToBoundsAllowed);
1555 } 1561 }
1556 } 1562 }
1557 1563
1558 /** 1564 /**
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 executableElement.parameters = parameters; 2107 executableElement.parameters = parameters;
2102 } 2108 }
2103 } 2109 }
2104 if (serializedExecutable.kind == UnlinkedExecutableKind.constructor) { 2110 if (serializedExecutable.kind == UnlinkedExecutableKind.constructor) {
2105 // Caller handles setting the return type. 2111 // Caller handles setting the return type.
2106 assert(serializedExecutable.returnType == null); 2112 assert(serializedExecutable.returnType == null);
2107 } else { 2113 } else {
2108 bool isSetter = 2114 bool isSetter =
2109 serializedExecutable.kind == UnlinkedExecutableKind.setter; 2115 serializedExecutable.kind == UnlinkedExecutableKind.setter;
2110 executableElement.returnType = buildLinkedType( 2116 executableElement.returnType = buildLinkedType(
2111 serializedExecutable.inferredReturnTypeSlot, 2117 serializedExecutable.inferredReturnTypeSlot, executableElement) ??
2112 _currentTypeParameterizedElement) ?? 2118 buildType(serializedExecutable.returnType, executableElement,
2113 buildType(
2114 serializedExecutable.returnType, _currentTypeParameterizedElement,
2115 defaultVoid: isSetter && summaryResynthesizer.strongMode); 2119 defaultVoid: isSetter && summaryResynthesizer.strongMode);
2116 } 2120 }
2117 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 2121 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
2118 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); 2122 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false);
2119 { 2123 {
2120 List<UnlinkedExecutable> unlinkedFunctions = 2124 List<UnlinkedExecutable> unlinkedFunctions =
2121 serializedExecutable.localFunctions; 2125 serializedExecutable.localFunctions;
2122 int length = unlinkedFunctions.length; 2126 int length = unlinkedFunctions.length;
2123 if (length != 0) { 2127 if (length != 0) {
2124 List<FunctionElementImpl> localFunctions = 2128 List<FunctionElementImpl> localFunctions =
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2312 return element; 2316 return element;
2313 } 2317 }
2314 2318
2315 /** 2319 /**
2316 * Resynthesize a [ParameterElement]. 2320 * Resynthesize a [ParameterElement].
2317 */ 2321 */
2318 ParameterElement buildParameter( 2322 ParameterElement buildParameter(
2319 UnlinkedParam serializedParameter, ElementImpl enclosingElement, 2323 UnlinkedParam serializedParameter, ElementImpl enclosingElement,
2320 {bool synthetic: false}) { 2324 {bool synthetic: false}) {
2321 ParameterElementImpl parameterElement; 2325 ParameterElementImpl parameterElement;
2322 bool isLazilyResynthesized = false;
2323 int nameOffset = synthetic ? -1 : serializedParameter.nameOffset;
2324 if (serializedParameter.isInitializingFormal) { 2326 if (serializedParameter.isInitializingFormal) {
2325 FieldFormalParameterElementImpl initializingParameter; 2327 FieldFormalParameterElementImpl initializingParameter;
2326 if (serializedParameter.kind == UnlinkedParamKind.required) { 2328 if (serializedParameter.kind == UnlinkedParamKind.required) {
2327 initializingParameter = new FieldFormalParameterElementImpl( 2329 initializingParameter =
2328 serializedParameter.name, nameOffset); 2330 new FieldFormalParameterElementImpl.forSerialized(
2331 serializedParameter, enclosingElement);
2329 } else { 2332 } else {
2330 DefaultFieldFormalParameterElementImpl defaultParameter = 2333 initializingParameter =
2331 new DefaultFieldFormalParameterElementImpl( 2334 new DefaultFieldFormalParameterElementImpl.forSerialized(
2332 serializedParameter.name, nameOffset); 2335 serializedParameter, enclosingElement);
2333 initializingParameter = defaultParameter;
2334 if (serializedParameter.defaultValue != null) {
2335 defaultParameter.constantInitializer = _buildConstExpression(
2336 enclosingElement, serializedParameter.defaultValue);
2337 defaultParameter.defaultValueCode =
2338 serializedParameter.defaultValueCode;
2339 }
2340 } 2336 }
2341 parameterElement = initializingParameter; 2337 parameterElement = initializingParameter;
2342 initializingParameter.field = fields[serializedParameter.name];
2343 } else { 2338 } else {
2344 if (serializedParameter.kind == UnlinkedParamKind.required) { 2339 if (serializedParameter.kind == UnlinkedParamKind.required) {
2345 parameterElement = new ParameterElementImpl.forSerialized( 2340 parameterElement = new ParameterElementImpl.forSerialized(
2346 serializedParameter, enclosingElement); 2341 serializedParameter, enclosingElement);
2347 isLazilyResynthesized = true;
2348 } else { 2342 } else {
2349 DefaultParameterElementImpl defaultParameter = 2343 parameterElement = new DefaultParameterElementImpl.forSerialized(
2350 new DefaultParameterElementImpl.forSerialized( 2344 serializedParameter, enclosingElement);
2351 serializedParameter, enclosingElement);
2352 isLazilyResynthesized = true;
2353 parameterElement = defaultParameter;
2354 } 2345 }
2355 } 2346 }
2356 parameterElement.synthetic = synthetic; 2347 parameterElement.synthetic = synthetic;
2357 if (!isLazilyResynthesized) {
2358 buildAnnotations(parameterElement, serializedParameter.annotations);
2359 buildCodeRange(parameterElement, serializedParameter.codeRange);
2360 }
2361 if (serializedParameter.isFunctionTyped) { 2348 if (serializedParameter.isFunctionTyped) {
2362 FunctionElementImpl parameterTypeElement = 2349 FunctionElementImpl parameterTypeElement =
2363 new FunctionElementImpl('', -1); 2350 new FunctionElementImpl_forFunctionTypedParameter(
2364 parameterTypeElement.synthetic = true; 2351 unit, parameterElement);
2352 if (!synthetic) {
2353 parameterTypeElement.enclosingElement = parameterElement;
2354 }
2365 List<ParameterElement> subParameters = serializedParameter.parameters 2355 List<ParameterElement> subParameters = serializedParameter.parameters
2366 .map((UnlinkedParam p) => 2356 .map((UnlinkedParam p) =>
2367 buildParameter(p, parameterTypeElement, synthetic: synthetic)) 2357 buildParameter(p, parameterTypeElement, synthetic: synthetic))
2368 .toList(); 2358 .toList();
2369 if (synthetic) { 2359 if (synthetic) {
2370 parameterTypeElement.parameters = subParameters; 2360 parameterTypeElement.parameters = subParameters;
2371 } else { 2361 } else {
2372 parameterElement.parameters = subParameters; 2362 parameterElement.parameters = subParameters;
2373 parameterTypeElement.shareParameters(subParameters); 2363 parameterTypeElement.shareParameters(subParameters);
2374 parameterTypeElement.enclosingElement = parameterElement;
2375 } 2364 }
2376 parameterTypeElement.returnType = 2365 parameterTypeElement.returnType =
2377 buildType(serializedParameter.type, _currentTypeParameterizedElement); 2366 buildType(serializedParameter.type, _currentTypeParameterizedElement);
2378 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 2367 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
2379 parameterTypeElement, null, getCurrentTypeArguments(), false); 2368 parameterTypeElement, null, getCurrentTypeArguments(), false);
2380 parameterTypeElement.type = parameterElement.type; 2369 parameterTypeElement.type = parameterElement.type;
2381 } else {
2382 if (serializedParameter.isInitializingFormal &&
2383 serializedParameter.type == null) {
2384 // The type is inherited from the matching field.
2385 parameterElement.type =
2386 fields[serializedParameter.name]?.type ?? DynamicTypeImpl.instance;
2387 } else {
2388 parameterElement.type = buildLinkedType(
2389 serializedParameter.inferredTypeSlot,
2390 _currentTypeParameterizedElement) ??
2391 buildType(
2392 serializedParameter.type, _currentTypeParameterizedElement);
2393 }
2394 if (!isLazilyResynthesized) {
2395 parameterElement.hasImplicitType = serializedParameter.type == null;
2396 }
2397 } 2370 }
2398 buildVariableInitializer(parameterElement, serializedParameter.initializer); 2371 buildVariableInitializer(parameterElement, serializedParameter.initializer);
2399 switch (serializedParameter.kind) { 2372 switch (serializedParameter.kind) {
2400 case UnlinkedParamKind.named: 2373 case UnlinkedParamKind.named:
2401 parameterElement.parameterKind = ParameterKind.NAMED; 2374 parameterElement.parameterKind = ParameterKind.NAMED;
2402 break; 2375 break;
2403 case UnlinkedParamKind.positional: 2376 case UnlinkedParamKind.positional:
2404 parameterElement.parameterKind = ParameterKind.POSITIONAL; 2377 parameterElement.parameterKind = ParameterKind.POSITIONAL;
2405 break; 2378 break;
2406 case UnlinkedParamKind.required: 2379 case UnlinkedParamKind.required:
2407 parameterElement.parameterKind = ParameterKind.REQUIRED; 2380 parameterElement.parameterKind = ParameterKind.REQUIRED;
2408 break; 2381 break;
2409 } 2382 }
2410 if (!isLazilyResynthesized) {
2411 if (serializedParameter.visibleOffset != 0) {
2412 parameterElement.setVisibleRange(serializedParameter.visibleOffset,
2413 serializedParameter.visibleLength);
2414 }
2415 }
2416 return parameterElement; 2383 return parameterElement;
2417 } 2384 }
2418 2385
2419 /** 2386 /**
2420 * Handle the parts that are common to top level variables and fields. 2387 * Handle the parts that are common to top level variables and fields.
2421 */ 2388 */
2422 void buildPropertyIntroducingElementCommonParts( 2389 void buildPropertyIntroducingElementCommonParts(
2423 PropertyInducingElementImpl element, 2390 PropertyInducingElementImpl element,
2424 UnlinkedVariable serializedVariable) { 2391 UnlinkedVariable serializedVariable) {
2425 buildVariableCommonParts(element, serializedVariable); 2392 buildVariableCommonParts(element, serializedVariable);
(...skipping 28 matching lines...) Expand all
2454 if (type == null) { 2421 if (type == null) {
2455 if (defaultVoid) { 2422 if (defaultVoid) {
2456 return VoidTypeImpl.instance; 2423 return VoidTypeImpl.instance;
2457 } else { 2424 } else {
2458 return DynamicTypeImpl.instance; 2425 return DynamicTypeImpl.instance;
2459 } 2426 }
2460 } 2427 }
2461 if (type.paramReference != 0) { 2428 if (type.paramReference != 0) {
2462 return typeParameterContext.getTypeParameterType(type.paramReference); 2429 return typeParameterContext.getTypeParameterType(type.paramReference);
2463 } else if (type.syntheticReturnType != null) { 2430 } else if (type.syntheticReturnType != null) {
2464 FunctionElementImpl element = new FunctionElementImpl('', -1); 2431 FunctionElementImpl element =
2465 element.synthetic = true; 2432 new FunctionElementImpl_forLUB(unit, typeParameterContext);
2466 element.parameters = type.syntheticParams 2433 element.parameters = type.syntheticParams
2467 .map((UnlinkedParam param) => 2434 .map((UnlinkedParam param) =>
2468 buildParameter(param, element, synthetic: true)) 2435 buildParameter(param, element, synthetic: true))
2469 .toList(); 2436 .toList();
2470 element.returnType = 2437 element.returnType =
2471 buildType(type.syntheticReturnType, typeParameterContext); 2438 buildType(type.syntheticReturnType, typeParameterContext);
2472 FunctionTypeImpl result = new FunctionTypeImpl.elementWithNameAndArgs( 2439 FunctionTypeImpl result = new FunctionTypeImpl.elementWithNameAndArgs(
2473 element, null, null, false); 2440 element, null, null, false);
2474 element.type = result; 2441 element.type = result;
2475 return result; 2442 return result;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2667 fields[element.name] = element; 2634 fields[element.name] = element;
2668 } 2635 }
2669 } 2636 }
2670 2637
2671 /** 2638 /**
2672 * Handle the parts that are common to variables. 2639 * Handle the parts that are common to variables.
2673 */ 2640 */
2674 void buildVariableCommonParts( 2641 void buildVariableCommonParts(
2675 VariableElementImpl element, UnlinkedVariable serializedVariable) { 2642 VariableElementImpl element, UnlinkedVariable serializedVariable) {
2676 element.type = buildLinkedType(serializedVariable.inferredTypeSlot, 2643 element.type = buildLinkedType(serializedVariable.inferredTypeSlot,
2677 _currentTypeParameterizedElement) ?? 2644 element.typeParameterContext) ??
2678 buildType(serializedVariable.type, _currentTypeParameterizedElement); 2645 buildType(serializedVariable.type, element.typeParameterContext);
2679 buildVariableInitializer(element, serializedVariable.initializer); 2646 buildVariableInitializer(element, serializedVariable.initializer);
2680 } 2647 }
2681 2648
2682 /** 2649 /**
2683 * If the given [serializedInitializer] is not `null`, create the 2650 * If the given [serializedInitializer] is not `null`, create the
2684 * corresponding [FunctionElementImpl] and set it for the [variable]. 2651 * corresponding [FunctionElementImpl] and set it for the [variable].
2685 */ 2652 */
2686 void buildVariableInitializer( 2653 void buildVariableInitializer(
2687 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) { 2654 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) {
2688 if (serializedInitializer == null) { 2655 if (serializedInitializer == null) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 static String _getElementIdentifier(String name, ReferenceKind kind) { 2927 static String _getElementIdentifier(String name, ReferenceKind kind) {
2961 if (kind == ReferenceKind.topLevelPropertyAccessor || 2928 if (kind == ReferenceKind.topLevelPropertyAccessor ||
2962 kind == ReferenceKind.propertyAccessor) { 2929 kind == ReferenceKind.propertyAccessor) {
2963 if (!name.endsWith('=')) { 2930 if (!name.endsWith('=')) {
2964 return name + '?'; 2931 return name + '?';
2965 } 2932 }
2966 } 2933 }
2967 return name; 2934 return name;
2968 } 2935 }
2969 } 2936 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698