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

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

Issue 1686713002: Add support for redirectedConstructor to summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 ? null 460 ? null
461 : typeArguments.map(_buildTypeAst).toList(); 461 : typeArguments.map(_buildTypeAst).toList();
462 TypeName node = AstFactory.typeName4(type.name, argumentNodes); 462 TypeName node = AstFactory.typeName4(type.name, argumentNodes);
463 node.type = type; 463 node.type = type;
464 (node.name as SimpleIdentifier).staticElement = type.element; 464 (node.name as SimpleIdentifier).staticElement = type.element;
465 return node; 465 return node;
466 } 466 }
467 throw new StateError('Unsupported type $type'); 467 throw new StateError('Unsupported type $type');
468 } 468 }
469 469
470 /**
471 * Return the [ConstructorElement] by applying [typeArgumentRefs] to the
472 * given linked [info]. Both cases when [info] is a [ClassElement] and
473 * [ConstructorElement] are supported.
474 */
475 _DeferredConstructorElement _createConstructorElement(
476 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) {
477 bool isClass = info.element is ClassElement;
478 _ReferenceInfo classInfo = isClass ? info : info.enclosing;
479 List<DartType> typeArguments =
480 typeArgumentRefs.map(resynthesizer.buildType).toList();
481 InterfaceType classType = classInfo.buildType((i) {
482 if (i < typeArguments.length) {
483 return typeArguments[i];
484 } else {
485 return DynamicTypeImpl.instance;
486 }
487 }, const <int>[]);
488 String name = isClass ? '' : info.name;
489 return new _DeferredConstructorElement(classType, name);
490 }
491
492 InterpolationElement _newInterpolationElement(Expression expr) { 470 InterpolationElement _newInterpolationElement(Expression expr) {
493 if (expr is SimpleStringLiteral) { 471 if (expr is SimpleStringLiteral) {
494 return new InterpolationString(expr.literal, expr.value); 472 return new InterpolationString(expr.literal, expr.value);
495 } else { 473 } else {
496 return new InterpolationExpression( 474 return new InterpolationExpression(
497 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), 475 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION),
498 expr, 476 expr,
499 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 477 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
500 } 478 }
501 } 479 }
(...skipping 27 matching lines...) Expand all
529 String constructorName; 507 String constructorName;
530 if (info.element is ConstructorElement) { 508 if (info.element is ConstructorElement) {
531 constructorName = info.name; 509 constructorName = info.name;
532 } else if (info.element is ClassElement) { 510 } else if (info.element is ClassElement) {
533 constructorName = null; 511 constructorName = null;
534 } else { 512 } else {
535 throw new StateError('Unsupported element for invokeConstructor ' 513 throw new StateError('Unsupported element for invokeConstructor '
536 '${info.element?.runtimeType}'); 514 '${info.element?.runtimeType}');
537 } 515 }
538 _DeferredConstructorElement constructorElement = 516 _DeferredConstructorElement constructorElement =
539 _createConstructorElement(info, ref.typeArguments); 517 resynthesizer._createConstructorElement(info, ref.typeArguments);
540 // prepare arguments 518 // prepare arguments
541 List<Expression> arguments; 519 List<Expression> arguments;
542 { 520 {
543 int numNamedArgs = uc.ints[intPtr++]; 521 int numNamedArgs = uc.ints[intPtr++];
544 int numPositionalArgs = uc.ints[intPtr++]; 522 int numPositionalArgs = uc.ints[intPtr++];
545 int numArgs = numNamedArgs + numPositionalArgs; 523 int numArgs = numNamedArgs + numPositionalArgs;
546 arguments = _removeTopItems(numArgs); 524 arguments = _removeTopItems(numArgs);
547 // add names to the named arguments 525 // add names to the named arguments
548 for (int i = 0; i < numNamedArgs; i++) { 526 for (int i = 0; i < numNamedArgs; i++) {
549 String name = uc.strings[stringPtr++]; 527 String name = uc.strings[stringPtr++];
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 serializedExecutable.name, serializedExecutable.nameOffset); 910 serializedExecutable.name, serializedExecutable.nameOffset);
933 constructors[serializedExecutable.name] = currentConstructor; 911 constructors[serializedExecutable.name] = currentConstructor;
934 currentConstructor.returnType = classType; 912 currentConstructor.returnType = classType;
935 buildExecutableCommonParts(currentConstructor, serializedExecutable); 913 buildExecutableCommonParts(currentConstructor, serializedExecutable);
936 currentConstructor.factory = serializedExecutable.isFactory; 914 currentConstructor.factory = serializedExecutable.isFactory;
937 currentConstructor.const2 = serializedExecutable.isConst; 915 currentConstructor.const2 = serializedExecutable.isConst;
938 currentConstructor.constantInitializers = serializedExecutable 916 currentConstructor.constantInitializers = serializedExecutable
939 .constantInitializers 917 .constantInitializers
940 .map(buildConstantInitializer) 918 .map(buildConstantInitializer)
941 .toList(); 919 .toList();
920 if (serializedExecutable.isRedirectedConstructor) {
921 if (serializedExecutable.isFactory) {
922 EntityRef redirectedConstructor =
923 serializedExecutable.redirectedConstructor;
924 currentConstructor.redirectedConstructor = _createConstructorElement(
925 referenceInfos[redirectedConstructor.reference],
926 redirectedConstructor.typeArguments);
927 } else {
928 List<String> locationComponents =
929 currentCompilationUnit.location.components.toList();
930 locationComponents.add(classType.name);
931 locationComponents.add(serializedExecutable.redirectedConstructorName);
932 currentConstructor.redirectedConstructor =
933 new _DeferredConstructorElement._(
934 classType,
935 serializedExecutable.redirectedConstructorName,
936 new ElementLocationImpl.con3(locationComponents));
937 }
938 }
942 holder.addConstructor(currentConstructor); 939 holder.addConstructor(currentConstructor);
943 currentConstructor = null; 940 currentConstructor = null;
944 } 941 }
945 942
946 /** 943 /**
947 * Build the documentation for the given [element]. Does nothing if 944 * Build the documentation for the given [element]. Does nothing if
948 * [serializedDocumentationComment] is `null`. 945 * [serializedDocumentationComment] is `null`.
949 */ 946 */
950 void buildDocumentation(ElementImpl element, 947 void buildDocumentation(ElementImpl element,
951 UnlinkedDocumentationComment serializedDocumentationComment) { 948 UnlinkedDocumentationComment serializedDocumentationComment) {
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 /** 1881 /**
1885 * Return the new handle of the `String.length` getter element. 1882 * Return the new handle of the `String.length` getter element.
1886 */ 1883 */
1887 PropertyAccessorElementHandle _buildStringLengthPropertyAccessorElement() => 1884 PropertyAccessorElementHandle _buildStringLengthPropertyAccessorElement() =>
1888 new PropertyAccessorElementHandle( 1885 new PropertyAccessorElementHandle(
1889 summaryResynthesizer, 1886 summaryResynthesizer,
1890 new ElementLocationImpl.con3( 1887 new ElementLocationImpl.con3(
1891 <String>['dart:core', 'dart:core', 'String', 'length?'])); 1888 <String>['dart:core', 'dart:core', 'String', 'length?']));
1892 1889
1893 /** 1890 /**
1891 * Return the [ConstructorElement] by applying [typeArgumentRefs] to the
1892 * given linked [info]. Both cases when [info] is a [ClassElement] and
1893 * [ConstructorElement] are supported.
1894 */
1895 _DeferredConstructorElement _createConstructorElement(
1896 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) {
1897 bool isClass = info.element is ClassElement;
1898 _ReferenceInfo classInfo = isClass ? info : info.enclosing;
1899 List<DartType> typeArguments = typeArgumentRefs.map(buildType).toList();
1900 InterfaceType classType = classInfo.buildType((i) {
1901 if (i < typeArguments.length) {
1902 return typeArguments[i];
1903 } else {
1904 return DynamicTypeImpl.instance;
1905 }
1906 }, const <int>[]);
1907 String name = isClass ? '' : info.name;
1908 return new _DeferredConstructorElement(classType, name);
1909 }
1910
1911 /**
1894 * If the given [kind] is a top-level or class member property accessor, and 1912 * If the given [kind] is a top-level or class member property accessor, and
1895 * the given [name] does not end with `=`, i.e. does not denote a setter, 1913 * the given [name] does not end with `=`, i.e. does not denote a setter,
1896 * return the getter identifier by appending `?`. 1914 * return the getter identifier by appending `?`.
1897 */ 1915 */
1898 static String _getElementIdentifier(String name, ReferenceKind kind) { 1916 static String _getElementIdentifier(String name, ReferenceKind kind) {
1899 if (kind == ReferenceKind.topLevelPropertyAccessor || 1917 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1900 kind == ReferenceKind.propertyAccessor) { 1918 kind == ReferenceKind.propertyAccessor) {
1901 if (!name.endsWith('=')) { 1919 if (!name.endsWith('=')) {
1902 return name + '?'; 1920 return name + '?';
1903 } 1921 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 } 2042 }
2025 : () => this.element; 2043 : () => this.element;
2026 // TODO(paulberry): Is it a bug that we have to pass `false` for 2044 // TODO(paulberry): Is it a bug that we have to pass `false` for
2027 // isInstantiated? 2045 // isInstantiated?
2028 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 2046 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
2029 } else { 2047 } else {
2030 return null; 2048 return null;
2031 } 2049 }
2032 } 2050 }
2033 } 2051 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698