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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart

Issue 2983413002: Resynthesize constructor initializers from Kernel. (Closed)
Patch Set: Created 3 years, 4 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 analyzer.test.src.summary.resynthesize_kernel_test; 5 library analyzer.test.src.summary.resynthesize_kernel_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 test_constructor_initializers_assertInvocation() async { 403 test_constructor_initializers_assertInvocation() async {
404 await super.test_constructor_initializers_assertInvocation(); 404 await super.test_constructor_initializers_assertInvocation();
405 } 405 }
406 406
407 @failingTest 407 @failingTest
408 test_constructor_initializers_assertInvocation_message() async { 408 test_constructor_initializers_assertInvocation_message() async {
409 await super.test_constructor_initializers_assertInvocation_message(); 409 await super.test_constructor_initializers_assertInvocation_message();
410 } 410 }
411 411
412 @failingTest 412 @failingTest
413 test_constructor_initializers_field() async { 413 @_fastaProblem
414 await super.test_constructor_initializers_field();
415 }
416
417 @failingTest
418 test_constructor_initializers_field_notConst() async { 414 test_constructor_initializers_field_notConst() async {
415 // Fasta generates additional `#errors` top-level variable.
419 await super.test_constructor_initializers_field_notConst(); 416 await super.test_constructor_initializers_field_notConst();
420 } 417 }
421 418
422 @failingTest 419 @failingTest
420 @_fastaProblem
423 test_constructor_initializers_field_withParameter() async { 421 test_constructor_initializers_field_withParameter() async {
422 // https://github.com/dart-lang/sdk/issues/30251
424 await super.test_constructor_initializers_field_withParameter(); 423 await super.test_constructor_initializers_field_withParameter();
425 } 424 }
426 425
427 @failingTest 426 @failingTest
428 test_constructor_initializers_superInvocation_named() async {
429 await super.test_constructor_initializers_superInvocation_named();
430 }
431
432 @failingTest
433 test_constructor_initializers_superInvocation_namedExpression() async {
434 await super.test_constructor_initializers_superInvocation_namedExpression();
435 }
436
437 @failingTest
438 test_constructor_initializers_superInvocation_unnamed() async {
439 await super.test_constructor_initializers_superInvocation_unnamed();
440 }
441
442 @failingTest
443 test_constructor_initializers_thisInvocation_named() async {
444 await super.test_constructor_initializers_thisInvocation_named();
445 }
446
447 @failingTest
448 test_constructor_initializers_thisInvocation_namedExpression() async {
449 await super.test_constructor_initializers_thisInvocation_namedExpression();
450 }
451
452 @failingTest
453 test_constructor_initializers_thisInvocation_unnamed() async {
454 await super.test_constructor_initializers_thisInvocation_unnamed();
455 }
456
457 @failingTest
458 test_constructor_redirected_factory_named() async { 427 test_constructor_redirected_factory_named() async {
459 await super.test_constructor_redirected_factory_named(); 428 await super.test_constructor_redirected_factory_named();
460 } 429 }
461 430
462 @failingTest 431 @failingTest
463 test_constructor_redirected_factory_named_generic() async { 432 test_constructor_redirected_factory_named_generic() async {
464 await super.test_constructor_redirected_factory_named_generic(); 433 await super.test_constructor_redirected_factory_named_generic();
465 } 434 }
466 435
467 @failingTest 436 @failingTest
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 test_constructor_redirected_thisInvocation_unnamed() async { 513 test_constructor_redirected_thisInvocation_unnamed() async {
545 await super.test_constructor_redirected_thisInvocation_unnamed(); 514 await super.test_constructor_redirected_thisInvocation_unnamed();
546 } 515 }
547 516
548 @failingTest 517 @failingTest
549 test_constructor_redirected_thisInvocation_unnamed_generic() async { 518 test_constructor_redirected_thisInvocation_unnamed_generic() async {
550 await super.test_constructor_redirected_thisInvocation_unnamed_generic(); 519 await super.test_constructor_redirected_thisInvocation_unnamed_generic();
551 } 520 }
552 521
553 @failingTest 522 @failingTest
554 test_constructor_withCycles_const() async {
555 await super.test_constructor_withCycles_const();
556 }
557
558 @failingTest
559 test_defaultValue_refersToGenericClass_constructor() async { 523 test_defaultValue_refersToGenericClass_constructor() async {
560 await super.test_defaultValue_refersToGenericClass_constructor(); 524 await super.test_defaultValue_refersToGenericClass_constructor();
561 } 525 }
562 526
563 @failingTest 527 @failingTest
564 test_defaultValue_refersToGenericClass_constructor2() async { 528 test_defaultValue_refersToGenericClass_constructor2() async {
565 await super.test_defaultValue_refersToGenericClass_constructor2(); 529 await super.test_defaultValue_refersToGenericClass_constructor2();
566 } 530 }
567 531
568 @failingTest 532 @failingTest
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 test_import_show() async { 903 test_import_show() async {
940 await super.test_import_show(); 904 await super.test_import_show();
941 } 905 }
942 906
943 @failingTest 907 @failingTest
944 test_inferred_function_type_for_variable_in_generic_function() async { 908 test_inferred_function_type_for_variable_in_generic_function() async {
945 await super.test_inferred_function_type_for_variable_in_generic_function(); 909 await super.test_inferred_function_type_for_variable_in_generic_function();
946 } 910 }
947 911
948 @failingTest 912 @failingTest
913 test_inferred_function_type_in_generic_class_constructor() async {
914 await super.test_inferred_function_type_in_generic_class_constructor();
915 }
916
917 @failingTest
949 test_inferred_function_type_in_generic_class_in_generic_method() async { 918 test_inferred_function_type_in_generic_class_in_generic_method() async {
950 await super 919 await super
951 .test_inferred_function_type_in_generic_class_in_generic_method(); 920 .test_inferred_function_type_in_generic_class_in_generic_method();
952 } 921 }
953 922
954 @failingTest 923 @failingTest
955 test_inferred_type_is_typedef() async { 924 test_inferred_type_is_typedef() async {
956 await super.test_inferred_type_is_typedef(); 925 await super.test_inferred_type_is_typedef();
957 } 926 }
958 927
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 } 1876 }
1908 } else if (args.length == 1) { 1877 } else if (args.length == 1) {
1909 var operator = _toBinaryOperatorTokenType(operatorName); 1878 var operator = _toBinaryOperatorTokenType(operatorName);
1910 var right = build(args.single); 1879 var right = build(args.single);
1911 return AstTestFactory.binaryExpression(left, operator, right); 1880 return AstTestFactory.binaryExpression(left, operator, right);
1912 } 1881 }
1913 } 1882 }
1914 } 1883 }
1915 } 1884 }
1916 1885
1886 if (expr is kernel.StaticInvocation) {
1887 kernel.Procedure target = expr.target;
1888 String name = target.name.name;
1889 List<Expression> arguments = _toArguments(expr.arguments);
1890 MethodInvocation invocation =
1891 AstTestFactory.methodInvocation3(null, name, null, arguments);
1892 invocation.methodName.staticElement = _getElement(target.reference);
1893 return invocation;
1894 }
1895
1917 if (expr is kernel.ConstructorInvocation) { 1896 if (expr is kernel.ConstructorInvocation) {
1918 var element = _getElement(expr.targetReference); 1897 var element = _getElement(expr.targetReference);
1919 1898
1920 var kernelType = expr.getStaticType(_context._resynthesizer._types); 1899 var kernelType = expr.getStaticType(_context._resynthesizer._types);
1921 var type = _context.getType(null, kernelType); 1900 var type = _context.getType(null, kernelType);
1922 TypeName typeName = _buildType(type); 1901 TypeName typeName = _buildType(type);
1923 1902
1924 var constructorName = AstTestFactory.constructorName( 1903 var constructorName = AstTestFactory.constructorName(
1925 typeName, element.name.isNotEmpty ? element.name : null); 1904 typeName, element.name.isNotEmpty ? element.name : null);
1926 constructorName?.name?.staticElement = element; 1905 constructorName?.name?.staticElement = element;
1927 1906
1928 var keyword = expr.isConst ? Keyword.CONST : Keyword.NEW; 1907 var keyword = expr.isConst ? Keyword.CONST : Keyword.NEW;
1929 var arguments = _toArguments(expr.arguments); 1908 var arguments = _toArguments(expr.arguments);
1930 return AstTestFactory.instanceCreationExpression( 1909 return AstTestFactory.instanceCreationExpression(
1931 keyword, constructorName, arguments); 1910 keyword, constructorName, arguments);
1932 } 1911 }
1933 1912
1934 // TODO(scheglov): complete getExpression 1913 // TODO(scheglov): complete getExpression
1935 throw new UnimplementedError('kernel: (${expr.runtimeType}) $expr'); 1914 throw new UnimplementedError('kernel: (${expr.runtimeType}) $expr');
1936 } 1915 }
1937 1916
1917 ConstructorInitializer buildInitializer(kernel.Initializer k) {
1918 if (k is kernel.FieldInitializer) {
1919 Expression value = build(k.value);
1920 ConstructorFieldInitializer initializer = AstTestFactory
1921 .constructorFieldInitializer(false, k.field.name.name, value);
1922 initializer.fieldName.staticElement = _getElement(k.fieldReference);
1923 return initializer;
1924 }
1925
1926 if (k is kernel.RedirectingInitializer) {
1927 ConstructorElementImpl redirect = _getElement(k.targetReference);
1928 var arguments = _toArguments(k.arguments);
1929
1930 RedirectingConstructorInvocation invocation =
1931 AstTestFactory.redirectingConstructorInvocation(arguments);
1932 invocation.staticElement = redirect;
1933
1934 String name = k.target.name.name;
1935 if (name.isNotEmpty) {
1936 invocation.constructorName = AstTestFactory.identifier3(name)
1937 ..staticElement = redirect;
1938 }
1939
1940 return invocation;
1941 }
1942
1943 if (k is kernel.SuperInitializer) {
1944 ConstructorElementImpl redirect = _getElement(k.targetReference);
1945 var arguments = _toArguments(k.arguments);
1946
1947 SuperConstructorInvocation invocation =
1948 AstTestFactory.superConstructorInvocation(arguments);
1949 invocation.staticElement = redirect;
1950
1951 String name = k.target.name.name;
1952 if (name.isNotEmpty) {
1953 invocation.constructorName = AstTestFactory.identifier3(name)
1954 ..staticElement = redirect;
1955 }
1956
1957 return invocation;
1958 }
1959
1960 // TODO(scheglov) Support other kernel initializer types.
1961 throw new UnimplementedError('For ${k.runtimeType}');
1962 }
1963
1938 Expression _buildIdentifier(kernel.Reference reference, {bool isGet: false}) { 1964 Expression _buildIdentifier(kernel.Reference reference, {bool isGet: false}) {
1939 Element element = _getElement(reference); 1965 Element element = _getElement(reference);
1940 if (isGet && element is PropertyInducingElement) { 1966 if (isGet && element is PropertyInducingElement) {
1941 element = (element as PropertyInducingElement).getter; 1967 element = (element as PropertyInducingElement).getter;
1942 } 1968 }
1943 SimpleIdentifier property = AstTestFactory.identifier3(element.displayName) 1969 SimpleIdentifier property = AstTestFactory.identifier3(element.displayName)
1944 ..staticElement = element; 1970 ..staticElement = element;
1945 Element enclosingElement = element.enclosingElement; 1971 Element enclosingElement = element.enclosingElement;
1946 if (enclosingElement is ClassElement) { 1972 if (enclosingElement is ClassElement) {
1947 SimpleIdentifier classRef = AstTestFactory 1973 SimpleIdentifier classRef = AstTestFactory
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 Future<List<int>> readAsBytes() async { 2109 Future<List<int>> readAsBytes() async {
2084 return file.readAsBytesSync(); 2110 return file.readAsBytesSync();
2085 } 2111 }
2086 2112
2087 @override 2113 @override
2088 Future<String> readAsString() async { 2114 Future<String> readAsString() async {
2089 return file.readAsStringSync(); 2115 return file.readAsStringSync();
2090 } 2116 }
2091 } 2117 }
2092 2118
2093 class _KernelLibraryResynthesizerContextImpl 2119 class _KernelLibraryResynthesizerContextImpl
Siggi Cherem (dart-lang) 2017/07/25 15:19:56 question unrelated to the CL: what is your plan wi
scheglov 2017/07/25 16:15:54 Yes, the plan is to extract these classes into a s
2094 implements KernelLibraryResynthesizerContext { 2120 implements KernelLibraryResynthesizerContext {
2095 final _KernelResynthesizer _resynthesizer; 2121 final _KernelResynthesizer _resynthesizer;
2096 2122
2097 @override 2123 @override
2098 final kernel.Library library; 2124 final kernel.Library library;
2099 2125
2100 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library); 2126 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library);
2101 2127
2102 @override 2128 @override
2129 ConstructorInitializer getConstructorInitializer(
2130 ConstructorElementImpl constructor, kernel.Initializer k) {
2131 if (k is kernel.LocalInitializer ||
2132 k is kernel.FieldInitializer && k.isSynthetic ||
2133 k is kernel.SuperInitializer && k.isSynthetic) {
2134 return null;
2135 }
2136 return new _ExprBuilder(this).buildInitializer(k);
2137 }
2138
2139 @override
2140 ElementImpl getElement(kernel.Reference reference) {
2141 return _getElement(reference.canonicalName);
2142 }
2143
2144 @override
2103 Expression getExpression(kernel.Expression expression) { 2145 Expression getExpression(kernel.Expression expression) {
2104 return new _ExprBuilder(this).build(expression); 2146 return new _ExprBuilder(this).build(expression);
2105 } 2147 }
2106 2148
2107 @override 2149 @override
2108 InterfaceType getInterfaceType( 2150 InterfaceType getInterfaceType(
2109 ElementImpl context, kernel.Supertype kernelType) { 2151 ElementImpl context, kernel.Supertype kernelType) {
2110 return _getInterfaceType( 2152 return _getInterfaceType(
2111 context, kernelType.className.canonicalName, kernelType.typeArguments); 2153 context, kernelType.className.canonicalName, kernelType.typeArguments);
2112 } 2154 }
(...skipping 24 matching lines...) Expand all
2137 */ 2179 */
2138 ElementImpl _getElement(kernel.CanonicalName name) { 2180 ElementImpl _getElement(kernel.CanonicalName name) {
2139 if (name == null) return null; 2181 if (name == null) return null;
2140 kernel.CanonicalName parentName = name.parent; 2182 kernel.CanonicalName parentName = name.parent;
2141 2183
2142 // If the parent is the root, then this name is a library. 2184 // If the parent is the root, then this name is a library.
2143 if (parentName.isRoot) { 2185 if (parentName.isRoot) {
2144 return _resynthesizer.getLibrary(name.name); 2186 return _resynthesizer.getLibrary(name.name);
2145 } 2187 }
2146 2188
2189 // If the name is private, it is prefixed with a library URI.
2190 if (name.name.startsWith('_')) {
2191 parentName = parentName.parent;
2192 }
2193
2147 // Skip qualifiers. 2194 // Skip qualifiers.
2148 bool isGetter = false; 2195 bool isGetter = false;
2149 bool isSetter = false; 2196 bool isSetter = false;
2150 bool isField = false; 2197 bool isField = false;
2151 bool isConstructor = false; 2198 bool isConstructor = false;
2152 bool isMethod = false; 2199 bool isMethod = false;
2153 if (parentName.name == '@getters') { 2200 if (parentName.name == '@getters') {
2154 isGetter = true; 2201 isGetter = true;
2155 parentName = parentName.parent; 2202 parentName = parentName.parent;
2156 } else if (parentName.name == '@setters') { 2203 } else if (parentName.name == '@setters') {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 } 2319 }
2273 2320
2274 /** 2321 /**
2275 * Get the [Source] object for the given [uri]. 2322 * Get the [Source] object for the given [uri].
2276 */ 2323 */
2277 Source _getSource(String uri) { 2324 Source _getSource(String uri) {
2278 return _sources.putIfAbsent( 2325 return _sources.putIfAbsent(
2279 uri, () => _analysisContext.sourceFactory.forUri(uri)); 2326 uri, () => _analysisContext.sourceFactory.forUri(uri));
2280 } 2327 }
2281 } 2328 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_common.dart ('k') | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698